X-Recipient: archive-cygwin@delorie.com
X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 	tests=BAYES_00,SPF_PASS
X-Spam-Check-By: sourceware.org
Message-ID: <4ACCB085.3070304@freesbee.fr>
Date: Wed, 07 Oct 2009 17:15:17 +0200
From: =?ISO-8859-1?Q?Vincent_Rivi=E8re?= <vincent.riviere@freesbee.fr>
User-Agent: Thunderbird 2.0.0.23 (Windows/20090812)
MIME-Version: 1.0
To: cygwin@cygwin.com
Subject: Re: Additional carriage return added by cygwin commands to DOS text  files
References: <loom.20091007T161054-245@post.gmane.org>
In-Reply-To: <loom.20091007T161054-245@post.gmane.org>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
X-IsSubscribed: yes
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com

ttjqryfbndgdx wrote:
> I know it's a common issue, but I didn't find a solution to my problem in the
> archive.
> 
> I have a "dos" file (lines ends with carriage return+line feed : 0d0a in Hex) :
> bash-3.2$ xxd test1
> 0000000: 6161 610d 0a62 6262 0d0a                 aaa..bbb..
> 
> If I apply a cygwin command to this file, I get an additional carriage return :
> bash-3.2$ grep -E 'a|b' test1 > test2
> bash-3.2$ xxd test2
> 0000000: 6161 610d 0d0a 6262 620d 0d0a            aaa...bbb...
> 
> I chose dos mode when installing cygwin.
> My filesystems are mounted "textmode"

It seems that grep always opens the file in binary mode, so it ignores 
the Cygwin mount mode.

http://cvs.savannah.gnu.org/viewvc/grep/grep/src/grep.c?view=markup

       while ((desc = open (file, O_RDONLY)) < 0 && errno == EINTR)
	continue;

Moreover, I see in the same source that grep has an "undossify" feature:

#if defined(HAVE_DOS_FILE_CONTENTS)
   if (fillsize)
     fillsize = undossify_input (readbuf, fillsize);
#endif

But it may be disabled in Cygwin.

I experienced the same issue with the "cat" command, and unfortunately I 
didn't find any transparent solution :-(

Cygwin's text mode handling is great, but some UNIX utilities like cat 
and grep are designed to act on either binary or text files, so they 
always open the files in binary mode, and we get that additional CR issue.

-- 
Vincent Rivière

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

