1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
From fe8fe654371824f9121e248a30204bfad7433aba Mon Sep 17 00:00:00 2001
From: jvdelisle <jvdelisle@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Sat, 30 Apr 2011 15:24:57 +0000
Subject: [PATCH] 2011-04-30 Jerry DeLisle <jvdelisle@gcc.gnu.org>
Backport from mainline:
PR libgfortran/48030
* io/read.c (read_x): Re-implement using fbuf_getc.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_6-branch@173218 138bc75d-0d04-0410-961f-82ee72b054a4
index 50b1b40..4eda4a2 100644
--- a/libgfortran/io/read.c
+++ b/libgfortran/io/read.c
@@ -1117,8 +1117,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)
@@ -1131,7 +1130,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;
@@ -1140,55 +1139,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;
--
1.7.0.4
|