+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>
* m4/spacing.m4: Use scalbn[f,l] if ldexp[f,l] is unavailable.
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;
source = salloc_r (dtp->u.p.current_unit->s, &nread);
switch (current_mode (dtp))
{
- /* No records in STREAM I/O. */
- case FORMATTED_STREAM:
+ /* No records in unformatted STREAM I/O. */
case UNFORMATTED_STREAM:
return;
}
break;
+ case FORMATTED_STREAM:
case FORMATTED_SEQUENTIAL:
length = 1;
/* sf_read has already terminated input because of an '\n' */
dtp->u.p.current_unit->endfile = AT_ENDFILE;
break;
}
+
+ if (is_stream_io (dtp))
+ dtp->u.p.current_unit->strm_pos++;
}
while (*p != '\n');
switch (current_mode (dtp))
{
- /* No records in STREAM I/O. */
- case FORMATTED_STREAM:
+ /* No records in unformatted STREAM I/O. */
case UNFORMATTED_STREAM:
return;
break;
+ case FORMATTED_STREAM:
case FORMATTED_SEQUENTIAL:
if (is_internal_unit (dtp))
}
else
{
- if (dtp->u.p.current_unit->bytes_left == 0)
- break;
/* If this is the last call to next_record move to the farthest
position reached in preparation for completing the record.
#endif
if (swrite (dtp->u.p.current_unit->s, &crlf[2-len], &len) != 0)
goto io_error;
+
+ if (is_stream_io (dtp))
+ dtp->u.p.current_unit->strm_pos += len;
}
break;
void
next_record (st_parameter_dt *dtp, int done)
{
- if (is_stream_io (dtp))
- return;
-
gfc_offset fp; /* File position. */
dtp->u.p.current_unit->read_bad = 0;
else
next_record_w (dtp, done);
- /* keep position up to date for INQUIRE */
- dtp->u.p.current_unit->flags.position = POSITION_ASIS;
- dtp->u.p.current_unit->current_record = 0;
- if (dtp->u.p.current_unit->flags.access == ACCESS_DIRECT)
- {
- fp = file_position (dtp->u.p.current_unit->s);
- /* Calculate next record, rounding up partial records. */
- dtp->u.p.current_unit->last_record = (fp + dtp->u.p.current_unit->recl - 1)
- / dtp->u.p.current_unit->recl;
- }
- else
- dtp->u.p.current_unit->last_record++;
+ if (!is_stream_io (dtp))
+ {
+ /* keep position up to date for INQUIRE */
+ dtp->u.p.current_unit->flags.position = POSITION_ASIS;
+ dtp->u.p.current_unit->current_record = 0;
+ if (dtp->u.p.current_unit->flags.access == ACCESS_DIRECT)
+ {
+ fp = file_position (dtp->u.p.current_unit->s);
+ /* Calculate next record, rounding up partial records. */
+ dtp->u.p.current_unit->last_record =
+ (fp + dtp->u.p.current_unit->recl - 1) /
+ dtp->u.p.current_unit->recl;
+ }
+ else
+ dtp->u.p.current_unit->last_record++;
+ }
if (!done)
pre_position (dtp);
next_record (dtp, 1);
}
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);
}