Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 20 Jun 2008 18:33:36 GMT
From:      Gabor Kovesdan <gabor@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 143830 for review
Message-ID:  <200806201833.m5KIXaqH062705@repoman.freebsd.org>

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

Change 143830 by gabor@gabor_server on 2008/06/20 18:32:37

	- GNU compatibility: return 2 for unbalanced parentheses if
	  -E is specified

Affected files ...

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

Differences ...

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

@@ -188,6 +188,7 @@
 add_pattern(char *pat, size_t len)
 {
 	char	*ptr, *st;
+	int	 lbr, rbr;
 
 /* Workaround for our libc-regex library to match GNU behaviour.
    Our library rejects '|' with empty subexpressions.  Just cut out
@@ -237,6 +238,25 @@
 		strlcpy(&(ptr[1]), &(ptr[2]), strlen(ptr));
 		st = ptr;
 	}
+	if (Eflag) {
+		st = pat;
+		lbr = 0;
+		while ((ptr = strstr(st, "(")) != NULL) {
+			if (strstr(st, "\\(") != (ptr - 1))
+				lbr++;
+			st = &(ptr[1]);
+		}
+		st = pat;
+		rbr = 0;
+		while ((ptr = strstr(st, ")")) != NULL) {
+			if (strstr(st, "\\)") != (ptr - 1))
+				rbr++;
+			st = &(ptr[1]);
+		}
+		if (lbr != rbr) {
+			errx(2, "parentheses not balanced");
+		}
+	}
 
 //	printf("PAT %s\n", pat);
 



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