]>
Commit | Line | Data |
---|---|---|
51f9884c AG |
1 | To: vim-dev@vim.org |
2 | Subject: Patch 6.2.411 | |
3 | Fcc: outbox | |
4 | From: Bram Moolenaar <Bram@moolenaar.net> | |
5 | Mime-Version: 1.0 | |
6 | Content-Type: text/plain; charset=ISO-8859-1 | |
7 | Content-Transfer-Encoding: 8bit | |
8 | ------------ | |
9 | ||
10 | Patch 6.2.411 | |
11 | Problem: A "\n" inside a string is not seen as a line break by the regular | |
12 | expression matching. (Hari Krishna Dara) | |
13 | Solution: Add the vim_regexec_nl() function for strings where "\n" is to be | |
14 | matched with a line break. | |
15 | Files: src/eval.c, src/ex_eval.c, src/proto/regexp.c, src/regexp.c | |
16 | ||
17 | ||
18 | *** ../vim-6.2.410/src/eval.c Sat Mar 27 13:23:01 2004 | |
19 | --- src/eval.c Sun Mar 28 11:56:13 2004 | |
20 | *************** | |
21 | *** 1996,2002 **** | |
22 | regmatch.rm_ic = ic; | |
23 | if (regmatch.regprog != NULL) | |
24 | { | |
25 | ! n1 = vim_regexec(®match, s1, (colnr_T)0); | |
26 | vim_free(regmatch.regprog); | |
27 | if (type == TYPE_NOMATCH) | |
28 | n1 = !n1; | |
29 | --- 1998,2004 ---- | |
30 | regmatch.rm_ic = ic; | |
31 | if (regmatch.regprog != NULL) | |
32 | { | |
33 | ! n1 = vim_regexec_nl(®match, s1, (colnr_T)0); | |
34 | vim_free(regmatch.regprog); | |
35 | if (type == TYPE_NOMATCH) | |
36 | n1 = !n1; | |
37 | *************** | |
38 | *** 5763,5769 **** | |
39 | if (regmatch.regprog != NULL) | |
40 | { | |
41 | regmatch.rm_ic = p_ic; | |
42 | ! if (vim_regexec(®match, str, (colnr_T)0)) | |
43 | { | |
44 | if (type == 2) | |
45 | retvar->var_val.var_string = vim_strnsave(regmatch.startp[0], | |
46 | --- 5765,5771 ---- | |
47 | if (regmatch.regprog != NULL) | |
48 | { | |
49 | regmatch.rm_ic = p_ic; | |
50 | ! if (vim_regexec_nl(®match, str, (colnr_T)0)) | |
51 | { | |
52 | if (type == 2) | |
53 | retvar->var_val.var_string = vim_strnsave(regmatch.startp[0], | |
54 | *************** | |
55 | *** 5771,5779 **** | |
56 | else | |
57 | { | |
58 | if (type != 0) | |
59 | ! retvar->var_val.var_number = (varnumber_T) (regmatch.startp[0] - str); | |
60 | else | |
61 | ! retvar->var_val.var_number = (varnumber_T) (regmatch.endp[0] - str); | |
62 | retvar->var_val.var_number += start; | |
63 | } | |
64 | } | |
65 | --- 5773,5783 ---- | |
66 | else | |
67 | { | |
68 | if (type != 0) | |
69 | ! retvar->var_val.var_number = | |
70 | ! (varnumber_T)(regmatch.startp[0] - str); | |
71 | else | |
72 | ! retvar->var_val.var_number = | |
73 | ! (varnumber_T)(regmatch.endp[0] - str); | |
74 | retvar->var_val.var_number += start; | |
75 | } | |
76 | } | |
77 | *************** | |
78 | *** 8235,8241 **** | |
79 | ||
80 | /* | |
81 | * Get the string value of a (global/local) variable. | |
82 | ! * Returns NULL when it doesn't exit. | |
83 | */ | |
84 | char_u * | |
85 | get_var_value(name) | |
86 | --- 8239,8245 ---- | |
87 | ||
88 | /* | |
89 | * Get the string value of a (global/local) variable. | |
90 | ! * Returns NULL when it doesn't exist. | |
91 | */ | |
92 | char_u * | |
93 | get_var_value(name) | |
94 | *************** | |
95 | *** 10477,10483 **** | |
96 | if (regmatch.regprog != NULL) | |
97 | { | |
98 | tail = str; | |
99 | ! while (vim_regexec(®match, str, (colnr_T)(tail - str))) | |
100 | { | |
101 | /* | |
102 | * Get some space for a temporary buffer to do the substitution | |
103 | --- 10481,10487 ---- | |
104 | if (regmatch.regprog != NULL) | |
105 | { | |
106 | tail = str; | |
107 | ! while (vim_regexec_nl(®match, str, (colnr_T)(tail - str))) | |
108 | { | |
109 | /* | |
110 | * Get some space for a temporary buffer to do the substitution | |
111 | *** ../vim-6.2.410/src/ex_eval.c Thu Feb 5 16:04:26 2004 | |
112 | --- src/ex_eval.c Fri Mar 26 12:23:47 2004 | |
113 | *************** | |
114 | *** 1456,1462 **** | |
115 | */ | |
116 | prev_got_int = got_int; | |
117 | got_int = FALSE; | |
118 | ! caught = vim_regexec(®match, current_exception->value, | |
119 | (colnr_T)0); | |
120 | got_int |= prev_got_int; | |
121 | vim_free(regmatch.regprog); | |
122 | --- 1456,1462 ---- | |
123 | */ | |
124 | prev_got_int = got_int; | |
125 | got_int = FALSE; | |
126 | ! caught = vim_regexec_nl(®match, current_exception->value, | |
127 | (colnr_T)0); | |
128 | got_int |= prev_got_int; | |
129 | vim_free(regmatch.regprog); | |
130 | diff: src/proto/regexp.c: No such file or directory | |
131 | *** ../vim-6.2.410/src/regexp.c Wed Mar 17 14:08:56 2004 | |
132 | --- src/regexp.c Fri Mar 26 12:46:45 2004 | |
133 | *************** | |
134 | *** 2671,2676 **** | |
135 | --- 2671,2677 ---- | |
136 | * reg_buf <invalid> buffer in which to search | |
137 | * reg_firstlnum <invalid> first line in which to search | |
138 | * reg_maxline 0 last line nr | |
139 | + * reg_line_lbr FALSE or TRUE FALSE | |
140 | */ | |
141 | static regmatch_T *reg_match; | |
142 | static regmmatch_T *reg_mmatch; | |
143 | *************** | |
144 | *** 2682,2687 **** | |
145 | --- 2683,2689 ---- | |
146 | static buf_T *reg_buf; | |
147 | static linenr_T reg_firstlnum; | |
148 | static linenr_T reg_maxline; | |
149 | + static int reg_line_lbr; /* "\n" in string is line break */ | |
150 | ||
151 | /* | |
152 | * Get pointer to the line "lnum", which is relative to "reg_firstlnum". | |
153 | *************** | |
154 | *** 2725,2730 **** | |
155 | --- 2727,2733 ---- | |
156 | reg_match = rmp; | |
157 | reg_mmatch = NULL; | |
158 | reg_maxline = 0; | |
159 | + reg_line_lbr = FALSE; | |
160 | reg_win = NULL; | |
161 | ireg_ic = rmp->rm_ic; | |
162 | #ifdef FEAT_MBYTE | |
163 | *************** | |
164 | *** 2733,2738 **** | |
165 | --- 2736,2764 ---- | |
166 | return (vim_regexec_both(line, col) != 0); | |
167 | } | |
168 | ||
169 | + #if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) || defined(PROTO) | |
170 | + /* | |
171 | + * Like vim_regexec(), but consider a "\n" in "line" to be a line break. | |
172 | + */ | |
173 | + int | |
174 | + vim_regexec_nl(rmp, line, col) | |
175 | + regmatch_T *rmp; | |
176 | + char_u *line; /* string to match against */ | |
177 | + colnr_T col; /* column to start looking for match */ | |
178 | + { | |
179 | + reg_match = rmp; | |
180 | + reg_mmatch = NULL; | |
181 | + reg_maxline = 0; | |
182 | + reg_line_lbr = TRUE; | |
183 | + reg_win = NULL; | |
184 | + ireg_ic = rmp->rm_ic; | |
185 | + #ifdef FEAT_MBYTE | |
186 | + ireg_icombine = FALSE; | |
187 | + #endif | |
188 | + return (vim_regexec_both(line, col) != 0); | |
189 | + } | |
190 | + #endif | |
191 | + | |
192 | /* | |
193 | * Match a regexp against multiple lines. | |
194 | * "rmp->regprog" is a compiled regexp as returned by vim_regcomp(). | |
195 | *************** | |
196 | *** 2758,2763 **** | |
197 | --- 2784,2790 ---- | |
198 | reg_win = win; | |
199 | reg_firstlnum = lnum; | |
200 | reg_maxline = reg_buf->b_ml.ml_line_count - lnum; | |
201 | + reg_line_lbr = FALSE; | |
202 | ireg_ic = rmp->rmm_ic; | |
203 | #ifdef FEAT_MBYTE | |
204 | ireg_icombine = FALSE; | |
205 | *************** | |
206 | *** 3230,3235 **** | |
207 | --- 3257,3266 ---- | |
208 | { | |
209 | reg_nextline(); | |
210 | } | |
211 | + else if (reg_line_lbr && WITH_NL(op) && *reginput == '\n') | |
212 | + { | |
213 | + ADVANCE_REGINPUT(); | |
214 | + } | |
215 | else | |
216 | { | |
217 | if (WITH_NL(op)) | |
218 | *************** | |
219 | *** 4201,4209 **** | |
220 | break; | |
221 | ||
222 | case NEWL: | |
223 | ! if (c != NUL || reglnum == reg_maxline) | |
224 | return FALSE; | |
225 | ! reg_nextline(); | |
226 | break; | |
227 | ||
228 | case END: | |
229 | --- 4232,4244 ---- | |
230 | break; | |
231 | ||
232 | case NEWL: | |
233 | ! if ((c != NUL || reglnum == reg_maxline) | |
234 | ! && (c != '\n' || !reg_line_lbr)) | |
235 | return FALSE; | |
236 | ! if (reg_line_lbr) | |
237 | ! ADVANCE_REGINPUT(); | |
238 | ! else | |
239 | ! reg_nextline(); | |
240 | break; | |
241 | ||
242 | case END: | |
243 | *************** | |
244 | *** 4299,4304 **** | |
245 | --- 4334,4341 ---- | |
246 | if (got_int) | |
247 | break; | |
248 | } | |
249 | + else if (reg_line_lbr && *scan == '\n' && WITH_NL(OP(p))) | |
250 | + ++scan; | |
251 | else | |
252 | break; | |
253 | ++count; | |
254 | *************** | |
255 | *** 4326,4331 **** | |
256 | --- 4363,4370 ---- | |
257 | if (got_int) | |
258 | break; | |
259 | } | |
260 | + else if (reg_line_lbr && *scan == '\n' && WITH_NL(OP(p))) | |
261 | + ++scan; | |
262 | else | |
263 | break; | |
264 | ++count; | |
265 | *************** | |
266 | *** 4353,4358 **** | |
267 | --- 4392,4399 ---- | |
268 | if (got_int) | |
269 | break; | |
270 | } | |
271 | + else if (reg_line_lbr && *scan == '\n' && WITH_NL(OP(p))) | |
272 | + ++scan; | |
273 | else | |
274 | break; | |
275 | ++count; | |
276 | *************** | |
277 | *** 4380,4385 **** | |
278 | --- 4421,4428 ---- | |
279 | { | |
280 | ADVANCE_P(scan); | |
281 | } | |
282 | + else if (reg_line_lbr && *scan == '\n' && WITH_NL(OP(p))) | |
283 | + ++scan; | |
284 | else | |
285 | break; | |
286 | ++count; | |
287 | *************** | |
288 | *** 4414,4419 **** | |
289 | --- 4457,4464 ---- | |
290 | #endif | |
291 | else if ((class_tab[*scan] & mask) == testval) | |
292 | ++scan; | |
293 | + else if (reg_line_lbr && *scan == '\n' && WITH_NL(OP(p))) | |
294 | + ++scan; | |
295 | else | |
296 | break; | |
297 | ++count; | |
298 | *************** | |
299 | *** 4565,4570 **** | |
300 | --- 4610,4617 ---- | |
301 | if (got_int) | |
302 | break; | |
303 | } | |
304 | + else if (reg_line_lbr && *scan == '\n' && WITH_NL(OP(p))) | |
305 | + ++scan; | |
306 | #ifdef FEAT_MBYTE | |
307 | else if (has_mbyte && (len = (*mb_ptr2len_check)(scan)) > 1) | |
308 | { | |
309 | *************** | |
310 | *** 4584,4593 **** | |
311 | break; | |
312 | ||
313 | case NEWL: | |
314 | ! while (count < maxcount && *scan == NUL && reglnum < reg_maxline) | |
315 | { | |
316 | count++; | |
317 | ! reg_nextline(); | |
318 | scan = reginput; | |
319 | if (got_int) | |
320 | break; | |
321 | --- 4631,4645 ---- | |
322 | break; | |
323 | ||
324 | case NEWL: | |
325 | ! while (count < maxcount | |
326 | ! && ((*scan == NUL && reglnum < reg_maxline) | |
327 | ! || (*scan == '\n' && reg_line_lbr))) | |
328 | { | |
329 | count++; | |
330 | ! if (reg_line_lbr) | |
331 | ! ADVANCE_REGINPUT(); | |
332 | ! else | |
333 | ! reg_nextline(); | |
334 | scan = reginput; | |
335 | if (got_int) | |
336 | break; | |
337 | *** ../vim-6.2.410/src/version.c Mon Mar 29 12:16:31 2004 | |
338 | --- src/version.c Mon Mar 29 14:29:22 2004 | |
339 | *************** | |
340 | *** 639,640 **** | |
341 | --- 639,642 ---- | |
342 | { /* Add new patch number below this line */ | |
343 | + /**/ | |
344 | + 411, | |
345 | /**/ | |
346 | ||
347 | -- | |
348 | hundred-and-one symptoms of being an internet addict: | |
349 | 171. You invent another person and chat with yourself in empty chat rooms. | |
350 | ||
351 | /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ | |
352 | /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ | |
353 | \\\ Project leader for A-A-P -- http://www.A-A-P.org /// | |
354 | \\\ Buy at Amazon and help AIDS victims -- http://ICCF.nl/click1.html /// |