aboutsummaryrefslogtreecommitdiff
path: root/libgfortran
diff options
context:
space:
mode:
authorJerry DeLisle <jvdelisle@gcc.gnu.org>2006-10-18 23:13:33 +0000
committerJerry DeLisle <jvdelisle@gcc.gnu.org>2006-10-18 23:13:33 +0000
commit9e7fc6b946e8a9f616ce12a458017bad8357247e (patch)
treebbdfab311ddfa41a621df118efe7d19a03ba516a /libgfortran
parent1368453c6a59c0441fcf9fef79d1821a74a71565 (diff)
downloadgcc-9e7fc6b946e8a9f616ce12a458017bad8357247e.zip
gcc-9e7fc6b946e8a9f616ce12a458017bad8357247e.tar.gz
gcc-9e7fc6b946e8a9f616ce12a458017bad8357247e.tar.bz2
re PR fortran/29277 (Formated stream output: Translate "\n" / achar(10) into "\r\n" on some platforms)
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. From-SVN: r117866
Diffstat (limited to 'libgfortran')
-rw-r--r--libgfortran/ChangeLog8
-rw-r--r--libgfortran/io/write.c75
2 files changed, 75 insertions, 8 deletions
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog
index 9eacd38..9001e2c 100644
--- a/libgfortran/ChangeLog
+++ b/libgfortran/ChangeLog
@@ -1,4 +1,10 @@
-2006-10-16 Tobias Burnus <burnus@net-b.de>
+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.
+
+2006-10-18 Tobias Burnus <burnus@net-b.de>
* m4/in_pack.m4: Fixed a typo.
* m4/iforeach.m4: Fixed a typo.
diff --git a/libgfortran/io/write.c b/libgfortran/io/write.c
index 121d629..9ff4804 100644
--- a/libgfortran/io/write.c
+++ b/libgfortran/io/write.c
@@ -54,17 +54,78 @@ write_a (st_parameter_dt *dtp, const fnode *f, const char *source, int len)
wlen = f->u.string.length < 0 ? len : f->u.string.length;
- p = write_block (dtp, wlen);
- if (p == NULL)
- return;
+#ifdef HAVE_CRLF
+ /* If this is formatted STREAM IO convert any embedded line feed characters
+ to CR_LF on systems that use that sequence for newlines. See F2003
+ Standard sections 10.6.3 and 9.9 for further information. */
+ if (is_stream_io (dtp))
+ {
+ const char crlf[] = "\r\n";
+ int i, q, bytes;
+ q = bytes = 0;
+
+ /* Write out any padding if needed. */
+ if (len < wlen)
+ {
+ p = write_block (dtp, wlen - len);
+ if (p == NULL)
+ return;
+ memset (p, ' ', wlen - len);
+ }
- if (wlen < len)
- memcpy (p, source, wlen);
+ /* Scan the source string looking for '\n' and convert it if found. */
+ for (i = 0; i < wlen; i++)
+ {
+ if (source[i] == '\n')
+ {
+ /* Write out the previously scanned characters in the string. */
+ if (bytes > 0)
+ {
+ p = write_block (dtp, bytes);
+ if (p == NULL)
+ return;
+ memcpy (p, &source[q], bytes);
+ q += bytes;
+ bytes = 0;
+ }
+
+ /* Write out the CR_LF sequence. */
+ q++;
+ p = write_block (dtp, 2);
+ if (p == NULL)
+ return;
+ memcpy (p, crlf, 2);
+ }
+ else
+ bytes++;
+ }
+
+ /* Write out any remaining bytes if no LF was found. */
+ if (bytes > 0)
+ {
+ p = write_block (dtp, bytes);
+ if (p == NULL)
+ return;
+ memcpy (p, &source[q], bytes);
+ }
+ }
else
{
- memset (p, ' ', wlen - len);
- memcpy (p + wlen - len, source, len);
+#endif
+ p = write_block (dtp, wlen);
+ if (p == NULL)
+ return;
+
+ if (wlen < len)
+ memcpy (p, source, wlen);
+ else
+ {
+ memset (p, ' ', wlen - len);
+ memcpy (p + wlen - len, source, len);
+ }
+#ifdef HAVE_CRLF
}
+#endif
}
static GFC_INTEGER_LARGEST