Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 13 Sep 2008 11:48:51 GMT
From:      Gabor Kovesdan <gabor@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 149702 for review
Message-ID:  <200809131148.m8DBmpp6006186@repoman.freebsd.org>

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

Change 149702 by gabor@gabor_server on 2008/09/13 11:48:42

	- Make the -i fixed string search wide char compliant
	
	Reported by:	ache

Affected files ...

.. //depot/projects/soc2008/gabor_textproc/grep/fastgrep.c#10 edit

Differences ...

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

@@ -40,10 +40,11 @@
 __FBSDID("$FreeBSD$");
 #endif /* not lint */
 
-#include <ctype.h>
 #include <limits.h>
 #include <stdlib.h>
 #include <string.h>
+#include <wchar.h>
+#include <wctype.h>
 
 #include "grep.h"
 
@@ -281,14 +282,39 @@
 grep_cmp(const unsigned char *pattern, const unsigned char *data, size_t len)
 {
 	int	 i;
+	size_t	 size;
+	wchar_t	*wdata, *wpat;
+
+	if (iflag) {
+		if ((size = mbstowcs(NULL, data, 0)) == -1)
+			return (-1);
+
+		wdata = grep_malloc(size * sizeof(wint_t));
+
+		if (mbstowcs(wdata, data, size) == -1)
+			return (-1);
+
+		if ((size = mbstowcs(NULL, pattern, 0)) == -1)
+			return (-1);
 
-	for (i = 0; i < len; i++) {
-		if (((pattern[i] == data[i]) || ((grepbehave != GREP_FIXED) && pattern[i] == '.'))
-		    || (iflag && toupper(pattern[i]) == toupper(data[i])))
-			continue;
-		return (i);
+		wpat = grep_malloc(size * sizeof(wint_t));
+
+		if (mbstowcs(wpat, pattern, size) == -1)
+			return (-1);
+		for (i = 0; i < len; i++) {
+			if ((towlower(wpat[i]) == towlower(wdata[i])) || ((grepbehave != GREP_FIXED) && wpat[i] == L'.'))
+				continue;
+			free(wpat);
+			free(wdata);
+				return (i);
+		}
+	} else {
+		for (i = 0; i < len; i++) {
+			if ((pattern[i] == data[i]) || ((grepbehave != GREP_FIXED) && pattern[i] == '.'))
+				continue;
+			return (i);
+		}
 	}
-
 	return (-1);
 }
 



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