From: K.Kosako Date: Sun, 11 Feb 2018 09:58:50 +0000 (+0900) Subject: add builtin callout (*ERROR:n) X-Git-Tag: v6.8.0~301 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cc3f1ead0a794d97306647552be4475184abe63e;p=onig add builtin callout (*ERROR:n) --- diff --git a/sample/callout.c b/sample/callout.c index 0ec6d69..caca62c 100644 --- a/sample/callout.c +++ b/sample/callout.c @@ -169,6 +169,7 @@ extern int main(int argc, char* argv[]) test("abc(?:(*FAIL)|$)", "abcabc"); test("abc(?:(*ABORT)|$)", "abcabc"); test("ab(*foo+:will be fail.)(*FAIL)", "abc"); + test("abc(d|(*ERROR:-999))", "abc"); onig_end(); return 0; diff --git a/src/regexec.c b/src/regexec.c index b50d299..4ab9e9f 100644 --- a/src/regexec.c +++ b/src/regexec.c @@ -4900,6 +4900,21 @@ onig_builtin_success(OnigCalloutArgs* args ARG_UNUSED, void* user_data ARG_UNUSE return ONIG_CALLOUT_SUCCESS; } +extern int +onig_builtin_error(OnigCalloutArgs* args, void* user_data ARG_UNUSED) +{ + long n; + + if (args->content != 0 && args->content_end > args->content) { + n = strtol((char* )args->content, 0, 10); + } + else { + n = ONIG_CALLOUT_FAIL; + } + + return (int )n; +} + #endif /* USE_CALLOUT */ extern int @@ -4920,6 +4935,7 @@ onig_initialize_builtin_callouts(void) B1(FAIL, fail); B1(SUCCESS, success); B1(ABORT, abort); + B1(ERROR, error); return ONIG_NORMAL; #endif /* USE_CALLOUT */