2004-05-13 08:41:07 +02:00
|
|
|
/* Copyright (C) 2002-2003 Free Software Foundation, Inc.
|
|
|
|
Contributed by Andy Vaught
|
|
|
|
|
|
|
|
This file is part of the GNU Fortran 95 runtime library (libgfortran).
|
|
|
|
|
|
|
|
Libgfortran is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
2005-01-12 22:27:33 +01:00
|
|
|
In addition to the permissions in the GNU General Public License, the
|
|
|
|
Free Software Foundation gives you unlimited permission to link the
|
|
|
|
compiled version of this file into combinations with other programs,
|
|
|
|
and to distribute those combinations without any restriction coming
|
|
|
|
from the use of this file. (The General Public License restrictions
|
|
|
|
do apply in other respects; for example, they cover modification of
|
|
|
|
the file, and distribution when not linked into a combine
|
|
|
|
executable.)
|
|
|
|
|
2004-05-13 08:41:07 +02:00
|
|
|
Libgfortran is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Libgfortran; see the file COPYING. If not, write to
|
|
|
|
the Free Software Foundation, 59 Temple Place - Suite 330,
|
|
|
|
Boston, MA 02111-1307, USA. */
|
|
|
|
|
|
|
|
|
|
|
|
/* Implement the non-IOLENGTH variant of the INQUIRY statement */
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "libgfortran.h"
|
|
|
|
#include "io.h"
|
|
|
|
|
|
|
|
|
|
|
|
static char undefined[] = "UNDEFINED";
|
|
|
|
|
|
|
|
|
|
|
|
/* inquire_via_unit()-- Inquiry via unit number. The unit might not exist. */
|
|
|
|
|
|
|
|
static void
|
re PR libfortran/15234 (libgfortran doesn't compile on Tru64 UNIX V4.0F)
PR fortran/15234
* io/io.h (unit_t): Rename to ...
(gfc_unit) ... this.
(unit_root, current_unit, find_file, find_unit, get_unit): Now
of type gfc_unit.
(delete_file, insert_unit, close_unit): Argument now of type
gfc_unit.
* backspace.c (st_backspace), close.c (st_close), endfile.c
(st_endfile), inquire.c (inquire_via_unit, st_inquire), open.c
(test_endfile, edit_modes, new_unit, already_open, st_open),
rewind.c (st_rewind), transfer.c (current_unit), unit.c
(internal_unit, unit_cache, rotate_left, rotate_right, insert,
insert_unit, delete_root, delete_treap, delete_unit, find_unit,
get_unit, init_units, close_unit), unix.c (find_file0,
find_file, delete_file): Replace all occurences of unit_t by
gfc_unit.
From-SVN: r81903
2004-05-15 22:44:38 +02:00
|
|
|
inquire_via_unit (gfc_unit * u)
|
2004-05-13 08:41:07 +02:00
|
|
|
{
|
|
|
|
const char *p;
|
|
|
|
|
|
|
|
if (ioparm.exist != NULL)
|
|
|
|
*ioparm.exist = (u != NULL);
|
|
|
|
|
|
|
|
if (ioparm.opened != NULL)
|
|
|
|
*ioparm.opened = (u != NULL);
|
|
|
|
|
|
|
|
if (ioparm.number != NULL)
|
|
|
|
*ioparm.number = (u != NULL) ? u->unit_number : -1;
|
|
|
|
|
|
|
|
if (ioparm.named != NULL)
|
|
|
|
*ioparm.named = (u != NULL && u->flags.status != STATUS_SCRATCH);
|
|
|
|
|
|
|
|
if (ioparm.name != NULL && u != NULL && u->flags.status != STATUS_SCRATCH)
|
|
|
|
fstrcpy (ioparm.name, ioparm.name_len, u->file, u->file_len);
|
|
|
|
|
|
|
|
if (ioparm.access != NULL)
|
|
|
|
{
|
|
|
|
if (u == NULL)
|
|
|
|
p = undefined;
|
|
|
|
else
|
|
|
|
switch (u->flags.access)
|
|
|
|
{
|
|
|
|
case ACCESS_SEQUENTIAL:
|
|
|
|
p = "SEQUENTIAL";
|
|
|
|
break;
|
|
|
|
case ACCESS_DIRECT:
|
|
|
|
p = "DIRECT";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
internal_error ("inquire_via_unit(): Bad access");
|
|
|
|
}
|
|
|
|
|
|
|
|
cf_strcpy (ioparm.access, ioparm.access_len, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioparm.sequential != NULL)
|
|
|
|
{
|
2004-12-02 05:13:21 +01:00
|
|
|
/* disallow an open direct access file to be accessed
|
|
|
|
sequentially */
|
|
|
|
if (u->flags.access==ACCESS_DIRECT)
|
|
|
|
p = "NO";
|
|
|
|
else
|
|
|
|
p = (u == NULL) ? inquire_sequential (NULL, 0) :
|
|
|
|
inquire_sequential (u->file, u->file_len);
|
2004-05-13 08:41:07 +02:00
|
|
|
|
|
|
|
cf_strcpy (ioparm.sequential, ioparm.sequential_len, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioparm.direct != NULL)
|
|
|
|
{
|
|
|
|
p = (u == NULL) ? inquire_direct (NULL, 0) :
|
|
|
|
inquire_direct (u->file, u->file_len);
|
|
|
|
|
|
|
|
cf_strcpy (ioparm.direct, ioparm.direct_len, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioparm.form != NULL)
|
|
|
|
{
|
|
|
|
if (u == NULL)
|
|
|
|
p = undefined;
|
|
|
|
else
|
|
|
|
switch (u->flags.form)
|
|
|
|
{
|
|
|
|
case FORM_FORMATTED:
|
|
|
|
p = "FORMATTED";
|
|
|
|
break;
|
|
|
|
case FORM_UNFORMATTED:
|
|
|
|
p = "UNFORMATTED";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
internal_error ("inquire_via_unit(): Bad form");
|
|
|
|
}
|
|
|
|
|
|
|
|
cf_strcpy (ioparm.form, ioparm.form_len, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioparm.formatted != NULL)
|
|
|
|
{
|
|
|
|
p = (u == NULL) ? inquire_formatted (NULL, 0) :
|
|
|
|
inquire_formatted (u->file, u->file_len);
|
|
|
|
|
|
|
|
cf_strcpy (ioparm.formatted, ioparm.formatted_len, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioparm.unformatted != NULL)
|
|
|
|
{
|
|
|
|
p = (u == NULL) ? inquire_unformatted (NULL, 0) :
|
|
|
|
inquire_unformatted (u->file, u->file_len);
|
|
|
|
|
|
|
|
cf_strcpy (ioparm.unformatted, ioparm.unformatted_len, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioparm.recl_out != NULL)
|
|
|
|
*ioparm.recl_out = (u != NULL) ? u->recl : 0;
|
|
|
|
|
|
|
|
if (ioparm.nextrec != NULL)
|
|
|
|
*ioparm.nextrec = (u != NULL) ? u->last_record + 1 : 0;
|
|
|
|
|
|
|
|
if (ioparm.blank != NULL)
|
|
|
|
{
|
|
|
|
if (u == NULL)
|
|
|
|
p = undefined;
|
|
|
|
else
|
|
|
|
switch (u->flags.blank)
|
|
|
|
{
|
|
|
|
case BLANK_NULL:
|
|
|
|
p = "NULL";
|
|
|
|
break;
|
|
|
|
case BLANK_ZERO:
|
|
|
|
p = "ZERO";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
internal_error ("inquire_via_unit(): Bad blank");
|
|
|
|
}
|
|
|
|
|
|
|
|
cf_strcpy (ioparm.blank, ioparm.blank_len, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioparm.position != NULL)
|
|
|
|
{
|
|
|
|
if (u == NULL || u->flags.access == ACCESS_DIRECT)
|
2005-01-22 04:51:12 +01:00
|
|
|
p = undefined;
|
2004-05-13 08:41:07 +02:00
|
|
|
else
|
2005-01-22 04:51:12 +01:00
|
|
|
switch (u->flags.position)
|
|
|
|
{
|
|
|
|
case POSITION_REWIND:
|
|
|
|
p = "REWIND";
|
|
|
|
break;
|
|
|
|
case POSITION_APPEND:
|
|
|
|
p = "APPEND";
|
|
|
|
break;
|
|
|
|
case POSITION_ASIS:
|
|
|
|
p = "ASIS";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* if not direct access, it must be
|
|
|
|
either REWIND, APPEND, or ASIS.
|
|
|
|
ASIS seems to be the best default */
|
|
|
|
p = "ASIS";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cf_strcpy (ioparm.position, ioparm.position_len, p);
|
2004-05-13 08:41:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ioparm.action != NULL)
|
|
|
|
{
|
|
|
|
if (u == NULL)
|
|
|
|
p = undefined;
|
|
|
|
else
|
|
|
|
switch (u->flags.action)
|
|
|
|
{
|
|
|
|
case ACTION_READ:
|
|
|
|
p = "READ";
|
|
|
|
break;
|
|
|
|
case ACTION_WRITE:
|
|
|
|
p = "WRITE";
|
|
|
|
break;
|
|
|
|
case ACTION_READWRITE:
|
|
|
|
p = "READWRITE";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
internal_error ("inquire_via_unit(): Bad action");
|
|
|
|
}
|
|
|
|
|
|
|
|
cf_strcpy (ioparm.action, ioparm.action_len, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioparm.read != NULL)
|
|
|
|
{
|
|
|
|
p = (u == NULL) ? inquire_read (NULL, 0) :
|
|
|
|
inquire_read (u->file, u->file_len);
|
|
|
|
|
|
|
|
cf_strcpy (ioparm.read, ioparm.read_len, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioparm.write != NULL)
|
|
|
|
{
|
|
|
|
p = (u == NULL) ? inquire_write (NULL, 0) :
|
|
|
|
inquire_write (u->file, u->file_len);
|
|
|
|
|
|
|
|
cf_strcpy (ioparm.write, ioparm.write_len, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioparm.readwrite != NULL)
|
|
|
|
{
|
|
|
|
p = (u == NULL) ? inquire_readwrite (NULL, 0) :
|
|
|
|
inquire_readwrite (u->file, u->file_len);
|
|
|
|
|
|
|
|
cf_strcpy (ioparm.readwrite, ioparm.readwrite_len, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioparm.delim != NULL)
|
|
|
|
{
|
|
|
|
if (u == NULL || u->flags.form != FORM_FORMATTED)
|
|
|
|
p = undefined;
|
|
|
|
else
|
|
|
|
switch (u->flags.delim)
|
|
|
|
{
|
|
|
|
case DELIM_NONE:
|
|
|
|
p = "NONE";
|
|
|
|
break;
|
|
|
|
case DELIM_QUOTE:
|
|
|
|
p = "QUOTE";
|
|
|
|
break;
|
|
|
|
case DELIM_APOSTROPHE:
|
|
|
|
p = "APOSTROPHE";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
internal_error ("inquire_via_unit(): Bad delim");
|
|
|
|
}
|
|
|
|
|
2005-01-30 14:16:19 +01:00
|
|
|
cf_strcpy (ioparm.delim, ioparm.delim_len, p);
|
2004-05-13 08:41:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ioparm.pad != NULL)
|
|
|
|
{
|
|
|
|
if (u == NULL || u->flags.form != FORM_FORMATTED)
|
|
|
|
p = undefined;
|
|
|
|
else
|
|
|
|
switch (u->flags.pad)
|
|
|
|
{
|
|
|
|
case PAD_NO:
|
|
|
|
p = "NO";
|
|
|
|
break;
|
|
|
|
case PAD_YES:
|
|
|
|
p = "YES";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
internal_error ("inquire_via_unit(): Bad pad");
|
|
|
|
}
|
|
|
|
|
|
|
|
cf_strcpy (ioparm.pad, ioparm.pad_len, p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* inquire_via_filename()-- Inquiry via filename. This subroutine is
|
|
|
|
* only used if the filename is *not* connected to a unit number. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
inquire_via_filename (void)
|
|
|
|
{
|
|
|
|
const char *p;
|
|
|
|
|
|
|
|
if (ioparm.exist != NULL)
|
|
|
|
*ioparm.exist = file_exists ();
|
|
|
|
|
|
|
|
if (ioparm.opened != NULL)
|
|
|
|
*ioparm.opened = 0;
|
|
|
|
|
|
|
|
if (ioparm.number != NULL)
|
|
|
|
*ioparm.number = -1;
|
|
|
|
|
|
|
|
if (ioparm.named != NULL)
|
|
|
|
*ioparm.named = 1;
|
|
|
|
|
|
|
|
if (ioparm.name != NULL)
|
|
|
|
fstrcpy (ioparm.name, ioparm.name_len, ioparm.file, ioparm.file_len);
|
|
|
|
|
|
|
|
if (ioparm.access != NULL)
|
|
|
|
cf_strcpy (ioparm.access, ioparm.access_len, undefined);
|
|
|
|
|
|
|
|
if (ioparm.sequential != NULL)
|
|
|
|
{
|
|
|
|
p = inquire_sequential (ioparm.file, ioparm.file_len);
|
|
|
|
cf_strcpy (ioparm.sequential, ioparm.sequential_len, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioparm.direct != NULL)
|
|
|
|
{
|
|
|
|
p = inquire_direct (ioparm.file, ioparm.file_len);
|
|
|
|
cf_strcpy (ioparm.direct, ioparm.direct_len, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioparm.form != NULL)
|
|
|
|
cf_strcpy (ioparm.form, ioparm.form_len, undefined);
|
|
|
|
|
|
|
|
if (ioparm.formatted != NULL)
|
|
|
|
{
|
|
|
|
p = inquire_formatted (ioparm.file, ioparm.file_len);
|
|
|
|
cf_strcpy (ioparm.formatted, ioparm.formatted_len, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioparm.unformatted != NULL)
|
|
|
|
{
|
|
|
|
p = inquire_unformatted (ioparm.file, ioparm.file_len);
|
|
|
|
cf_strcpy (ioparm.unformatted, ioparm.unformatted_len, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioparm.recl_out != NULL)
|
|
|
|
*ioparm.recl_out = 0;
|
|
|
|
|
|
|
|
if (ioparm.nextrec != NULL)
|
|
|
|
*ioparm.nextrec = 0;
|
|
|
|
|
|
|
|
if (ioparm.blank != NULL)
|
|
|
|
cf_strcpy (ioparm.blank, ioparm.blank_len, undefined);
|
|
|
|
|
|
|
|
if (ioparm.position != NULL)
|
|
|
|
cf_strcpy (ioparm.position, ioparm.position_len, undefined);
|
|
|
|
|
|
|
|
if (ioparm.access != NULL)
|
|
|
|
cf_strcpy (ioparm.access, ioparm.access_len, undefined);
|
|
|
|
|
|
|
|
if (ioparm.read != NULL)
|
|
|
|
{
|
|
|
|
p = inquire_read (ioparm.file, ioparm.file_len);
|
|
|
|
cf_strcpy (ioparm.read, ioparm.read_len, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioparm.write != NULL)
|
|
|
|
{
|
|
|
|
p = inquire_write (ioparm.file, ioparm.file_len);
|
|
|
|
cf_strcpy (ioparm.write, ioparm.write_len, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioparm.readwrite != NULL)
|
|
|
|
{
|
|
|
|
p = inquire_read (ioparm.file, ioparm.file_len);
|
|
|
|
cf_strcpy (ioparm.readwrite, ioparm.readwrite_len, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioparm.delim != NULL)
|
|
|
|
cf_strcpy (ioparm.delim, ioparm.delim_len, undefined);
|
|
|
|
|
|
|
|
if (ioparm.pad != NULL)
|
|
|
|
cf_strcpy (ioparm.pad, ioparm.pad_len, undefined);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-22 02:43:55 +02:00
|
|
|
/* Library entry point for the INQUIRE statement (non-IOLENGTH
|
|
|
|
form). */
|
2004-05-13 08:41:07 +02:00
|
|
|
|
acinclude.m4 (LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY): New.
* acinclude.m4 (LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY): New.
(LIBGFOR_CHECK_ATTRIBUTE_DLLEXPORT): New.
(LIBGFOR_CHECK_ATTRIBUTE_ALIAS): New.
* configure.ac: Use them.
* configure, config.h.in, aclocal.m4: Rebuild.
* libgfortran.h (prefix): Remove.
(PREFIX, IPREFIX): New.
(sym_rename, sym_rename1, sym_rename2): New.
(internal_proto, export_proto, export_proto_np): New.
(iexport_proto, iexport): New.
(iexport_data_proto, iexport_data): New.
* intrinsics/abort.c, intrinsics/args.c, intrinsics/associated.c,
intrinsics/cpu_time.c, intrinsics/cshift0.c,
intrinsics/date_and_time.c, intrinsics/env.c, intrinsics/eoshift0.c,
intrinsics/eoshift2.c, intrinsics/etime.c, intrinsics/exit.c,
intrinsics/flush.c, intrinsics/fnum.c, intrinsics/getXid.c,
intrinsics/getcwd.c, intrinsics/ishftc.c, intrinsics/mvbits.c,
intrinsics/pack_generic.c, intrinsics/rand.c, intrinsics/random.c,
intrinsics/reshape_generic.c, intrinsics/size.c,
intrinsics/spread_generic.c, intrinsics/stat.c,
intrinsics/string_intrinsics.c, intrinsics/system.c,
intrinsics/system_clock.c, intrinsics/transpose_generic.c,
intrinsics/umask.c, intrinsics/unlink.c, intrinsics/unpack_generic.c,
io/backspace.c, io/close.c, io/endfile.c, io/inquire.c, io/io.h,
io/open.c, io/rewind.c, io/transfer.c, libgfortran.h, m4/cshift1.m4,
m4/dotprod.m4, m4/dotprodc.m4, m4/dotprodl.m4, m4/eoshift1.m4,
m4/eoshift3.m4, m4/exponent.m4, m4/fraction.m4, m4/iforeach.m4,
m4/ifunction.m4, m4/matmul.m4, m4/matmull.m4, m4/nearest.m4,
m4/pow.m4, m4/reshape.m4, m4/set_exponent.m4, m4/shape.m4,
m4/transpose.m4, runtime/environ.c, runtime/error.c,
runtime/in_pack_generic.c, runtime/in_unpack_generic.c,
runtime/main.c, runtime/memory.c, runtime/pause.c, runtime/select.c,
runtime/stop.c: Use them to mark symbols internal or external.
* generated/*: Rebuild.
From-SVN: r92045
2004-12-12 09:59:05 +01:00
|
|
|
extern void st_inquire (void);
|
|
|
|
export_proto(st_inquire);
|
|
|
|
|
2004-05-13 08:41:07 +02:00
|
|
|
void
|
|
|
|
st_inquire (void)
|
|
|
|
{
|
re PR libfortran/15234 (libgfortran doesn't compile on Tru64 UNIX V4.0F)
PR fortran/15234
* io/io.h (unit_t): Rename to ...
(gfc_unit) ... this.
(unit_root, current_unit, find_file, find_unit, get_unit): Now
of type gfc_unit.
(delete_file, insert_unit, close_unit): Argument now of type
gfc_unit.
* backspace.c (st_backspace), close.c (st_close), endfile.c
(st_endfile), inquire.c (inquire_via_unit, st_inquire), open.c
(test_endfile, edit_modes, new_unit, already_open, st_open),
rewind.c (st_rewind), transfer.c (current_unit), unit.c
(internal_unit, unit_cache, rotate_left, rotate_right, insert,
insert_unit, delete_root, delete_treap, delete_unit, find_unit,
get_unit, init_units, close_unit), unix.c (find_file0,
find_file, delete_file): Replace all occurences of unit_t by
gfc_unit.
From-SVN: r81903
2004-05-15 22:44:38 +02:00
|
|
|
gfc_unit *u;
|
2004-05-13 08:41:07 +02:00
|
|
|
|
|
|
|
library_start ();
|
|
|
|
|
|
|
|
if (ioparm.file == NULL)
|
|
|
|
inquire_via_unit (find_unit (ioparm.unit));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
u = find_file ();
|
|
|
|
if (u == NULL)
|
|
|
|
inquire_via_filename ();
|
|
|
|
else
|
|
|
|
inquire_via_unit (u);
|
|
|
|
}
|
|
|
|
|
|
|
|
library_end ();
|
|
|
|
}
|