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