From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5124 invoked from network); 25 Mar 2009 09:50:47 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 25 Mar 2009 09:50:47 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 62668 invoked from network); 25 Mar 2009 09:50:41 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 25 Mar 2009 09:50:41 -0000 Received: (qmail 5886 invoked by alias); 25 Mar 2009 09:50:35 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 26778 Received: (qmail 5873 invoked from network); 25 Mar 2009 09:50:34 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 25 Mar 2009 09:50:34 -0000 Received: from novuscom.net (smtp.novuscom.net [216.19.176.3]) by bifrost.dotsrc.org (Postfix) with ESMTP id 9D60F80EA0C1 for ; Wed, 25 Mar 2009 10:50:19 +0100 (CET) Received: (qmail 14444 invoked from network); 25 Mar 2009 09:50:18 -0000 Received: from 216-19-179-189.dyn.novuscom.net (HELO [192.168.0.101]) ([216.19.179.189]) (envelope-sender ) by smtp.novuscom.net (qmail-ldap-1.03) with SMTP for ; 25 Mar 2009 09:50:18 -0000 Message-ID: <49C9FE0B.8030303@moonloop.net> Date: Wed, 25 Mar 2009 02:48:59 -0700 From: Jon Strait User-Agent: Thunderbird 2.0.0.19 (X11/20090213) MIME-Version: 1.0 To: zsh workers Subject: PATCH: Correction on pcre.c Content-Type: multipart/mixed; boundary="------------050302020508080306010404" X-Virus-Scanned: ClamAV 0.92.1/9164/Wed Mar 25 05:02:31 2009 on bifrost X-Virus-Status: Clean This is a multi-part message in MIME format. --------------050302020508080306010404 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit The last patch for the pcre.c file was missing a couple of lines. Sorry. Jon --------------050302020508080306010404 Content-Type: text/x-patch; name="pcre.c.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="pcre.c.patch" --- pcre-old.c 2007-07-09 02:30:42.000000000 -0700 +++ pcre.c 2009-03-25 02:42:44.000000000 -0700 @@ -82,6 +82,7 @@ if(OPT_ISSET(ops,'i')) pcre_opts |= PCRE_CASELESS; if(OPT_ISSET(ops,'m')) pcre_opts |= PCRE_MULTILINE; if(OPT_ISSET(ops,'x')) pcre_opts |= PCRE_EXTENDED; + if(OPT_ISSET(ops,'s')) pcre_opts |= PCRE_DOTALL; if (zpcre_utf8_enabled()) pcre_opts |= PCRE_UTF8; @@ -137,9 +138,11 @@ /**/ static int -zpcre_get_substrings(char *arg, int *ovec, int ret, char *matchvar, char *substravar, int matchedinarr) +zpcre_get_substrings(char *arg, int *ovec, int ret, char *matchvar, char *substravar, + int want_offset_pair, int matchedinarr) { char **captures, *match_all, **matches; + char offset_all[50]; int capture_start = 1; if (matchedinarr) @@ -148,9 +151,14 @@ matchvar = "MATCH"; if (substravar == NULL) substravar = "match"; - + /* captures[0] will be entire matched string, [1] first substring */ - if(!pcre_get_substring_list(arg, ovec, ret, (const char ***)&captures)) { + if (!pcre_get_substring_list(arg, ovec, ret, (const char ***)&captures)) { + /* Set to the offsets of the complete match */ + if (want_offset_pair) { + sprintf(offset_all, "%d %d", ovec[0], ovec[1]); + setsparam("ZPCRE_OP", ztrdup(offset_all)); + } match_all = ztrdup(captures[0]); setsparam(matchvar, match_all); matches = zarrdup(&captures[capture_start]); @@ -163,12 +171,32 @@ /**/ static int +getposint(char *instr, char *nam) +{ + char *eptr; + int ret; + + ret = (int)zstrtol(instr, &eptr, 10); + if (*eptr || ret < 0) { + zwarnnam(nam, "integer expected: %s", instr); + return -1; + } + + return ret; +} + +/**/ +static int bin_pcre_match(char *nam, char **args, Options ops, UNUSED(int func)) { int ret, capcount, *ovec, ovecsize, c; char *matched_portion = NULL; char *receptacle = NULL; int return_value = 1; + /* The subject length and offset start are both int values in pcre_exec */ + int subject_len; + int offset_start = 0; + int want_offset_pair = 0; if (pcre_pattern == NULL) { zwarnnam(nam, "no pattern has been compiled"); @@ -181,6 +209,12 @@ if(OPT_HASARG(ops,c='v')) { matched_portion = OPT_ARG(ops,c); } + if(OPT_HASARG(ops,c='n')) { /* The offset position to start the search, in bytes. */ + offset_start = getposint(OPT_ARG(ops,c), nam); + } + /* For the entire match, 'Return' the offset byte positions instead of the matched string */ + if(OPT_ISSET(ops,'b')) want_offset_pair = 1; + if(!*args) { zwarnnam(nam, "not enough arguments"); } @@ -194,12 +228,17 @@ ovecsize = (capcount+1)*3; ovec = zalloc(ovecsize*sizeof(int)); - ret = pcre_exec(pcre_pattern, pcre_hints, *args, strlen(*args), 0, 0, ovec, ovecsize); - + subject_len = (int)strlen(*args); + + if (offset_start < 0 || offset_start >= subject_len) + ret = PCRE_ERROR_NOMATCH; + else + ret = pcre_exec(pcre_pattern, pcre_hints, *args, subject_len, offset_start, 0, ovec, ovecsize); + if (ret==0) return_value = 0; else if (ret==PCRE_ERROR_NOMATCH) /* no match */; else if (ret>0) { - zpcre_get_substrings(*args, ovec, ret, matched_portion, receptacle, 0); + zpcre_get_substrings(*args, ovec, ret, matched_portion, receptacle, want_offset_pair, 0); return_value = 0; } else { @@ -258,7 +297,7 @@ break; } else if (r>0) { - zpcre_get_substrings(lhstr, ov, r, NULL, avar, isset(BASHREMATCH)); + zpcre_get_substrings(lhstr, ov, r, NULL, avar, 0, isset(BASHREMATCH)); return_value = 1; break; } @@ -289,8 +328,8 @@ #endif /* !(HAVE_PCRE_COMPILE && HAVE_PCRE_EXEC) */ static struct builtin bintab[] = { - BUILTIN("pcre_compile", 0, bin_pcre_compile, 1, 1, 0, "aimx", NULL), - BUILTIN("pcre_match", 0, bin_pcre_match, 1, 1, 0, "a:v:", NULL), + BUILTIN("pcre_compile", 0, bin_pcre_compile, 1, 1, 0, "aimxs", NULL), + BUILTIN("pcre_match", 0, bin_pcre_match, 1, 1, 0, "a:v:n:b", NULL), BUILTIN("pcre_study", 0, bin_pcre_study, 0, 0, 0, NULL, NULL) }; --------------050302020508080306010404--