diff options
author | Jerry DeLisle <jvdelisle@gcc.gnu.org> | 2011-03-24 01:48:57 +0000 |
---|---|---|
committer | Jerry DeLisle <jvdelisle@gcc.gnu.org> | 2011-03-24 01:48:57 +0000 |
commit | 27deda791be9fff34b41cbb2525b69879da36ee0 (patch) | |
tree | 3bfddd974381485ec49aa6ceb5bdc05d2a0427ff /libgfortran/io | |
parent | fd68e6ba7254ebe7feeeafe1fd6686b2ada8eeff (diff) | |
download | gcc-27deda791be9fff34b41cbb2525b69879da36ee0.zip gcc-27deda791be9fff34b41cbb2525b69879da36ee0.tar.gz gcc-27deda791be9fff34b41cbb2525b69879da36ee0.tar.bz2 |
re PR libfortran/48030 (Implement read_x using fbuf_getc)
2011-03-23 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR libgfortran/48030
* io/read.c (read_x): Re-implement using fbuf_getc.
From-SVN: r171378
Diffstat (limited to 'libgfortran/io')
-rw-r--r-- | libgfortran/io/read.c | 53 |
1 files changed, 17 insertions, 36 deletions
diff --git a/libgfortran/io/read.c b/libgfortran/io/read.c index d8d2a81..3ee5717 100644 --- a/libgfortran/io/read.c +++ b/libgfortran/io/read.c @@ -1186,8 +1186,7 @@ bad_float: void read_x (st_parameter_dt *dtp, int n) { - int length; - char *p, q; + int length, q, q2; if ((dtp->u.p.current_unit->pad_status == PAD_NO || is_internal_unit (dtp)) && dtp->u.p.current_unit->bytes_left < n) @@ -1200,7 +1199,7 @@ read_x (st_parameter_dt *dtp, int n) if (is_internal_unit (dtp)) { - p = mem_alloc_r (dtp->u.p.current_unit->s, &length); + mem_alloc_r (dtp->u.p.current_unit->s, &length); if (unlikely (length < n)) n = length; goto done; @@ -1209,55 +1208,37 @@ read_x (st_parameter_dt *dtp, int n) if (dtp->u.p.sf_seen_eor) return; - p = fbuf_read (dtp->u.p.current_unit, &length); - if (p == NULL) - { - hit_eof (dtp); - return; - } - - if (length == 0 && dtp->u.p.item_count == 1) - { - if (dtp->u.p.current_unit->pad_status == PAD_NO) - { - hit_eof (dtp); - return; - } - else - return; - } - n = 0; while (n < length) { - q = *p; - if (q == '\n' || q == '\r') + q = fbuf_getc (dtp->u.p.current_unit); + if (q == EOF) + break; + else if (q == '\n' || q == '\r') { /* Unexpected end of line. Set the position. */ - fbuf_seek (dtp->u.p.current_unit, n + 1 ,SEEK_CUR); dtp->u.p.sf_seen_eor = 1; + /* If we see an EOR during non-advancing I/O, we need to skip + the rest of the I/O statement. Set the corresponding flag. */ + if (dtp->u.p.advance_status == ADVANCE_NO || dtp->u.p.seen_dollar) + dtp->u.p.eor_condition = 1; + /* If we encounter a CR, it might be a CRLF. */ if (q == '\r') /* Probably a CRLF */ { - /* See if there is an LF. Use fbuf_read rather then fbuf_getc so - the position is not advanced unless it really is an LF. */ - int readlen = 1; - p = fbuf_read (dtp->u.p.current_unit, &readlen); - if (*p == '\n' && readlen == 1) - { - dtp->u.p.sf_seen_eor = 2; - fbuf_seek (dtp->u.p.current_unit, 1 ,SEEK_CUR); - } + /* See if there is an LF. */ + q2 = fbuf_getc (dtp->u.p.current_unit); + if (q2 == '\n') + dtp->u.p.sf_seen_eor = 2; + else if (q2 != EOF) /* Oops, seek back. */ + fbuf_seek (dtp->u.p.current_unit, -1, SEEK_CUR); } goto done; } n++; - p++; } - fbuf_seek (dtp->u.p.current_unit, n, SEEK_CUR); - done: if ((dtp->common.flags & IOPARM_DT_HAS_SIZE) != 0) dtp->u.p.size_used += (GFC_IO_INT) n; |