1 /* Copyright (C) 2002-2003 Free Software Foundation, Inc.
2 Contributed by Andy Vaught
4 This file is part of the GNU Fortran 95 runtime library (libgfortran).
6 Libgfortran is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 In addition to the permissions in the GNU General Public License, the
12 Free Software Foundation gives you unlimited permission to link the
13 compiled version of this file into combinations with other programs,
14 and to distribute those combinations without any restriction coming
15 from the use of this file. (The General Public License restrictions
16 do apply in other respects; for example, they cover modification of
17 the file, and distribution when not linked into a combine
20 Libgfortran is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with Libgfortran; see the file COPYING. If not, write to
27 the Free Software Foundation, 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. */
31 /* Implement the non-IOLENGTH variant of the INQUIRY statement */
34 #include "libgfortran.h"
38 static char undefined[] = "UNDEFINED";
41 /* inquire_via_unit()-- Inquiry via unit number. The unit might not exist. */
44 inquire_via_unit (gfc_unit * u)
48 if (ioparm.exist != NULL)
49 *ioparm.exist = (u != NULL);
51 if (ioparm.opened != NULL)
52 *ioparm.opened = (u != NULL);
54 if (ioparm.number != NULL)
55 *ioparm.number = (u != NULL) ? u->unit_number : -1;
57 if (ioparm.named != NULL)
58 *ioparm.named = (u != NULL && u->flags.status != STATUS_SCRATCH);
60 if (ioparm.name != NULL && u != NULL && u->flags.status != STATUS_SCRATCH)
61 fstrcpy (ioparm.name, ioparm.name_len, u->file, u->file_len);
63 if (ioparm.access != NULL)
68 switch (u->flags.access)
70 case ACCESS_SEQUENTIAL:
77 internal_error ("inquire_via_unit(): Bad access");
80 cf_strcpy (ioparm.access, ioparm.access_len, p);
83 if (ioparm.sequential != NULL)
85 /* disallow an open direct access file to be accessed
87 if (u->flags.access==ACCESS_DIRECT)
90 p = (u == NULL) ? inquire_sequential (NULL, 0) :
91 inquire_sequential (u->file, u->file_len);
93 cf_strcpy (ioparm.sequential, ioparm.sequential_len, p);
96 if (ioparm.direct != NULL)
98 p = (u == NULL) ? inquire_direct (NULL, 0) :
99 inquire_direct (u->file, u->file_len);
101 cf_strcpy (ioparm.direct, ioparm.direct_len, p);
104 if (ioparm.form != NULL)
109 switch (u->flags.form)
114 case FORM_UNFORMATTED:
118 internal_error ("inquire_via_unit(): Bad form");
121 cf_strcpy (ioparm.form, ioparm.form_len, p);
124 if (ioparm.formatted != NULL)
126 p = (u == NULL) ? inquire_formatted (NULL, 0) :
127 inquire_formatted (u->file, u->file_len);
129 cf_strcpy (ioparm.formatted, ioparm.formatted_len, p);
132 if (ioparm.unformatted != NULL)
134 p = (u == NULL) ? inquire_unformatted (NULL, 0) :
135 inquire_unformatted (u->file, u->file_len);
137 cf_strcpy (ioparm.unformatted, ioparm.unformatted_len, p);
140 if (ioparm.recl_out != NULL)
141 *ioparm.recl_out = (u != NULL) ? u->recl : 0;
143 if (ioparm.nextrec != NULL)
144 *ioparm.nextrec = (u != NULL) ? u->last_record + 1 : 0;
146 if (ioparm.blank != NULL)
151 switch (u->flags.blank)
160 internal_error ("inquire_via_unit(): Bad blank");
163 cf_strcpy (ioparm.blank, ioparm.blank_len, p);
166 if (ioparm.position != NULL)
168 if (u == NULL || u->flags.access == ACCESS_DIRECT)
171 switch (u->flags.position)
173 case POSITION_REWIND:
176 case POSITION_APPEND:
183 /* if not direct access, it must be
184 either REWIND, APPEND, or ASIS.
185 ASIS seems to be the best default */
189 cf_strcpy (ioparm.position, ioparm.position_len, p);
192 if (ioparm.action != NULL)
197 switch (u->flags.action)
205 case ACTION_READWRITE:
209 internal_error ("inquire_via_unit(): Bad action");
212 cf_strcpy (ioparm.action, ioparm.action_len, p);
215 if (ioparm.read != NULL)
217 p = (u == NULL) ? inquire_read (NULL, 0) :
218 inquire_read (u->file, u->file_len);
220 cf_strcpy (ioparm.read, ioparm.read_len, p);
223 if (ioparm.write != NULL)
225 p = (u == NULL) ? inquire_write (NULL, 0) :
226 inquire_write (u->file, u->file_len);
228 cf_strcpy (ioparm.write, ioparm.write_len, p);
231 if (ioparm.readwrite != NULL)
233 p = (u == NULL) ? inquire_readwrite (NULL, 0) :
234 inquire_readwrite (u->file, u->file_len);
236 cf_strcpy (ioparm.readwrite, ioparm.readwrite_len, p);
239 if (ioparm.delim != NULL)
241 if (u == NULL || u->flags.form != FORM_FORMATTED)
244 switch (u->flags.delim)
252 case DELIM_APOSTROPHE:
256 internal_error ("inquire_via_unit(): Bad delim");
259 cf_strcpy (ioparm.delim, ioparm.delim_len, p);
262 if (ioparm.pad != NULL)
264 if (u == NULL || u->flags.form != FORM_FORMATTED)
267 switch (u->flags.pad)
276 internal_error ("inquire_via_unit(): Bad pad");
279 cf_strcpy (ioparm.pad, ioparm.pad_len, p);
284 /* inquire_via_filename()-- Inquiry via filename. This subroutine is
285 * only used if the filename is *not* connected to a unit number. */
288 inquire_via_filename (void)
292 if (ioparm.exist != NULL)
293 *ioparm.exist = file_exists ();
295 if (ioparm.opened != NULL)
298 if (ioparm.number != NULL)
301 if (ioparm.named != NULL)
304 if (ioparm.name != NULL)
305 fstrcpy (ioparm.name, ioparm.name_len, ioparm.file, ioparm.file_len);
307 if (ioparm.access != NULL)
308 cf_strcpy (ioparm.access, ioparm.access_len, undefined);
310 if (ioparm.sequential != NULL)
312 p = inquire_sequential (ioparm.file, ioparm.file_len);
313 cf_strcpy (ioparm.sequential, ioparm.sequential_len, p);
316 if (ioparm.direct != NULL)
318 p = inquire_direct (ioparm.file, ioparm.file_len);
319 cf_strcpy (ioparm.direct, ioparm.direct_len, p);
322 if (ioparm.form != NULL)
323 cf_strcpy (ioparm.form, ioparm.form_len, undefined);
325 if (ioparm.formatted != NULL)
327 p = inquire_formatted (ioparm.file, ioparm.file_len);
328 cf_strcpy (ioparm.formatted, ioparm.formatted_len, p);
331 if (ioparm.unformatted != NULL)
333 p = inquire_unformatted (ioparm.file, ioparm.file_len);
334 cf_strcpy (ioparm.unformatted, ioparm.unformatted_len, p);
337 if (ioparm.recl_out != NULL)
338 *ioparm.recl_out = 0;
340 if (ioparm.nextrec != NULL)
343 if (ioparm.blank != NULL)
344 cf_strcpy (ioparm.blank, ioparm.blank_len, undefined);
346 if (ioparm.position != NULL)
347 cf_strcpy (ioparm.position, ioparm.position_len, undefined);
349 if (ioparm.access != NULL)
350 cf_strcpy (ioparm.access, ioparm.access_len, undefined);
352 if (ioparm.read != NULL)
354 p = inquire_read (ioparm.file, ioparm.file_len);
355 cf_strcpy (ioparm.read, ioparm.read_len, p);
358 if (ioparm.write != NULL)
360 p = inquire_write (ioparm.file, ioparm.file_len);
361 cf_strcpy (ioparm.write, ioparm.write_len, p);
364 if (ioparm.readwrite != NULL)
366 p = inquire_read (ioparm.file, ioparm.file_len);
367 cf_strcpy (ioparm.readwrite, ioparm.readwrite_len, p);
370 if (ioparm.delim != NULL)
371 cf_strcpy (ioparm.delim, ioparm.delim_len, undefined);
373 if (ioparm.pad != NULL)
374 cf_strcpy (ioparm.pad, ioparm.pad_len, undefined);
379 /* Library entry point for the INQUIRE statement (non-IOLENGTH
382 extern void st_inquire (void);
383 export_proto(st_inquire);
392 if (ioparm.file == NULL)
393 inquire_via_unit (find_unit (ioparm.unit));
398 inquire_via_filename ();
400 inquire_via_unit (u);