Bug 24919 - [4.0] CRLF support in libgfortran
Summary: [4.0] CRLF support in libgfortran
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libfortran (show other bugs)
Version: unknown
: P3 normal
Target Milestone: 4.1.0
Assignee: Francois-Xavier Coudert
URL: http://gcc.gnu.org/ml/fortran/2005-11...
Keywords: patch
: 24918 (view as bug list)
Depends on:
Blocks: 19292
  Show dependency treegraph
 
Reported: 2005-11-17 19:49 UTC by Ray Nachlinger
Modified: 2005-12-02 15:47 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-11-17 20:31:40


Attachments
dos (253 bytes, text/plain)
2005-11-17 20:28 UTC, Ray Nachlinger
Details
Almost complete patch for handling CRLF correctly (1.38 KB, patch)
2005-11-23 12:57 UTC, Francois-Xavier Coudert
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ray Nachlinger 2005-11-17 19:49:55 UTC
When reading a "dos" file, gfortran returns two records for each line
in the file: the real record and a null one. In other words it is treating
the carriage return as a newline instead of the pair carriage return/newline
as the newline.
Here is an example:


      integer ios
      character buf*(50)
c
      open(10,file='dos',iostat=ios)
      print *,' open ios ',ios
 1000 read(10,'(a)',iostat=ios) buf
      if(ios .ne.0) go to 9000
      print '(a,a,a)',' read <',buf,'>'
      go to 1000
c
 9000 end
Comment 1 Andrew Pinski 2005-11-17 20:11:19 UTC
*** Bug 24918 has been marked as a duplicate of this bug. ***
Comment 2 Andrew Pinski 2005-11-17 20:13:43 UTC
First can you try 4.0.2 or a snapshot of 4.0.3? Second can you attach the dos file?
Comment 3 Ray Nachlinger 2005-11-17 20:28:35 UTC
Subject: Re:  GFORTRAN input and carriage returns

On Thu, 17 Nov 2005, pinskia at gcc dot gnu dot org wrote:

> 
> 
> ------- Comment #2 from pinskia at gcc dot gnu dot org  2005-11-17 20:13 -------
> First can you try 4.0.2 or a snapshot of 4.0.3? Second can you attach the dos
> file?
> 
> 
> -- 
> 
> pinskia at gcc dot gnu dot org changed:
> 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>                  CC|                            |pinskia at gcc dot gnu dot
>                    |                            |org
> 
> 

  Sorry, but there was no good way to do that with the form.
Comment 4 Ray Nachlinger 2005-11-17 20:28:35 UTC
Created attachment 10268 [details]
dos
Comment 5 Andrew Pinski 2005-11-17 20:31:40 UTC
Confirmed on the mainline.
Comment 6 Jerry DeLisle 2005-11-18 00:47:02 UTC
This is near stuff I am working on so I will work it.
Comment 7 Francois-Xavier Coudert 2005-11-18 13:38:34 UTC
(In reply to comment #6)
> This is near stuff I am working on so I will work it.

This is amazing because I thought I add it fixed some time ago now. I will look into it too in the train tonight ;-)
Comment 8 Ray Nachlinger 2005-11-18 19:32:44 UTC
(In reply to comment #3)
> Subject: Re:  GFORTRAN input and carriage returns
> 
> On Thu, 17 Nov 2005, pinskia at gcc dot gnu dot org wrote:
> 
> > 
> > 
> > ------- Comment #2 from pinskia at gcc dot gnu dot org  2005-11-17 20:13 -------
> > First can you try 4.0.2 or a snapshot of 4.0.3? Second can you attach the dos
> > file?


     Tried yesterday's snapshot of 4.1 and it still does not work.
> > 
> > 
> > -- 
> > 
> > pinskia at gcc dot gnu dot org changed:
> > 
> >            What    |Removed                     |Added
> > ----------------------------------------------------------------------------
> >                  CC|                            |pinskia at gcc dot gnu dot
> >                    |                            |org
> > 
> > 
> 
>   Sorry, but there was no good way to do that with the form.
> 

Comment 9 Francois-Xavier Coudert 2005-11-19 00:58:46 UTC
(In reply to comment #8)
> Tried yesterday's snapshot of 4.1 and it still does not work.

OK, I'm on it. Looks like someone forgot about CRLF systems :)

I'll try to submit a first patch tomorrow...
Comment 10 Ray Nachlinger 2005-11-21 13:52:57 UTC
(In reply to comment #9)
> (In reply to comment #8)
> > Tried yesterday's snapshot of 4.1 and it still does not work.
> 
> OK, I'm on it. Looks like someone forgot about CRLF systems :)
> 
> I'll try to submit a first patch tomorrow...
> 
    The following changes in transfer.c appear to fix the problem in Linux:
157c157
<   char *base, *p, *q;
---
>   char *base, *p, *q, last;
173a174
>   last    = 0;
197c198
<       if (readlen < 1 || *q == '\n' || *q == '\r')
---
>       if (readlen < 1 || *q == '\n' )
215a217,219
>           if ( last  == '\r') {
>              *length = n-1;
>           } else {
216a221
>           }
222a228
>       last = *q;

  Ray


Comment 11 Francois-Xavier Coudert 2005-11-21 14:02:06 UTC
(In reply to comment #10)
> The following changes in transfer.c appear to fix the problem in Linux:

Confirming this patch, I have something similar in my own tree. But there are some other problems with CRLF and I'll try to submit a full patch soon (a few days at most) to fix them all. Forcing HAVE_CRLF in config.h and running the testsuite appears to be a very good way to find those :)
Comment 12 Jerry DeLisle 2005-11-21 14:21:50 UTC
Subject: Re:  GFORTRAN input and carriage returns

fxcoudert at gcc dot gnu dot org wrote:
> ------- Comment #11 from fxcoudert at gcc dot gnu dot org  2005-11-21 14:02 -------
> (In reply to comment #10)
> 
>>The following changes in transfer.c appear to fix the problem in Linux:
> 
> 
> Confirming this patch, I have something similar in my own tree. But there are
> some other problems with CRLF and I'll try to submit a full patch soon (a few
> days at most) to fix them all. Forcing HAVE_CRLF in config.h and running the
> testsuite appears to be a very good way to find those :)
> 
> 
Tres bien!
Comment 13 Francois-Xavier Coudert 2005-11-22 22:59:52 UTC
(In reply to comment #10)
> The following changes in transfer.c appear to fix the problem in Linux

Well, this patch is actually not OK, since it causes regression in the handling of EOR (like eor_handling_3.f90 and eor_handling_5.f90 from the testsuite). I'm still working on something, but wanted to note somewhere (just in case) that this patch is not OK.
Comment 14 Francois-Xavier Coudert 2005-11-23 12:57:04 UTC
Created attachment 10325 [details]
Almost complete patch for handling CRLF correctly

Attached patch corrects the problem reported here as well as most other problems related to CRLF. There is still a slight issue with the handling of T format descriptors. When this is resolved, I'll submit the patch properly.
Comment 15 Francois-Xavier Coudert 2005-11-23 16:58:48 UTC
Complete patch submitted for review.
Comment 16 Francois-Xavier Coudert 2005-11-27 11:42:49 UTC
Subject: Bug 24919

Author: fxcoudert
Date: Sun Nov 27 11:42:46 2005
New Revision: 107563

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=107563
Log:
	PR libfortran/24919

	* io/list_read.c (eat_separator, finish_separator,
	read_character): Handle CRLF separators correctly during reads.
	(nml_query): Use the HAVE_CRLF macro to print adequate newlines.
	* io/io.h (st_parameter_dt): Add comment about the possible
	values for sf_seen_eor.
	* io/unix.c (tempfile, regular_file): HAVE_CRLF doesn't imply
	that O_BINARY is defined, so we add that condition.
	(stream_at_bof): Fix typo in comment.
	* io/transfer.c (read_sf): Handle correctly CRLF, setting
	sf_seen_eor value to 2 instead of 1.
	(formatted_transfer_scalar): Use the sf_seen_eor value to
	handle CRLF the right way.
	* io/write.c (nml_write_obj, namelist_write): Use CRLF as newline
	when HAVE_CRLF is defined.

	* gfortran.dg/ftell_1.f90: Modify testcase so that it doesn't
	fail on CRLF platforms.
	* gfortran.dg/ftell_2.f90: Likewise.

Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/ftell_1.f90
    trunk/gcc/testsuite/gfortran.dg/ftell_2.f90
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/io/io.h
    trunk/libgfortran/io/list_read.c
    trunk/libgfortran/io/transfer.c
    trunk/libgfortran/io/unix.c
    trunk/libgfortran/io/write.c

Comment 17 Francois-Xavier Coudert 2005-11-27 12:25:35 UTC
Will wait a bit before backporting to 4.1.
Comment 18 Francois-Xavier Coudert 2005-12-02 15:35:53 UTC
Subject: Bug 24919

Author: fxcoudert
Date: Fri Dec  2 15:35:47 2005
New Revision: 107895

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=107895
Log:
	PR libfortran/24919
	* io/list_read.c (eat_separator, finish_separator,
	read_character): Handle CRLF separators correctly during reads.
	(nml_query): Use the HAVE_CRLF macro to print adequate newlines.
	* io/io.h (st_parameter_dt): Add comment about the possible
	values for sf_seen_eor.
	* io/unix.c (tempfile, regular_file): HAVE_CRLF doesn't imply
	that O_BINARY is defined, so we add that condition.
	(stream_at_bof): Fix typo in comment.
	* io/transfer.c (read_sf): Handle correctly CRLF, setting
	sf_seen_eor value to 2 instead of 1.
	(formatted_transfer_scalar): Use the sf_seen_eor value to
	handle CRLF the right way.
	* io/write.c (nml_write_obj, namelist_write): Use CRLF as newline
	when HAVE_CRLF is defined.


Modified:
    branches/gcc-4_1-branch/libgfortran/ChangeLog
    branches/gcc-4_1-branch/libgfortran/io/io.h
    branches/gcc-4_1-branch/libgfortran/io/list_read.c
    branches/gcc-4_1-branch/libgfortran/io/transfer.c
    branches/gcc-4_1-branch/libgfortran/io/unix.c
    branches/gcc-4_1-branch/libgfortran/io/write.c

Comment 19 Francois-Xavier Coudert 2005-12-02 15:47:12 UTC
Backported to 4.1. Will not fix on 4.0 since 4.1.0 will be released soon and mingw does not intend to use gcc-4.0.x