annotate src/spell.c @ 231:8eec9649b7a2 v7.0064

updated for version 7.0064
author vimboss
date Fri, 25 Mar 2005 21:58:17 +0000
parents 723a01584c3e
children fca8a9b65afa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4:
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
2 *
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
4 *
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
8 */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
9
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
10 /*
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
11 * spell.c: code for spell checking
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
12 *
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
13 * Terminology:
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
14 * "dword" is a dictionary word, made out of letters and digits.
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
15 * "nword" is a word with a character that's not a letter or digit.
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
16 * "word" is either a "dword" or an "nword".
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
17 */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
18
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
19 #if defined(MSDOS) || defined(WIN16) || defined(WIN32) || defined(_WIN64)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
20 # include <io.h> /* for lseek(), must be before vim.h */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
21 #endif
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
22
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
23 #include "vim.h"
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
24
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
25 #if defined(FEAT_SYN_HL) || defined(PROTO)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
26
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
27 #ifdef HAVE_FCNTL_H
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
28 # include <fcntl.h>
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
29 #endif
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
30
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
31 #define MAXWLEN 100 /* assume max. word len is this many bytes */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
32
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
33 /*
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
34 * Structure that is used to store the text from the language file. This
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
35 * avoids the need to allocate each individual word and copying it. It's
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
36 * allocated in big chunks for speed.
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
37 */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
38 #define SBLOCKSIZE 4096 /* default size of sb_data */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
39 typedef struct sblock_S sblock_T;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
40 struct sblock_S
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
41 {
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
42 sblock_T *sb_next; /* next block in list */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
43 char_u sb_data[1]; /* data, actually longer */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
44 };
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
45
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
46 /* Structure to store words and additions. Used twice : once for case-folded
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
47 * and once for keep-case words. */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
48 typedef struct winfo_S
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
49 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
50 hashtab_T wi_ht; /* hashtable with all words, both dword_T and
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
51 nword_T (check flags for DW_NWORD) */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
52 garray_T wi_add; /* table with pointers to additions in a
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
53 dword_T */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
54 int wi_addlen; /* longest addition length */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
55 } winfo_T;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
56
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
57 /*
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
58 * Structure used to store words and other info for one language.
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
59 */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
60 typedef struct slang_S slang_T;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
61 struct slang_S
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
62 {
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
63 slang_T *sl_next; /* next language */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
64 char_u sl_name[2]; /* language name "en", "nl", etc. */
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
65 winfo_T sl_fwords; /* case-folded words and additions */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
66 winfo_T sl_kwords; /* keep-case words and additions */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
67 char_u sl_regions[17]; /* table with up to 8 region names plus NUL */
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
68 sblock_T *sl_block; /* list with allocated memory blocks */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
69 };
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
70
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
71 static slang_T *first_lang = NULL;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
72
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
73 /* Entry for dword in "sl_ht". Also used for part of an nword, starting with
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
74 * the first non-word character. And used for additions in wi_add. */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
75 typedef struct dword_S
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
76 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
77 char_u dw_region; /* one bit per region where it's valid */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
78 char_u dw_flags; /* WF_ flags */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
79 char_u dw_word[1]; /* actually longer, NUL terminated */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
80 } dword_T;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
81
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
82 #define REGION_ALL 0xff
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
83
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
84 #define HI2DWORD(hi) (dword_T *)(hi->hi_key - 2)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
85
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
86 /* Entry for a nword in "sl_ht". Note that the last three items must be
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
87 * identical to dword_T, so that they can be in the same hashtable. */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
88 typedef struct nword_S
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
89 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
90 garray_T nw_ga; /* table with pointers to dword_T for part
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
91 starting with non-word character */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
92 int nw_maxlen; /* longest nword length (after the dword) */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
93 char_u nw_region; /* one bit per region where it's valid */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
94 char_u nw_flags; /* WF_ flags */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
95 char_u nw_word[1]; /* actually longer, NUL terminated */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
96 } nword_T;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
97
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
98 /* Get nword_T pointer from hashitem that uses nw_word */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
99 static nword_T dumnw;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
100 #define HI2NWORD(hi) ((nword_T *)((hi)->hi_key - (dumnw.nw_word - (char_u *)&dumnw)))
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
101
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
102 #define DW_CAP 0x01 /* word must start with capital */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
103 #define DW_RARE 0x02 /* rare word */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
104 #define DW_NWORD 0x04 /* this is an nword_T */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
105 #define DW_DWORD 0x08 /* (also) use as dword without nword */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
106
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
107 /*
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
108 * Structure used in "b_langp", filled from 'spelllang'.
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
109 */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
110 typedef struct langp_S
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
111 {
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
112 slang_T *lp_slang; /* info for this language (NULL for last one) */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
113 int lp_region; /* bitmask for region or REGION_ALL */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
114 } langp_T;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
115
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
116 #define LANGP_ENTRY(ga, i) (((langp_T *)(ga).ga_data) + (i))
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
117 #define DWORD_ENTRY(gap, i) *(((dword_T **)(gap)->ga_data) + i)
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
118
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
119 #define SP_OK 0
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
120 #define SP_BAD 1
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
121 #define SP_RARE 2
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
122 #define SP_LOCAL 3
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
123
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
124 static char *e_invchar2 = N_("E753: Invalid character in \"%s\"");
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
125
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
126 static slang_T *spell_load_lang __ARGS((char_u *lang));
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
127 static void spell_load_file __ARGS((char_u *fname));
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
128 static int find_region __ARGS((char_u *rp, char_u *region));
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
129
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
130 /*
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
131 * Main spell-checking function.
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
132 * "ptr" points to the start of a word.
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
133 * "*attrp" is set to the attributes for a badly spelled word. For a non-word
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
134 * or when it's OK it remains unchanged.
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
135 * This must only be called when 'spelllang' is not empty.
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
136 * Returns the length of the word in bytes, also when it's OK, so that the
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
137 * caller can skip over the word.
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
138 */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
139 int
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
140 spell_check(wp, ptr, attrp)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
141 win_T *wp; /* current window */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
142 char_u *ptr;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
143 int *attrp;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
144 {
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
145 char_u *e; /* end of word */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
146 char_u *ne; /* new end of word */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
147 char_u *me; /* max. end of match */
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
148 langp_T *lp;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
149 int result;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
150 int len = 0;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
151 hashitem_T *hi;
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
152 int round;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
153 char_u kword[MAXWLEN + 1]; /* word copy */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
154 char_u fword[MAXWLEN + 1]; /* word with case folded */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
155 char_u match[MAXWLEN + 1]; /* fword with additional chars */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
156 char_u kwordclen[MAXWLEN + 1]; /* len of orig chars after kword[] */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
157 char_u fwordclen[MAXWLEN + 1]; /* len of chars after fword[] */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
158 char_u *clen;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
159 int cidx = 0; /* char index in xwordclen[] */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
160 hash_T fhash; /* hash for fword */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
161 hash_T khash; /* hash for kword */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
162 int match_len = 0; /* length of match[] */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
163 int fmatch_len = 0; /* length of nword match in chars */
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
164 garray_T *gap;
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
165 int l, t;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
166 char_u *p, *tp;
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
167 int n;
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
168 dword_T *dw;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
169 dword_T *tdw;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
170 winfo_T *wi;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
171 nword_T *nw;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
172 int w_isupper;
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
173
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
174 /* Find the end of the word. We already know that *ptr is a word char. */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
175 e = ptr;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
176 do
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
177 {
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
178 mb_ptr_adv(e);
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
179 ++len;
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
180 } while (*e != NUL && spell_iswordc(e));
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
181
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
182 /* A word starting with a number is always OK. */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
183 if (*ptr >= '0' && *ptr <= '9')
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
184 return (int)(e - ptr);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
185
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
186 #ifdef FEAT_MBYTE
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
187 w_isupper = MB_ISUPPER(mb_ptr2char(ptr));
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
188 #else
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
189 w_isupper = MB_ISUPPER(*ptr);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
190 #endif
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
191
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
192 /* Make a copy of the word so that it can be NUL terminated.
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
193 * Compute hash value. */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
194 mch_memmove(kword, ptr, e - ptr);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
195 kword[e - ptr] = NUL;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
196 khash = hash_hash(kword);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
197
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
198 /* Make case-folded copy of the Word. Compute its hash value. */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
199 (void)str_foldcase(ptr, e - ptr, fword, MAXWLEN + 1);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
200 fhash = hash_hash(fword);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
201
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
202 /* Further case-folded characters to check for an nword match go in
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
203 * match[]. */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
204 me = e;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
205
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
206 /* "ne" is the end for the longest match */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
207 ne = e;
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
208
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
209 /* The word is bad unless we find it in the dictionary. */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
210 result = SP_BAD;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
211
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
212 /*
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
213 * Loop over the languages specified in 'spelllang'.
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
214 * We check them all, because a matching nword may be longer than an
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
215 * already found dword or nword.
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
216 */
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
217 for (lp = LANGP_ENTRY(wp->w_buffer->b_langp, 0); lp->lp_slang != NULL; ++lp)
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
218 {
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
219 /*
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
220 * Check for a matching word in the hashtable.
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
221 * Check both the keep-case word and the fold-case word.
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
222 */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
223 for (round = 0; round <= 1; ++round)
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
224 {
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
225 if (round == 0)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
226 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
227 wi = &lp->lp_slang->sl_kwords;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
228 hi = hash_lookup(&wi->wi_ht, kword, khash);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
229 }
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
230 else
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
231 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
232 wi = &lp->lp_slang->sl_fwords;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
233 hi = hash_lookup(&wi->wi_ht, fword, fhash);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
234 }
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
235 if (!HASHITEM_EMPTY(hi))
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
236 {
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
237 /*
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
238 * If this is an nword entry, check for match with remainder.
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
239 */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
240 dw = HI2DWORD(hi);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
241 if (dw->dw_flags & DW_NWORD)
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
242 {
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
243 /* If the word is not defined as a dword we must find an
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
244 * nword. */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
245 if ((dw->dw_flags & DW_DWORD) == 0)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
246 dw = NULL;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
247
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
248 /* Fold more characters when needed for the nword. Need
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
249 * to do one extra to check for a non-word character after
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
250 * the nword. Also keep the byte-size of each character,
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
251 * both before and after folding case. */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
252 nw = HI2NWORD(hi);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
253 while ((round == 0
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
254 ? me - e <= nw->nw_maxlen
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
255 : match_len <= nw->nw_maxlen)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
256 && *me != NUL)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
257 {
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
258 #ifdef FEAT_MBYTE
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
259 l = mb_ptr2len_check(me);
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
260 #else
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
261 l = 1;
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
262 #endif
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
263 (void)str_foldcase(me, l, match + match_len,
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
264 MAXWLEN - match_len + 1);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
265 me += l;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
266 kwordclen[cidx] = l;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
267 fwordclen[cidx] = STRLEN(match + match_len);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
268 match_len += fwordclen[cidx];
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
269 ++cidx;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
270 }
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
271
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
272 if (round == 0)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
273 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
274 clen = kwordclen;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
275 tp = e;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
276 }
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
277 else
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
278 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
279 clen = fwordclen;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
280 tp = match;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
281 }
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
282
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
283 /* Match with each item. The longest match wins:
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
284 * "you've" is longer than "you". */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
285 gap = &nw->nw_ga;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
286 for (t = 0; t < gap->ga_len; ++t)
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
287 {
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
288 /* Skip entries with wrong case for first char.
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
289 * Continue if it's a rare word without a captial. */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
290 tdw = DWORD_ENTRY(gap, t);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
291 if ((tdw->dw_flags & (DW_CAP | DW_RARE)) == DW_CAP
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
292 && !w_isupper)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
293 continue;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
294
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
295 p = tdw->dw_word;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
296 l = 0;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
297 for (n = 0; p[n] != 0; n += clen[l++])
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
298 if (vim_memcmp(p + n, tp + n, clen[l]) != 0)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
299 break;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
300
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
301 /* Use a match if it's longer than previous matches
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
302 * and the next character is not a word character. */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
303 if (p[n] == 0 && l > fmatch_len && (tp[n] == 0
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
304 || !spell_iswordc(tp + n)))
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
305 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
306 dw = tdw;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
307 fmatch_len = l;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
308 if (round == 0)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
309 ne = tp + n;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
310 else
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
311 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
312 /* Need to use the length of the original
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
313 * chars, not the fold-case ones. */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
314 ne = e;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
315 for (l = 0; l < fmatch_len; ++l)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
316 ne += kwordclen[l];
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
317 }
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
318 if ((lp->lp_region & tdw->dw_region) == 0)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
319 result = SP_LOCAL;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
320 else if ((tdw->dw_flags & DW_CAP) && !w_isupper)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
321 result = SP_RARE;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
322 else
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
323 result = SP_OK;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
324 }
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
325 }
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
326
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
327 }
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
328
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
329 if (dw != NULL)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
330 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
331 if (dw->dw_flags & DW_CAP)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
332 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
333 /* Need to check first letter is uppercase. If it is,
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
334 * check region. If it isn't it may be a rare word.
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
335 * */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
336 if (w_isupper)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
337 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
338 if ((dw->dw_region & lp->lp_region) == 0)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
339 result = SP_LOCAL;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
340 else
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
341 result = SP_OK;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
342 }
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
343 else if (dw->dw_flags & DW_RARE)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
344 result = SP_RARE;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
345 }
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
346 else
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
347 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
348 if ((dw->dw_region & lp->lp_region) == 0)
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
349 result = SP_LOCAL;
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
350 else if (dw->dw_flags & DW_RARE)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
351 result = SP_RARE;
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
352 else
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
353 result = SP_OK;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
354 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
355 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
356 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
357 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
358
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
359 /*
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
360 * Check for an addition.
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
361 * Only after a dword, not after an nword.
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
362 * Check both the keep-case word and the fold-case word.
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
363 */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
364 if (fmatch_len == 0)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
365 for (round = 0; round <= 1; ++round)
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
366 {
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
367 if (round == 0)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
368 wi = &lp->lp_slang->sl_kwords;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
369 else
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
370 wi = &lp->lp_slang->sl_fwords;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
371 gap = &wi->wi_add;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
372 if (gap->ga_len == 0) /* no additions, skip quickly */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
373 continue;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
374
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
375 /* Fold characters when needed for the addition. Need to do one
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
376 * extra to check for a word character after the addition. */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
377 while ((round == 0
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
378 ? me - e <= wi->wi_addlen
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
379 : match_len <= wi->wi_addlen)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
380 && *me != NUL)
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
381 {
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
382 #ifdef FEAT_MBYTE
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
383 l = mb_ptr2len_check(me);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
384 #else
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
385 l = 1;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
386 #endif
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
387 (void)str_foldcase(me, l, match + match_len,
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
388 MAXWLEN - match_len + 1);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
389 me += l;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
390 kwordclen[cidx] = l;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
391 fwordclen[cidx] = STRLEN(match + match_len);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
392 match_len += fwordclen[cidx];
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
393 ++cidx;
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
394 }
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
395
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
396 if (round == 0)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
397 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
398 clen = kwordclen;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
399 tp = e;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
400 }
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
401 else
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
402 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
403 clen = fwordclen;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
404 tp = match;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
405 }
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
406
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
407 /* Addition lookup. Uses a linear search, there should be
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
408 * very few. If there is a match adjust "ne" to the end.
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
409 * This doesn't change whether a word was good or bad, only
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
410 * the length. */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
411 for (t = 0; t < gap->ga_len; ++t)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
412 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
413 tdw = DWORD_ENTRY(gap, t);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
414 p = tdw->dw_word;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
415 l = 0;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
416 for (n = 0; p[n] != 0; n += clen[l++])
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
417 if (vim_memcmp(p + n, tp + n, clen[l]) != 0)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
418 break;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
419
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
420 /* Use a match if it's longer than previous matches
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
421 * and the next character is not a word character. */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
422 if (p[n] == 0 && l > fmatch_len
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
423 && (tp[n] == 0 || !spell_iswordc(tp + n)))
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
424 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
425 fmatch_len = l;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
426 if (round == 0)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
427 ne = tp + n;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
428 else
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
429 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
430 /* Need to use the length of the original
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
431 * chars, not the fold-case ones. */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
432 ne = e;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
433 for (l = 0; l < fmatch_len; ++l)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
434 ne += kwordclen[l];
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
435 }
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
436 }
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
437 }
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
438 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
439 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
440
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
441 if (result != SP_OK)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
442 {
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
443 if (result == SP_BAD)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
444 *attrp = highlight_attr[HLF_SPB];
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
445 else if (result == SP_RARE)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
446 *attrp = highlight_attr[HLF_SPR];
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
447 else
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
448 *attrp = highlight_attr[HLF_SPL];
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
449 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
450
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
451 return (int)(ne - ptr);
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
452 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
453
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
454 static slang_T *load_lp; /* passed from spell_load_lang() to
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
455 spell_load_file() */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
456
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
457 /*
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
458 * Load language "lang[2]".
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
459 */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
460 static slang_T *
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
461 spell_load_lang(lang)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
462 char_u *lang;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
463 {
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
464 slang_T *lp;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
465 char_u fname_enc[80];
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
466 char_u fname_ascii[20];
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
467 char_u *p;
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
468 int r;
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
469
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
470 lp = (slang_T *)alloc(sizeof(slang_T));
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
471 if (lp != NULL)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
472 {
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
473 lp->sl_name[0] = lang[0];
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
474 lp->sl_name[1] = lang[1];
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
475 hash_init(&lp->sl_fwords.wi_ht);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
476 ga_init2(&lp->sl_fwords.wi_add, sizeof(dword_T *), 4);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
477 lp->sl_fwords.wi_addlen = 0;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
478 hash_init(&lp->sl_kwords.wi_ht);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
479 ga_init2(&lp->sl_kwords.wi_add, sizeof(dword_T *), 4);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
480 lp->sl_kwords.wi_addlen = 0;
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
481 lp->sl_regions[0] = NUL;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
482 lp->sl_block = NULL;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
483
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
484 /* Find all spell files for "lang" in 'runtimepath' and load them.
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
485 * Use 'encoding', except that we use "latin1" for "latin9". */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
486 #ifdef FEAT_MBYTE
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
487 if (STRLEN(p_enc) < 60 && STRCMP(p_enc, "iso-8859-15") != 0)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
488 p = p_enc;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
489 else
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
490 #endif
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
491 p = (char_u *)"latin1";
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
492 load_lp = lp;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
493 sprintf((char *)fname_enc, "spell/%c%c.%s.spl", lang[0], lang[1], p);
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
494 r = do_in_runtimepath(fname_enc, TRUE, spell_load_file);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
495 if (r == FAIL)
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
496 {
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
497 /* Try again to find an ASCII spell file. */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
498 sprintf((char *)fname_ascii, "spell/%c%c.spl", lang[0], lang[1]);
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
499 r = do_in_runtimepath(fname_ascii, TRUE, spell_load_file);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
500 }
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
501
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
502 if (r == FAIL)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
503 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
504 vim_free(lp);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
505 lp = NULL;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
506 smsg((char_u *)_("Warning: Cannot find dictionary \"%s\""),
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
507 fname_enc + 6);
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
508 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
509 else
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
510 {
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
511 lp->sl_next = first_lang;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
512 first_lang = lp;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
513 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
514 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
515
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
516 return lp;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
517 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
518
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
519 /*
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
520 * Load one spell file into "load_lp".
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
521 * Invoked through do_in_runtimepath().
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
522 */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
523 static void
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
524 spell_load_file(fname)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
525 char_u *fname;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
526 {
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
527 int fd;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
528 size_t len;
229
723a01584c3e updated for version 7.0064
vimboss
parents: 226
diff changeset
529 int l;
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
530 char_u *p = NULL, *np;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
531 sblock_T *bl = NULL;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
532 int bl_used = 0;
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
533 size_t rest = 0;
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
534 char_u *rbuf; /* read buffer */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
535 char_u *rbuf_end; /* past last valid char in "rbuf" */
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
536 hash_T hash;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
537 hashitem_T *hi;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
538 int c;
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
539 int cc;
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
540 int region = REGION_ALL;
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
541 int wlen;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
542 winfo_T *wi;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
543 dword_T *dw, *edw;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
544 nword_T *nw = NULL;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
545 int flags;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
546 char_u *save_sourcing_name = sourcing_name;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
547 linenr_T save_sourcing_lnum = sourcing_lnum;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
548
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
549 rbuf = alloc((unsigned)(SBLOCKSIZE + MAXWLEN + 1));
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
550 if (rbuf == NULL)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
551 return;
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
552
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
553 fd = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0);
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
554 if (fd < 0)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
555 {
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
556 EMSG2(_(e_notopen), fname);
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
557 goto theend;
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
558 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
559
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
560 sourcing_name = fname;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
561 sourcing_lnum = 0;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
562
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
563 /* Get the length of the whole file. */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
564 len = lseek(fd, (off_t)0, SEEK_END);
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
565 lseek(fd, (off_t)0, SEEK_SET);
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
566
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
567 /*
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
568 * Read the file one block at a time.
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
569 * "rest" is the length of an incomplete line at the previous block.
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
570 * "p" points to the remainder.
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
571 */
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
572 while (len > 0)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
573 {
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
574 /* Read a block from the file. Prepend the remainder of the previous
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
575 * block, if any. */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
576 if (rest > 0)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
577 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
578 if (rest > MAXWLEN) /* truncate long line (should be comment) */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
579 rest = MAXWLEN;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
580 mch_memmove(rbuf, p, rest);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
581 --sourcing_lnum;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
582 }
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
583 if (len > SBLOCKSIZE)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
584 l = SBLOCKSIZE;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
585 else
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
586 l = len;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
587 len -= l;
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
588 if (read(fd, rbuf + rest, l) != l)
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
589 {
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
590 EMSG2(_(e_notread), fname);
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
591 break;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
592 }
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
593 rbuf_end = rbuf + l + rest;
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
594 rest = 0;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
595
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
596 /* Deal with each line that was read until we finish the block. */
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
597 for (p = rbuf; p < rbuf_end; p = np)
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
598 {
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
599 ++sourcing_lnum;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
600
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
601 /* "np" points to the first char after the line (CR, NL or white
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
602 * space). */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
603 for (np = p; np < rbuf_end && *np >= ' '; mb_ptr_adv(np))
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
604 ;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
605 if (np >= rbuf_end)
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
606 {
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
607 /* Incomplete line or end of file. */
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
608 rest = np - p;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
609 if (len == 0)
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
610 EMSG(_("E751: Truncated spell file"));
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
611 break;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
612 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
613 *np = NUL; /* terminate the line with a NUL */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
614
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
615 if (*p == '-')
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
616 {
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
617 /*
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
618 * Region marker: ---, -xx, -xx-yy, etc.
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
619 */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
620 ++p;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
621 if (*p == '-')
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
622 {
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
623 if (p[1] != '-' || p[2] != NUL)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
624 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
625 EMSG2(_(e_invchar2), p - 1);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
626 len = 0;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
627 break;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
628 }
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
629 region = REGION_ALL;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
630 }
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
631 else
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
632 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
633 char_u *rp = load_lp->sl_regions;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
634 int r;
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
635
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
636 /* Start of a region. The region may be repeated:
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
637 * "-ca-uk". Fill "region" with the bit mask for the
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
638 * ones we find. */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
639 region = 0;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
640 for (;;)
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
641 {
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
642 r = find_region(rp, p);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
643 if (r == REGION_ALL)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
644 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
645 /* new region, add it to sl_regions[] */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
646 r = STRLEN(rp);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
647 if (r >= 16)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
648 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
649 EMSG2(_("E752: Too many regions: %s"), p);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
650 len = 0;
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
651 break;
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
652 }
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
653 else
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
654 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
655 rp[r] = p[0];
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
656 rp[r + 1] = p[1];
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
657 rp[r + 2] = NUL;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
658 r = 1 << (r / 2);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
659 }
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
660 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
661 else
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
662 r = 1 << r;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
663
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
664 region |= r;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
665 if (p[2] != '-')
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
666 {
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
667 if (p[2] > ' ')
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
668 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
669 EMSG2(_(e_invchar2), p - 1);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
670 len = 0;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
671 }
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
672 break;
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
673 }
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
674 p += 3;
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
675 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
676 }
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
677 }
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
678 else if (*p != '#' && *p != NUL)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
679 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
680 /*
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
681 * Not an empty line or comment.
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
682 */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
683 if (*p == '!')
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
684 {
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
685 wi = &load_lp->sl_kwords; /* keep case */
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
686 ++p;
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
687 }
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
688 else
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
689 wi = &load_lp->sl_fwords; /* fold case */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
690
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
691 flags = 0;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
692 c = *p;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
693 if (c == '>') /* rare word */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
694 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
695 flags = DW_RARE;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
696 ++p;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
697 }
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
698 else if (*p == '+') /* addition */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
699 ++p;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
700
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
701 if (c != '+' && !spell_iswordc(p))
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
702 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
703 EMSG2(_(e_invchar2), p);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
704 len = 0;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
705 break;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
706 }
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
707
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
708 /* Make sure there is room for the word. Folding case may
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
709 * double the size. */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
710 wlen = np - p;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
711 if (bl == NULL || bl_used + sizeof(dword_T) + wlen
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
712 #ifdef FEAT_MBYTE
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
713 * (has_mbyte ? 2 : 1)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
714 #endif
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
715 >= SBLOCKSIZE)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
716 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
717 /* Allocate a block of memory to store the dword_T in.
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
718 * This is not freed until spell_reload() is called. */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
719 bl = (sblock_T *)alloc((unsigned)(sizeof(sblock_T)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
720 + SBLOCKSIZE));
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
721 if (bl == NULL)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
722 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
723 len = 0;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
724 break;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
725 }
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
726 bl->sb_next = load_lp->sl_block;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
727 load_lp->sl_block = bl;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
728 bl_used = 0;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
729 }
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
730 dw = (dword_T *)(bl->sb_data + bl_used);
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
731
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
732 /* For fold-case words fold the case and check for start
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
733 * with uppercase letter. */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
734 if (wi == &load_lp->sl_fwords)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
735 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
736 #ifdef FEAT_MBYTE
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
737 if (MB_ISUPPER(mb_ptr2char(p)))
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
738 #else
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
739 if (MB_ISUPPER(*p))
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
740 #endif
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
741 flags |= DW_CAP;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
742
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
743 /* Fold case. */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
744 (void)str_foldcase(p, np - p, dw->dw_word, wlen
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
745 #ifdef FEAT_MBYTE
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
746 * (has_mbyte ? 2 : 1)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
747 #endif
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
748 + 1);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
749 #ifdef FEAT_MBYTE
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
750 /* case folding may change length of word */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
751 wlen = STRLEN(dw->dw_word);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
752 #endif
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
753 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
754 else
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
755 {
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
756 /* Keep case: copy the word as-is. */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
757 mch_memmove(dw->dw_word, p, wlen + 1);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
758 }
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
759
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
760 if (c == '+')
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
761 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
762 garray_T *gap = &wi->wi_add;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
763
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
764 /* Addition. TODO: search for matching entry? */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
765 if (wi->wi_addlen < wlen)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
766 wi->wi_addlen = wlen;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
767 if (ga_grow(gap, 1) == FAIL)
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
768 {
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
769 len = 0;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
770 break;
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
771 }
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
772 *(((dword_T **)gap->ga_data) + gap->ga_len) = dw;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
773 ++gap->ga_len;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
774 dw->dw_region = region;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
775 dw->dw_flags = flags;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
776 bl_used += sizeof(dword_T) + wlen;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
777 }
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
778 else
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
779 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
780 /*
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
781 * Check for a non-word character. If found it's
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
782 * going to be an nword.
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
783 * For an nword we split in two: the leading dword and
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
784 * the remainder. The dword goes in the hashtable
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
785 * with an nword_T, the remainder is put in the
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
786 * dword_T (starting with the first non-word
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
787 * character).
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
788 */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
789 cc = NUL;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
790 for (p = dw->dw_word; *p != NUL; mb_ptr_adv(p))
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
791 if (!spell_iswordc(p))
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
792 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
793 cc = *p;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
794 *p = NUL;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
795 break;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
796 }
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
797
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
798 /* check if we already have this dword */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
799 hash = hash_hash(dw->dw_word);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
800 hi = hash_lookup(&wi->wi_ht, dw->dw_word, hash);
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
801 if (!HASHITEM_EMPTY(hi))
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
802 {
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
803 /* Existing entry. */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
804 edw = HI2DWORD(hi);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
805 if ((edw->dw_flags & (DW_CAP | DW_RARE))
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
806 == (dw->dw_flags & (DW_CAP | DW_RARE)))
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
807 {
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
808 if (p_verbose > 0)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
809 smsg((char_u *)_("Warning: duplicate word \"%s\" in %s"),
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
810 dw->dw_word, fname);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
811 }
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
812 }
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
813
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
814 if (cc != NUL) /* nword */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
815 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
816 if (HASHITEM_EMPTY(hi)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
817 || (edw->dw_flags & DW_NWORD) == 0)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
818 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
819 sblock_T *sb;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
820
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
821 /* Need to allocate a new nword_T. Put it in an
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
822 * sblock_T, so that we can free it later. */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
823 sb = (sblock_T *)alloc(
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
824 (unsigned)(sizeof(sblock_T)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
825 + sizeof(nword_T) + wlen));
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
826 if (sb == NULL)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
827 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
828 len = 0;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
829 break;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
830 }
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
831 sb->sb_next = load_lp->sl_block;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
832 load_lp->sl_block = sb;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
833 nw = (nword_T *)sb->sb_data;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
834
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
835 ga_init2(&nw->nw_ga, sizeof(dword_T *), 4);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
836 nw->nw_maxlen = 0;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
837 STRCPY(nw->nw_word, dw->dw_word);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
838 if (!HASHITEM_EMPTY(hi))
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
839 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
840 /* Note: the nw_region and nw_flags is for
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
841 * the dword that matches with the start
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
842 * of this nword, not for the nword
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
843 * itself! */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
844 nw->nw_region = edw->dw_region;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
845 nw->nw_flags = edw->dw_flags | DW_NWORD;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
846
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
847 /* Remove the dword item so that we can
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
848 * add it as an nword. */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
849 hash_remove(&wi->wi_ht, hi);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
850 hi = hash_lookup(&wi->wi_ht,
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
851 nw->nw_word, hash);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
852 }
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
853 else
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
854 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
855 nw->nw_region = 0;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
856 nw->nw_flags = DW_NWORD;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
857 }
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
858 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
859 else
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
860 nw = HI2NWORD(hi);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
861 }
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
862
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
863 if (HASHITEM_EMPTY(hi))
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
864 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
865 /* Add new dword or nword entry. */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
866 hash_add_item(&wi->wi_ht, hi, cc == NUL
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
867 ? dw->dw_word : nw->nw_word, hash);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
868 if (cc == NUL)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
869 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
870 /* New dword: init the values and count the
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
871 * used space. */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
872 dw->dw_flags = DW_DWORD | flags;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
873 dw->dw_region = region;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
874 bl_used += sizeof(dword_T) + wlen;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
875 }
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
876 }
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
877 else if (cc == NUL)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
878 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
879 /* existing dword: add the region and flags */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
880 dw = edw;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
881 dw->dw_region |= region;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
882 dw->dw_flags |= DW_DWORD | flags;
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
883 }
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
884
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
885 if (cc != NUL)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
886 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
887 /* Use the dword for the non-word character and
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
888 * following characters. */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
889 dw->dw_region = region;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
890 dw->dw_flags = flags;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
891 STRCPY(dw->dw_word + 1, p + 1);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
892 dw->dw_word[0] = cc;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
893 l = wlen - (p - dw->dw_word);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
894 bl_used += sizeof(dword_T) + l;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
895 if (nw->nw_maxlen < l)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
896 nw->nw_maxlen = l;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
897
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
898 /* Add the dword to the growarray in the nword. */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
899 if (ga_grow(&nw->nw_ga, 1) == FAIL)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
900 {
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
901 len = 0;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
902 break;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
903 }
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
904 *((dword_T **)nw->nw_ga.ga_data + nw->nw_ga.ga_len)
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
905 = dw;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
906 ++nw->nw_ga.ga_len;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
907 }
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
908 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
909 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
910
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
911 /* Skip over CR and NL characters and trailing white space. */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
912 while (np < rbuf_end && *np <= ' ')
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
913 ++np;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
914 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
915 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
916
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
917 close(fd);
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
918 theend:
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
919 sourcing_name = save_sourcing_name;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
920 sourcing_lnum = save_sourcing_lnum;
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
921 vim_free(rbuf);
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
922 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
923
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
924 /*
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
925 * Parse 'spelllang' and set buf->b_langp accordingly.
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
926 * Returns an error message or NULL.
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
927 */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
928 char_u *
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
929 did_set_spelllang(buf)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
930 buf_T *buf;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
931 {
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
932 garray_T ga;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
933 char_u *lang;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
934 char_u *e;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
935 char_u *region;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
936 int region_mask;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
937 slang_T *lp;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
938 int c;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
939
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
940 ga_init2(&ga, sizeof(langp_T), 2);
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
941
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
942 /* loop over comma separated languages. */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
943 for (lang = buf->b_p_spl; *lang != NUL; lang = e)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
944 {
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
945 e = vim_strchr(lang, ',');
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
946 if (e == NULL)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
947 e = lang + STRLEN(lang);
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
948 if (e > lang + 2)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
949 {
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
950 if (lang[2] != '_' || e - lang != 5)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
951 {
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
952 ga_clear(&ga);
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
953 return e_invarg;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
954 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
955 region = lang + 3;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
956 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
957 else
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
958 region = NULL;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
959
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
960 for (lp = first_lang; lp != NULL; lp = lp->sl_next)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
961 if (STRNICMP(lp->sl_name, lang, 2) == 0)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
962 break;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
963
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
964 if (lp == NULL)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
965 /* Not found, load the language. */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
966 lp = spell_load_lang(lang);
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
967
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
968 if (lp != NULL)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
969 {
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
970 if (region == NULL)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
971 region_mask = REGION_ALL;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
972 else
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
973 {
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
974 /* find region in sl_regions */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
975 c = find_region(lp->sl_regions, region);
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
976 if (c == REGION_ALL)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
977 {
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
978 c = lang[5];
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
979 lang[5] = NUL;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
980 smsg((char_u *)_("Warning: region %s not supported"), lang);
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
981 lang[5] = c;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
982 region_mask = REGION_ALL;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
983 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
984 else
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
985 region_mask = 1 << c;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
986 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
987
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
988 if (ga_grow(&ga, 1) == FAIL)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
989 {
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
990 ga_clear(&ga);
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
991 return e_outofmem;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
992 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
993 LANGP_ENTRY(ga, ga.ga_len)->lp_slang = lp;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
994 LANGP_ENTRY(ga, ga.ga_len)->lp_region = region_mask;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
995 ++ga.ga_len;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
996 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
997
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
998 if (*e == ',')
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
999 ++e;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1000 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1001
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1002 /* Add a NULL entry to mark the end of the list. */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1003 if (ga_grow(&ga, 1) == FAIL)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1004 {
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1005 ga_clear(&ga);
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1006 return e_outofmem;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1007 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1008 LANGP_ENTRY(ga, ga.ga_len)->lp_slang = NULL;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1009 ++ga.ga_len;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1010
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1011 /* Everything is fine, store the new b_langp value. */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1012 ga_clear(&buf->b_langp);
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1013 buf->b_langp = ga;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1014
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1015 return NULL;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1016 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1017
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1018 /*
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1019 * Find the region "region[2]" in "rp" (points to "sl_regions").
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1020 * Each region is simply stored as the two characters of it's name.
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1021 * Returns the index if found, REGION_ALL if not found.
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1022 */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1023 static int
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1024 find_region(rp, region)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1025 char_u *rp;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1026 char_u *region;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1027 {
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1028 int i;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1029
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1030 for (i = 0; ; i += 2)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1031 {
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1032 if (rp[i] == NUL)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1033 return REGION_ALL;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1034 if (rp[i] == region[0] && rp[i + 1] == region[1])
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1035 break;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1036 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1037 return i / 2;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1038 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1039
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1040 # if defined(FEAT_MBYTE) || defined(PROTO)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1041 /*
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1042 * Clear all spelling tables and reload them.
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1043 * Used after 'encoding' is set.
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1044 */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1045 void
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1046 spell_reload()
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1047 {
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1048 buf_T *buf;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1049 slang_T *lp;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1050 sblock_T *sp;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1051
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
1052 /* Initialize the table for spell_iswordc(). */
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
1053 init_spell_chartab();
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
1054
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1055 /* Unload all allocated memory. */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1056 while (first_lang != NULL)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1057 {
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1058 lp = first_lang;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1059 first_lang = lp->sl_next;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1060
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
1061 hash_clear(&lp->sl_fwords.wi_ht);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
1062 ga_clear(&lp->sl_fwords.wi_add);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
1063 hash_clear(&lp->sl_kwords.wi_ht);
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
1064 ga_clear(&lp->sl_kwords.wi_add);
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1065 while (lp->sl_block != NULL)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1066 {
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1067 sp = lp->sl_block;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1068 lp->sl_block = sp->sb_next;
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1069 vim_free(sp);
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1070 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1071 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1072
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1073 /* Go through all buffers and handle 'spelllang'. */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1074 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1075 {
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1076 ga_clear(&buf->b_langp);
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1077 if (*buf->b_p_spl != NUL)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1078 did_set_spelllang(buf);
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1079 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1080 }
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1081 # endif
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1082
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1083 #endif /* FEAT_SYN_HL */