aboutsummaryrefslogtreecommitdiff
path: root/libgfortran/io/open.c
diff options
context:
space:
mode:
authorThomas Koenig <Thomas.Koenig@online.de>2005-12-10 20:01:56 +0000
committerThomas Koenig <tkoenig@gcc.gnu.org>2005-12-10 20:01:56 +0000
commit181c9f4a9ba6b2d64c7c0b56b777ad366e05a9c1 (patch)
treea3d754eebe0bc2166ffe8c241b2d9dfdd1098340 /libgfortran/io/open.c
parent775fe6e36ddaef38cca67c39bf34b93fcb836dc3 (diff)
downloadgcc-181c9f4a9ba6b2d64c7c0b56b777ad366e05a9c1.zip
gcc-181c9f4a9ba6b2d64c7c0b56b777ad366e05a9c1.tar.gz
gcc-181c9f4a9ba6b2d64c7c0b56b777ad366e05a9c1.tar.bz2
re PR fortran/23815 (Add -byteswapio flag)
2005-12-10 Thomas Koenig <Thomas.Koenig@online.de> PR fortran/23815 * io.c (top level): Add convert to io_tag. (resolve_tag): convert is GFC_STD_GNU. (match_open_element): Add convert. (gfc_free_open): Likewise. (gfc_resolve_open): Likewise. (gfc_free_inquire): Likewise. (match_inquire_element): Likewise. * dump-parse-tree.c (gfc_show_code_node): Add convet for open and inquire. gfortran.h: Add convert to gfc_open and gfc_inquire. * trans-io.c (gfc_trans_open): Add convert. (gfc_trans_inquire): Likewise. * ioparm.def: Add convert to open and inquire. * gfortran.texi: Document CONVERT. 2005-12-10 Thomas Koenig <Thomas.Koenig@online.de> PR fortran/23815 * io/file_pos.c (unformatted_backspace): If flags.convert does not equal CONVERT_NATIVE, reverse the record marker. * io/open.c: Add convert_opt[]. (st_open): If no convert option is given, set CONVERT_NATIVE. If CONVERT_BIG or CONVERT_LITTLE are given, set flags.convert to CONVERT_NATIVE or CONVERT_SWAP (depending on wether we have a big- or little-endian system). * io/transfer.c (unformatted_read): Remove unused attribute from arguments. If we need to reverse bytes, break up large transfers into a loop. Split complex numbers into its two parts. (unformatted_write): Likewise. (us_read): If flags.convert does not equal CONVERT_NATIVE, reverse the record marker. (next_record_w): Likewise. (reverse_memcpy): New function. * io/inquire.c (inquire_via_unit): Implement convert. * io/io.h (top level): Add enum unit_convert. Add convert to st_parameter_open and st_parameter_inquire. Define IOPARM_OPEN_HAS_CONVERT and IOPARM_INQUIRE_HAS_CONVERT. Increase padding for st_parameter_dt. Declare reverse_memcpy(). 2005-12-10 Thomas Koenig <Thomas.Koenig@online.de> PR fortran/23815 * gfortran.dg/unf_io_convert_1.f90: New test. * gfortran.dg/unf_io_convert_2.f90: New test. * gfortran.dg/unf_io_convert_3.f90: New test. From-SVN: r108358
Diffstat (limited to 'libgfortran/io/open.c')
-rw-r--r--libgfortran/io/open.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/libgfortran/io/open.c b/libgfortran/io/open.c
index 7e42cc6..3dc2b11 100644
--- a/libgfortran/io/open.c
+++ b/libgfortran/io/open.c
@@ -98,6 +98,14 @@ static const st_option pad_opt[] =
{ NULL, 0}
};
+static const st_option convert_opt[] =
+{
+ { "native", CONVERT_NATIVE},
+ { "swap", CONVERT_SWAP},
+ { "big_endian", CONVERT_BIG},
+ { "little_endian", CONVERT_LITTLE},
+ { NULL, 0}
+};
/* Given a unit, test to see if the file is positioned at the terminal
point, and if so, change state from NO_ENDFILE flag to AT_ENDFILE.
@@ -531,6 +539,36 @@ st_open (st_parameter_open *opp)
find_option (&opp->common, opp->status, opp->status_len,
status_opt, "Bad STATUS parameter in OPEN statement");
+ if (cf & IOPARM_OPEN_HAS_CONVERT)
+ {
+ unit_convert conv;
+ conv = find_option (&opp->common, opp->convert, opp->convert_len,
+ convert_opt, "Bad CONVERT parameter in OPEN statement");
+ /* We use l8_to_l4_offset, which is 0 on little-endian machines
+ and 1 on big-endian machines. */
+ switch (conv)
+ {
+ case CONVERT_NATIVE:
+ case CONVERT_SWAP:
+ break;
+
+ case CONVERT_BIG:
+ conv = l8_to_l4_offset ? CONVERT_NATIVE : CONVERT_SWAP;
+ break;
+
+ case CONVERT_LITTLE:
+ conv = l8_to_l4_offset ? CONVERT_SWAP : CONVERT_NATIVE;
+ break;
+
+ default:
+ internal_error (&opp->common, "Illegal value for CONVERT");
+ break;
+ }
+ flags.convert = conv;
+ }
+ else
+ flags.convert = CONVERT_NATIVE;
+
if (opp->common.unit < 0)
generate_error (&opp->common, ERROR_BAD_OPTION,
"Bad unit number in OPEN statement");