From owner-p4-projects@FreeBSD.ORG Tue Jul 22 13:56:03 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 9C41A106568A; Tue, 22 Jul 2008 13:56:03 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 257A61065675 for ; Tue, 22 Jul 2008 13:56:03 +0000 (UTC) (envelope-from gabor@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 1441D8FC24 for ; Tue, 22 Jul 2008 13:56:03 +0000 (UTC) (envelope-from gabor@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m6MDu24T046972 for ; Tue, 22 Jul 2008 13:56:02 GMT (envelope-from gabor@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.2/8.14.1/Submit) id m6MDu2Qo046970 for perforce@freebsd.org; Tue, 22 Jul 2008 13:56:02 GMT (envelope-from gabor@freebsd.org) Date: Tue, 22 Jul 2008 13:56:02 GMT Message-Id: <200807221356.m6MDu2Qo046970@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to gabor@freebsd.org using -f From: Gabor Kovesdan To: Perforce Change Reviews Cc: Subject: PERFORCE change 145609 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Jul 2008 13:56:03 -0000 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++;