166
pcre2_malloc, pcre2_free, NULL);
167
#endif
168
169
-#ifdef USE_LIBPCRE1
170
- pcre_malloc = malloc;
171
- pcre_free = free;
172
-#endif
173
-
169
*opt = grep_defaults;
170
171
opt->repo = repo;
218
break;
219
220
case GREP_PATTERN_TYPE_PCRE:
226
-#ifdef USE_LIBPCRE2
221
opt->pcre2 = 1;
228
-#else
229
- /*
230
- * It's important that pcre1 always be assigned to
231
- * even when there's no USE_LIBPCRE* defined. We still
232
- * call the PCRE stub function, it just dies with
233
- * "cannot use Perl-compatible regexes[...]".
234
- */
235
- opt->pcre1 = 1;
236
-#endif
222
break;
223
}
224
}
362
return 1;
363
}
364
380
-#ifdef USE_LIBPCRE1
381
-static void compile_pcre1_regexp(struct grep_pat *p, const struct grep_opt *opt)
382
-{
383
- const char *error;
384
- int erroffset;
385
- int options = PCRE_MULTILINE;
386
- int study_options = 0;
387
-
388
- if (opt->ignore_case) {
389
- if (!opt->ignore_locale && has_non_ascii(p->pattern))
390
- p->pcre1_tables = pcre_maketables();
391
- options |= PCRE_CASELESS;
392
- }
393
- if (!opt->ignore_locale && is_utf8_locale() && has_non_ascii(p->pattern))
394
- options |= PCRE_UTF8;
395
-
396
- p->pcre1_regexp = pcre_compile(p->pattern, options, &error, &erroffset,
397
- p->pcre1_tables);
398
- if (!p->pcre1_regexp)
399
- compile_regexp_failed(p, error);
400
-
401
-#if defined(PCRE_CONFIG_JIT) && !defined(NO_LIBPCRE1_JIT)
402
- pcre_config(PCRE_CONFIG_JIT, &p->pcre1_jit_on);
403
- if (opt->debug)
404
- fprintf(stderr, "pcre1_jit_on=%d\n", p->pcre1_jit_on);
405
-
406
- if (p->pcre1_jit_on)
407
- study_options = PCRE_STUDY_JIT_COMPILE;
408
-#endif
409
-
410
- p->pcre1_extra_info = pcre_study(p->pcre1_regexp, study_options, &error);
411
- if (!p->pcre1_extra_info && error)
412
- die("%s", error);
413
-}
414
-
415
-static int pcre1match(struct grep_pat *p, const char *line, const char *eol,
416
- regmatch_t *match, int eflags)
417
-{
418
- int ovector[30], ret, flags = PCRE_NO_UTF8_CHECK;
419
-
420
- if (eflags & REG_NOTBOL)
421
- flags |= PCRE_NOTBOL;
422
-
423
- ret = pcre_exec(p->pcre1_regexp, p->pcre1_extra_info, line,
424
- eol - line, 0, flags, ovector,
425
- ARRAY_SIZE(ovector));
426
-
427
- if (ret < 0 && ret != PCRE_ERROR_NOMATCH)
428
- die("pcre_exec failed with error code %d", ret);
429
- if (ret > 0) {
430
- ret = 0;
431
- match->rm_so = ovector[0];
432
- match->rm_eo = ovector[1];
433
- }
434
-
435
- return ret;
436
-}
437
-
438
-static void free_pcre1_regexp(struct grep_pat *p)
439
-{
440
- pcre_free(p->pcre1_regexp);
441
-#ifdef PCRE_CONFIG_JIT
442
- if (p->pcre1_jit_on)
443
- pcre_free_study(p->pcre1_extra_info);
444
- else
445
-#endif
446
- pcre_free(p->pcre1_extra_info);
447
- pcre_free((void *)p->pcre1_tables);
448
-}
449
-#else /* !USE_LIBPCRE1 */
450
-static void compile_pcre1_regexp(struct grep_pat *p, const struct grep_opt *opt)
451
-{
452
- die("cannot use Perl-compatible regexes when not compiled with USE_LIBPCRE");
453
-}
454
-
455
-static int pcre1match(struct grep_pat *p, const char *line, const char *eol,
456
- regmatch_t *match, int eflags)
457
-{
458
- return 1;
459
-}
460
-
461
-static void free_pcre1_regexp(struct grep_pat *p)
462
-{
463
-}
464
-#endif /* !USE_LIBPCRE1 */
465
-
365
#ifdef USE_LIBPCRE2
366
static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt)
367
{
487
#else /* !USE_LIBPCRE2 */
488
static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt)
489
{
591
- /*
592
- * Unreachable until USE_LIBPCRE2 becomes synonymous with
593
- * USE_LIBPCRE. See the sibling comment in
594
- * grep_set_pattern_type_option().
595
- */
490
die("cannot use Perl-compatible regexes when not compiled with USE_LIBPCRE");
491
}
492
587
return;
588
}
589
696
- if (opt->pcre1) {
697
- compile_pcre1_regexp(p, opt);
698
- return;
699
- }
700
-
590
if (p->ignore_case)
591
regflags |= REG_ICASE;
592
if (opt->extended_regexp_option)
940
case GREP_PATTERN: /* atom */
941
case GREP_PATTERN_HEAD:
942
case GREP_PATTERN_BODY:
1054
- if (p->pcre1_regexp)
1055
- free_pcre1_regexp(p);
1056
- else if (p->pcre2_pattern)
943
+ if (p->pcre2_pattern)
944
free_pcre2_pattern(p);
945
else
946
regfree(&p->regexp);
1003
{
1004
int hit;
1005
1119
- if (p->pcre1_regexp)
1120
- hit = !pcre1match(p, line, eol, match, eflags);
1121
- else if (p->pcre2_pattern)
1006
+ if (p->pcre2_pattern)
1007
hit = !pcre2match(p, line, eol, match, eflags);
1008
else
1009
hit = !regexec_buf(&p->regexp, line, eol - line, 1, match,