summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--Src/Modules/pcre.c40
-rw-r--r--zshconfig.ac2
3 files changed, 43 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index df6cb2ce5..9262ff0f4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2001-07-03  Clint Adams  <clint@zsh.org>
 
+	* 15228: zshconfig.ac, Src/Modules/pcre.c:
+	switch AC_CHECK_LIB to AC_SEARCH_LIBS for pcre.
+	Have pcre_match set positional parameters
+	with the contents of capture buffers.
+
+2001-07-03  Clint Adams  <clint@zsh.org>
+
 	* unposted: Doc/Makefile.in: add mod_pcre.yo to makefile.
 
 2001-07-03  Oliver Kiddle  <opk@zsh.org>
diff --git a/Src/Modules/pcre.c b/Src/Modules/pcre.c
index a4dbb24c9..899056c6f 100644
--- a/Src/Modules/pcre.c
+++ b/Src/Modules/pcre.c
@@ -27,11 +27,12 @@
  *
  */
 
-/**/
-#if defined(HAVE_PCRE_COMPILE) && defined(HAVE_PCRE_EXEC)
 
 #include "pcre.mdh"
 #include "pcre.pro"
+
+/**/
+#if defined(HAVE_PCRE_COMPILE) && defined(HAVE_PCRE_EXEC)
 #include <pcre.h>
 
 static pcre *pcre_pattern;
@@ -49,6 +50,8 @@ bin_pcre_compile(char *nam, char **args, char *ops, int func)
     if(ops['m']) pcre_opts |= PCRE_MULTILINE;
     if(ops['x']) pcre_opts |= PCRE_EXTENDED;
     
+    pcre_hints = NULL;  /* Is this necessary? */
+    
     pcre_pattern = pcre_compile(*args, pcre_opts, &pcre_error, &pcre_errptr, NULL);
     
     if (pcre_pattern == NULL)
@@ -86,11 +89,38 @@ bin_pcre_study(char *nam, char **args, char *ops, int func)
 static int
 bin_pcre_match(char *nam, char **args, char *ops, int func)
 {
-#define PCRE_OVEC_SIZE 50
+    int ret, capcount, *ovec, ovecsize;
+    char **captures;
+    
+    if (pcre_fullinfo(pcre_pattern, pcre_hints, PCRE_INFO_CAPTURECOUNT, &capcount))
+    {
+	zwarnnam(nam, "error in fullinfo", NULL, 0);
+	return 1;
+    }
+    
+    ovecsize = (capcount+1)*3;
+    ovec = zalloc(ovecsize*sizeof(int));
+    
+    ret = pcre_exec(pcre_pattern, pcre_hints, *args, strlen(*args), 0, 0, ovec, ovecsize);
     
-    int ovec[PCRE_OVEC_SIZE];   /* throwing this away now, but will be useful someday */
+    if (ret==0) return 0;
+    else if (ret==PCRE_ERROR_NOMATCH) return 1; /* no match */
+    else if (ret>0) {
+	if(!pcre_get_substring_list(*args, ovec, ret, (const char ***)&captures)) {
+
+	    freearray(pparams);
+	    pparams = zarrdup(&captures[1]); /* first one would be entire string */
+	    
+	    pcre_free_substring_list((const char **)captures);
+	    return 0;
+      	}
+    }
+    else {
+	zwarnnam(nam, "error in pcre_exec", NULL, 0);
+	return 1;
+    }
     
-    return !(pcre_exec(pcre_pattern, pcre_hints, *args, strlen(*args), 0, 0, ovec, PCRE_OVEC_SIZE) >= 0);
+    return 1;
 }
 
 static struct builtin bintab[] = {
diff --git a/zshconfig.ac b/zshconfig.ac
index 6019d6f4f..83b7620c1 100644
--- a/zshconfig.ac
+++ b/zshconfig.ac
@@ -644,7 +644,7 @@ AC_CHECK_LIB(cap, cap_get_proc)
 AC_CHECK_LIB(socket, socket)
 
 dnl pcre-config should probably be employed here
-AC_CHECK_LIB(pcre, pcre_compile)
+AC_SEARCH_LIBS(pcre_compile, pcre)
 
 dnl ---------------------
 dnl CHECK TERMCAP LIBRARY