Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 22 Jul 2008 13:56:02 GMT
From:      Gabor Kovesdan <gabor@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 145609 for review
Message-ID:  <200807221356.m6MDu2Qo046970@repoman.freebsd.org>

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

Change 145609 by gabor@gabor_server on 2008/07/22 13:55:59

	- Fix checking of binary files by moving a code snippet to an
	  appropriate place, where f->binary is initialized.
	- Fix handling cases, where binbehave == BINFILE_TEXT.

Affected files ...

.. //depot/projects/soc2008/gabor_textproc/grep/file.c#21 edit
.. //depot/projects/soc2008/gabor_textproc/grep/util.c#65 edit

Differences ...

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

@@ -116,30 +116,36 @@
 char *
 grep_fgetln(struct file *f, size_t *len)
 {
-	int		 i;
+	int		 i = 0;
 	char		 ch;
 	size_t		 size;
 	wchar_t		 wbinbuf[BUFSIZ];
 	const char	*src = binbuf;
 	mbstate_t	 mbs;
 
-	if ((binbufptr == NULL) && (binbehave != BINFILE_TEXT)) {
-		for (i = 0; i < (BUFSIZ * sizeof(wint_t)); i++) {
-			if (grep_feof(f))
-				break;
-			ch = grep_fgetc(f);
-			binbuf[i] = ch;
+	if (binbufptr == NULL) {
+		if (binbehave != BINFILE_TEXT) {
+			for (; i < (BUFSIZ * sizeof(wint_t)); i++) {
+				if (grep_feof(f))
+					break;
+				ch = grep_fgetc(f);
+				binbuf[i] = ch;
+			}
+			binbufsiz = i;
+			binbufptr = binbuf;
+
+			size = mbsnrtowcs(wbinbuf, &src, BUFSIZ * sizeof(wint_t), BUFSIZ - 1, &mbs);
+			f->binary = 0;
+			for (; size > 0; size--)
+				if (iswbinary(wbinbuf[size])) {
+					f->binary = 1;
+					break;
+				}
+			
+		} else {
+			binbufsiz = i;
+			binbufptr = binbuf;
 		}
-		binbufsiz = i;
-		binbufptr = binbuf;
-
-		size = mbsnrtowcs(wbinbuf, &src, BUFSIZ * sizeof(wint_t), BUFSIZ - 1, &mbs);
-		f->binary = 0;
-		for (; size > 0; size--)
-			if (iswbinary(wbinbuf[size])) {
-				f->binary = 1;
-				break;
-			}
 	}
 
 	for (i = 0; ; i++) {

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

@@ -163,11 +163,6 @@
 		return (0);
 	}
 
-	if (f->binary && binbehave == BINFILE_SKIP) {
-		grep_close(f);
-		return (0);
-	}
-
 	ln.file = fn;
 	ln.line_no = 0;
 	ln.len = 0;
@@ -185,6 +180,11 @@
 			--ln.len;
 		ln.line_no++;
 
+		if (f->binary && binbehave == BINFILE_SKIP) {
+			grep_close(f);
+			return (0);
+		}
+
 		if ((t = procline(&ln, f->binary)) == 0 && Bflag > 0) {
 			enqueue(&ln);
 			linesqueued++;



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