Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 9 Aug 2008 13:21:57 GMT
From:      Gabor Kovesdan <gabor@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 146986 for review
Message-ID:  <200808091321.m79DLvqR083275@repoman.freebsd.org>

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

Change 146986 by gabor@gabor_server on 2008/08/09 13:21:56

	- Partly revert the previous change to the binary file detecting,
	  in some case it was more accurate, but in some cases it did
	  not work well

Affected files ...

.. //depot/projects/soc2008/gabor_textproc/grep/file.c#32 edit

Differences ...

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

@@ -119,20 +119,32 @@
 {
 	int		 i = 0;
 	char		 ch;
+	size_t		 size;
+	wchar_t		 wbinbuf[BUFSIZ];
+	const char	*src = binbuf;
+	mbstate_t	 mbs;
 
 	/* Fill in the buffer if it is empty. */
 	if (binbufptr == NULL) {
 		/* Only pre-read to the buffer if we need the binary check. */
 		if (binbehave != BINFILE_TEXT) {
-			for (; i < sizeof(binbuf) && !grep_feof(f); i++) {
+			for (; i < sizeof(wbinbuf) && !grep_feof(f); i++) {
 				ch = grep_fgetc(f);
-				if ((unsigned char)ch == 0)
-					f->binary = 1;
 				if (ch != EOF)
 					binbuf[i] = ch;
 				else
 					break;
 			}
+			/* Convert at most (BUFSIZ * sizeof(wint_t)) characters or
+				(BUFSIZ - 1) bytes to wide character string. */
+			size = mbsnrtowcs(wbinbuf, &src, sizeof(wbinbuf), BUFSIZ - 1, &mbs);
+			f->binary = 0;
+			for (; size > 0; size--)
+				if (iswbinary(wbinbuf[size])) {
+					f->binary = 1;
+					break;
+				}
+			
 		}
 		binbufsiz = i;
 		binbufptr = binbuf;



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