comparison src/regex.c @ 175:2d532a89d707 r20-3b14

Import from CVS: tag r20-3b14
author cvs
date Mon, 13 Aug 2007 09:50:14 +0200
parents 15872534500d
children 9ad43877534d
comparison
equal deleted inserted replaced
174:bb3568571b84 175:2d532a89d707
1312 this_reg++) \ 1312 this_reg++) \
1313 { \ 1313 { \
1314 DEBUG_PRINT2 (" Pushing reg: %d\n", this_reg); \ 1314 DEBUG_PRINT2 (" Pushing reg: %d\n", this_reg); \
1315 DEBUG_STATEMENT (num_regs_pushed++); \ 1315 DEBUG_STATEMENT (num_regs_pushed++); \
1316 \ 1316 \
1317 DEBUG_PRINT2 (" start: 0x%lx\n", \ 1317 DEBUG_PRINT2 (" start: 0x%p\n", regstart[this_reg]); \
1318 (unsigned long) regstart[this_reg]); \
1319 PUSH_FAILURE_POINTER (regstart[this_reg]); \ 1318 PUSH_FAILURE_POINTER (regstart[this_reg]); \
1320 \ 1319 \
1321 DEBUG_PRINT2 (" end: 0x%lx\n", \ 1320 DEBUG_PRINT2 (" end: 0x%p\n", regend[this_reg]); \
1322 (unsigned long) regend[this_reg]); \
1323 PUSH_FAILURE_POINTER (regend[this_reg]); \ 1321 PUSH_FAILURE_POINTER (regend[this_reg]); \
1324 \ 1322 \
1325 DEBUG_PRINT2 (" info: 0x%lx\n ", \ 1323 DEBUG_PRINT2 (" info: 0x%lx\n ", \
1326 * (unsigned long *) (&reg_info[this_reg])); \ 1324 * (unsigned long *) (&reg_info[this_reg])); \
1327 DEBUG_PRINT2 (" match_null=%d", \ 1325 DEBUG_PRINT2 (" match_null=%d", \
1339 PUSH_FAILURE_INT (lowest_active_reg); \ 1337 PUSH_FAILURE_INT (lowest_active_reg); \
1340 \ 1338 \
1341 DEBUG_PRINT2 (" Pushing high active reg: %d\n", highest_active_reg);\ 1339 DEBUG_PRINT2 (" Pushing high active reg: %d\n", highest_active_reg);\
1342 PUSH_FAILURE_INT (highest_active_reg); \ 1340 PUSH_FAILURE_INT (highest_active_reg); \
1343 \ 1341 \
1344 DEBUG_PRINT2 (" Pushing pattern 0x%lx: ", \ 1342 DEBUG_PRINT2 (" Pushing pattern 0x%p: ", pattern_place); \
1345 (unsigned long) pattern_place); \
1346 DEBUG_PRINT_COMPILED_PATTERN (bufp, pattern_place, pend); \ 1343 DEBUG_PRINT_COMPILED_PATTERN (bufp, pattern_place, pend); \
1347 PUSH_FAILURE_POINTER (pattern_place); \ 1344 PUSH_FAILURE_POINTER (pattern_place); \
1348 \ 1345 \
1349 DEBUG_PRINT2 (" Pushing string 0x%lx: `", \ 1346 DEBUG_PRINT2 (" Pushing string 0x%p: `", string_place); \
1350 (unsigned long) string_place); \
1351 DEBUG_PRINT_DOUBLE_STRING (string_place, string1, size1, string2, \ 1347 DEBUG_PRINT_DOUBLE_STRING (string_place, string1, size1, string2, \
1352 size2); \ 1348 size2); \
1353 DEBUG_PRINT1 ("'\n"); \ 1349 DEBUG_PRINT1 ("'\n"); \
1354 PUSH_FAILURE_POINTER (string_place); \ 1350 PUSH_FAILURE_POINTER (string_place); \
1355 \ 1351 \
1419 saved NULL, thus retaining our current position in the string. */ \ 1415 saved NULL, thus retaining our current position in the string. */ \
1420 string_temp = POP_FAILURE_POINTER (); \ 1416 string_temp = POP_FAILURE_POINTER (); \
1421 if (string_temp != NULL) \ 1417 if (string_temp != NULL) \
1422 str = (CONST char *) string_temp; \ 1418 str = (CONST char *) string_temp; \
1423 \ 1419 \
1424 DEBUG_PRINT2 (" Popping string 0x%lx: `", (unsigned long) str); \ 1420 DEBUG_PRINT2 (" Popping string 0x%p: `", str); \
1425 DEBUG_PRINT_DOUBLE_STRING (str, string1, size1, string2, size2); \ 1421 DEBUG_PRINT_DOUBLE_STRING (str, string1, size1, string2, size2); \
1426 DEBUG_PRINT1 ("'\n"); \ 1422 DEBUG_PRINT1 ("'\n"); \
1427 \ 1423 \
1428 pat = (unsigned char *) POP_FAILURE_POINTER (); \ 1424 pat = (unsigned char *) POP_FAILURE_POINTER (); \
1429 DEBUG_PRINT2 (" Popping pattern 0x%lx: ", (unsigned long) pat); \ 1425 DEBUG_PRINT2 (" Popping pattern 0x%p: ", pat); \
1430 DEBUG_PRINT_COMPILED_PATTERN (bufp, pat, pend); \ 1426 DEBUG_PRINT_COMPILED_PATTERN (bufp, pat, pend); \
1431 \ 1427 \
1432 /* Restore register info. */ \ 1428 /* Restore register info. */ \
1433 high_reg = (unsigned) POP_FAILURE_INT (); \ 1429 high_reg = (unsigned) POP_FAILURE_INT (); \
1434 DEBUG_PRINT2 (" Popping high active reg: %d\n", high_reg); \ 1430 DEBUG_PRINT2 (" Popping high active reg: %d\n", high_reg); \
1443 reg_info[this_reg].word = POP_FAILURE_ELT (); \ 1439 reg_info[this_reg].word = POP_FAILURE_ELT (); \
1444 DEBUG_PRINT2 (" info: 0x%lx\n", \ 1440 DEBUG_PRINT2 (" info: 0x%lx\n", \
1445 * (unsigned long *) &reg_info[this_reg]); \ 1441 * (unsigned long *) &reg_info[this_reg]); \
1446 \ 1442 \
1447 regend[this_reg] = (CONST char *) POP_FAILURE_POINTER (); \ 1443 regend[this_reg] = (CONST char *) POP_FAILURE_POINTER (); \
1448 DEBUG_PRINT2 (" end: 0x%lx\n", \ 1444 DEBUG_PRINT2 (" end: 0x%p\n", regend[this_reg]); \
1449 (unsigned long) regend[this_reg]); \
1450 \ 1445 \
1451 regstart[this_reg] = (CONST char *) POP_FAILURE_POINTER (); \ 1446 regstart[this_reg] = (CONST char *) POP_FAILURE_POINTER (); \
1452 DEBUG_PRINT2 (" start: 0x%lx\n", \ 1447 DEBUG_PRINT2 (" start: 0x%p\n", regstart[this_reg]); \
1453 (unsigned long) regstart[this_reg]); \
1454 } \ 1448 } \
1455 \ 1449 \
1456 set_regs_matched_done = 0; \ 1450 set_regs_matched_done = 0; \
1457 DEBUG_STATEMENT (nfailure_points_popped++); \ 1451 DEBUG_STATEMENT (nfailure_points_popped++); \
1458 } /* POP_FAILURE_POINT */ 1452 } /* POP_FAILURE_POINT */
3322 #ifdef MATCH_MAY_ALLOCATE 3316 #ifdef MATCH_MAY_ALLOCATE
3323 fail_stack_type fail_stack; 3317 fail_stack_type fail_stack;
3324 #endif 3318 #endif
3325 DECLARE_DESTINATION 3319 DECLARE_DESTINATION
3326 /* We don't push any register information onto the failure stack. */ 3320 /* We don't push any register information onto the failure stack. */
3327 unsigned num_regs = 0;
3328 3321
3329 register char *fastmap = bufp->fastmap; 3322 register char *fastmap = bufp->fastmap;
3330 unsigned char *pattern = bufp->buffer; 3323 unsigned char *pattern = bufp->buffer;
3331 unsigned long size = bufp->used; 3324 unsigned long size = bufp->used;
3332 unsigned char *p = pattern; 3325 unsigned char *p = pattern;
4418 /* This loops over pattern commands. It exits by returning from the 4411 /* This loops over pattern commands. It exits by returning from the
4419 function if the match is complete, or it drops through if the match 4412 function if the match is complete, or it drops through if the match
4420 fails at this starting point in the input data. */ 4413 fails at this starting point in the input data. */
4421 for (;;) 4414 for (;;)
4422 { 4415 {
4423 DEBUG_PRINT2 ("\n0x%lx: ", (unsigned long) p); 4416 DEBUG_PRINT2 ("\n0x%p: ", p);
4424 4417
4425 if (p == pend) 4418 if (p == pend)
4426 { /* End of pattern means we might have succeeded. */ 4419 { /* End of pattern means we might have succeeded. */
4427 DEBUG_PRINT1 ("end of pattern ... "); 4420 DEBUG_PRINT1 ("end of pattern ... ");
4428 4421
5021 case; that seems worse than this. */ 5014 case; that seems worse than this. */
5022 case on_failure_keep_string_jump: 5015 case on_failure_keep_string_jump:
5023 DEBUG_PRINT1 ("EXECUTING on_failure_keep_string_jump"); 5016 DEBUG_PRINT1 ("EXECUTING on_failure_keep_string_jump");
5024 5017
5025 EXTRACT_NUMBER_AND_INCR (mcnt, p); 5018 EXTRACT_NUMBER_AND_INCR (mcnt, p);
5026 DEBUG_PRINT3 (" %d (to 0x%lx):\n", mcnt, (unsigned long) (p + mcnt)); 5019 DEBUG_PRINT3 (" %d (to 0x%p):\n", mcnt, p + mcnt);
5027 5020
5028 PUSH_FAILURE_POINT (p + mcnt, NULL, -2); 5021 PUSH_FAILURE_POINT (p + mcnt, NULL, -2);
5029 break; 5022 break;
5030 5023
5031 5024
5044 case on_failure_jump: 5037 case on_failure_jump:
5045 on_failure: 5038 on_failure:
5046 DEBUG_PRINT1 ("EXECUTING on_failure_jump"); 5039 DEBUG_PRINT1 ("EXECUTING on_failure_jump");
5047 5040
5048 EXTRACT_NUMBER_AND_INCR (mcnt, p); 5041 EXTRACT_NUMBER_AND_INCR (mcnt, p);
5049 DEBUG_PRINT3 (" %d (to 0x%lx)", mcnt, (unsigned long) (p + mcnt)); 5042 DEBUG_PRINT3 (" %d (to 0x%p)", mcnt, p + mcnt);
5050 5043
5051 /* If this on_failure_jump comes right before a group (i.e., 5044 /* If this on_failure_jump comes right before a group (i.e.,
5052 the original * applied to a group), save the information 5045 the original * applied to a group), save the information
5053 for that group and all inner ones, so that if we fail back 5046 for that group and all inner ones, so that if we fail back
5054 to this point, the group's information will be correct. 5047 to this point, the group's information will be correct.
5259 case jump: 5252 case jump:
5260 unconditional_jump: 5253 unconditional_jump:
5261 EXTRACT_NUMBER_AND_INCR (mcnt, p); /* Get the amount to jump. */ 5254 EXTRACT_NUMBER_AND_INCR (mcnt, p); /* Get the amount to jump. */
5262 DEBUG_PRINT2 ("EXECUTING jump %d ", mcnt); 5255 DEBUG_PRINT2 ("EXECUTING jump %d ", mcnt);
5263 p += mcnt; /* Do the jump. */ 5256 p += mcnt; /* Do the jump. */
5264 DEBUG_PRINT2 ("(to 0x%lx).\n", (unsigned long) p); 5257 DEBUG_PRINT2 ("(to 0x%p).\n", p);
5265 break; 5258 break;
5266 5259
5267 5260
5268 /* We need this opcode so we can detect where alternatives end 5261 /* We need this opcode so we can detect where alternatives end
5269 in `group_match_null_string_p' et al. */ 5262 in `group_match_null_string_p' et al. */
5279 something meaningless for pop_failure_jump to pop. */ 5272 something meaningless for pop_failure_jump to pop. */
5280 case dummy_failure_jump: 5273 case dummy_failure_jump:
5281 DEBUG_PRINT1 ("EXECUTING dummy_failure_jump.\n"); 5274 DEBUG_PRINT1 ("EXECUTING dummy_failure_jump.\n");
5282 /* It doesn't matter what we push for the string here. What 5275 /* It doesn't matter what we push for the string here. What
5283 the code at `fail' tests is the value for the pattern. */ 5276 the code at `fail' tests is the value for the pattern. */
5284 PUSH_FAILURE_POINT (0, 0, -2); 5277 PUSH_FAILURE_POINT (NULL, NULL, -2);
5285 goto unconditional_jump; 5278 goto unconditional_jump;
5286 5279
5287 5280
5288 /* At the end of an alternative, we need to push a dummy failure 5281 /* At the end of an alternative, we need to push a dummy failure
5289 point in case we are followed by a `pop_failure_jump', because 5282 point in case we are followed by a `pop_failure_jump', because
5292 requires that we match the `ab' alternative. */ 5285 requires that we match the `ab' alternative. */
5293 case push_dummy_failure: 5286 case push_dummy_failure:
5294 DEBUG_PRINT1 ("EXECUTING push_dummy_failure.\n"); 5287 DEBUG_PRINT1 ("EXECUTING push_dummy_failure.\n");
5295 /* See comments just above at `dummy_failure_jump' about the 5288 /* See comments just above at `dummy_failure_jump' about the
5296 two zeroes. */ 5289 two zeroes. */
5297 PUSH_FAILURE_POINT (0, 0, -2); 5290 PUSH_FAILURE_POINT (NULL, NULL, -2);
5298 break; 5291 break;
5299 5292
5300 /* Have to succeed matching what follows at least n times. 5293 /* Have to succeed matching what follows at least n times.
5301 After that, handle like `on_failure_jump'. */ 5294 After that, handle like `on_failure_jump'. */
5302 case succeed_n: 5295 case succeed_n:
5308 if (mcnt > 0) 5301 if (mcnt > 0)
5309 { 5302 {
5310 mcnt--; 5303 mcnt--;
5311 p += 2; 5304 p += 2;
5312 STORE_NUMBER_AND_INCR (p, mcnt); 5305 STORE_NUMBER_AND_INCR (p, mcnt);
5313 DEBUG_PRINT3 (" Setting 0x%lx to %d.\n", (unsigned long) p, 5306 DEBUG_PRINT3 (" Setting 0x%p to %d.\n", p, mcnt);
5314 mcnt);
5315 } 5307 }
5316 else if (mcnt == 0) 5308 else if (mcnt == 0)
5317 { 5309 {
5318 DEBUG_PRINT2 (" Setting two bytes from 0x%lx to no_op.\n", 5310 DEBUG_PRINT2 (" Setting two bytes from 0x%p to no_op.\n", p+2);
5319 (unsigned long) p+2);
5320 p[2] = (unsigned char) no_op; 5311 p[2] = (unsigned char) no_op;
5321 p[3] = (unsigned char) no_op; 5312 p[3] = (unsigned char) no_op;
5322 goto on_failure; 5313 goto on_failure;
5323 } 5314 }
5324 break; 5315 break;
5344 DEBUG_PRINT1 ("EXECUTING set_number_at.\n"); 5335 DEBUG_PRINT1 ("EXECUTING set_number_at.\n");
5345 5336
5346 EXTRACT_NUMBER_AND_INCR (mcnt, p); 5337 EXTRACT_NUMBER_AND_INCR (mcnt, p);
5347 p1 = p + mcnt; 5338 p1 = p + mcnt;
5348 EXTRACT_NUMBER_AND_INCR (mcnt, p); 5339 EXTRACT_NUMBER_AND_INCR (mcnt, p);
5349 DEBUG_PRINT3 (" Setting 0x%lx to %d.\n", (unsigned long) p1, 5340 DEBUG_PRINT3 (" Setting 0x%p to %d.\n", p1, mcnt);
5350 mcnt);
5351 STORE_NUMBER (p1, mcnt); 5341 STORE_NUMBER (p1, mcnt);
5352 break; 5342 break;
5353 } 5343 }
5354 5344
5355 case wordbound: 5345 case wordbound: