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 Libgfortran is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Libgfortran; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 /* Implement the non-IOLENGTH variant of the INQUIRY statement */
25 #include "libgfortran.h"
29 static char undefined[] = "UNDEFINED";
32 /* inquire_via_unit()-- Inquiry via unit number. The unit might not exist. */
35 inquire_via_unit (gfc_unit * u)
39 if (ioparm.exist != NULL)
40 *ioparm.exist = (u != NULL);
42 if (ioparm.opened != NULL)
43 *ioparm.opened = (u != NULL);
45 if (ioparm.number != NULL)
46 *ioparm.number = (u != NULL) ? u->unit_number : -1;
48 if (ioparm.named != NULL)
49 *ioparm.named = (u != NULL && u->flags.status != STATUS_SCRATCH);
51 if (ioparm.name != NULL && u != NULL && u->flags.status != STATUS_SCRATCH)
52 fstrcpy (ioparm.name, ioparm.name_len, u->file, u->file_len);
54 if (ioparm.access != NULL)
59 switch (u->flags.access)
61 case ACCESS_SEQUENTIAL:
68 internal_error ("inquire_via_unit(): Bad access");
71 cf_strcpy (ioparm.access, ioparm.access_len, p);
74 if (ioparm.sequential != NULL)
76 p = (u == NULL) ? inquire_sequential (NULL, 0) :
77 inquire_sequential (u->file, u->file_len);
79 cf_strcpy (ioparm.sequential, ioparm.sequential_len, p);
82 if (ioparm.direct != NULL)
84 p = (u == NULL) ? inquire_direct (NULL, 0) :
85 inquire_direct (u->file, u->file_len);
87 cf_strcpy (ioparm.direct, ioparm.direct_len, p);
90 if (ioparm.form != NULL)
95 switch (u->flags.form)
100 case FORM_UNFORMATTED:
104 internal_error ("inquire_via_unit(): Bad form");
107 cf_strcpy (ioparm.form, ioparm.form_len, p);
110 if (ioparm.formatted != NULL)
112 p = (u == NULL) ? inquire_formatted (NULL, 0) :
113 inquire_formatted (u->file, u->file_len);
115 cf_strcpy (ioparm.formatted, ioparm.formatted_len, p);
118 if (ioparm.unformatted != NULL)
120 p = (u == NULL) ? inquire_unformatted (NULL, 0) :
121 inquire_unformatted (u->file, u->file_len);
123 cf_strcpy (ioparm.unformatted, ioparm.unformatted_len, p);
126 if (ioparm.recl_out != NULL)
127 *ioparm.recl_out = (u != NULL) ? u->recl : 0;
129 if (ioparm.nextrec != NULL)
130 *ioparm.nextrec = (u != NULL) ? u->last_record + 1 : 0;
132 if (ioparm.blank != NULL)
137 switch (u->flags.blank)
146 internal_error ("inquire_via_unit(): Bad blank");
149 cf_strcpy (ioparm.blank, ioparm.blank_len, p);
152 if (ioparm.position != NULL)
154 if (u == NULL || u->flags.access == ACCESS_DIRECT)
158 p = NULL; /* TODO: Try to decode what the standard says... */
161 cf_strcpy (ioparm.blank, ioparm.blank_len, p);
164 if (ioparm.action != NULL)
169 switch (u->flags.action)
177 case ACTION_READWRITE:
181 internal_error ("inquire_via_unit(): Bad action");
184 cf_strcpy (ioparm.action, ioparm.action_len, p);
187 if (ioparm.read != NULL)
189 p = (u == NULL) ? inquire_read (NULL, 0) :
190 inquire_read (u->file, u->file_len);
192 cf_strcpy (ioparm.read, ioparm.read_len, p);
195 if (ioparm.write != NULL)
197 p = (u == NULL) ? inquire_write (NULL, 0) :
198 inquire_write (u->file, u->file_len);
200 cf_strcpy (ioparm.write, ioparm.write_len, p);
203 if (ioparm.readwrite != NULL)
205 p = (u == NULL) ? inquire_readwrite (NULL, 0) :
206 inquire_readwrite (u->file, u->file_len);
208 cf_strcpy (ioparm.readwrite, ioparm.readwrite_len, p);
211 if (ioparm.delim != NULL)
213 if (u == NULL || u->flags.form != FORM_FORMATTED)
216 switch (u->flags.delim)
224 case DELIM_APOSTROPHE:
228 internal_error ("inquire_via_unit(): Bad delim");
231 cf_strcpy (ioparm.access, ioparm.access_len, p);
234 if (ioparm.pad != NULL)
236 if (u == NULL || u->flags.form != FORM_FORMATTED)
239 switch (u->flags.pad)
248 internal_error ("inquire_via_unit(): Bad pad");
251 cf_strcpy (ioparm.pad, ioparm.pad_len, p);
256 /* inquire_via_filename()-- Inquiry via filename. This subroutine is
257 * only used if the filename is *not* connected to a unit number. */
260 inquire_via_filename (void)
264 if (ioparm.exist != NULL)
265 *ioparm.exist = file_exists ();
267 if (ioparm.opened != NULL)
270 if (ioparm.number != NULL)
273 if (ioparm.named != NULL)
276 if (ioparm.name != NULL)
277 fstrcpy (ioparm.name, ioparm.name_len, ioparm.file, ioparm.file_len);
279 if (ioparm.access != NULL)
280 cf_strcpy (ioparm.access, ioparm.access_len, undefined);
282 if (ioparm.sequential != NULL)
284 p = inquire_sequential (ioparm.file, ioparm.file_len);
285 cf_strcpy (ioparm.sequential, ioparm.sequential_len, p);
288 if (ioparm.direct != NULL)
290 p = inquire_direct (ioparm.file, ioparm.file_len);
291 cf_strcpy (ioparm.direct, ioparm.direct_len, p);
294 if (ioparm.form != NULL)
295 cf_strcpy (ioparm.form, ioparm.form_len, undefined);
297 if (ioparm.formatted != NULL)
299 p = inquire_formatted (ioparm.file, ioparm.file_len);
300 cf_strcpy (ioparm.formatted, ioparm.formatted_len, p);
303 if (ioparm.unformatted != NULL)
305 p = inquire_unformatted (ioparm.file, ioparm.file_len);
306 cf_strcpy (ioparm.unformatted, ioparm.unformatted_len, p);
309 if (ioparm.recl_out != NULL)
310 *ioparm.recl_out = 0;
312 if (ioparm.nextrec != NULL)
315 if (ioparm.blank != NULL)
316 cf_strcpy (ioparm.blank, ioparm.blank_len, undefined);
318 if (ioparm.position != NULL)
319 cf_strcpy (ioparm.position, ioparm.position_len, undefined);
321 if (ioparm.access != NULL)
322 cf_strcpy (ioparm.access, ioparm.access_len, undefined);
324 if (ioparm.read != NULL)
326 p = inquire_read (ioparm.file, ioparm.file_len);
327 cf_strcpy (ioparm.read, ioparm.read_len, p);
330 if (ioparm.write != NULL)
332 p = inquire_write (ioparm.file, ioparm.file_len);
333 cf_strcpy (ioparm.write, ioparm.write_len, p);
336 if (ioparm.readwrite != NULL)
338 p = inquire_read (ioparm.file, ioparm.file_len);
339 cf_strcpy (ioparm.readwrite, ioparm.readwrite_len, p);
342 if (ioparm.delim != NULL)
343 cf_strcpy (ioparm.delim, ioparm.delim_len, undefined);
345 if (ioparm.pad != NULL)
346 cf_strcpy (ioparm.pad, ioparm.pad_len, undefined);
351 /* Library entry point for the INQUIRE statement (non-IOLENGTH
361 if (ioparm.file == NULL)
362 inquire_via_unit (find_unit (ioparm.unit));
367 inquire_via_filename ();
369 inquire_via_unit (u);