PERFORCE change 143830 for review
    Gabor Kovesdan 
    gabor at FreeBSD.org
       
    Fri Jun 20 18:33:37 UTC 2008
    
    
  
http://perforce.freebsd.org/chv.cgi?CH=143830
Change 143830 by gabor at 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);
 
    
    
More information about the p4-projects
mailing list