This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Incorrect DOS line ending conversion for cygwin build of perl


At 09:37 PM 10/2/02 +0200, Gerrit P. Haase wrote:
>Hallo Bertie,
>
>Am Mittwoch, 2. Oktober 2002 um 15:33 schriebst du:
>
>> I note that the cygwin build of perl does not correctly translate DOS \r\n
>> line endings into \n when opening files in text mode, this causes all sorts
>> of grief in perl scripts which search for things like fred$ in DOS text
>> files. 
>
>> After a bit of digging around in perl source it turns out that the problem
>> is in the function str_gets() in x2p/str.c, this code uses the FILE *fp->_p
>> variable to read directly from the FILE buffer, but alas cygwin only does
>> the \r\n -> \n conversion when serving up the contents of the _p buffer (
>> in fread, fgets, fgetc etc ), not before, so reading the _p buffer directly
>> circumvents the translation.
>
>> There is a perl variable USE_STDIO_PTR which can be undefined to stop perl
>> from using the FILE _p variable. I have built a cygwin version of perl with
>> this undefined and the line ending conversion now works fine. 
>
>> You might consider this to be a bug in the perl build system (USE_STDIO_PTR
>> should be undefined by default for cygwin builds), however at the very
>> least cygwin should ship a version of perl which has been built correctly.
>
>> Alternatively cygwin could be altered to do the line ending conversion
>> before putting data into FILE *fp->_p, I imagine this might cause slight
>> upheaval though.
>
>Which version of perl do you use?
>Have you tried to build perl with -UUSE_STDIO_PTR?
>Does it work as expected by you?

Here is a transcript demonstrating bad line ending conversion, it uses a
version of perl recently downloaded from cygwin, presumably it was built
with USE_STDIO_PTR defined:

----------------------------------------------------------------------------
---------
/test$ echo fred > fred.txt && cat -vet fred.txt && perl -pe
's,fred$,tom,;' fred.txt
fred^M$
fred
/test$ perl -v

This is perl, v5.6.1 built for cygwin-multi

Copyright 1987-2001, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'.  If you have access to the
Internet, point your browser at http://www.perl.com/, the Perl Home Page.
----------------------------------------------------------------------------
---------

Here is a transcript demonstrating correct line ending conversion, it uses
a version of perl I built with USE_STDIO_PTR undefined.

----------------------------------------------------------------------------
---------
bash-2.05a$ echo fred >fred.txt && cat -vet fred.txt && perl -pe
's,fred$,tom,'
 fred.txt
fred^M$
tom
bash-2.05a$ perl -v

This is perl, v5.6.1 built for cygwin

Copyright 1987-2001, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'.  If you have access to the
Internet, point your browser at http://www.perl.com/, the Perl Home Page.
----------------------------------------------------------------------------
---------

Bertie

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]