Commit 09861cbe by Jerry DeLisle

re PR fortran/29277 (Formated stream output: Translate "\n" / achar(10) into…

re PR fortran/29277 (Formated stream output: Translate "\n" / achar(10) into "\r\n" on some platforms)

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.

From-SVN: r117846
parent 6bc222ff
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.
2006-10-13 Steven G. Kargl <kargl@gcc.gnu.org> 2006-10-13 Steven G. Kargl <kargl@gcc.gnu.org>
* m4/spacing.m4: Use scalbn[f,l] if ldexp[f,l] is unavailable. * m4/spacing.m4: Use scalbn[f,l] if ldexp[f,l] is unavailable.
......
...@@ -187,6 +187,9 @@ next_char (st_parameter_dt *dtp) ...@@ -187,6 +187,9 @@ next_char (st_parameter_dt *dtp)
length = 1; length = 1;
p = salloc_r (dtp->u.p.current_unit->s, &length); p = salloc_r (dtp->u.p.current_unit->s, &length);
if (is_stream_io (dtp))
dtp->u.p.current_unit->strm_pos++;
if (is_internal_unit(dtp)) if (is_internal_unit(dtp))
{ {
...@@ -294,10 +297,7 @@ eat_separator (st_parameter_dt *dtp) ...@@ -294,10 +297,7 @@ eat_separator (st_parameter_dt *dtp)
if (n == '\n') if (n == '\n')
dtp->u.p.at_eol = 1; dtp->u.p.at_eol = 1;
else else
{ unget_char (dtp, n);
unget_char (dtp, n);
unget_char (dtp, c);
}
break; break;
case '\n': case '\n':
......
...@@ -324,6 +324,13 @@ read_block (st_parameter_dt *dtp, int *length) ...@@ -324,6 +324,13 @@ read_block (st_parameter_dt *dtp, int *length)
return NULL; return NULL;
} }
if (dtp->u.p.current_unit->flags.form == FORM_FORMATTED)
{
source = read_sf (dtp, length, 0);
dtp->u.p.current_unit->strm_pos +=
(gfc_offset) (*length + dtp->u.p.sf_seen_eor);
return source;
}
nread = *length; nread = *length;
source = salloc_r (dtp->u.p.current_unit->s, &nread); source = salloc_r (dtp->u.p.current_unit->s, &nread);
...@@ -1921,8 +1928,7 @@ next_record_r (st_parameter_dt *dtp) ...@@ -1921,8 +1928,7 @@ next_record_r (st_parameter_dt *dtp)
switch (current_mode (dtp)) switch (current_mode (dtp))
{ {
/* No records in STREAM I/O. */ /* No records in unformatted STREAM I/O. */
case FORMATTED_STREAM:
case UNFORMATTED_STREAM: case UNFORMATTED_STREAM:
return; return;
...@@ -1970,6 +1976,7 @@ next_record_r (st_parameter_dt *dtp) ...@@ -1970,6 +1976,7 @@ next_record_r (st_parameter_dt *dtp)
} }
break; break;
case FORMATTED_STREAM:
case FORMATTED_SEQUENTIAL: case FORMATTED_SEQUENTIAL:
length = 1; length = 1;
/* sf_read has already terminated input because of an '\n' */ /* sf_read has already terminated input because of an '\n' */
...@@ -2019,6 +2026,9 @@ next_record_r (st_parameter_dt *dtp) ...@@ -2019,6 +2026,9 @@ next_record_r (st_parameter_dt *dtp)
dtp->u.p.current_unit->endfile = AT_ENDFILE; dtp->u.p.current_unit->endfile = AT_ENDFILE;
break; break;
} }
if (is_stream_io (dtp))
dtp->u.p.current_unit->strm_pos++;
} }
while (*p != '\n'); while (*p != '\n');
...@@ -2116,8 +2126,7 @@ next_record_w (st_parameter_dt *dtp, int done) ...@@ -2116,8 +2126,7 @@ next_record_w (st_parameter_dt *dtp, int done)
switch (current_mode (dtp)) switch (current_mode (dtp))
{ {
/* No records in STREAM I/O. */ /* No records in unformatted STREAM I/O. */
case FORMATTED_STREAM:
case UNFORMATTED_STREAM: case UNFORMATTED_STREAM:
return; return;
...@@ -2168,6 +2177,7 @@ next_record_w (st_parameter_dt *dtp, int done) ...@@ -2168,6 +2177,7 @@ next_record_w (st_parameter_dt *dtp, int done)
break; break;
case FORMATTED_STREAM:
case FORMATTED_SEQUENTIAL: case FORMATTED_SEQUENTIAL:
if (is_internal_unit (dtp)) if (is_internal_unit (dtp))
...@@ -2241,8 +2251,6 @@ next_record_w (st_parameter_dt *dtp, int done) ...@@ -2241,8 +2251,6 @@ next_record_w (st_parameter_dt *dtp, int done)
} }
else else
{ {
if (dtp->u.p.current_unit->bytes_left == 0)
break;
/* If this is the last call to next_record move to the farthest /* If this is the last call to next_record move to the farthest
position reached in preparation for completing the record. position reached in preparation for completing the record.
...@@ -2266,6 +2274,9 @@ next_record_w (st_parameter_dt *dtp, int done) ...@@ -2266,6 +2274,9 @@ next_record_w (st_parameter_dt *dtp, int done)
#endif #endif
if (swrite (dtp->u.p.current_unit->s, &crlf[2-len], &len) != 0) if (swrite (dtp->u.p.current_unit->s, &crlf[2-len], &len) != 0)
goto io_error; goto io_error;
if (is_stream_io (dtp))
dtp->u.p.current_unit->strm_pos += len;
} }
break; break;
...@@ -2284,9 +2295,6 @@ next_record_w (st_parameter_dt *dtp, int done) ...@@ -2284,9 +2295,6 @@ next_record_w (st_parameter_dt *dtp, int done)
void void
next_record (st_parameter_dt *dtp, int done) next_record (st_parameter_dt *dtp, int done)
{ {
if (is_stream_io (dtp))
return;
gfc_offset fp; /* File position. */ gfc_offset fp; /* File position. */
dtp->u.p.current_unit->read_bad = 0; dtp->u.p.current_unit->read_bad = 0;
...@@ -2296,18 +2304,22 @@ next_record (st_parameter_dt *dtp, int done) ...@@ -2296,18 +2304,22 @@ next_record (st_parameter_dt *dtp, int done)
else else
next_record_w (dtp, done); next_record_w (dtp, done);
/* keep position up to date for INQUIRE */ if (!is_stream_io (dtp))
dtp->u.p.current_unit->flags.position = POSITION_ASIS; {
dtp->u.p.current_unit->current_record = 0; /* keep position up to date for INQUIRE */
if (dtp->u.p.current_unit->flags.access == ACCESS_DIRECT) dtp->u.p.current_unit->flags.position = POSITION_ASIS;
{ dtp->u.p.current_unit->current_record = 0;
fp = file_position (dtp->u.p.current_unit->s); if (dtp->u.p.current_unit->flags.access == ACCESS_DIRECT)
/* Calculate next record, rounding up partial records. */ {
dtp->u.p.current_unit->last_record = (fp + dtp->u.p.current_unit->recl - 1) fp = file_position (dtp->u.p.current_unit->s);
/ dtp->u.p.current_unit->recl; /* Calculate next record, rounding up partial records. */
} dtp->u.p.current_unit->last_record =
else (fp + dtp->u.p.current_unit->recl - 1) /
dtp->u.p.current_unit->last_record++; dtp->u.p.current_unit->recl;
}
else
dtp->u.p.current_unit->last_record++;
}
if (!done) if (!done)
pre_position (dtp); pre_position (dtp);
...@@ -2373,7 +2385,11 @@ finalize_transfer (st_parameter_dt *dtp) ...@@ -2373,7 +2385,11 @@ finalize_transfer (st_parameter_dt *dtp)
next_record (dtp, 1); next_record (dtp, 1);
} }
else else
flush (dtp->u.p.current_unit->s); {
if (dtp->u.p.current_unit->flags.form == FORM_FORMATTED)
next_record (dtp, 1);
flush (dtp->u.p.current_unit->s);
}
sfree (dtp->u.p.current_unit->s); sfree (dtp->u.p.current_unit->s);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment