Mercurial > vim
annotate src/spell.c @ 32669:448aef880252
normalize line endings
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Mon, 26 Jun 2023 09:54:34 +0200 |
parents | 238e25832d07 |
children | 695b50472e85 |
rev | line source |
---|---|
32669
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2 * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3 * VIM - Vi IMproved by Bram Moolenaar |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4 * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
5 * Do ":help uganda" in Vim to read copying and usage conditions. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
6 * Do ":help credits" in Vim to see a list of people who contributed. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
7 * See README.txt for an overview of the Vim source code. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
8 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
9 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
10 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
11 * spell.c: code for spell checking |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
12 * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
13 * See spellfile.c for the Vim spell file format. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
14 * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
15 * The spell checking mechanism uses a tree (aka trie). Each node in the tree |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
16 * has a list of bytes that can appear (siblings). For each byte there is a |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
17 * pointer to the node with the byte that follows in the word (child). |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
18 * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
19 * A NUL byte is used where the word may end. The bytes are sorted, so that |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
20 * binary searching can be used and the NUL bytes are at the start. The |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
21 * number of possible bytes is stored before the list of bytes. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
22 * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
23 * The tree uses two arrays: "byts" stores the characters, "idxs" stores |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
24 * either the next index or flags. The tree starts at index 0. For example, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
25 * to lookup "vi" this sequence is followed: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
26 * i = 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
27 * len = byts[i] |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
28 * n = where "v" appears in byts[i + 1] to byts[i + len] |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
29 * i = idxs[n] |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
30 * len = byts[i] |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
31 * n = where "i" appears in byts[i + 1] to byts[i + len] |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
32 * i = idxs[n] |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
33 * len = byts[i] |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
34 * find that byts[i + 1] is 0, idxs[i + 1] has flags for "vi". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
35 * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
36 * There are two word trees: one with case-folded words and one with words in |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
37 * original case. The second one is only used for keep-case words and is |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
38 * usually small. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
39 * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
40 * There is one additional tree for when not all prefixes are applied when |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
41 * generating the .spl file. This tree stores all the possible prefixes, as |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
42 * if they were words. At each word (prefix) end the prefix nr is stored, the |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
43 * following word must support this prefix nr. And the condition nr is |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
44 * stored, used to lookup the condition that the word must match with. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
45 * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
46 * Thanks to Olaf Seibert for providing an example implementation of this tree |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
47 * and the compression mechanism. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
48 * LZ trie ideas: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
49 * http://www.irb.hr/hr/home/ristov/papers/RistovLZtrieRevision1.pdf |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
50 * More papers: http://www-igm.univ-mlv.fr/~laporte/publi_en.html |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
51 * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
52 * Matching involves checking the caps type: Onecap ALLCAP KeepCap. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
53 * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
54 * Why doesn't Vim use aspell/ispell/myspell/etc.? |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
55 * See ":help develop-spell". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
56 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
57 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
58 #define IN_SPELL_C |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
59 #include "vim.h" |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
60 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
61 #if defined(FEAT_SPELL) || defined(PROTO) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
62 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
63 #ifndef UNIX // it's in os_unix.h for Unix |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
64 # include <time.h> // for time_t |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
65 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
66 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
67 #define REGION_ALL 0xff // word valid in all regions |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
68 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
69 // Result values. Lower number is accepted over higher one. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
70 #define SP_BANNED (-1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
71 #define SP_OK 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
72 #define SP_RARE 1 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
73 #define SP_LOCAL 2 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
74 #define SP_BAD 3 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
75 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
76 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
77 * Structure to store info for word matching. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
78 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
79 typedef struct matchinf_S |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
80 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
81 langp_T *mi_lp; // info for language and region |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
82 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
83 // pointers to original text to be checked |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
84 char_u *mi_word; // start of word being checked |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
85 char_u *mi_end; // end of matching word so far |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
86 char_u *mi_fend; // next char to be added to mi_fword |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
87 char_u *mi_cend; // char after what was used for |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
88 // mi_capflags |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
89 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
90 // case-folded text |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
91 char_u mi_fword[MAXWLEN + 1]; // mi_word case-folded |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
92 int mi_fwordlen; // nr of valid bytes in mi_fword |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
93 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
94 // for when checking word after a prefix |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
95 int mi_prefarridx; // index in sl_pidxs with list of |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
96 // affixID/condition |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
97 int mi_prefcnt; // number of entries at mi_prefarridx |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
98 int mi_prefixlen; // byte length of prefix |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
99 int mi_cprefixlen; // byte length of prefix in original |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
100 // case |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
101 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
102 // for when checking a compound word |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
103 int mi_compoff; // start of following word offset |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
104 char_u mi_compflags[MAXWLEN]; // flags for compound words used |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
105 int mi_complen; // nr of compound words used |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
106 int mi_compextra; // nr of COMPOUNDROOT words |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
107 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
108 // others |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
109 int mi_result; // result so far: SP_BAD, SP_OK, etc. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
110 int mi_capflags; // WF_ONECAP WF_ALLCAP WF_KEEPCAP |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
111 win_T *mi_win; // buffer being checked |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
112 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
113 // for NOBREAK |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
114 int mi_result2; // "mi_result" without following word |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
115 char_u *mi_end2; // "mi_end" without following word |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
116 } matchinf_T; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
117 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
118 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
119 static int spell_mb_isword_class(int cl, win_T *wp); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
120 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
121 // mode values for find_word |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
122 #define FIND_FOLDWORD 0 // find word case-folded |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
123 #define FIND_KEEPWORD 1 // find keep-case word |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
124 #define FIND_PREFIX 2 // find word after prefix |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
125 #define FIND_COMPOUND 3 // find case-folded compound word |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
126 #define FIND_KEEPCOMPOUND 4 // find keep-case compound word |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
127 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
128 static void find_word(matchinf_T *mip, int mode); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
129 static void find_prefix(matchinf_T *mip, int mode); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
130 static int fold_more(matchinf_T *mip); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
131 static void spell_load_cb(char_u *fname, void *cookie); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
132 static int count_syllables(slang_T *slang, char_u *word); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
133 static void clear_midword(win_T *buf); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
134 static void use_midword(slang_T *lp, win_T *buf); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
135 static int find_region(char_u *rp, char_u *region); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
136 static void spell_soundfold_sofo(slang_T *slang, char_u *inword, char_u *res); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
137 static void spell_soundfold_sal(slang_T *slang, char_u *inword, char_u *res); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
138 static void spell_soundfold_wsal(slang_T *slang, char_u *inword, char_u *res); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
139 static void dump_word(slang_T *slang, char_u *word, char_u *pat, int *dir, int round, int flags, linenr_T lnum); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
140 static linenr_T dump_prefixes(slang_T *slang, char_u *word, char_u *pat, int *dir, int round, int flags, linenr_T startlnum); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
141 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
142 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
143 * Main spell-checking function. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
144 * "ptr" points to a character that could be the start of a word. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
145 * "*attrp" is set to the highlight index for a badly spelled word. For a |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
146 * non-word or when it's OK it remains unchanged. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
147 * This must only be called when 'spelllang' is not empty. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
148 * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
149 * "capcol" is used to check for a Capitalised word after the end of a |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
150 * sentence. If it's zero then perform the check. Return the column where to |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
151 * check next, or -1 when no sentence end was found. If it's NULL then don't |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
152 * worry. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
153 * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
154 * Returns the length of the word in bytes, also when it's OK, so that the |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
155 * caller can skip over the word. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
156 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
157 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
158 spell_check( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
159 win_T *wp, // current window |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
160 char_u *ptr, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
161 hlf_T *attrp, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
162 int *capcol, // column to check for Capital |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
163 int docount) // count good words |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
164 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
165 matchinf_T mi; // Most things are put in "mi" so that it can |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
166 // be passed to functions quickly. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
167 int nrlen = 0; // found a number first |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
168 int c; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
169 int wrongcaplen = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
170 int lpi; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
171 int count_word = docount; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
172 int use_camel_case = *wp->w_s->b_p_spo != NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
173 int camel_case = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
174 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
175 // A word never starts at a space or a control character. Return quickly |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
176 // then, skipping over the character. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
177 if (*ptr <= ' ') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
178 return 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
179 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
180 // Return here when loading language files failed. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
181 if (wp->w_s->b_langp.ga_len == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
182 return 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
183 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
184 CLEAR_FIELD(mi); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
185 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
186 // A number is always OK. Also skip hexadecimal numbers 0xFF99 and |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
187 // 0X99FF. But always do check spelling to find "3GPP" and "11 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
188 // julifeest". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
189 if (*ptr >= '0' && *ptr <= '9') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
190 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
191 if (*ptr == '0' && (ptr[1] == 'b' || ptr[1] == 'B')) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
192 mi.mi_end = skipbin(ptr + 2); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
193 else if (*ptr == '0' && (ptr[1] == 'x' || ptr[1] == 'X')) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
194 mi.mi_end = skiphex(ptr + 2); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
195 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
196 mi.mi_end = skipdigits(ptr); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
197 nrlen = (int)(mi.mi_end - ptr); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
198 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
199 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
200 // Find the normal end of the word (until the next non-word character). |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
201 mi.mi_word = ptr; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
202 mi.mi_fend = ptr; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
203 if (spell_iswordp(mi.mi_fend, wp)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
204 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
205 int prev_upper; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
206 int this_upper = FALSE; // init for gcc |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
207 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
208 if (use_camel_case) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
209 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
210 c = PTR2CHAR(mi.mi_fend); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
211 this_upper = SPELL_ISUPPER(c); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
212 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
213 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
214 do |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
215 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
216 MB_PTR_ADV(mi.mi_fend); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
217 if (use_camel_case) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
218 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
219 prev_upper = this_upper; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
220 c = PTR2CHAR(mi.mi_fend); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
221 this_upper = SPELL_ISUPPER(c); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
222 camel_case = !prev_upper && this_upper; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
223 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
224 } while (*mi.mi_fend != NUL && spell_iswordp(mi.mi_fend, wp) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
225 && !camel_case); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
226 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
227 if (capcol != NULL && *capcol == 0 && wp->w_s->b_cap_prog != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
228 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
229 // Check word starting with capital letter. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
230 c = PTR2CHAR(ptr); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
231 if (!SPELL_ISUPPER(c)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
232 wrongcaplen = (int)(mi.mi_fend - ptr); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
233 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
234 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
235 if (capcol != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
236 *capcol = -1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
237 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
238 // We always use the characters up to the next non-word character, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
239 // also for bad words. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
240 mi.mi_end = mi.mi_fend; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
241 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
242 // Check caps type later. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
243 mi.mi_capflags = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
244 mi.mi_cend = NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
245 mi.mi_win = wp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
246 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
247 // case-fold the word with one non-word character, so that we can check |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
248 // for the word end. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
249 if (*mi.mi_fend != NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
250 MB_PTR_ADV(mi.mi_fend); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
251 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
252 (void)spell_casefold(wp, ptr, (int)(mi.mi_fend - ptr), mi.mi_fword, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
253 MAXWLEN + 1); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
254 mi.mi_fwordlen = (int)STRLEN(mi.mi_fword); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
255 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
256 if (camel_case && mi.mi_fwordlen > 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
257 // Introduce a fake word end space into the folded word. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
258 mi.mi_fword[mi.mi_fwordlen - 1] = ' '; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
259 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
260 // The word is bad unless we recognize it. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
261 mi.mi_result = SP_BAD; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
262 mi.mi_result2 = SP_BAD; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
263 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
264 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
265 * Loop over the languages specified in 'spelllang'. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
266 * We check them all, because a word may be matched longer in another |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
267 * language. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
268 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
269 for (lpi = 0; lpi < wp->w_s->b_langp.ga_len; ++lpi) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
270 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
271 mi.mi_lp = LANGP_ENTRY(wp->w_s->b_langp, lpi); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
272 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
273 // If reloading fails the language is still in the list but everything |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
274 // has been cleared. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
275 if (mi.mi_lp->lp_slang->sl_fidxs == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
276 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
277 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
278 // Check for a matching word in case-folded words. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
279 find_word(&mi, FIND_FOLDWORD); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
280 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
281 // Check for a matching word in keep-case words. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
282 find_word(&mi, FIND_KEEPWORD); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
283 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
284 // Check for matching prefixes. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
285 find_prefix(&mi, FIND_FOLDWORD); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
286 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
287 // For a NOBREAK language, may want to use a word without a following |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
288 // word as a backup. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
289 if (mi.mi_lp->lp_slang->sl_nobreak && mi.mi_result == SP_BAD |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
290 && mi.mi_result2 != SP_BAD) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
291 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
292 mi.mi_result = mi.mi_result2; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
293 mi.mi_end = mi.mi_end2; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
294 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
295 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
296 // Count the word in the first language where it's found to be OK. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
297 if (count_word && mi.mi_result == SP_OK) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
298 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
299 count_common_word(mi.mi_lp->lp_slang, ptr, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
300 (int)(mi.mi_end - ptr), 1); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
301 count_word = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
302 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
303 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
304 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
305 if (mi.mi_result != SP_OK) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
306 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
307 // If we found a number skip over it. Allows for "42nd". Do flag |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
308 // rare and local words, e.g., "3GPP". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
309 if (nrlen > 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
310 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
311 if (mi.mi_result == SP_BAD || mi.mi_result == SP_BANNED) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
312 return nrlen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
313 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
314 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
315 // When we are at a non-word character there is no error, just |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
316 // skip over the character (try looking for a word after it). |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
317 else if (!spell_iswordp_nmw(ptr, wp)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
318 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
319 if (capcol != NULL && wp->w_s->b_cap_prog != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
320 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
321 regmatch_T regmatch; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
322 int r; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
323 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
324 // Check for end of sentence. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
325 regmatch.regprog = wp->w_s->b_cap_prog; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
326 regmatch.rm_ic = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
327 r = vim_regexec(®match, ptr, 0); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
328 wp->w_s->b_cap_prog = regmatch.regprog; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
329 if (r) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
330 *capcol = (int)(regmatch.endp[0] - ptr); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
331 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
332 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
333 if (has_mbyte) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
334 return (*mb_ptr2len)(ptr); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
335 return 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
336 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
337 else if (mi.mi_end == ptr) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
338 // Always include at least one character. Required for when there |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
339 // is a mixup in "midword". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
340 MB_PTR_ADV(mi.mi_end); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
341 else if (mi.mi_result == SP_BAD |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
342 && LANGP_ENTRY(wp->w_s->b_langp, 0)->lp_slang->sl_nobreak) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
343 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
344 char_u *p, *fp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
345 int save_result = mi.mi_result; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
346 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
347 // First language in 'spelllang' is NOBREAK. Find first position |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
348 // at which any word would be valid. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
349 mi.mi_lp = LANGP_ENTRY(wp->w_s->b_langp, 0); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
350 if (mi.mi_lp->lp_slang->sl_fidxs != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
351 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
352 p = mi.mi_word; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
353 fp = mi.mi_fword; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
354 for (;;) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
355 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
356 MB_PTR_ADV(p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
357 MB_PTR_ADV(fp); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
358 if (p >= mi.mi_end) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
359 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
360 mi.mi_compoff = (int)(fp - mi.mi_fword); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
361 find_word(&mi, FIND_COMPOUND); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
362 if (mi.mi_result != SP_BAD) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
363 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
364 mi.mi_end = p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
365 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
366 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
367 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
368 mi.mi_result = save_result; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
369 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
370 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
371 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
372 if (mi.mi_result == SP_BAD || mi.mi_result == SP_BANNED) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
373 *attrp = HLF_SPB; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
374 else if (mi.mi_result == SP_RARE) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
375 *attrp = HLF_SPR; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
376 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
377 *attrp = HLF_SPL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
378 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
379 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
380 if (wrongcaplen > 0 && (mi.mi_result == SP_OK || mi.mi_result == SP_RARE)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
381 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
382 // Report SpellCap only when the word isn't badly spelled. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
383 *attrp = HLF_SPC; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
384 return wrongcaplen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
385 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
386 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
387 return (int)(mi.mi_end - ptr); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
388 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
389 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
390 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
391 * Check if the word at "mip->mi_word" is in the tree. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
392 * When "mode" is FIND_FOLDWORD check in fold-case word tree. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
393 * When "mode" is FIND_KEEPWORD check in keep-case word tree. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
394 * When "mode" is FIND_PREFIX check for word after prefix in fold-case word |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
395 * tree. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
396 * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
397 * For a match mip->mi_result is updated. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
398 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
399 static void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
400 find_word(matchinf_T *mip, int mode) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
401 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
402 idx_T arridx = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
403 int endlen[MAXWLEN]; // length at possible word endings |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
404 idx_T endidx[MAXWLEN]; // possible word endings |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
405 int endidxcnt = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
406 int len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
407 int wlen = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
408 int flen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
409 int c; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
410 char_u *ptr; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
411 idx_T lo, hi, m; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
412 char_u *s; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
413 char_u *p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
414 int res = SP_BAD; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
415 slang_T *slang = mip->mi_lp->lp_slang; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
416 unsigned flags; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
417 char_u *byts; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
418 idx_T *idxs; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
419 int word_ends; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
420 int prefix_found; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
421 int nobreak_result; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
422 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
423 if (mode == FIND_KEEPWORD || mode == FIND_KEEPCOMPOUND) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
424 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
425 // Check for word with matching case in keep-case tree. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
426 ptr = mip->mi_word; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
427 flen = 9999; // no case folding, always enough bytes |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
428 byts = slang->sl_kbyts; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
429 idxs = slang->sl_kidxs; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
430 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
431 if (mode == FIND_KEEPCOMPOUND) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
432 // Skip over the previously found word(s). |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
433 wlen += mip->mi_compoff; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
434 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
435 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
436 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
437 // Check for case-folded in case-folded tree. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
438 ptr = mip->mi_fword; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
439 flen = mip->mi_fwordlen; // available case-folded bytes |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
440 byts = slang->sl_fbyts; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
441 idxs = slang->sl_fidxs; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
442 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
443 if (mode == FIND_PREFIX) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
444 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
445 // Skip over the prefix. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
446 wlen = mip->mi_prefixlen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
447 flen -= mip->mi_prefixlen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
448 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
449 else if (mode == FIND_COMPOUND) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
450 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
451 // Skip over the previously found word(s). |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
452 wlen = mip->mi_compoff; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
453 flen -= mip->mi_compoff; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
454 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
455 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
456 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
457 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
458 if (byts == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
459 return; // array is empty |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
460 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
461 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
462 * Repeat advancing in the tree until: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
463 * - there is a byte that doesn't match, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
464 * - we reach the end of the tree, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
465 * - or we reach the end of the line. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
466 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
467 for (;;) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
468 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
469 if (flen <= 0 && *mip->mi_fend != NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
470 flen = fold_more(mip); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
471 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
472 len = byts[arridx++]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
473 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
474 // If the first possible byte is a zero the word could end here. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
475 // Remember this index, we first check for the longest word. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
476 if (byts[arridx] == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
477 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
478 if (endidxcnt == MAXWLEN) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
479 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
480 // Must be a corrupted spell file. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
481 emsg(_(e_format_error_in_spell_file)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
482 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
483 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
484 endlen[endidxcnt] = wlen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
485 endidx[endidxcnt++] = arridx++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
486 --len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
487 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
488 // Skip over the zeros, there can be several flag/region |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
489 // combinations. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
490 while (len > 0 && byts[arridx] == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
491 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
492 ++arridx; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
493 --len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
494 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
495 if (len == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
496 break; // no children, word must end here |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
497 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
498 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
499 // Stop looking at end of the line. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
500 if (ptr[wlen] == NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
501 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
502 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
503 // Perform a binary search in the list of accepted bytes. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
504 c = ptr[wlen]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
505 if (c == TAB) // <Tab> is handled like <Space> |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
506 c = ' '; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
507 lo = arridx; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
508 hi = arridx + len - 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
509 while (lo < hi) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
510 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
511 m = (lo + hi) / 2; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
512 if (byts[m] > c) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
513 hi = m - 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
514 else if (byts[m] < c) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
515 lo = m + 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
516 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
517 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
518 lo = hi = m; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
519 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
520 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
521 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
522 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
523 // Stop if there is no matching byte. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
524 if (hi < lo || byts[lo] != c) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
525 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
526 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
527 // Continue at the child (if there is one). |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
528 arridx = idxs[lo]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
529 ++wlen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
530 --flen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
531 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
532 // One space in the good word may stand for several spaces in the |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
533 // checked word. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
534 if (c == ' ') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
535 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
536 for (;;) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
537 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
538 if (flen <= 0 && *mip->mi_fend != NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
539 flen = fold_more(mip); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
540 if (ptr[wlen] != ' ' && ptr[wlen] != TAB) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
541 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
542 ++wlen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
543 --flen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
544 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
545 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
546 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
547 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
548 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
549 * Verify that one of the possible endings is valid. Try the longest |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
550 * first. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
551 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
552 while (endidxcnt > 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
553 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
554 --endidxcnt; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
555 arridx = endidx[endidxcnt]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
556 wlen = endlen[endidxcnt]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
557 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
558 if ((*mb_head_off)(ptr, ptr + wlen) > 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
559 continue; // not at first byte of character |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
560 if (spell_iswordp(ptr + wlen, mip->mi_win)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
561 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
562 if (slang->sl_compprog == NULL && !slang->sl_nobreak) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
563 continue; // next char is a word character |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
564 word_ends = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
565 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
566 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
567 word_ends = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
568 // The prefix flag is before compound flags. Once a valid prefix flag |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
569 // has been found we try compound flags. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
570 prefix_found = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
571 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
572 if (mode != FIND_KEEPWORD && has_mbyte) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
573 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
574 // Compute byte length in original word, length may change |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
575 // when folding case. This can be slow, take a shortcut when the |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
576 // case-folded word is equal to the keep-case word. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
577 p = mip->mi_word; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
578 if (STRNCMP(ptr, p, wlen) != 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
579 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
580 for (s = ptr; s < ptr + wlen; MB_PTR_ADV(s)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
581 MB_PTR_ADV(p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
582 wlen = (int)(p - mip->mi_word); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
583 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
584 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
585 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
586 // Check flags and region. For FIND_PREFIX check the condition and |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
587 // prefix ID. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
588 // Repeat this if there are more flags/region alternatives until there |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
589 // is a match. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
590 res = SP_BAD; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
591 for (len = byts[arridx - 1]; len > 0 && byts[arridx] == 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
592 --len, ++arridx) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
593 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
594 flags = idxs[arridx]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
595 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
596 // For the fold-case tree check that the case of the checked word |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
597 // matches with what the word in the tree requires. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
598 // For keep-case tree the case is always right. For prefixes we |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
599 // don't bother to check. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
600 if (mode == FIND_FOLDWORD) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
601 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
602 if (mip->mi_cend != mip->mi_word + wlen) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
603 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
604 // mi_capflags was set for a different word length, need |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
605 // to do it again. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
606 mip->mi_cend = mip->mi_word + wlen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
607 mip->mi_capflags = captype(mip->mi_word, mip->mi_cend); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
608 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
609 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
610 if (mip->mi_capflags == WF_KEEPCAP |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
611 || !spell_valid_case(mip->mi_capflags, flags)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
612 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
613 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
614 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
615 // When mode is FIND_PREFIX the word must support the prefix: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
616 // check the prefix ID and the condition. Do that for the list at |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
617 // mip->mi_prefarridx that find_prefix() filled. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
618 else if (mode == FIND_PREFIX && !prefix_found) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
619 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
620 c = valid_word_prefix(mip->mi_prefcnt, mip->mi_prefarridx, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
621 flags, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
622 mip->mi_word + mip->mi_cprefixlen, slang, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
623 FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
624 if (c == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
625 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
626 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
627 // Use the WF_RARE flag for a rare prefix. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
628 if (c & WF_RAREPFX) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
629 flags |= WF_RARE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
630 prefix_found = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
631 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
632 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
633 if (slang->sl_nobreak) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
634 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
635 if ((mode == FIND_COMPOUND || mode == FIND_KEEPCOMPOUND) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
636 && (flags & WF_BANNED) == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
637 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
638 // NOBREAK: found a valid following word. That's all we |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
639 // need to know, so return. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
640 mip->mi_result = SP_OK; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
641 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
642 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
643 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
644 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
645 else if ((mode == FIND_COMPOUND || mode == FIND_KEEPCOMPOUND |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
646 || !word_ends)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
647 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
648 // If there is no compound flag or the word is shorter than |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
649 // COMPOUNDMIN reject it quickly. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
650 // Makes you wonder why someone puts a compound flag on a word |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
651 // that's too short... Myspell compatibility requires this |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
652 // anyway. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
653 if (((unsigned)flags >> 24) == 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
654 || wlen - mip->mi_compoff < slang->sl_compminlen) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
655 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
656 // For multi-byte chars check character length against |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
657 // COMPOUNDMIN. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
658 if (has_mbyte |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
659 && slang->sl_compminlen > 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
660 && mb_charlen_len(mip->mi_word + mip->mi_compoff, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
661 wlen - mip->mi_compoff) < slang->sl_compminlen) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
662 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
663 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
664 // Limit the number of compound words to COMPOUNDWORDMAX if no |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
665 // maximum for syllables is specified. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
666 if (!word_ends && mip->mi_complen + mip->mi_compextra + 2 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
667 > slang->sl_compmax |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
668 && slang->sl_compsylmax == MAXWLEN) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
669 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
670 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
671 // Don't allow compounding on a side where an affix was added, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
672 // unless COMPOUNDPERMITFLAG was used. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
673 if (mip->mi_complen > 0 && (flags & WF_NOCOMPBEF)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
674 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
675 if (!word_ends && (flags & WF_NOCOMPAFT)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
676 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
677 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
678 // Quickly check if compounding is possible with this flag. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
679 if (!byte_in_str(mip->mi_complen == 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
680 ? slang->sl_compstartflags |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
681 : slang->sl_compallflags, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
682 ((unsigned)flags >> 24))) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
683 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
684 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
685 // If there is a match with a CHECKCOMPOUNDPATTERN rule |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
686 // discard the compound word. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
687 if (match_checkcompoundpattern(ptr, wlen, &slang->sl_comppat)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
688 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
689 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
690 if (mode == FIND_COMPOUND) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
691 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
692 int capflags; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
693 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
694 // Need to check the caps type of the appended compound |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
695 // word. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
696 if (has_mbyte && STRNCMP(ptr, mip->mi_word, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
697 mip->mi_compoff) != 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
698 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
699 // case folding may have changed the length |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
700 p = mip->mi_word; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
701 for (s = ptr; s < ptr + mip->mi_compoff; MB_PTR_ADV(s)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
702 MB_PTR_ADV(p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
703 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
704 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
705 p = mip->mi_word + mip->mi_compoff; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
706 capflags = captype(p, mip->mi_word + wlen); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
707 if (capflags == WF_KEEPCAP || (capflags == WF_ALLCAP |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
708 && (flags & WF_FIXCAP) != 0)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
709 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
710 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
711 if (capflags != WF_ALLCAP) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
712 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
713 // When the character before the word is a word |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
714 // character we do not accept a Onecap word. We do |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
715 // accept a no-caps word, even when the dictionary |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
716 // word specifies ONECAP. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
717 MB_PTR_BACK(mip->mi_word, p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
718 if (spell_iswordp_nmw(p, mip->mi_win) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
719 ? capflags == WF_ONECAP |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
720 : (flags & WF_ONECAP) != 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
721 && capflags != WF_ONECAP) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
722 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
723 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
724 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
725 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
726 // If the word ends the sequence of compound flags of the |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
727 // words must match with one of the COMPOUNDRULE items and |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
728 // the number of syllables must not be too large. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
729 mip->mi_compflags[mip->mi_complen] = ((unsigned)flags >> 24); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
730 mip->mi_compflags[mip->mi_complen + 1] = NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
731 if (word_ends) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
732 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
733 char_u fword[MAXWLEN]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
734 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
735 if (slang->sl_compsylmax < MAXWLEN) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
736 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
737 // "fword" is only needed for checking syllables. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
738 if (ptr == mip->mi_word) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
739 (void)spell_casefold(mip->mi_win, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
740 ptr, wlen, fword, MAXWLEN); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
741 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
742 vim_strncpy(fword, ptr, endlen[endidxcnt]); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
743 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
744 if (!can_compound(slang, fword, mip->mi_compflags)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
745 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
746 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
747 else if (slang->sl_comprules != NULL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
748 && !match_compoundrule(slang, mip->mi_compflags)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
749 // The compound flags collected so far do not match any |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
750 // COMPOUNDRULE, discard the compounded word. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
751 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
752 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
753 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
754 // Check NEEDCOMPOUND: can't use word without compounding. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
755 else if (flags & WF_NEEDCOMP) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
756 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
757 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
758 nobreak_result = SP_OK; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
759 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
760 if (!word_ends) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
761 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
762 int save_result = mip->mi_result; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
763 char_u *save_end = mip->mi_end; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
764 langp_T *save_lp = mip->mi_lp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
765 int lpi; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
766 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
767 // Check that a valid word follows. If there is one and we |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
768 // are compounding, it will set "mi_result", thus we are |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
769 // always finished here. For NOBREAK we only check that a |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
770 // valid word follows. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
771 // Recursive! |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
772 if (slang->sl_nobreak) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
773 mip->mi_result = SP_BAD; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
774 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
775 // Find following word in case-folded tree. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
776 mip->mi_compoff = endlen[endidxcnt]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
777 if (has_mbyte && mode == FIND_KEEPWORD) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
778 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
779 // Compute byte length in case-folded word from "wlen": |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
780 // byte length in keep-case word. Length may change when |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
781 // folding case. This can be slow, take a shortcut when |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
782 // the case-folded word is equal to the keep-case word. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
783 p = mip->mi_fword; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
784 if (STRNCMP(ptr, p, wlen) != 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
785 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
786 for (s = ptr; s < ptr + wlen; MB_PTR_ADV(s)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
787 MB_PTR_ADV(p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
788 mip->mi_compoff = (int)(p - mip->mi_fword); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
789 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
790 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
791 #if 0 // Disabled, see below |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
792 c = mip->mi_compoff; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
793 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
794 ++mip->mi_complen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
795 if (flags & WF_COMPROOT) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
796 ++mip->mi_compextra; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
797 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
798 // For NOBREAK we need to try all NOBREAK languages, at least |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
799 // to find the ".add" file(s). |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
800 for (lpi = 0; lpi < mip->mi_win->w_s->b_langp.ga_len; ++lpi) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
801 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
802 if (slang->sl_nobreak) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
803 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
804 mip->mi_lp = LANGP_ENTRY(mip->mi_win->w_s->b_langp, lpi); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
805 if (mip->mi_lp->lp_slang->sl_fidxs == NULL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
806 || !mip->mi_lp->lp_slang->sl_nobreak) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
807 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
808 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
809 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
810 find_word(mip, FIND_COMPOUND); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
811 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
812 // When NOBREAK any word that matches is OK. Otherwise we |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
813 // need to find the longest match, thus try with keep-case |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
814 // and prefix too. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
815 if (!slang->sl_nobreak || mip->mi_result == SP_BAD) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
816 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
817 // Find following word in keep-case tree. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
818 mip->mi_compoff = wlen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
819 find_word(mip, FIND_KEEPCOMPOUND); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
820 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
821 #if 0 // Disabled, a prefix must not appear halfway a compound word, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
822 // unless the COMPOUNDPERMITFLAG is used and then it can't be a |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
823 // postponed prefix. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
824 if (!slang->sl_nobreak || mip->mi_result == SP_BAD) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
825 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
826 // Check for following word with prefix. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
827 mip->mi_compoff = c; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
828 find_prefix(mip, FIND_COMPOUND); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
829 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
830 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
831 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
832 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
833 if (!slang->sl_nobreak) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
834 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
835 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
836 --mip->mi_complen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
837 if (flags & WF_COMPROOT) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
838 --mip->mi_compextra; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
839 mip->mi_lp = save_lp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
840 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
841 if (slang->sl_nobreak) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
842 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
843 nobreak_result = mip->mi_result; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
844 mip->mi_result = save_result; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
845 mip->mi_end = save_end; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
846 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
847 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
848 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
849 if (mip->mi_result == SP_OK) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
850 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
851 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
852 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
853 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
854 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
855 if (flags & WF_BANNED) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
856 res = SP_BANNED; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
857 else if (flags & WF_REGION) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
858 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
859 // Check region. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
860 if ((mip->mi_lp->lp_region & (flags >> 16)) != 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
861 res = SP_OK; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
862 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
863 res = SP_LOCAL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
864 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
865 else if (flags & WF_RARE) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
866 res = SP_RARE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
867 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
868 res = SP_OK; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
869 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
870 // Always use the longest match and the best result. For NOBREAK |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
871 // we separately keep the longest match without a following good |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
872 // word as a fall-back. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
873 if (nobreak_result == SP_BAD) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
874 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
875 if (mip->mi_result2 > res) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
876 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
877 mip->mi_result2 = res; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
878 mip->mi_end2 = mip->mi_word + wlen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
879 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
880 else if (mip->mi_result2 == res |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
881 && mip->mi_end2 < mip->mi_word + wlen) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
882 mip->mi_end2 = mip->mi_word + wlen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
883 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
884 else if (mip->mi_result > res) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
885 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
886 mip->mi_result = res; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
887 mip->mi_end = mip->mi_word + wlen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
888 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
889 else if (mip->mi_result == res && mip->mi_end < mip->mi_word + wlen) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
890 mip->mi_end = mip->mi_word + wlen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
891 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
892 if (mip->mi_result == SP_OK) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
893 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
894 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
895 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
896 if (mip->mi_result == SP_OK) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
897 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
898 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
899 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
900 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
901 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
902 * Return TRUE if there is a match between the word ptr[wlen] and |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
903 * CHECKCOMPOUNDPATTERN rules, assuming that we will concatenate with another |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
904 * word. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
905 * A match means that the first part of CHECKCOMPOUNDPATTERN matches at the |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
906 * end of ptr[wlen] and the second part matches after it. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
907 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
908 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
909 match_checkcompoundpattern( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
910 char_u *ptr, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
911 int wlen, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
912 garray_T *gap) // &sl_comppat |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
913 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
914 int i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
915 char_u *p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
916 int len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
917 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
918 for (i = 0; i + 1 < gap->ga_len; i += 2) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
919 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
920 p = ((char_u **)gap->ga_data)[i + 1]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
921 if (STRNCMP(ptr + wlen, p, STRLEN(p)) == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
922 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
923 // Second part matches at start of following compound word, now |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
924 // check if first part matches at end of previous word. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
925 p = ((char_u **)gap->ga_data)[i]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
926 len = (int)STRLEN(p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
927 if (len <= wlen && STRNCMP(ptr + wlen - len, p, len) == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
928 return TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
929 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
930 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
931 return FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
932 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
933 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
934 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
935 * Return TRUE if "flags" is a valid sequence of compound flags and "word" |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
936 * does not have too many syllables. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
937 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
938 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
939 can_compound(slang_T *slang, char_u *word, char_u *flags) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
940 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
941 char_u uflags[MAXWLEN * 2]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
942 int i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
943 char_u *p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
944 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
945 if (slang->sl_compprog == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
946 return FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
947 if (enc_utf8) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
948 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
949 // Need to convert the single byte flags to utf8 characters. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
950 p = uflags; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
951 for (i = 0; flags[i] != NUL; ++i) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
952 p += utf_char2bytes(flags[i], p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
953 *p = NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
954 p = uflags; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
955 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
956 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
957 p = flags; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
958 if (!vim_regexec_prog(&slang->sl_compprog, FALSE, p, 0)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
959 return FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
960 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
961 // Count the number of syllables. This may be slow, do it last. If there |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
962 // are too many syllables AND the number of compound words is above |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
963 // COMPOUNDWORDMAX then compounding is not allowed. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
964 if (slang->sl_compsylmax < MAXWLEN |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
965 && count_syllables(slang, word) > slang->sl_compsylmax) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
966 return (int)STRLEN(flags) < slang->sl_compmax; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
967 return TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
968 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
969 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
970 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
971 * Return TRUE if the compound flags in compflags[] match the start of any |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
972 * compound rule. This is used to stop trying a compound if the flags |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
973 * collected so far can't possibly match any compound rule. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
974 * Caller must check that slang->sl_comprules is not NULL. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
975 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
976 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
977 match_compoundrule(slang_T *slang, char_u *compflags) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
978 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
979 char_u *p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
980 int i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
981 int c; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
982 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
983 // loop over all the COMPOUNDRULE entries |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
984 for (p = slang->sl_comprules; *p != NUL; ++p) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
985 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
986 // loop over the flags in the compound word we have made, match |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
987 // them against the current rule entry |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
988 for (i = 0; ; ++i) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
989 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
990 c = compflags[i]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
991 if (c == NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
992 // found a rule that matches for the flags we have so far |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
993 return TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
994 if (*p == '/' || *p == NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
995 break; // end of rule, it's too short |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
996 if (*p == '[') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
997 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
998 int match = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
999 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1000 // compare against all the flags in [] |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1001 ++p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1002 while (*p != ']' && *p != NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1003 if (*p++ == c) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1004 match = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1005 if (!match) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1006 break; // none matches |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1007 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1008 else if (*p != c) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1009 break; // flag of word doesn't match flag in pattern |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1010 ++p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1011 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1012 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1013 // Skip to the next "/", where the next pattern starts. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1014 p = vim_strchr(p, '/'); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1015 if (p == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1016 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1017 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1018 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1019 // Checked all the rules and none of them match the flags, so there |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1020 // can't possibly be a compound starting with these flags. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1021 return FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1022 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1023 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1024 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1025 * Return non-zero if the prefix indicated by "arridx" matches with the prefix |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1026 * ID in "flags" for the word "word". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1027 * The WF_RAREPFX flag is included in the return value for a rare prefix. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1028 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1029 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1030 valid_word_prefix( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1031 int totprefcnt, // nr of prefix IDs |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1032 int arridx, // idx in sl_pidxs[] |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1033 int flags, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1034 char_u *word, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1035 slang_T *slang, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1036 int cond_req) // only use prefixes with a condition |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1037 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1038 int prefcnt; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1039 int pidx; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1040 regprog_T **rp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1041 int prefid; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1042 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1043 prefid = (unsigned)flags >> 24; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1044 for (prefcnt = totprefcnt - 1; prefcnt >= 0; --prefcnt) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1045 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1046 pidx = slang->sl_pidxs[arridx + prefcnt]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1047 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1048 // Check the prefix ID. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1049 if (prefid != (pidx & 0xff)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1050 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1051 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1052 // Check if the prefix doesn't combine and the word already has a |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1053 // suffix. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1054 if ((flags & WF_HAS_AFF) && (pidx & WF_PFX_NC)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1055 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1056 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1057 // Check the condition, if there is one. The condition index is |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1058 // stored in the two bytes above the prefix ID byte. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1059 rp = &slang->sl_prefprog[((unsigned)pidx >> 8) & 0xffff]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1060 if (*rp != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1061 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1062 if (!vim_regexec_prog(rp, FALSE, word, 0)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1063 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1064 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1065 else if (cond_req) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1066 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1067 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1068 // It's a match! Return the WF_ flags. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1069 return pidx; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1070 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1071 return 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1072 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1073 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1074 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1075 * Check if the word at "mip->mi_word" has a matching prefix. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1076 * If it does, then check the following word. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1077 * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1078 * If "mode" is "FIND_COMPOUND" then do the same after another word, find a |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1079 * prefix in a compound word. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1080 * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1081 * For a match mip->mi_result is updated. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1082 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1083 static void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1084 find_prefix(matchinf_T *mip, int mode) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1085 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1086 idx_T arridx = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1087 int len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1088 int wlen = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1089 int flen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1090 int c; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1091 char_u *ptr; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1092 idx_T lo, hi, m; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1093 slang_T *slang = mip->mi_lp->lp_slang; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1094 char_u *byts; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1095 idx_T *idxs; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1096 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1097 byts = slang->sl_pbyts; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1098 if (byts == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1099 return; // array is empty |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1100 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1101 // We use the case-folded word here, since prefixes are always |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1102 // case-folded. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1103 ptr = mip->mi_fword; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1104 flen = mip->mi_fwordlen; // available case-folded bytes |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1105 if (mode == FIND_COMPOUND) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1106 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1107 // Skip over the previously found word(s). |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1108 ptr += mip->mi_compoff; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1109 flen -= mip->mi_compoff; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1110 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1111 idxs = slang->sl_pidxs; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1112 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1113 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1114 * Repeat advancing in the tree until: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1115 * - there is a byte that doesn't match, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1116 * - we reach the end of the tree, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1117 * - or we reach the end of the line. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1118 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1119 for (;;) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1120 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1121 if (flen == 0 && *mip->mi_fend != NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1122 flen = fold_more(mip); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1123 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1124 len = byts[arridx++]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1125 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1126 // If the first possible byte is a zero the prefix could end here. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1127 // Check if the following word matches and supports the prefix. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1128 if (byts[arridx] == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1129 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1130 // There can be several prefixes with different conditions. We |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1131 // try them all, since we don't know which one will give the |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1132 // longest match. The word is the same each time, pass the list |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1133 // of possible prefixes to find_word(). |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1134 mip->mi_prefarridx = arridx; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1135 mip->mi_prefcnt = len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1136 while (len > 0 && byts[arridx] == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1137 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1138 ++arridx; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1139 --len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1140 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1141 mip->mi_prefcnt -= len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1142 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1143 // Find the word that comes after the prefix. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1144 mip->mi_prefixlen = wlen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1145 if (mode == FIND_COMPOUND) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1146 // Skip over the previously found word(s). |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1147 mip->mi_prefixlen += mip->mi_compoff; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1148 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1149 if (has_mbyte) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1150 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1151 // Case-folded length may differ from original length. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1152 mip->mi_cprefixlen = nofold_len(mip->mi_fword, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1153 mip->mi_prefixlen, mip->mi_word); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1154 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1155 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1156 mip->mi_cprefixlen = mip->mi_prefixlen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1157 find_word(mip, FIND_PREFIX); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1158 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1159 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1160 if (len == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1161 break; // no children, word must end here |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1162 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1163 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1164 // Stop looking at end of the line. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1165 if (ptr[wlen] == NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1166 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1167 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1168 // Perform a binary search in the list of accepted bytes. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1169 c = ptr[wlen]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1170 lo = arridx; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1171 hi = arridx + len - 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1172 while (lo < hi) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1173 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1174 m = (lo + hi) / 2; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1175 if (byts[m] > c) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1176 hi = m - 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1177 else if (byts[m] < c) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1178 lo = m + 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1179 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1180 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1181 lo = hi = m; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1182 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1183 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1184 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1185 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1186 // Stop if there is no matching byte. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1187 if (hi < lo || byts[lo] != c) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1188 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1189 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1190 // Continue at the child (if there is one). |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1191 arridx = idxs[lo]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1192 ++wlen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1193 --flen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1194 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1195 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1196 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1197 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1198 * Need to fold at least one more character. Do until next non-word character |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1199 * for efficiency. Include the non-word character too. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1200 * Return the length of the folded chars in bytes. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1201 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1202 static int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1203 fold_more(matchinf_T *mip) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1204 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1205 int flen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1206 char_u *p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1207 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1208 p = mip->mi_fend; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1209 do |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1210 MB_PTR_ADV(mip->mi_fend); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1211 while (*mip->mi_fend != NUL && spell_iswordp(mip->mi_fend, mip->mi_win)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1212 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1213 // Include the non-word character so that we can check for the word end. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1214 if (*mip->mi_fend != NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1215 MB_PTR_ADV(mip->mi_fend); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1216 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1217 (void)spell_casefold(mip->mi_win, p, (int)(mip->mi_fend - p), |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1218 mip->mi_fword + mip->mi_fwordlen, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1219 MAXWLEN - mip->mi_fwordlen); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1220 flen = (int)STRLEN(mip->mi_fword + mip->mi_fwordlen); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1221 mip->mi_fwordlen += flen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1222 return flen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1223 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1224 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1225 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1226 * Check case flags for a word. Return TRUE if the word has the requested |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1227 * case. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1228 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1229 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1230 spell_valid_case( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1231 int wordflags, // flags for the checked word. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1232 int treeflags) // flags for the word in the spell tree |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1233 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1234 return ((wordflags == WF_ALLCAP && (treeflags & WF_FIXCAP) == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1235 || ((treeflags & (WF_ALLCAP | WF_KEEPCAP)) == 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1236 && ((treeflags & WF_ONECAP) == 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1237 || (wordflags & WF_ONECAP) != 0))); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1238 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1239 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1240 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1241 * Return TRUE if spell checking is enabled for "wp". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1242 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1243 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1244 spell_check_window(win_T *wp) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1245 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1246 return wp->w_p_spell |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1247 && *wp->w_s->b_p_spl != NUL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1248 && wp->w_s->b_langp.ga_len > 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1249 && *(char **)(wp->w_s->b_langp.ga_data) != NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1250 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1251 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1252 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1253 * Return TRUE and give an error if spell checking is not enabled. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1254 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1255 static int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1256 no_spell_checking(win_T *wp) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1257 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1258 if (spell_check_window(wp)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1259 return FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1260 emsg(_(e_spell_checking_is_not_possible)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1261 return TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1262 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1263 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1264 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1265 * Move to next spell error. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1266 * "curline" is FALSE for "[s", "]s", "[S" and "]S". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1267 * "curline" is TRUE to find word under/after cursor in the same line. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1268 * For Insert mode completion "dir" is BACKWARD and "curline" is TRUE: move |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1269 * to after badly spelled word before the cursor. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1270 * Return 0 if not found, length of the badly spelled word otherwise. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1271 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1272 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1273 spell_move_to( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1274 win_T *wp, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1275 int dir, // FORWARD or BACKWARD |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1276 int allwords, // TRUE for "[s"/"]s", FALSE for "[S"/"]S" |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1277 int curline, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1278 hlf_T *attrp) // return: attributes of bad word or NULL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1279 // (only when "dir" is FORWARD) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1280 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1281 linenr_T lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1282 pos_T found_pos; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1283 int found_len = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1284 char_u *line; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1285 char_u *p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1286 char_u *endp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1287 hlf_T attr = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1288 int len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1289 #ifdef FEAT_SYN_HL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1290 int has_syntax = syntax_present(wp); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1291 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1292 int col; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1293 int can_spell; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1294 char_u *buf = NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1295 int buflen = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1296 int skip = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1297 int capcol = -1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1298 int found_one = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1299 int wrapped = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1300 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1301 if (no_spell_checking(wp)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1302 return 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1303 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1304 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1305 * Start looking for bad word at the start of the line, because we can't |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1306 * start halfway a word, we don't know where it starts or ends. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1307 * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1308 * When searching backwards, we continue in the line to find the last |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1309 * bad word (in the cursor line: before the cursor). |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1310 * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1311 * We concatenate the start of the next line, so that wrapped words work |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1312 * (e.g. "et<line-break>cetera"). Doesn't work when searching backwards |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1313 * though... |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1314 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1315 lnum = wp->w_cursor.lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1316 CLEAR_POS(&found_pos); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1317 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1318 while (!got_int) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1319 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1320 int empty_line; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1321 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1322 line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1323 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1324 len = (int)STRLEN(line); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1325 if (buflen < len + MAXWLEN + 2) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1326 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1327 vim_free(buf); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1328 buflen = len + MAXWLEN + 2; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1329 buf = alloc(buflen); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1330 if (buf == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1331 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1332 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1333 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1334 // In first line check first word for Capital. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1335 if (lnum == 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1336 capcol = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1337 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1338 // For checking first word with a capital skip white space. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1339 if (capcol == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1340 capcol = getwhitecols(line); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1341 else if (curline && wp == curwin) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1342 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1343 // For spellbadword(): check if first word needs a capital. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1344 col = getwhitecols(line); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1345 if (check_need_cap(curwin, lnum, col)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1346 capcol = col; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1347 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1348 // Need to get the line again, may have looked at the previous |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1349 // one. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1350 line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1351 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1352 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1353 // Copy the line into "buf" and append the start of the next line if |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1354 // possible. Note: this ml_get_buf() may make "line" invalid, check |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1355 // for empty line first. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1356 empty_line = *skipwhite(line) == NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1357 STRCPY(buf, line); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1358 if (lnum < wp->w_buffer->b_ml.ml_line_count) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1359 spell_cat_line(buf + STRLEN(buf), |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1360 ml_get_buf(wp->w_buffer, lnum + 1, FALSE), MAXWLEN); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1361 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1362 p = buf + skip; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1363 endp = buf + len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1364 while (p < endp) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1365 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1366 // When searching backward don't search after the cursor. Unless |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1367 // we wrapped around the end of the buffer. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1368 if (dir == BACKWARD |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1369 && lnum == wp->w_cursor.lnum |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1370 && !wrapped |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1371 && (colnr_T)(p - buf) >= wp->w_cursor.col) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1372 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1373 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1374 // start of word |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1375 attr = HLF_COUNT; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1376 len = spell_check(wp, p, &attr, &capcol, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1377 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1378 if (attr != HLF_COUNT) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1379 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1380 // We found a bad word. Check the attribute. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1381 if (allwords || attr == HLF_SPB) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1382 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1383 // When searching forward only accept a bad word after |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1384 // the cursor. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1385 if (dir == BACKWARD |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1386 || lnum != wp->w_cursor.lnum |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1387 || (wrapped |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1388 || (colnr_T)(curline ? p - buf + len |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1389 : p - buf) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1390 > wp->w_cursor.col)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1391 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1392 #ifdef FEAT_SYN_HL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1393 if (has_syntax) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1394 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1395 col = (int)(p - buf); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1396 (void)syn_get_id(wp, lnum, (colnr_T)col, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1397 FALSE, &can_spell, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1398 if (!can_spell) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1399 attr = HLF_COUNT; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1400 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1401 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1402 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1403 can_spell = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1404 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1405 if (can_spell) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1406 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1407 found_one = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1408 found_pos.lnum = lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1409 found_pos.col = (int)(p - buf); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1410 found_pos.coladd = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1411 if (dir == FORWARD) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1412 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1413 // No need to search further. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1414 wp->w_cursor = found_pos; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1415 vim_free(buf); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1416 if (attrp != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1417 *attrp = attr; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1418 return len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1419 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1420 else if (curline) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1421 // Insert mode completion: put cursor after |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1422 // the bad word. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1423 found_pos.col += len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1424 found_len = len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1425 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1426 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1427 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1428 found_one = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1429 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1430 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1431 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1432 // advance to character after the word |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1433 p += len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1434 capcol -= len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1435 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1436 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1437 if (dir == BACKWARD && found_pos.lnum != 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1438 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1439 // Use the last match in the line (before the cursor). |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1440 wp->w_cursor = found_pos; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1441 vim_free(buf); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1442 return found_len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1443 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1444 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1445 if (curline) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1446 break; // only check cursor line |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1447 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1448 // If we are back at the starting line and searched it again there |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1449 // is no match, give up. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1450 if (lnum == wp->w_cursor.lnum && wrapped) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1451 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1452 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1453 // Advance to next line. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1454 if (dir == BACKWARD) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1455 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1456 if (lnum > 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1457 --lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1458 else if (!p_ws) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1459 break; // at first line and 'nowrapscan' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1460 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1461 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1462 // Wrap around to the end of the buffer. May search the |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1463 // starting line again and accept the last match. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1464 lnum = wp->w_buffer->b_ml.ml_line_count; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1465 wrapped = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1466 if (!shortmess(SHM_SEARCH)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1467 give_warning((char_u *)_(top_bot_msg), TRUE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1468 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1469 capcol = -1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1470 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1471 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1472 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1473 if (lnum < wp->w_buffer->b_ml.ml_line_count) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1474 ++lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1475 else if (!p_ws) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1476 break; // at first line and 'nowrapscan' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1477 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1478 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1479 // Wrap around to the start of the buffer. May search the |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1480 // starting line again and accept the first match. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1481 lnum = 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1482 wrapped = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1483 if (!shortmess(SHM_SEARCH)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1484 give_warning((char_u *)_(bot_top_msg), TRUE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1485 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1486 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1487 // If we are back at the starting line and there is no match then |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1488 // give up. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1489 if (lnum == wp->w_cursor.lnum && !found_one) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1490 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1491 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1492 // Skip the characters at the start of the next line that were |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1493 // included in a match crossing line boundaries. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1494 if (attr == HLF_COUNT) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1495 skip = (int)(p - endp); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1496 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1497 skip = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1498 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1499 // Capcol skips over the inserted space. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1500 --capcol; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1501 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1502 // But after empty line check first word in next line |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1503 if (empty_line) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1504 capcol = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1505 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1506 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1507 line_breakcheck(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1508 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1509 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1510 vim_free(buf); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1511 return 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1512 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1513 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1514 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1515 * For spell checking: concatenate the start of the following line "line" into |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1516 * "buf", blanking-out special characters. Copy less than "maxlen" bytes. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1517 * Keep the blanks at the start of the next line, this is used in win_line() |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1518 * to skip those bytes if the word was OK. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1519 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1520 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1521 spell_cat_line(char_u *buf, char_u *line, int maxlen) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1522 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1523 char_u *p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1524 int n; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1525 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1526 p = skipwhite(line); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1527 while (vim_strchr((char_u *)"*#/\"\t", *p) != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1528 p = skipwhite(p + 1); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1529 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1530 if (*p == NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1531 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1532 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1533 // Only worth concatenating if there is something else than spaces to |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1534 // concatenate. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1535 n = (int)(p - line) + 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1536 if (n < maxlen - 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1537 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1538 vim_memset(buf, ' ', n); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1539 vim_strncpy(buf + n, p, maxlen - 1 - n); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1540 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1541 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1542 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1543 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1544 * Structure used for the cookie argument of do_in_runtimepath(). |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1545 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1546 typedef struct spelload_S |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1547 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1548 char_u sl_lang[MAXWLEN + 1]; // language name |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1549 slang_T *sl_slang; // resulting slang_T struct |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1550 int sl_nobreak; // NOBREAK language found |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1551 } spelload_T; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1552 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1553 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1554 * Load word list(s) for "lang" from Vim spell file(s). |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1555 * "lang" must be the language without the region: e.g., "en". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1556 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1557 static void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1558 spell_load_lang(char_u *lang) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1559 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1560 char_u fname_enc[85]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1561 int r; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1562 spelload_T sl; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1563 int round; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1564 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1565 // Copy the language name to pass it to spell_load_cb() as a cookie. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1566 // It's truncated when an error is detected. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1567 STRCPY(sl.sl_lang, lang); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1568 sl.sl_slang = NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1569 sl.sl_nobreak = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1570 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1571 // Disallow deleting the current buffer. Autocommands can do weird things |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1572 // and cause "lang" to be freed. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1573 ++curbuf->b_locked; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1574 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1575 // We may retry when no spell file is found for the language, an |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1576 // autocommand may load it then. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1577 for (round = 1; round <= 2; ++round) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1578 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1579 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1580 * Find the first spell file for "lang" in 'runtimepath' and load it. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1581 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1582 vim_snprintf((char *)fname_enc, sizeof(fname_enc) - 5, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1583 #ifdef VMS |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1584 "spell/%s_%s.spl", |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1585 #else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1586 "spell/%s.%s.spl", |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1587 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1588 lang, spell_enc()); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1589 r = do_in_runtimepath(fname_enc, 0, spell_load_cb, &sl); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1590 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1591 if (r == FAIL && *sl.sl_lang != NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1592 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1593 // Try loading the ASCII version. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1594 vim_snprintf((char *)fname_enc, sizeof(fname_enc) - 5, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1595 #ifdef VMS |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1596 "spell/%s_ascii.spl", |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1597 #else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1598 "spell/%s.ascii.spl", |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1599 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1600 lang); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1601 r = do_in_runtimepath(fname_enc, 0, spell_load_cb, &sl); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1602 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1603 if (r == FAIL && *sl.sl_lang != NUL && round == 1 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1604 && apply_autocmds(EVENT_SPELLFILEMISSING, lang, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1605 curbuf->b_fname, FALSE, curbuf)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1606 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1607 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1608 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1609 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1610 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1611 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1612 if (r == FAIL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1613 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1614 smsg( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1615 #ifdef VMS |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1616 _("Warning: Cannot find word list \"%s_%s.spl\" or \"%s_ascii.spl\""), |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1617 #else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1618 _("Warning: Cannot find word list \"%s.%s.spl\" or \"%s.ascii.spl\""), |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1619 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1620 lang, spell_enc(), lang); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1621 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1622 else if (sl.sl_slang != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1623 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1624 // At least one file was loaded, now load ALL the additions. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1625 STRCPY(fname_enc + STRLEN(fname_enc) - 3, "add.spl"); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1626 do_in_runtimepath(fname_enc, DIP_ALL, spell_load_cb, &sl); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1627 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1628 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1629 --curbuf->b_locked; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1630 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1631 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1632 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1633 * Return the encoding used for spell checking: Use 'encoding', except that we |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1634 * use "latin1" for "latin9". And limit to 60 characters (just in case). |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1635 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1636 char_u * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1637 spell_enc(void) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1638 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1639 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1640 if (STRLEN(p_enc) < 60 && STRCMP(p_enc, "iso-8859-15") != 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1641 return p_enc; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1642 return (char_u *)"latin1"; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1643 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1644 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1645 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1646 * Get the name of the .spl file for the internal wordlist into |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1647 * "fname[MAXPATHL]". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1648 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1649 static void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1650 int_wordlist_spl(char_u *fname) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1651 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1652 vim_snprintf((char *)fname, MAXPATHL, SPL_FNAME_TMPL, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1653 int_wordlist, spell_enc()); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1654 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1655 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1656 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1657 * Allocate a new slang_T for language "lang". "lang" can be NULL. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1658 * Caller must fill "sl_next". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1659 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1660 slang_T * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1661 slang_alloc(char_u *lang) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1662 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1663 slang_T *lp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1664 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1665 lp = ALLOC_CLEAR_ONE(slang_T); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1666 if (lp != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1667 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1668 if (lang != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1669 lp->sl_name = vim_strsave(lang); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1670 ga_init2(&lp->sl_rep, sizeof(fromto_T), 10); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1671 ga_init2(&lp->sl_repsal, sizeof(fromto_T), 10); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1672 lp->sl_compmax = MAXWLEN; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1673 lp->sl_compsylmax = MAXWLEN; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1674 hash_init(&lp->sl_wordcount); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1675 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1676 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1677 return lp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1678 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1679 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1680 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1681 * Free the contents of an slang_T and the structure itself. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1682 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1683 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1684 slang_free(slang_T *lp) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1685 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1686 vim_free(lp->sl_name); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1687 vim_free(lp->sl_fname); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1688 slang_clear(lp); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1689 vim_free(lp); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1690 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1691 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1692 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1693 * Clear an slang_T so that the file can be reloaded. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1694 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1695 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1696 slang_clear(slang_T *lp) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1697 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1698 garray_T *gap; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1699 fromto_T *ftp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1700 salitem_T *smp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1701 int i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1702 int round; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1703 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1704 VIM_CLEAR(lp->sl_fbyts); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1705 VIM_CLEAR(lp->sl_kbyts); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1706 VIM_CLEAR(lp->sl_pbyts); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1707 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1708 VIM_CLEAR(lp->sl_fidxs); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1709 VIM_CLEAR(lp->sl_kidxs); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1710 VIM_CLEAR(lp->sl_pidxs); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1711 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1712 for (round = 1; round <= 2; ++round) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1713 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1714 gap = round == 1 ? &lp->sl_rep : &lp->sl_repsal; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1715 while (gap->ga_len > 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1716 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1717 ftp = &((fromto_T *)gap->ga_data)[--gap->ga_len]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1718 vim_free(ftp->ft_from); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1719 vim_free(ftp->ft_to); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1720 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1721 ga_clear(gap); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1722 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1723 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1724 gap = &lp->sl_sal; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1725 if (lp->sl_sofo) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1726 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1727 // "ga_len" is set to 1 without adding an item for latin1 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1728 if (gap->ga_data != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1729 // SOFOFROM and SOFOTO items: free lists of wide characters. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1730 for (i = 0; i < gap->ga_len; ++i) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1731 vim_free(((int **)gap->ga_data)[i]); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1732 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1733 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1734 // SAL items: free salitem_T items |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1735 while (gap->ga_len > 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1736 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1737 smp = &((salitem_T *)gap->ga_data)[--gap->ga_len]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1738 vim_free(smp->sm_lead); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1739 // Don't free sm_oneof and sm_rules, they point into sm_lead. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1740 vim_free(smp->sm_to); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1741 vim_free(smp->sm_lead_w); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1742 vim_free(smp->sm_oneof_w); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1743 vim_free(smp->sm_to_w); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1744 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1745 ga_clear(gap); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1746 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1747 for (i = 0; i < lp->sl_prefixcnt; ++i) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1748 vim_regfree(lp->sl_prefprog[i]); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1749 lp->sl_prefixcnt = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1750 VIM_CLEAR(lp->sl_prefprog); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1751 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1752 VIM_CLEAR(lp->sl_info); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1753 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1754 VIM_CLEAR(lp->sl_midword); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1755 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1756 vim_regfree(lp->sl_compprog); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1757 lp->sl_compprog = NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1758 VIM_CLEAR(lp->sl_comprules); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1759 VIM_CLEAR(lp->sl_compstartflags); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1760 VIM_CLEAR(lp->sl_compallflags); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1761 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1762 VIM_CLEAR(lp->sl_syllable); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1763 ga_clear(&lp->sl_syl_items); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1764 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1765 ga_clear_strings(&lp->sl_comppat); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1766 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1767 hash_clear_all(&lp->sl_wordcount, WC_KEY_OFF); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1768 hash_init(&lp->sl_wordcount); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1769 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1770 hash_clear_all(&lp->sl_map_hash, 0); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1771 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1772 // Clear info from .sug file. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1773 slang_clear_sug(lp); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1774 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1775 lp->sl_compmax = MAXWLEN; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1776 lp->sl_compminlen = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1777 lp->sl_compsylmax = MAXWLEN; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1778 lp->sl_regions[0] = NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1779 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1780 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1781 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1782 * Clear the info from the .sug file in "lp". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1783 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1784 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1785 slang_clear_sug(slang_T *lp) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1786 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1787 VIM_CLEAR(lp->sl_sbyts); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1788 VIM_CLEAR(lp->sl_sidxs); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1789 close_spellbuf(lp->sl_sugbuf); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1790 lp->sl_sugbuf = NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1791 lp->sl_sugloaded = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1792 lp->sl_sugtime = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1793 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1794 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1795 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1796 * Load one spell file and store the info into a slang_T. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1797 * Invoked through do_in_runtimepath(). |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1798 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1799 static void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1800 spell_load_cb(char_u *fname, void *cookie) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1801 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1802 spelload_T *slp = (spelload_T *)cookie; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1803 slang_T *slang; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1804 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1805 slang = spell_load_file(fname, slp->sl_lang, NULL, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1806 if (slang == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1807 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1808 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1809 // When a previously loaded file has NOBREAK also use it for the |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1810 // ".add" files. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1811 if (slp->sl_nobreak && slang->sl_add) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1812 slang->sl_nobreak = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1813 else if (slang->sl_nobreak) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1814 slp->sl_nobreak = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1815 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1816 slp->sl_slang = slang; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1817 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1818 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1819 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1820 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1821 * Add a word to the hashtable of common words. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1822 * If it's already there then the counter is increased. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1823 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1824 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1825 count_common_word( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1826 slang_T *lp, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1827 char_u *word, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1828 int len, // word length, -1 for up to NUL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1829 int count) // 1 to count once, 10 to init |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1830 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1831 hash_T hash; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1832 hashitem_T *hi; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1833 wordcount_T *wc; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1834 char_u buf[MAXWLEN]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1835 char_u *p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1836 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1837 if (len == -1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1838 p = word; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1839 else if (len >= MAXWLEN) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1840 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1841 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1842 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1843 vim_strncpy(buf, word, len); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1844 p = buf; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1845 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1846 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1847 hash = hash_hash(p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1848 hi = hash_lookup(&lp->sl_wordcount, p, hash); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1849 if (HASHITEM_EMPTY(hi)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1850 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1851 wc = alloc(offsetof(wordcount_T, wc_word) + STRLEN(p) + 1); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1852 if (wc == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1853 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1854 STRCPY(wc->wc_word, p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1855 wc->wc_count = count; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1856 hash_add_item(&lp->sl_wordcount, hi, wc->wc_word, hash); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1857 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1858 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1859 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1860 wc = HI2WC(hi); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1861 if ((wc->wc_count += count) < (unsigned)count) // check for overflow |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1862 wc->wc_count = MAXWORDCOUNT; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1863 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1864 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1865 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1866 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1867 * Return TRUE if byte "n" appears in "str". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1868 * Like strchr() but independent of locale. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1869 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1870 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1871 byte_in_str(char_u *str, int n) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1872 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1873 char_u *p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1874 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1875 for (p = str; *p != NUL; ++p) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1876 if (*p == n) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1877 return TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1878 return FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1879 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1880 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1881 #define SY_MAXLEN 30 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1882 typedef struct syl_item_S |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1883 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1884 char_u sy_chars[SY_MAXLEN]; // the sequence of chars |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1885 int sy_len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1886 } syl_item_T; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1887 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1888 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1889 * Truncate "slang->sl_syllable" at the first slash and put the following items |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1890 * in "slang->sl_syl_items". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1891 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1892 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1893 init_syl_tab(slang_T *slang) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1894 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1895 char_u *p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1896 char_u *s; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1897 int l; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1898 syl_item_T *syl; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1899 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1900 ga_init2(&slang->sl_syl_items, sizeof(syl_item_T), 4); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1901 p = vim_strchr(slang->sl_syllable, '/'); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1902 while (p != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1903 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1904 *p++ = NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1905 if (*p == NUL) // trailing slash |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1906 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1907 s = p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1908 p = vim_strchr(p, '/'); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1909 if (p == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1910 l = (int)STRLEN(s); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1911 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1912 l = (int)(p - s); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1913 if (l >= SY_MAXLEN) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1914 return SP_FORMERROR; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1915 if (ga_grow(&slang->sl_syl_items, 1) == FAIL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1916 return SP_OTHERERROR; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1917 syl = ((syl_item_T *)slang->sl_syl_items.ga_data) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1918 + slang->sl_syl_items.ga_len++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1919 vim_strncpy(syl->sy_chars, s, l); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1920 syl->sy_len = l; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1921 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1922 return OK; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1923 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1924 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1925 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1926 * Count the number of syllables in "word". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1927 * When "word" contains spaces the syllables after the last space are counted. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1928 * Returns zero if syllables are not defines. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1929 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1930 static int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1931 count_syllables(slang_T *slang, char_u *word) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1932 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1933 int cnt = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1934 int skip = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1935 char_u *p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1936 int len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1937 int i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1938 syl_item_T *syl; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1939 int c; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1940 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1941 if (slang->sl_syllable == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1942 return 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1943 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1944 for (p = word; *p != NUL; p += len) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1945 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1946 // When running into a space reset counter. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1947 if (*p == ' ') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1948 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1949 len = 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1950 cnt = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1951 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1952 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1953 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1954 // Find longest match of syllable items. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1955 len = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1956 for (i = 0; i < slang->sl_syl_items.ga_len; ++i) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1957 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1958 syl = ((syl_item_T *)slang->sl_syl_items.ga_data) + i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1959 if (syl->sy_len > len |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1960 && STRNCMP(p, syl->sy_chars, syl->sy_len) == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1961 len = syl->sy_len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1962 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1963 if (len != 0) // found a match, count syllable |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1964 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1965 ++cnt; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1966 skip = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1967 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1968 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1969 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1970 // No recognized syllable item, at least a syllable char then? |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1971 c = mb_ptr2char(p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1972 len = (*mb_ptr2len)(p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1973 if (vim_strchr(slang->sl_syllable, c) == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1974 skip = FALSE; // No, search for next syllable |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1975 else if (!skip) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1976 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1977 ++cnt; // Yes, count it |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1978 skip = TRUE; // don't count following syllable chars |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1979 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1980 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1981 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1982 return cnt; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1983 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1984 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1985 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1986 * Parse 'spelllang' and set w_s->b_langp accordingly. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1987 * Returns NULL if it's OK, an untranslated error message otherwise. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1988 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1989 char * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1990 parse_spelllang(win_T *wp) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1991 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1992 garray_T ga; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1993 char_u *splp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1994 char_u *region; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1995 char_u region_cp[3]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1996 int filename; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1997 int region_mask; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1998 slang_T *slang; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
1999 int c; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2000 char_u lang[MAXWLEN + 1]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2001 char_u spf_name[MAXPATHL]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2002 int len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2003 char_u *p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2004 int round; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2005 char_u *spf; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2006 char_u *use_region = NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2007 int dont_use_region = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2008 int nobreak = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2009 int i, j; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2010 langp_T *lp, *lp2; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2011 static int recursive = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2012 char *ret_msg = NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2013 char_u *spl_copy; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2014 bufref_T bufref; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2015 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2016 set_bufref(&bufref, wp->w_buffer); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2017 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2018 // We don't want to do this recursively. May happen when a language is |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2019 // not available and the SpellFileMissing autocommand opens a new buffer |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2020 // in which 'spell' is set. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2021 if (recursive) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2022 return NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2023 recursive = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2024 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2025 ga_init2(&ga, sizeof(langp_T), 2); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2026 clear_midword(wp); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2027 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2028 // Make a copy of 'spelllang', the SpellFileMissing autocommands may change |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2029 // it under our fingers. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2030 spl_copy = vim_strsave(wp->w_s->b_p_spl); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2031 if (spl_copy == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2032 goto theend; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2033 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2034 wp->w_s->b_cjk = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2035 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2036 // Loop over comma separated language names. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2037 for (splp = spl_copy; *splp != NUL; ) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2038 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2039 // Get one language name. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2040 copy_option_part(&splp, lang, MAXWLEN, ","); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2041 region = NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2042 len = (int)STRLEN(lang); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2043 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2044 if (!valid_spelllang(lang)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2045 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2046 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2047 if (STRCMP(lang, "cjk") == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2048 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2049 wp->w_s->b_cjk = 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2050 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2051 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2052 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2053 // If the name ends in ".spl" use it as the name of the spell file. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2054 // If there is a region name let "region" point to it and remove it |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2055 // from the name. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2056 if (len > 4 && fnamecmp(lang + len - 4, ".spl") == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2057 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2058 filename = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2059 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2060 // Locate a region and remove it from the file name. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2061 p = vim_strchr(gettail(lang), '_'); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2062 if (p != NULL && ASCII_ISALPHA(p[1]) && ASCII_ISALPHA(p[2]) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2063 && !ASCII_ISALPHA(p[3])) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2064 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2065 vim_strncpy(region_cp, p + 1, 2); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2066 mch_memmove(p, p + 3, len - (p - lang) - 2); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2067 region = region_cp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2068 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2069 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2070 dont_use_region = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2071 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2072 // Check if we loaded this language before. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2073 FOR_ALL_SPELL_LANGS(slang) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2074 if (fullpathcmp(lang, slang->sl_fname, FALSE, TRUE) == FPC_SAME) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2075 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2076 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2077 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2078 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2079 filename = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2080 if (len > 3 && lang[len - 3] == '_') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2081 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2082 region = lang + len - 2; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2083 len -= 3; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2084 lang[len] = NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2085 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2086 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2087 dont_use_region = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2088 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2089 // Check if we loaded this language before. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2090 FOR_ALL_SPELL_LANGS(slang) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2091 if (STRICMP(lang, slang->sl_name) == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2092 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2093 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2094 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2095 if (region != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2096 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2097 // If the region differs from what was used before then don't |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2098 // use it for 'spellfile'. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2099 if (use_region != NULL && STRCMP(region, use_region) != 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2100 dont_use_region = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2101 use_region = region; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2102 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2103 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2104 // If not found try loading the language now. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2105 if (slang == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2106 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2107 if (filename) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2108 (void)spell_load_file(lang, lang, NULL, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2109 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2110 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2111 spell_load_lang(lang); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2112 // SpellFileMissing autocommands may do anything, including |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2113 // destroying the buffer we are using or closing the window. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2114 if (!bufref_valid(&bufref) || !win_valid_any_tab(wp)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2115 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2116 ret_msg = N_(e_spellfilemising_autocommand_deleted_buffer); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2117 goto theend; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2118 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2119 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2120 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2121 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2122 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2123 * Loop over the languages, there can be several files for "lang". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2124 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2125 FOR_ALL_SPELL_LANGS(slang) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2126 if (filename ? fullpathcmp(lang, slang->sl_fname, FALSE, TRUE) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2127 == FPC_SAME |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2128 : STRICMP(lang, slang->sl_name) == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2129 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2130 region_mask = REGION_ALL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2131 if (!filename && region != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2132 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2133 // find region in sl_regions |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2134 c = find_region(slang->sl_regions, region); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2135 if (c == REGION_ALL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2136 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2137 if (slang->sl_add) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2138 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2139 if (*slang->sl_regions != NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2140 // This addition file is for other regions. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2141 region_mask = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2142 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2143 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2144 // This is probably an error. Give a warning and |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2145 // accept the words anyway. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2146 smsg(_("Warning: region %s not supported"), |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2147 region); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2148 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2149 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2150 region_mask = 1 << c; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2151 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2152 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2153 if (region_mask != 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2154 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2155 if (ga_grow(&ga, 1) == FAIL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2156 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2157 ga_clear(&ga); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2158 ret_msg = e_out_of_memory; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2159 goto theend; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2160 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2161 LANGP_ENTRY(ga, ga.ga_len)->lp_slang = slang; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2162 LANGP_ENTRY(ga, ga.ga_len)->lp_region = region_mask; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2163 ++ga.ga_len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2164 use_midword(slang, wp); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2165 if (slang->sl_nobreak) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2166 nobreak = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2167 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2168 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2169 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2170 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2171 // round 0: load int_wordlist, if possible. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2172 // round 1: load first name in 'spellfile'. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2173 // round 2: load second name in 'spellfile. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2174 // etc. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2175 spf = curwin->w_s->b_p_spf; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2176 for (round = 0; round == 0 || *spf != NUL; ++round) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2177 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2178 if (round == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2179 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2180 // Internal wordlist, if there is one. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2181 if (int_wordlist == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2182 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2183 int_wordlist_spl(spf_name); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2184 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2185 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2186 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2187 // One entry in 'spellfile'. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2188 copy_option_part(&spf, spf_name, MAXPATHL - 5, ","); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2189 STRCAT(spf_name, ".spl"); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2190 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2191 // If it was already found above then skip it. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2192 for (c = 0; c < ga.ga_len; ++c) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2193 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2194 p = LANGP_ENTRY(ga, c)->lp_slang->sl_fname; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2195 if (p != NULL && fullpathcmp(spf_name, p, FALSE, TRUE) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2196 == FPC_SAME) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2197 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2198 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2199 if (c < ga.ga_len) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2200 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2201 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2202 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2203 // Check if it was loaded already. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2204 FOR_ALL_SPELL_LANGS(slang) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2205 if (fullpathcmp(spf_name, slang->sl_fname, FALSE, TRUE) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2206 == FPC_SAME) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2207 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2208 if (slang == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2209 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2210 // Not loaded, try loading it now. The language name includes the |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2211 // region name, the region is ignored otherwise. for int_wordlist |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2212 // use an arbitrary name. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2213 if (round == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2214 STRCPY(lang, "internal wordlist"); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2215 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2216 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2217 vim_strncpy(lang, gettail(spf_name), MAXWLEN); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2218 p = vim_strchr(lang, '.'); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2219 if (p != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2220 *p = NUL; // truncate at ".encoding.add" |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2221 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2222 slang = spell_load_file(spf_name, lang, NULL, TRUE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2223 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2224 // If one of the languages has NOBREAK we assume the addition |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2225 // files also have this. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2226 if (slang != NULL && nobreak) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2227 slang->sl_nobreak = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2228 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2229 if (slang != NULL && ga_grow(&ga, 1) == OK) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2230 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2231 region_mask = REGION_ALL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2232 if (use_region != NULL && !dont_use_region) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2233 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2234 // find region in sl_regions |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2235 c = find_region(slang->sl_regions, use_region); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2236 if (c != REGION_ALL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2237 region_mask = 1 << c; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2238 else if (*slang->sl_regions != NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2239 // This spell file is for other regions. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2240 region_mask = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2241 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2242 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2243 if (region_mask != 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2244 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2245 LANGP_ENTRY(ga, ga.ga_len)->lp_slang = slang; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2246 LANGP_ENTRY(ga, ga.ga_len)->lp_sallang = NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2247 LANGP_ENTRY(ga, ga.ga_len)->lp_replang = NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2248 LANGP_ENTRY(ga, ga.ga_len)->lp_region = region_mask; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2249 ++ga.ga_len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2250 use_midword(slang, wp); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2251 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2252 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2253 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2254 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2255 // Everything is fine, store the new b_langp value. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2256 ga_clear(&wp->w_s->b_langp); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2257 wp->w_s->b_langp = ga; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2258 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2259 // For each language figure out what language to use for sound folding and |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2260 // REP items. If the language doesn't support it itself use another one |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2261 // with the same name. E.g. for "en-math" use "en". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2262 for (i = 0; i < ga.ga_len; ++i) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2263 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2264 lp = LANGP_ENTRY(ga, i); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2265 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2266 // sound folding |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2267 if (lp->lp_slang->sl_sal.ga_len > 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2268 // language does sound folding itself |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2269 lp->lp_sallang = lp->lp_slang; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2270 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2271 // find first similar language that does sound folding |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2272 for (j = 0; j < ga.ga_len; ++j) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2273 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2274 lp2 = LANGP_ENTRY(ga, j); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2275 if (lp2->lp_slang->sl_sal.ga_len > 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2276 && STRNCMP(lp->lp_slang->sl_name, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2277 lp2->lp_slang->sl_name, 2) == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2278 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2279 lp->lp_sallang = lp2->lp_slang; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2280 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2281 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2282 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2283 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2284 // REP items |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2285 if (lp->lp_slang->sl_rep.ga_len > 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2286 // language has REP items itself |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2287 lp->lp_replang = lp->lp_slang; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2288 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2289 // find first similar language that has REP items |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2290 for (j = 0; j < ga.ga_len; ++j) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2291 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2292 lp2 = LANGP_ENTRY(ga, j); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2293 if (lp2->lp_slang->sl_rep.ga_len > 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2294 && STRNCMP(lp->lp_slang->sl_name, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2295 lp2->lp_slang->sl_name, 2) == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2296 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2297 lp->lp_replang = lp2->lp_slang; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2298 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2299 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2300 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2301 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2302 redraw_win_later(wp, UPD_NOT_VALID); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2303 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2304 theend: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2305 vim_free(spl_copy); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2306 recursive = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2307 return ret_msg; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2308 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2309 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2310 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2311 * Clear the midword characters for buffer "buf". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2312 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2313 static void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2314 clear_midword(win_T *wp) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2315 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2316 CLEAR_FIELD(wp->w_s->b_spell_ismw); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2317 VIM_CLEAR(wp->w_s->b_spell_ismw_mb); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2318 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2319 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2320 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2321 * Use the "sl_midword" field of language "lp" for buffer "buf". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2322 * They add up to any currently used midword characters. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2323 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2324 static void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2325 use_midword(slang_T *lp, win_T *wp) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2326 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2327 char_u *p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2328 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2329 if (lp->sl_midword == NULL) // there aren't any |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2330 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2331 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2332 for (p = lp->sl_midword; *p != NUL; ) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2333 if (has_mbyte) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2334 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2335 int c, l, n; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2336 char_u *bp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2337 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2338 c = mb_ptr2char(p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2339 l = (*mb_ptr2len)(p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2340 if (c < 256 && l <= 2) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2341 wp->w_s->b_spell_ismw[c] = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2342 else if (wp->w_s->b_spell_ismw_mb == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2343 // First multi-byte char in "b_spell_ismw_mb". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2344 wp->w_s->b_spell_ismw_mb = vim_strnsave(p, l); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2345 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2346 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2347 // Append multi-byte chars to "b_spell_ismw_mb". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2348 n = (int)STRLEN(wp->w_s->b_spell_ismw_mb); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2349 bp = vim_strnsave(wp->w_s->b_spell_ismw_mb, n + l); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2350 if (bp != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2351 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2352 vim_free(wp->w_s->b_spell_ismw_mb); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2353 wp->w_s->b_spell_ismw_mb = bp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2354 vim_strncpy(bp + n, p, l); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2355 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2356 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2357 p += l; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2358 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2359 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2360 wp->w_s->b_spell_ismw[*p++] = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2361 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2362 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2363 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2364 * Find the region "region[2]" in "rp" (points to "sl_regions"). |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2365 * Each region is simply stored as the two characters of its name. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2366 * Returns the index if found (first is 0), REGION_ALL if not found. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2367 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2368 static int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2369 find_region(char_u *rp, char_u *region) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2370 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2371 int i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2372 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2373 for (i = 0; ; i += 2) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2374 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2375 if (rp[i] == NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2376 return REGION_ALL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2377 if (rp[i] == region[0] && rp[i + 1] == region[1]) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2378 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2379 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2380 return i / 2; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2381 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2382 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2383 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2384 * Return case type of word: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2385 * w word 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2386 * Word WF_ONECAP |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2387 * W WORD WF_ALLCAP |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2388 * WoRd wOrd WF_KEEPCAP |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2389 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2390 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2391 captype( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2392 char_u *word, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2393 char_u *end) // When NULL use up to NUL byte. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2394 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2395 char_u *p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2396 int c; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2397 int firstcap; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2398 int allcap; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2399 int past_second = FALSE; // past second word char |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2400 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2401 // find first letter |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2402 for (p = word; !spell_iswordp_nmw(p, curwin); MB_PTR_ADV(p)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2403 if (end == NULL ? *p == NUL : p >= end) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2404 return 0; // only non-word characters, illegal word |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2405 if (has_mbyte) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2406 c = mb_ptr2char_adv(&p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2407 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2408 c = *p++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2409 firstcap = allcap = SPELL_ISUPPER(c); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2410 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2411 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2412 * Need to check all letters to find a word with mixed upper/lower. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2413 * But a word with an upper char only at start is a ONECAP. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2414 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2415 for ( ; end == NULL ? *p != NUL : p < end; MB_PTR_ADV(p)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2416 if (spell_iswordp_nmw(p, curwin)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2417 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2418 c = PTR2CHAR(p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2419 if (!SPELL_ISUPPER(c)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2420 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2421 // UUl -> KEEPCAP |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2422 if (past_second && allcap) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2423 return WF_KEEPCAP; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2424 allcap = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2425 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2426 else if (!allcap) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2427 // UlU -> KEEPCAP |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2428 return WF_KEEPCAP; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2429 past_second = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2430 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2431 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2432 if (allcap) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2433 return WF_ALLCAP; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2434 if (firstcap) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2435 return WF_ONECAP; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2436 return 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2437 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2438 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2439 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2440 * Delete the internal wordlist and its .spl file. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2441 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2442 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2443 spell_delete_wordlist(void) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2444 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2445 char_u fname[MAXPATHL]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2446 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2447 if (int_wordlist == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2448 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2449 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2450 mch_remove(int_wordlist); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2451 int_wordlist_spl(fname); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2452 mch_remove(fname); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2453 VIM_CLEAR(int_wordlist); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2454 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2455 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2456 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2457 * Free all languages. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2458 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2459 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2460 spell_free_all(void) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2461 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2462 slang_T *slang; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2463 buf_T *buf; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2464 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2465 // Go through all buffers and handle 'spelllang'. <VN> |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2466 FOR_ALL_BUFFERS(buf) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2467 ga_clear(&buf->b_s.b_langp); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2468 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2469 while (first_lang != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2470 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2471 slang = first_lang; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2472 first_lang = slang->sl_next; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2473 slang_free(slang); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2474 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2475 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2476 spell_delete_wordlist(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2477 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2478 VIM_CLEAR(repl_to); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2479 VIM_CLEAR(repl_from); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2480 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2481 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2482 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2483 * Clear all spelling tables and reload them. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2484 * Used after 'encoding' is set and when ":mkspell" was used. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2485 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2486 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2487 spell_reload(void) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2488 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2489 win_T *wp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2490 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2491 // Initialize the table for spell_iswordp(). |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2492 init_spell_chartab(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2493 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2494 // Unload all allocated memory. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2495 spell_free_all(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2496 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2497 // Go through all buffers and handle 'spelllang'. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2498 FOR_ALL_WINDOWS(wp) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2499 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2500 // Only load the wordlists when 'spelllang' is set and there is a |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2501 // window for this buffer in which 'spell' is set. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2502 if (*wp->w_s->b_p_spl != NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2503 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2504 if (wp->w_p_spell) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2505 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2506 (void)parse_spelllang(wp); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2507 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2508 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2509 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2510 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2511 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2512 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2513 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2514 * Open a spell buffer. This is a nameless buffer that is not in the buffer |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2515 * list and only contains text lines. Can use a swapfile to reduce memory |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2516 * use. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2517 * Most other fields are invalid! Esp. watch out for string options being |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2518 * NULL and there is no undo info. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2519 * Returns NULL when out of memory. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2520 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2521 buf_T * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2522 open_spellbuf(void) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2523 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2524 buf_T *buf; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2525 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2526 buf = ALLOC_CLEAR_ONE(buf_T); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2527 if (buf == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2528 return NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2529 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2530 buf->b_spell = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2531 buf->b_p_swf = TRUE; // may create a swap file |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2532 #ifdef FEAT_CRYPT |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2533 buf->b_p_key = empty_option; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2534 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2535 ml_open(buf); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2536 ml_open_file(buf); // create swap file now |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2537 return buf; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2538 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2539 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2540 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2541 * Close the buffer used for spell info. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2542 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2543 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2544 close_spellbuf(buf_T *buf) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2545 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2546 if (buf == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2547 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2548 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2549 ml_close(buf, TRUE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2550 vim_free(buf); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2551 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2552 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2553 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2554 * Init the chartab used for spelling for ASCII. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2555 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2556 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2557 clear_spell_chartab(spelltab_T *sp) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2558 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2559 int i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2560 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2561 // Init everything to FALSE (zero). |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2562 CLEAR_FIELD(sp->st_isw); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2563 CLEAR_FIELD(sp->st_isu); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2564 for (i = 0; i < 256; ++i) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2565 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2566 sp->st_fold[i] = i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2567 sp->st_upper[i] = i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2568 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2569 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2570 // We include digits. A word shouldn't start with a digit, but handling |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2571 // that is done separately. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2572 for (i = '0'; i <= '9'; ++i) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2573 sp->st_isw[i] = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2574 for (i = 'A'; i <= 'Z'; ++i) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2575 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2576 sp->st_isw[i] = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2577 sp->st_isu[i] = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2578 sp->st_fold[i] = i + 0x20; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2579 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2580 for (i = 'a'; i <= 'z'; ++i) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2581 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2582 sp->st_isw[i] = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2583 sp->st_upper[i] = i - 0x20; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2584 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2585 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2586 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2587 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2588 * Init the chartab used for spelling. Only depends on 'encoding'. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2589 * Called once while starting up and when 'encoding' changes. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2590 * The default is to use isalpha(), but the spell file should define the word |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2591 * characters to make it possible that 'encoding' differs from the current |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2592 * locale. For utf-8 we don't use isalpha() but our own functions. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2593 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2594 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2595 init_spell_chartab(void) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2596 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2597 int i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2598 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2599 did_set_spelltab = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2600 clear_spell_chartab(&spelltab); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2601 if (enc_dbcs) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2602 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2603 // DBCS: assume double-wide characters are word characters. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2604 for (i = 128; i <= 255; ++i) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2605 if (MB_BYTE2LEN(i) == 2) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2606 spelltab.st_isw[i] = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2607 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2608 else if (enc_utf8) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2609 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2610 for (i = 128; i < 256; ++i) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2611 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2612 int f = utf_fold(i); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2613 int u = utf_toupper(i); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2614 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2615 spelltab.st_isu[i] = utf_isupper(i); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2616 spelltab.st_isw[i] = spelltab.st_isu[i] || utf_islower(i); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2617 // The folded/upper-cased value is different between latin1 and |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2618 // utf8 for 0xb5, causing E763 for no good reason. Use the latin1 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2619 // value for utf-8 to avoid this. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2620 spelltab.st_fold[i] = (f < 256) ? f : i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2621 spelltab.st_upper[i] = (u < 256) ? u : i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2622 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2623 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2624 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2625 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2626 // Rough guess: use locale-dependent library functions. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2627 for (i = 128; i < 256; ++i) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2628 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2629 if (MB_ISUPPER(i)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2630 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2631 spelltab.st_isw[i] = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2632 spelltab.st_isu[i] = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2633 spelltab.st_fold[i] = MB_TOLOWER(i); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2634 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2635 else if (MB_ISLOWER(i)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2636 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2637 spelltab.st_isw[i] = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2638 spelltab.st_upper[i] = MB_TOUPPER(i); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2639 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2640 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2641 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2642 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2643 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2644 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2645 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2646 * Return TRUE if "p" points to a word character. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2647 * As a special case we see "midword" characters as word character when it is |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2648 * followed by a word character. This finds they'there but not 'they there'. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2649 * Thus this only works properly when past the first character of the word. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2650 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2651 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2652 spell_iswordp( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2653 char_u *p, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2654 win_T *wp) // buffer used |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2655 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2656 char_u *s; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2657 int l; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2658 int c; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2659 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2660 if (has_mbyte) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2661 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2662 l = mb_ptr2len(p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2663 s = p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2664 if (l == 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2665 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2666 // be quick for ASCII |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2667 if (wp->w_s->b_spell_ismw[*p]) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2668 s = p + 1; // skip a mid-word character |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2669 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2670 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2671 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2672 c = mb_ptr2char(p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2673 if (c < 256 ? wp->w_s->b_spell_ismw[c] |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2674 : (wp->w_s->b_spell_ismw_mb != NULL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2675 && vim_strchr(wp->w_s->b_spell_ismw_mb, c) != NULL)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2676 s = p + l; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2677 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2678 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2679 c = mb_ptr2char(s); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2680 if (c > 255) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2681 return spell_mb_isword_class(mb_get_class(s), wp); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2682 return spelltab.st_isw[c]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2683 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2684 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2685 return spelltab.st_isw[wp->w_s->b_spell_ismw[*p] ? p[1] : p[0]]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2686 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2687 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2688 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2689 * Return TRUE if "p" points to a word character. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2690 * Unlike spell_iswordp() this doesn't check for "midword" characters. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2691 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2692 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2693 spell_iswordp_nmw(char_u *p, win_T *wp) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2694 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2695 int c; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2696 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2697 if (has_mbyte) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2698 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2699 c = mb_ptr2char(p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2700 if (c > 255) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2701 return spell_mb_isword_class(mb_get_class(p), wp); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2702 return spelltab.st_isw[c]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2703 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2704 return spelltab.st_isw[*p]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2705 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2706 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2707 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2708 * Return TRUE if word class indicates a word character. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2709 * Only for characters above 255. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2710 * Unicode subscript and superscript are not considered word characters. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2711 * See also dbcs_class() and utf_class() in mbyte.c. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2712 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2713 static int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2714 spell_mb_isword_class(int cl, win_T *wp) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2715 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2716 if (wp->w_s->b_cjk) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2717 // East Asian characters are not considered word characters. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2718 return cl == 2 || cl == 0x2800; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2719 return cl >= 2 && cl != 0x2070 && cl != 0x2080 && cl != 3; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2720 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2721 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2722 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2723 * Return TRUE if "p" points to a word character. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2724 * Wide version of spell_iswordp(). |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2725 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2726 static int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2727 spell_iswordp_w(int *p, win_T *wp) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2728 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2729 int *s; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2730 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2731 if (*p < 256 ? wp->w_s->b_spell_ismw[*p] |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2732 : (wp->w_s->b_spell_ismw_mb != NULL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2733 && vim_strchr(wp->w_s->b_spell_ismw_mb, *p) != NULL)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2734 s = p + 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2735 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2736 s = p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2737 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2738 if (*s > 255) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2739 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2740 if (enc_utf8) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2741 return spell_mb_isword_class(utf_class(*s), wp); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2742 if (enc_dbcs) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2743 return spell_mb_isword_class( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2744 dbcs_class((unsigned)*s >> 8, *s & 0xff), wp); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2745 return 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2746 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2747 return spelltab.st_isw[*s]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2748 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2749 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2750 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2751 * Case-fold "str[len]" into "buf[buflen]". The result is NUL terminated. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2752 * Uses the character definitions from the .spl file. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2753 * When using a multi-byte 'encoding' the length may change! |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2754 * Returns FAIL when something wrong. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2755 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2756 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2757 spell_casefold( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2758 win_T *wp, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2759 char_u *str, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2760 int len, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2761 char_u *buf, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2762 int buflen) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2763 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2764 int i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2765 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2766 if (len >= buflen) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2767 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2768 buf[0] = NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2769 return FAIL; // result will not fit |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2770 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2771 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2772 if (has_mbyte) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2773 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2774 int outi = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2775 char_u *p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2776 int c; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2777 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2778 // Fold one character at a time. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2779 for (p = str; p < str + len; ) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2780 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2781 if (outi + MB_MAXBYTES > buflen) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2782 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2783 buf[outi] = NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2784 return FAIL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2785 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2786 c = mb_cptr2char_adv(&p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2787 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2788 // Exception: greek capital sigma 0x03A3 folds to 0x03C3, except |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2789 // when it is the last character in a word, then it folds to |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2790 // 0x03C2. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2791 if (c == 0x03a3 || c == 0x03c2) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2792 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2793 if (p == str + len || !spell_iswordp(p, wp)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2794 c = 0x03c2; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2795 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2796 c = 0x03c3; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2797 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2798 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2799 c = SPELL_TOFOLD(c); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2800 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2801 outi += mb_char2bytes(c, buf + outi); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2802 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2803 buf[outi] = NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2804 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2805 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2806 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2807 // Be quick for non-multibyte encodings. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2808 for (i = 0; i < len; ++i) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2809 buf[i] = spelltab.st_fold[str[i]]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2810 buf[i] = NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2811 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2812 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2813 return OK; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2814 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2815 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2816 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2817 * Check if the word at line "lnum" column "col" is required to start with a |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2818 * capital. This uses 'spellcapcheck' of the buffer in window "wp". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2819 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2820 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2821 check_need_cap(win_T *wp, linenr_T lnum, colnr_T col) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2822 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2823 if (wp->w_s->b_cap_prog == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2824 return FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2825 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2826 int need_cap = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2827 char_u *line = col ? ml_get_buf(wp->w_buffer, lnum, FALSE) : NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2828 char_u *line_copy = NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2829 colnr_T endcol = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2830 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2831 if (col == 0 || getwhitecols(line) >= col) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2832 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2833 // At start of line, check if previous line is empty or sentence |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2834 // ends there. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2835 if (lnum == 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2836 need_cap = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2837 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2838 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2839 line = ml_get_buf(wp->w_buffer, lnum - 1, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2840 if (*skipwhite(line) == NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2841 need_cap = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2842 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2843 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2844 // Append a space in place of the line break. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2845 line_copy = concat_str(line, (char_u *)" "); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2846 if (line_copy == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2847 return FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2848 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2849 line = line_copy; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2850 endcol = (colnr_T)STRLEN(line); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2851 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2852 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2853 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2854 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2855 endcol = col; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2856 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2857 if (endcol > 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2858 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2859 // Check if sentence ends before the bad word. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2860 regmatch_T regmatch; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2861 regmatch.regprog = wp->w_s->b_cap_prog; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2862 regmatch.rm_ic = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2863 char_u *p = line + endcol; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2864 for (;;) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2865 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2866 MB_PTR_BACK(line, p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2867 if (p == line || spell_iswordp_nmw(p, wp)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2868 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2869 if (vim_regexec(®match, p, 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2870 && regmatch.endp[0] == line + endcol) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2871 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2872 need_cap = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2873 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2874 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2875 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2876 wp->w_s->b_cap_prog = regmatch.regprog; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2877 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2878 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2879 vim_free(line_copy); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2880 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2881 return need_cap; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2882 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2883 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2884 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2885 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2886 * ":spellrepall" |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2887 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2888 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2889 ex_spellrepall(exarg_T *eap UNUSED) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2890 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2891 pos_T pos = curwin->w_cursor; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2892 char_u *frompat; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2893 char_u *line; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2894 char_u *p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2895 int save_ws = p_ws; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2896 linenr_T prev_lnum = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2897 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2898 if (repl_from == NULL || repl_to == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2899 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2900 emsg(_(e_no_previous_spell_replacement)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2901 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2902 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2903 size_t repl_from_len = STRLEN(repl_from); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2904 size_t repl_to_len = STRLEN(repl_to); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2905 int addlen = (int)(repl_to_len - repl_from_len); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2906 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2907 frompat = alloc(repl_from_len + 7); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2908 if (frompat == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2909 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2910 sprintf((char *)frompat, "\\V\\<%s\\>", repl_from); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2911 p_ws = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2912 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2913 sub_nsubs = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2914 sub_nlines = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2915 curwin->w_cursor.lnum = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2916 while (!got_int) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2917 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2918 if (do_search(NULL, '/', '/', frompat, 1L, SEARCH_KEEP, NULL) == 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2919 || u_save_cursor() == FAIL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2920 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2921 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2922 // Only replace when the right word isn't there yet. This happens |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2923 // when changing "etc" to "etc.". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2924 line = ml_get_curline(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2925 if (addlen <= 0 || STRNCMP(line + curwin->w_cursor.col, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2926 repl_to, repl_to_len) != 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2927 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2928 p = alloc(STRLEN(line) + addlen + 1); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2929 if (p == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2930 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2931 mch_memmove(p, line, curwin->w_cursor.col); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2932 STRCPY(p + curwin->w_cursor.col, repl_to); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2933 STRCAT(p, line + curwin->w_cursor.col + repl_from_len); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2934 ml_replace(curwin->w_cursor.lnum, p, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2935 changed_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2936 #if defined(FEAT_PROP_POPUP) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2937 if (curbuf->b_has_textprop && addlen != 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2938 adjust_prop_columns(curwin->w_cursor.lnum, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2939 curwin->w_cursor.col, addlen, APC_SUBSTITUTE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2940 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2941 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2942 if (curwin->w_cursor.lnum != prev_lnum) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2943 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2944 ++sub_nlines; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2945 prev_lnum = curwin->w_cursor.lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2946 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2947 ++sub_nsubs; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2948 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2949 curwin->w_cursor.col += (colnr_T)repl_to_len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2950 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2951 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2952 p_ws = save_ws; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2953 curwin->w_cursor = pos; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2954 vim_free(frompat); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2955 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2956 if (sub_nsubs == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2957 semsg(_(e_not_found_str), repl_from); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2958 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2959 do_sub_msg(FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2960 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2961 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2962 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2963 * Make a copy of "word", with the first letter upper or lower cased, to |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2964 * "wcopy[MAXWLEN]". "word" must not be empty. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2965 * The result is NUL terminated. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2966 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2967 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2968 onecap_copy( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2969 char_u *word, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2970 char_u *wcopy, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2971 int upper) // TRUE: first letter made upper case |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2972 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2973 char_u *p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2974 int c; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2975 int l; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2976 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2977 p = word; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2978 if (has_mbyte) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2979 c = mb_cptr2char_adv(&p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2980 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2981 c = *p++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2982 if (upper) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2983 c = SPELL_TOUPPER(c); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2984 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2985 c = SPELL_TOFOLD(c); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2986 if (has_mbyte) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2987 l = mb_char2bytes(c, wcopy); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2988 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2989 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2990 l = 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2991 wcopy[0] = c; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2992 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2993 vim_strncpy(wcopy + l, p, MAXWLEN - l - 1); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2994 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2995 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2996 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2997 * Make a copy of "word" with all the letters upper cased into |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2998 * "wcopy[MAXWLEN]". The result is NUL terminated. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
2999 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3000 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3001 allcap_copy(char_u *word, char_u *wcopy) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3002 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3003 char_u *s; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3004 char_u *d; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3005 int c; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3006 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3007 d = wcopy; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3008 for (s = word; *s != NUL; ) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3009 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3010 if (has_mbyte) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3011 c = mb_cptr2char_adv(&s); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3012 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3013 c = *s++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3014 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3015 // We only change 0xdf to SS when we are certain latin1 is used. It |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3016 // would cause weird errors in other 8-bit encodings. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3017 if (enc_latin1like && c == 0xdf) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3018 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3019 c = 'S'; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3020 if (d - wcopy >= MAXWLEN - 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3021 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3022 *d++ = c; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3023 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3024 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3025 c = SPELL_TOUPPER(c); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3026 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3027 if (has_mbyte) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3028 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3029 if (d - wcopy >= MAXWLEN - MB_MAXBYTES) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3030 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3031 d += mb_char2bytes(c, d); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3032 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3033 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3034 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3035 if (d - wcopy >= MAXWLEN - 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3036 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3037 *d++ = c; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3038 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3039 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3040 *d = NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3041 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3042 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3043 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3044 * Case-folding may change the number of bytes: Count nr of chars in |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3045 * fword[flen] and return the byte length of that many chars in "word". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3046 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3047 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3048 nofold_len(char_u *fword, int flen, char_u *word) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3049 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3050 char_u *p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3051 int i = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3052 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3053 for (p = fword; p < fword + flen; MB_PTR_ADV(p)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3054 ++i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3055 for (p = word; i > 0; MB_PTR_ADV(p)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3056 --i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3057 return (int)(p - word); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3058 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3059 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3060 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3061 * Copy "fword" to "cword", fixing case according to "flags". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3062 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3063 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3064 make_case_word(char_u *fword, char_u *cword, int flags) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3065 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3066 if (flags & WF_ALLCAP) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3067 // Make it all upper-case |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3068 allcap_copy(fword, cword); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3069 else if (flags & WF_ONECAP) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3070 // Make the first letter upper-case |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3071 onecap_copy(fword, cword, TRUE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3072 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3073 // Use goodword as-is. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3074 STRCPY(cword, fword); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3075 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3076 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3077 #if defined(FEAT_EVAL) || defined(PROTO) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3078 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3079 * Soundfold a string, for soundfold(). |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3080 * Result is in allocated memory, NULL for an error. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3081 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3082 char_u * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3083 eval_soundfold(char_u *word) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3084 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3085 langp_T *lp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3086 char_u sound[MAXWLEN]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3087 int lpi; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3088 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3089 if (curwin->w_p_spell && *curwin->w_s->b_p_spl != NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3090 // Use the sound-folding of the first language that supports it. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3091 for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3092 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3093 lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3094 if (lp->lp_slang->sl_sal.ga_len > 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3095 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3096 // soundfold the word |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3097 spell_soundfold(lp->lp_slang, word, FALSE, sound); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3098 return vim_strsave(sound); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3099 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3100 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3101 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3102 // No language with sound folding, return word as-is. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3103 return vim_strsave(word); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3104 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3105 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3106 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3107 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3108 * Turn "inword" into its sound-a-like equivalent in "res[MAXWLEN]". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3109 * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3110 * There are many ways to turn a word into a sound-a-like representation. The |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3111 * oldest is Soundex (1918!). A nice overview can be found in "Approximate |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3112 * swedish name matching - survey and test of different algorithms" by Klas |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3113 * Erikson. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3114 * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3115 * We support two methods: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3116 * 1. SOFOFROM/SOFOTO do a simple character mapping. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3117 * 2. SAL items define a more advanced sound-folding (and much slower). |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3118 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3119 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3120 spell_soundfold( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3121 slang_T *slang, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3122 char_u *inword, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3123 int folded, // "inword" is already case-folded |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3124 char_u *res) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3125 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3126 char_u fword[MAXWLEN]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3127 char_u *word; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3128 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3129 if (slang->sl_sofo) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3130 // SOFOFROM and SOFOTO used |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3131 spell_soundfold_sofo(slang, inword, res); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3132 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3133 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3134 // SAL items used. Requires the word to be case-folded. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3135 if (folded) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3136 word = inword; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3137 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3138 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3139 (void)spell_casefold(curwin, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3140 inword, (int)STRLEN(inword), fword, MAXWLEN); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3141 word = fword; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3142 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3143 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3144 if (has_mbyte) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3145 spell_soundfold_wsal(slang, word, res); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3146 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3147 spell_soundfold_sal(slang, word, res); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3148 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3149 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3150 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3151 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3152 * Perform sound folding of "inword" into "res" according to SOFOFROM and |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3153 * SOFOTO lines. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3154 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3155 static void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3156 spell_soundfold_sofo(slang_T *slang, char_u *inword, char_u *res) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3157 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3158 char_u *s; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3159 int ri = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3160 int c; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3161 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3162 if (has_mbyte) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3163 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3164 int prevc = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3165 int *ip; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3166 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3167 // The sl_sal_first[] table contains the translation for chars up to |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3168 // 255, sl_sal the rest. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3169 for (s = inword; *s != NUL; ) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3170 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3171 c = mb_cptr2char_adv(&s); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3172 if (enc_utf8 ? utf_class(c) == 0 : VIM_ISWHITE(c)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3173 c = ' '; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3174 else if (c < 256) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3175 c = slang->sl_sal_first[c]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3176 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3177 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3178 ip = ((int **)slang->sl_sal.ga_data)[c & 0xff]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3179 if (ip == NULL) // empty list, can't match |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3180 c = NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3181 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3182 for (;;) // find "c" in the list |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3183 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3184 if (*ip == 0) // not found |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3185 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3186 c = NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3187 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3188 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3189 if (*ip == c) // match! |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3190 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3191 c = ip[1]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3192 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3193 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3194 ip += 2; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3195 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3196 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3197 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3198 if (c != NUL && c != prevc) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3199 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3200 ri += mb_char2bytes(c, res + ri); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3201 if (ri + MB_MAXBYTES > MAXWLEN) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3202 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3203 prevc = c; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3204 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3205 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3206 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3207 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3208 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3209 // The sl_sal_first[] table contains the translation. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3210 for (s = inword; (c = *s) != NUL; ++s) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3211 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3212 if (VIM_ISWHITE(c)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3213 c = ' '; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3214 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3215 c = slang->sl_sal_first[c]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3216 if (c != NUL && (ri == 0 || res[ri - 1] != c)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3217 res[ri++] = c; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3218 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3219 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3220 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3221 res[ri] = NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3222 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3223 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3224 static void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3225 spell_soundfold_sal(slang_T *slang, char_u *inword, char_u *res) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3226 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3227 salitem_T *smp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3228 char_u word[MAXWLEN]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3229 char_u *s = inword; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3230 char_u *t; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3231 char_u *pf; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3232 int i, j, z; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3233 int reslen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3234 int n, k = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3235 int z0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3236 int k0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3237 int n0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3238 int c; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3239 int pri; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3240 int p0 = -333; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3241 int c0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3242 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3243 // Remove accents, if wanted. We actually remove all non-word characters. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3244 // But keep white space. We need a copy, the word may be changed here. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3245 if (slang->sl_rem_accents) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3246 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3247 t = word; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3248 while (*s != NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3249 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3250 if (VIM_ISWHITE(*s)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3251 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3252 *t++ = ' '; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3253 s = skipwhite(s); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3254 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3255 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3256 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3257 if (spell_iswordp_nmw(s, curwin)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3258 *t++ = *s; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3259 ++s; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3260 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3261 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3262 *t = NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3263 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3264 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3265 vim_strncpy(word, s, MAXWLEN - 1); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3266 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3267 smp = (salitem_T *)slang->sl_sal.ga_data; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3268 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3269 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3270 * This comes from Aspell phonet.cpp. Converted from C++ to C. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3271 * Changed to keep spaces. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3272 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3273 i = reslen = z = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3274 while ((c = word[i]) != NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3275 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3276 // Start with the first rule that has the character in the word. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3277 n = slang->sl_sal_first[c]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3278 z0 = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3279 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3280 if (n >= 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3281 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3282 // check all rules for the same letter |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3283 for (; (s = smp[n].sm_lead)[0] == c; ++n) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3284 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3285 // Quickly skip entries that don't match the word. Most |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3286 // entries are less than three chars, optimize for that. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3287 k = smp[n].sm_leadlen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3288 if (k > 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3289 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3290 if (word[i + 1] != s[1]) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3291 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3292 if (k > 2) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3293 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3294 for (j = 2; j < k; ++j) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3295 if (word[i + j] != s[j]) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3296 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3297 if (j < k) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3298 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3299 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3300 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3301 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3302 if ((pf = smp[n].sm_oneof) != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3303 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3304 // Check for match with one of the chars in "sm_oneof". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3305 while (*pf != NUL && *pf != word[i + k]) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3306 ++pf; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3307 if (*pf == NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3308 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3309 ++k; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3310 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3311 s = smp[n].sm_rules; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3312 pri = 5; // default priority |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3313 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3314 p0 = *s; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3315 k0 = k; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3316 while (*s == '-' && k > 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3317 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3318 k--; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3319 s++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3320 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3321 if (*s == '<') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3322 s++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3323 if (VIM_ISDIGIT(*s)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3324 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3325 // determine priority |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3326 pri = *s - '0'; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3327 s++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3328 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3329 if (*s == '^' && *(s + 1) == '^') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3330 s++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3331 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3332 if (*s == NUL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3333 || (*s == '^' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3334 && (i == 0 || !(word[i - 1] == ' ' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3335 || spell_iswordp(word + i - 1, curwin))) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3336 && (*(s + 1) != '$' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3337 || (!spell_iswordp(word + i + k0, curwin)))) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3338 || (*s == '$' && i > 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3339 && spell_iswordp(word + i - 1, curwin) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3340 && (!spell_iswordp(word + i + k0, curwin)))) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3341 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3342 // search for followup rules, if: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3343 // followup and k > 1 and NO '-' in searchstring |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3344 c0 = word[i + k - 1]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3345 n0 = slang->sl_sal_first[c0]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3346 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3347 if (slang->sl_followup && k > 1 && n0 >= 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3348 && p0 != '-' && word[i + k] != NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3349 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3350 // test follow-up rule for "word[i + k]" |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3351 for ( ; (s = smp[n0].sm_lead)[0] == c0; ++n0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3352 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3353 // Quickly skip entries that don't match the word. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3354 // |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3355 k0 = smp[n0].sm_leadlen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3356 if (k0 > 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3357 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3358 if (word[i + k] != s[1]) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3359 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3360 if (k0 > 2) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3361 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3362 pf = word + i + k + 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3363 for (j = 2; j < k0; ++j) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3364 if (*pf++ != s[j]) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3365 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3366 if (j < k0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3367 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3368 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3369 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3370 k0 += k - 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3371 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3372 if ((pf = smp[n0].sm_oneof) != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3373 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3374 // Check for match with one of the chars in |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3375 // "sm_oneof". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3376 while (*pf != NUL && *pf != word[i + k0]) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3377 ++pf; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3378 if (*pf == NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3379 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3380 ++k0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3381 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3382 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3383 p0 = 5; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3384 s = smp[n0].sm_rules; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3385 while (*s == '-') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3386 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3387 // "k0" gets NOT reduced because |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3388 // "if (k0 == k)" |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3389 s++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3390 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3391 if (*s == '<') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3392 s++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3393 if (VIM_ISDIGIT(*s)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3394 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3395 p0 = *s - '0'; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3396 s++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3397 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3398 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3399 if (*s == NUL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3400 // *s == '^' cuts |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3401 || (*s == '$' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3402 && !spell_iswordp(word + i + k0, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3403 curwin))) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3404 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3405 if (k0 == k) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3406 // this is just a piece of the string |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3407 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3408 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3409 if (p0 < pri) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3410 // priority too low |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3411 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3412 // rule fits; stop search |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3413 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3414 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3415 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3416 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3417 if (p0 >= pri && smp[n0].sm_lead[0] == c0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3418 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3419 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3420 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3421 // replace string |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3422 s = smp[n].sm_to; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3423 if (s == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3424 s = (char_u *)""; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3425 pf = smp[n].sm_rules; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3426 p0 = (vim_strchr(pf, '<') != NULL) ? 1 : 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3427 if (p0 == 1 && z == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3428 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3429 // rule with '<' is used |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3430 if (reslen > 0 && *s != NUL && (res[reslen - 1] == c |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3431 || res[reslen - 1] == *s)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3432 reslen--; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3433 z0 = 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3434 z = 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3435 k0 = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3436 while (*s != NUL && word[i + k0] != NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3437 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3438 word[i + k0] = *s; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3439 k0++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3440 s++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3441 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3442 if (k > k0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3443 STRMOVE(word + i + k0, word + i + k); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3444 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3445 // new "actual letter" |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3446 c = word[i]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3447 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3448 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3449 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3450 // no '<' rule used |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3451 i += k - 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3452 z = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3453 while (*s != NUL && s[1] != NUL && reslen < MAXWLEN) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3454 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3455 if (reslen == 0 || res[reslen - 1] != *s) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3456 res[reslen++] = *s; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3457 s++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3458 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3459 // new "actual letter" |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3460 c = *s; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3461 if (strstr((char *)pf, "^^") != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3462 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3463 if (c != NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3464 res[reslen++] = c; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3465 STRMOVE(word, word + i + 1); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3466 i = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3467 z0 = 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3468 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3469 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3470 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3471 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3472 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3473 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3474 else if (VIM_ISWHITE(c)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3475 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3476 c = ' '; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3477 k = 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3478 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3479 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3480 if (z0 == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3481 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3482 if (k && !p0 && reslen < MAXWLEN && c != NUL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3483 && (!slang->sl_collapse || reslen == 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3484 || res[reslen - 1] != c)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3485 // condense only double letters |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3486 res[reslen++] = c; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3487 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3488 i++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3489 z = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3490 k = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3491 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3492 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3493 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3494 res[reslen] = NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3495 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3496 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3497 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3498 * Turn "inword" into its sound-a-like equivalent in "res[MAXWLEN]". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3499 * Multi-byte version of spell_soundfold(). |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3500 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3501 static void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3502 spell_soundfold_wsal(slang_T *slang, char_u *inword, char_u *res) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3503 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3504 salitem_T *smp = (salitem_T *)slang->sl_sal.ga_data; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3505 int word[MAXWLEN]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3506 int wres[MAXWLEN]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3507 int l; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3508 char_u *s; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3509 int *ws; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3510 char_u *t; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3511 int *pf; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3512 int i, j, z; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3513 int reslen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3514 int n, k = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3515 int z0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3516 int k0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3517 int n0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3518 int c; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3519 int pri; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3520 int p0 = -333; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3521 int c0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3522 int did_white = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3523 int wordlen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3524 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3525 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3526 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3527 * Convert the multi-byte string to a wide-character string. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3528 * Remove accents, if wanted. We actually remove all non-word characters. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3529 * But keep white space. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3530 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3531 wordlen = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3532 for (s = inword; *s != NUL; ) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3533 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3534 t = s; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3535 c = mb_cptr2char_adv(&s); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3536 if (slang->sl_rem_accents) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3537 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3538 if (enc_utf8 ? utf_class(c) == 0 : VIM_ISWHITE(c)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3539 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3540 if (did_white) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3541 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3542 c = ' '; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3543 did_white = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3544 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3545 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3546 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3547 did_white = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3548 if (!spell_iswordp_nmw(t, curwin)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3549 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3550 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3551 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3552 word[wordlen++] = c; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3553 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3554 word[wordlen] = NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3555 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3556 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3557 * This algorithm comes from Aspell phonet.cpp. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3558 * Converted from C++ to C. Added support for multi-byte chars. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3559 * Changed to keep spaces. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3560 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3561 i = reslen = z = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3562 while ((c = word[i]) != NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3563 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3564 // Start with the first rule that has the character in the word. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3565 n = slang->sl_sal_first[c & 0xff]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3566 z0 = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3567 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3568 if (n >= 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3569 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3570 // Check all rules for the same index byte. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3571 // If c is 0x300 need extra check for the end of the array, as |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3572 // (c & 0xff) is NUL. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3573 for (; ((ws = smp[n].sm_lead_w)[0] & 0xff) == (c & 0xff) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3574 && ws[0] != NUL; ++n) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3575 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3576 // Quickly skip entries that don't match the word. Most |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3577 // entries are less than three chars, optimize for that. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3578 if (c != ws[0]) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3579 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3580 k = smp[n].sm_leadlen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3581 if (k > 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3582 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3583 if (word[i + 1] != ws[1]) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3584 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3585 if (k > 2) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3586 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3587 for (j = 2; j < k; ++j) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3588 if (word[i + j] != ws[j]) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3589 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3590 if (j < k) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3591 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3592 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3593 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3594 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3595 if ((pf = smp[n].sm_oneof_w) != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3596 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3597 // Check for match with one of the chars in "sm_oneof". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3598 while (*pf != NUL && *pf != word[i + k]) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3599 ++pf; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3600 if (*pf == NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3601 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3602 ++k; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3603 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3604 s = smp[n].sm_rules; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3605 pri = 5; // default priority |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3606 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3607 p0 = *s; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3608 k0 = k; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3609 while (*s == '-' && k > 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3610 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3611 k--; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3612 s++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3613 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3614 if (*s == '<') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3615 s++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3616 if (VIM_ISDIGIT(*s)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3617 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3618 // determine priority |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3619 pri = *s - '0'; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3620 s++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3621 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3622 if (*s == '^' && *(s + 1) == '^') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3623 s++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3624 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3625 if (*s == NUL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3626 || (*s == '^' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3627 && (i == 0 || !(word[i - 1] == ' ' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3628 || spell_iswordp_w(word + i - 1, curwin))) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3629 && (*(s + 1) != '$' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3630 || (!spell_iswordp_w(word + i + k0, curwin)))) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3631 || (*s == '$' && i > 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3632 && spell_iswordp_w(word + i - 1, curwin) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3633 && (!spell_iswordp_w(word + i + k0, curwin)))) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3634 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3635 // search for followup rules, if: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3636 // followup and k > 1 and NO '-' in searchstring |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3637 c0 = word[i + k - 1]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3638 n0 = slang->sl_sal_first[c0 & 0xff]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3639 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3640 if (slang->sl_followup && k > 1 && n0 >= 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3641 && p0 != '-' && word[i + k] != NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3642 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3643 // Test follow-up rule for "word[i + k]"; loop over |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3644 // all entries with the same index byte. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3645 for ( ; ((ws = smp[n0].sm_lead_w)[0] & 0xff) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3646 == (c0 & 0xff); ++n0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3647 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3648 // Quickly skip entries that don't match the word. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3649 if (c0 != ws[0]) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3650 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3651 k0 = smp[n0].sm_leadlen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3652 if (k0 > 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3653 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3654 if (word[i + k] != ws[1]) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3655 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3656 if (k0 > 2) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3657 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3658 pf = word + i + k + 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3659 for (j = 2; j < k0; ++j) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3660 if (*pf++ != ws[j]) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3661 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3662 if (j < k0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3663 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3664 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3665 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3666 k0 += k - 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3667 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3668 if ((pf = smp[n0].sm_oneof_w) != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3669 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3670 // Check for match with one of the chars in |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3671 // "sm_oneof". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3672 while (*pf != NUL && *pf != word[i + k0]) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3673 ++pf; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3674 if (*pf == NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3675 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3676 ++k0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3677 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3678 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3679 p0 = 5; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3680 s = smp[n0].sm_rules; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3681 while (*s == '-') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3682 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3683 // "k0" gets NOT reduced because |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3684 // "if (k0 == k)" |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3685 s++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3686 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3687 if (*s == '<') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3688 s++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3689 if (VIM_ISDIGIT(*s)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3690 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3691 p0 = *s - '0'; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3692 s++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3693 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3694 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3695 if (*s == NUL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3696 // *s == '^' cuts |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3697 || (*s == '$' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3698 && !spell_iswordp_w(word + i + k0, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3699 curwin))) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3700 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3701 if (k0 == k) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3702 // this is just a piece of the string |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3703 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3704 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3705 if (p0 < pri) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3706 // priority too low |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3707 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3708 // rule fits; stop search |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3709 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3710 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3711 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3712 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3713 if (p0 >= pri && (smp[n0].sm_lead_w[0] & 0xff) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3714 == (c0 & 0xff)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3715 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3716 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3717 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3718 // replace string |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3719 ws = smp[n].sm_to_w; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3720 s = smp[n].sm_rules; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3721 p0 = (vim_strchr(s, '<') != NULL) ? 1 : 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3722 if (p0 == 1 && z == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3723 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3724 // rule with '<' is used |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3725 if (reslen > 0 && ws != NULL && *ws != NUL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3726 && (wres[reslen - 1] == c |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3727 || wres[reslen - 1] == *ws)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3728 reslen--; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3729 z0 = 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3730 z = 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3731 k0 = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3732 if (ws != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3733 while (*ws != NUL && word[i + k0] != NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3734 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3735 word[i + k0] = *ws; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3736 k0++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3737 ws++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3738 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3739 if (k > k0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3740 mch_memmove(word + i + k0, word + i + k, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3741 sizeof(int) * (wordlen - (i + k) + 1)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3742 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3743 // new "actual letter" |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3744 c = word[i]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3745 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3746 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3747 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3748 // no '<' rule used |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3749 i += k - 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3750 z = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3751 if (ws != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3752 while (*ws != NUL && ws[1] != NUL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3753 && reslen < MAXWLEN) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3754 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3755 if (reslen == 0 || wres[reslen - 1] != *ws) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3756 wres[reslen++] = *ws; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3757 ws++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3758 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3759 // new "actual letter" |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3760 if (ws == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3761 c = NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3762 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3763 c = *ws; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3764 if (strstr((char *)s, "^^") != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3765 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3766 if (c != NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3767 wres[reslen++] = c; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3768 mch_memmove(word, word + i + 1, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3769 sizeof(int) * (wordlen - (i + 1) + 1)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3770 i = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3771 z0 = 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3772 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3773 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3774 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3775 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3776 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3777 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3778 else if (VIM_ISWHITE(c)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3779 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3780 c = ' '; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3781 k = 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3782 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3783 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3784 if (z0 == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3785 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3786 if (k && !p0 && reslen < MAXWLEN && c != NUL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3787 && (!slang->sl_collapse || reslen == 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3788 || wres[reslen - 1] != c)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3789 // condense only double letters |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3790 wres[reslen++] = c; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3791 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3792 i++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3793 z = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3794 k = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3795 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3796 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3797 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3798 // Convert wide characters in "wres" to a multi-byte string in "res". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3799 l = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3800 for (n = 0; n < reslen; ++n) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3801 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3802 l += mb_char2bytes(wres[n], res + l); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3803 if (l + MB_MAXBYTES > MAXWLEN) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3804 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3805 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3806 res[l] = NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3807 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3808 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3809 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3810 * ":spellinfo" |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3811 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3812 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3813 ex_spellinfo(exarg_T *eap UNUSED) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3814 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3815 int lpi; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3816 langp_T *lp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3817 char_u *p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3818 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3819 if (no_spell_checking(curwin)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3820 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3821 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3822 msg_start(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3823 for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len && !got_int; ++lpi) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3824 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3825 lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3826 msg_puts("file: "); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3827 msg_puts((char *)lp->lp_slang->sl_fname); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3828 msg_putchar('\n'); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3829 p = lp->lp_slang->sl_info; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3830 if (p != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3831 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3832 msg_puts((char *)p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3833 msg_putchar('\n'); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3834 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3835 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3836 msg_end(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3837 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3838 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3839 #define DUMPFLAG_KEEPCASE 1 // round 2: keep-case tree |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3840 #define DUMPFLAG_COUNT 2 // include word count |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3841 #define DUMPFLAG_ICASE 4 // ignore case when finding matches |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3842 #define DUMPFLAG_ONECAP 8 // pattern starts with capital |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3843 #define DUMPFLAG_ALLCAP 16 // pattern is all capitals |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3844 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3845 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3846 * ":spelldump" |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3847 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3848 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3849 ex_spelldump(exarg_T *eap) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3850 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3851 char_u *spl; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3852 long dummy; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3853 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3854 if (no_spell_checking(curwin)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3855 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3856 (void)get_option_value((char_u*)"spl", &dummy, &spl, NULL, OPT_LOCAL); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3857 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3858 // Create a new empty buffer in a new window. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3859 do_cmdline_cmd((char_u *)"new"); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3860 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3861 // enable spelling locally in the new window |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3862 set_option_value_give_err((char_u*)"spell", TRUE, (char_u*)"", OPT_LOCAL); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3863 set_option_value_give_err((char_u*)"spl", dummy, spl, OPT_LOCAL); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3864 vim_free(spl); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3865 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3866 if (!BUFEMPTY()) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3867 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3868 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3869 spell_dump_compl(NULL, 0, NULL, eap->forceit ? DUMPFLAG_COUNT : 0); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3870 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3871 // Delete the empty line that we started with. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3872 if (curbuf->b_ml.ml_line_count > 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3873 ml_delete(curbuf->b_ml.ml_line_count); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3874 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3875 redraw_later(UPD_NOT_VALID); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3876 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3877 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3878 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3879 * Go through all possible words and: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3880 * 1. When "pat" is NULL: dump a list of all words in the current buffer. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3881 * "ic" and "dir" are not used. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3882 * 2. When "pat" is not NULL: add matching words to insert mode completion. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3883 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3884 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3885 spell_dump_compl( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3886 char_u *pat, // leading part of the word |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3887 int ic, // ignore case |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3888 int *dir, // direction for adding matches |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3889 int dumpflags_arg) // DUMPFLAG_* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3890 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3891 langp_T *lp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3892 slang_T *slang; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3893 idx_T arridx[MAXWLEN]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3894 int curi[MAXWLEN]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3895 char_u word[MAXWLEN]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3896 int c; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3897 char_u *byts; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3898 idx_T *idxs; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3899 linenr_T lnum = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3900 int round; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3901 int depth; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3902 int n; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3903 int flags; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3904 char_u *region_names = NULL; // region names being used |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3905 int do_region = TRUE; // dump region names and numbers |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3906 char_u *p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3907 int lpi; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3908 int dumpflags = dumpflags_arg; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3909 int patlen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3910 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3911 // When ignoring case or when the pattern starts with capital pass this on |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3912 // to dump_word(). |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3913 if (pat != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3914 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3915 if (ic) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3916 dumpflags |= DUMPFLAG_ICASE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3917 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3918 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3919 n = captype(pat, NULL); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3920 if (n == WF_ONECAP) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3921 dumpflags |= DUMPFLAG_ONECAP; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3922 else if (n == WF_ALLCAP && (int)STRLEN(pat) > mb_ptr2len(pat)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3923 dumpflags |= DUMPFLAG_ALLCAP; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3924 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3925 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3926 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3927 // Find out if we can support regions: All languages must support the same |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3928 // regions or none at all. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3929 for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3930 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3931 lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3932 p = lp->lp_slang->sl_regions; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3933 if (p[0] != 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3934 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3935 if (region_names == NULL) // first language with regions |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3936 region_names = p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3937 else if (STRCMP(region_names, p) != 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3938 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3939 do_region = FALSE; // region names are different |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3940 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3941 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3942 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3943 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3944 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3945 if (do_region && region_names != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3946 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3947 if (pat == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3948 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3949 vim_snprintf((char *)IObuff, IOSIZE, "/regions=%s", region_names); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3950 ml_append(lnum++, IObuff, (colnr_T)0, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3951 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3952 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3953 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3954 do_region = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3955 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3956 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3957 * Loop over all files loaded for the entries in 'spelllang'. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3958 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3959 for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3960 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3961 lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3962 slang = lp->lp_slang; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3963 if (slang->sl_fbyts == NULL) // reloading failed |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3964 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3965 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3966 if (pat == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3967 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3968 vim_snprintf((char *)IObuff, IOSIZE, "# file: %s", slang->sl_fname); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3969 ml_append(lnum++, IObuff, (colnr_T)0, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3970 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3971 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3972 // When matching with a pattern and there are no prefixes only use |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3973 // parts of the tree that match "pat". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3974 if (pat != NULL && slang->sl_pbyts == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3975 patlen = (int)STRLEN(pat); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3976 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3977 patlen = -1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3978 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3979 // round 1: case-folded tree |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3980 // round 2: keep-case tree |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3981 for (round = 1; round <= 2; ++round) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3982 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3983 if (round == 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3984 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3985 dumpflags &= ~DUMPFLAG_KEEPCASE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3986 byts = slang->sl_fbyts; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3987 idxs = slang->sl_fidxs; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3988 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3989 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3990 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3991 dumpflags |= DUMPFLAG_KEEPCASE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3992 byts = slang->sl_kbyts; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3993 idxs = slang->sl_kidxs; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3994 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3995 if (byts == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3996 continue; // array is empty |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3997 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3998 depth = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
3999 arridx[0] = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4000 curi[0] = 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4001 while (depth >= 0 && !got_int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4002 && (pat == NULL || !ins_compl_interrupted())) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4003 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4004 if (curi[depth] > byts[arridx[depth]]) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4005 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4006 // Done all bytes at this node, go up one level. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4007 --depth; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4008 line_breakcheck(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4009 ins_compl_check_keys(50, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4010 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4011 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4012 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4013 // Do one more byte at this node. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4014 n = arridx[depth] + curi[depth]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4015 ++curi[depth]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4016 c = byts[n]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4017 if (c == 0 || depth >= MAXWLEN - 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4018 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4019 // End of word or reached maximum length, deal with the |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4020 // word. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4021 // Don't use keep-case words in the fold-case tree, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4022 // they will appear in the keep-case tree. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4023 // Only use the word when the region matches. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4024 flags = (int)idxs[n]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4025 if ((round == 2 || (flags & WF_KEEPCAP) == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4026 && (flags & WF_NEEDCOMP) == 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4027 && (do_region |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4028 || (flags & WF_REGION) == 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4029 || (((unsigned)flags >> 16) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4030 & lp->lp_region) != 0)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4031 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4032 word[depth] = NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4033 if (!do_region) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4034 flags &= ~WF_REGION; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4035 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4036 // Dump the basic word if there is no prefix or |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4037 // when it's the first one. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4038 c = (unsigned)flags >> 24; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4039 if (c == 0 || curi[depth] == 2) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4040 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4041 dump_word(slang, word, pat, dir, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4042 dumpflags, flags, lnum); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4043 if (pat == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4044 ++lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4045 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4046 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4047 // Apply the prefix, if there is one. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4048 if (c != 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4049 lnum = dump_prefixes(slang, word, pat, dir, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4050 dumpflags, flags, lnum); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4051 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4052 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4053 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4054 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4055 // Normal char, go one level deeper. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4056 word[depth++] = c; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4057 arridx[depth] = idxs[n]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4058 curi[depth] = 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4059 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4060 // Check if this character matches with the pattern. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4061 // If not skip the whole tree below it. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4062 // Always ignore case here, dump_word() will check |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4063 // proper case later. This isn't exactly right when |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4064 // length changes for multi-byte characters with |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4065 // ignore case... |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4066 if (depth <= patlen |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4067 && MB_STRNICMP(word, pat, depth) != 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4068 --depth; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4069 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4070 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4071 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4072 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4073 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4074 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4075 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4076 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4077 * Dump one word: apply case modifications and append a line to the buffer. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4078 * When "lnum" is zero add insert mode completion. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4079 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4080 static void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4081 dump_word( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4082 slang_T *slang, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4083 char_u *word, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4084 char_u *pat, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4085 int *dir, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4086 int dumpflags, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4087 int wordflags, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4088 linenr_T lnum) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4089 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4090 int keepcap = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4091 char_u *p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4092 char_u *tw; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4093 char_u cword[MAXWLEN]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4094 char_u badword[MAXWLEN + 10]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4095 int i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4096 int flags = wordflags; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4097 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4098 if (dumpflags & DUMPFLAG_ONECAP) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4099 flags |= WF_ONECAP; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4100 if (dumpflags & DUMPFLAG_ALLCAP) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4101 flags |= WF_ALLCAP; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4102 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4103 if ((dumpflags & DUMPFLAG_KEEPCASE) == 0 && (flags & WF_CAPMASK) != 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4104 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4105 // Need to fix case according to "flags". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4106 make_case_word(word, cword, flags); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4107 p = cword; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4108 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4109 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4110 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4111 p = word; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4112 if ((dumpflags & DUMPFLAG_KEEPCASE) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4113 && ((captype(word, NULL) & WF_KEEPCAP) == 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4114 || (flags & WF_FIXCAP) != 0)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4115 keepcap = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4116 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4117 tw = p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4118 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4119 if (pat == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4120 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4121 // Add flags and regions after a slash. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4122 if ((flags & (WF_BANNED | WF_RARE | WF_REGION)) || keepcap) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4123 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4124 STRCPY(badword, p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4125 STRCAT(badword, "/"); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4126 if (keepcap) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4127 STRCAT(badword, "="); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4128 if (flags & WF_BANNED) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4129 STRCAT(badword, "!"); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4130 else if (flags & WF_RARE) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4131 STRCAT(badword, "?"); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4132 if (flags & WF_REGION) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4133 for (i = 0; i < 7; ++i) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4134 if (flags & (0x10000 << i)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4135 sprintf((char *)badword + STRLEN(badword), "%d", i + 1); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4136 p = badword; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4137 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4138 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4139 if (dumpflags & DUMPFLAG_COUNT) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4140 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4141 hashitem_T *hi; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4142 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4143 // Include the word count for ":spelldump!". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4144 hi = hash_find(&slang->sl_wordcount, tw); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4145 if (!HASHITEM_EMPTY(hi)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4146 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4147 vim_snprintf((char *)IObuff, IOSIZE, "%s\t%d", |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4148 tw, HI2WC(hi)->wc_count); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4149 p = IObuff; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4150 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4151 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4152 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4153 ml_append(lnum, p, (colnr_T)0, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4154 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4155 else if (((dumpflags & DUMPFLAG_ICASE) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4156 ? MB_STRNICMP(p, pat, STRLEN(pat)) == 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4157 : STRNCMP(p, pat, STRLEN(pat)) == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4158 && ins_compl_add_infercase(p, (int)STRLEN(p), |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4159 p_ic, NULL, *dir, FALSE) == OK) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4160 // if dir was BACKWARD then honor it just once |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4161 *dir = FORWARD; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4162 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4163 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4164 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4165 * For ":spelldump": Find matching prefixes for "word". Prepend each to |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4166 * "word" and append a line to the buffer. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4167 * When "lnum" is zero add insert mode completion. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4168 * Return the updated line number. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4169 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4170 static linenr_T |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4171 dump_prefixes( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4172 slang_T *slang, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4173 char_u *word, // case-folded word |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4174 char_u *pat, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4175 int *dir, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4176 int dumpflags, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4177 int flags, // flags with prefix ID |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4178 linenr_T startlnum) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4179 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4180 idx_T arridx[MAXWLEN]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4181 int curi[MAXWLEN]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4182 char_u prefix[MAXWLEN]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4183 char_u word_up[MAXWLEN]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4184 int has_word_up = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4185 int c; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4186 char_u *byts; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4187 idx_T *idxs; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4188 linenr_T lnum = startlnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4189 int depth; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4190 int n; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4191 int len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4192 int i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4193 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4194 // If the word starts with a lower-case letter make the word with an |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4195 // upper-case letter in word_up[]. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4196 c = PTR2CHAR(word); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4197 if (SPELL_TOUPPER(c) != c) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4198 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4199 onecap_copy(word, word_up, TRUE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4200 has_word_up = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4201 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4202 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4203 byts = slang->sl_pbyts; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4204 idxs = slang->sl_pidxs; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4205 if (byts != NULL) // array not is empty |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4206 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4207 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4208 * Loop over all prefixes, building them byte-by-byte in prefix[]. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4209 * When at the end of a prefix check that it supports "flags". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4210 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4211 depth = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4212 arridx[0] = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4213 curi[0] = 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4214 while (depth >= 0 && !got_int) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4215 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4216 n = arridx[depth]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4217 len = byts[n]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4218 if (curi[depth] > len) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4219 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4220 // Done all bytes at this node, go up one level. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4221 --depth; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4222 line_breakcheck(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4223 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4224 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4225 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4226 // Do one more byte at this node. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4227 n += curi[depth]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4228 ++curi[depth]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4229 c = byts[n]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4230 if (c == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4231 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4232 // End of prefix, find out how many IDs there are. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4233 for (i = 1; i < len; ++i) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4234 if (byts[n + i] != 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4235 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4236 curi[depth] += i - 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4237 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4238 c = valid_word_prefix(i, n, flags, word, slang, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4239 if (c != 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4240 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4241 vim_strncpy(prefix + depth, word, MAXWLEN - depth - 1); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4242 dump_word(slang, prefix, pat, dir, dumpflags, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4243 (c & WF_RAREPFX) ? (flags | WF_RARE) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4244 : flags, lnum); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4245 if (lnum != 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4246 ++lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4247 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4248 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4249 // Check for prefix that matches the word when the |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4250 // first letter is upper-case, but only if the prefix has |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4251 // a condition. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4252 if (has_word_up) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4253 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4254 c = valid_word_prefix(i, n, flags, word_up, slang, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4255 TRUE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4256 if (c != 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4257 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4258 vim_strncpy(prefix + depth, word_up, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4259 MAXWLEN - depth - 1); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4260 dump_word(slang, prefix, pat, dir, dumpflags, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4261 (c & WF_RAREPFX) ? (flags | WF_RARE) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4262 : flags, lnum); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4263 if (lnum != 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4264 ++lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4265 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4266 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4267 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4268 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4269 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4270 // Normal char, go one level deeper. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4271 prefix[depth++] = c; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4272 arridx[depth] = idxs[n]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4273 curi[depth] = 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4274 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4275 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4276 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4277 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4278 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4279 return lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4280 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4281 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4282 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4283 * Move "p" to the end of word "start". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4284 * Uses the spell-checking word characters. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4285 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4286 char_u * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4287 spell_to_word_end(char_u *start, win_T *win) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4288 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4289 char_u *p = start; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4290 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4291 while (*p != NUL && spell_iswordp(p, win)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4292 MB_PTR_ADV(p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4293 return p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4294 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4295 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4296 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4297 * For Insert mode completion CTRL-X s: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4298 * Find start of the word in front of column "startcol". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4299 * We don't check if it is badly spelled, with completion we can only change |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4300 * the word in front of the cursor. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4301 * Returns the column number of the word. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4302 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4303 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4304 spell_word_start(int startcol) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4305 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4306 char_u *line; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4307 char_u *p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4308 int col = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4309 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4310 if (no_spell_checking(curwin)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4311 return startcol; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4312 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4313 // Find a word character before "startcol". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4314 line = ml_get_curline(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4315 for (p = line + startcol; p > line; ) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4316 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4317 MB_PTR_BACK(line, p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4318 if (spell_iswordp_nmw(p, curwin)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4319 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4320 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4321 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4322 // Go back to start of the word. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4323 while (p > line) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4324 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4325 col = (int)(p - line); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4326 MB_PTR_BACK(line, p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4327 if (!spell_iswordp(p, curwin)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4328 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4329 col = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4330 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4331 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4332 return col; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4333 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4334 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4335 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4336 * Need to check for 'spellcapcheck' now, the word is removed before |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4337 * expand_spelling() is called. Therefore the ugly global variable. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4338 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4339 static int spell_expand_need_cap; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4340 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4341 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4342 spell_expand_check_cap(colnr_T col) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4343 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4344 spell_expand_need_cap = check_need_cap(curwin, curwin->w_cursor.lnum, col); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4345 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4346 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4347 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4348 * Get list of spelling suggestions. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4349 * Used for Insert mode completion CTRL-X ?. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4350 * Returns the number of matches. The matches are in "matchp[]", array of |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4351 * allocated strings. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4352 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4353 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4354 expand_spelling( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4355 linenr_T lnum UNUSED, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4356 char_u *pat, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4357 char_u ***matchp) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4358 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4359 garray_T ga; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4360 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4361 spell_suggest_list(&ga, pat, 100, spell_expand_need_cap, TRUE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4362 *matchp = ga.ga_data; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4363 return ga.ga_len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4364 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4365 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4366 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4367 * Return TRUE if "val" is a valid 'spelllang' value. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4368 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4369 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4370 valid_spelllang(char_u *val) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4371 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4372 return valid_name(val, ".-_,@"); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4373 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4374 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4375 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4376 * Return TRUE if "val" is a valid 'spellfile' value. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4377 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4378 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4379 valid_spellfile(char_u *val) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4380 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4381 char_u *s; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4382 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4383 for (s = val; *s != NUL; ++s) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4384 if (!vim_is_fname_char(*s)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4385 return FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4386 return TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4387 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4388 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4389 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4390 * Handle side effects of setting 'spell' or 'spellfile' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4391 * Return an error message or NULL for success. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4392 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4393 char * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4394 did_set_spell_option(int is_spellfile) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4395 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4396 char *errmsg = NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4397 win_T *wp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4398 int l; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4399 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4400 if (is_spellfile) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4401 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4402 l = (int)STRLEN(curwin->w_s->b_p_spf); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4403 if (l > 0 && (l < 4 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4404 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4405 errmsg = e_invalid_argument; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4406 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4407 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4408 if (errmsg != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4409 return errmsg; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4410 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4411 FOR_ALL_WINDOWS(wp) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4412 if (wp->w_buffer == curbuf && wp->w_p_spell) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4413 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4414 errmsg = parse_spelllang(wp); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4415 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4416 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4417 return errmsg; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4418 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4419 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4420 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4421 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4422 * Return error message when failed, NULL when OK. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4423 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4424 char * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4425 compile_cap_prog(synblock_T *synblock) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4426 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4427 regprog_T *rp = synblock->b_cap_prog; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4428 char_u *re; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4429 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4430 if (synblock->b_p_spc == NULL || *synblock->b_p_spc == NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4431 synblock->b_cap_prog = NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4432 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4433 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4434 // Prepend a ^ so that we only match at one column |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4435 re = concat_str((char_u *)"^", synblock->b_p_spc); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4436 if (re != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4437 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4438 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4439 vim_free(re); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4440 if (synblock->b_cap_prog == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4441 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4442 synblock->b_cap_prog = rp; // restore the previous program |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4443 return e_invalid_argument; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4444 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4445 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4446 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4447 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4448 vim_regfree(rp); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4449 return NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4450 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4451 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32564
diff
changeset
|
4452 #endif // FEAT_SPELL |