| 406 | } |
| 407 | |
| 408 | static int pcre2match(struct grep_pat *p, const char *line, const char *eol, |
| 409 | regmatch_t *match, int eflags) |
| 410 | { |
| 411 | int ret, flags = 0; |
| 412 | PCRE2_SIZE *ovector; |
| 413 | PCRE2_UCHAR errbuf[256]; |
| 414 | |
| 415 | if (eflags & REG_NOTBOL) |
| 416 | flags |= PCRE2_NOTBOL; |
| 417 | |
| 418 | if (p->pcre2_jit_on) |
| 419 | ret = pcre2_jit_match(p->pcre2_pattern, (unsigned char *)line, |
| 420 | eol - line, 0, flags, p->pcre2_match_data, |
| 421 | NULL); |
| 422 | else |
| 423 | ret = pcre2_match(p->pcre2_pattern, (unsigned char *)line, |
| 424 | eol - line, 0, flags, p->pcre2_match_data, |
| 425 | NULL); |
| 426 | |
| 427 | if (ret < 0 && ret != PCRE2_ERROR_NOMATCH) { |
| 428 | pcre2_get_error_message(ret, errbuf, sizeof(errbuf)); |
| 429 | die("%s failed with error code %d: %s", |
| 430 | (p->pcre2_jit_on ? "pcre2_jit_match" : "pcre2_match"), ret, |
| 431 | errbuf); |
| 432 | } |
| 433 | if (ret > 0) { |
| 434 | ovector = pcre2_get_ovector_pointer(p->pcre2_match_data); |
| 435 | ret = 0; |
| 436 | match->rm_so = (int)ovector[0]; |
| 437 | match->rm_eo = (int)ovector[1]; |
| 438 | } |
| 439 | |
| 440 | return ret; |
| 441 | } |
| 442 | |
| 443 | static void free_pcre2_pattern(struct grep_pat *p) |
| 444 | { |