From 6cef1e77274f883a8b06f0546efeff6e6b8660d8 Mon Sep 17 00:00:00 2001 From: Ilya Zakharevich Date: Tue, 21 Jul 1998 19:00:35 -0400 Subject: support match indices via special variables @- and @+ Message-Id: <199807220300.XAA16081@monk.mps.ohio-state.edu> Subject: [PATCH 5.004_76] @- and @+ p4raw-id: //depot/perl@1800 --- mg.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'mg.c') diff --git a/mg.c b/mg.c index f0039056cb..185b4f54a9 100644 --- a/mg.c +++ b/mg.c @@ -282,6 +282,48 @@ mg_free(SV *sv) #include #endif +int +magic_regdata_cnt(SV *sv, MAGIC *mg) +{ + dTHR; + register char *s; + register I32 i; + register REGEXP *rx; + char *t; + + if (PL_curpm && (rx = PL_curpm->op_pmregexp)) + return rx->lastparen; + return -1; +} + +int +magic_regdatum_get(SV *sv, MAGIC *mg) +{ + dTHR; + register I32 paren; + register char *s; + register I32 i; + register REGEXP *rx; + char *t; + + if (PL_curpm && (rx = PL_curpm->op_pmregexp)) { + paren = mg->mg_len; + if (paren < 0) + return 0; + if (paren <= rx->nparens && + (s = rx->startp[paren]) && + (t = rx->endp[paren])) + { + if (mg->mg_obj) /* @+ */ + i = t - rx->subbase; + else /* @- */ + i = s - rx->subbase; + sv_setiv(sv,i); + } + } + return 0; +} + U32 magic_len(SV *sv, MAGIC *mg) { -- cgit v1.2.1