PERFORCE change 145609 for review
Gabor Kovesdan
gabor at FreeBSD.org
Tue Jul 22 13:56:03 UTC 2008
http://perforce.freebsd.org/chv.cgi?CH=145609
Change 145609 by gabor at 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++;
More information about the p4-projects
mailing list