PERFORCE change 149702 for review
Gabor Kovesdan
gabor at FreeBSD.org
Sat Sep 13 11:48:52 UTC 2008
http://perforce.freebsd.org/chv.cgi?CH=149702
Change 149702 by gabor at 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);
}
More information about the p4-projects
mailing list