[multiple changes]

2005-07-12 Paul Thomas  <pault@gcc.gnu.org>

	PR libfortran/16435
	* transfer.c (formatted_transfer): Correct the problems
	with X- and T-editting that caused TLs followed by TRs
	to overwrite data, which caused NIST FM908.FOR to fail
	on many tests.
	(data_transfer_init): Zero X- and T-editting counters at
	the start of formatted IO.
	* write.c (write_x): Write specified number of skips with
	specified number of spaces at the end.

2005-07-12  Paul Thomas  <pault@gcc.gnu.org>

	PR libfortran/16435
	* gfortran.dg/tl_editting.f90: New.
	* gfortran.dg/g77/f77-edit-x-out.f: Remove XFAIL.

From-SVN: r102008
This commit is contained in:
Paul Thomas 2005-07-14 06:21:59 +00:00
parent 93e261acea
commit be0cc7e21c
7 changed files with 189 additions and 112 deletions

View File

@ -1,3 +1,9 @@
2005-07-12 Paul Thomas <pault@gcc.gnu.org>
PR libfortran/16435
* gfortran.dg/tl_editting.f90: New.
* gfortran.dg/g77/f77-edit-x-out.f: Remove XFAIL.
2005-07-14 Steven G. Kargl <kargls@comcast.net> 2005-07-14 Steven G. Kargl <kargls@comcast.net>
* gfortran.dg/char_array_constructor.f90: New test. * gfortran.dg/char_array_constructor.f90: New test.

View File

@ -8,5 +8,5 @@ C ( dg-output "^" }
write(*,'(I1,1X,I1,2X,I1)') 1,2,3 ! { dg-output "1 2 3(\n|\r\n|\r)" } write(*,'(I1,1X,I1,2X,I1)') 1,2,3 ! { dg-output "1 2 3(\n|\r\n|\r)" }
C Section 13.5.3 explains why there are no trailing blanks C Section 13.5.3 explains why there are no trailing blanks
write(*,'(I1,1X,I1,2X,I1,3X)') 1,2,3 ! { dg-output "1 2 3(\n|\r\n|\r)" } write(*,'(I1,1X,I1,2X,I1,3X)') 1,2,3 ! { dg-output "1 2 3(\n|\r\n|\r)" }
C { dg-output "\$" {xfail *-*-*} } gfortran PR 16435 C { dg-output "\$" }
end end

View File

@ -0,0 +1,13 @@
! { dg-do run }
! Test of fix to bug triggered by NIST fm908.for.
! Left tabbing, followed by X or T-tabbing to the right would
! cause spaces to be overwritten on output data.
! Contributed by Paul Thomas <pault@gcc.gnu.org>
program tl_editting
character*10 :: line
character*10 :: aline = "abcdefxyij"
character*2 :: bline = "gh"
character*10 :: cline = "abcdefghij"
write (line, '(a10,tl6,2x,a2)') aline, bline
if (line.ne.cline) call abort ()
end program tl_editting

View File

@ -1,3 +1,15 @@
2005-07-12 Paul Thomas <pault@gcc.gnu.org>
PR libfortran/16435
* transfer.c (formatted_transfer): Correct the problems
with X- and T-editting that caused TLs followed by TRs
to overwrite data, which caused NIST FM908.FOR to fail
on many tests.
(data_transfer_init): Zero X- and T-editting counters at
the start of formatted IO.
* write.c (write_x): Write specified number of skips with
specified number of spaces at the end.
2005-07-13 Paul Thomas <pault@gcc.gnu.org> 2005-07-13 Paul Thomas <pault@gcc.gnu.org>
* io/read.c (read_complex): Prevent X formatting during reads * io/read.c (read_complex): Prevent X formatting during reads

View File

@ -638,7 +638,7 @@ internal_proto(write_l);
extern void write_o (fnode *, const char *, int); extern void write_o (fnode *, const char *, int);
internal_proto(write_o); internal_proto(write_o);
extern void write_x (fnode *); extern void write_x (int, int);
internal_proto(write_x); internal_proto(write_x);
extern void write_z (fnode *, const char *, int); extern void write_z (fnode *, const char *, int);

View File

@ -82,6 +82,13 @@ gfc_unit *current_unit = NULL;
static int sf_seen_eor = 0; static int sf_seen_eor = 0;
static int eor_condition = 0; static int eor_condition = 0;
/* Maximum righthand column written to. */
static int max_pos;
/* Number of skips + spaces to be done for T and X-editing. */
static int skips;
/* Number of spaces to be done for T and X-editing. */
static int pending_spaces;
char scratch[SCRATCH_SIZE]; char scratch[SCRATCH_SIZE];
static char *line_buffer = NULL; static char *line_buffer = NULL;
@ -437,8 +444,9 @@ require_type (bt expected, bt actual, fnode * f)
static void static void
formatted_transfer (bt type, void *p, int len) formatted_transfer (bt type, void *p, int len)
{ {
int pos ,m ; int pos;
fnode *f; fnode *f;
format_token t;
int n; int n;
int consume_data_flag; int consume_data_flag;
@ -471,7 +479,21 @@ formatted_transfer (bt type, void *p, int len)
if (f == NULL) if (f == NULL)
return; /* No data descriptors left (already raised). */ return; /* No data descriptors left (already raised). */
switch (f->format) /* Now discharge T, TR and X movements to the right. This is delayed
until a data producing format to supress trailing spaces. */
t = f->format;
if (g.mode == WRITING && skips > 0
&& (t == FMT_I || t == FMT_B || t == FMT_O || t == FMT_Z
|| t == FMT_F || t == FMT_E || t == FMT_EN || t == FMT_ES
|| t == FMT_G || t == FMT_L || t == FMT_A || t == FMT_D
|| t == FMT_STRING))
{
write_x (skips, pending_spaces);
max_pos = current_unit->recl - current_unit->bytes_left;
skips = pending_spaces = 0;
}
switch (t)
{ {
case FMT_I: case FMT_I:
if (n == 0) if (n == 0)
@ -664,10 +686,15 @@ formatted_transfer (bt type, void *p, int len)
case FMT_X: case FMT_X:
case FMT_TR: case FMT_TR:
consume_data_flag = 0 ; consume_data_flag = 0 ;
pos = current_unit->recl - current_unit->bytes_left + f->u.n;
skips = f->u.n;
pending_spaces = pos - max_pos;
/* Writes occur just before the switch on f->format, above, so that
trailing blanks are suppressed. */
if (g.mode == READING) if (g.mode == READING)
read_x (f); read_x (f);
else
write_x (f);
break; break;
@ -681,28 +708,33 @@ formatted_transfer (bt type, void *p, int len)
pos = f->u.n - 1; pos = f->u.n - 1;
} }
if (pos < 0 || pos >= current_unit->recl ) /* Standard 10.6.1.1: excessive left tabbing is reset to the
{ left tab limit. We do not check if the position has gone
generate_error (ERROR_EOR, "T or TL edit position error"); beyond the end of record because a subsequent tab could
break ; bring us back again. */
} pos = pos < 0 ? 0 : pos;
m = pos - (current_unit->recl - current_unit->bytes_left);
if (m == 0) skips = skips + pos - (current_unit->recl - current_unit->bytes_left);
pending_spaces = pending_spaces + pos - max_pos;
if (skips == 0)
break; break;
if (m > 0) /* Writes occur just before the switch on f->format, above, so that
trailing blanks are suppressed. */
if (skips > 0)
{ {
f->u.n = m;
if (g.mode == READING) if (g.mode == READING)
read_x (f);
else
write_x (f);
}
if (m < 0)
{ {
move_pos_offset (current_unit->s,m); f->u.n = skips;
current_unit->bytes_left -= m; read_x (f);
}
}
if (skips < 0)
{
move_pos_offset (current_unit->s, skips);
current_unit->bytes_left -= skips;
skips = pending_spaces = 0;
} }
break; break;
@ -778,6 +810,13 @@ formatted_transfer (bt type, void *p, int len)
n--; n--;
p = ((char *) p) + len; p = ((char *) p) + len;
} }
if (g.mode == READING)
skips = 0;
pos = current_unit->recl - current_unit->bytes_left;
max_pos = (max_pos > pos) ? max_pos : pos;
} }
return; return;
@ -1185,6 +1224,10 @@ data_transfer_init (int read_flag)
current_unit->read_bad = 1; current_unit->read_bad = 1;
} }
/* Reset counters for T and X-editing. */
if (current_unit->flags.form == FORM_FORMATTED)
max_pos = skips = pending_spaces = 0;
/* Start the data transfer if we are doing a formatted transfer. */ /* Start the data transfer if we are doing a formatted transfer. */
if (current_unit->flags.form == FORM_FORMATTED && !ioparm.list_format if (current_unit->flags.form == FORM_FORMATTED && !ioparm.list_format
&& ioparm.namelist_name == NULL && ionml == NULL) && ioparm.namelist_name == NULL && ionml == NULL)
@ -1537,6 +1580,7 @@ export_proto(st_read);
void void
st_read (void) st_read (void)
{ {
library_start (); library_start ();
data_transfer_init (1); data_transfer_init (1);
@ -1582,6 +1626,7 @@ export_proto(st_write);
void void
st_write (void) st_write (void)
{ {
library_start (); library_start ();
data_transfer_init (0); data_transfer_init (0);
} }

View File

@ -1110,15 +1110,16 @@ write_es (fnode *f, const char *p, int len)
/* Take care of the X/TR descriptor. */ /* Take care of the X/TR descriptor. */
void void
write_x (fnode * f) write_x (int len, int nspaces)
{ {
char *p; char *p;
p = write_block (f->u.n); p = write_block (len);
if (p == NULL) if (p == NULL)
return; return;
memset (p, ' ', f->u.n); if (nspaces > 0)
memset (&p[len - nspaces], ' ', nspaces);
} }