comparison src/regexp_bt.c @ 18029:72524e906658 v8.1.2010

patch 8.1.2010: new file uses old style comments Commit: https://github.com/vim/vim/commit/9490b9a61cf1f1f3fa9758663a33124ea9f71c87 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Sep 8 17:20:12 2019 +0200 patch 8.1.2010: new file uses old style comments Problem: New file uses old style comments. Solution: Change to new style comments. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/4910)
author Bram Moolenaar <Bram@vim.org>
date Sun, 08 Sep 2019 17:30:03 +0200
parents 68fd5296bf73
children c62d63d2b9f0
comparison
equal deleted inserted replaced
18028:2bc45b2e57c2 18029:72524e906658
132 132
133 /* 133 /*
134 * The opcodes are: 134 * The opcodes are:
135 */ 135 */
136 136
137 /* definition number opnd? meaning */ 137 // definition number opnd? meaning
138 #define END 0 /* End of program or NOMATCH operand. */ 138 #define END 0 // End of program or NOMATCH operand.
139 #define BOL 1 /* Match "" at beginning of line. */ 139 #define BOL 1 // Match "" at beginning of line.
140 #define EOL 2 /* Match "" at end of line. */ 140 #define EOL 2 // Match "" at end of line.
141 #define BRANCH 3 /* node Match this alternative, or the 141 #define BRANCH 3 // node Match this alternative, or the
142 * next... */ 142 // next...
143 #define BACK 4 /* Match "", "next" ptr points backward. */ 143 #define BACK 4 // Match "", "next" ptr points backward.
144 #define EXACTLY 5 /* str Match this string. */ 144 #define EXACTLY 5 // str Match this string.
145 #define NOTHING 6 /* Match empty string. */ 145 #define NOTHING 6 // Match empty string.
146 #define STAR 7 /* node Match this (simple) thing 0 or more 146 #define STAR 7 // node Match this (simple) thing 0 or more
147 * times. */ 147 // times.
148 #define PLUS 8 /* node Match this (simple) thing 1 or more 148 #define PLUS 8 // node Match this (simple) thing 1 or more
149 * times. */ 149 // times.
150 #define MATCH 9 /* node match the operand zero-width */ 150 #define MATCH 9 // node match the operand zero-width
151 #define NOMATCH 10 /* node check for no match with operand */ 151 #define NOMATCH 10 // node check for no match with operand
152 #define BEHIND 11 /* node look behind for a match with operand */ 152 #define BEHIND 11 // node look behind for a match with operand
153 #define NOBEHIND 12 /* node look behind for no match with operand */ 153 #define NOBEHIND 12 // node look behind for no match with operand
154 #define SUBPAT 13 /* node match the operand here */ 154 #define SUBPAT 13 // node match the operand here
155 #define BRACE_SIMPLE 14 /* node Match this (simple) thing between m and 155 #define BRACE_SIMPLE 14 // node Match this (simple) thing between m and
156 * n times (\{m,n\}). */ 156 // n times (\{m,n\}).
157 #define BOW 15 /* Match "" after [^a-zA-Z0-9_] */ 157 #define BOW 15 // Match "" after [^a-zA-Z0-9_]
158 #define EOW 16 /* Match "" at [^a-zA-Z0-9_] */ 158 #define EOW 16 // Match "" at [^a-zA-Z0-9_]
159 #define BRACE_LIMITS 17 /* nr nr define the min & max for BRACE_SIMPLE 159 #define BRACE_LIMITS 17 // nr nr define the min & max for BRACE_SIMPLE
160 * and BRACE_COMPLEX. */ 160 // and BRACE_COMPLEX.
161 #define NEWL 18 /* Match line-break */ 161 #define NEWL 18 // Match line-break
162 #define BHPOS 19 /* End position for BEHIND or NOBEHIND */ 162 #define BHPOS 19 // End position for BEHIND or NOBEHIND
163 163
164 164
165 /* character classes: 20-48 normal, 50-78 include a line-break */ 165 // character classes: 20-48 normal, 50-78 include a line-break
166 #define ADD_NL 30 166 #define ADD_NL 30
167 #define FIRST_NL ANY + ADD_NL 167 #define FIRST_NL ANY + ADD_NL
168 #define ANY 20 /* Match any one character. */ 168 #define ANY 20 // Match any one character.
169 #define ANYOF 21 /* str Match any character in this string. */ 169 #define ANYOF 21 // str Match any character in this string.
170 #define ANYBUT 22 /* str Match any character not in this 170 #define ANYBUT 22 // str Match any character not in this
171 * string. */ 171 // string.
172 #define IDENT 23 /* Match identifier char */ 172 #define IDENT 23 // Match identifier char
173 #define SIDENT 24 /* Match identifier char but no digit */ 173 #define SIDENT 24 // Match identifier char but no digit
174 #define KWORD 25 /* Match keyword char */ 174 #define KWORD 25 // Match keyword char
175 #define SKWORD 26 /* Match word char but no digit */ 175 #define SKWORD 26 // Match word char but no digit
176 #define FNAME 27 /* Match file name char */ 176 #define FNAME 27 // Match file name char
177 #define SFNAME 28 /* Match file name char but no digit */ 177 #define SFNAME 28 // Match file name char but no digit
178 #define PRINT 29 /* Match printable char */ 178 #define PRINT 29 // Match printable char
179 #define SPRINT 30 /* Match printable char but no digit */ 179 #define SPRINT 30 // Match printable char but no digit
180 #define WHITE 31 /* Match whitespace char */ 180 #define WHITE 31 // Match whitespace char
181 #define NWHITE 32 /* Match non-whitespace char */ 181 #define NWHITE 32 // Match non-whitespace char
182 #define DIGIT 33 /* Match digit char */ 182 #define DIGIT 33 // Match digit char
183 #define NDIGIT 34 /* Match non-digit char */ 183 #define NDIGIT 34 // Match non-digit char
184 #define HEX 35 /* Match hex char */ 184 #define HEX 35 // Match hex char
185 #define NHEX 36 /* Match non-hex char */ 185 #define NHEX 36 // Match non-hex char
186 #define OCTAL 37 /* Match octal char */ 186 #define OCTAL 37 // Match octal char
187 #define NOCTAL 38 /* Match non-octal char */ 187 #define NOCTAL 38 // Match non-octal char
188 #define WORD 39 /* Match word char */ 188 #define WORD 39 // Match word char
189 #define NWORD 40 /* Match non-word char */ 189 #define NWORD 40 // Match non-word char
190 #define HEAD 41 /* Match head char */ 190 #define HEAD 41 // Match head char
191 #define NHEAD 42 /* Match non-head char */ 191 #define NHEAD 42 // Match non-head char
192 #define ALPHA 43 /* Match alpha char */ 192 #define ALPHA 43 // Match alpha char
193 #define NALPHA 44 /* Match non-alpha char */ 193 #define NALPHA 44 // Match non-alpha char
194 #define LOWER 45 /* Match lowercase char */ 194 #define LOWER 45 // Match lowercase char
195 #define NLOWER 46 /* Match non-lowercase char */ 195 #define NLOWER 46 // Match non-lowercase char
196 #define UPPER 47 /* Match uppercase char */ 196 #define UPPER 47 // Match uppercase char
197 #define NUPPER 48 /* Match non-uppercase char */ 197 #define NUPPER 48 // Match non-uppercase char
198 #define LAST_NL NUPPER + ADD_NL 198 #define LAST_NL NUPPER + ADD_NL
199 #define WITH_NL(op) ((op) >= FIRST_NL && (op) <= LAST_NL) 199 #define WITH_NL(op) ((op) >= FIRST_NL && (op) <= LAST_NL)
200 200
201 #define MOPEN 80 /* -89 Mark this point in input as start of 201 #define MOPEN 80 // -89 Mark this point in input as start of
202 * \( subexpr. MOPEN + 0 marks start of 202 // \( subexpr. MOPEN + 0 marks start of
203 * match. */ 203 // match.
204 #define MCLOSE 90 /* -99 Analogous to MOPEN. MCLOSE + 0 marks 204 #define MCLOSE 90 // -99 Analogous to MOPEN. MCLOSE + 0 marks
205 * end of match. */ 205 // end of match.
206 #define BACKREF 100 /* -109 node Match same string again \1-\9 */ 206 #define BACKREF 100 // -109 node Match same string again \1-\9
207 207
208 #ifdef FEAT_SYN_HL 208 #ifdef FEAT_SYN_HL
209 # define ZOPEN 110 /* -119 Mark this point in input as start of 209 # define ZOPEN 110 // -119 Mark this point in input as start of
210 * \z( subexpr. */ 210 // \z( subexpr.
211 # define ZCLOSE 120 /* -129 Analogous to ZOPEN. */ 211 # define ZCLOSE 120 // -129 Analogous to ZOPEN.
212 # define ZREF 130 /* -139 node Match external submatch \z1-\z9 */ 212 # define ZREF 130 // -139 node Match external submatch \z1-\z9
213 #endif 213 #endif
214 214
215 #define BRACE_COMPLEX 140 /* -149 node Match nodes between m & n times */ 215 #define BRACE_COMPLEX 140 // -149 node Match nodes between m & n times
216 216
217 #define NOPEN 150 /* Mark this point in input as start of 217 #define NOPEN 150 // Mark this point in input as start of
218 \%( subexpr. */ 218 // \%( subexpr.
219 #define NCLOSE 151 /* Analogous to NOPEN. */ 219 #define NCLOSE 151 // Analogous to NOPEN.
220 220
221 #define MULTIBYTECODE 200 /* mbc Match one multi-byte character */ 221 #define MULTIBYTECODE 200 // mbc Match one multi-byte character
222 #define RE_BOF 201 /* Match "" at beginning of file. */ 222 #define RE_BOF 201 // Match "" at beginning of file.
223 #define RE_EOF 202 /* Match "" at end of file. */ 223 #define RE_EOF 202 // Match "" at end of file.
224 #define CURSOR 203 /* Match location of cursor. */ 224 #define CURSOR 203 // Match location of cursor.
225 225
226 #define RE_LNUM 204 /* nr cmp Match line number */ 226 #define RE_LNUM 204 // nr cmp Match line number
227 #define RE_COL 205 /* nr cmp Match column number */ 227 #define RE_COL 205 // nr cmp Match column number
228 #define RE_VCOL 206 /* nr cmp Match virtual column number */ 228 #define RE_VCOL 206 // nr cmp Match virtual column number
229 229
230 #define RE_MARK 207 /* mark cmp Match mark position */ 230 #define RE_MARK 207 // mark cmp Match mark position
231 #define RE_VISUAL 208 /* Match Visual area */ 231 #define RE_VISUAL 208 // Match Visual area
232 #define RE_COMPOSING 209 /* any composing characters */ 232 #define RE_COMPOSING 209 // any composing characters
233 233
234 /* 234 /*
235 * Flags to be passed up and down. 235 * Flags to be passed up and down.
236 */ 236 */
237 #define HASWIDTH 0x1 /* Known never to match null string. */ 237 #define HASWIDTH 0x1 // Known never to match null string.
238 #define SIMPLE 0x2 /* Simple enough to be STAR/PLUS operand. */ 238 #define SIMPLE 0x2 // Simple enough to be STAR/PLUS operand.
239 #define SPSTART 0x4 /* Starts with * or +. */ 239 #define SPSTART 0x4 // Starts with * or +.
240 #define HASNL 0x8 /* Contains some \n. */ 240 #define HASNL 0x8 // Contains some \n.
241 #define HASLOOKBH 0x10 /* Contains "\@<=" or "\@<!". */ 241 #define HASLOOKBH 0x10 // Contains "\@<=" or "\@<!".
242 #define WORST 0 /* Worst case. */ 242 #define WORST 0 // Worst case.
243 243
244 static int num_complex_braces; /* Complex \{...} count */ 244 static int num_complex_braces; // Complex \{...} count
245 static char_u *regcode; /* Code-emit pointer, or JUST_CALC_SIZE */ 245 static char_u *regcode; // Code-emit pointer, or JUST_CALC_SIZE
246 static long regsize; /* Code size. */ 246 static long regsize; // Code size.
247 static int reg_toolong; /* TRUE when offset out of range */ 247 static int reg_toolong; // TRUE when offset out of range
248 static char_u had_endbrace[NSUBEXP]; /* flags, TRUE if end of () found */ 248 static char_u had_endbrace[NSUBEXP]; // flags, TRUE if end of () found
249 static long brace_min[10]; /* Minimums for complex brace repeats */ 249 static long brace_min[10]; // Minimums for complex brace repeats
250 static long brace_max[10]; /* Maximums for complex brace repeats */ 250 static long brace_max[10]; // Maximums for complex brace repeats
251 static int brace_count[10]; /* Current counts for complex brace repeats */ 251 static int brace_count[10]; // Current counts for complex brace repeats
252 static int one_exactly = FALSE; /* only do one char for EXACTLY */ 252 static int one_exactly = FALSE; // only do one char for EXACTLY
253 253
254 /* When making changes to classchars also change nfa_classcodes. */ 254 // When making changes to classchars also change nfa_classcodes.
255 static char_u *classchars = (char_u *)".iIkKfFpPsSdDxXoOwWhHaAlLuU"; 255 static char_u *classchars = (char_u *)".iIkKfFpPsSdDxXoOwWhHaAlLuU";
256 static int classcodes[] = { 256 static int classcodes[] = {
257 ANY, IDENT, SIDENT, KWORD, SKWORD, 257 ANY, IDENT, SIDENT, KWORD, SKWORD,
258 FNAME, SFNAME, PRINT, SPRINT, 258 FNAME, SFNAME, PRINT, SPRINT,
259 WHITE, NWHITE, DIGIT, NDIGIT, 259 WHITE, NWHITE, DIGIT, NDIGIT,
267 * When regcode is set to this value, code is not emitted and size is computed 267 * When regcode is set to this value, code is not emitted and size is computed
268 * instead. 268 * instead.
269 */ 269 */
270 #define JUST_CALC_SIZE ((char_u *) -1) 270 #define JUST_CALC_SIZE ((char_u *) -1)
271 271
272 /* Values for rs_state in regitem_T. */ 272 // Values for rs_state in regitem_T.
273 typedef enum regstate_E 273 typedef enum regstate_E
274 { 274 {
275 RS_NOPEN = 0 /* NOPEN and NCLOSE */ 275 RS_NOPEN = 0 // NOPEN and NCLOSE
276 , RS_MOPEN /* MOPEN + [0-9] */ 276 , RS_MOPEN // MOPEN + [0-9]
277 , RS_MCLOSE /* MCLOSE + [0-9] */ 277 , RS_MCLOSE // MCLOSE + [0-9]
278 #ifdef FEAT_SYN_HL 278 #ifdef FEAT_SYN_HL
279 , RS_ZOPEN /* ZOPEN + [0-9] */ 279 , RS_ZOPEN // ZOPEN + [0-9]
280 , RS_ZCLOSE /* ZCLOSE + [0-9] */ 280 , RS_ZCLOSE // ZCLOSE + [0-9]
281 #endif 281 #endif
282 , RS_BRANCH /* BRANCH */ 282 , RS_BRANCH // BRANCH
283 , RS_BRCPLX_MORE /* BRACE_COMPLEX and trying one more match */ 283 , RS_BRCPLX_MORE // BRACE_COMPLEX and trying one more match
284 , RS_BRCPLX_LONG /* BRACE_COMPLEX and trying longest match */ 284 , RS_BRCPLX_LONG // BRACE_COMPLEX and trying longest match
285 , RS_BRCPLX_SHORT /* BRACE_COMPLEX and trying shortest match */ 285 , RS_BRCPLX_SHORT // BRACE_COMPLEX and trying shortest match
286 , RS_NOMATCH /* NOMATCH */ 286 , RS_NOMATCH // NOMATCH
287 , RS_BEHIND1 /* BEHIND / NOBEHIND matching rest */ 287 , RS_BEHIND1 // BEHIND / NOBEHIND matching rest
288 , RS_BEHIND2 /* BEHIND / NOBEHIND matching behind part */ 288 , RS_BEHIND2 // BEHIND / NOBEHIND matching behind part
289 , RS_STAR_LONG /* STAR/PLUS/BRACE_SIMPLE longest match */ 289 , RS_STAR_LONG // STAR/PLUS/BRACE_SIMPLE longest match
290 , RS_STAR_SHORT /* STAR/PLUS/BRACE_SIMPLE shortest match */ 290 , RS_STAR_SHORT // STAR/PLUS/BRACE_SIMPLE shortest match
291 } regstate_T; 291 } regstate_T;
292 292
293 /* 293 /*
294 * Structure used to save the current input state, when it needs to be 294 * Structure used to save the current input state, when it needs to be
295 * restored after trying a match. Used by reg_save() and reg_restore(). 295 * restored after trying a match. Used by reg_save() and reg_restore().
297 */ 297 */
298 typedef struct 298 typedef struct
299 { 299 {
300 union 300 union
301 { 301 {
302 char_u *ptr; /* rex.input pointer, for single-line regexp */ 302 char_u *ptr; // rex.input pointer, for single-line regexp
303 lpos_T pos; /* rex.input pos, for multi-line regexp */ 303 lpos_T pos; // rex.input pos, for multi-line regexp
304 } rs_u; 304 } rs_u;
305 int rs_len; 305 int rs_len;
306 } regsave_T; 306 } regsave_T;
307 307
308 /* struct to save start/end pointer/position in for \(\) */ 308 // struct to save start/end pointer/position in for \(\)
309 typedef struct 309 typedef struct
310 { 310 {
311 union 311 union
312 { 312 {
313 char_u *ptr; 313 char_u *ptr;
314 lpos_T pos; 314 lpos_T pos;
315 } se_u; 315 } se_u;
316 } save_se_T; 316 } save_se_T;
317 317
318 /* used for BEHIND and NOBEHIND matching */ 318 // used for BEHIND and NOBEHIND matching
319 typedef struct regbehind_S 319 typedef struct regbehind_S
320 { 320 {
321 regsave_T save_after; 321 regsave_T save_after;
322 regsave_T save_behind; 322 regsave_T save_behind;
323 int save_need_clear_subexpr; 323 int save_need_clear_subexpr;
342 regsave_T regsave; 342 regsave_T regsave;
343 } rs_un; // room for saving rex.input 343 } rs_un; // room for saving rex.input
344 } regitem_T; 344 } regitem_T;
345 345
346 346
347 /* used for STAR, PLUS and BRACE_SIMPLE matching */ 347 // used for STAR, PLUS and BRACE_SIMPLE matching
348 typedef struct regstar_S 348 typedef struct regstar_S
349 { 349 {
350 int nextb; /* next byte */ 350 int nextb; // next byte
351 int nextb_ic; /* next byte reverse case */ 351 int nextb_ic; // next byte reverse case
352 long count; 352 long count;
353 long minval; 353 long minval;
354 long maxval; 354 long maxval;
355 } regstar_T; 355 } regstar_T;
356 356
357 /* used to store input position when a BACK was encountered, so that we now if 357 // used to store input position when a BACK was encountered, so that we now if
358 * we made any progress since the last time. */ 358 // we made any progress since the last time.
359 typedef struct backpos_S 359 typedef struct backpos_S
360 { 360 {
361 char_u *bp_scan; /* "scan" where BACK was encountered */ 361 char_u *bp_scan; // "scan" where BACK was encountered
362 regsave_T bp_pos; /* last input position */ 362 regsave_T bp_pos; // last input position
363 } backpos_T; 363 } backpos_T;
364 364
365 /* 365 /*
366 * "regstack" and "backpos" are used by regmatch(). They are kept over calls 366 * "regstack" and "backpos" are used by regmatch(). They are kept over calls
367 * to avoid invoking malloc() and free() often. 367 * to avoid invoking malloc() and free() often.
426 * but allows patterns to get big without disasters. 426 * but allows patterns to get big without disasters.
427 */ 427 */
428 #define OP(p) ((int)*(p)) 428 #define OP(p) ((int)*(p))
429 #define NEXT(p) (((*((p) + 1) & 0377) << 8) + (*((p) + 2) & 0377)) 429 #define NEXT(p) (((*((p) + 1) & 0377) << 8) + (*((p) + 2) & 0377))
430 #define OPERAND(p) ((p) + 3) 430 #define OPERAND(p) ((p) + 3)
431 /* Obtain an operand that was stored as four bytes, MSB first. */ 431 // Obtain an operand that was stored as four bytes, MSB first.
432 #define OPERAND_MIN(p) (((long)(p)[3] << 24) + ((long)(p)[4] << 16) \ 432 #define OPERAND_MIN(p) (((long)(p)[3] << 24) + ((long)(p)[4] << 16) \
433 + ((long)(p)[5] << 8) + (long)(p)[6]) 433 + ((long)(p)[5] << 8) + (long)(p)[6])
434 /* Obtain a second operand stored as four bytes. */ 434 // Obtain a second operand stored as four bytes.
435 #define OPERAND_MAX(p) OPERAND_MIN((p) + 4) 435 #define OPERAND_MAX(p) OPERAND_MIN((p) + 4)
436 /* Obtain a second single-byte operand stored after a four bytes operand. */ 436 // Obtain a second single-byte operand stored after a four bytes operand.
437 #define OPERAND_CMP(p) (p)[7] 437 #define OPERAND_CMP(p) (p)[7]
438 438
439 static char_u *reg(int paren, int *flagp); 439 static char_u *reg(int paren, int *flagp);
440 440
441 #ifdef BT_REGEXP_DUMP 441 #ifdef BT_REGEXP_DUMP
455 * Setup to parse the regexp. Used once to get the length and once to do it. 455 * Setup to parse the regexp. Used once to get the length and once to do it.
456 */ 456 */
457 static void 457 static void
458 regcomp_start( 458 regcomp_start(
459 char_u *expr, 459 char_u *expr,
460 int re_flags) /* see vim_regcomp() */ 460 int re_flags) // see vim_regcomp()
461 { 461 {
462 initchr(expr); 462 initchr(expr);
463 if (re_flags & RE_MAGIC) 463 if (re_flags & RE_MAGIC)
464 reg_magic = MAGIC_ON; 464 reg_magic = MAGIC_ON;
465 else 465 else
536 || STRCMP(p_enc, "iso-8859-15") == 0) 536 || STRCMP(p_enc, "iso-8859-15") == 0)
537 { 537 {
538 #ifdef EBCDIC 538 #ifdef EBCDIC
539 int i; 539 int i;
540 540
541 /* This might be slower than switch/case below. */ 541 // This might be slower than switch/case below.
542 for (i = 0; i < 16; i++) 542 for (i = 0; i < 16; i++)
543 { 543 {
544 if (vim_strchr(EQUIVAL_CLASS_C[i], c) != NULL) 544 if (vim_strchr(EQUIVAL_CLASS_C[i], c) != NULL)
545 { 545 {
546 char *p = EQUIVAL_CLASS_C[i]; 546 char *p = EQUIVAL_CLASS_C[i];
551 } 551 }
552 } 552 }
553 #else 553 #else
554 switch (c) 554 switch (c)
555 { 555 {
556 /* Do not use '\300' style, it results in a negative number. */ 556 // Do not use '\300' style, it results in a negative number.
557 case 'A': case 0xc0: case 0xc1: case 0xc2: 557 case 'A': case 0xc0: case 0xc1: case 0xc2:
558 case 0xc3: case 0xc4: case 0xc5: 558 case 0xc3: case 0xc4: case 0xc5:
559 CASEMBC(0x100) CASEMBC(0x102) CASEMBC(0x104) CASEMBC(0x1cd) 559 CASEMBC(0x100) CASEMBC(0x102) CASEMBC(0x104) CASEMBC(0x1cd)
560 CASEMBC(0x1de) CASEMBC(0x1e0) CASEMBC(0x1ea2) 560 CASEMBC(0x1de) CASEMBC(0x1e0) CASEMBC(0x1ea2)
561 regmbc('A'); regmbc(0xc0); regmbc(0xc1); 561 regmbc('A'); regmbc(0xc0); regmbc(0xc1);
864 if (ret == JUST_CALC_SIZE) 864 if (ret == JUST_CALC_SIZE)
865 regsize += 3; 865 regsize += 3;
866 else 866 else
867 { 867 {
868 *regcode++ = op; 868 *regcode++ = op;
869 *regcode++ = NUL; /* Null "next" pointer. */ 869 *regcode++ = NUL; // Null "next" pointer.
870 *regcode++ = NUL; 870 *regcode++ = NUL;
871 } 871 }
872 return ret; 872 return ret;
873 } 873 }
874 874
919 int offset; 919 int offset;
920 920
921 if (p == JUST_CALC_SIZE) 921 if (p == JUST_CALC_SIZE)
922 return; 922 return;
923 923
924 /* Find last node. */ 924 // Find last node.
925 scan = p; 925 scan = p;
926 for (;;) 926 for (;;)
927 { 927 {
928 temp = regnext(scan); 928 temp = regnext(scan);
929 if (temp == NULL) 929 if (temp == NULL)
933 933
934 if (OP(scan) == BACK) 934 if (OP(scan) == BACK)
935 offset = (int)(scan - val); 935 offset = (int)(scan - val);
936 else 936 else
937 offset = (int)(val - scan); 937 offset = (int)(val - scan);
938 /* When the offset uses more than 16 bits it can no longer fit in the two 938 // When the offset uses more than 16 bits it can no longer fit in the two
939 * bytes available. Use a global flag to avoid having to check return 939 // bytes available. Use a global flag to avoid having to check return
940 * values in too many places. */ 940 // values in too many places.
941 if (offset > 0xffff) 941 if (offset > 0xffff)
942 reg_toolong = TRUE; 942 reg_toolong = TRUE;
943 else 943 else
944 { 944 {
945 *(scan + 1) = (char_u) (((unsigned)offset >> 8) & 0377); 945 *(scan + 1) = (char_u) (((unsigned)offset >> 8) & 0377);
951 * Like regtail, on item after a BRANCH; nop if none. 951 * Like regtail, on item after a BRANCH; nop if none.
952 */ 952 */
953 static void 953 static void
954 regoptail(char_u *p, char_u *val) 954 regoptail(char_u *p, char_u *val)
955 { 955 {
956 /* When op is neither BRANCH nor BRACE_COMPLEX0-9, it is "operandless" */ 956 // When op is neither BRANCH nor BRACE_COMPLEX0-9, it is "operandless"
957 if (p == NULL || p == JUST_CALC_SIZE 957 if (p == NULL || p == JUST_CALC_SIZE
958 || (OP(p) != BRANCH 958 || (OP(p) != BRANCH
959 && (OP(p) < BRACE_COMPLEX || OP(p) > BRACE_COMPLEX + 9))) 959 && (OP(p) < BRACE_COMPLEX || OP(p) > BRACE_COMPLEX + 9)))
960 return; 960 return;
961 regtail(OPERAND(p), val); 961 regtail(OPERAND(p), val);
982 regcode += 3; 982 regcode += 3;
983 dst = regcode; 983 dst = regcode;
984 while (src > opnd) 984 while (src > opnd)
985 *--dst = *--src; 985 *--dst = *--src;
986 986
987 place = opnd; /* Op node, where operand used to be. */ 987 place = opnd; // Op node, where operand used to be.
988 *place++ = op; 988 *place++ = op;
989 *place++ = NUL; 989 *place++ = NUL;
990 *place = NUL; 990 *place = NUL;
991 } 991 }
992 992
1010 regcode += 7; 1010 regcode += 7;
1011 dst = regcode; 1011 dst = regcode;
1012 while (src > opnd) 1012 while (src > opnd)
1013 *--dst = *--src; 1013 *--dst = *--src;
1014 1014
1015 place = opnd; /* Op node, where operand used to be. */ 1015 place = opnd; // Op node, where operand used to be.
1016 *place++ = op; 1016 *place++ = op;
1017 *place++ = NUL; 1017 *place++ = NUL;
1018 *place++ = NUL; 1018 *place++ = NUL;
1019 re_put_long(place, (long_u)val); 1019 re_put_long(place, (long_u)val);
1020 } 1020 }
1045 regcode += 11; 1045 regcode += 11;
1046 dst = regcode; 1046 dst = regcode;
1047 while (src > opnd) 1047 while (src > opnd)
1048 *--dst = *--src; 1048 *--dst = *--src;
1049 1049
1050 place = opnd; /* Op node, where operand used to be. */ 1050 place = opnd; // Op node, where operand used to be.
1051 *place++ = op; 1051 *place++ = op;
1052 *place++ = NUL; 1052 *place++ = NUL;
1053 *place++ = NUL; 1053 *place++ = NUL;
1054 place = re_put_long(place, (long_u)minval); 1054 place = re_put_long(place, (long_u)minval);
1055 place = re_put_long(place, (long_u)maxval); 1055 place = re_put_long(place, (long_u)maxval);
1067 { 1067 {
1068 if (!had_endbrace[refnum]) 1068 if (!had_endbrace[refnum])
1069 { 1069 {
1070 char_u *p; 1070 char_u *p;
1071 1071
1072 /* Trick: check if "@<=" or "@<!" follows, in which case 1072 // Trick: check if "@<=" or "@<!" follows, in which case
1073 * the \1 can appear before the referenced match. */ 1073 // the \1 can appear before the referenced match.
1074 for (p = regparse; *p != NUL; ++p) 1074 for (p = regparse; *p != NUL; ++p)
1075 if (p[0] == '@' && p[1] == '<' && (p[2] == '!' || p[2] == '=')) 1075 if (p[0] == '@' && p[1] == '<' && (p[2] == '!' || p[2] == '='))
1076 break; 1076 break;
1077 if (*p == NUL) 1077 if (*p == NUL)
1078 { 1078 {
1099 int c; 1099 int c;
1100 char_u *p; 1100 char_u *p;
1101 int extra = 0; 1101 int extra = 0;
1102 int save_prev_at_start = prev_at_start; 1102 int save_prev_at_start = prev_at_start;
1103 1103
1104 *flagp = WORST; /* Tentatively. */ 1104 *flagp = WORST; // Tentatively.
1105 1105
1106 c = getchr(); 1106 c = getchr();
1107 switch (c) 1107 switch (c)
1108 { 1108 {
1109 case Magic('^'): 1109 case Magic('^'):
1125 ret = regnode(EOW); 1125 ret = regnode(EOW);
1126 break; 1126 break;
1127 1127
1128 case Magic('_'): 1128 case Magic('_'):
1129 c = no_Magic(getchr()); 1129 c = no_Magic(getchr());
1130 if (c == '^') /* "\_^" is start-of-line */ 1130 if (c == '^') // "\_^" is start-of-line
1131 { 1131 {
1132 ret = regnode(BOL); 1132 ret = regnode(BOL);
1133 break; 1133 break;
1134 } 1134 }
1135 if (c == '$') /* "\_$" is end-of-line */ 1135 if (c == '$') // "\_$" is end-of-line
1136 { 1136 {
1137 ret = regnode(EOL); 1137 ret = regnode(EOL);
1138 #if defined(FEAT_SYN_HL) || defined(PROTO) 1138 #if defined(FEAT_SYN_HL) || defined(PROTO)
1139 had_eol = TRUE; 1139 had_eol = TRUE;
1140 #endif 1140 #endif
1142 } 1142 }
1143 1143
1144 extra = ADD_NL; 1144 extra = ADD_NL;
1145 *flagp |= HASNL; 1145 *flagp |= HASNL;
1146 1146
1147 /* "\_[" is character range plus newline */ 1147 // "\_[" is character range plus newline
1148 if (c == '[') 1148 if (c == '[')
1149 goto collection; 1149 goto collection;
1150 1150
1151 /* "\_x" is character class plus newline */ 1151 // "\_x" is character class plus newline
1152 /* FALLTHROUGH */ 1152 // FALLTHROUGH
1153 1153
1154 /* 1154 // Character classes.
1155 * Character classes.
1156 */
1157 case Magic('.'): 1155 case Magic('.'):
1158 case Magic('i'): 1156 case Magic('i'):
1159 case Magic('I'): 1157 case Magic('I'):
1160 case Magic('k'): 1158 case Magic('k'):
1161 case Magic('K'): 1159 case Magic('K'):
1183 case Magic('U'): 1181 case Magic('U'):
1184 p = vim_strchr(classchars, no_Magic(c)); 1182 p = vim_strchr(classchars, no_Magic(c));
1185 if (p == NULL) 1183 if (p == NULL)
1186 EMSG_RET_NULL(_("E63: invalid use of \\_")); 1184 EMSG_RET_NULL(_("E63: invalid use of \\_"));
1187 1185
1188 /* When '.' is followed by a composing char ignore the dot, so that 1186 // When '.' is followed by a composing char ignore the dot, so that
1189 * the composing char is matched here. */ 1187 // the composing char is matched here.
1190 if (enc_utf8 && c == Magic('.') && utf_iscomposing(peekchr())) 1188 if (enc_utf8 && c == Magic('.') && utf_iscomposing(peekchr()))
1191 { 1189 {
1192 c = getchr(); 1190 c = getchr();
1193 goto do_multibyte; 1191 goto do_multibyte;
1194 } 1192 }
1197 break; 1195 break;
1198 1196
1199 case Magic('n'): 1197 case Magic('n'):
1200 if (reg_string) 1198 if (reg_string)
1201 { 1199 {
1202 /* In a string "\n" matches a newline character. */ 1200 // In a string "\n" matches a newline character.
1203 ret = regnode(EXACTLY); 1201 ret = regnode(EXACTLY);
1204 regc(NL); 1202 regc(NL);
1205 regc(NUL); 1203 regc(NUL);
1206 *flagp |= HASWIDTH | SIMPLE; 1204 *flagp |= HASWIDTH | SIMPLE;
1207 } 1205 }
1208 else 1206 else
1209 { 1207 {
1210 /* In buffer text "\n" matches the end of a line. */ 1208 // In buffer text "\n" matches the end of a line.
1211 ret = regnode(NEWL); 1209 ret = regnode(NEWL);
1212 *flagp |= HASWIDTH | HASNL; 1210 *flagp |= HASWIDTH | HASNL;
1213 } 1211 }
1214 break; 1212 break;
1215 1213
1226 case Magic('|'): 1224 case Magic('|'):
1227 case Magic('&'): 1225 case Magic('&'):
1228 case Magic(')'): 1226 case Magic(')'):
1229 if (one_exactly) 1227 if (one_exactly)
1230 EMSG_ONE_RET_NULL; 1228 EMSG_ONE_RET_NULL;
1231 IEMSG_RET_NULL(_(e_internal)); /* Supposed to be caught earlier. */ 1229 IEMSG_RET_NULL(_(e_internal)); // Supposed to be caught earlier.
1232 /* NOTREACHED */ 1230 // NOTREACHED
1233 1231
1234 case Magic('='): 1232 case Magic('='):
1235 case Magic('?'): 1233 case Magic('?'):
1236 case Magic('+'): 1234 case Magic('+'):
1237 case Magic('@'): 1235 case Magic('@'):
1238 case Magic('{'): 1236 case Magic('{'):
1239 case Magic('*'): 1237 case Magic('*'):
1240 c = no_Magic(c); 1238 c = no_Magic(c);
1241 EMSG3_RET_NULL(_("E64: %s%c follows nothing"), 1239 EMSG3_RET_NULL(_("E64: %s%c follows nothing"),
1242 (c == '*' ? reg_magic >= MAGIC_ON : reg_magic == MAGIC_ALL), c); 1240 (c == '*' ? reg_magic >= MAGIC_ON : reg_magic == MAGIC_ALL), c);
1243 /* NOTREACHED */ 1241 // NOTREACHED
1244 1242
1245 case Magic('~'): /* previous substitute pattern */ 1243 case Magic('~'): // previous substitute pattern
1246 if (reg_prev_sub != NULL) 1244 if (reg_prev_sub != NULL)
1247 { 1245 {
1248 char_u *lp; 1246 char_u *lp;
1249 1247
1250 ret = regnode(EXACTLY); 1248 ret = regnode(EXACTLY);
1332 case Magic('%'): 1330 case Magic('%'):
1333 { 1331 {
1334 c = no_Magic(getchr()); 1332 c = no_Magic(getchr());
1335 switch (c) 1333 switch (c)
1336 { 1334 {
1337 /* () without a back reference */ 1335 // () without a back reference
1338 case '(': 1336 case '(':
1339 if (one_exactly) 1337 if (one_exactly)
1340 EMSG_ONE_RET_NULL; 1338 EMSG_ONE_RET_NULL;
1341 ret = reg(REG_NPAREN, &flags); 1339 ret = reg(REG_NPAREN, &flags);
1342 if (ret == NULL) 1340 if (ret == NULL)
1343 return NULL; 1341 return NULL;
1344 *flagp |= flags & (HASWIDTH | SPSTART | HASNL | HASLOOKBH); 1342 *flagp |= flags & (HASWIDTH | SPSTART | HASNL | HASLOOKBH);
1345 break; 1343 break;
1346 1344
1347 /* Catch \%^ and \%$ regardless of where they appear in the 1345 // Catch \%^ and \%$ regardless of where they appear in the
1348 * pattern -- regardless of whether or not it makes sense. */ 1346 // pattern -- regardless of whether or not it makes sense.
1349 case '^': 1347 case '^':
1350 ret = regnode(RE_BOF); 1348 ret = regnode(RE_BOF);
1351 break; 1349 break;
1352 1350
1353 case '$': 1351 case '$':
1364 1362
1365 case 'C': 1363 case 'C':
1366 ret = regnode(RE_COMPOSING); 1364 ret = regnode(RE_COMPOSING);
1367 break; 1365 break;
1368 1366
1369 /* \%[abc]: Emit as a list of branches, all ending at the last 1367 // \%[abc]: Emit as a list of branches, all ending at the last
1370 * branch which matches nothing. */ 1368 // branch which matches nothing.
1371 case '[': 1369 case '[':
1372 if (one_exactly) /* doesn't nest */ 1370 if (one_exactly) // doesn't nest
1373 EMSG_ONE_RET_NULL; 1371 EMSG_ONE_RET_NULL;
1374 { 1372 {
1375 char_u *lastbranch; 1373 char_u *lastbranch;
1376 char_u *lastnode = NULL; 1374 char_u *lastnode = NULL;
1377 char_u *br; 1375 char_u *br;
1406 br = regnode(NOTHING); 1404 br = regnode(NOTHING);
1407 if (ret != JUST_CALC_SIZE) 1405 if (ret != JUST_CALC_SIZE)
1408 { 1406 {
1409 regtail(lastnode, br); 1407 regtail(lastnode, br);
1410 regtail(lastbranch, br); 1408 regtail(lastbranch, br);
1411 /* connect all branches to the NOTHING 1409 // connect all branches to the NOTHING
1412 * branch at the end */ 1410 // branch at the end
1413 for (br = ret; br != lastnode; ) 1411 for (br = ret; br != lastnode; )
1414 { 1412 {
1415 if (OP(br) == BRANCH) 1413 if (OP(br) == BRANCH)
1416 { 1414 {
1417 regtail(br, lastbranch); 1415 regtail(br, lastbranch);
1425 } 1423 }
1426 *flagp &= ~(HASWIDTH | SIMPLE); 1424 *flagp &= ~(HASWIDTH | SIMPLE);
1427 break; 1425 break;
1428 } 1426 }
1429 1427
1430 case 'd': /* %d123 decimal */ 1428 case 'd': // %d123 decimal
1431 case 'o': /* %o123 octal */ 1429 case 'o': // %o123 octal
1432 case 'x': /* %xab hex 2 */ 1430 case 'x': // %xab hex 2
1433 case 'u': /* %uabcd hex 4 */ 1431 case 'u': // %uabcd hex 4
1434 case 'U': /* %U1234abcd hex 8 */ 1432 case 'U': // %U1234abcd hex 8
1435 { 1433 {
1436 long i; 1434 long i;
1437 1435
1438 switch (c) 1436 switch (c)
1439 { 1437 {
1477 n = n * 10 + (c - '0'); 1475 n = n * 10 + (c - '0');
1478 c = getchr(); 1476 c = getchr();
1479 } 1477 }
1480 if (c == '\'' && n == 0) 1478 if (c == '\'' && n == 0)
1481 { 1479 {
1482 /* "\%'m", "\%<'m" and "\%>'m": Mark */ 1480 // "\%'m", "\%<'m" and "\%>'m": Mark
1483 c = getchr(); 1481 c = getchr();
1484 ret = regnode(RE_MARK); 1482 ret = regnode(RE_MARK);
1485 if (ret == JUST_CALC_SIZE) 1483 if (ret == JUST_CALC_SIZE)
1486 regsize += 2; 1484 regsize += 2;
1487 else 1485 else
1505 ret = regnode(RE_VCOL); 1503 ret = regnode(RE_VCOL);
1506 if (ret == JUST_CALC_SIZE) 1504 if (ret == JUST_CALC_SIZE)
1507 regsize += 5; 1505 regsize += 5;
1508 else 1506 else
1509 { 1507 {
1510 /* put the number and the optional 1508 // put the number and the optional
1511 * comparator after the opcode */ 1509 // comparator after the opcode
1512 regcode = re_put_long(regcode, n); 1510 regcode = re_put_long(regcode, n);
1513 *regcode++ = cmp; 1511 *regcode++ = cmp;
1514 } 1512 }
1515 break; 1513 break;
1516 } 1514 }
1525 case Magic('['): 1523 case Magic('['):
1526 collection: 1524 collection:
1527 { 1525 {
1528 char_u *lp; 1526 char_u *lp;
1529 1527
1530 /* 1528 // If there is no matching ']', we assume the '[' is a normal
1531 * If there is no matching ']', we assume the '[' is a normal 1529 // character. This makes 'incsearch' and ":help [" work.
1532 * character. This makes 'incsearch' and ":help [" work.
1533 */
1534 lp = skip_anyof(regparse); 1530 lp = skip_anyof(regparse);
1535 if (*lp == ']') /* there is a matching ']' */ 1531 if (*lp == ']') // there is a matching ']'
1536 { 1532 {
1537 int startc = -1; /* > 0 when next '-' is a range */ 1533 int startc = -1; // > 0 when next '-' is a range
1538 int endc; 1534 int endc;
1539 1535
1540 /* 1536 // In a character class, different parsing rules apply.
1541 * In a character class, different parsing rules apply. 1537 // Not even \ is special anymore, nothing is.
1542 * Not even \ is special anymore, nothing is. 1538 if (*regparse == '^') // Complement of range.
1543 */
1544 if (*regparse == '^') /* Complement of range. */
1545 { 1539 {
1546 ret = regnode(ANYBUT + extra); 1540 ret = regnode(ANYBUT + extra);
1547 regparse++; 1541 regparse++;
1548 } 1542 }
1549 else 1543 else
1550 ret = regnode(ANYOF + extra); 1544 ret = regnode(ANYOF + extra);
1551 1545
1552 /* At the start ']' and '-' mean the literal character. */ 1546 // At the start ']' and '-' mean the literal character.
1553 if (*regparse == ']' || *regparse == '-') 1547 if (*regparse == ']' || *regparse == '-')
1554 { 1548 {
1555 startc = *regparse; 1549 startc = *regparse;
1556 regc(*regparse++); 1550 regc(*regparse++);
1557 } 1551 }
1559 while (*regparse != NUL && *regparse != ']') 1553 while (*regparse != NUL && *regparse != ']')
1560 { 1554 {
1561 if (*regparse == '-') 1555 if (*regparse == '-')
1562 { 1556 {
1563 ++regparse; 1557 ++regparse;
1564 /* The '-' is not used for a range at the end and 1558 // The '-' is not used for a range at the end and
1565 * after or before a '\n'. */ 1559 // after or before a '\n'.
1566 if (*regparse == ']' || *regparse == NUL 1560 if (*regparse == ']' || *regparse == NUL
1567 || startc == -1 1561 || startc == -1
1568 || (regparse[0] == '\\' && regparse[1] == 'n')) 1562 || (regparse[0] == '\\' && regparse[1] == 'n'))
1569 { 1563 {
1570 regc('-'); 1564 regc('-');
1571 startc = '-'; /* [--x] is a range */ 1565 startc = '-'; // [--x] is a range
1572 } 1566 }
1573 else 1567 else
1574 { 1568 {
1575 /* Also accept "a-[.z.]" */ 1569 // Also accept "a-[.z.]"
1576 endc = 0; 1570 endc = 0;
1577 if (*regparse == '[') 1571 if (*regparse == '[')
1578 endc = get_coll_element(&regparse); 1572 endc = get_coll_element(&regparse);
1579 if (endc == 0) 1573 if (endc == 0)
1580 { 1574 {
1582 endc = mb_ptr2char_adv(&regparse); 1576 endc = mb_ptr2char_adv(&regparse);
1583 else 1577 else
1584 endc = *regparse++; 1578 endc = *regparse++;
1585 } 1579 }
1586 1580
1587 /* Handle \o40, \x20 and \u20AC style sequences */ 1581 // Handle \o40, \x20 and \u20AC style sequences
1588 if (endc == '\\' && !reg_cpo_lit && !reg_cpo_bsl) 1582 if (endc == '\\' && !reg_cpo_lit && !reg_cpo_bsl)
1589 endc = coll_get_char(); 1583 endc = coll_get_char();
1590 1584
1591 if (startc > endc) 1585 if (startc > endc)
1592 EMSG_RET_NULL(_(e_reverse_range)); 1586 EMSG_RET_NULL(_(e_reverse_range));
1593 if (has_mbyte && ((*mb_char2len)(startc) > 1 1587 if (has_mbyte && ((*mb_char2len)(startc) > 1
1594 || (*mb_char2len)(endc) > 1)) 1588 || (*mb_char2len)(endc) > 1))
1595 { 1589 {
1596 /* Limit to a range of 256 chars. */ 1590 // Limit to a range of 256 chars.
1597 if (endc > startc + 256) 1591 if (endc > startc + 256)
1598 EMSG_RET_NULL(_(e_large_class)); 1592 EMSG_RET_NULL(_(e_large_class));
1599 while (++startc <= endc) 1593 while (++startc <= endc)
1600 regmbc(startc); 1594 regmbc(startc);
1601 } 1595 }
1602 else 1596 else
1603 { 1597 {
1604 #ifdef EBCDIC 1598 #ifdef EBCDIC
1605 int alpha_only = FALSE; 1599 int alpha_only = FALSE;
1606 1600
1607 /* for alphabetical range skip the gaps 1601 // for alphabetical range skip the gaps
1608 * 'i'-'j', 'r'-'s', 'I'-'J' and 'R'-'S'. */ 1602 // 'i'-'j', 'r'-'s', 'I'-'J' and 'R'-'S'.
1609 if (isalpha(startc) && isalpha(endc)) 1603 if (isalpha(startc) && isalpha(endc))
1610 alpha_only = TRUE; 1604 alpha_only = TRUE;
1611 #endif 1605 #endif
1612 while (++startc <= endc) 1606 while (++startc <= endc)
1613 #ifdef EBCDIC 1607 #ifdef EBCDIC
1616 regc(startc); 1610 regc(startc);
1617 } 1611 }
1618 startc = -1; 1612 startc = -1;
1619 } 1613 }
1620 } 1614 }
1621 /* 1615 // Only "\]", "\^", "\]" and "\\" are special in Vi. Vim
1622 * Only "\]", "\^", "\]" and "\\" are special in Vi. Vim 1616 // accepts "\t", "\e", etc., but only when the 'l' flag in
1623 * accepts "\t", "\e", etc., but only when the 'l' flag in 1617 // 'cpoptions' is not included.
1624 * 'cpoptions' is not included. 1618 // Posix doesn't recognize backslash at all.
1625 * Posix doesn't recognize backslash at all.
1626 */
1627 else if (*regparse == '\\' 1619 else if (*regparse == '\\'
1628 && !reg_cpo_bsl 1620 && !reg_cpo_bsl
1629 && (vim_strchr(REGEXP_INRANGE, regparse[1]) != NULL 1621 && (vim_strchr(REGEXP_INRANGE, regparse[1]) != NULL
1630 || (!reg_cpo_lit 1622 || (!reg_cpo_lit
1631 && vim_strchr(REGEXP_ABBR, 1623 && vim_strchr(REGEXP_ABBR,
1632 regparse[1]) != NULL))) 1624 regparse[1]) != NULL)))
1633 { 1625 {
1634 regparse++; 1626 regparse++;
1635 if (*regparse == 'n') 1627 if (*regparse == 'n')
1636 { 1628 {
1637 /* '\n' in range: also match NL */ 1629 // '\n' in range: also match NL
1638 if (ret != JUST_CALC_SIZE) 1630 if (ret != JUST_CALC_SIZE)
1639 { 1631 {
1640 /* Using \n inside [^] does not change what 1632 // Using \n inside [^] does not change what
1641 * matches. "[^\n]" is the same as ".". */ 1633 // matches. "[^\n]" is the same as ".".
1642 if (*ret == ANYOF) 1634 if (*ret == ANYOF)
1643 { 1635 {
1644 *ret = ANYOF + ADD_NL; 1636 *ret = ANYOF + ADD_NL;
1645 *flagp |= HASNL; 1637 *flagp |= HASNL;
1646 } 1638 }
1647 /* else: must have had a \n already */ 1639 // else: must have had a \n already
1648 } 1640 }
1649 regparse++; 1641 regparse++;
1650 startc = -1; 1642 startc = -1;
1651 } 1643 }
1652 else if (*regparse == 'd' 1644 else if (*regparse == 'd'
1672 int c_class; 1664 int c_class;
1673 int cu; 1665 int cu;
1674 1666
1675 c_class = get_char_class(&regparse); 1667 c_class = get_char_class(&regparse);
1676 startc = -1; 1668 startc = -1;
1677 /* Characters assumed to be 8 bits! */ 1669 // Characters assumed to be 8 bits!
1678 switch (c_class) 1670 switch (c_class)
1679 { 1671 {
1680 case CLASS_NONE: 1672 case CLASS_NONE:
1681 c_class = get_equi_class(&regparse); 1673 c_class = get_equi_class(&regparse);
1682 if (c_class != 0) 1674 if (c_class != 0)
1683 { 1675 {
1684 /* produce equivalence class */ 1676 // produce equivalence class
1685 reg_equi_class(c_class); 1677 reg_equi_class(c_class);
1686 } 1678 }
1687 else if ((c_class = 1679 else if ((c_class =
1688 get_coll_element(&regparse)) != 0) 1680 get_coll_element(&regparse)) != 0)
1689 { 1681 {
1690 /* produce a collating element */ 1682 // produce a collating element
1691 regmbc(c_class); 1683 regmbc(c_class);
1692 } 1684 }
1693 else 1685 else
1694 { 1686 {
1695 /* literal '[', allow [[-x] as a range */ 1687 // literal '[', allow [[-x] as a range
1696 startc = *regparse++; 1688 startc = *regparse++;
1697 regc(startc); 1689 regc(startc);
1698 } 1690 }
1699 break; 1691 break;
1700 case CLASS_ALNUM: 1692 case CLASS_ALNUM:
1790 { 1782 {
1791 if (has_mbyte) 1783 if (has_mbyte)
1792 { 1784 {
1793 int len; 1785 int len;
1794 1786
1795 /* produce a multibyte character, including any 1787 // produce a multibyte character, including any
1796 * following composing characters */ 1788 // following composing characters
1797 startc = mb_ptr2char(regparse); 1789 startc = mb_ptr2char(regparse);
1798 len = (*mb_ptr2len)(regparse); 1790 len = (*mb_ptr2len)(regparse);
1799 if (enc_utf8 && utf_char2len(startc) != len) 1791 if (enc_utf8 && utf_char2len(startc) != len)
1800 startc = -1; /* composing chars */ 1792 startc = -1; // composing chars
1801 while (--len >= 0) 1793 while (--len >= 0)
1802 regc(*regparse++); 1794 regc(*regparse++);
1803 } 1795 }
1804 else 1796 else
1805 { 1797 {
1807 regc(startc); 1799 regc(startc);
1808 } 1800 }
1809 } 1801 }
1810 } 1802 }
1811 regc(NUL); 1803 regc(NUL);
1812 prevchr_len = 1; /* last char was the ']' */ 1804 prevchr_len = 1; // last char was the ']'
1813 if (*regparse != ']') 1805 if (*regparse != ']')
1814 EMSG_RET_NULL(_(e_toomsbra)); /* Cannot happen? */ 1806 EMSG_RET_NULL(_(e_toomsbra)); // Cannot happen?
1815 skipchr(); /* let's be friends with the lexer again */ 1807 skipchr(); // let's be friends with the lexer again
1816 *flagp |= HASWIDTH | SIMPLE; 1808 *flagp |= HASWIDTH | SIMPLE;
1817 break; 1809 break;
1818 } 1810 }
1819 else if (reg_strict) 1811 else if (reg_strict)
1820 EMSG2_RET_NULL(_(e_missingbracket), reg_magic > MAGIC_OFF); 1812 EMSG2_RET_NULL(_(e_missingbracket), reg_magic > MAGIC_OFF);
1821 } 1813 }
1822 /* FALLTHROUGH */ 1814 // FALLTHROUGH
1823 1815
1824 default: 1816 default:
1825 { 1817 {
1826 int len; 1818 int len;
1827 1819
1828 /* A multi-byte character is handled as a separate atom if it's 1820 // A multi-byte character is handled as a separate atom if it's
1829 * before a multi and when it's a composing char. */ 1821 // before a multi and when it's a composing char.
1830 if (use_multibytecode(c)) 1822 if (use_multibytecode(c))
1831 { 1823 {
1832 do_multibyte: 1824 do_multibyte:
1833 ret = regnode(MULTIBYTECODE); 1825 ret = regnode(MULTIBYTECODE);
1834 regmbc(c); 1826 regmbc(c);
1836 break; 1828 break;
1837 } 1829 }
1838 1830
1839 ret = regnode(EXACTLY); 1831 ret = regnode(EXACTLY);
1840 1832
1841 /* 1833 // Append characters as long as:
1842 * Append characters as long as: 1834 // - there is no following multi, we then need the character in
1843 * - there is no following multi, we then need the character in 1835 // front of it as a single character operand
1844 * front of it as a single character operand 1836 // - not running into a Magic character
1845 * - not running into a Magic character 1837 // - "one_exactly" is not set
1846 * - "one_exactly" is not set 1838 // But always emit at least one character. Might be a Multi,
1847 * But always emit at least one character. Might be a Multi, 1839 // e.g., a "[" without matching "]".
1848 * e.g., a "[" without matching "]".
1849 */
1850 for (len = 0; c != NUL && (len == 0 1840 for (len = 0; c != NUL && (len == 0
1851 || (re_multi_type(peekchr()) == NOT_MULTI 1841 || (re_multi_type(peekchr()) == NOT_MULTI
1852 && !one_exactly 1842 && !one_exactly
1853 && !is_Magic(c))); ++len) 1843 && !is_Magic(c))); ++len)
1854 { 1844 {
1858 regmbc(c); 1848 regmbc(c);
1859 if (enc_utf8) 1849 if (enc_utf8)
1860 { 1850 {
1861 int l; 1851 int l;
1862 1852
1863 /* Need to get composing character too. */ 1853 // Need to get composing character too.
1864 for (;;) 1854 for (;;)
1865 { 1855 {
1866 l = utf_ptr2len(regparse); 1856 l = utf_ptr2len(regparse);
1867 if (!UTF_COMPOSINGLIKE(regparse, regparse + l)) 1857 if (!UTF_COMPOSINGLIKE(regparse, regparse + l))
1868 break; 1858 break;
1915 if (re_multi_type(op) == NOT_MULTI) 1905 if (re_multi_type(op) == NOT_MULTI)
1916 { 1906 {
1917 *flagp = flags; 1907 *flagp = flags;
1918 return ret; 1908 return ret;
1919 } 1909 }
1920 /* default flags */ 1910 // default flags
1921 *flagp = (WORST | SPSTART | (flags & (HASNL | HASLOOKBH))); 1911 *flagp = (WORST | SPSTART | (flags & (HASNL | HASLOOKBH)));
1922 1912
1923 skipchr(); 1913 skipchr();
1924 switch (op) 1914 switch (op)
1925 { 1915 {
1926 case Magic('*'): 1916 case Magic('*'):
1927 if (flags & SIMPLE) 1917 if (flags & SIMPLE)
1928 reginsert(STAR, ret); 1918 reginsert(STAR, ret);
1929 else 1919 else
1930 { 1920 {
1931 /* Emit x* as (x&|), where & means "self". */ 1921 // Emit x* as (x&|), where & means "self".
1932 reginsert(BRANCH, ret); /* Either x */ 1922 reginsert(BRANCH, ret); // Either x
1933 regoptail(ret, regnode(BACK)); /* and loop */ 1923 regoptail(ret, regnode(BACK)); // and loop
1934 regoptail(ret, ret); /* back */ 1924 regoptail(ret, ret); // back
1935 regtail(ret, regnode(BRANCH)); /* or */ 1925 regtail(ret, regnode(BRANCH)); // or
1936 regtail(ret, regnode(NOTHING)); /* null. */ 1926 regtail(ret, regnode(NOTHING)); // null.
1937 } 1927 }
1938 break; 1928 break;
1939 1929
1940 case Magic('+'): 1930 case Magic('+'):
1941 if (flags & SIMPLE) 1931 if (flags & SIMPLE)
1942 reginsert(PLUS, ret); 1932 reginsert(PLUS, ret);
1943 else 1933 else
1944 { 1934 {
1945 /* Emit x+ as x(&|), where & means "self". */ 1935 // Emit x+ as x(&|), where & means "self".
1946 next = regnode(BRANCH); /* Either */ 1936 next = regnode(BRANCH); // Either
1947 regtail(ret, next); 1937 regtail(ret, next);
1948 regtail(regnode(BACK), ret); /* loop back */ 1938 regtail(regnode(BACK), ret); // loop back
1949 regtail(next, regnode(BRANCH)); /* or */ 1939 regtail(next, regnode(BRANCH)); // or
1950 regtail(ret, regnode(NOTHING)); /* null. */ 1940 regtail(ret, regnode(NOTHING)); // null.
1951 } 1941 }
1952 *flagp = (WORST | HASWIDTH | (flags & (HASNL | HASLOOKBH))); 1942 *flagp = (WORST | HASWIDTH | (flags & (HASNL | HASLOOKBH)));
1953 break; 1943 break;
1954 1944
1955 case Magic('@'): 1945 case Magic('@'):
1958 long nr; 1948 long nr;
1959 1949
1960 nr = getdecchrs(); 1950 nr = getdecchrs();
1961 switch (no_Magic(getchr())) 1951 switch (no_Magic(getchr()))
1962 { 1952 {
1963 case '=': lop = MATCH; break; /* \@= */ 1953 case '=': lop = MATCH; break; // \@=
1964 case '!': lop = NOMATCH; break; /* \@! */ 1954 case '!': lop = NOMATCH; break; // \@!
1965 case '>': lop = SUBPAT; break; /* \@> */ 1955 case '>': lop = SUBPAT; break; // \@>
1966 case '<': switch (no_Magic(getchr())) 1956 case '<': switch (no_Magic(getchr()))
1967 { 1957 {
1968 case '=': lop = BEHIND; break; /* \@<= */ 1958 case '=': lop = BEHIND; break; // \@<=
1969 case '!': lop = NOBEHIND; break; /* \@<! */ 1959 case '!': lop = NOBEHIND; break; // \@<!
1970 } 1960 }
1971 } 1961 }
1972 if (lop == END) 1962 if (lop == END)
1973 EMSG2_RET_NULL(_("E59: invalid character after %s@"), 1963 EMSG2_RET_NULL(_("E59: invalid character after %s@"),
1974 reg_magic == MAGIC_ALL); 1964 reg_magic == MAGIC_ALL);
1975 /* Look behind must match with behind_pos. */ 1965 // Look behind must match with behind_pos.
1976 if (lop == BEHIND || lop == NOBEHIND) 1966 if (lop == BEHIND || lop == NOBEHIND)
1977 { 1967 {
1978 regtail(ret, regnode(BHPOS)); 1968 regtail(ret, regnode(BHPOS));
1979 *flagp |= HASLOOKBH; 1969 *flagp |= HASLOOKBH;
1980 } 1970 }
1981 regtail(ret, regnode(END)); /* operand ends */ 1971 regtail(ret, regnode(END)); // operand ends
1982 if (lop == BEHIND || lop == NOBEHIND) 1972 if (lop == BEHIND || lop == NOBEHIND)
1983 { 1973 {
1984 if (nr < 0) 1974 if (nr < 0)
1985 nr = 0; /* no limit is same as zero limit */ 1975 nr = 0; // no limit is same as zero limit
1986 reginsert_nr(lop, nr, ret); 1976 reginsert_nr(lop, nr, ret);
1987 } 1977 }
1988 else 1978 else
1989 reginsert(lop, ret); 1979 reginsert(lop, ret);
1990 break; 1980 break;
1991 } 1981 }
1992 1982
1993 case Magic('?'): 1983 case Magic('?'):
1994 case Magic('='): 1984 case Magic('='):
1995 /* Emit x= as (x|) */ 1985 // Emit x= as (x|)
1996 reginsert(BRANCH, ret); /* Either x */ 1986 reginsert(BRANCH, ret); // Either x
1997 regtail(ret, regnode(BRANCH)); /* or */ 1987 regtail(ret, regnode(BRANCH)); // or
1998 next = regnode(NOTHING); /* null. */ 1988 next = regnode(NOTHING); // null.
1999 regtail(ret, next); 1989 regtail(ret, next);
2000 regoptail(ret, next); 1990 regoptail(ret, next);
2001 break; 1991 break;
2002 1992
2003 case Magic('{'): 1993 case Magic('{'):
2046 char_u *chain = NULL; 2036 char_u *chain = NULL;
2047 char_u *latest; 2037 char_u *latest;
2048 int flags; 2038 int flags;
2049 int cont = TRUE; 2039 int cont = TRUE;
2050 2040
2051 *flagp = WORST; /* Tentatively. */ 2041 *flagp = WORST; // Tentatively.
2052 2042
2053 while (cont) 2043 while (cont)
2054 { 2044 {
2055 switch (peekchr()) 2045 switch (peekchr())
2056 { 2046 {
2095 default: 2085 default:
2096 latest = regpiece(&flags); 2086 latest = regpiece(&flags);
2097 if (latest == NULL || reg_toolong) 2087 if (latest == NULL || reg_toolong)
2098 return NULL; 2088 return NULL;
2099 *flagp |= flags & (HASWIDTH | HASNL | HASLOOKBH); 2089 *flagp |= flags & (HASWIDTH | HASNL | HASLOOKBH);
2100 if (chain == NULL) /* First piece. */ 2090 if (chain == NULL) // First piece.
2101 *flagp |= flags & SPSTART; 2091 *flagp |= flags & SPSTART;
2102 else 2092 else
2103 regtail(chain, latest); 2093 regtail(chain, latest);
2104 chain = latest; 2094 chain = latest;
2105 if (first == NULL) 2095 if (first == NULL)
2106 first = latest; 2096 first = latest;
2107 break; 2097 break;
2108 } 2098 }
2109 } 2099 }
2110 if (first == NULL) /* Loop ran zero times. */ 2100 if (first == NULL) // Loop ran zero times.
2111 first = regnode(NOTHING); 2101 first = regnode(NOTHING);
2112 return first; 2102 return first;
2113 } 2103 }
2114 2104
2115 /* 2105 /*
2122 char_u *ret; 2112 char_u *ret;
2123 char_u *chain = NULL; 2113 char_u *chain = NULL;
2124 char_u *latest; 2114 char_u *latest;
2125 int flags; 2115 int flags;
2126 2116
2127 *flagp = WORST | HASNL; /* Tentatively. */ 2117 *flagp = WORST | HASNL; // Tentatively.
2128 2118
2129 ret = regnode(BRANCH); 2119 ret = regnode(BRANCH);
2130 for (;;) 2120 for (;;)
2131 { 2121 {
2132 latest = regconcat(&flags); 2122 latest = regconcat(&flags);
2133 if (latest == NULL) 2123 if (latest == NULL)
2134 return NULL; 2124 return NULL;
2135 /* If one of the branches has width, the whole thing has. If one of 2125 // If one of the branches has width, the whole thing has. If one of
2136 * the branches anchors at start-of-line, the whole thing does. 2126 // the branches anchors at start-of-line, the whole thing does.
2137 * If one of the branches uses look-behind, the whole thing does. */ 2127 // If one of the branches uses look-behind, the whole thing does.
2138 *flagp |= flags & (HASWIDTH | SPSTART | HASLOOKBH); 2128 *flagp |= flags & (HASWIDTH | SPSTART | HASLOOKBH);
2139 /* If one of the branches doesn't match a line-break, the whole thing 2129 // If one of the branches doesn't match a line-break, the whole thing
2140 * doesn't. */ 2130 // doesn't.
2141 *flagp &= ~HASNL | (flags & HASNL); 2131 *flagp &= ~HASNL | (flags & HASNL);
2142 if (chain != NULL) 2132 if (chain != NULL)
2143 regtail(chain, latest); 2133 regtail(chain, latest);
2144 if (peekchr() != Magic('&')) 2134 if (peekchr() != Magic('&'))
2145 break; 2135 break;
2146 skipchr(); 2136 skipchr();
2147 regtail(latest, regnode(END)); /* operand ends */ 2137 regtail(latest, regnode(END)); // operand ends
2148 if (reg_toolong) 2138 if (reg_toolong)
2149 break; 2139 break;
2150 reginsert(MATCH, latest); 2140 reginsert(MATCH, latest);
2151 chain = latest; 2141 chain = latest;
2152 } 2142 }
2163 * is a trifle forced, but the need to tie the tails of the branches to what 2153 * is a trifle forced, but the need to tie the tails of the branches to what
2164 * follows makes it hard to avoid. 2154 * follows makes it hard to avoid.
2165 */ 2155 */
2166 static char_u * 2156 static char_u *
2167 reg( 2157 reg(
2168 int paren, /* REG_NOPAREN, REG_PAREN, REG_NPAREN or REG_ZPAREN */ 2158 int paren, // REG_NOPAREN, REG_PAREN, REG_NPAREN or REG_ZPAREN
2169 int *flagp) 2159 int *flagp)
2170 { 2160 {
2171 char_u *ret; 2161 char_u *ret;
2172 char_u *br; 2162 char_u *br;
2173 char_u *ender; 2163 char_u *ender;
2174 int parno = 0; 2164 int parno = 0;
2175 int flags; 2165 int flags;
2176 2166
2177 *flagp = HASWIDTH; /* Tentatively. */ 2167 *flagp = HASWIDTH; // Tentatively.
2178 2168
2179 #ifdef FEAT_SYN_HL 2169 #ifdef FEAT_SYN_HL
2180 if (paren == REG_ZPAREN) 2170 if (paren == REG_ZPAREN)
2181 { 2171 {
2182 /* Make a ZOPEN node. */ 2172 // Make a ZOPEN node.
2183 if (regnzpar >= NSUBEXP) 2173 if (regnzpar >= NSUBEXP)
2184 EMSG_RET_NULL(_("E50: Too many \\z(")); 2174 EMSG_RET_NULL(_("E50: Too many \\z("));
2185 parno = regnzpar; 2175 parno = regnzpar;
2186 regnzpar++; 2176 regnzpar++;
2187 ret = regnode(ZOPEN + parno); 2177 ret = regnode(ZOPEN + parno);
2188 } 2178 }
2189 else 2179 else
2190 #endif 2180 #endif
2191 if (paren == REG_PAREN) 2181 if (paren == REG_PAREN)
2192 { 2182 {
2193 /* Make a MOPEN node. */ 2183 // Make a MOPEN node.
2194 if (regnpar >= NSUBEXP) 2184 if (regnpar >= NSUBEXP)
2195 EMSG2_RET_NULL(_("E51: Too many %s("), reg_magic == MAGIC_ALL); 2185 EMSG2_RET_NULL(_("E51: Too many %s("), reg_magic == MAGIC_ALL);
2196 parno = regnpar; 2186 parno = regnpar;
2197 ++regnpar; 2187 ++regnpar;
2198 ret = regnode(MOPEN + parno); 2188 ret = regnode(MOPEN + parno);
2199 } 2189 }
2200 else if (paren == REG_NPAREN) 2190 else if (paren == REG_NPAREN)
2201 { 2191 {
2202 /* Make a NOPEN node. */ 2192 // Make a NOPEN node.
2203 ret = regnode(NOPEN); 2193 ret = regnode(NOPEN);
2204 } 2194 }
2205 else 2195 else
2206 ret = NULL; 2196 ret = NULL;
2207 2197
2208 /* Pick up the branches, linking them together. */ 2198 // Pick up the branches, linking them together.
2209 br = regbranch(&flags); 2199 br = regbranch(&flags);
2210 if (br == NULL) 2200 if (br == NULL)
2211 return NULL; 2201 return NULL;
2212 if (ret != NULL) 2202 if (ret != NULL)
2213 regtail(ret, br); /* [MZ]OPEN -> first. */ 2203 regtail(ret, br); // [MZ]OPEN -> first.
2214 else 2204 else
2215 ret = br; 2205 ret = br;
2216 /* If one of the branches can be zero-width, the whole thing can. 2206 // If one of the branches can be zero-width, the whole thing can.
2217 * If one of the branches has * at start or matches a line-break, the 2207 // If one of the branches has * at start or matches a line-break, the
2218 * whole thing can. */ 2208 // whole thing can.
2219 if (!(flags & HASWIDTH)) 2209 if (!(flags & HASWIDTH))
2220 *flagp &= ~HASWIDTH; 2210 *flagp &= ~HASWIDTH;
2221 *flagp |= flags & (SPSTART | HASNL | HASLOOKBH); 2211 *flagp |= flags & (SPSTART | HASNL | HASLOOKBH);
2222 while (peekchr() == Magic('|')) 2212 while (peekchr() == Magic('|'))
2223 { 2213 {
2224 skipchr(); 2214 skipchr();
2225 br = regbranch(&flags); 2215 br = regbranch(&flags);
2226 if (br == NULL || reg_toolong) 2216 if (br == NULL || reg_toolong)
2227 return NULL; 2217 return NULL;
2228 regtail(ret, br); /* BRANCH -> BRANCH. */ 2218 regtail(ret, br); // BRANCH -> BRANCH.
2229 if (!(flags & HASWIDTH)) 2219 if (!(flags & HASWIDTH))
2230 *flagp &= ~HASWIDTH; 2220 *flagp &= ~HASWIDTH;
2231 *flagp |= flags & (SPSTART | HASNL | HASLOOKBH); 2221 *flagp |= flags & (SPSTART | HASNL | HASLOOKBH);
2232 } 2222 }
2233 2223
2234 /* Make a closing node, and hook it on the end. */ 2224 // Make a closing node, and hook it on the end.
2235 ender = regnode( 2225 ender = regnode(
2236 #ifdef FEAT_SYN_HL 2226 #ifdef FEAT_SYN_HL
2237 paren == REG_ZPAREN ? ZCLOSE + parno : 2227 paren == REG_ZPAREN ? ZCLOSE + parno :
2238 #endif 2228 #endif
2239 paren == REG_PAREN ? MCLOSE + parno : 2229 paren == REG_PAREN ? MCLOSE + parno :
2240 paren == REG_NPAREN ? NCLOSE : END); 2230 paren == REG_NPAREN ? NCLOSE : END);
2241 regtail(ret, ender); 2231 regtail(ret, ender);
2242 2232
2243 /* Hook the tails of the branches to the closing node. */ 2233 // Hook the tails of the branches to the closing node.
2244 for (br = ret; br != NULL; br = regnext(br)) 2234 for (br = ret; br != NULL; br = regnext(br))
2245 regoptail(br, ender); 2235 regoptail(br, ender);
2246 2236
2247 /* Check for proper termination. */ 2237 // Check for proper termination.
2248 if (paren != REG_NOPAREN && getchr() != Magic(')')) 2238 if (paren != REG_NOPAREN && getchr() != Magic(')'))
2249 { 2239 {
2250 #ifdef FEAT_SYN_HL 2240 #ifdef FEAT_SYN_HL
2251 if (paren == REG_ZPAREN) 2241 if (paren == REG_ZPAREN)
2252 EMSG_RET_NULL(_("E52: Unmatched \\z(")); 2242 EMSG_RET_NULL(_("E52: Unmatched \\z("));
2260 else if (paren == REG_NOPAREN && peekchr() != NUL) 2250 else if (paren == REG_NOPAREN && peekchr() != NUL)
2261 { 2251 {
2262 if (curchr == Magic(')')) 2252 if (curchr == Magic(')'))
2263 EMSG2_RET_NULL(_(e_unmatchedpar), reg_magic == MAGIC_ALL); 2253 EMSG2_RET_NULL(_(e_unmatchedpar), reg_magic == MAGIC_ALL);
2264 else 2254 else
2265 EMSG_RET_NULL(_(e_trailing)); /* "Can't happen". */ 2255 EMSG_RET_NULL(_(e_trailing)); // "Can't happen".
2266 /* NOTREACHED */ 2256 // NOTREACHED
2267 } 2257 }
2268 /* 2258 // Here we set the flag allowing back references to this set of
2269 * Here we set the flag allowing back references to this set of 2259 // parentheses.
2270 * parentheses.
2271 */
2272 if (paren == REG_PAREN) 2260 if (paren == REG_PAREN)
2273 had_endbrace[parno] = TRUE; /* have seen the close paren */ 2261 had_endbrace[parno] = TRUE; // have seen the close paren
2274 return ret; 2262 return ret;
2275 } 2263 }
2276 2264
2277 /* 2265 /*
2278 * bt_regcomp() - compile a regular expression into internal code for the 2266 * bt_regcomp() - compile a regular expression into internal code for the
2440 case 'u': nr = gethexchrs(4); break; 2428 case 'u': nr = gethexchrs(4); break;
2441 case 'U': nr = gethexchrs(8); break; 2429 case 'U': nr = gethexchrs(8); break;
2442 } 2430 }
2443 if (nr < 0 || nr > INT_MAX) 2431 if (nr < 0 || nr > INT_MAX)
2444 { 2432 {
2445 /* If getting the number fails be backwards compatible: the character 2433 // If getting the number fails be backwards compatible: the character
2446 * is a backslash. */ 2434 // is a backslash.
2447 --regparse; 2435 --regparse;
2448 nr = '\\'; 2436 nr = '\\';
2449 } 2437 }
2450 return nr; 2438 return nr;
2451 } 2439 }
2493 { 2481 {
2494 if (REG_MULTI) 2482 if (REG_MULTI)
2495 { 2483 {
2496 if (rex.lnum != save->rs_u.pos.lnum) 2484 if (rex.lnum != save->rs_u.pos.lnum)
2497 { 2485 {
2498 /* only call reg_getline() when the line number changed to save 2486 // only call reg_getline() when the line number changed to save
2499 * a bit of time */ 2487 // a bit of time
2500 rex.lnum = save->rs_u.pos.lnum; 2488 rex.lnum = save->rs_u.pos.lnum;
2501 rex.line = reg_getline(rex.lnum); 2489 rex.line = reg_getline(rex.lnum);
2502 } 2490 }
2503 rex.input = rex.line + save->rs_u.pos.col; 2491 rex.input = rex.line + save->rs_u.pos.col;
2504 } 2492 }
2517 return rex.lnum == save->rs_u.pos.lnum 2505 return rex.lnum == save->rs_u.pos.lnum
2518 && rex.input == rex.line + save->rs_u.pos.col; 2506 && rex.input == rex.line + save->rs_u.pos.col;
2519 return rex.input == save->rs_u.ptr; 2507 return rex.input == save->rs_u.ptr;
2520 } 2508 }
2521 2509
2522 /* Save the sub-expressions before attempting a match. */ 2510 // Save the sub-expressions before attempting a match.
2523 #define save_se(savep, posp, pp) \ 2511 #define save_se(savep, posp, pp) \
2524 REG_MULTI ? save_se_multi((savep), (posp)) : save_se_one((savep), (pp)) 2512 REG_MULTI ? save_se_multi((savep), (posp)) : save_se_one((savep), (pp))
2525 2513
2526 /* After a failed match restore the sub-expressions. */ 2514 // After a failed match restore the sub-expressions.
2527 #define restore_se(savep, posp, pp) { \ 2515 #define restore_se(savep, posp, pp) { \
2528 if (REG_MULTI) \ 2516 if (REG_MULTI) \
2529 *(posp) = (savep)->se_u.pos; \ 2517 *(posp) = (savep)->se_u.pos; \
2530 else \ 2518 else \
2531 *(pp) = (savep)->se_u.ptr; } 2519 *(pp) = (savep)->se_u.ptr; }
2557 * Advances rex.input (and rex.lnum) to just after the matched chars. 2545 * Advances rex.input (and rex.lnum) to just after the matched chars.
2558 */ 2546 */
2559 static int 2547 static int
2560 regrepeat( 2548 regrepeat(
2561 char_u *p, 2549 char_u *p,
2562 long maxcount) /* maximum number of matches allowed */ 2550 long maxcount) // maximum number of matches allowed
2563 { 2551 {
2564 long count = 0; 2552 long count = 0;
2565 char_u *scan; 2553 char_u *scan;
2566 char_u *opnd; 2554 char_u *opnd;
2567 int mask; 2555 int mask;
2568 int testval = 0; 2556 int testval = 0;
2569 2557
2570 scan = rex.input; /* Make local copy of rex.input for speed. */ 2558 scan = rex.input; // Make local copy of rex.input for speed.
2571 opnd = OPERAND(p); 2559 opnd = OPERAND(p);
2572 switch (OP(p)) 2560 switch (OP(p))
2573 { 2561 {
2574 case ANY: 2562 case ANY:
2575 case ANY + ADD_NL: 2563 case ANY + ADD_NL:
2576 while (count < maxcount) 2564 while (count < maxcount)
2577 { 2565 {
2578 /* Matching anything means we continue until end-of-line (or 2566 // Matching anything means we continue until end-of-line (or
2579 * end-of-file for ANY + ADD_NL), only limited by maxcount. */ 2567 // end-of-file for ANY + ADD_NL), only limited by maxcount.
2580 while (*scan != NUL && count < maxcount) 2568 while (*scan != NUL && count < maxcount)
2581 { 2569 {
2582 ++count; 2570 ++count;
2583 MB_PTR_ADV(scan); 2571 MB_PTR_ADV(scan);
2584 } 2572 }
2585 if (!REG_MULTI || !WITH_NL(OP(p)) || rex.lnum > rex.reg_maxline 2573 if (!REG_MULTI || !WITH_NL(OP(p)) || rex.lnum > rex.reg_maxline
2586 || rex.reg_line_lbr || count == maxcount) 2574 || rex.reg_line_lbr || count == maxcount)
2587 break; 2575 break;
2588 ++count; /* count the line-break */ 2576 ++count; // count the line-break
2589 reg_nextline(); 2577 reg_nextline();
2590 scan = rex.input; 2578 scan = rex.input;
2591 if (got_int) 2579 if (got_int)
2592 break; 2580 break;
2593 } 2581 }
2594 break; 2582 break;
2595 2583
2596 case IDENT: 2584 case IDENT:
2597 case IDENT + ADD_NL: 2585 case IDENT + ADD_NL:
2598 testval = TRUE; 2586 testval = TRUE;
2599 /* FALLTHROUGH */ 2587 // FALLTHROUGH
2600 case SIDENT: 2588 case SIDENT:
2601 case SIDENT + ADD_NL: 2589 case SIDENT + ADD_NL:
2602 while (count < maxcount) 2590 while (count < maxcount)
2603 { 2591 {
2604 if (vim_isIDc(PTR2CHAR(scan)) && (testval || !VIM_ISDIGIT(*scan))) 2592 if (vim_isIDc(PTR2CHAR(scan)) && (testval || !VIM_ISDIGIT(*scan)))
2624 break; 2612 break;
2625 2613
2626 case KWORD: 2614 case KWORD:
2627 case KWORD + ADD_NL: 2615 case KWORD + ADD_NL:
2628 testval = TRUE; 2616 testval = TRUE;
2629 /* FALLTHROUGH */ 2617 // FALLTHROUGH
2630 case SKWORD: 2618 case SKWORD:
2631 case SKWORD + ADD_NL: 2619 case SKWORD + ADD_NL:
2632 while (count < maxcount) 2620 while (count < maxcount)
2633 { 2621 {
2634 if (vim_iswordp_buf(scan, rex.reg_buf) 2622 if (vim_iswordp_buf(scan, rex.reg_buf)
2655 break; 2643 break;
2656 2644
2657 case FNAME: 2645 case FNAME:
2658 case FNAME + ADD_NL: 2646 case FNAME + ADD_NL:
2659 testval = TRUE; 2647 testval = TRUE;
2660 /* FALLTHROUGH */ 2648 // FALLTHROUGH
2661 case SFNAME: 2649 case SFNAME:
2662 case SFNAME + ADD_NL: 2650 case SFNAME + ADD_NL:
2663 while (count < maxcount) 2651 while (count < maxcount)
2664 { 2652 {
2665 if (vim_isfilec(PTR2CHAR(scan)) && (testval || !VIM_ISDIGIT(*scan))) 2653 if (vim_isfilec(PTR2CHAR(scan)) && (testval || !VIM_ISDIGIT(*scan)))
2685 break; 2673 break;
2686 2674
2687 case PRINT: 2675 case PRINT:
2688 case PRINT + ADD_NL: 2676 case PRINT + ADD_NL:
2689 testval = TRUE; 2677 testval = TRUE;
2690 /* FALLTHROUGH */ 2678 // FALLTHROUGH
2691 case SPRINT: 2679 case SPRINT:
2692 case SPRINT + ADD_NL: 2680 case SPRINT + ADD_NL:
2693 while (count < maxcount) 2681 while (count < maxcount)
2694 { 2682 {
2695 if (*scan == NUL) 2683 if (*scan == NUL)
2820 2808
2821 case EXACTLY: 2809 case EXACTLY:
2822 { 2810 {
2823 int cu, cl; 2811 int cu, cl;
2824 2812
2825 /* This doesn't do a multi-byte character, because a MULTIBYTECODE 2813 // This doesn't do a multi-byte character, because a MULTIBYTECODE
2826 * would have been used for it. It does handle single-byte 2814 // would have been used for it. It does handle single-byte
2827 * characters, such as latin1. */ 2815 // characters, such as latin1.
2828 if (rex.reg_ic) 2816 if (rex.reg_ic)
2829 { 2817 {
2830 cu = MB_TOUPPER(*opnd); 2818 cu = MB_TOUPPER(*opnd);
2831 cl = MB_TOLOWER(*opnd); 2819 cl = MB_TOLOWER(*opnd);
2832 while (count < maxcount && (*scan == cu || *scan == cl)) 2820 while (count < maxcount && (*scan == cu || *scan == cl))
2849 2837
2850 case MULTIBYTECODE: 2838 case MULTIBYTECODE:
2851 { 2839 {
2852 int i, len, cf = 0; 2840 int i, len, cf = 0;
2853 2841
2854 /* Safety check (just in case 'encoding' was changed since 2842 // Safety check (just in case 'encoding' was changed since
2855 * compiling the program). */ 2843 // compiling the program).
2856 if ((len = (*mb_ptr2len)(opnd)) > 1) 2844 if ((len = (*mb_ptr2len)(opnd)) > 1)
2857 { 2845 {
2858 if (rex.reg_ic && enc_utf8) 2846 if (rex.reg_ic && enc_utf8)
2859 cf = utf_fold(utf_ptr2char(opnd)); 2847 cf = utf_fold(utf_ptr2char(opnd));
2860 while (count < maxcount && (*mb_ptr2len)(scan) >= len) 2848 while (count < maxcount && (*mb_ptr2len)(scan) >= len)
2873 break; 2861 break;
2874 2862
2875 case ANYOF: 2863 case ANYOF:
2876 case ANYOF + ADD_NL: 2864 case ANYOF + ADD_NL:
2877 testval = TRUE; 2865 testval = TRUE;
2878 /* FALLTHROUGH */ 2866 // FALLTHROUGH
2879 2867
2880 case ANYBUT: 2868 case ANYBUT:
2881 case ANYBUT + ADD_NL: 2869 case ANYBUT + ADD_NL:
2882 while (count < maxcount) 2870 while (count < maxcount)
2883 { 2871 {
2926 if (got_int) 2914 if (got_int)
2927 break; 2915 break;
2928 } 2916 }
2929 break; 2917 break;
2930 2918
2931 default: /* Oh dear. Called inappropriately. */ 2919 default: // Oh dear. Called inappropriately.
2932 emsg(_(e_re_corr)); 2920 emsg(_(e_re_corr));
2933 #ifdef DEBUG 2921 #ifdef DEBUG
2934 printf("Called regrepeat with op code %d\n", OP(p)); 2922 printf("Called regrepeat with op code %d\n", OP(p));
2935 #endif 2923 #endif
2936 break; 2924 break;
2987 static void 2975 static void
2988 save_subexpr(regbehind_T *bp) 2976 save_subexpr(regbehind_T *bp)
2989 { 2977 {
2990 int i; 2978 int i;
2991 2979
2992 /* When "rex.need_clear_subexpr" is set we don't need to save the values, only 2980 // When "rex.need_clear_subexpr" is set we don't need to save the values,
2993 * remember that this flag needs to be set again when restoring. */ 2981 // only remember that this flag needs to be set again when restoring.
2994 bp->save_need_clear_subexpr = rex.need_clear_subexpr; 2982 bp->save_need_clear_subexpr = rex.need_clear_subexpr;
2995 if (!rex.need_clear_subexpr) 2983 if (!rex.need_clear_subexpr)
2996 { 2984 {
2997 for (i = 0; i < NSUBEXP; ++i) 2985 for (i = 0; i < NSUBEXP; ++i)
2998 { 2986 {
3016 static void 3004 static void
3017 restore_subexpr(regbehind_T *bp) 3005 restore_subexpr(regbehind_T *bp)
3018 { 3006 {
3019 int i; 3007 int i;
3020 3008
3021 /* Only need to restore saved values when they are not to be cleared. */ 3009 // Only need to restore saved values when they are not to be cleared.
3022 rex.need_clear_subexpr = bp->save_need_clear_subexpr; 3010 rex.need_clear_subexpr = bp->save_need_clear_subexpr;
3023 if (!rex.need_clear_subexpr) 3011 if (!rex.need_clear_subexpr)
3024 { 3012 {
3025 for (i = 0; i < NSUBEXP; ++i) 3013 for (i = 0; i < NSUBEXP; ++i)
3026 { 3014 {
3053 * Returns FALSE when there is no match. Leaves rex.input and rex.lnum in an 3041 * Returns FALSE when there is no match. Leaves rex.input and rex.lnum in an
3054 * undefined state! 3042 * undefined state!
3055 */ 3043 */
3056 static int 3044 static int
3057 regmatch( 3045 regmatch(
3058 char_u *scan, /* Current node. */ 3046 char_u *scan, // Current node.
3059 proftime_T *tm UNUSED, /* timeout limit or NULL */ 3047 proftime_T *tm UNUSED, // timeout limit or NULL
3060 int *timed_out UNUSED) /* flag set on timeout or NULL */ 3048 int *timed_out UNUSED) // flag set on timeout or NULL
3061 { 3049 {
3062 char_u *next; /* Next node. */ 3050 char_u *next; // Next node.
3063 int op; 3051 int op;
3064 int c; 3052 int c;
3065 regitem_T *rp; 3053 regitem_T *rp;
3066 int no; 3054 int no;
3067 int status; /* one of the RA_ values: */ 3055 int status; // one of the RA_ values:
3068 #ifdef FEAT_RELTIME 3056 #ifdef FEAT_RELTIME
3069 int tm_count = 0; 3057 int tm_count = 0;
3070 #endif 3058 #endif
3071 3059
3072 /* Make "regstack" and "backpos" empty. They are allocated and freed in 3060 // Make "regstack" and "backpos" empty. They are allocated and freed in
3073 * bt_regexec_both() to reduce malloc()/free() calls. */ 3061 // bt_regexec_both() to reduce malloc()/free() calls.
3074 regstack.ga_len = 0; 3062 regstack.ga_len = 0;
3075 backpos.ga_len = 0; 3063 backpos.ga_len = 0;
3076 3064
3077 /* 3065 // Repeat until "regstack" is empty.
3078 * Repeat until "regstack" is empty.
3079 */
3080 for (;;) 3066 for (;;)
3081 { 3067 {
3082 /* Some patterns may take a long time to match, e.g., "\([a-z]\+\)\+Q". 3068 // Some patterns may take a long time to match, e.g., "\([a-z]\+\)\+Q".
3083 * Allow interrupting them with CTRL-C. */ 3069 // Allow interrupting them with CTRL-C.
3084 fast_breakcheck(); 3070 fast_breakcheck();
3085 3071
3086 #ifdef DEBUG 3072 #ifdef DEBUG
3087 if (scan != NULL && regnarrate) 3073 if (scan != NULL && regnarrate)
3088 { 3074 {
3089 mch_errmsg((char *)regprop(scan)); 3075 mch_errmsg((char *)regprop(scan));
3090 mch_errmsg("(\n"); 3076 mch_errmsg("(\n");
3091 } 3077 }
3092 #endif 3078 #endif
3093 3079
3094 /* 3080 // Repeat for items that can be matched sequentially, without using the
3095 * Repeat for items that can be matched sequentially, without using the 3081 // regstack.
3096 * regstack.
3097 */
3098 for (;;) 3082 for (;;)
3099 { 3083 {
3100 if (got_int || scan == NULL) 3084 if (got_int || scan == NULL)
3101 { 3085 {
3102 status = RA_FAIL; 3086 status = RA_FAIL;
3103 break; 3087 break;
3104 } 3088 }
3105 #ifdef FEAT_RELTIME 3089 #ifdef FEAT_RELTIME
3106 /* Check for timeout once in a 100 times to avoid overhead. */ 3090 // Check for timeout once in a 100 times to avoid overhead.
3107 if (tm != NULL && ++tm_count == 100) 3091 if (tm != NULL && ++tm_count == 100)
3108 { 3092 {
3109 tm_count = 0; 3093 tm_count = 0;
3110 if (profile_passed_limit(tm)) 3094 if (profile_passed_limit(tm))
3111 { 3095 {
3141 } 3125 }
3142 #endif 3126 #endif
3143 next = regnext(scan); 3127 next = regnext(scan);
3144 3128
3145 op = OP(scan); 3129 op = OP(scan);
3146 /* Check for character class with NL added. */ 3130 // Check for character class with NL added.
3147 if (!rex.reg_line_lbr && WITH_NL(op) && REG_MULTI 3131 if (!rex.reg_line_lbr && WITH_NL(op) && REG_MULTI
3148 && *rex.input == NUL && rex.lnum <= rex.reg_maxline) 3132 && *rex.input == NUL && rex.lnum <= rex.reg_maxline)
3149 { 3133 {
3150 reg_nextline(); 3134 reg_nextline();
3151 } 3135 }
3172 if (c != NUL) 3156 if (c != NUL)
3173 status = RA_NOMATCH; 3157 status = RA_NOMATCH;
3174 break; 3158 break;
3175 3159
3176 case RE_BOF: 3160 case RE_BOF:
3177 /* We're not at the beginning of the file when below the first 3161 // We're not at the beginning of the file when below the first
3178 * line where we started, not at the start of the line or we 3162 // line where we started, not at the start of the line or we
3179 * didn't start at the first line of the buffer. */ 3163 // didn't start at the first line of the buffer.
3180 if (rex.lnum != 0 || rex.input != rex.line 3164 if (rex.lnum != 0 || rex.input != rex.line
3181 || (REG_MULTI && rex.reg_firstlnum > 1)) 3165 || (REG_MULTI && rex.reg_firstlnum > 1))
3182 status = RA_NOMATCH; 3166 status = RA_NOMATCH;
3183 break; 3167 break;
3184 3168
3186 if (rex.lnum != rex.reg_maxline || c != NUL) 3170 if (rex.lnum != rex.reg_maxline || c != NUL)
3187 status = RA_NOMATCH; 3171 status = RA_NOMATCH;
3188 break; 3172 break;
3189 3173
3190 case CURSOR: 3174 case CURSOR:
3191 /* Check if the buffer is in a window and compare the 3175 // Check if the buffer is in a window and compare the
3192 * rex.reg_win->w_cursor position to the match position. */ 3176 // rex.reg_win->w_cursor position to the match position.
3193 if (rex.reg_win == NULL 3177 if (rex.reg_win == NULL
3194 || (rex.lnum + rex.reg_firstlnum 3178 || (rex.lnum + rex.reg_firstlnum
3195 != rex.reg_win->w_cursor.lnum) 3179 != rex.reg_win->w_cursor.lnum)
3196 || ((colnr_T)(rex.input - rex.line) 3180 || ((colnr_T)(rex.input - rex.line)
3197 != rex.reg_win->w_cursor.col)) 3181 != rex.reg_win->w_cursor.col))
3198 status = RA_NOMATCH; 3182 status = RA_NOMATCH;
3199 break; 3183 break;
3200 3184
3201 case RE_MARK: 3185 case RE_MARK:
3202 /* Compare the mark position to the match position. */ 3186 // Compare the mark position to the match position.
3203 { 3187 {
3204 int mark = OPERAND(scan)[0]; 3188 int mark = OPERAND(scan)[0];
3205 int cmp = OPERAND(scan)[1]; 3189 int cmp = OPERAND(scan)[1];
3206 pos_T *pos; 3190 pos_T *pos;
3207 3191
3208 pos = getmark_buf(rex.reg_buf, mark, FALSE); 3192 pos = getmark_buf(rex.reg_buf, mark, FALSE);
3209 if (pos == NULL /* mark doesn't exist */ 3193 if (pos == NULL // mark doesn't exist
3210 || pos->lnum <= 0 /* mark isn't set in reg_buf */ 3194 || pos->lnum <= 0 // mark isn't set in reg_buf
3211 || (pos->lnum == rex.lnum + rex.reg_firstlnum 3195 || (pos->lnum == rex.lnum + rex.reg_firstlnum
3212 ? (pos->col == (colnr_T)(rex.input - rex.line) 3196 ? (pos->col == (colnr_T)(rex.input - rex.line)
3213 ? (cmp == '<' || cmp == '>') 3197 ? (cmp == '<' || cmp == '>')
3214 : (pos->col < (colnr_T)(rex.input - rex.line) 3198 : (pos->col < (colnr_T)(rex.input - rex.line)
3215 ? cmp != '>' 3199 ? cmp != '>'
3242 rex.reg_win == NULL ? curwin : rex.reg_win, 3226 rex.reg_win == NULL ? curwin : rex.reg_win,
3243 rex.line, (colnr_T)(rex.input - rex.line)) + 1, scan)) 3227 rex.line, (colnr_T)(rex.input - rex.line)) + 1, scan))
3244 status = RA_NOMATCH; 3228 status = RA_NOMATCH;
3245 break; 3229 break;
3246 3230
3247 case BOW: /* \<word; rex.input points to w */ 3231 case BOW: // \<word; rex.input points to w
3248 if (c == NUL) /* Can't match at end of line */ 3232 if (c == NUL) // Can't match at end of line
3249 status = RA_NOMATCH; 3233 status = RA_NOMATCH;
3250 else if (has_mbyte) 3234 else if (has_mbyte)
3251 { 3235 {
3252 int this_class; 3236 int this_class;
3253 3237
3254 /* Get class of current and previous char (if it exists). */ 3238 // Get class of current and previous char (if it exists).
3255 this_class = mb_get_class_buf(rex.input, rex.reg_buf); 3239 this_class = mb_get_class_buf(rex.input, rex.reg_buf);
3256 if (this_class <= 1) 3240 if (this_class <= 1)
3257 status = RA_NOMATCH; /* not on a word at all */ 3241 status = RA_NOMATCH; // not on a word at all
3258 else if (reg_prev_class() == this_class) 3242 else if (reg_prev_class() == this_class)
3259 status = RA_NOMATCH; /* previous char is in same word */ 3243 status = RA_NOMATCH; // previous char is in same word
3260 } 3244 }
3261 else 3245 else
3262 { 3246 {
3263 if (!vim_iswordc_buf(c, rex.reg_buf) || (rex.input > rex.line 3247 if (!vim_iswordc_buf(c, rex.reg_buf) || (rex.input > rex.line
3264 && vim_iswordc_buf(rex.input[-1], rex.reg_buf))) 3248 && vim_iswordc_buf(rex.input[-1], rex.reg_buf)))
3265 status = RA_NOMATCH; 3249 status = RA_NOMATCH;
3266 } 3250 }
3267 break; 3251 break;
3268 3252
3269 case EOW: /* word\>; rex.input points after d */ 3253 case EOW: // word\>; rex.input points after d
3270 if (rex.input == rex.line) /* Can't match at start of line */ 3254 if (rex.input == rex.line) // Can't match at start of line
3271 status = RA_NOMATCH; 3255 status = RA_NOMATCH;
3272 else if (has_mbyte) 3256 else if (has_mbyte)
3273 { 3257 {
3274 int this_class, prev_class; 3258 int this_class, prev_class;
3275 3259
3276 /* Get class of current and previous char (if it exists). */ 3260 // Get class of current and previous char (if it exists).
3277 this_class = mb_get_class_buf(rex.input, rex.reg_buf); 3261 this_class = mb_get_class_buf(rex.input, rex.reg_buf);
3278 prev_class = reg_prev_class(); 3262 prev_class = reg_prev_class();
3279 if (this_class == prev_class 3263 if (this_class == prev_class
3280 || prev_class == 0 || prev_class == 1) 3264 || prev_class == 0 || prev_class == 1)
3281 status = RA_NOMATCH; 3265 status = RA_NOMATCH;
3285 if (!vim_iswordc_buf(rex.input[-1], rex.reg_buf) 3269 if (!vim_iswordc_buf(rex.input[-1], rex.reg_buf)
3286 || (rex.input[0] != NUL 3270 || (rex.input[0] != NUL
3287 && vim_iswordc_buf(c, rex.reg_buf))) 3271 && vim_iswordc_buf(c, rex.reg_buf)))
3288 status = RA_NOMATCH; 3272 status = RA_NOMATCH;
3289 } 3273 }
3290 break; /* Matched with EOW */ 3274 break; // Matched with EOW
3291 3275
3292 case ANY: 3276 case ANY:
3293 /* ANY does not match new lines. */ 3277 // ANY does not match new lines.
3294 if (c == NUL) 3278 if (c == NUL)
3295 status = RA_NOMATCH; 3279 status = RA_NOMATCH;
3296 else 3280 else
3297 ADVANCE_REGINPUT(); 3281 ADVANCE_REGINPUT();
3298 break; 3282 break;
3484 { 3468 {
3485 int len; 3469 int len;
3486 char_u *opnd; 3470 char_u *opnd;
3487 3471
3488 opnd = OPERAND(scan); 3472 opnd = OPERAND(scan);
3489 /* Inline the first byte, for speed. */ 3473 // Inline the first byte, for speed.
3490 if (*opnd != *rex.input 3474 if (*opnd != *rex.input
3491 && (!rex.reg_ic 3475 && (!rex.reg_ic
3492 || (!enc_utf8 3476 || (!enc_utf8
3493 && MB_TOLOWER(*opnd) != MB_TOLOWER(*rex.input)))) 3477 && MB_TOLOWER(*opnd) != MB_TOLOWER(*rex.input))))
3494 status = RA_NOMATCH; 3478 status = RA_NOMATCH;
3495 else if (*opnd == NUL) 3479 else if (*opnd == NUL)
3496 { 3480 {
3497 /* match empty string always works; happens when "~" is 3481 // match empty string always works; happens when "~" is
3498 * empty. */ 3482 // empty.
3499 } 3483 }
3500 else 3484 else
3501 { 3485 {
3502 if (opnd[1] == NUL && !(enc_utf8 && rex.reg_ic)) 3486 if (opnd[1] == NUL && !(enc_utf8 && rex.reg_ic))
3503 { 3487 {
3504 len = 1; /* matched a single byte above */ 3488 len = 1; // matched a single byte above
3505 } 3489 }
3506 else 3490 else
3507 { 3491 {
3508 /* Need to match first byte again for multi-byte. */ 3492 // Need to match first byte again for multi-byte.
3509 len = (int)STRLEN(opnd); 3493 len = (int)STRLEN(opnd);
3510 if (cstrncmp(opnd, rex.input, &len) != 0) 3494 if (cstrncmp(opnd, rex.input, &len) != 0)
3511 status = RA_NOMATCH; 3495 status = RA_NOMATCH;
3512 } 3496 }
3513 /* Check for following composing character, unless %C 3497 // Check for following composing character, unless %C
3514 * follows (skips over all composing chars). */ 3498 // follows (skips over all composing chars).
3515 if (status != RA_NOMATCH 3499 if (status != RA_NOMATCH
3516 && enc_utf8 3500 && enc_utf8
3517 && UTF_COMPOSINGLIKE(rex.input, rex.input + len) 3501 && UTF_COMPOSINGLIKE(rex.input, rex.input + len)
3518 && !rex.reg_icombine 3502 && !rex.reg_icombine
3519 && OP(next) != RE_COMPOSING) 3503 && OP(next) != RE_COMPOSING)
3520 { 3504 {
3521 /* raaron: This code makes a composing character get 3505 // raaron: This code makes a composing character get
3522 * ignored, which is the correct behavior (sometimes) 3506 // ignored, which is the correct behavior (sometimes)
3523 * for voweled Hebrew texts. */ 3507 // for voweled Hebrew texts.
3524 status = RA_NOMATCH; 3508 status = RA_NOMATCH;
3525 } 3509 }
3526 if (status != RA_NOMATCH) 3510 if (status != RA_NOMATCH)
3527 rex.input += len; 3511 rex.input += len;
3528 } 3512 }
3545 int i, len; 3529 int i, len;
3546 char_u *opnd; 3530 char_u *opnd;
3547 int opndc = 0, inpc; 3531 int opndc = 0, inpc;
3548 3532
3549 opnd = OPERAND(scan); 3533 opnd = OPERAND(scan);
3550 /* Safety check (just in case 'encoding' was changed since 3534 // Safety check (just in case 'encoding' was changed since
3551 * compiling the program). */ 3535 // compiling the program).
3552 if ((len = (*mb_ptr2len)(opnd)) < 2) 3536 if ((len = (*mb_ptr2len)(opnd)) < 2)
3553 { 3537 {
3554 status = RA_NOMATCH; 3538 status = RA_NOMATCH;
3555 break; 3539 break;
3556 } 3540 }
3557 if (enc_utf8) 3541 if (enc_utf8)
3558 opndc = utf_ptr2char(opnd); 3542 opndc = utf_ptr2char(opnd);
3559 if (enc_utf8 && utf_iscomposing(opndc)) 3543 if (enc_utf8 && utf_iscomposing(opndc))
3560 { 3544 {
3561 /* When only a composing char is given match at any 3545 // When only a composing char is given match at any
3562 * position where that composing char appears. */ 3546 // position where that composing char appears.
3563 status = RA_NOMATCH; 3547 status = RA_NOMATCH;
3564 for (i = 0; rex.input[i] != NUL; 3548 for (i = 0; rex.input[i] != NUL;
3565 i += utf_ptr2len(rex.input + i)) 3549 i += utf_ptr2len(rex.input + i))
3566 { 3550 {
3567 inpc = utf_ptr2char(rex.input + i); 3551 inpc = utf_ptr2char(rex.input + i);
3570 if (i > 0) 3554 if (i > 0)
3571 break; 3555 break;
3572 } 3556 }
3573 else if (opndc == inpc) 3557 else if (opndc == inpc)
3574 { 3558 {
3575 /* Include all following composing chars. */ 3559 // Include all following composing chars.
3576 len = i + utfc_ptr2len(rex.input + i); 3560 len = i + utfc_ptr2len(rex.input + i);
3577 status = RA_MATCH; 3561 status = RA_MATCH;
3578 break; 3562 break;
3579 } 3563 }
3580 } 3564 }
3592 status = RA_NOMATCH; 3576 status = RA_NOMATCH;
3593 break; 3577 break;
3594 case RE_COMPOSING: 3578 case RE_COMPOSING:
3595 if (enc_utf8) 3579 if (enc_utf8)
3596 { 3580 {
3597 /* Skip composing characters. */ 3581 // Skip composing characters.
3598 while (utf_iscomposing(utf_ptr2char(rex.input))) 3582 while (utf_iscomposing(utf_ptr2char(rex.input)))
3599 MB_CPTR_ADV(rex.input); 3583 MB_CPTR_ADV(rex.input);
3600 } 3584 }
3601 break; 3585 break;
3602 3586
3606 case BACK: 3590 case BACK:
3607 { 3591 {
3608 int i; 3592 int i;
3609 backpos_T *bp; 3593 backpos_T *bp;
3610 3594
3611 /* 3595 // When we run into BACK we need to check if we don't keep
3612 * When we run into BACK we need to check if we don't keep 3596 // looping without matching any input. The second and later
3613 * looping without matching any input. The second and later 3597 // times a BACK is encountered it fails if the input is still
3614 * times a BACK is encountered it fails if the input is still 3598 // at the same position as the previous time.
3615 * at the same position as the previous time. 3599 // The positions are stored in "backpos" and found by the
3616 * The positions are stored in "backpos" and found by the 3600 // current value of "scan", the position in the RE program.
3617 * current value of "scan", the position in the RE program.
3618 */
3619 bp = (backpos_T *)backpos.ga_data; 3601 bp = (backpos_T *)backpos.ga_data;
3620 for (i = 0; i < backpos.ga_len; ++i) 3602 for (i = 0; i < backpos.ga_len; ++i)
3621 if (bp[i].bp_scan == scan) 3603 if (bp[i].bp_scan == scan)
3622 break; 3604 break;
3623 if (i == backpos.ga_len) 3605 if (i == backpos.ga_len)
3624 { 3606 {
3625 /* First time at this BACK, make room to store the pos. */ 3607 // First time at this BACK, make room to store the pos.
3626 if (ga_grow(&backpos, 1) == FAIL) 3608 if (ga_grow(&backpos, 1) == FAIL)
3627 status = RA_FAIL; 3609 status = RA_FAIL;
3628 else 3610 else
3629 { 3611 {
3630 /* get "ga_data" again, it may have changed */ 3612 // get "ga_data" again, it may have changed
3631 bp = (backpos_T *)backpos.ga_data; 3613 bp = (backpos_T *)backpos.ga_data;
3632 bp[i].bp_scan = scan; 3614 bp[i].bp_scan = scan;
3633 ++backpos.ga_len; 3615 ++backpos.ga_len;
3634 } 3616 }
3635 } 3617 }
3636 else if (reg_save_equal(&bp[i].bp_pos)) 3618 else if (reg_save_equal(&bp[i].bp_pos))
3637 /* Still at same position as last time, fail. */ 3619 // Still at same position as last time, fail.
3638 status = RA_NOMATCH; 3620 status = RA_NOMATCH;
3639 3621
3640 if (status != RA_FAIL && status != RA_NOMATCH) 3622 if (status != RA_FAIL && status != RA_NOMATCH)
3641 reg_save(&bp[i].bp_pos, &backpos); 3623 reg_save(&bp[i].bp_pos, &backpos);
3642 } 3624 }
3643 break; 3625 break;
3644 3626
3645 case MOPEN + 0: /* Match start: \zs */ 3627 case MOPEN + 0: // Match start: \zs
3646 case MOPEN + 1: /* \( */ 3628 case MOPEN + 1: // \(
3647 case MOPEN + 2: 3629 case MOPEN + 2:
3648 case MOPEN + 3: 3630 case MOPEN + 3:
3649 case MOPEN + 4: 3631 case MOPEN + 4:
3650 case MOPEN + 5: 3632 case MOPEN + 5:
3651 case MOPEN + 6: 3633 case MOPEN + 6:
3661 else 3643 else
3662 { 3644 {
3663 rp->rs_no = no; 3645 rp->rs_no = no;
3664 save_se(&rp->rs_un.sesave, &rex.reg_startpos[no], 3646 save_se(&rp->rs_un.sesave, &rex.reg_startpos[no],
3665 &rex.reg_startp[no]); 3647 &rex.reg_startp[no]);
3666 /* We simply continue and handle the result when done. */ 3648 // We simply continue and handle the result when done.
3667 } 3649 }
3668 } 3650 }
3669 break; 3651 break;
3670 3652
3671 case NOPEN: /* \%( */ 3653 case NOPEN: // \%(
3672 case NCLOSE: /* \) after \%( */ 3654 case NCLOSE: // \) after \%(
3673 if (regstack_push(RS_NOPEN, scan) == NULL) 3655 if (regstack_push(RS_NOPEN, scan) == NULL)
3674 status = RA_FAIL; 3656 status = RA_FAIL;
3675 /* We simply continue and handle the result when done. */ 3657 // We simply continue and handle the result when done.
3676 break; 3658 break;
3677 3659
3678 #ifdef FEAT_SYN_HL 3660 #ifdef FEAT_SYN_HL
3679 case ZOPEN + 1: 3661 case ZOPEN + 1:
3680 case ZOPEN + 2: 3662 case ZOPEN + 2:
3694 else 3676 else
3695 { 3677 {
3696 rp->rs_no = no; 3678 rp->rs_no = no;
3697 save_se(&rp->rs_un.sesave, &reg_startzpos[no], 3679 save_se(&rp->rs_un.sesave, &reg_startzpos[no],
3698 &reg_startzp[no]); 3680 &reg_startzp[no]);
3699 /* We simply continue and handle the result when done. */ 3681 // We simply continue and handle the result when done.
3700 } 3682 }
3701 } 3683 }
3702 break; 3684 break;
3703 #endif 3685 #endif
3704 3686
3705 case MCLOSE + 0: /* Match end: \ze */ 3687 case MCLOSE + 0: // Match end: \ze
3706 case MCLOSE + 1: /* \) */ 3688 case MCLOSE + 1: // \)
3707 case MCLOSE + 2: 3689 case MCLOSE + 2:
3708 case MCLOSE + 3: 3690 case MCLOSE + 3:
3709 case MCLOSE + 4: 3691 case MCLOSE + 4:
3710 case MCLOSE + 5: 3692 case MCLOSE + 5:
3711 case MCLOSE + 6: 3693 case MCLOSE + 6:
3721 else 3703 else
3722 { 3704 {
3723 rp->rs_no = no; 3705 rp->rs_no = no;
3724 save_se(&rp->rs_un.sesave, &rex.reg_endpos[no], 3706 save_se(&rp->rs_un.sesave, &rex.reg_endpos[no],
3725 &rex.reg_endp[no]); 3707 &rex.reg_endp[no]);
3726 /* We simply continue and handle the result when done. */ 3708 // We simply continue and handle the result when done.
3727 } 3709 }
3728 } 3710 }
3729 break; 3711 break;
3730 3712
3731 #ifdef FEAT_SYN_HL 3713 #ifdef FEAT_SYN_HL
3732 case ZCLOSE + 1: /* \) after \z( */ 3714 case ZCLOSE + 1: // \) after \z(
3733 case ZCLOSE + 2: 3715 case ZCLOSE + 2:
3734 case ZCLOSE + 3: 3716 case ZCLOSE + 3:
3735 case ZCLOSE + 4: 3717 case ZCLOSE + 4:
3736 case ZCLOSE + 5: 3718 case ZCLOSE + 5:
3737 case ZCLOSE + 6: 3719 case ZCLOSE + 6:
3747 else 3729 else
3748 { 3730 {
3749 rp->rs_no = no; 3731 rp->rs_no = no;
3750 save_se(&rp->rs_un.sesave, &reg_endzpos[no], 3732 save_se(&rp->rs_un.sesave, &reg_endzpos[no],
3751 &reg_endzp[no]); 3733 &reg_endzp[no]);
3752 /* We simply continue and handle the result when done. */ 3734 // We simply continue and handle the result when done.
3753 } 3735 }
3754 } 3736 }
3755 break; 3737 break;
3756 #endif 3738 #endif
3757 3739
3767 { 3749 {
3768 int len; 3750 int len;
3769 3751
3770 no = op - BACKREF; 3752 no = op - BACKREF;
3771 cleanup_subexpr(); 3753 cleanup_subexpr();
3772 if (!REG_MULTI) /* Single-line regexp */ 3754 if (!REG_MULTI) // Single-line regexp
3773 { 3755 {
3774 if (rex.reg_startp[no] == NULL || rex.reg_endp[no] == NULL) 3756 if (rex.reg_startp[no] == NULL || rex.reg_endp[no] == NULL)
3775 { 3757 {
3776 /* Backref was not set: Match an empty string. */ 3758 // Backref was not set: Match an empty string.
3777 len = 0; 3759 len = 0;
3778 } 3760 }
3779 else 3761 else
3780 { 3762 {
3781 /* Compare current input with back-ref in the same 3763 // Compare current input with back-ref in the same
3782 * line. */ 3764 // line.
3783 len = (int)(rex.reg_endp[no] - rex.reg_startp[no]); 3765 len = (int)(rex.reg_endp[no] - rex.reg_startp[no]);
3784 if (cstrncmp(rex.reg_startp[no], rex.input, &len) != 0) 3766 if (cstrncmp(rex.reg_startp[no], rex.input, &len) != 0)
3785 status = RA_NOMATCH; 3767 status = RA_NOMATCH;
3786 } 3768 }
3787 } 3769 }
3788 else /* Multi-line regexp */ 3770 else // Multi-line regexp
3789 { 3771 {
3790 if (rex.reg_startpos[no].lnum < 0 3772 if (rex.reg_startpos[no].lnum < 0
3791 || rex.reg_endpos[no].lnum < 0) 3773 || rex.reg_endpos[no].lnum < 0)
3792 { 3774 {
3793 /* Backref was not set: Match an empty string. */ 3775 // Backref was not set: Match an empty string.
3794 len = 0; 3776 len = 0;
3795 } 3777 }
3796 else 3778 else
3797 { 3779 {
3798 if (rex.reg_startpos[no].lnum == rex.lnum 3780 if (rex.reg_startpos[no].lnum == rex.lnum
3799 && rex.reg_endpos[no].lnum == rex.lnum) 3781 && rex.reg_endpos[no].lnum == rex.lnum)
3800 { 3782 {
3801 /* Compare back-ref within the current line. */ 3783 // Compare back-ref within the current line.
3802 len = rex.reg_endpos[no].col 3784 len = rex.reg_endpos[no].col
3803 - rex.reg_startpos[no].col; 3785 - rex.reg_startpos[no].col;
3804 if (cstrncmp(rex.line + rex.reg_startpos[no].col, 3786 if (cstrncmp(rex.line + rex.reg_startpos[no].col,
3805 rex.input, &len) != 0) 3787 rex.input, &len) != 0)
3806 status = RA_NOMATCH; 3788 status = RA_NOMATCH;
3807 } 3789 }
3808 else 3790 else
3809 { 3791 {
3810 /* Messy situation: Need to compare between two 3792 // Messy situation: Need to compare between two
3811 * lines. */ 3793 // lines.
3812 int r = match_with_backref( 3794 int r = match_with_backref(
3813 rex.reg_startpos[no].lnum, 3795 rex.reg_startpos[no].lnum,
3814 rex.reg_startpos[no].col, 3796 rex.reg_startpos[no].col,
3815 rex.reg_endpos[no].lnum, 3797 rex.reg_endpos[no].lnum,
3816 rex.reg_endpos[no].col, 3798 rex.reg_endpos[no].col,
3820 status = r; 3802 status = r;
3821 } 3803 }
3822 } 3804 }
3823 } 3805 }
3824 3806
3825 /* Matched the backref, skip over it. */ 3807 // Matched the backref, skip over it.
3826 rex.input += len; 3808 rex.input += len;
3827 } 3809 }
3828 break; 3810 break;
3829 3811
3830 #ifdef FEAT_SYN_HL 3812 #ifdef FEAT_SYN_HL
3852 else 3834 else
3853 rex.input += len; 3835 rex.input += len;
3854 } 3836 }
3855 else 3837 else
3856 { 3838 {
3857 /* Backref was not set: Match an empty string. */ 3839 // Backref was not set: Match an empty string.
3858 } 3840 }
3859 } 3841 }
3860 break; 3842 break;
3861 #endif 3843 #endif
3862 3844
3863 case BRANCH: 3845 case BRANCH:
3864 { 3846 {
3865 if (OP(next) != BRANCH) /* No choice. */ 3847 if (OP(next) != BRANCH) // No choice.
3866 next = OPERAND(scan); /* Avoid recursion. */ 3848 next = OPERAND(scan); // Avoid recursion.
3867 else 3849 else
3868 { 3850 {
3869 rp = regstack_push(RS_BRANCH, scan); 3851 rp = regstack_push(RS_BRANCH, scan);
3870 if (rp == NULL) 3852 if (rp == NULL)
3871 status = RA_FAIL; 3853 status = RA_FAIL;
3872 else 3854 else
3873 status = RA_BREAK; /* rest is below */ 3855 status = RA_BREAK; // rest is below
3874 } 3856 }
3875 } 3857 }
3876 break; 3858 break;
3877 3859
3878 case BRACE_LIMITS: 3860 case BRACE_LIMITS:
3910 case BRACE_COMPLEX + 9: 3892 case BRACE_COMPLEX + 9:
3911 { 3893 {
3912 no = op - BRACE_COMPLEX; 3894 no = op - BRACE_COMPLEX;
3913 ++brace_count[no]; 3895 ++brace_count[no];
3914 3896
3915 /* If not matched enough times yet, try one more */ 3897 // If not matched enough times yet, try one more
3916 if (brace_count[no] <= (brace_min[no] <= brace_max[no] 3898 if (brace_count[no] <= (brace_min[no] <= brace_max[no]
3917 ? brace_min[no] : brace_max[no])) 3899 ? brace_min[no] : brace_max[no]))
3918 { 3900 {
3919 rp = regstack_push(RS_BRCPLX_MORE, scan); 3901 rp = regstack_push(RS_BRCPLX_MORE, scan);
3920 if (rp == NULL) 3902 if (rp == NULL)
3922 else 3904 else
3923 { 3905 {
3924 rp->rs_no = no; 3906 rp->rs_no = no;
3925 reg_save(&rp->rs_un.regsave, &backpos); 3907 reg_save(&rp->rs_un.regsave, &backpos);
3926 next = OPERAND(scan); 3908 next = OPERAND(scan);
3927 /* We continue and handle the result when done. */ 3909 // We continue and handle the result when done.
3928 } 3910 }
3929 break; 3911 break;
3930 } 3912 }
3931 3913
3932 /* If matched enough times, may try matching some more */ 3914 // If matched enough times, may try matching some more
3933 if (brace_min[no] <= brace_max[no]) 3915 if (brace_min[no] <= brace_max[no])
3934 { 3916 {
3935 /* Range is the normal way around, use longest match */ 3917 // Range is the normal way around, use longest match
3936 if (brace_count[no] <= brace_max[no]) 3918 if (brace_count[no] <= brace_max[no])
3937 { 3919 {
3938 rp = regstack_push(RS_BRCPLX_LONG, scan); 3920 rp = regstack_push(RS_BRCPLX_LONG, scan);
3939 if (rp == NULL) 3921 if (rp == NULL)
3940 status = RA_FAIL; 3922 status = RA_FAIL;
3941 else 3923 else
3942 { 3924 {
3943 rp->rs_no = no; 3925 rp->rs_no = no;
3944 reg_save(&rp->rs_un.regsave, &backpos); 3926 reg_save(&rp->rs_un.regsave, &backpos);
3945 next = OPERAND(scan); 3927 next = OPERAND(scan);
3946 /* We continue and handle the result when done. */ 3928 // We continue and handle the result when done.
3947 } 3929 }
3948 } 3930 }
3949 } 3931 }
3950 else 3932 else
3951 { 3933 {
3952 /* Range is backwards, use shortest match first */ 3934 // Range is backwards, use shortest match first
3953 if (brace_count[no] <= brace_min[no]) 3935 if (brace_count[no] <= brace_min[no])
3954 { 3936 {
3955 rp = regstack_push(RS_BRCPLX_SHORT, scan); 3937 rp = regstack_push(RS_BRCPLX_SHORT, scan);
3956 if (rp == NULL) 3938 if (rp == NULL)
3957 status = RA_FAIL; 3939 status = RA_FAIL;
3958 else 3940 else
3959 { 3941 {
3960 reg_save(&rp->rs_un.regsave, &backpos); 3942 reg_save(&rp->rs_un.regsave, &backpos);
3961 /* We continue and handle the result when done. */ 3943 // We continue and handle the result when done.
3962 } 3944 }
3963 } 3945 }
3964 } 3946 }
3965 } 3947 }
3966 break; 3948 break;
3969 case STAR: 3951 case STAR:
3970 case PLUS: 3952 case PLUS:
3971 { 3953 {
3972 regstar_T rst; 3954 regstar_T rst;
3973 3955
3974 /* 3956 // Lookahead to avoid useless match attempts when we know
3975 * Lookahead to avoid useless match attempts when we know 3957 // what character comes next.
3976 * what character comes next.
3977 */
3978 if (OP(next) == EXACTLY) 3958 if (OP(next) == EXACTLY)
3979 { 3959 {
3980 rst.nextb = *OPERAND(next); 3960 rst.nextb = *OPERAND(next);
3981 if (rex.reg_ic) 3961 if (rex.reg_ic)
3982 { 3962 {
4002 { 3982 {
4003 rst.minval = bl_minval; 3983 rst.minval = bl_minval;
4004 rst.maxval = bl_maxval; 3984 rst.maxval = bl_maxval;
4005 } 3985 }
4006 3986
4007 /* 3987 // When maxval > minval, try matching as much as possible, up
4008 * When maxval > minval, try matching as much as possible, up 3988 // to maxval. When maxval < minval, try matching at least the
4009 * to maxval. When maxval < minval, try matching at least the 3989 // minimal number (since the range is backwards, that's also
4010 * minimal number (since the range is backwards, that's also 3990 // maxval!).
4011 * maxval!).
4012 */
4013 rst.count = regrepeat(OPERAND(scan), rst.maxval); 3991 rst.count = regrepeat(OPERAND(scan), rst.maxval);
4014 if (got_int) 3992 if (got_int)
4015 { 3993 {
4016 status = RA_FAIL; 3994 status = RA_FAIL;
4017 break; 3995 break;
4018 } 3996 }
4019 if (rst.minval <= rst.maxval 3997 if (rst.minval <= rst.maxval
4020 ? rst.count >= rst.minval : rst.count >= rst.maxval) 3998 ? rst.count >= rst.minval : rst.count >= rst.maxval)
4021 { 3999 {
4022 /* It could match. Prepare for trying to match what 4000 // It could match. Prepare for trying to match what
4023 * follows. The code is below. Parameters are stored in 4001 // follows. The code is below. Parameters are stored in
4024 * a regstar_T on the regstack. */ 4002 // a regstar_T on the regstack.
4025 if ((long)((unsigned)regstack.ga_len >> 10) >= p_mmp) 4003 if ((long)((unsigned)regstack.ga_len >> 10) >= p_mmp)
4026 { 4004 {
4027 emsg(_(e_maxmempat)); 4005 emsg(_(e_maxmempat));
4028 status = RA_FAIL; 4006 status = RA_FAIL;
4029 } 4007 }
4037 if (rp == NULL) 4015 if (rp == NULL)
4038 status = RA_FAIL; 4016 status = RA_FAIL;
4039 else 4017 else
4040 { 4018 {
4041 *(((regstar_T *)rp) - 1) = rst; 4019 *(((regstar_T *)rp) - 1) = rst;
4042 status = RA_BREAK; /* skip the restore bits */ 4020 status = RA_BREAK; // skip the restore bits
4043 } 4021 }
4044 } 4022 }
4045 } 4023 }
4046 else 4024 else
4047 status = RA_NOMATCH; 4025 status = RA_NOMATCH;
4058 else 4036 else
4059 { 4037 {
4060 rp->rs_no = op; 4038 rp->rs_no = op;
4061 reg_save(&rp->rs_un.regsave, &backpos); 4039 reg_save(&rp->rs_un.regsave, &backpos);
4062 next = OPERAND(scan); 4040 next = OPERAND(scan);
4063 /* We continue and handle the result when done. */ 4041 // We continue and handle the result when done.
4064 } 4042 }
4065 break; 4043 break;
4066 4044
4067 case BEHIND: 4045 case BEHIND:
4068 case NOBEHIND: 4046 case NOBEHIND:
4069 /* Need a bit of room to store extra positions. */ 4047 // Need a bit of room to store extra positions.
4070 if ((long)((unsigned)regstack.ga_len >> 10) >= p_mmp) 4048 if ((long)((unsigned)regstack.ga_len >> 10) >= p_mmp)
4071 { 4049 {
4072 emsg(_(e_maxmempat)); 4050 emsg(_(e_maxmempat));
4073 status = RA_FAIL; 4051 status = RA_FAIL;
4074 } 4052 }
4080 rp = regstack_push(RS_BEHIND1, scan); 4058 rp = regstack_push(RS_BEHIND1, scan);
4081 if (rp == NULL) 4059 if (rp == NULL)
4082 status = RA_FAIL; 4060 status = RA_FAIL;
4083 else 4061 else
4084 { 4062 {
4085 /* Need to save the subexpr to be able to restore them 4063 // Need to save the subexpr to be able to restore them
4086 * when there is a match but we don't use it. */ 4064 // when there is a match but we don't use it.
4087 save_subexpr(((regbehind_T *)rp) - 1); 4065 save_subexpr(((regbehind_T *)rp) - 1);
4088 4066
4089 rp->rs_no = op; 4067 rp->rs_no = op;
4090 reg_save(&rp->rs_un.regsave, &backpos); 4068 reg_save(&rp->rs_un.regsave, &backpos);
4091 /* First try if what follows matches. If it does then we 4069 // First try if what follows matches. If it does then we
4092 * check the behind match by looping. */ 4070 // check the behind match by looping.
4093 } 4071 }
4094 } 4072 }
4095 break; 4073 break;
4096 4074
4097 case BHPOS: 4075 case BHPOS:
4115 else 4093 else
4116 reg_nextline(); 4094 reg_nextline();
4117 break; 4095 break;
4118 4096
4119 case END: 4097 case END:
4120 status = RA_MATCH; /* Success! */ 4098 status = RA_MATCH; // Success!
4121 break; 4099 break;
4122 4100
4123 default: 4101 default:
4124 emsg(_(e_re_corr)); 4102 emsg(_(e_re_corr));
4125 #ifdef DEBUG 4103 #ifdef DEBUG
4128 status = RA_FAIL; 4106 status = RA_FAIL;
4129 break; 4107 break;
4130 } 4108 }
4131 } 4109 }
4132 4110
4133 /* If we can't continue sequentially, break the inner loop. */ 4111 // If we can't continue sequentially, break the inner loop.
4134 if (status != RA_CONT) 4112 if (status != RA_CONT)
4135 break; 4113 break;
4136 4114
4137 /* Continue in inner loop, advance to next item. */ 4115 // Continue in inner loop, advance to next item.
4138 scan = next; 4116 scan = next;
4139 4117
4140 } /* end of inner loop */ 4118 } // end of inner loop
4141 4119
4142 /* 4120 // If there is something on the regstack execute the code for the state.
4143 * If there is something on the regstack execute the code for the state. 4121 // If the state is popped then loop and use the older state.
4144 * If the state is popped then loop and use the older state.
4145 */
4146 while (regstack.ga_len > 0 && status != RA_FAIL) 4122 while (regstack.ga_len > 0 && status != RA_FAIL)
4147 { 4123 {
4148 rp = (regitem_T *)((char *)regstack.ga_data + regstack.ga_len) - 1; 4124 rp = (regitem_T *)((char *)regstack.ga_data + regstack.ga_len) - 1;
4149 switch (rp->rs_state) 4125 switch (rp->rs_state)
4150 { 4126 {
4151 case RS_NOPEN: 4127 case RS_NOPEN:
4152 /* Result is passed on as-is, simply pop the state. */ 4128 // Result is passed on as-is, simply pop the state.
4153 regstack_pop(&scan); 4129 regstack_pop(&scan);
4154 break; 4130 break;
4155 4131
4156 case RS_MOPEN: 4132 case RS_MOPEN:
4157 /* Pop the state. Restore pointers when there is no match. */ 4133 // Pop the state. Restore pointers when there is no match.
4158 if (status == RA_NOMATCH) 4134 if (status == RA_NOMATCH)
4159 restore_se(&rp->rs_un.sesave, &rex.reg_startpos[rp->rs_no], 4135 restore_se(&rp->rs_un.sesave, &rex.reg_startpos[rp->rs_no],
4160 &rex.reg_startp[rp->rs_no]); 4136 &rex.reg_startp[rp->rs_no]);
4161 regstack_pop(&scan); 4137 regstack_pop(&scan);
4162 break; 4138 break;
4163 4139
4164 #ifdef FEAT_SYN_HL 4140 #ifdef FEAT_SYN_HL
4165 case RS_ZOPEN: 4141 case RS_ZOPEN:
4166 /* Pop the state. Restore pointers when there is no match. */ 4142 // Pop the state. Restore pointers when there is no match.
4167 if (status == RA_NOMATCH) 4143 if (status == RA_NOMATCH)
4168 restore_se(&rp->rs_un.sesave, &reg_startzpos[rp->rs_no], 4144 restore_se(&rp->rs_un.sesave, &reg_startzpos[rp->rs_no],
4169 &reg_startzp[rp->rs_no]); 4145 &reg_startzp[rp->rs_no]);
4170 regstack_pop(&scan); 4146 regstack_pop(&scan);
4171 break; 4147 break;
4172 #endif 4148 #endif
4173 4149
4174 case RS_MCLOSE: 4150 case RS_MCLOSE:
4175 /* Pop the state. Restore pointers when there is no match. */ 4151 // Pop the state. Restore pointers when there is no match.
4176 if (status == RA_NOMATCH) 4152 if (status == RA_NOMATCH)
4177 restore_se(&rp->rs_un.sesave, &rex.reg_endpos[rp->rs_no], 4153 restore_se(&rp->rs_un.sesave, &rex.reg_endpos[rp->rs_no],
4178 &rex.reg_endp[rp->rs_no]); 4154 &rex.reg_endp[rp->rs_no]);
4179 regstack_pop(&scan); 4155 regstack_pop(&scan);
4180 break; 4156 break;
4181 4157
4182 #ifdef FEAT_SYN_HL 4158 #ifdef FEAT_SYN_HL
4183 case RS_ZCLOSE: 4159 case RS_ZCLOSE:
4184 /* Pop the state. Restore pointers when there is no match. */ 4160 // Pop the state. Restore pointers when there is no match.
4185 if (status == RA_NOMATCH) 4161 if (status == RA_NOMATCH)
4186 restore_se(&rp->rs_un.sesave, &reg_endzpos[rp->rs_no], 4162 restore_se(&rp->rs_un.sesave, &reg_endzpos[rp->rs_no],
4187 &reg_endzp[rp->rs_no]); 4163 &reg_endzp[rp->rs_no]);
4188 regstack_pop(&scan); 4164 regstack_pop(&scan);
4189 break; 4165 break;
4190 #endif 4166 #endif
4191 4167
4192 case RS_BRANCH: 4168 case RS_BRANCH:
4193 if (status == RA_MATCH) 4169 if (status == RA_MATCH)
4194 /* this branch matched, use it */ 4170 // this branch matched, use it
4195 regstack_pop(&scan); 4171 regstack_pop(&scan);
4196 else 4172 else
4197 { 4173 {
4198 if (status != RA_BREAK) 4174 if (status != RA_BREAK)
4199 { 4175 {
4200 /* After a non-matching branch: try next one. */ 4176 // After a non-matching branch: try next one.
4201 reg_restore(&rp->rs_un.regsave, &backpos); 4177 reg_restore(&rp->rs_un.regsave, &backpos);
4202 scan = rp->rs_scan; 4178 scan = rp->rs_scan;
4203 } 4179 }
4204 if (scan == NULL || OP(scan) != BRANCH) 4180 if (scan == NULL || OP(scan) != BRANCH)
4205 { 4181 {
4206 /* no more branches, didn't find a match */ 4182 // no more branches, didn't find a match
4207 status = RA_NOMATCH; 4183 status = RA_NOMATCH;
4208 regstack_pop(&scan); 4184 regstack_pop(&scan);
4209 } 4185 }
4210 else 4186 else
4211 { 4187 {
4212 /* Prepare to try a branch. */ 4188 // Prepare to try a branch.
4213 rp->rs_scan = regnext(scan); 4189 rp->rs_scan = regnext(scan);
4214 reg_save(&rp->rs_un.regsave, &backpos); 4190 reg_save(&rp->rs_un.regsave, &backpos);
4215 scan = OPERAND(scan); 4191 scan = OPERAND(scan);
4216 } 4192 }
4217 } 4193 }
4218 break; 4194 break;
4219 4195
4220 case RS_BRCPLX_MORE: 4196 case RS_BRCPLX_MORE:
4221 /* Pop the state. Restore pointers when there is no match. */ 4197 // Pop the state. Restore pointers when there is no match.
4222 if (status == RA_NOMATCH) 4198 if (status == RA_NOMATCH)
4223 { 4199 {
4224 reg_restore(&rp->rs_un.regsave, &backpos); 4200 reg_restore(&rp->rs_un.regsave, &backpos);
4225 --brace_count[rp->rs_no]; /* decrement match count */ 4201 --brace_count[rp->rs_no]; // decrement match count
4226 } 4202 }
4227 regstack_pop(&scan); 4203 regstack_pop(&scan);
4228 break; 4204 break;
4229 4205
4230 case RS_BRCPLX_LONG: 4206 case RS_BRCPLX_LONG:
4231 /* Pop the state. Restore pointers when there is no match. */ 4207 // Pop the state. Restore pointers when there is no match.
4232 if (status == RA_NOMATCH) 4208 if (status == RA_NOMATCH)
4233 { 4209 {
4234 /* There was no match, but we did find enough matches. */ 4210 // There was no match, but we did find enough matches.
4235 reg_restore(&rp->rs_un.regsave, &backpos); 4211 reg_restore(&rp->rs_un.regsave, &backpos);
4236 --brace_count[rp->rs_no]; 4212 --brace_count[rp->rs_no];
4237 /* continue with the items after "\{}" */ 4213 // continue with the items after "\{}"
4238 status = RA_CONT; 4214 status = RA_CONT;
4239 } 4215 }
4240 regstack_pop(&scan); 4216 regstack_pop(&scan);
4241 if (status == RA_CONT) 4217 if (status == RA_CONT)
4242 scan = regnext(scan); 4218 scan = regnext(scan);
4243 break; 4219 break;
4244 4220
4245 case RS_BRCPLX_SHORT: 4221 case RS_BRCPLX_SHORT:
4246 /* Pop the state. Restore pointers when there is no match. */ 4222 // Pop the state. Restore pointers when there is no match.
4247 if (status == RA_NOMATCH) 4223 if (status == RA_NOMATCH)
4248 /* There was no match, try to match one more item. */ 4224 // There was no match, try to match one more item.
4249 reg_restore(&rp->rs_un.regsave, &backpos); 4225 reg_restore(&rp->rs_un.regsave, &backpos);
4250 regstack_pop(&scan); 4226 regstack_pop(&scan);
4251 if (status == RA_NOMATCH) 4227 if (status == RA_NOMATCH)
4252 { 4228 {
4253 scan = OPERAND(scan); 4229 scan = OPERAND(scan);
4254 status = RA_CONT; 4230 status = RA_CONT;
4255 } 4231 }
4256 break; 4232 break;
4257 4233
4258 case RS_NOMATCH: 4234 case RS_NOMATCH:
4259 /* Pop the state. If the operand matches for NOMATCH or 4235 // Pop the state. If the operand matches for NOMATCH or
4260 * doesn't match for MATCH/SUBPAT, we fail. Otherwise backup, 4236 // doesn't match for MATCH/SUBPAT, we fail. Otherwise backup,
4261 * except for SUBPAT, and continue with the next item. */ 4237 // except for SUBPAT, and continue with the next item.
4262 if (status == (rp->rs_no == NOMATCH ? RA_MATCH : RA_NOMATCH)) 4238 if (status == (rp->rs_no == NOMATCH ? RA_MATCH : RA_NOMATCH))
4263 status = RA_NOMATCH; 4239 status = RA_NOMATCH;
4264 else 4240 else
4265 { 4241 {
4266 status = RA_CONT; 4242 status = RA_CONT;
4267 if (rp->rs_no != SUBPAT) /* zero-width */ 4243 if (rp->rs_no != SUBPAT) // zero-width
4268 reg_restore(&rp->rs_un.regsave, &backpos); 4244 reg_restore(&rp->rs_un.regsave, &backpos);
4269 } 4245 }
4270 regstack_pop(&scan); 4246 regstack_pop(&scan);
4271 if (status == RA_CONT) 4247 if (status == RA_CONT)
4272 scan = regnext(scan); 4248 scan = regnext(scan);
4278 regstack_pop(&scan); 4254 regstack_pop(&scan);
4279 regstack.ga_len -= sizeof(regbehind_T); 4255 regstack.ga_len -= sizeof(regbehind_T);
4280 } 4256 }
4281 else 4257 else
4282 { 4258 {
4283 /* The stuff after BEHIND/NOBEHIND matches. Now try if 4259 // The stuff after BEHIND/NOBEHIND matches. Now try if
4284 * the behind part does (not) match before the current 4260 // the behind part does (not) match before the current
4285 * position in the input. This must be done at every 4261 // position in the input. This must be done at every
4286 * position in the input and checking if the match ends at 4262 // position in the input and checking if the match ends at
4287 * the current position. */ 4263 // the current position.
4288 4264
4289 /* save the position after the found match for next */ 4265 // save the position after the found match for next
4290 reg_save(&(((regbehind_T *)rp) - 1)->save_after, &backpos); 4266 reg_save(&(((regbehind_T *)rp) - 1)->save_after, &backpos);
4291 4267
4292 /* Start looking for a match with operand at the current 4268 // Start looking for a match with operand at the current
4293 * position. Go back one character until we find the 4269 // position. Go back one character until we find the
4294 * result, hitting the start of the line or the previous 4270 // result, hitting the start of the line or the previous
4295 * line (for multi-line matching). 4271 // line (for multi-line matching).
4296 * Set behind_pos to where the match should end, BHPOS 4272 // Set behind_pos to where the match should end, BHPOS
4297 * will match it. Save the current value. */ 4273 // will match it. Save the current value.
4298 (((regbehind_T *)rp) - 1)->save_behind = behind_pos; 4274 (((regbehind_T *)rp) - 1)->save_behind = behind_pos;
4299 behind_pos = rp->rs_un.regsave; 4275 behind_pos = rp->rs_un.regsave;
4300 4276
4301 rp->rs_state = RS_BEHIND2; 4277 rp->rs_state = RS_BEHIND2;
4302 4278
4304 scan = OPERAND(rp->rs_scan) + 4; 4280 scan = OPERAND(rp->rs_scan) + 4;
4305 } 4281 }
4306 break; 4282 break;
4307 4283
4308 case RS_BEHIND2: 4284 case RS_BEHIND2:
4309 /* 4285 // Looping for BEHIND / NOBEHIND match.
4310 * Looping for BEHIND / NOBEHIND match.
4311 */
4312 if (status == RA_MATCH && reg_save_equal(&behind_pos)) 4286 if (status == RA_MATCH && reg_save_equal(&behind_pos))
4313 { 4287 {
4314 /* found a match that ends where "next" started */ 4288 // found a match that ends where "next" started
4315 behind_pos = (((regbehind_T *)rp) - 1)->save_behind; 4289 behind_pos = (((regbehind_T *)rp) - 1)->save_behind;
4316 if (rp->rs_no == BEHIND) 4290 if (rp->rs_no == BEHIND)
4317 reg_restore(&(((regbehind_T *)rp) - 1)->save_after, 4291 reg_restore(&(((regbehind_T *)rp) - 1)->save_after,
4318 &backpos); 4292 &backpos);
4319 else 4293 else
4320 { 4294 {
4321 /* But we didn't want a match. Need to restore the 4295 // But we didn't want a match. Need to restore the
4322 * subexpr, because what follows matched, so they have 4296 // subexpr, because what follows matched, so they have
4323 * been set. */ 4297 // been set.
4324 status = RA_NOMATCH; 4298 status = RA_NOMATCH;
4325 restore_subexpr(((regbehind_T *)rp) - 1); 4299 restore_subexpr(((regbehind_T *)rp) - 1);
4326 } 4300 }
4327 regstack_pop(&scan); 4301 regstack_pop(&scan);
4328 regstack.ga_len -= sizeof(regbehind_T); 4302 regstack.ga_len -= sizeof(regbehind_T);
4329 } 4303 }
4330 else 4304 else
4331 { 4305 {
4332 long limit; 4306 long limit;
4333 4307
4334 /* No match or a match that doesn't end where we want it: Go 4308 // No match or a match that doesn't end where we want it: Go
4335 * back one character. May go to previous line once. */ 4309 // back one character. May go to previous line once.
4336 no = OK; 4310 no = OK;
4337 limit = OPERAND_MIN(rp->rs_scan); 4311 limit = OPERAND_MIN(rp->rs_scan);
4338 if (REG_MULTI) 4312 if (REG_MULTI)
4339 { 4313 {
4340 if (limit > 0 4314 if (limit > 0
4386 no = FAIL; 4360 no = FAIL;
4387 } 4361 }
4388 } 4362 }
4389 if (no == OK) 4363 if (no == OK)
4390 { 4364 {
4391 /* Advanced, prepare for finding match again. */ 4365 // Advanced, prepare for finding match again.
4392 reg_restore(&rp->rs_un.regsave, &backpos); 4366 reg_restore(&rp->rs_un.regsave, &backpos);
4393 scan = OPERAND(rp->rs_scan) + 4; 4367 scan = OPERAND(rp->rs_scan) + 4;
4394 if (status == RA_MATCH) 4368 if (status == RA_MATCH)
4395 { 4369 {
4396 /* We did match, so subexpr may have been changed, 4370 // We did match, so subexpr may have been changed,
4397 * need to restore them for the next try. */ 4371 // need to restore them for the next try.
4398 status = RA_NOMATCH; 4372 status = RA_NOMATCH;
4399 restore_subexpr(((regbehind_T *)rp) - 1); 4373 restore_subexpr(((regbehind_T *)rp) - 1);
4400 } 4374 }
4401 } 4375 }
4402 else 4376 else
4403 { 4377 {
4404 /* Can't advance. For NOBEHIND that's a match. */ 4378 // Can't advance. For NOBEHIND that's a match.
4405 behind_pos = (((regbehind_T *)rp) - 1)->save_behind; 4379 behind_pos = (((regbehind_T *)rp) - 1)->save_behind;
4406 if (rp->rs_no == NOBEHIND) 4380 if (rp->rs_no == NOBEHIND)
4407 { 4381 {
4408 reg_restore(&(((regbehind_T *)rp) - 1)->save_after, 4382 reg_restore(&(((regbehind_T *)rp) - 1)->save_after,
4409 &backpos); 4383 &backpos);
4410 status = RA_MATCH; 4384 status = RA_MATCH;
4411 } 4385 }
4412 else 4386 else
4413 { 4387 {
4414 /* We do want a proper match. Need to restore the 4388 // We do want a proper match. Need to restore the
4415 * subexpr if we had a match, because they may have 4389 // subexpr if we had a match, because they may have
4416 * been set. */ 4390 // been set.
4417 if (status == RA_MATCH) 4391 if (status == RA_MATCH)
4418 { 4392 {
4419 status = RA_NOMATCH; 4393 status = RA_NOMATCH;
4420 restore_subexpr(((regbehind_T *)rp) - 1); 4394 restore_subexpr(((regbehind_T *)rp) - 1);
4421 } 4395 }
4436 regstack_pop(&scan); 4410 regstack_pop(&scan);
4437 regstack.ga_len -= sizeof(regstar_T); 4411 regstack.ga_len -= sizeof(regstar_T);
4438 break; 4412 break;
4439 } 4413 }
4440 4414
4441 /* Tried once already, restore input pointers. */ 4415 // Tried once already, restore input pointers.
4442 if (status != RA_BREAK) 4416 if (status != RA_BREAK)
4443 reg_restore(&rp->rs_un.regsave, &backpos); 4417 reg_restore(&rp->rs_un.regsave, &backpos);
4444 4418
4445 /* Repeat until we found a position where it could match. */ 4419 // Repeat until we found a position where it could match.
4446 for (;;) 4420 for (;;)
4447 { 4421 {
4448 if (status != RA_BREAK) 4422 if (status != RA_BREAK)
4449 { 4423 {
4450 /* Tried first position already, advance. */ 4424 // Tried first position already, advance.
4451 if (rp->rs_state == RS_STAR_LONG) 4425 if (rp->rs_state == RS_STAR_LONG)
4452 { 4426 {
4453 /* Trying for longest match, but couldn't or 4427 // Trying for longest match, but couldn't or
4454 * didn't match -- back up one char. */ 4428 // didn't match -- back up one char.
4455 if (--rst->count < rst->minval) 4429 if (--rst->count < rst->minval)
4456 break; 4430 break;
4457 if (rex.input == rex.line) 4431 if (rex.input == rex.line)
4458 { 4432 {
4459 /* backup to last char of previous line */ 4433 // backup to last char of previous line
4460 --rex.lnum; 4434 --rex.lnum;
4461 rex.line = reg_getline(rex.lnum); 4435 rex.line = reg_getline(rex.lnum);
4462 /* Just in case regrepeat() didn't count 4436 // Just in case regrepeat() didn't count
4463 * right. */ 4437 // right.
4464 if (rex.line == NULL) 4438 if (rex.line == NULL)
4465 break; 4439 break;
4466 rex.input = rex.line + STRLEN(rex.line); 4440 rex.input = rex.line + STRLEN(rex.line);
4467 fast_breakcheck(); 4441 fast_breakcheck();
4468 } 4442 }
4469 else 4443 else
4470 MB_PTR_BACK(rex.line, rex.input); 4444 MB_PTR_BACK(rex.line, rex.input);
4471 } 4445 }
4472 else 4446 else
4473 { 4447 {
4474 /* Range is backwards, use shortest match first. 4448 // Range is backwards, use shortest match first.
4475 * Careful: maxval and minval are exchanged! 4449 // Careful: maxval and minval are exchanged!
4476 * Couldn't or didn't match: try advancing one 4450 // Couldn't or didn't match: try advancing one
4477 * char. */ 4451 // char.
4478 if (rst->count == rst->minval 4452 if (rst->count == rst->minval
4479 || regrepeat(OPERAND(rp->rs_scan), 1L) == 0) 4453 || regrepeat(OPERAND(rp->rs_scan), 1L) == 0)
4480 break; 4454 break;
4481 ++rst->count; 4455 ++rst->count;
4482 } 4456 }
4484 break; 4458 break;
4485 } 4459 }
4486 else 4460 else
4487 status = RA_NOMATCH; 4461 status = RA_NOMATCH;
4488 4462
4489 /* If it could match, try it. */ 4463 // If it could match, try it.
4490 if (rst->nextb == NUL || *rex.input == rst->nextb 4464 if (rst->nextb == NUL || *rex.input == rst->nextb
4491 || *rex.input == rst->nextb_ic) 4465 || *rex.input == rst->nextb_ic)
4492 { 4466 {
4493 reg_save(&rp->rs_un.regsave, &backpos); 4467 reg_save(&rp->rs_un.regsave, &backpos);
4494 scan = regnext(rp->rs_scan); 4468 scan = regnext(rp->rs_scan);
4496 break; 4470 break;
4497 } 4471 }
4498 } 4472 }
4499 if (status != RA_CONT) 4473 if (status != RA_CONT)
4500 { 4474 {
4501 /* Failed. */ 4475 // Failed.
4502 regstack_pop(&scan); 4476 regstack_pop(&scan);
4503 regstack.ga_len -= sizeof(regstar_T); 4477 regstack.ga_len -= sizeof(regstar_T);
4504 status = RA_NOMATCH; 4478 status = RA_NOMATCH;
4505 } 4479 }
4506 } 4480 }
4507 break; 4481 break;
4508 } 4482 }
4509 4483
4510 /* If we want to continue the inner loop or didn't pop a state 4484 // If we want to continue the inner loop or didn't pop a state
4511 * continue matching loop */ 4485 // continue matching loop
4512 if (status == RA_CONT || rp == (regitem_T *) 4486 if (status == RA_CONT || rp == (regitem_T *)
4513 ((char *)regstack.ga_data + regstack.ga_len) - 1) 4487 ((char *)regstack.ga_data + regstack.ga_len) - 1)
4514 break; 4488 break;
4515 } 4489 }
4516 4490
4517 /* May need to continue with the inner loop, starting at "scan". */ 4491 // May need to continue with the inner loop, starting at "scan".
4518 if (status == RA_CONT) 4492 if (status == RA_CONT)
4519 continue; 4493 continue;
4520 4494
4521 /* 4495 // If the regstack is empty or something failed we are done.
4522 * If the regstack is empty or something failed we are done.
4523 */
4524 if (regstack.ga_len == 0 || status == RA_FAIL) 4496 if (regstack.ga_len == 0 || status == RA_FAIL)
4525 { 4497 {
4526 if (scan == NULL) 4498 if (scan == NULL)
4527 { 4499 {
4528 /* 4500 // We get here only if there's trouble -- normally "case END" is
4529 * We get here only if there's trouble -- normally "case END" is 4501 // the terminating point.
4530 * the terminating point.
4531 */
4532 emsg(_(e_re_corr)); 4502 emsg(_(e_re_corr));
4533 #ifdef DEBUG 4503 #ifdef DEBUG
4534 printf("Premature EOL\n"); 4504 printf("Premature EOL\n");
4535 #endif 4505 #endif
4536 } 4506 }
4537 return (status == RA_MATCH); 4507 return (status == RA_MATCH);
4538 } 4508 }
4539 4509
4540 } /* End of loop until the regstack is empty. */ 4510 } // End of loop until the regstack is empty.
4541 4511
4542 /* NOTREACHED */ 4512 // NOTREACHED
4543 } 4513 }
4544 4514
4545 /* 4515 /*
4546 * regtry - try match of "prog" with at rex.line["col"]. 4516 * regtry - try match of "prog" with at rex.line["col"].
4547 * Returns 0 for failure, number of lines contained in the match otherwise. 4517 * Returns 0 for failure, number of lines contained in the match otherwise.