Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 17 Jun 2008 18:54:45 GMT
From:      Gabor Kovesdan <gabor@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 143658 for review
Message-ID:  <200806171854.m5HIsjMo088750@repoman.freebsd.org>

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

Change 143658 by gabor@gabor_server on 2008/06/17 18:54:12

	- GNU compatibility: Add workaround to allow '|' with empty
	  subexpressions.  This is done by cutting off those parts,
	  e.g. "(|a|b||c|)" will be "(a|b|c)"
	
	Reported by:	dougb

Affected files ...

.. //depot/projects/soc2008/gabor_textproc/grep/grep.c#22 edit

Differences ...

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

@@ -187,6 +187,18 @@
 static void
 add_pattern(char *pat, size_t len)
 {
+	char	*ptr;
+
+/* Workaround for our libc-regex library to match GNU behaviour.
+   Our library rejects '|' with empty subexpressions.  Just cut out
+   those parts, e.g. "(|a|b||c|)" will be "(a|b|c)" */
+	while ((ptr = strstr(pat, "|)")) != NULL)
+		strlcpy(ptr, &(ptr[1]), strlen(pat) - strlen(ptr));
+	while ((ptr = strstr(pat, "(|")) != NULL)
+		strlcpy(&(ptr[1]), &(ptr[2]), strlen(pat) - strlen(ptr) - 1);
+	while ((ptr = strstr(pat, "||")) != NULL)
+		strlcpy(&(ptr[1]), &(ptr[2]), strlen(pat) - strlen(ptr) - 1);
+
 	if (!xflag && (len == 0 || matchall)) {
 		matchall = 1;
 		return;



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