X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=miniexpect.c;h=77d781c0be9fe00083f6d8fcb49dc5ff03a4bb56;hb=fcf73607913050d246dbcc4f39e7717d0960763f;hp=7debc0238e4771c59bed605c66712120947bd68e;hpb=eba90008396f05e2c0fa752421793b797383fca7;p=miniexpect.git diff --git a/miniexpect.c b/miniexpect.c index 7debc02..77d781c 100644 --- a/miniexpect.c +++ b/miniexpect.c @@ -35,14 +35,8 @@ #include #include -#include - -/* RHEL 6 pcre did not define PCRE_PARTIAL_SOFT. However PCRE_PARTIAL - * is a synonym so use that. - */ -#ifndef PCRE_PARTIAL_SOFT -#define PCRE_PARTIAL_SOFT PCRE_PARTIAL -#endif +#define PCRE2_CODE_UNIT_WIDTH 8 +#include #include "miniexpect.h" @@ -251,7 +245,8 @@ mexp_spawnvf (unsigned flags, const char *file, char **argv) } enum mexp_status -mexp_expect (mexp_h *h, const mexp_regexp *regexps, int *ovector, int ovecsize) +mexp_expect (mexp_h *h, const mexp_regexp *regexps, + pcre2_match_data *match_data) { time_t start_t, now_t; int timeout; @@ -347,29 +342,36 @@ mexp_expect (mexp_h *h, const mexp_regexp *regexps, int *ovector, int ovecsize) assert (h->buffer != NULL); for (i = 0; regexps[i].r > 0; ++i) { - const int options = regexps[i].options | PCRE_PARTIAL_SOFT; + const int options = regexps[i].options | PCRE2_PARTIAL_SOFT; - r = pcre_exec (regexps[i].re, regexps[i].extra, - h->buffer, (int)h->len, 0, - options, - ovector, ovecsize); + r = pcre2_match (regexps[i].re, + (PCRE2_SPTR) h->buffer, (int)h->len, 0, + options, match_data, NULL); h->pcre_error = r; if (r >= 0) { /* A full match. */ - if (ovector != NULL && ovecsize >= 1 && ovector[1] >= 0) + const PCRE2_SIZE *ovector = NULL; + + if (match_data) + ovector = pcre2_get_ovector_pointer (match_data); + + if (ovector != NULL && ovector[1] >= 0) h->next_match = ovector[1]; else h->next_match = -1; + if (h->debug_fp) + fprintf (h->debug_fp, "DEBUG: next_match at buffer offset %zu\n", + h->next_match); return regexps[i].r; } - else if (r == PCRE_ERROR_NOMATCH) { + else if (r == PCRE2_ERROR_NOMATCH) { /* No match at all. */ /* (nothing here) */ } - else if (r == PCRE_ERROR_PARTIAL) { + else if (r == PCRE2_ERROR_PARTIAL) { /* Partial match. Keep the buffer and keep reading. */ can_clear_buffer = 0; }