Mercurial > vim
annotate src/regexp.c @ 19506:8602a051c9bd
Added tag v8.2.0310 for changeset e7eec9cae0ea189c45b910ffa62ee6bac71fa29a
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 23 Feb 2020 16:30:04 +0100 |
parents | 08f4dc2ba716 |
children | 5feb426d2ea1 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9723
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * Handling of regular expressions: vim_regcomp(), vim_regexec(), vim_regsub() | |
4 */ | |
5 | |
16395
a849fe2a4b21
patch 8.1.1202: always get regexp debugging logs when building with -DDEBUG
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
6 // By default: do not create debugging logs or files related to regular |
a849fe2a4b21
patch 8.1.1202: always get regexp debugging logs when building with -DDEBUG
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
7 // expressions, even when compiling with -DDEBUG. |
a849fe2a4b21
patch 8.1.1202: always get regexp debugging logs when building with -DDEBUG
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
8 // Uncomment the second line to get the regexp debugging. |
a849fe2a4b21
patch 8.1.1202: always get regexp debugging logs when building with -DDEBUG
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
9 #undef DEBUG |
a849fe2a4b21
patch 8.1.1202: always get regexp debugging logs when building with -DDEBUG
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
10 // #define DEBUG |
4444 | 11 |
7 | 12 #include "vim.h" |
13 | |
4444 | 14 #ifdef DEBUG |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
15 // show/save debugging data when BT engine is used |
4444 | 16 # define BT_REGEXP_DUMP |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
17 // save the debugging data to a file instead of displaying it |
4444 | 18 # define BT_REGEXP_LOG |
4460 | 19 # define BT_REGEXP_DEBUG_LOG |
20 # define BT_REGEXP_DEBUG_LOG_NAME "bt_regexp_debug.log" | |
4444 | 21 #endif |
7 | 22 |
23 /* | |
24 * Magic characters have a special meaning, they don't match literally. | |
25 * Magic characters are negative. This separates them from literal characters | |
26 * (possibly multi-byte). Only ASCII characters can be Magic. | |
27 */ | |
28 #define Magic(x) ((int)(x) - 256) | |
29 #define un_Magic(x) ((x) + 256) | |
30 #define is_Magic(x) ((x) < 0) | |
31 | |
32 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
33 no_Magic(int x) |
7 | 34 { |
35 if (is_Magic(x)) | |
36 return un_Magic(x); | |
37 return x; | |
38 } | |
39 | |
40 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
41 toggle_Magic(int x) |
7 | 42 { |
43 if (is_Magic(x)) | |
44 return un_Magic(x); | |
45 return Magic(x); | |
46 } | |
47 | |
48 /* | |
18019
68fd5296bf73
patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
49 * The first byte of the BT regexp internal "program" is actually this magic |
7 | 50 * number; the start node begins in the second byte. It's used to catch the |
51 * most severe mutilation of the program by the caller. | |
52 */ | |
53 | |
54 #define REGMAGIC 0234 | |
55 | |
56 /* | |
57 * Utility definitions. | |
58 */ | |
59 #define UCHARAT(p) ((int)*(char_u *)(p)) | |
60 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
61 // Used for an error (down from) vim_regcomp(): give the error message, set |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
62 // rc_did_emsg and return NULL |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15339
diff
changeset
|
63 #define EMSG_RET_NULL(m) return (emsg((m)), rc_did_emsg = TRUE, (void *)NULL) |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15339
diff
changeset
|
64 #define IEMSG_RET_NULL(m) return (iemsg((m)), rc_did_emsg = TRUE, (void *)NULL) |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15339
diff
changeset
|
65 #define EMSG_RET_FAIL(m) return (emsg((m)), rc_did_emsg = TRUE, FAIL) |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15339
diff
changeset
|
66 #define EMSG2_RET_NULL(m, c) return (semsg((const char *)(m), (c) ? "" : "\\"), rc_did_emsg = TRUE, (void *)NULL) |
15480
bd12ace1bab2
patch 8.1.0748: using sprintf() instead of semsg()
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
67 #define EMSG3_RET_NULL(m, c, a) return (semsg((const char *)(m), (c) ? "" : "\\", (a)), rc_did_emsg = TRUE, (void *)NULL) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15339
diff
changeset
|
68 #define EMSG2_RET_FAIL(m, c) return (semsg((const char *)(m), (c) ? "" : "\\"), rc_did_emsg = TRUE, FAIL) |
4444 | 69 #define EMSG_ONE_RET_NULL EMSG2_RET_NULL(_("E369: invalid item in %s%%[]"), reg_magic == MAGIC_ALL) |
7 | 70 |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10245
diff
changeset
|
71 |
7 | 72 #define MAX_LIMIT (32767L << 16L) |
73 | |
4444 | 74 static char_u e_missingbracket[] = N_("E769: Missing ] after %s["); |
11480
99ce30ac4226
patch 8.0.0623: error for invalid regexp is not very informative
Christian Brabandt <cb@256bit.org>
parents:
11269
diff
changeset
|
75 static char_u e_reverse_range[] = N_("E944: Reverse range in character class"); |
99ce30ac4226
patch 8.0.0623: error for invalid regexp is not very informative
Christian Brabandt <cb@256bit.org>
parents:
11269
diff
changeset
|
76 static char_u e_large_class[] = N_("E945: Range too large in character class"); |
4444 | 77 static char_u e_unmatchedpp[] = N_("E53: Unmatched %s%%("); |
78 static char_u e_unmatchedp[] = N_("E54: Unmatched %s("); | |
79 static char_u e_unmatchedpar[] = N_("E55: Unmatched %s)"); | |
4720
bd6bef0bd0fb
updated for version 7.3.1107
Bram Moolenaar <bram@vim.org>
parents:
4688
diff
changeset
|
80 #ifdef FEAT_SYN_HL |
4688
371cc0c44097
updated for version 7.3.1091
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
81 static char_u e_z_not_allowed[] = N_("E66: \\z( not allowed here"); |
14161
7cac4646c552
patch 8.1.0098: segfault when pattern with z() is very slow
Christian Brabandt <cb@256bit.org>
parents:
13286
diff
changeset
|
82 static char_u e_z1_not_allowed[] = N_("E67: \\z1 - \\z9 not allowed here"); |
4720
bd6bef0bd0fb
updated for version 7.3.1107
Bram Moolenaar <bram@vim.org>
parents:
4688
diff
changeset
|
83 #endif |
4744
a62695305e03
updated for version 7.3.1119
Bram Moolenaar <bram@vim.org>
parents:
4732
diff
changeset
|
84 static char_u e_missing_sb[] = N_("E69: Missing ] after %s%%["); |
4760
532a9855bd30
updated for version 7.3.1127
Bram Moolenaar <bram@vim.org>
parents:
4746
diff
changeset
|
85 static char_u e_empty_sb[] = N_("E70: Empty %s%%[]"); |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
86 static char_u e_recursive[] = N_("E956: Cannot use pattern recursively"); |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
87 |
7 | 88 #define NOT_MULTI 0 |
89 #define MULTI_ONE 1 | |
90 #define MULTI_MULT 2 | |
18019
68fd5296bf73
patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
91 |
68fd5296bf73
patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
92 // return values for regmatch() |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
93 #define RA_FAIL 1 // something failed, abort |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
94 #define RA_CONT 2 // continue in inner loop |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
95 #define RA_BREAK 3 // break inner loop |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
96 #define RA_MATCH 4 // successful match |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
97 #define RA_NOMATCH 5 // didn't match |
18019
68fd5296bf73
patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
98 |
7 | 99 /* |
100 * Return NOT_MULTI if c is not a "multi" operator. | |
101 * Return MULTI_ONE if c is a single "multi" operator. | |
102 * Return MULTI_MULT if c is a multi "multi" operator. | |
103 */ | |
104 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
105 re_multi_type(int c) |
7 | 106 { |
107 if (c == Magic('@') || c == Magic('=') || c == Magic('?')) | |
108 return MULTI_ONE; | |
109 if (c == Magic('*') || c == Magic('+') || c == Magic('{')) | |
110 return MULTI_MULT; | |
111 return NOT_MULTI; | |
112 } | |
113 | |
359 | 114 static char_u *reg_prev_sub = NULL; |
115 | |
7 | 116 /* |
117 * REGEXP_INRANGE contains all characters which are always special in a [] | |
118 * range after '\'. | |
119 * REGEXP_ABBR contains all characters which act as abbreviations after '\'. | |
120 * These are: | |
121 * \n - New line (NL). | |
122 * \r - Carriage Return (CR). | |
123 * \t - Tab (TAB). | |
124 * \e - Escape (ESC). | |
125 * \b - Backspace (Ctrl_H). | |
24 | 126 * \d - Character code in decimal, eg \d123 |
127 * \o - Character code in octal, eg \o80 | |
128 * \x - Character code in hex, eg \x4a | |
129 * \u - Multibyte character code, eg \u20ac | |
130 * \U - Long multibyte character code, eg \U12345678 | |
7 | 131 */ |
132 static char_u REGEXP_INRANGE[] = "]^-n\\"; | |
24 | 133 static char_u REGEXP_ABBR[] = "nrtebdoxuU"; |
7 | 134 |
135 /* | |
136 * Translate '\x' to its control character, except "\n", which is Magic. | |
137 */ | |
138 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
139 backslash_trans(int c) |
7 | 140 { |
141 switch (c) | |
142 { | |
143 case 'r': return CAR; | |
144 case 't': return TAB; | |
145 case 'e': return ESC; | |
146 case 'b': return BS; | |
147 } | |
148 return c; | |
149 } | |
150 | |
151 /* | |
167 | 152 * Check for a character class name "[:name:]". "pp" points to the '['. |
7 | 153 * Returns one of the CLASS_ items. CLASS_NONE means that no item was |
154 * recognized. Otherwise "pp" is advanced to after the item. | |
155 */ | |
156 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
157 get_char_class(char_u **pp) |
7 | 158 { |
159 static const char *(class_names[]) = | |
160 { | |
161 "alnum:]", | |
162 #define CLASS_ALNUM 0 | |
163 "alpha:]", | |
164 #define CLASS_ALPHA 1 | |
165 "blank:]", | |
166 #define CLASS_BLANK 2 | |
167 "cntrl:]", | |
168 #define CLASS_CNTRL 3 | |
169 "digit:]", | |
170 #define CLASS_DIGIT 4 | |
171 "graph:]", | |
172 #define CLASS_GRAPH 5 | |
173 "lower:]", | |
174 #define CLASS_LOWER 6 | |
175 "print:]", | |
176 #define CLASS_PRINT 7 | |
177 "punct:]", | |
178 #define CLASS_PUNCT 8 | |
179 "space:]", | |
180 #define CLASS_SPACE 9 | |
181 "upper:]", | |
182 #define CLASS_UPPER 10 | |
183 "xdigit:]", | |
184 #define CLASS_XDIGIT 11 | |
185 "tab:]", | |
186 #define CLASS_TAB 12 | |
187 "return:]", | |
188 #define CLASS_RETURN 13 | |
189 "backspace:]", | |
190 #define CLASS_BACKSPACE 14 | |
191 "escape:]", | |
192 #define CLASS_ESCAPE 15 | |
15709
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
193 "ident:]", |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
194 #define CLASS_IDENT 16 |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
195 "keyword:]", |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
196 #define CLASS_KEYWORD 17 |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
197 "fname:]", |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
198 #define CLASS_FNAME 18 |
7 | 199 }; |
200 #define CLASS_NONE 99 | |
201 int i; | |
202 | |
203 if ((*pp)[1] == ':') | |
204 { | |
1877 | 205 for (i = 0; i < (int)(sizeof(class_names) / sizeof(*class_names)); ++i) |
7 | 206 if (STRNCMP(*pp + 2, class_names[i], STRLEN(class_names[i])) == 0) |
207 { | |
208 *pp += STRLEN(class_names[i]) + 2; | |
209 return i; | |
210 } | |
211 } | |
212 return CLASS_NONE; | |
213 } | |
214 | |
215 /* | |
216 * Specific version of character class functions. | |
217 * Using a table to keep this fast. | |
218 */ | |
219 static short class_tab[256]; | |
220 | |
221 #define RI_DIGIT 0x01 | |
222 #define RI_HEX 0x02 | |
223 #define RI_OCTAL 0x04 | |
224 #define RI_WORD 0x08 | |
225 #define RI_HEAD 0x10 | |
226 #define RI_ALPHA 0x20 | |
227 #define RI_LOWER 0x40 | |
228 #define RI_UPPER 0x80 | |
229 #define RI_WHITE 0x100 | |
230 | |
231 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
232 init_class_tab(void) |
7 | 233 { |
234 int i; | |
235 static int done = FALSE; | |
236 | |
237 if (done) | |
238 return; | |
239 | |
240 for (i = 0; i < 256; ++i) | |
241 { | |
242 if (i >= '0' && i <= '7') | |
243 class_tab[i] = RI_DIGIT + RI_HEX + RI_OCTAL + RI_WORD; | |
244 else if (i >= '8' && i <= '9') | |
245 class_tab[i] = RI_DIGIT + RI_HEX + RI_WORD; | |
246 else if (i >= 'a' && i <= 'f') | |
247 class_tab[i] = RI_HEX + RI_WORD + RI_HEAD + RI_ALPHA + RI_LOWER; | |
248 #ifdef EBCDIC | |
249 else if ((i >= 'g' && i <= 'i') || (i >= 'j' && i <= 'r') | |
250 || (i >= 's' && i <= 'z')) | |
251 #else | |
252 else if (i >= 'g' && i <= 'z') | |
253 #endif | |
254 class_tab[i] = RI_WORD + RI_HEAD + RI_ALPHA + RI_LOWER; | |
255 else if (i >= 'A' && i <= 'F') | |
256 class_tab[i] = RI_HEX + RI_WORD + RI_HEAD + RI_ALPHA + RI_UPPER; | |
257 #ifdef EBCDIC | |
258 else if ((i >= 'G' && i <= 'I') || ( i >= 'J' && i <= 'R') | |
259 || (i >= 'S' && i <= 'Z')) | |
260 #else | |
261 else if (i >= 'G' && i <= 'Z') | |
262 #endif | |
263 class_tab[i] = RI_WORD + RI_HEAD + RI_ALPHA + RI_UPPER; | |
264 else if (i == '_') | |
265 class_tab[i] = RI_WORD + RI_HEAD; | |
266 else | |
267 class_tab[i] = 0; | |
268 } | |
269 class_tab[' '] |= RI_WHITE; | |
270 class_tab['\t'] |= RI_WHITE; | |
271 done = TRUE; | |
272 } | |
273 | |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
274 #define ri_digit(c) (c < 0x100 && (class_tab[c] & RI_DIGIT)) |
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
275 #define ri_hex(c) (c < 0x100 && (class_tab[c] & RI_HEX)) |
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
276 #define ri_octal(c) (c < 0x100 && (class_tab[c] & RI_OCTAL)) |
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
277 #define ri_word(c) (c < 0x100 && (class_tab[c] & RI_WORD)) |
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
278 #define ri_head(c) (c < 0x100 && (class_tab[c] & RI_HEAD)) |
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
279 #define ri_alpha(c) (c < 0x100 && (class_tab[c] & RI_ALPHA)) |
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
280 #define ri_lower(c) (c < 0x100 && (class_tab[c] & RI_LOWER)) |
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
281 #define ri_upper(c) (c < 0x100 && (class_tab[c] & RI_UPPER)) |
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
282 #define ri_white(c) (c < 0x100 && (class_tab[c] & RI_WHITE)) |
7 | 283 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
284 // flags for regflags |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
285 #define RF_ICASE 1 // ignore case |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
286 #define RF_NOICASE 2 // don't ignore case |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
287 #define RF_HASNL 4 // can match a NL |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
288 #define RF_ICOMBINE 8 // ignore combining characters |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
289 #define RF_LOOKBH 16 // uses "\@<=" or "\@<!" |
7 | 290 |
291 /* | |
292 * Global work variables for vim_regcomp(). | |
293 */ | |
294 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
295 static char_u *regparse; // Input-scan pointer. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
296 static int regnpar; // () count. |
7 | 297 #ifdef FEAT_SYN_HL |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
298 static int regnzpar; // \z() count. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
299 static int re_has_z; // \z item detected |
7 | 300 #endif |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
301 static unsigned regflags; // RF_ flags for prog |
7 | 302 #if defined(FEAT_SYN_HL) || defined(PROTO) |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
303 static int had_eol; // TRUE when EOL found by vim_regcomp() |
7 | 304 #endif |
305 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
306 static int reg_magic; // magicness of the pattern: |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
307 #define MAGIC_NONE 1 // "\V" very unmagic |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
308 #define MAGIC_OFF 2 // "\M" or 'magic' off |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
309 #define MAGIC_ON 3 // "\m" or 'magic' |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
310 #define MAGIC_ALL 4 // "\v" very magic |
7 | 311 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
312 static int reg_string; // matching with a string instead of a buffer |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
313 // line |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
314 static int reg_strict; // "[abc" is illegal |
7 | 315 |
316 /* | |
317 * META contains all characters that may be magic, except '^' and '$'. | |
318 */ | |
319 | |
320 #ifdef EBCDIC | |
321 static char_u META[] = "%&()*+.123456789<=>?@ACDFHIKLMOPSUVWX[_acdfhiklmnopsuvwxz{|~"; | |
322 #else | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
323 // META[] is used often enough to justify turning it into a table. |
7 | 324 static char_u META_flags[] = { |
325 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
326 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
327 // % & ( ) * + . |
7 | 328 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
329 // 1 2 3 4 5 6 7 8 9 < = > ? |
7 | 330 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
331 // @ A C D F H I K L M O |
7 | 332 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
333 // P S U V W X Z [ _ |
7 | 334 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
335 // a c d f h i k l m n o |
7 | 336 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
337 // p s u v w x z { | ~ |
7 | 338 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1 |
339 }; | |
340 #endif | |
341 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
342 static int curchr; // currently parsed character |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
343 // Previous character. Note: prevchr is sometimes -1 when we are not at the |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
344 // start, eg in /[ ^I]^ the pattern was never found even if it existed, |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
345 // because ^ was taken to be magic -- webb |
4444 | 346 static int prevchr; |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
347 static int prevprevchr; // previous-previous character |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
348 static int nextchr; // used for ungetchr() |
7 | 349 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
350 // arguments for reg() |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
351 #define REG_NOPAREN 0 // toplevel reg() |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
352 #define REG_PAREN 1 // \(\) |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
353 #define REG_ZPAREN 2 // \z(\) |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
354 #define REG_NPAREN 3 // \%(\) |
7 | 355 |
4679
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
356 typedef struct |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
357 { |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
358 char_u *regparse; |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
359 int prevchr_len; |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
360 int curchr; |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
361 int prevchr; |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
362 int prevprevchr; |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
363 int nextchr; |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
364 int at_start; |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
365 int prev_at_start; |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
366 int regnpar; |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
367 } parse_state_T; |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
368 |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
369 static void initchr(char_u *); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
370 static int getchr(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
371 static void skipchr_keepstart(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
372 static int peekchr(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
373 static void skipchr(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
374 static void ungetchr(void); |
12752
09c856605191
patch 8.0.1254: undefined left shift in gethexchrs()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
375 static long gethexchrs(int maxinputlen); |
09c856605191
patch 8.0.1254: undefined left shift in gethexchrs()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
376 static long getoctchrs(void); |
09c856605191
patch 8.0.1254: undefined left shift in gethexchrs()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
377 static long getdecchrs(void); |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
378 static int coll_get_char(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
379 static int prog_magic_wrong(void); |
18019
68fd5296bf73
patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
380 static int cstrncmp(char_u *s1, char_u *s2, int *n); |
68fd5296bf73
patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
381 static char_u *cstrchr(char_u *, int); |
68fd5296bf73
patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
382 static int re_mult_next(char *what); |
15709
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
383 static int reg_iswordc(int); |
7 | 384 |
4444 | 385 static regengine_T bt_regengine; |
386 static regengine_T nfa_regengine; | |
387 | |
7 | 388 /* |
389 * Return TRUE if compiled regular expression "prog" can match a line break. | |
390 */ | |
391 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
392 re_multiline(regprog_T *prog) |
7 | 393 { |
394 return (prog->regflags & RF_HASNL); | |
395 } | |
396 | |
397 /* | |
167 | 398 * Check for an equivalence class name "[=a=]". "pp" points to the '['. |
399 * Returns a character representing the class. Zero means that no item was | |
400 * recognized. Otherwise "pp" is advanced to after the item. | |
401 */ | |
402 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
403 get_equi_class(char_u **pp) |
167 | 404 { |
405 int c; | |
406 int l = 1; | |
407 char_u *p = *pp; | |
408 | |
15854
4ac1c185b0b8
patch 8.1.0934: invalid memory access in search pattern
Bram Moolenaar <Bram@vim.org>
parents:
15792
diff
changeset
|
409 if (p[1] == '=' && p[2] != NUL) |
167 | 410 { |
411 if (has_mbyte) | |
474 | 412 l = (*mb_ptr2len)(p + 2); |
167 | 413 if (p[l + 2] == '=' && p[l + 3] == ']') |
414 { | |
415 if (has_mbyte) | |
416 c = mb_ptr2char(p + 2); | |
417 else | |
418 c = p[2]; | |
419 *pp += l + 4; | |
420 return c; | |
421 } | |
422 } | |
423 return 0; | |
424 } | |
425 | |
2247
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2173
diff
changeset
|
426 #ifdef EBCDIC |
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2173
diff
changeset
|
427 /* |
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2173
diff
changeset
|
428 * Table for equivalence class "c". (IBM-1047) |
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2173
diff
changeset
|
429 */ |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17659
diff
changeset
|
430 static char *EQUIVAL_CLASS_C[16] = { |
2247
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2173
diff
changeset
|
431 "A\x62\x63\x64\x65\x66\x67", |
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2173
diff
changeset
|
432 "C\x68", |
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2173
diff
changeset
|
433 "E\x71\x72\x73\x74", |
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2173
diff
changeset
|
434 "I\x75\x76\x77\x78", |
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2173
diff
changeset
|
435 "N\x69", |
8825
318eaa6fa973
commit https://github.com/vim/vim/commit/22e421549d54147d003f6444de007cb1d73f1d27
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
436 "O\xEB\xEC\xED\xEE\xEF\x80", |
2247
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2173
diff
changeset
|
437 "U\xFB\xFC\xFD\xFE", |
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2173
diff
changeset
|
438 "Y\xBA", |
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2173
diff
changeset
|
439 "a\x42\x43\x44\x45\x46\x47", |
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2173
diff
changeset
|
440 "c\x48", |
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2173
diff
changeset
|
441 "e\x51\x52\x53\x54", |
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2173
diff
changeset
|
442 "i\x55\x56\x57\x58", |
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2173
diff
changeset
|
443 "n\x49", |
8825
318eaa6fa973
commit https://github.com/vim/vim/commit/22e421549d54147d003f6444de007cb1d73f1d27
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
444 "o\xCB\xCC\xCD\xCE\xCF\x70", |
2247
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2173
diff
changeset
|
445 "u\xDB\xDC\xDD\xDE", |
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2173
diff
changeset
|
446 "y\x8D\xDF", |
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2173
diff
changeset
|
447 }; |
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2173
diff
changeset
|
448 #endif |
c40cd9aad546
Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
Bram Moolenaar <bram@vim.org>
parents:
2173
diff
changeset
|
449 |
167 | 450 /* |
451 * Check for a collating element "[.a.]". "pp" points to the '['. | |
452 * Returns a character. Zero means that no item was recognized. Otherwise | |
453 * "pp" is advanced to after the item. | |
454 * Currently only single characters are recognized! | |
455 */ | |
456 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
457 get_coll_element(char_u **pp) |
167 | 458 { |
459 int c; | |
460 int l = 1; | |
461 char_u *p = *pp; | |
462 | |
15860
9cd9bf2897de
patch 8.1.0937: invalid memory access in search pattern
Bram Moolenaar <Bram@vim.org>
parents:
15856
diff
changeset
|
463 if (p[0] != NUL && p[1] == '.' && p[2] != NUL) |
167 | 464 { |
465 if (has_mbyte) | |
474 | 466 l = (*mb_ptr2len)(p + 2); |
167 | 467 if (p[l + 2] == '.' && p[l + 3] == ']') |
468 { | |
469 if (has_mbyte) | |
470 c = mb_ptr2char(p + 2); | |
471 else | |
472 c = p[2]; | |
473 *pp += l + 4; | |
474 return c; | |
475 } | |
476 } | |
477 return 0; | |
478 } | |
479 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
480 static int reg_cpo_lit; // 'cpoptions' contains 'l' flag |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
481 static int reg_cpo_bsl; // 'cpoptions' contains '\' flag |
4744
a62695305e03
updated for version 7.3.1119
Bram Moolenaar <bram@vim.org>
parents:
4732
diff
changeset
|
482 |
a62695305e03
updated for version 7.3.1119
Bram Moolenaar <bram@vim.org>
parents:
4732
diff
changeset
|
483 static void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
484 get_cpo_flags(void) |
4744
a62695305e03
updated for version 7.3.1119
Bram Moolenaar <bram@vim.org>
parents:
4732
diff
changeset
|
485 { |
a62695305e03
updated for version 7.3.1119
Bram Moolenaar <bram@vim.org>
parents:
4732
diff
changeset
|
486 reg_cpo_lit = vim_strchr(p_cpo, CPO_LITERAL) != NULL; |
a62695305e03
updated for version 7.3.1119
Bram Moolenaar <bram@vim.org>
parents:
4732
diff
changeset
|
487 reg_cpo_bsl = vim_strchr(p_cpo, CPO_BACKSL) != NULL; |
a62695305e03
updated for version 7.3.1119
Bram Moolenaar <bram@vim.org>
parents:
4732
diff
changeset
|
488 } |
167 | 489 |
490 /* | |
491 * Skip over a "[]" range. | |
492 * "p" must point to the character after the '['. | |
493 * The returned pointer is on the matching ']', or the terminating NUL. | |
494 */ | |
495 static char_u * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
496 skip_anyof(char_u *p) |
167 | 497 { |
498 int l; | |
499 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
500 if (*p == '^') // Complement of range. |
167 | 501 ++p; |
502 if (*p == ']' || *p == '-') | |
503 ++p; | |
504 while (*p != NUL && *p != ']') | |
505 { | |
474 | 506 if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) |
167 | 507 p += l; |
508 else | |
509 if (*p == '-') | |
510 { | |
511 ++p; | |
512 if (*p != ']' && *p != NUL) | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
513 MB_PTR_ADV(p); |
167 | 514 } |
515 else if (*p == '\\' | |
4744
a62695305e03
updated for version 7.3.1119
Bram Moolenaar <bram@vim.org>
parents:
4732
diff
changeset
|
516 && !reg_cpo_bsl |
167 | 517 && (vim_strchr(REGEXP_INRANGE, p[1]) != NULL |
4744
a62695305e03
updated for version 7.3.1119
Bram Moolenaar <bram@vim.org>
parents:
4732
diff
changeset
|
518 || (!reg_cpo_lit && vim_strchr(REGEXP_ABBR, p[1]) != NULL))) |
167 | 519 p += 2; |
520 else if (*p == '[') | |
521 { | |
522 if (get_char_class(&p) == CLASS_NONE | |
523 && get_equi_class(&p) == 0 | |
6830 | 524 && get_coll_element(&p) == 0 |
525 && *p != NUL) | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
526 ++p; // it is not a class name and not NUL |
167 | 527 } |
528 else | |
529 ++p; | |
530 } | |
531 | |
532 return p; | |
533 } | |
534 | |
535 /* | |
7 | 536 * Skip past regular expression. |
153 | 537 * Stop at end of "startp" or where "dirc" is found ('/', '?', etc). |
7 | 538 * Take care of characters with a backslash in front of it. |
539 * Skip strings inside [ and ]. | |
540 * When "newp" is not NULL and "dirc" is '?', make an allocated copy of the | |
541 * expression and change "\?" to "?". If "*newp" is not NULL the expression | |
542 * is changed in-place. | |
543 */ | |
544 char_u * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
545 skip_regexp( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
546 char_u *startp, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
547 int dirc, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
548 int magic, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
549 char_u **newp) |
7 | 550 { |
551 int mymagic; | |
552 char_u *p = startp; | |
553 | |
554 if (magic) | |
555 mymagic = MAGIC_ON; | |
556 else | |
557 mymagic = MAGIC_OFF; | |
4744
a62695305e03
updated for version 7.3.1119
Bram Moolenaar <bram@vim.org>
parents:
4732
diff
changeset
|
558 get_cpo_flags(); |
7 | 559 |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
560 for (; p[0] != NUL; MB_PTR_ADV(p)) |
7 | 561 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
562 if (p[0] == dirc) // found end of regexp |
7 | 563 break; |
564 if ((p[0] == '[' && mymagic >= MAGIC_ON) | |
565 || (p[0] == '\\' && p[1] == '[' && mymagic <= MAGIC_OFF)) | |
566 { | |
567 p = skip_anyof(p + 1); | |
568 if (p[0] == NUL) | |
569 break; | |
570 } | |
571 else if (p[0] == '\\' && p[1] != NUL) | |
572 { | |
573 if (dirc == '?' && newp != NULL && p[1] == '?') | |
574 { | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
575 // change "\?" to "?", make a copy first. |
7 | 576 if (*newp == NULL) |
577 { | |
578 *newp = vim_strsave(startp); | |
579 if (*newp != NULL) | |
580 p = *newp + (p - startp); | |
581 } | |
582 if (*newp != NULL) | |
1621 | 583 STRMOVE(p, p + 1); |
7 | 584 else |
585 ++p; | |
586 } | |
587 else | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
588 ++p; // skip next character |
7 | 589 if (*p == 'v') |
590 mymagic = MAGIC_ALL; | |
591 else if (*p == 'V') | |
592 mymagic = MAGIC_NONE; | |
593 } | |
594 } | |
595 return p; | |
596 } | |
597 | |
11525
14b6b79d685b
patch 8.0.0645: no error for illegal back reference in NFA engine
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
598 /* |
18019
68fd5296bf73
patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
599 * Functions for getting characters from the regexp input. |
7 | 600 */ |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
601 static int prevchr_len; // byte length of previous char |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
602 static int at_start; // True when on the first character |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
603 static int prev_at_start; // True when on the second character |
8021
b6b4f354df23
commit https://github.com/vim/vim/commit/7c29f387819b5817b003d2ba73e2b5cf3cb3d0dd
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
604 |
7 | 605 /* |
4444 | 606 * Start parsing at "str". |
607 */ | |
7 | 608 static void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
609 initchr(char_u *str) |
7 | 610 { |
611 regparse = str; | |
612 prevchr_len = 0; | |
613 curchr = prevprevchr = prevchr = nextchr = -1; | |
614 at_start = TRUE; | |
615 prev_at_start = FALSE; | |
616 } | |
617 | |
4444 | 618 /* |
4679
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
619 * Save the current parse state, so that it can be restored and parsing |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
620 * starts in the same state again. |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
621 */ |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
622 static void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
623 save_parse_state(parse_state_T *ps) |
4679
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
624 { |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
625 ps->regparse = regparse; |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
626 ps->prevchr_len = prevchr_len; |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
627 ps->curchr = curchr; |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
628 ps->prevchr = prevchr; |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
629 ps->prevprevchr = prevprevchr; |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
630 ps->nextchr = nextchr; |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
631 ps->at_start = at_start; |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
632 ps->prev_at_start = prev_at_start; |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
633 ps->regnpar = regnpar; |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
634 } |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
635 |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
636 /* |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
637 * Restore a previously saved parse state. |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
638 */ |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
639 static void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
640 restore_parse_state(parse_state_T *ps) |
4679
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
641 { |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
642 regparse = ps->regparse; |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
643 prevchr_len = ps->prevchr_len; |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
644 curchr = ps->curchr; |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
645 prevchr = ps->prevchr; |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
646 prevprevchr = ps->prevprevchr; |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
647 nextchr = ps->nextchr; |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
648 at_start = ps->at_start; |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
649 prev_at_start = ps->prev_at_start; |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
650 regnpar = ps->regnpar; |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
651 } |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
652 |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
653 |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
654 /* |
4444 | 655 * Get the next character without advancing. |
656 */ | |
7 | 657 static int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
658 peekchr(void) |
7 | 659 { |
167 | 660 static int after_slash = FALSE; |
661 | |
7 | 662 if (curchr == -1) |
663 { | |
664 switch (curchr = regparse[0]) | |
665 { | |
666 case '.': | |
667 case '[': | |
668 case '~': | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
669 // magic when 'magic' is on |
7 | 670 if (reg_magic >= MAGIC_ON) |
671 curchr = Magic(curchr); | |
672 break; | |
673 case '(': | |
674 case ')': | |
675 case '{': | |
676 case '%': | |
677 case '+': | |
678 case '=': | |
679 case '?': | |
680 case '@': | |
681 case '!': | |
682 case '&': | |
683 case '|': | |
684 case '<': | |
685 case '>': | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
686 case '#': // future ext. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
687 case '"': // future ext. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
688 case '\'': // future ext. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
689 case ',': // future ext. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
690 case '-': // future ext. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
691 case ':': // future ext. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
692 case ';': // future ext. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
693 case '`': // future ext. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
694 case '/': // Can't be used in / command |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
695 // magic only after "\v" |
7 | 696 if (reg_magic == MAGIC_ALL) |
697 curchr = Magic(curchr); | |
698 break; | |
699 case '*': | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
700 // * is not magic as the very first character, eg "?*ptr", when |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
701 // after '^', eg "/^*ptr" and when after "\(", "\|", "\&". But |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
702 // "\(\*" is not magic, thus must be magic if "after_slash" |
167 | 703 if (reg_magic >= MAGIC_ON |
704 && !at_start | |
705 && !(prev_at_start && prevchr == Magic('^')) | |
706 && (after_slash | |
707 || (prevchr != Magic('(') | |
708 && prevchr != Magic('&') | |
709 && prevchr != Magic('|')))) | |
7 | 710 curchr = Magic('*'); |
711 break; | |
712 case '^': | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
713 // '^' is only magic as the very first character and if it's after |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
714 // "\(", "\|", "\&' or "\n" |
7 | 715 if (reg_magic >= MAGIC_OFF |
716 && (at_start | |
717 || reg_magic == MAGIC_ALL | |
718 || prevchr == Magic('(') | |
719 || prevchr == Magic('|') | |
720 || prevchr == Magic('&') | |
721 || prevchr == Magic('n') | |
722 || (no_Magic(prevchr) == '(' | |
723 && prevprevchr == Magic('%')))) | |
724 { | |
725 curchr = Magic('^'); | |
726 at_start = TRUE; | |
727 prev_at_start = FALSE; | |
728 } | |
729 break; | |
730 case '$': | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
731 // '$' is only magic as the very last char and if it's in front of |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
732 // either "\|", "\)", "\&", or "\n" |
7 | 733 if (reg_magic >= MAGIC_OFF) |
734 { | |
735 char_u *p = regparse + 1; | |
6041 | 736 int is_magic_all = (reg_magic == MAGIC_ALL); |
737 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
738 // ignore \c \C \m \M \v \V and \Z after '$' |
7 | 739 while (p[0] == '\\' && (p[1] == 'c' || p[1] == 'C' |
6041 | 740 || p[1] == 'm' || p[1] == 'M' |
741 || p[1] == 'v' || p[1] == 'V' || p[1] == 'Z')) | |
742 { | |
743 if (p[1] == 'v') | |
744 is_magic_all = TRUE; | |
745 else if (p[1] == 'm' || p[1] == 'M' || p[1] == 'V') | |
746 is_magic_all = FALSE; | |
7 | 747 p += 2; |
6041 | 748 } |
7 | 749 if (p[0] == NUL |
750 || (p[0] == '\\' | |
751 && (p[1] == '|' || p[1] == '&' || p[1] == ')' | |
752 || p[1] == 'n')) | |
6041 | 753 || (is_magic_all |
754 && (p[0] == '|' || p[0] == '&' || p[0] == ')')) | |
7 | 755 || reg_magic == MAGIC_ALL) |
756 curchr = Magic('$'); | |
757 } | |
758 break; | |
759 case '\\': | |
760 { | |
761 int c = regparse[1]; | |
762 | |
763 if (c == NUL) | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
764 curchr = '\\'; // trailing '\' |
7 | 765 else if ( |
766 #ifdef EBCDIC | |
767 vim_strchr(META, c) | |
768 #else | |
769 c <= '~' && META_flags[c] | |
770 #endif | |
771 ) | |
772 { | |
773 /* | |
774 * META contains everything that may be magic sometimes, | |
775 * except ^ and $ ("\^" and "\$" are only magic after | |
6830 | 776 * "\V"). We now fetch the next character and toggle its |
7 | 777 * magicness. Therefore, \ is so meta-magic that it is |
778 * not in META. | |
779 */ | |
780 curchr = -1; | |
781 prev_at_start = at_start; | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
782 at_start = FALSE; // be able to say "/\*ptr" |
7 | 783 ++regparse; |
167 | 784 ++after_slash; |
7 | 785 peekchr(); |
786 --regparse; | |
167 | 787 --after_slash; |
7 | 788 curchr = toggle_Magic(curchr); |
789 } | |
790 else if (vim_strchr(REGEXP_ABBR, c)) | |
791 { | |
792 /* | |
793 * Handle abbreviations, like "\t" for TAB -- webb | |
794 */ | |
795 curchr = backslash_trans(c); | |
796 } | |
797 else if (reg_magic == MAGIC_NONE && (c == '$' || c == '^')) | |
798 curchr = toggle_Magic(c); | |
799 else | |
800 { | |
801 /* | |
802 * Next character can never be (made) magic? | |
803 * Then backslashing it won't do anything. | |
804 */ | |
805 if (has_mbyte) | |
806 curchr = (*mb_ptr2char)(regparse + 1); | |
807 else | |
808 curchr = c; | |
809 } | |
810 break; | |
811 } | |
812 | |
813 default: | |
814 if (has_mbyte) | |
815 curchr = (*mb_ptr2char)(regparse); | |
816 } | |
817 } | |
818 | |
819 return curchr; | |
820 } | |
821 | |
822 /* | |
823 * Eat one lexed character. Do this in a way that we can undo it. | |
824 */ | |
825 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
826 skipchr(void) |
7 | 827 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
828 // peekchr() eats a backslash, do the same here |
7 | 829 if (*regparse == '\\') |
830 prevchr_len = 1; | |
831 else | |
832 prevchr_len = 0; | |
833 if (regparse[prevchr_len] != NUL) | |
834 { | |
714 | 835 if (enc_utf8) |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
836 // exclude composing chars that mb_ptr2len does include |
1449 | 837 prevchr_len += utf_ptr2len(regparse + prevchr_len); |
714 | 838 else if (has_mbyte) |
474 | 839 prevchr_len += (*mb_ptr2len)(regparse + prevchr_len); |
7 | 840 else |
841 ++prevchr_len; | |
842 } | |
843 regparse += prevchr_len; | |
844 prev_at_start = at_start; | |
845 at_start = FALSE; | |
846 prevprevchr = prevchr; | |
847 prevchr = curchr; | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
848 curchr = nextchr; // use previously unget char, or -1 |
7 | 849 nextchr = -1; |
850 } | |
851 | |
852 /* | |
853 * Skip a character while keeping the value of prev_at_start for at_start. | |
854 * prevchr and prevprevchr are also kept. | |
855 */ | |
856 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
857 skipchr_keepstart(void) |
7 | 858 { |
859 int as = prev_at_start; | |
860 int pr = prevchr; | |
861 int prpr = prevprevchr; | |
862 | |
863 skipchr(); | |
864 at_start = as; | |
865 prevchr = pr; | |
866 prevprevchr = prpr; | |
867 } | |
868 | |
4444 | 869 /* |
870 * Get the next character from the pattern. We know about magic and such, so | |
871 * therefore we need a lexical analyzer. | |
872 */ | |
7 | 873 static int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
874 getchr(void) |
7 | 875 { |
876 int chr = peekchr(); | |
877 | |
878 skipchr(); | |
879 return chr; | |
880 } | |
881 | |
882 /* | |
883 * put character back. Works only once! | |
884 */ | |
885 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
886 ungetchr(void) |
7 | 887 { |
888 nextchr = curchr; | |
889 curchr = prevchr; | |
890 prevchr = prevprevchr; | |
891 at_start = prev_at_start; | |
892 prev_at_start = FALSE; | |
893 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
894 // Backup regparse, so that it's at the same position as before the |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
895 // getchr(). |
7 | 896 regparse -= prevchr_len; |
897 } | |
898 | |
899 /* | |
29 | 900 * Get and return the value of the hex string at the current position. |
901 * Return -1 if there is no valid hex number. | |
902 * The position is updated: | |
24 | 903 * blahblah\%x20asdf |
856 | 904 * before-^ ^-after |
24 | 905 * The parameter controls the maximum number of input characters. This will be |
906 * 2 when reading a \%x20 sequence and 4 when reading a \%u20AC sequence. | |
907 */ | |
12752
09c856605191
patch 8.0.1254: undefined left shift in gethexchrs()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
908 static long |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
909 gethexchrs(int maxinputlen) |
24 | 910 { |
12752
09c856605191
patch 8.0.1254: undefined left shift in gethexchrs()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
911 long_u nr = 0; |
24 | 912 int c; |
913 int i; | |
914 | |
915 for (i = 0; i < maxinputlen; ++i) | |
916 { | |
917 c = regparse[0]; | |
918 if (!vim_isxdigit(c)) | |
919 break; | |
920 nr <<= 4; | |
921 nr |= hex2nr(c); | |
922 ++regparse; | |
923 } | |
924 | |
925 if (i == 0) | |
926 return -1; | |
12752
09c856605191
patch 8.0.1254: undefined left shift in gethexchrs()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
927 return (long)nr; |
24 | 928 } |
929 | |
930 /* | |
4579
7a2be4a39423
updated for version 7.3.1037
Bram Moolenaar <bram@vim.org>
parents:
4505
diff
changeset
|
931 * Get and return the value of the decimal string immediately after the |
24 | 932 * current position. Return -1 for invalid. Consumes all digits. |
933 */ | |
12752
09c856605191
patch 8.0.1254: undefined left shift in gethexchrs()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
934 static long |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
935 getdecchrs(void) |
24 | 936 { |
12752
09c856605191
patch 8.0.1254: undefined left shift in gethexchrs()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
937 long_u nr = 0; |
24 | 938 int c; |
939 int i; | |
940 | |
941 for (i = 0; ; ++i) | |
942 { | |
943 c = regparse[0]; | |
944 if (c < '0' || c > '9') | |
945 break; | |
946 nr *= 10; | |
947 nr += c - '0'; | |
948 ++regparse; | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
949 curchr = -1; // no longer valid |
24 | 950 } |
951 | |
952 if (i == 0) | |
953 return -1; | |
12752
09c856605191
patch 8.0.1254: undefined left shift in gethexchrs()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
954 return (long)nr; |
24 | 955 } |
956 | |
957 /* | |
958 * get and return the value of the octal string immediately after the current | |
959 * position. Return -1 for invalid, or 0-255 for valid. Smart enough to handle | |
960 * numbers > 377 correctly (for example, 400 is treated as 40) and doesn't | |
961 * treat 8 or 9 as recognised characters. Position is updated: | |
962 * blahblah\%o210asdf | |
856 | 963 * before-^ ^-after |
24 | 964 */ |
12752
09c856605191
patch 8.0.1254: undefined left shift in gethexchrs()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
965 static long |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
966 getoctchrs(void) |
24 | 967 { |
12752
09c856605191
patch 8.0.1254: undefined left shift in gethexchrs()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
968 long_u nr = 0; |
24 | 969 int c; |
970 int i; | |
971 | |
972 for (i = 0; i < 3 && nr < 040; ++i) | |
973 { | |
974 c = regparse[0]; | |
975 if (c < '0' || c > '7') | |
976 break; | |
977 nr <<= 3; | |
978 nr |= hex2nr(c); | |
979 ++regparse; | |
980 } | |
981 | |
982 if (i == 0) | |
983 return -1; | |
12752
09c856605191
patch 8.0.1254: undefined left shift in gethexchrs()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
984 return (long)nr; |
24 | 985 } |
986 | |
987 /* | |
7 | 988 * read_limits - Read two integers to be taken as a minimum and maximum. |
989 * If the first character is '-', then the range is reversed. | |
990 * Should end with 'end'. If minval is missing, zero is default, if maxval is | |
991 * missing, a very big number is the default. | |
992 */ | |
993 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
994 read_limits(long *minval, long *maxval) |
7 | 995 { |
996 int reverse = FALSE; | |
997 char_u *first_char; | |
998 long tmp; | |
999 | |
1000 if (*regparse == '-') | |
1001 { | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1002 // Starts with '-', so reverse the range later |
7 | 1003 regparse++; |
1004 reverse = TRUE; | |
1005 } | |
1006 first_char = regparse; | |
1007 *minval = getdigits(®parse); | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1008 if (*regparse == ',') // There is a comma |
7 | 1009 { |
1010 if (vim_isdigit(*++regparse)) | |
1011 *maxval = getdigits(®parse); | |
1012 else | |
1013 *maxval = MAX_LIMIT; | |
1014 } | |
1015 else if (VIM_ISDIGIT(*first_char)) | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1016 *maxval = *minval; // It was \{n} or \{-n} |
7 | 1017 else |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1018 *maxval = MAX_LIMIT; // It was \{} or \{-} |
7 | 1019 if (*regparse == '\\') |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1020 regparse++; // Allow either \{...} or \{...\} |
167 | 1021 if (*regparse != '}') |
15480
bd12ace1bab2
patch 8.1.0748: using sprintf() instead of semsg()
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1022 EMSG2_RET_FAIL(_("E554: Syntax error in %s{...}"), |
bd12ace1bab2
patch 8.1.0748: using sprintf() instead of semsg()
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1023 reg_magic == MAGIC_ALL); |
7 | 1024 |
1025 /* | |
1026 * Reverse the range if there was a '-', or make sure it is in the right | |
1027 * order otherwise. | |
1028 */ | |
1029 if ((!reverse && *minval > *maxval) || (reverse && *minval < *maxval)) | |
1030 { | |
1031 tmp = *minval; | |
1032 *minval = *maxval; | |
1033 *maxval = tmp; | |
1034 } | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1035 skipchr(); // let's be friends with the lexer again |
7 | 1036 return OK; |
1037 } | |
1038 | |
1039 /* | |
1040 * vim_regexec and friends | |
1041 */ | |
1042 | |
1043 /* | |
1044 * Global work variables for vim_regexec(). | |
1045 */ | |
1046 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1047 static void cleanup_subexpr(void); |
7 | 1048 #ifdef FEAT_SYN_HL |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1049 static void cleanup_zsubexpr(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1050 #endif |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1051 static void reg_nextline(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1052 static int match_with_backref(linenr_T start_lnum, colnr_T start_col, linenr_T end_lnum, colnr_T end_col, int *bytelen); |
7 | 1053 |
1054 /* | |
1055 * Sometimes need to save a copy of a line. Since alloc()/free() is very | |
1056 * slow, we keep one allocated piece of memory and only re-allocate it when | |
4444 | 1057 * it's too small. It's freed in bt_regexec_both() when finished. |
7 | 1058 */ |
1468 | 1059 static char_u *reg_tofree = NULL; |
7 | 1060 static unsigned reg_tofreelen; |
1061 | |
1062 /* | |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1063 * Structure used to store the execution state of the regex engine. |
1209 | 1064 * Which ones are set depends on whether a single-line or multi-line match is |
7 | 1065 * done: |
1066 * single-line multi-line | |
1067 * reg_match ®match_T NULL | |
1068 * reg_mmatch NULL ®mmatch_T | |
1069 * reg_startp reg_match->startp <invalid> | |
1070 * reg_endp reg_match->endp <invalid> | |
1071 * reg_startpos <invalid> reg_mmatch->startpos | |
1072 * reg_endpos <invalid> reg_mmatch->endpos | |
1073 * reg_win NULL window in which to search | |
4061 | 1074 * reg_buf curbuf buffer in which to search |
7 | 1075 * reg_firstlnum <invalid> first line in which to search |
1076 * reg_maxline 0 last line nr | |
1077 * reg_line_lbr FALSE or TRUE FALSE | |
1078 */ | |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1079 typedef struct { |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1080 regmatch_T *reg_match; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1081 regmmatch_T *reg_mmatch; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1082 char_u **reg_startp; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1083 char_u **reg_endp; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1084 lpos_T *reg_startpos; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1085 lpos_T *reg_endpos; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1086 win_T *reg_win; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1087 buf_T *reg_buf; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1088 linenr_T reg_firstlnum; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1089 linenr_T reg_maxline; |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1090 int reg_line_lbr; // "\n" in string is line break |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1091 |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1092 // The current match-position is stord in these variables: |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1093 linenr_T lnum; // line number, relative to first line |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1094 char_u *line; // start of current line |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1095 char_u *input; // current input, points into "regline" |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1096 |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1097 int need_clear_subexpr; // subexpressions still need to be cleared |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1098 #ifdef FEAT_SYN_HL |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1099 int need_clear_zsubexpr; // extmatch subexpressions still need to be |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1100 // cleared |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1101 #endif |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1102 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1103 // Internal copy of 'ignorecase'. It is set at each call to vim_regexec(). |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1104 // Normally it gets the value of "rm_ic" or "rmm_ic", but when the pattern |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1105 // contains '\c' or '\C' the value is overruled. |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1106 int reg_ic; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1107 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1108 // Similar to "reg_ic", but only for 'combining' characters. Set with \Z |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1109 // flag in the regexp. Defaults to false, always. |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1110 int reg_icombine; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1111 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1112 // Copy of "rmm_maxcol": maximum column to search for a match. Zero when |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1113 // there is no maximum. |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1114 colnr_T reg_maxcol; |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1115 |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1116 // State for the NFA engine regexec. |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1117 int nfa_has_zend; // NFA regexp \ze operator encountered. |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1118 int nfa_has_backref; // NFA regexp \1 .. \9 encountered. |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1119 int nfa_nsubexpr; // Number of sub expressions actually being used |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1120 // during execution. 1 if only the whole match |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1121 // (subexpr 0) is used. |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1122 // listid is global, so that it increases on recursive calls to |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1123 // nfa_regmatch(), which means we don't have to clear the lastlist field of |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1124 // all the states. |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1125 int nfa_listid; |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1126 int nfa_alt_listid; |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1127 |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1128 #ifdef FEAT_SYN_HL |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1129 int nfa_has_zsubexpr; // NFA regexp has \z( ), set zsubexpr. |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1130 #endif |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1131 } regexec_T; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1132 |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1133 static regexec_T rex; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1134 static int rex_in_use = FALSE; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1135 |
7 | 1136 /* |
15709
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1137 * Return TRUE if character 'c' is included in 'iskeyword' option for |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1138 * "reg_buf" buffer. |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1139 */ |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1140 static int |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1141 reg_iswordc(int c) |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1142 { |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1143 return vim_iswordc_buf(c, rex.reg_buf); |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1144 } |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1145 |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1146 /* |
7 | 1147 * Get pointer to the line "lnum", which is relative to "reg_firstlnum". |
1148 */ | |
1149 static char_u * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1150 reg_getline(linenr_T lnum) |
7 | 1151 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1152 // when looking behind for a match/no-match lnum is negative. But we |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1153 // can't go before line 1 |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1154 if (rex.reg_firstlnum + lnum < 1) |
7 | 1155 return NULL; |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1156 if (lnum > rex.reg_maxline) |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1157 // Must have matched the "\n" in the last line. |
481 | 1158 return (char_u *)""; |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1159 return ml_get_buf(rex.reg_buf, rex.reg_firstlnum + lnum, FALSE); |
7 | 1160 } |
1161 | |
1162 #ifdef FEAT_SYN_HL | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1163 static char_u *reg_startzp[NSUBEXP]; // Workspace to mark beginning |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1164 static char_u *reg_endzp[NSUBEXP]; // and end of \z(...\) matches |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1165 static lpos_T reg_startzpos[NSUBEXP]; // idem, beginning pos |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1166 static lpos_T reg_endzpos[NSUBEXP]; // idem, end pos |
7 | 1167 #endif |
1168 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1169 // TRUE if using multi-line regexp. |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1170 #define REG_MULTI (rex.reg_match == NULL) |
4444 | 1171 |
7 | 1172 #ifdef FEAT_SYN_HL |
1173 /* | |
1174 * Create a new extmatch and mark it as referenced once. | |
1175 */ | |
1176 static reg_extmatch_T * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1177 make_extmatch(void) |
7 | 1178 { |
1179 reg_extmatch_T *em; | |
1180 | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
1181 em = ALLOC_CLEAR_ONE(reg_extmatch_T); |
7 | 1182 if (em != NULL) |
1183 em->refcnt = 1; | |
1184 return em; | |
1185 } | |
1186 | |
1187 /* | |
1188 * Add a reference to an extmatch. | |
1189 */ | |
1190 reg_extmatch_T * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1191 ref_extmatch(reg_extmatch_T *em) |
7 | 1192 { |
1193 if (em != NULL) | |
1194 em->refcnt++; | |
1195 return em; | |
1196 } | |
1197 | |
1198 /* | |
1199 * Remove a reference to an extmatch. If there are no references left, free | |
1200 * the info. | |
1201 */ | |
1202 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1203 unref_extmatch(reg_extmatch_T *em) |
7 | 1204 { |
1205 int i; | |
1206 | |
1207 if (em != NULL && --em->refcnt <= 0) | |
1208 { | |
1209 for (i = 0; i < NSUBEXP; ++i) | |
1210 vim_free(em->matches[i]); | |
1211 vim_free(em); | |
1212 } | |
1213 } | |
1214 #endif | |
1215 | |
1216 /* | |
1217 * Get class of previous character. | |
1218 */ | |
1219 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1220 reg_prev_class(void) |
7 | 1221 { |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1222 if (rex.input > rex.line) |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1223 return mb_get_class_buf(rex.input - 1 |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1224 - (*mb_head_off)(rex.line, rex.input - 1), rex.reg_buf); |
7 | 1225 return -1; |
1226 } | |
5735 | 1227 |
4730
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1228 /* |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1229 * Return TRUE if the current rex.input position matches the Visual area. |
4730
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1230 */ |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1231 static int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1232 reg_match_visual(void) |
4730
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1233 { |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1234 pos_T top, bot; |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1235 linenr_T lnum; |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1236 colnr_T col; |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1237 win_T *wp = rex.reg_win == NULL ? curwin : rex.reg_win; |
4730
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1238 int mode; |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1239 colnr_T start, end; |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1240 colnr_T start2, end2; |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1241 colnr_T cols; |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1242 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1243 // Check if the buffer is the current buffer. |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1244 if (rex.reg_buf != curbuf || VIsual.lnum == 0) |
4730
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1245 return FALSE; |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1246 |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1247 if (VIsual_active) |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1248 { |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1249 if (LT_POS(VIsual, wp->w_cursor)) |
4730
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1250 { |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1251 top = VIsual; |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1252 bot = wp->w_cursor; |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1253 } |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1254 else |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1255 { |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1256 top = wp->w_cursor; |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1257 bot = VIsual; |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1258 } |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1259 mode = VIsual_mode; |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1260 } |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1261 else |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1262 { |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1263 if (LT_POS(curbuf->b_visual.vi_start, curbuf->b_visual.vi_end)) |
4730
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1264 { |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1265 top = curbuf->b_visual.vi_start; |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1266 bot = curbuf->b_visual.vi_end; |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1267 } |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1268 else |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1269 { |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1270 top = curbuf->b_visual.vi_end; |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1271 bot = curbuf->b_visual.vi_start; |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1272 } |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1273 mode = curbuf->b_visual.vi_mode; |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1274 } |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1275 lnum = rex.lnum + rex.reg_firstlnum; |
4730
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1276 if (lnum < top.lnum || lnum > bot.lnum) |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1277 return FALSE; |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1278 |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1279 if (mode == 'v') |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1280 { |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1281 col = (colnr_T)(rex.input - rex.line); |
4730
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1282 if ((lnum == top.lnum && col < top.col) |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1283 || (lnum == bot.lnum && col >= bot.col + (*p_sel != 'e'))) |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1284 return FALSE; |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1285 } |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1286 else if (mode == Ctrl_V) |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1287 { |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1288 getvvcol(wp, &top, &start, NULL, &end); |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1289 getvvcol(wp, &bot, &start2, NULL, &end2); |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1290 if (start2 < start) |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1291 start = start2; |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1292 if (end2 > end) |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1293 end = end2; |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1294 if (top.col == MAXCOL || bot.col == MAXCOL) |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1295 end = MAXCOL; |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1296 cols = win_linetabsize(wp, rex.line, (colnr_T)(rex.input - rex.line)); |
4730
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1297 if (cols < start || cols > end - (*p_sel == 'e')) |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1298 return FALSE; |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1299 } |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1300 return TRUE; |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1301 } |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
1302 |
7 | 1303 /* |
1304 * Check the regexp program for its magic number. | |
1305 * Return TRUE if it's wrong. | |
1306 */ | |
1307 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1308 prog_magic_wrong(void) |
7 | 1309 { |
4444 | 1310 regprog_T *prog; |
1311 | |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1312 prog = REG_MULTI ? rex.reg_mmatch->regprog : rex.reg_match->regprog; |
4444 | 1313 if (prog->engine == &nfa_regengine) |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1314 // For NFA matcher we don't check the magic |
4444 | 1315 return FALSE; |
1316 | |
1317 if (UCHARAT(((bt_regprog_T *)prog)->program) != REGMAGIC) | |
7 | 1318 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15339
diff
changeset
|
1319 emsg(_(e_re_corr)); |
7 | 1320 return TRUE; |
1321 } | |
1322 return FALSE; | |
1323 } | |
1324 | |
1325 /* | |
1326 * Cleanup the subexpressions, if this wasn't done yet. | |
1327 * This construction is used to clear the subexpressions only when they are | |
1328 * used (to increase speed). | |
1329 */ | |
1330 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1331 cleanup_subexpr(void) |
7 | 1332 { |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1333 if (rex.need_clear_subexpr) |
7 | 1334 { |
1335 if (REG_MULTI) | |
1336 { | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1337 // Use 0xff to set lnum to -1 |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1338 vim_memset(rex.reg_startpos, 0xff, sizeof(lpos_T) * NSUBEXP); |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1339 vim_memset(rex.reg_endpos, 0xff, sizeof(lpos_T) * NSUBEXP); |
7 | 1340 } |
1341 else | |
1342 { | |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1343 vim_memset(rex.reg_startp, 0, sizeof(char_u *) * NSUBEXP); |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1344 vim_memset(rex.reg_endp, 0, sizeof(char_u *) * NSUBEXP); |
7 | 1345 } |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1346 rex.need_clear_subexpr = FALSE; |
7 | 1347 } |
1348 } | |
1349 | |
1350 #ifdef FEAT_SYN_HL | |
1351 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1352 cleanup_zsubexpr(void) |
7 | 1353 { |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1354 if (rex.need_clear_zsubexpr) |
7 | 1355 { |
1356 if (REG_MULTI) | |
1357 { | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1358 // Use 0xff to set lnum to -1 |
7 | 1359 vim_memset(reg_startzpos, 0xff, sizeof(lpos_T) * NSUBEXP); |
1360 vim_memset(reg_endzpos, 0xff, sizeof(lpos_T) * NSUBEXP); | |
1361 } | |
1362 else | |
1363 { | |
1364 vim_memset(reg_startzp, 0, sizeof(char_u *) * NSUBEXP); | |
1365 vim_memset(reg_endzp, 0, sizeof(char_u *) * NSUBEXP); | |
1366 } | |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1367 rex.need_clear_zsubexpr = FALSE; |
7 | 1368 } |
1369 } | |
1370 #endif | |
1371 | |
1372 /* | |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1373 * Advance rex.lnum, rex.line and rex.input to the next line. |
7 | 1374 */ |
1375 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1376 reg_nextline(void) |
7 | 1377 { |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1378 rex.line = reg_getline(++rex.lnum); |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1379 rex.input = rex.line; |
7 | 1380 fast_breakcheck(); |
1381 } | |
1382 | |
1383 /* | |
4891
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1384 * Check whether a backreference matches. |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1385 * Returns RA_FAIL, RA_NOMATCH or RA_MATCH. |
5504 | 1386 * If "bytelen" is not NULL, it is set to the byte length of the match in the |
1387 * last line. | |
4891
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1388 */ |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1389 static int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1390 match_with_backref( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1391 linenr_T start_lnum, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1392 colnr_T start_col, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1393 linenr_T end_lnum, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1394 colnr_T end_col, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1395 int *bytelen) |
4891
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1396 { |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1397 linenr_T clnum = start_lnum; |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1398 colnr_T ccol = start_col; |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1399 int len; |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1400 char_u *p; |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1401 |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1402 if (bytelen != NULL) |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1403 *bytelen = 0; |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1404 for (;;) |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1405 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1406 // Since getting one line may invalidate the other, need to make copy. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1407 // Slow! |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1408 if (rex.line != reg_tofree) |
4891
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1409 { |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1410 len = (int)STRLEN(rex.line); |
4891
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1411 if (reg_tofree == NULL || len >= (int)reg_tofreelen) |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1412 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1413 len += 50; // get some extra |
4891
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1414 vim_free(reg_tofree); |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1415 reg_tofree = alloc(len); |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1416 if (reg_tofree == NULL) |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1417 return RA_FAIL; // out of memory! |
4891
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1418 reg_tofreelen = len; |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1419 } |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1420 STRCPY(reg_tofree, rex.line); |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1421 rex.input = reg_tofree + (rex.input - rex.line); |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1422 rex.line = reg_tofree; |
4891
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1423 } |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1424 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1425 // Get the line to compare with. |
4891
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1426 p = reg_getline(clnum); |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1427 if (clnum == end_lnum) |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1428 len = end_col - ccol; |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1429 else |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1430 len = (int)STRLEN(p + ccol); |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1431 |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1432 if (cstrncmp(p + ccol, rex.input, &len) != 0) |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1433 return RA_NOMATCH; // doesn't match |
4891
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1434 if (bytelen != NULL) |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1435 *bytelen += len; |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1436 if (clnum == end_lnum) |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1437 break; // match and at end! |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
1438 if (rex.lnum >= rex.reg_maxline) |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1439 return RA_NOMATCH; // text too short |
4891
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1440 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1441 // Advance to next line. |
4891
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1442 reg_nextline(); |
5504 | 1443 if (bytelen != NULL) |
1444 *bytelen = 0; | |
4891
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1445 ++clnum; |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1446 ccol = 0; |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1447 if (got_int) |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1448 return RA_FAIL; |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1449 } |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1450 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1451 // found a match! Note that rex.line may now point to a copy of the line, |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1452 // that should not matter. |
4891
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1453 return RA_MATCH; |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1454 } |
7 | 1455 |
6203 | 1456 /* |
1457 * Used in a place where no * or \+ can follow. | |
1458 */ | |
1459 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1460 re_mult_next(char *what) |
6203 | 1461 { |
1462 if (re_multi_type(peekchr()) == MULTI_MULT) | |
15480
bd12ace1bab2
patch 8.1.0748: using sprintf() instead of semsg()
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1463 { |
bd12ace1bab2
patch 8.1.0748: using sprintf() instead of semsg()
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1464 semsg(_("E888: (NFA regexp) cannot repeat %s"), what); |
bd12ace1bab2
patch 8.1.0748: using sprintf() instead of semsg()
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1465 rc_did_emsg = TRUE; |
bd12ace1bab2
patch 8.1.0748: using sprintf() instead of semsg()
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1466 return FAIL; |
bd12ace1bab2
patch 8.1.0748: using sprintf() instead of semsg()
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1467 } |
6203 | 1468 return OK; |
1469 } | |
1470 | |
7 | 1471 typedef struct |
1472 { | |
1473 int a, b, c; | |
1474 } decomp_T; | |
1475 | |
1476 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1477 // 0xfb20 - 0xfb4f |
297 | 1478 static decomp_T decomp_table[0xfb4f-0xfb20+1] = |
7 | 1479 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1480 {0x5e2,0,0}, // 0xfb20 alt ayin |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1481 {0x5d0,0,0}, // 0xfb21 alt alef |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1482 {0x5d3,0,0}, // 0xfb22 alt dalet |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1483 {0x5d4,0,0}, // 0xfb23 alt he |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1484 {0x5db,0,0}, // 0xfb24 alt kaf |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1485 {0x5dc,0,0}, // 0xfb25 alt lamed |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1486 {0x5dd,0,0}, // 0xfb26 alt mem-sofit |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1487 {0x5e8,0,0}, // 0xfb27 alt resh |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1488 {0x5ea,0,0}, // 0xfb28 alt tav |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1489 {'+', 0, 0}, // 0xfb29 alt plus |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1490 {0x5e9, 0x5c1, 0}, // 0xfb2a shin+shin-dot |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1491 {0x5e9, 0x5c2, 0}, // 0xfb2b shin+sin-dot |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1492 {0x5e9, 0x5c1, 0x5bc}, // 0xfb2c shin+shin-dot+dagesh |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1493 {0x5e9, 0x5c2, 0x5bc}, // 0xfb2d shin+sin-dot+dagesh |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1494 {0x5d0, 0x5b7, 0}, // 0xfb2e alef+patah |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1495 {0x5d0, 0x5b8, 0}, // 0xfb2f alef+qamats |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1496 {0x5d0, 0x5b4, 0}, // 0xfb30 alef+hiriq |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1497 {0x5d1, 0x5bc, 0}, // 0xfb31 bet+dagesh |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1498 {0x5d2, 0x5bc, 0}, // 0xfb32 gimel+dagesh |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1499 {0x5d3, 0x5bc, 0}, // 0xfb33 dalet+dagesh |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1500 {0x5d4, 0x5bc, 0}, // 0xfb34 he+dagesh |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1501 {0x5d5, 0x5bc, 0}, // 0xfb35 vav+dagesh |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1502 {0x5d6, 0x5bc, 0}, // 0xfb36 zayin+dagesh |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1503 {0xfb37, 0, 0}, // 0xfb37 -- UNUSED |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1504 {0x5d8, 0x5bc, 0}, // 0xfb38 tet+dagesh |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1505 {0x5d9, 0x5bc, 0}, // 0xfb39 yud+dagesh |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1506 {0x5da, 0x5bc, 0}, // 0xfb3a kaf sofit+dagesh |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1507 {0x5db, 0x5bc, 0}, // 0xfb3b kaf+dagesh |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1508 {0x5dc, 0x5bc, 0}, // 0xfb3c lamed+dagesh |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1509 {0xfb3d, 0, 0}, // 0xfb3d -- UNUSED |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1510 {0x5de, 0x5bc, 0}, // 0xfb3e mem+dagesh |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1511 {0xfb3f, 0, 0}, // 0xfb3f -- UNUSED |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1512 {0x5e0, 0x5bc, 0}, // 0xfb40 nun+dagesh |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1513 {0x5e1, 0x5bc, 0}, // 0xfb41 samech+dagesh |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1514 {0xfb42, 0, 0}, // 0xfb42 -- UNUSED |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1515 {0x5e3, 0x5bc, 0}, // 0xfb43 pe sofit+dagesh |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1516 {0x5e4, 0x5bc,0}, // 0xfb44 pe+dagesh |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1517 {0xfb45, 0, 0}, // 0xfb45 -- UNUSED |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1518 {0x5e6, 0x5bc, 0}, // 0xfb46 tsadi+dagesh |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1519 {0x5e7, 0x5bc, 0}, // 0xfb47 qof+dagesh |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1520 {0x5e8, 0x5bc, 0}, // 0xfb48 resh+dagesh |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1521 {0x5e9, 0x5bc, 0}, // 0xfb49 shin+dagesh |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1522 {0x5ea, 0x5bc, 0}, // 0xfb4a tav+dagesh |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1523 {0x5d5, 0x5b9, 0}, // 0xfb4b vav+holam |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1524 {0x5d1, 0x5bf, 0}, // 0xfb4c bet+rafe |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1525 {0x5db, 0x5bf, 0}, // 0xfb4d kaf+rafe |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1526 {0x5e4, 0x5bf, 0}, // 0xfb4e pe+rafe |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1527 {0x5d0, 0x5dc, 0} // 0xfb4f alef-lamed |
7 | 1528 }; |
1529 | |
1530 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1531 mb_decompose(int c, int *c1, int *c2, int *c3) |
7 | 1532 { |
1533 decomp_T d; | |
1534 | |
4505
d037b9cbdaaa
updated for version 7.3.1000
Bram Moolenaar <bram@vim.org>
parents:
4466
diff
changeset
|
1535 if (c >= 0xfb20 && c <= 0xfb4f) |
7 | 1536 { |
1537 d = decomp_table[c - 0xfb20]; | |
1538 *c1 = d.a; | |
1539 *c2 = d.b; | |
1540 *c3 = d.c; | |
1541 } | |
1542 else | |
1543 { | |
1544 *c1 = c; | |
1545 *c2 = *c3 = 0; | |
1546 } | |
1547 } | |
1548 | |
1549 /* | |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1550 * Compare two strings, ignore case if rex.reg_ic set. |
7 | 1551 * Return 0 if strings match, non-zero otherwise. |
1552 * Correct the length "*n" when composing characters are ignored. | |
1553 */ | |
1554 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1555 cstrncmp(char_u *s1, char_u *s2, int *n) |
7 | 1556 { |
1557 int result; | |
1558 | |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1559 if (!rex.reg_ic) |
7 | 1560 result = STRNCMP(s1, s2, *n); |
1561 else | |
1562 result = MB_STRNICMP(s1, s2, *n); | |
1563 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1564 // if it failed and it's utf8 and we want to combineignore: |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1565 if (result != 0 && enc_utf8 && rex.reg_icombine) |
7 | 1566 { |
1567 char_u *str1, *str2; | |
1568 int c1, c2, c11, c12; | |
1569 int junk; | |
1570 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1571 // we have to handle the strcmp ourselves, since it is necessary to |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1572 // deal with the composing characters by ignoring them: |
7 | 1573 str1 = s1; |
1574 str2 = s2; | |
1575 c1 = c2 = 0; | |
507 | 1576 while ((int)(str1 - s1) < *n) |
7 | 1577 { |
1578 c1 = mb_ptr2char_adv(&str1); | |
1579 c2 = mb_ptr2char_adv(&str2); | |
1580 | |
18019
68fd5296bf73
patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1581 // Decompose the character if necessary, into 'base' characters. |
68fd5296bf73
patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1582 // Currently hard-coded for Hebrew, Arabic to be done... |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1583 if (c1 != c2 && (!rex.reg_ic || utf_fold(c1) != utf_fold(c2))) |
7 | 1584 { |
18019
68fd5296bf73
patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1585 // decomposition necessary? |
7 | 1586 mb_decompose(c1, &c11, &junk, &junk); |
1587 mb_decompose(c2, &c12, &junk, &junk); | |
1588 c1 = c11; | |
1589 c2 = c12; | |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1590 if (c11 != c12 |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1591 && (!rex.reg_ic || utf_fold(c11) != utf_fold(c12))) |
7 | 1592 break; |
1593 } | |
1594 } | |
1595 result = c2 - c1; | |
1596 if (result == 0) | |
1597 *n = (int)(str2 - s2); | |
1598 } | |
1599 | |
1600 return result; | |
1601 } | |
1602 | |
1603 /* | |
1604 * cstrchr: This function is used a lot for simple searches, keep it fast! | |
1605 */ | |
1606 static char_u * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1607 cstrchr(char_u *s, int c) |
7 | 1608 { |
1609 char_u *p; | |
1610 int cc; | |
1611 | |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1612 if (!rex.reg_ic || (!enc_utf8 && mb_char2len(c) > 1)) |
7 | 1613 return vim_strchr(s, c); |
1614 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1615 // tolower() and toupper() can be slow, comparing twice should be a lot |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1616 // faster (esp. when using MS Visual C++!). |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1617 // For UTF-8 need to use folded case. |
7 | 1618 if (enc_utf8 && c > 0x80) |
1619 cc = utf_fold(c); | |
1620 else | |
1347 | 1621 if (MB_ISUPPER(c)) |
1622 cc = MB_TOLOWER(c); | |
1623 else if (MB_ISLOWER(c)) | |
1624 cc = MB_TOUPPER(c); | |
7 | 1625 else |
1626 return vim_strchr(s, c); | |
1627 | |
1628 if (has_mbyte) | |
1629 { | |
474 | 1630 for (p = s; *p != NUL; p += (*mb_ptr2len)(p)) |
7 | 1631 { |
1632 if (enc_utf8 && c > 0x80) | |
1633 { | |
1634 if (utf_fold(utf_ptr2char(p)) == cc) | |
1635 return p; | |
1636 } | |
1637 else if (*p == c || *p == cc) | |
1638 return p; | |
1639 } | |
1640 } | |
1641 else | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1642 // Faster version for when there are no multi-byte characters. |
7 | 1643 for (p = s; *p != NUL; ++p) |
1644 if (*p == c || *p == cc) | |
1645 return p; | |
1646 | |
1647 return NULL; | |
1648 } | |
1649 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1650 //////////////////////////////////////////////////////////////// |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1651 // regsub stuff // |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1652 //////////////////////////////////////////////////////////////// |
7 | 1653 |
1654 /* | |
1655 * We should define ftpr as a pointer to a function returning a pointer to | |
1656 * a function returning a pointer to a function ... | |
1657 * This is impossible, so we declare a pointer to a function returning a | |
1658 * pointer to a function returning void. This should work for all compilers. | |
1659 */ | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1660 typedef void (*(*fptr_T)(int *, int))(); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1661 |
9589
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9015
diff
changeset
|
1662 static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest, int copy, int magic, int backslash); |
7 | 1663 |
772 | 1664 static fptr_T |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1665 do_upper(int *d, int c) |
7 | 1666 { |
772 | 1667 *d = MB_TOUPPER(c); |
1668 | |
1669 return (fptr_T)NULL; | |
7 | 1670 } |
1671 | |
772 | 1672 static fptr_T |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1673 do_Upper(int *d, int c) |
7 | 1674 { |
772 | 1675 *d = MB_TOUPPER(c); |
1676 | |
1677 return (fptr_T)do_Upper; | |
1678 } | |
1679 | |
1680 static fptr_T | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1681 do_lower(int *d, int c) |
772 | 1682 { |
1683 *d = MB_TOLOWER(c); | |
1684 | |
1685 return (fptr_T)NULL; | |
1686 } | |
1687 | |
1688 static fptr_T | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1689 do_Lower(int *d, int c) |
772 | 1690 { |
1691 *d = MB_TOLOWER(c); | |
1692 | |
1693 return (fptr_T)do_Lower; | |
7 | 1694 } |
1695 | |
1696 /* | |
1697 * regtilde(): Replace tildes in the pattern by the old pattern. | |
1698 * | |
1699 * Short explanation of the tilde: It stands for the previous replacement | |
1700 * pattern. If that previous pattern also contains a ~ we should go back a | |
1701 * step further... But we insert the previous pattern into the current one | |
1702 * and remember that. | |
772 | 1703 * This still does not handle the case where "magic" changes. So require the |
1704 * user to keep his hands off of "magic". | |
7 | 1705 * |
1706 * The tildes are parsed once before the first call to vim_regsub(). | |
1707 */ | |
1708 char_u * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1709 regtilde(char_u *source, int magic) |
7 | 1710 { |
1711 char_u *newsub = source; | |
1712 char_u *tmpsub; | |
1713 char_u *p; | |
1714 int len; | |
1715 int prevlen; | |
1716 | |
1717 for (p = newsub; *p; ++p) | |
1718 { | |
1719 if ((*p == '~' && magic) || (*p == '\\' && *(p + 1) == '~' && !magic)) | |
1720 { | |
1721 if (reg_prev_sub != NULL) | |
1722 { | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1723 // length = len(newsub) - 1 + len(prev_sub) + 1 |
7 | 1724 prevlen = (int)STRLEN(reg_prev_sub); |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16634
diff
changeset
|
1725 tmpsub = alloc(STRLEN(newsub) + prevlen); |
7 | 1726 if (tmpsub != NULL) |
1727 { | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1728 // copy prefix |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1729 len = (int)(p - newsub); // not including ~ |
7 | 1730 mch_memmove(tmpsub, newsub, (size_t)len); |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1731 // interpret tilde |
7 | 1732 mch_memmove(tmpsub + len, reg_prev_sub, (size_t)prevlen); |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1733 // copy postfix |
7 | 1734 if (!magic) |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1735 ++p; // back off backslash |
7 | 1736 STRCPY(tmpsub + len + prevlen, p + 1); |
1737 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1738 if (newsub != source) // already allocated newsub |
7 | 1739 vim_free(newsub); |
1740 newsub = tmpsub; | |
1741 p = newsub + len + prevlen; | |
1742 } | |
1743 } | |
1744 else if (magic) | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1745 STRMOVE(p, p + 1); // remove '~' |
7 | 1746 else |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1747 STRMOVE(p, p + 2); // remove '\~' |
7 | 1748 --p; |
1749 } | |
1750 else | |
1751 { | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1752 if (*p == '\\' && p[1]) // skip escaped characters |
7 | 1753 ++p; |
1754 if (has_mbyte) | |
474 | 1755 p += (*mb_ptr2len)(p) - 1; |
7 | 1756 } |
1757 } | |
1758 | |
1759 vim_free(reg_prev_sub); | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1760 if (newsub != source) // newsub was allocated, just keep it |
7 | 1761 reg_prev_sub = newsub; |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1762 else // no ~ found, need to save newsub |
7 | 1763 reg_prev_sub = vim_strsave(newsub); |
1764 return newsub; | |
1765 } | |
1766 | |
1767 #ifdef FEAT_EVAL | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1768 static int can_f_submatch = FALSE; // TRUE when submatch() can be used |
7 | 1769 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1770 // These pointers are used for reg_submatch(). Needed for when the |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1771 // substitution string is an expression that contains a call to substitute() |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1772 // and submatch(). |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1773 typedef struct { |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1774 regmatch_T *sm_match; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1775 regmmatch_T *sm_mmatch; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1776 linenr_T sm_firstlnum; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1777 linenr_T sm_maxline; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1778 int sm_line_lbr; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1779 } regsubmatch_T; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1780 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1781 static regsubmatch_T rsm; // can only be used when can_f_submatch is TRUE |
7 | 1782 #endif |
1783 | |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
1784 #ifdef FEAT_EVAL |
9626
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9589
diff
changeset
|
1785 |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9589
diff
changeset
|
1786 /* |
18572
23fef64352a1
patch 8.1.2280: crash when passing partial to substitute()
Bram Moolenaar <Bram@vim.org>
parents:
18019
diff
changeset
|
1787 * Put the submatches in "argv[argskip]" which is a list passed into |
23fef64352a1
patch 8.1.2280: crash when passing partial to substitute()
Bram Moolenaar <Bram@vim.org>
parents:
18019
diff
changeset
|
1788 * call_func() by vim_regsub_both(). |
9626
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9589
diff
changeset
|
1789 */ |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9589
diff
changeset
|
1790 static int |
18572
23fef64352a1
patch 8.1.2280: crash when passing partial to substitute()
Bram Moolenaar <Bram@vim.org>
parents:
18019
diff
changeset
|
1791 fill_submatch_list(int argc UNUSED, typval_T *argv, int argskip, int argcount) |
9626
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9589
diff
changeset
|
1792 { |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9589
diff
changeset
|
1793 listitem_T *li; |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9589
diff
changeset
|
1794 int i; |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9589
diff
changeset
|
1795 char_u *s; |
18572
23fef64352a1
patch 8.1.2280: crash when passing partial to substitute()
Bram Moolenaar <Bram@vim.org>
parents:
18019
diff
changeset
|
1796 typval_T *listarg = argv + argskip; |
9626
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9589
diff
changeset
|
1797 |
18572
23fef64352a1
patch 8.1.2280: crash when passing partial to substitute()
Bram Moolenaar <Bram@vim.org>
parents:
18019
diff
changeset
|
1798 if (argcount == argskip) |
23fef64352a1
patch 8.1.2280: crash when passing partial to substitute()
Bram Moolenaar <Bram@vim.org>
parents:
18019
diff
changeset
|
1799 // called function doesn't take a submatches argument |
23fef64352a1
patch 8.1.2280: crash when passing partial to substitute()
Bram Moolenaar <Bram@vim.org>
parents:
18019
diff
changeset
|
1800 return argskip; |
9626
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9589
diff
changeset
|
1801 |
18572
23fef64352a1
patch 8.1.2280: crash when passing partial to substitute()
Bram Moolenaar <Bram@vim.org>
parents:
18019
diff
changeset
|
1802 // Relies on sl_list to be the first item in staticList10_T. |
23fef64352a1
patch 8.1.2280: crash when passing partial to substitute()
Bram Moolenaar <Bram@vim.org>
parents:
18019
diff
changeset
|
1803 init_static_list((staticList10_T *)(listarg->vval.v_list)); |
9626
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9589
diff
changeset
|
1804 |
18572
23fef64352a1
patch 8.1.2280: crash when passing partial to substitute()
Bram Moolenaar <Bram@vim.org>
parents:
18019
diff
changeset
|
1805 // There are always 10 list items in staticList10_T. |
23fef64352a1
patch 8.1.2280: crash when passing partial to substitute()
Bram Moolenaar <Bram@vim.org>
parents:
18019
diff
changeset
|
1806 li = listarg->vval.v_list->lv_first; |
9626
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9589
diff
changeset
|
1807 for (i = 0; i < 10; ++i) |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9589
diff
changeset
|
1808 { |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1809 s = rsm.sm_match->startp[i]; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1810 if (s == NULL || rsm.sm_match->endp[i] == NULL) |
9626
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9589
diff
changeset
|
1811 s = NULL; |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9589
diff
changeset
|
1812 else |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1813 s = vim_strnsave(s, (int)(rsm.sm_match->endp[i] - s)); |
9626
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9589
diff
changeset
|
1814 li->li_tv.v_type = VAR_STRING; |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9589
diff
changeset
|
1815 li->li_tv.vval.v_string = s; |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9589
diff
changeset
|
1816 li = li->li_next; |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9589
diff
changeset
|
1817 } |
18572
23fef64352a1
patch 8.1.2280: crash when passing partial to substitute()
Bram Moolenaar <Bram@vim.org>
parents:
18019
diff
changeset
|
1818 return argskip + 1; |
9626
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9589
diff
changeset
|
1819 } |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9589
diff
changeset
|
1820 |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9589
diff
changeset
|
1821 static void |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9589
diff
changeset
|
1822 clear_submatch_list(staticList10_T *sl) |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9589
diff
changeset
|
1823 { |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9589
diff
changeset
|
1824 int i; |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9589
diff
changeset
|
1825 |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9589
diff
changeset
|
1826 for (i = 0; i < 10; ++i) |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9589
diff
changeset
|
1827 vim_free(sl->sl_items[i].li_tv.vval.v_string); |
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9589
diff
changeset
|
1828 } |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
1829 #endif |
9626
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9589
diff
changeset
|
1830 |
7 | 1831 /* |
1832 * vim_regsub() - perform substitutions after a vim_regexec() or | |
1833 * vim_regexec_multi() match. | |
1834 * | |
1835 * If "copy" is TRUE really copy into "dest". | |
1836 * If "copy" is FALSE nothing is copied, this is just to find out the length | |
1837 * of the result. | |
1838 * | |
1839 * If "backslash" is TRUE, a backslash will be removed later, need to double | |
1840 * them to keep them, and insert a backslash before a CR to avoid it being | |
1841 * replaced with a line break later. | |
1842 * | |
1843 * Note: The matched text must not change between the call of | |
1844 * vim_regexec()/vim_regexec_multi() and vim_regsub()! It would make the back | |
1845 * references invalid! | |
1846 * | |
1847 * Returns the size of the replacement, including terminating NUL. | |
1848 */ | |
1849 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1850 vim_regsub( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1851 regmatch_T *rmp, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1852 char_u *source, |
9589
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9015
diff
changeset
|
1853 typval_T *expr, |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1854 char_u *dest, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1855 int copy, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1856 int magic, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1857 int backslash) |
7 | 1858 { |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1859 int result; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1860 regexec_T rex_save; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1861 int rex_in_use_save = rex_in_use; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1862 |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1863 if (rex_in_use) |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1864 // Being called recursively, save the state. |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1865 rex_save = rex; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1866 rex_in_use = TRUE; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1867 |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1868 rex.reg_match = rmp; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1869 rex.reg_mmatch = NULL; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1870 rex.reg_maxline = 0; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1871 rex.reg_buf = curbuf; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1872 rex.reg_line_lbr = TRUE; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1873 result = vim_regsub_both(source, expr, dest, copy, magic, backslash); |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1874 |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1875 rex_in_use = rex_in_use_save; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1876 if (rex_in_use) |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1877 rex = rex_save; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1878 |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1879 return result; |
7 | 1880 } |
1881 | |
1882 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1883 vim_regsub_multi( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1884 regmmatch_T *rmp, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1885 linenr_T lnum, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1886 char_u *source, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1887 char_u *dest, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1888 int copy, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1889 int magic, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1890 int backslash) |
7 | 1891 { |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1892 int result; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1893 regexec_T rex_save; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1894 int rex_in_use_save = rex_in_use; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1895 |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1896 if (rex_in_use) |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1897 // Being called recursively, save the state. |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1898 rex_save = rex; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1899 rex_in_use = TRUE; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1900 |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1901 rex.reg_match = NULL; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1902 rex.reg_mmatch = rmp; |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1903 rex.reg_buf = curbuf; // always works on the current buffer! |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1904 rex.reg_firstlnum = lnum; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1905 rex.reg_maxline = curbuf->b_ml.ml_line_count - lnum; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1906 rex.reg_line_lbr = FALSE; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1907 result = vim_regsub_both(source, NULL, dest, copy, magic, backslash); |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1908 |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1909 rex_in_use = rex_in_use_save; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1910 if (rex_in_use) |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1911 rex = rex_save; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1912 |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1913 return result; |
7 | 1914 } |
1915 | |
1916 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1917 vim_regsub_both( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1918 char_u *source, |
9589
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9015
diff
changeset
|
1919 typval_T *expr, |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1920 char_u *dest, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1921 int copy, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1922 int magic, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1923 int backslash) |
7 | 1924 { |
1925 char_u *src; | |
1926 char_u *dst; | |
1927 char_u *s; | |
1928 int c; | |
772 | 1929 int cc; |
7 | 1930 int no = -1; |
4244 | 1931 fptr_T func_all = (fptr_T)NULL; |
1932 fptr_T func_one = (fptr_T)NULL; | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1933 linenr_T clnum = 0; // init for GCC |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1934 int len = 0; // init for GCC |
7 | 1935 #ifdef FEAT_EVAL |
9589
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9015
diff
changeset
|
1936 static char_u *eval_result = NULL; |
7 | 1937 #endif |
1938 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1939 // Be paranoid... |
9589
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9015
diff
changeset
|
1940 if ((source == NULL && expr == NULL) || dest == NULL) |
7 | 1941 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15339
diff
changeset
|
1942 emsg(_(e_null)); |
7 | 1943 return 0; |
1944 } | |
1945 if (prog_magic_wrong()) | |
1946 return 0; | |
1947 src = source; | |
1948 dst = dest; | |
1949 | |
1950 /* | |
1951 * When the substitute part starts with "\=" evaluate it as an expression. | |
1952 */ | |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1953 if (expr != NULL || (source[0] == '\\' && source[1] == '=')) |
7 | 1954 { |
1955 #ifdef FEAT_EVAL | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1956 // To make sure that the length doesn't change between checking the |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1957 // length and copying the string, and to speed up things, the |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1958 // resulting string is saved from the call with "copy" == FALSE to the |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1959 // call with "copy" == TRUE. |
7 | 1960 if (copy) |
1961 { | |
1962 if (eval_result != NULL) | |
1963 { | |
1964 STRCPY(dest, eval_result); | |
1965 dst += STRLEN(eval_result); | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12752
diff
changeset
|
1966 VIM_CLEAR(eval_result); |
7 | 1967 } |
1968 } | |
1969 else | |
1970 { | |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1971 int prev_can_f_submatch = can_f_submatch; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1972 regsubmatch_T rsm_save; |
7 | 1973 |
1974 vim_free(eval_result); | |
1975 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1976 // The expression may contain substitute(), which calls us |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1977 // recursively. Make sure submatch() gets the text from the first |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1978 // level. |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1979 if (can_f_submatch) |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1980 rsm_save = rsm; |
7 | 1981 can_f_submatch = TRUE; |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1982 rsm.sm_match = rex.reg_match; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1983 rsm.sm_mmatch = rex.reg_mmatch; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1984 rsm.sm_firstlnum = rex.reg_firstlnum; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1985 rsm.sm_maxline = rex.reg_maxline; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1986 rsm.sm_line_lbr = rex.reg_line_lbr; |
7 | 1987 |
9589
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9015
diff
changeset
|
1988 if (expr != NULL) |
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9015
diff
changeset
|
1989 { |
9626
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9589
diff
changeset
|
1990 typval_T argv[2]; |
9589
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9015
diff
changeset
|
1991 char_u buf[NUMBUFLEN]; |
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9015
diff
changeset
|
1992 typval_T rettv; |
9626
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9589
diff
changeset
|
1993 staticList10_T matchList; |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17444
diff
changeset
|
1994 funcexe_T funcexe; |
9589
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9015
diff
changeset
|
1995 |
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9015
diff
changeset
|
1996 rettv.v_type = VAR_STRING; |
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9015
diff
changeset
|
1997 rettv.vval.v_string = NULL; |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1998 argv[0].v_type = VAR_LIST; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
1999 argv[0].vval.v_list = &matchList.sl_list; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2000 matchList.sl_list.lv_len = 0; |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17444
diff
changeset
|
2001 vim_memset(&funcexe, 0, sizeof(funcexe)); |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17444
diff
changeset
|
2002 funcexe.argv_func = fill_submatch_list; |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17444
diff
changeset
|
2003 funcexe.evaluate = TRUE; |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2004 if (expr->v_type == VAR_FUNC) |
9589
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9015
diff
changeset
|
2005 { |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2006 s = expr->vval.v_string; |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17444
diff
changeset
|
2007 call_func(s, -1, &rettv, 1, argv, &funcexe); |
9589
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9015
diff
changeset
|
2008 } |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2009 else if (expr->v_type == VAR_PARTIAL) |
9589
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9015
diff
changeset
|
2010 { |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2011 partial_T *partial = expr->vval.v_partial; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2012 |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2013 s = partial_name(partial); |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17444
diff
changeset
|
2014 funcexe.partial = partial; |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17444
diff
changeset
|
2015 call_func(s, -1, &rettv, 1, argv, &funcexe); |
9589
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9015
diff
changeset
|
2016 } |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2017 if (matchList.sl_list.lv_len > 0) |
18576
e9675870c480
patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents:
18572
diff
changeset
|
2018 // fill_submatch_list() was called |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2019 clear_submatch_list(&matchList); |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2020 |
18576
e9675870c480
patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents:
18572
diff
changeset
|
2021 if (rettv.v_type == VAR_UNKNOWN) |
e9675870c480
patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents:
18572
diff
changeset
|
2022 // something failed, no need to report another error |
e9675870c480
patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents:
18572
diff
changeset
|
2023 eval_result = NULL; |
e9675870c480
patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents:
18572
diff
changeset
|
2024 else |
e9675870c480
patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents:
18572
diff
changeset
|
2025 { |
e9675870c480
patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents:
18572
diff
changeset
|
2026 eval_result = tv_get_string_buf_chk(&rettv, buf); |
e9675870c480
patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents:
18572
diff
changeset
|
2027 if (eval_result != NULL) |
e9675870c480
patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents:
18572
diff
changeset
|
2028 eval_result = vim_strsave(eval_result); |
e9675870c480
patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents:
18572
diff
changeset
|
2029 } |
9626
172131507c85
commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents:
9589
diff
changeset
|
2030 clear_tv(&rettv); |
9589
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9015
diff
changeset
|
2031 } |
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9015
diff
changeset
|
2032 else |
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9015
diff
changeset
|
2033 eval_result = eval_to_string(source + 2, NULL, TRUE); |
bf204ab1ce7d
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents:
9015
diff
changeset
|
2034 |
7 | 2035 if (eval_result != NULL) |
2036 { | |
2125
b8744d1982d1
updated for version 7.2.407
Bram Moolenaar <bram@zimbu.org>
parents:
2012
diff
changeset
|
2037 int had_backslash = FALSE; |
b8744d1982d1
updated for version 7.2.407
Bram Moolenaar <bram@zimbu.org>
parents:
2012
diff
changeset
|
2038 |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
2039 for (s = eval_result; *s != NUL; MB_PTR_ADV(s)) |
7 | 2040 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2041 // Change NL to CR, so that it becomes a line break, |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2042 // unless called from vim_regexec_nl(). |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2043 // Skip over a backslashed character. |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2044 if (*s == NL && !rsm.sm_line_lbr) |
7 | 2045 *s = CAR; |
2046 else if (*s == '\\' && s[1] != NUL) | |
2125
b8744d1982d1
updated for version 7.2.407
Bram Moolenaar <bram@zimbu.org>
parents:
2012
diff
changeset
|
2047 { |
7 | 2048 ++s; |
2173 | 2049 /* Change NL to CR here too, so that this works: |
2050 * :s/abc\\\ndef/\="aaa\\\nbbb"/ on text: | |
2051 * abc\ | |
2052 * def | |
2904 | 2053 * Not when called from vim_regexec_nl(). |
2173 | 2054 */ |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2055 if (*s == NL && !rsm.sm_line_lbr) |
2173 | 2056 *s = CAR; |
2125
b8744d1982d1
updated for version 7.2.407
Bram Moolenaar <bram@zimbu.org>
parents:
2012
diff
changeset
|
2057 had_backslash = TRUE; |
b8744d1982d1
updated for version 7.2.407
Bram Moolenaar <bram@zimbu.org>
parents:
2012
diff
changeset
|
2058 } |
b8744d1982d1
updated for version 7.2.407
Bram Moolenaar <bram@zimbu.org>
parents:
2012
diff
changeset
|
2059 } |
b8744d1982d1
updated for version 7.2.407
Bram Moolenaar <bram@zimbu.org>
parents:
2012
diff
changeset
|
2060 if (had_backslash && backslash) |
b8744d1982d1
updated for version 7.2.407
Bram Moolenaar <bram@zimbu.org>
parents:
2012
diff
changeset
|
2061 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2062 // Backslashes will be consumed, need to double them. |
2125
b8744d1982d1
updated for version 7.2.407
Bram Moolenaar <bram@zimbu.org>
parents:
2012
diff
changeset
|
2063 s = vim_strsave_escaped(eval_result, (char_u *)"\\"); |
b8744d1982d1
updated for version 7.2.407
Bram Moolenaar <bram@zimbu.org>
parents:
2012
diff
changeset
|
2064 if (s != NULL) |
b8744d1982d1
updated for version 7.2.407
Bram Moolenaar <bram@zimbu.org>
parents:
2012
diff
changeset
|
2065 { |
b8744d1982d1
updated for version 7.2.407
Bram Moolenaar <bram@zimbu.org>
parents:
2012
diff
changeset
|
2066 vim_free(eval_result); |
b8744d1982d1
updated for version 7.2.407
Bram Moolenaar <bram@zimbu.org>
parents:
2012
diff
changeset
|
2067 eval_result = s; |
b8744d1982d1
updated for version 7.2.407
Bram Moolenaar <bram@zimbu.org>
parents:
2012
diff
changeset
|
2068 } |
7 | 2069 } |
2070 | |
2071 dst += STRLEN(eval_result); | |
2072 } | |
2073 | |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2074 can_f_submatch = prev_can_f_submatch; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2075 if (can_f_submatch) |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2076 rsm = rsm_save; |
7 | 2077 } |
2078 #endif | |
2079 } | |
2080 else | |
2081 while ((c = *src++) != NUL) | |
2082 { | |
2083 if (c == '&' && magic) | |
2084 no = 0; | |
2085 else if (c == '\\' && *src != NUL) | |
2086 { | |
2087 if (*src == '&' && !magic) | |
2088 { | |
2089 ++src; | |
2090 no = 0; | |
2091 } | |
2092 else if ('0' <= *src && *src <= '9') | |
2093 { | |
2094 no = *src++ - '0'; | |
2095 } | |
2096 else if (vim_strchr((char_u *)"uUlLeE", *src)) | |
2097 { | |
2098 switch (*src++) | |
2099 { | |
4244 | 2100 case 'u': func_one = (fptr_T)do_upper; |
7 | 2101 continue; |
4244 | 2102 case 'U': func_all = (fptr_T)do_Upper; |
7 | 2103 continue; |
4244 | 2104 case 'l': func_one = (fptr_T)do_lower; |
7 | 2105 continue; |
4244 | 2106 case 'L': func_all = (fptr_T)do_Lower; |
7 | 2107 continue; |
2108 case 'e': | |
4244 | 2109 case 'E': func_one = func_all = (fptr_T)NULL; |
7 | 2110 continue; |
2111 } | |
2112 } | |
2113 } | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2114 if (no < 0) // Ordinary character. |
7 | 2115 { |
798 | 2116 if (c == K_SPECIAL && src[0] != NUL && src[1] != NUL) |
2117 { | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2118 // Copy a special key as-is. |
798 | 2119 if (copy) |
2120 { | |
2121 *dst++ = c; | |
2122 *dst++ = *src++; | |
2123 *dst++ = *src++; | |
2124 } | |
2125 else | |
2126 { | |
2127 dst += 3; | |
2128 src += 2; | |
2129 } | |
2130 continue; | |
2131 } | |
2132 | |
7 | 2133 if (c == '\\' && *src != NUL) |
2134 { | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2135 // Check for abbreviations -- webb |
7 | 2136 switch (*src) |
2137 { | |
2138 case 'r': c = CAR; ++src; break; | |
2139 case 'n': c = NL; ++src; break; | |
2140 case 't': c = TAB; ++src; break; | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2141 // Oh no! \e already has meaning in subst pat :-( |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2142 // case 'e': c = ESC; ++src; break; |
7 | 2143 case 'b': c = Ctrl_H; ++src; break; |
2144 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2145 // If "backslash" is TRUE the backslash will be removed |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2146 // later. Used to insert a literal CR. |
7 | 2147 default: if (backslash) |
2148 { | |
2149 if (copy) | |
2150 *dst = '\\'; | |
2151 ++dst; | |
2152 } | |
2153 c = *src++; | |
2154 } | |
2155 } | |
798 | 2156 else if (has_mbyte) |
2157 c = mb_ptr2char(src - 1); | |
7 | 2158 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2159 // Write to buffer, if copy is set. |
4244 | 2160 if (func_one != (fptr_T)NULL) |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2161 // Turbo C complains without the typecast |
4244 | 2162 func_one = (fptr_T)(func_one(&cc, c)); |
2163 else if (func_all != (fptr_T)NULL) | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2164 // Turbo C complains without the typecast |
4244 | 2165 func_all = (fptr_T)(func_all(&cc, c)); |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2166 else // just copy |
772 | 2167 cc = c; |
2168 | |
2169 if (has_mbyte) | |
7 | 2170 { |
2307
81527f127fb1
Fix: Composing characters in :s substitute text were dropped.
Bram Moolenaar <bram@vim.org>
parents:
2247
diff
changeset
|
2171 int totlen = mb_ptr2len(src - 1); |
81527f127fb1
Fix: Composing characters in :s substitute text were dropped.
Bram Moolenaar <bram@vim.org>
parents:
2247
diff
changeset
|
2172 |
7 | 2173 if (copy) |
772 | 2174 mb_char2bytes(cc, dst); |
2175 dst += mb_char2len(cc) - 1; | |
2307
81527f127fb1
Fix: Composing characters in :s substitute text were dropped.
Bram Moolenaar <bram@vim.org>
parents:
2247
diff
changeset
|
2176 if (enc_utf8) |
81527f127fb1
Fix: Composing characters in :s substitute text were dropped.
Bram Moolenaar <bram@vim.org>
parents:
2247
diff
changeset
|
2177 { |
81527f127fb1
Fix: Composing characters in :s substitute text were dropped.
Bram Moolenaar <bram@vim.org>
parents:
2247
diff
changeset
|
2178 int clen = utf_ptr2len(src - 1); |
81527f127fb1
Fix: Composing characters in :s substitute text were dropped.
Bram Moolenaar <bram@vim.org>
parents:
2247
diff
changeset
|
2179 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2180 // If the character length is shorter than "totlen", there |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2181 // are composing characters; copy them as-is. |
2307
81527f127fb1
Fix: Composing characters in :s substitute text were dropped.
Bram Moolenaar <bram@vim.org>
parents:
2247
diff
changeset
|
2182 if (clen < totlen) |
81527f127fb1
Fix: Composing characters in :s substitute text were dropped.
Bram Moolenaar <bram@vim.org>
parents:
2247
diff
changeset
|
2183 { |
81527f127fb1
Fix: Composing characters in :s substitute text were dropped.
Bram Moolenaar <bram@vim.org>
parents:
2247
diff
changeset
|
2184 if (copy) |
81527f127fb1
Fix: Composing characters in :s substitute text were dropped.
Bram Moolenaar <bram@vim.org>
parents:
2247
diff
changeset
|
2185 mch_memmove(dst + 1, src - 1 + clen, |
81527f127fb1
Fix: Composing characters in :s substitute text were dropped.
Bram Moolenaar <bram@vim.org>
parents:
2247
diff
changeset
|
2186 (size_t)(totlen - clen)); |
81527f127fb1
Fix: Composing characters in :s substitute text were dropped.
Bram Moolenaar <bram@vim.org>
parents:
2247
diff
changeset
|
2187 dst += totlen - clen; |
81527f127fb1
Fix: Composing characters in :s substitute text were dropped.
Bram Moolenaar <bram@vim.org>
parents:
2247
diff
changeset
|
2188 } |
81527f127fb1
Fix: Composing characters in :s substitute text were dropped.
Bram Moolenaar <bram@vim.org>
parents:
2247
diff
changeset
|
2189 } |
81527f127fb1
Fix: Composing characters in :s substitute text were dropped.
Bram Moolenaar <bram@vim.org>
parents:
2247
diff
changeset
|
2190 src += totlen - 1; |
7 | 2191 } |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2192 else if (copy) |
772 | 2193 *dst = cc; |
7 | 2194 dst++; |
2195 } | |
2196 else | |
2197 { | |
2198 if (REG_MULTI) | |
2199 { | |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2200 clnum = rex.reg_mmatch->startpos[no].lnum; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2201 if (clnum < 0 || rex.reg_mmatch->endpos[no].lnum < 0) |
7 | 2202 s = NULL; |
2203 else | |
2204 { | |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2205 s = reg_getline(clnum) + rex.reg_mmatch->startpos[no].col; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2206 if (rex.reg_mmatch->endpos[no].lnum == clnum) |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2207 len = rex.reg_mmatch->endpos[no].col |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2208 - rex.reg_mmatch->startpos[no].col; |
7 | 2209 else |
2210 len = (int)STRLEN(s); | |
2211 } | |
2212 } | |
2213 else | |
2214 { | |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2215 s = rex.reg_match->startp[no]; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2216 if (rex.reg_match->endp[no] == NULL) |
7 | 2217 s = NULL; |
2218 else | |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2219 len = (int)(rex.reg_match->endp[no] - s); |
7 | 2220 } |
2221 if (s != NULL) | |
2222 { | |
2223 for (;;) | |
2224 { | |
2225 if (len == 0) | |
2226 { | |
2227 if (REG_MULTI) | |
2228 { | |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2229 if (rex.reg_mmatch->endpos[no].lnum == clnum) |
7 | 2230 break; |
2231 if (copy) | |
2232 *dst = CAR; | |
2233 ++dst; | |
2234 s = reg_getline(++clnum); | |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2235 if (rex.reg_mmatch->endpos[no].lnum == clnum) |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2236 len = rex.reg_mmatch->endpos[no].col; |
7 | 2237 else |
2238 len = (int)STRLEN(s); | |
2239 } | |
2240 else | |
2241 break; | |
2242 } | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2243 else if (*s == NUL) // we hit NUL. |
7 | 2244 { |
2245 if (copy) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15339
diff
changeset
|
2246 emsg(_(e_re_damg)); |
7 | 2247 goto exit; |
2248 } | |
2249 else | |
2250 { | |
2251 if (backslash && (*s == CAR || *s == '\\')) | |
2252 { | |
2253 /* | |
2254 * Insert a backslash in front of a CR, otherwise | |
2255 * it will be replaced by a line break. | |
2256 * Number of backslashes will be halved later, | |
2257 * double them here. | |
2258 */ | |
2259 if (copy) | |
2260 { | |
2261 dst[0] = '\\'; | |
2262 dst[1] = *s; | |
2263 } | |
2264 dst += 2; | |
2265 } | |
2266 else | |
2267 { | |
772 | 2268 if (has_mbyte) |
2269 c = mb_ptr2char(s); | |
2270 else | |
2271 c = *s; | |
2272 | |
4244 | 2273 if (func_one != (fptr_T)NULL) |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2274 // Turbo C complains without the typecast |
4244 | 2275 func_one = (fptr_T)(func_one(&cc, c)); |
2276 else if (func_all != (fptr_T)NULL) | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2277 // Turbo C complains without the typecast |
4244 | 2278 func_all = (fptr_T)(func_all(&cc, c)); |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2279 else // just copy |
772 | 2280 cc = c; |
2281 | |
2282 if (has_mbyte) | |
7 | 2283 { |
1332 | 2284 int l; |
2285 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2286 // Copy composing characters separately, one |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2287 // at a time. |
1332 | 2288 if (enc_utf8) |
2289 l = utf_ptr2len(s) - 1; | |
2290 else | |
2291 l = mb_ptr2len(s) - 1; | |
772 | 2292 |
2293 s += l; | |
2294 len -= l; | |
2295 if (copy) | |
2296 mb_char2bytes(cc, dst); | |
2297 dst += mb_char2len(cc) - 1; | |
7 | 2298 } |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2299 else if (copy) |
772 | 2300 *dst = cc; |
2301 dst++; | |
7 | 2302 } |
772 | 2303 |
7 | 2304 ++s; |
2305 --len; | |
2306 } | |
2307 } | |
2308 } | |
2309 no = -1; | |
2310 } | |
2311 } | |
2312 if (copy) | |
2313 *dst = NUL; | |
2314 | |
2315 exit: | |
2316 return (int)((dst - dest) + 1); | |
2317 } | |
2318 | |
2319 #ifdef FEAT_EVAL | |
2320 /* | |
2011 | 2321 * Call reg_getline() with the line numbers from the submatch. If a |
2322 * substitute() was used the reg_maxline and other values have been | |
2323 * overwritten. | |
2324 */ | |
2325 static char_u * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2326 reg_getline_submatch(linenr_T lnum) |
2011 | 2327 { |
2328 char_u *s; | |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2329 linenr_T save_first = rex.reg_firstlnum; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2330 linenr_T save_max = rex.reg_maxline; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2331 |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2332 rex.reg_firstlnum = rsm.sm_firstlnum; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2333 rex.reg_maxline = rsm.sm_maxline; |
2011 | 2334 |
2335 s = reg_getline(lnum); | |
2336 | |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2337 rex.reg_firstlnum = save_first; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2338 rex.reg_maxline = save_max; |
2011 | 2339 return s; |
2340 } | |
2341 | |
2342 /* | |
1209 | 2343 * Used for the submatch() function: get the string from the n'th submatch in |
7 | 2344 * allocated memory. |
2345 * Returns NULL when not in a ":s" command and for a non-existing submatch. | |
2346 */ | |
2347 char_u * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2348 reg_submatch(int no) |
7 | 2349 { |
2350 char_u *retval = NULL; | |
2351 char_u *s; | |
2352 int len; | |
2353 int round; | |
2354 linenr_T lnum; | |
2355 | |
840 | 2356 if (!can_f_submatch || no < 0) |
7 | 2357 return NULL; |
2358 | |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2359 if (rsm.sm_match == NULL) |
7 | 2360 { |
2361 /* | |
2362 * First round: compute the length and allocate memory. | |
2363 * Second round: copy the text. | |
2364 */ | |
2365 for (round = 1; round <= 2; ++round) | |
2366 { | |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2367 lnum = rsm.sm_mmatch->startpos[no].lnum; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2368 if (lnum < 0 || rsm.sm_mmatch->endpos[no].lnum < 0) |
7 | 2369 return NULL; |
2370 | |
16040
13ab270dd68d
patch 8.1.1025: checking NULL pointer after addition
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
2371 s = reg_getline_submatch(lnum); |
13ab270dd68d
patch 8.1.1025: checking NULL pointer after addition
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
2372 if (s == NULL) // anti-crash check, cannot happen? |
7 | 2373 break; |
16040
13ab270dd68d
patch 8.1.1025: checking NULL pointer after addition
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
2374 s += rsm.sm_mmatch->startpos[no].col; |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2375 if (rsm.sm_mmatch->endpos[no].lnum == lnum) |
7 | 2376 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2377 // Within one line: take form start to end col. |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2378 len = rsm.sm_mmatch->endpos[no].col |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2379 - rsm.sm_mmatch->startpos[no].col; |
7 | 2380 if (round == 2) |
418 | 2381 vim_strncpy(retval, s, len); |
7 | 2382 ++len; |
2383 } | |
2384 else | |
2385 { | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2386 // Multiple lines: take start line from start col, middle |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2387 // lines completely and end line up to end col. |
7 | 2388 len = (int)STRLEN(s); |
2389 if (round == 2) | |
2390 { | |
2391 STRCPY(retval, s); | |
2392 retval[len] = '\n'; | |
2393 } | |
2394 ++len; | |
2395 ++lnum; | |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2396 while (lnum < rsm.sm_mmatch->endpos[no].lnum) |
7 | 2397 { |
2011 | 2398 s = reg_getline_submatch(lnum++); |
7 | 2399 if (round == 2) |
2400 STRCPY(retval + len, s); | |
2401 len += (int)STRLEN(s); | |
2402 if (round == 2) | |
2403 retval[len] = '\n'; | |
2404 ++len; | |
2405 } | |
2406 if (round == 2) | |
2011 | 2407 STRNCPY(retval + len, reg_getline_submatch(lnum), |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2408 rsm.sm_mmatch->endpos[no].col); |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2409 len += rsm.sm_mmatch->endpos[no].col; |
7 | 2410 if (round == 2) |
2411 retval[len] = NUL; | |
2412 ++len; | |
2413 } | |
2414 | |
840 | 2415 if (retval == NULL) |
7 | 2416 { |
16768
695d9ef00b03
patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
2417 retval = alloc(len); |
840 | 2418 if (retval == NULL) |
7 | 2419 return NULL; |
2420 } | |
2421 } | |
2422 } | |
2423 else | |
2424 { | |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2425 s = rsm.sm_match->startp[no]; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2426 if (s == NULL || rsm.sm_match->endp[no] == NULL) |
7 | 2427 retval = NULL; |
2428 else | |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2429 retval = vim_strnsave(s, (int)(rsm.sm_match->endp[no] - s)); |
7 | 2430 } |
2431 | |
2432 return retval; | |
2433 } | |
5794 | 2434 |
2435 /* | |
2436 * Used for the submatch() function with the optional non-zero argument: get | |
2437 * the list of strings from the n'th submatch in allocated memory with NULs | |
2438 * represented in NLs. | |
2439 * Returns a list of allocated strings. Returns NULL when not in a ":s" | |
2440 * command, for a non-existing submatch and for any error. | |
2441 */ | |
2442 list_T * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2443 reg_submatch_list(int no) |
5794 | 2444 { |
2445 char_u *s; | |
2446 linenr_T slnum; | |
2447 linenr_T elnum; | |
2448 colnr_T scol; | |
2449 colnr_T ecol; | |
2450 int i; | |
2451 list_T *list; | |
2452 int error = FALSE; | |
2453 | |
2454 if (!can_f_submatch || no < 0) | |
2455 return NULL; | |
2456 | |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2457 if (rsm.sm_match == NULL) |
5794 | 2458 { |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2459 slnum = rsm.sm_mmatch->startpos[no].lnum; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2460 elnum = rsm.sm_mmatch->endpos[no].lnum; |
5794 | 2461 if (slnum < 0 || elnum < 0) |
2462 return NULL; | |
2463 | |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2464 scol = rsm.sm_mmatch->startpos[no].col; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2465 ecol = rsm.sm_mmatch->endpos[no].col; |
5794 | 2466 |
2467 list = list_alloc(); | |
2468 if (list == NULL) | |
2469 return NULL; | |
2470 | |
2471 s = reg_getline_submatch(slnum) + scol; | |
2472 if (slnum == elnum) | |
2473 { | |
2474 if (list_append_string(list, s, ecol - scol) == FAIL) | |
2475 error = TRUE; | |
2476 } | |
2477 else | |
2478 { | |
2479 if (list_append_string(list, s, -1) == FAIL) | |
2480 error = TRUE; | |
2481 for (i = 1; i < elnum - slnum; i++) | |
2482 { | |
2483 s = reg_getline_submatch(slnum + i); | |
2484 if (list_append_string(list, s, -1) == FAIL) | |
2485 error = TRUE; | |
2486 } | |
2487 s = reg_getline_submatch(elnum); | |
2488 if (list_append_string(list, s, ecol) == FAIL) | |
2489 error = TRUE; | |
2490 } | |
2491 } | |
2492 else | |
2493 { | |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2494 s = rsm.sm_match->startp[no]; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2495 if (s == NULL || rsm.sm_match->endp[no] == NULL) |
5794 | 2496 return NULL; |
2497 list = list_alloc(); | |
2498 if (list == NULL) | |
2499 return NULL; | |
2500 if (list_append_string(list, s, | |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2501 (int)(rsm.sm_match->endp[no] - s)) == FAIL) |
5794 | 2502 error = TRUE; |
2503 } | |
2504 | |
2505 if (error) | |
2506 { | |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8825
diff
changeset
|
2507 list_free(list); |
5794 | 2508 return NULL; |
2509 } | |
2510 return list; | |
2511 } | |
7 | 2512 #endif |
4444 | 2513 |
19405
08f4dc2ba716
patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents:
19384
diff
changeset
|
2514 /* |
08f4dc2ba716
patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents:
19384
diff
changeset
|
2515 * Initialize the values used for matching against multiple lines |
08f4dc2ba716
patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents:
19384
diff
changeset
|
2516 */ |
08f4dc2ba716
patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents:
19384
diff
changeset
|
2517 static void |
08f4dc2ba716
patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents:
19384
diff
changeset
|
2518 init_regexec_multi( |
08f4dc2ba716
patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents:
19384
diff
changeset
|
2519 regmmatch_T *rmp, |
08f4dc2ba716
patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents:
19384
diff
changeset
|
2520 win_T *win, // window in which to search or NULL |
08f4dc2ba716
patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents:
19384
diff
changeset
|
2521 buf_T *buf, // buffer in which to search |
08f4dc2ba716
patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents:
19384
diff
changeset
|
2522 linenr_T lnum) // nr of line to start looking for match |
08f4dc2ba716
patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents:
19384
diff
changeset
|
2523 { |
08f4dc2ba716
patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents:
19384
diff
changeset
|
2524 rex.reg_match = NULL; |
08f4dc2ba716
patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents:
19384
diff
changeset
|
2525 rex.reg_mmatch = rmp; |
08f4dc2ba716
patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents:
19384
diff
changeset
|
2526 rex.reg_buf = buf; |
08f4dc2ba716
patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents:
19384
diff
changeset
|
2527 rex.reg_win = win; |
08f4dc2ba716
patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents:
19384
diff
changeset
|
2528 rex.reg_firstlnum = lnum; |
08f4dc2ba716
patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents:
19384
diff
changeset
|
2529 rex.reg_maxline = rex.reg_buf->b_ml.ml_line_count - lnum; |
08f4dc2ba716
patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents:
19384
diff
changeset
|
2530 rex.reg_line_lbr = FALSE; |
08f4dc2ba716
patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents:
19384
diff
changeset
|
2531 rex.reg_ic = rmp->rmm_ic; |
08f4dc2ba716
patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents:
19384
diff
changeset
|
2532 rex.reg_icombine = FALSE; |
08f4dc2ba716
patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents:
19384
diff
changeset
|
2533 rex.reg_maxcol = rmp->rmm_maxcol; |
08f4dc2ba716
patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents:
19384
diff
changeset
|
2534 } |
08f4dc2ba716
patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents:
19384
diff
changeset
|
2535 |
18019
68fd5296bf73
patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2536 #include "regexp_bt.c" |
68fd5296bf73
patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2537 |
4444 | 2538 static regengine_T bt_regengine = |
2539 { | |
2540 bt_regcomp, | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
2541 bt_regfree, |
4444 | 2542 bt_regexec_nl, |
6328 | 2543 bt_regexec_multi, |
2544 (char_u *)"" | |
4444 | 2545 }; |
2546 | |
2547 #include "regexp_nfa.c" | |
2548 | |
2549 static regengine_T nfa_regengine = | |
2550 { | |
2551 nfa_regcomp, | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
2552 nfa_regfree, |
4444 | 2553 nfa_regexec_nl, |
6328 | 2554 nfa_regexec_multi, |
2555 (char_u *)"" | |
4444 | 2556 }; |
2557 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2558 // Which regexp engine to use? Needed for vim_regcomp(). |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2559 // Must match with 'regexpengine'. |
4444 | 2560 static int regexp_engine = 0; |
6328 | 2561 |
4444 | 2562 #ifdef DEBUG |
2563 static char_u regname[][30] = { | |
2564 "AUTOMATIC Regexp Engine", | |
4579
7a2be4a39423
updated for version 7.3.1037
Bram Moolenaar <bram@vim.org>
parents:
4505
diff
changeset
|
2565 "BACKTRACKING Regexp Engine", |
4444 | 2566 "NFA Regexp Engine" |
2567 }; | |
2568 #endif | |
2569 | |
2570 /* | |
2571 * Compile a regular expression into internal code. | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
2572 * Returns the program in allocated memory. |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
2573 * Use vim_regfree() to free the memory. |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
2574 * Returns NULL for an error. |
4444 | 2575 */ |
2576 regprog_T * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2577 vim_regcomp(char_u *expr_arg, int re_flags) |
4444 | 2578 { |
2579 regprog_T *prog = NULL; | |
2580 char_u *expr = expr_arg; | |
18949
5c405689da3e
patch 8.2.0035: saving and restoring called_emsg is clumsy
Bram Moolenaar <Bram@vim.org>
parents:
18812
diff
changeset
|
2581 int called_emsg_before; |
4444 | 2582 |
2583 regexp_engine = p_re; | |
2584 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2585 // Check for prefix "\%#=", that sets the regexp engine |
4444 | 2586 if (STRNCMP(expr, "\\%#=", 4) == 0) |
2587 { | |
2588 int newengine = expr[4] - '0'; | |
2589 | |
2590 if (newengine == AUTOMATIC_ENGINE | |
2591 || newengine == BACKTRACKING_ENGINE | |
2592 || newengine == NFA_ENGINE) | |
2593 { | |
2594 regexp_engine = expr[4] - '0'; | |
2595 expr += 5; | |
2596 #ifdef DEBUG | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15339
diff
changeset
|
2597 smsg("New regexp mode selected (%d): %s", |
5897 | 2598 regexp_engine, regname[newengine]); |
4444 | 2599 #endif |
2600 } | |
2601 else | |
2602 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15339
diff
changeset
|
2603 emsg(_("E864: \\%#= can only be followed by 0, 1, or 2. The automatic engine will be used ")); |
4444 | 2604 regexp_engine = AUTOMATIC_ENGINE; |
2605 } | |
2606 } | |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
2607 #ifdef DEBUG |
4444 | 2608 bt_regengine.expr = expr; |
2609 nfa_regengine.expr = expr; | |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
2610 #endif |
15856
e44b7caaf373
patch 8.1.0935: old regexp engine may use invalid buffer
Bram Moolenaar <Bram@vim.org>
parents:
15854
diff
changeset
|
2611 // reg_iswordc() uses rex.reg_buf |
e44b7caaf373
patch 8.1.0935: old regexp engine may use invalid buffer
Bram Moolenaar <Bram@vim.org>
parents:
15854
diff
changeset
|
2612 rex.reg_buf = curbuf; |
4444 | 2613 |
2614 /* | |
2615 * First try the NFA engine, unless backtracking was requested. | |
2616 */ | |
18949
5c405689da3e
patch 8.2.0035: saving and restoring called_emsg is clumsy
Bram Moolenaar <Bram@vim.org>
parents:
18812
diff
changeset
|
2617 called_emsg_before = called_emsg; |
4444 | 2618 if (regexp_engine != BACKTRACKING_ENGINE) |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12752
diff
changeset
|
2619 prog = nfa_regengine.regcomp(expr, |
6533 | 2620 re_flags + (regexp_engine == AUTOMATIC_ENGINE ? RE_AUTO : 0)); |
4444 | 2621 else |
2622 prog = bt_regengine.regcomp(expr, re_flags); | |
2623 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2624 // Check for error compiling regexp with initial engine. |
6328 | 2625 if (prog == NULL) |
4444 | 2626 { |
4460 | 2627 #ifdef BT_REGEXP_DEBUG_LOG |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2628 if (regexp_engine != BACKTRACKING_ENGINE) // debugging log for NFA |
4444 | 2629 { |
2630 FILE *f; | |
4460 | 2631 f = fopen(BT_REGEXP_DEBUG_LOG_NAME, "a"); |
4444 | 2632 if (f) |
2633 { | |
4762
47906f888725
updated for version 7.3.1128
Bram Moolenaar <bram@vim.org>
parents:
4760
diff
changeset
|
2634 fprintf(f, "Syntax error in \"%s\"\n", expr); |
4444 | 2635 fclose(f); |
2636 } | |
2637 else | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15339
diff
changeset
|
2638 semsg("(NFA) Could not open \"%s\" to write !!!", |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12752
diff
changeset
|
2639 BT_REGEXP_DEBUG_LOG_NAME); |
4444 | 2640 } |
2641 #endif | |
2642 /* | |
6328 | 2643 * If the NFA engine failed, try the backtracking engine. |
6533 | 2644 * The NFA engine also fails for patterns that it can't handle well |
2645 * but are still valid patterns, thus a retry should work. | |
15935
ff00d207cc5e
patch 8.1.0973: pattern with syntax error gives threee error messages
Bram Moolenaar <Bram@vim.org>
parents:
15860
diff
changeset
|
2646 * But don't try if an error message was given. |
6533 | 2647 */ |
18949
5c405689da3e
patch 8.2.0035: saving and restoring called_emsg is clumsy
Bram Moolenaar <Bram@vim.org>
parents:
18812
diff
changeset
|
2648 if (regexp_engine == AUTOMATIC_ENGINE |
5c405689da3e
patch 8.2.0035: saving and restoring called_emsg is clumsy
Bram Moolenaar <Bram@vim.org>
parents:
18812
diff
changeset
|
2649 && called_emsg == called_emsg_before) |
6328 | 2650 { |
6533 | 2651 regexp_engine = BACKTRACKING_ENGINE; |
4762
47906f888725
updated for version 7.3.1128
Bram Moolenaar <bram@vim.org>
parents:
4760
diff
changeset
|
2652 prog = bt_regengine.regcomp(expr, re_flags); |
6328 | 2653 } |
4762
47906f888725
updated for version 7.3.1128
Bram Moolenaar <bram@vim.org>
parents:
4760
diff
changeset
|
2654 } |
4444 | 2655 |
6328 | 2656 if (prog != NULL) |
2657 { | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2658 // Store the info needed to call regcomp() again when the engine turns |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2659 // out to be very slow when executing it. |
6328 | 2660 prog->re_engine = regexp_engine; |
2661 prog->re_flags = re_flags; | |
2662 } | |
2663 | |
4444 | 2664 return prog; |
2665 } | |
2666 | |
2667 /* | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
2668 * Free a compiled regexp program, returned by vim_regcomp(). |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
2669 */ |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
2670 void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2671 vim_regfree(regprog_T *prog) |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
2672 { |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
2673 if (prog != NULL) |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
2674 prog->engine->regfree(prog); |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
2675 } |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
2676 |
18019
68fd5296bf73
patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2677 #if defined(EXITFREE) || defined(PROTO) |
68fd5296bf73
patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2678 void |
68fd5296bf73
patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2679 free_regexp_stuff(void) |
68fd5296bf73
patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2680 { |
68fd5296bf73
patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2681 ga_clear(®stack); |
68fd5296bf73
patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2682 ga_clear(&backpos); |
68fd5296bf73
patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2683 vim_free(reg_tofree); |
68fd5296bf73
patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2684 vim_free(reg_prev_sub); |
68fd5296bf73
patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2685 } |
68fd5296bf73
patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2686 #endif |
68fd5296bf73
patch 8.1.2005: the regexp.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2687 |
6328 | 2688 #ifdef FEAT_EVAL |
2689 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2690 report_re_switch(char_u *pat) |
6328 | 2691 { |
2692 if (p_verbose > 0) | |
2693 { | |
2694 verbose_enter(); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15480
diff
changeset
|
2695 msg_puts(_("Switching to backtracking RE engine for pattern: ")); |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15480
diff
changeset
|
2696 msg_puts((char *)pat); |
6328 | 2697 verbose_leave(); |
2698 } | |
2699 } | |
2700 #endif | |
2701 | |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
2702 #if (defined(FEAT_X11) && (defined(FEAT_TITLE) || defined(FEAT_XCLIPBOARD))) \ |
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
2703 || defined(PROTO) |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
2704 /* |
15306
7fff2d18e191
patch 8.1.0661: clipboard regexp might be used recursively
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
2705 * Return whether "prog" is currently being executed. |
7fff2d18e191
patch 8.1.0661: clipboard regexp might be used recursively
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
2706 */ |
7fff2d18e191
patch 8.1.0661: clipboard regexp might be used recursively
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
2707 int |
7fff2d18e191
patch 8.1.0661: clipboard regexp might be used recursively
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
2708 regprog_in_use(regprog_T *prog) |
7fff2d18e191
patch 8.1.0661: clipboard regexp might be used recursively
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
2709 { |
7fff2d18e191
patch 8.1.0661: clipboard regexp might be used recursively
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
2710 return prog->re_in_use; |
7fff2d18e191
patch 8.1.0661: clipboard regexp might be used recursively
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
2711 } |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
2712 #endif |
15306
7fff2d18e191
patch 8.1.0661: clipboard regexp might be used recursively
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
2713 |
7fff2d18e191
patch 8.1.0661: clipboard regexp might be used recursively
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
2714 /* |
4444 | 2715 * Match a regexp against a string. |
2716 * "rmp->regprog" is a compiled regexp as returned by vim_regcomp(). | |
6375 | 2717 * Note: "rmp->regprog" may be freed and changed. |
4444 | 2718 * Uses curbuf for line count and 'iskeyword'. |
6328 | 2719 * When "nl" is TRUE consider a "\n" in "line" to be a line break. |
4444 | 2720 * |
2721 * Return TRUE if there is a match, FALSE if not. | |
2722 */ | |
6328 | 2723 static int |
11529
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11527
diff
changeset
|
2724 vim_regexec_string( |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2725 regmatch_T *rmp, |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2726 char_u *line, // string to match against |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2727 colnr_T col, // column to start looking for match |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2728 int nl) |
6328 | 2729 { |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2730 int result; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2731 regexec_T rex_save; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2732 int rex_in_use_save = rex_in_use; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2733 |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
2734 // Cannot use the same prog recursively, it contains state. |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
2735 if (rmp->regprog->re_in_use) |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
2736 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15339
diff
changeset
|
2737 emsg(_(e_recursive)); |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
2738 return FALSE; |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
2739 } |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
2740 rmp->regprog->re_in_use = TRUE; |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
2741 |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2742 if (rex_in_use) |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
2743 // Being called recursively, save the state. |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2744 rex_save = rex; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2745 rex_in_use = TRUE; |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
2746 |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2747 rex.reg_startp = NULL; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2748 rex.reg_endp = NULL; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2749 rex.reg_startpos = NULL; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2750 rex.reg_endpos = NULL; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2751 |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2752 result = rmp->regprog->engine->regexec_nl(rmp, line, col, nl); |
14358
72d506d94f3f
patch 8.1.0194: possibly use of NULL pointer
Christian Brabandt <cb@256bit.org>
parents:
14354
diff
changeset
|
2753 rmp->regprog->re_in_use = FALSE; |
6328 | 2754 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2755 // NFA engine aborted because it's very slow. |
6328 | 2756 if (rmp->regprog->re_engine == AUTOMATIC_ENGINE |
2757 && result == NFA_TOO_EXPENSIVE) | |
2758 { | |
2759 int save_p_re = p_re; | |
2760 int re_flags = rmp->regprog->re_flags; | |
2761 char_u *pat = vim_strsave(((nfa_regprog_T *)rmp->regprog)->pattern); | |
2762 | |
2763 p_re = BACKTRACKING_ENGINE; | |
2764 vim_regfree(rmp->regprog); | |
2765 if (pat != NULL) | |
2766 { | |
2767 #ifdef FEAT_EVAL | |
2768 report_re_switch(pat); | |
2769 #endif | |
2770 rmp->regprog = vim_regcomp(pat, re_flags); | |
2771 if (rmp->regprog != NULL) | |
14358
72d506d94f3f
patch 8.1.0194: possibly use of NULL pointer
Christian Brabandt <cb@256bit.org>
parents:
14354
diff
changeset
|
2772 { |
72d506d94f3f
patch 8.1.0194: possibly use of NULL pointer
Christian Brabandt <cb@256bit.org>
parents:
14354
diff
changeset
|
2773 rmp->regprog->re_in_use = TRUE; |
6328 | 2774 result = rmp->regprog->engine->regexec_nl(rmp, line, col, nl); |
14358
72d506d94f3f
patch 8.1.0194: possibly use of NULL pointer
Christian Brabandt <cb@256bit.org>
parents:
14354
diff
changeset
|
2775 rmp->regprog->re_in_use = FALSE; |
72d506d94f3f
patch 8.1.0194: possibly use of NULL pointer
Christian Brabandt <cb@256bit.org>
parents:
14354
diff
changeset
|
2776 } |
6328 | 2777 vim_free(pat); |
2778 } | |
2779 | |
2780 p_re = save_p_re; | |
2781 } | |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2782 |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2783 rex_in_use = rex_in_use_save; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2784 if (rex_in_use) |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2785 rex = rex_save; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2786 |
6390 | 2787 return result > 0; |
6328 | 2788 } |
2789 | |
6375 | 2790 /* |
2791 * Note: "*prog" may be freed and changed. | |
6390 | 2792 * Return TRUE if there is a match, FALSE if not. |
6375 | 2793 */ |
2794 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2795 vim_regexec_prog( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2796 regprog_T **prog, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2797 int ignore_case, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2798 char_u *line, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2799 colnr_T col) |
6375 | 2800 { |
11529
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11527
diff
changeset
|
2801 int r; |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11527
diff
changeset
|
2802 regmatch_T regmatch; |
6375 | 2803 |
2804 regmatch.regprog = *prog; | |
2805 regmatch.rm_ic = ignore_case; | |
11529
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11527
diff
changeset
|
2806 r = vim_regexec_string(®match, line, col, FALSE); |
6375 | 2807 *prog = regmatch.regprog; |
2808 return r; | |
2809 } | |
2810 | |
2811 /* | |
2812 * Note: "rmp->regprog" may be freed and changed. | |
6390 | 2813 * Return TRUE if there is a match, FALSE if not. |
6375 | 2814 */ |
4444 | 2815 int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2816 vim_regexec(regmatch_T *rmp, char_u *line, colnr_T col) |
4444 | 2817 { |
11529
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11527
diff
changeset
|
2818 return vim_regexec_string(rmp, line, col, FALSE); |
4444 | 2819 } |
2820 | |
2821 /* | |
2822 * Like vim_regexec(), but consider a "\n" in "line" to be a line break. | |
6375 | 2823 * Note: "rmp->regprog" may be freed and changed. |
6390 | 2824 * Return TRUE if there is a match, FALSE if not. |
4444 | 2825 */ |
2826 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2827 vim_regexec_nl(regmatch_T *rmp, char_u *line, colnr_T col) |
4444 | 2828 { |
11529
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11527
diff
changeset
|
2829 return vim_regexec_string(rmp, line, col, TRUE); |
4444 | 2830 } |
2831 | |
2832 /* | |
2833 * Match a regexp against multiple lines. | |
14161
7cac4646c552
patch 8.1.0098: segfault when pattern with z() is very slow
Christian Brabandt <cb@256bit.org>
parents:
13286
diff
changeset
|
2834 * "rmp->regprog" must be a compiled regexp as returned by vim_regcomp(). |
7cac4646c552
patch 8.1.0098: segfault when pattern with z() is very slow
Christian Brabandt <cb@256bit.org>
parents:
13286
diff
changeset
|
2835 * Note: "rmp->regprog" may be freed and changed, even set to NULL. |
4444 | 2836 * Uses curbuf for line count and 'iskeyword'. |
2837 * | |
2838 * Return zero if there is no match. Return number of lines contained in the | |
2839 * match otherwise. | |
2840 */ | |
2841 long | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2842 vim_regexec_multi( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2843 regmmatch_T *rmp, |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2844 win_T *win, // window in which to search or NULL |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2845 buf_T *buf, // buffer in which to search |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2846 linenr_T lnum, // nr of line to start looking for match |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2847 colnr_T col, // column to start looking for match |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2848 proftime_T *tm, // timeout limit or NULL |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2849 int *timed_out) // flag is set when timeout limit reached |
4444 | 2850 { |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2851 int result; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2852 regexec_T rex_save; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2853 int rex_in_use_save = rex_in_use; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2854 |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
2855 // Cannot use the same prog recursively, it contains state. |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
2856 if (rmp->regprog->re_in_use) |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
2857 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15339
diff
changeset
|
2858 emsg(_(e_recursive)); |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
2859 return FALSE; |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
2860 } |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
2861 rmp->regprog->re_in_use = TRUE; |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14169
diff
changeset
|
2862 |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2863 if (rex_in_use) |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2864 // Being called recursively, save the state. |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2865 rex_save = rex; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2866 rex_in_use = TRUE; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2867 |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11482
diff
changeset
|
2868 result = rmp->regprog->engine->regexec_multi( |
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11482
diff
changeset
|
2869 rmp, win, buf, lnum, col, tm, timed_out); |
14358
72d506d94f3f
patch 8.1.0194: possibly use of NULL pointer
Christian Brabandt <cb@256bit.org>
parents:
14354
diff
changeset
|
2870 rmp->regprog->re_in_use = FALSE; |
6328 | 2871 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2872 // NFA engine aborted because it's very slow. |
6328 | 2873 if (rmp->regprog->re_engine == AUTOMATIC_ENGINE |
2874 && result == NFA_TOO_EXPENSIVE) | |
2875 { | |
2876 int save_p_re = p_re; | |
2877 int re_flags = rmp->regprog->re_flags; | |
2878 char_u *pat = vim_strsave(((nfa_regprog_T *)rmp->regprog)->pattern); | |
2879 | |
2880 p_re = BACKTRACKING_ENGINE; | |
2881 vim_regfree(rmp->regprog); | |
2882 if (pat != NULL) | |
2883 { | |
2884 #ifdef FEAT_EVAL | |
2885 report_re_switch(pat); | |
2886 #endif | |
14169
42a9178374d1
patch 8.1.0102: cannot build without syntax highlighting
Christian Brabandt <cb@256bit.org>
parents:
14161
diff
changeset
|
2887 #ifdef FEAT_SYN_HL |
14161
7cac4646c552
patch 8.1.0098: segfault when pattern with z() is very slow
Christian Brabandt <cb@256bit.org>
parents:
13286
diff
changeset
|
2888 // checking for \z misuse was already done when compiling for NFA, |
7cac4646c552
patch 8.1.0098: segfault when pattern with z() is very slow
Christian Brabandt <cb@256bit.org>
parents:
13286
diff
changeset
|
2889 // allow all here |
7cac4646c552
patch 8.1.0098: segfault when pattern with z() is very slow
Christian Brabandt <cb@256bit.org>
parents:
13286
diff
changeset
|
2890 reg_do_extmatch = REX_ALL; |
14169
42a9178374d1
patch 8.1.0102: cannot build without syntax highlighting
Christian Brabandt <cb@256bit.org>
parents:
14161
diff
changeset
|
2891 #endif |
6328 | 2892 rmp->regprog = vim_regcomp(pat, re_flags); |
14169
42a9178374d1
patch 8.1.0102: cannot build without syntax highlighting
Christian Brabandt <cb@256bit.org>
parents:
14161
diff
changeset
|
2893 #ifdef FEAT_SYN_HL |
14161
7cac4646c552
patch 8.1.0098: segfault when pattern with z() is very slow
Christian Brabandt <cb@256bit.org>
parents:
13286
diff
changeset
|
2894 reg_do_extmatch = 0; |
14169
42a9178374d1
patch 8.1.0102: cannot build without syntax highlighting
Christian Brabandt <cb@256bit.org>
parents:
14161
diff
changeset
|
2895 #endif |
14161
7cac4646c552
patch 8.1.0098: segfault when pattern with z() is very slow
Christian Brabandt <cb@256bit.org>
parents:
13286
diff
changeset
|
2896 |
6328 | 2897 if (rmp->regprog != NULL) |
14358
72d506d94f3f
patch 8.1.0194: possibly use of NULL pointer
Christian Brabandt <cb@256bit.org>
parents:
14354
diff
changeset
|
2898 { |
72d506d94f3f
patch 8.1.0194: possibly use of NULL pointer
Christian Brabandt <cb@256bit.org>
parents:
14354
diff
changeset
|
2899 rmp->regprog->re_in_use = TRUE; |
6328 | 2900 result = rmp->regprog->engine->regexec_multi( |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11482
diff
changeset
|
2901 rmp, win, buf, lnum, col, tm, timed_out); |
14358
72d506d94f3f
patch 8.1.0194: possibly use of NULL pointer
Christian Brabandt <cb@256bit.org>
parents:
14354
diff
changeset
|
2902 rmp->regprog->re_in_use = FALSE; |
72d506d94f3f
patch 8.1.0194: possibly use of NULL pointer
Christian Brabandt <cb@256bit.org>
parents:
14354
diff
changeset
|
2903 } |
6328 | 2904 vim_free(pat); |
2905 } | |
2906 p_re = save_p_re; | |
2907 } | |
2908 | |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2909 rex_in_use = rex_in_use_save; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2910 if (rex_in_use) |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2911 rex = rex_save; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10187
diff
changeset
|
2912 |
6390 | 2913 return result <= 0 ? 0 : result; |
4444 | 2914 } |