Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 15 Jul 2008 13:00:19 GMT
From:      Gabor Kovesdan <gabor@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 145277 for review
Message-ID:  <200807151300.m6FD0JD9044085@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=145277

Change 145277 by gabor@gabor_server on 2008/07/15 13:00:19

	- Add some work-in-progress PCRE code

Affected files ...

.. //depot/projects/soc2008/gabor_textproc/grep/Makefile#12 edit
.. //depot/projects/soc2008/gabor_textproc/grep/grep.c#67 edit
.. //depot/projects/soc2008/gabor_textproc/grep/grep.h#38 edit
.. //depot/projects/soc2008/gabor_textproc/grep/util.c#61 edit

Differences ...

==== //depot/projects/soc2008/gabor_textproc/grep/Makefile#12 (text+ko) ====

@@ -21,9 +21,10 @@
 DPADD=	${LIBZ} ${LIBBZ2}
 
 .if defined(WITH_PCRE)
-CFLAGS+=	WITH_PCRE=yes
+CFLAGS+=	-DWITH_PCRE=yes -I/usr/local/include
+LDFLAGS+=	-L/usr/local/lib
 LDADD+=	-lpcre
-DPADD=	/usr/local/lib/libpcre.a
+DPADD+=	/usr/local/lib/libpcre.a
 .endif
 
 .if !defined(WITHOUT_NLS)

==== //depot/projects/soc2008/gabor_textproc/grep/grep.c#67 (text+ko) ====

@@ -87,6 +87,9 @@
 int		 patterns, pattern_sz;
 char		**pattern;
 regex_t		*r_pattern;
+#ifdef WITH_PCRE
+pcre		**perl_pattern;
+#endif
 
 /* Filename exclusion/inclusion patterns */
 int		 epatterns, epattern_sz;
@@ -551,20 +554,35 @@
 		cflags |= REG_EXTENDED;
 		break;
 	case GREP_PERL:
-		errx(2, "Not yet implemented");
 		break;
 	default:
 		/* NOTREACHED */
 		usage();
 	}
-	r_pattern = grep_calloc(patterns, sizeof(*r_pattern));
-	for (i = 0; i < patterns; ++i) {
-		c = regcomp(&r_pattern[i], pattern[i], cflags);
-		if (c != 0) {
-			regerror(c, &r_pattern[i], re_error,
-			    RE_ERROR_BUF);
-			errx(2, "%s", re_error);
+	if (grepbehave != GREP_PERL) {
+		r_pattern = grep_calloc(patterns, sizeof(*r_pattern));
+		for (i = 0; i < patterns; ++i) {
+			c = regcomp(&r_pattern[i], pattern[i], cflags);
+			if (c != 0) {
+				regerror(c, &r_pattern[i], re_error,
+				    RE_ERROR_BUF);
+				errx(2, "%s", re_error);
+			}
+		}
+	} else {
+#ifdef WITH_PCRE
+		perl_pattern = grep_calloc(patterns, sizeof(perl_pattern));
+		for (i = 0; i < patterns; ++i) {
+			char	**err_msg = NULL;
+			int	erroff;
+
+			perl_pattern[i] = pcre_compile(pattern[i], 0, (const char **)err_msg, &erroff, NULL);
+			if (perl_pattern[i] != NULL)
+				errx(2, "wrong PCRE: %s", err_msg[0]);
 		}
+#else
+		;
+#endif
 	}
 
 	if (lbflag)

==== //depot/projects/soc2008/gabor_textproc/grep/grep.h#38 (text+ko) ====

@@ -31,7 +31,7 @@
 #include <stdio.h>
 #include <zlib.h>
 
-#if defined(WITH_PCRE)
+#ifdef WITH_PCRE
 #include <pcre.h>
 #endif
 
@@ -100,12 +100,17 @@
 extern int	 nullflag, exclflag, inclflag;
 extern unsigned long long Aflag, Bflag, mcount;
 extern char	*color, *label;
-extern int	 binbehave, filebehave, devbehave, dirbehave, linkbehave;
+extern int	 grepbehave, binbehave, filebehave, devbehave, dirbehave, linkbehave;
 
 extern int	 first, prev, matchall, patterns, epatterns, tail, notfound;
 extern char    **pattern, **epattern;
 extern regex_t	*r_pattern, *er_pattern;
 
+#ifdef WITH_PCRE
+extern pcre	**perl_pattern;
+#endif
+
+
 /* For regex errors  */
 #define RE_ERROR_BUF	512
 extern char	 re_error[RE_ERROR_BUF + 1];	/* Seems big enough */

==== //depot/projects/soc2008/gabor_textproc/grep/util.c#61 (text+ko) ====

@@ -221,7 +221,10 @@
 	regmatch_t	 pmatch;
 	regmatch_t	 matches[MAX_LINE_MATCHES];
 	regoff_t	 st = 0;
-	int		 c = 0, i, r, m = 0, t;
+	int		 c = 0, i, r = 0, m = 0, t;
+#ifdef WITH_PCRE
+	int		 ovector[3];
+#endif
 
 	if (!matchall) {
 		t = vflag ? REG_NOMATCH : 0;
@@ -231,7 +234,19 @@
 			pmatch.rm_eo = l->len;
 
 			for (i = 0; i < patterns; i++) {
-				r = regexec(&r_pattern[i], l->dat, 1, &pmatch, eflags);
+				if (grepbehave != GREP_PERL) {
+					r = regexec(&r_pattern[i], l->dat, 1, &pmatch, eflags);
+					st = pmatch.rm_eo;
+				} else {
+#ifdef WITH_PCRE
+					r = pcre_exec(perl_pattern[i], NULL, l->dat, l->len, st, 0, &ovector, 3);
+					pmatch.rm_so = ovector[0];
+					pmatch.rm_eo = ovector[1];
+					st = ovector[1];
+#else
+					;
+#endif
+				}
 				if (r == REG_NOMATCH && t == 0)
 					continue;
 				if (r == 0 && xflag)
@@ -256,7 +271,6 @@
 						matches[m] = pmatch;
 						m++;
 				}
-					st = pmatch.rm_eo;
 					break;
 			}
 			/* One pass if we are not recording matches */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200807151300.m6FD0JD9044085>