Summary: | Formated stream output: Translate "\n" / achar(10) into "\r\n" on some platforms | ||
---|---|---|---|
Product: | gcc | Reporter: | tobias.burnus |
Component: | fortran | Assignee: | Jerry DeLisle <jvdelisle2> |
Status: | RESOLVED FIXED | ||
Severity: | enhancement | CC: | gcc-bugs |
Priority: | P3 | ||
Version: | 4.2.0 | ||
Target Milestone: | 4.2.0 | ||
Host: | Target: | ||
Build: | Known to work: | ||
Known to fail: | Last reconfirmed: | 2006-10-04 05:28:37 | |
Attachments: | Preliminaey patch for STREAM formatted read. |
Description
tobias.burnus
2006-09-28 22:39:20 UTC
Please note that with formatted stream I/O we implicitly write a /n or /r/n in the next_record_w () function in transfer.c depending on the system. I think this meets the intent. Now an issue I see is what if we want to explicitly write a /n on this system? There would be no way to do that if we translate it to /n/r. I am not sure the intent of the committee was to restrict this in this way, but allow it in the case of formatted end of record. I have not tried this, but if I write out a formatted string with one character /n I wonder if we we get /n/r/n with current gfortran. I am not agreeing or diagreeing here. You have raised a good question here. Another thought occurs to me. With formatted stream I/O the newline is handled automatically for the user. However, there is nothing to say someone would not want to use unformatted stream I/O to write human readable files. In that case, you would want the result of newline to give the /r/n or /n on the respective systems. Based on this thinking, the translation, if any, should be done for unformatted I/O and only when the NEWLINE function is explicitly used. Clealy we have a case where the standard may not be all that clear. OK, I confess I sen a note to Richard Maine to doble check on this. Brooks has it absolutely right. So, I will see what I can come up with for you. If its a requirement of the standard, it is not an enhancement. Oops. This is F2003 issue and therfore an enhancement relative to F95. Created attachment 12398 [details]
Preliminaey patch for STREAM formatted read.
There is a related problem with formatted stream read:
program stream
implicit none
character(len=50) :: r1,r2
open(10,file='test.dat',form='formatted',access='stream',status='old')
read(10,'(a)') r1
read(10,'(a)') r2
print *, ':',trim(r1),':'
print *, ':',trim(r2),':'
end program stream
I have a preliminary patch for this that I would appreciate some testing on cygwin or other CR-LF type system. This is for the read only.
I expect the test case streamio_4.f90 to fail with the preliminary patch. I have not completed the formatted stream write portion. What I need confirmed is that when reading that the file is being positioned correctly when a CR-LF is encountered. Subject: Bug number PR29277 A patch for this bug has been added to the patch tracker. The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2006-10/msg00677.html Note: I believe it may be necessary to explicitly inject a '\r' when a '\n' is embedded in a string. I am not quite set up to test this yet here. So I would much appreciate if some one can do that, while I continue to study that part. The patch submitted in comment #7 is fully test on '\n' only system. Subject: Bug 29277 Author: jvdelisle Date: Wed Oct 18 04:04:07 2006 New Revision: 117846 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117846 Log: 2006-10-17 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libgfortran/29277 * io/list_read.c (next_char): Update strm_pos. (eat_separator): Delete extra call to unget_char. * io/transfer.c (read_block): Use read_sf for formatted stream I/O. (next_record_r): Update strm_pos for formatted stream I/O and handle end-of-record correctly. (next_record_w): Ditto. (next_record): Enable next record (r/w) functions and update strm_pos. (finalize_transfer): Call next_record to finish the record. Modified: trunk/libgfortran/ChangeLog trunk/libgfortran/io/list_read.c trunk/libgfortran/io/transfer.c Subject: Bug 29277 Author: jvdelisle Date: Wed Oct 18 04:08:30 2006 New Revision: 117847 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117847 Log: 2006-10-17 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libgfortran/29277 * gfortran.dg/streamio_4.f90: Update test. * gfortran.dg/streamio_11.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/streamio_11.f90 Modified: trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gfortran.dg/streamio_4.f90 There is one final patch to go before closing this PR. I am testing it now and developing a test case. This is the part that converts LF to CR-LF for FORMATTED STREAM IO on those systems that #define HAVE_CRLF. Subject: Bug number PR29277 A patch for this bug has been added to the patch tracker. The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2006-10/msg00887.html Subject: Bug 29277 Author: jvdelisle Date: Wed Oct 18 23:13:33 2006 New Revision: 117866 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117866 Log: 2006-10-18 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libgfortran/29277 * io/write.c (write_a): Add conversion of LF to CR-LF for systems with #define HAVE_CRLF. Modified: trunk/libgfortran/ChangeLog trunk/libgfortran/io/write.c Fixed on 4.2. |