]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgfortran/io/io.h
alpha.c (va_list_skip_additions): Only define if TARGET_ABI_OSF.
[thirdparty/gcc.git] / libgfortran / io / io.h
CommitLineData
b8d5e926 1/* Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
6de9cd9a
DN
2 Contributed by Andy Vaught
3
4This file is part of the GNU Fortran 95 runtime library (libgfortran).
5
6Libgfortran is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11Libgfortran is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with Libgfortran; see the file COPYING. If not, write to
18the Free Software Foundation, 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
20
57dea9f6
TM
21/* As a special exception, if you link this library with other files,
22 some of which are compiled with GCC, to produce an executable,
23 this library does not by itself cause the resulting executable
24 to be covered by the GNU General Public License.
25 This exception does not however invalidate any other reasons why
26 the executable file might be covered by the GNU General Public License. */
27
6de9cd9a
DN
28#ifndef GFOR_IO_H
29#define GFOR_IO_H
30
31/* IO library include. */
32
33#include <setjmp.h>
34#include "libgfortran.h"
7d7b8bfe 35
6de9cd9a
DN
36#define DEFAULT_TEMPDIR "/var/tmp"
37
38/* Basic types used in data transfers. */
39
40typedef enum
41{ BT_NULL, BT_INTEGER, BT_LOGICAL, BT_CHARACTER, BT_REAL,
42 BT_COMPLEX
43}
44bt;
45
46
47typedef enum
48{ SUCCESS = 1, FAILURE }
49try;
50
51typedef struct stream
52{
81f4be3c
TS
53 char *(*alloc_w_at) (struct stream *, int *, gfc_offset);
54 char *(*alloc_r_at) (struct stream *, int *, gfc_offset);
7d7b8bfe
RH
55 try (*sfree) (struct stream *);
56 try (*close) (struct stream *);
57 try (*seek) (struct stream *, gfc_offset);
58 try (*truncate) (struct stream *);
6de9cd9a
DN
59}
60stream;
61
62
63/* Macros for doing file I/O given a stream. */
64
65#define sfree(s) ((s)->sfree)(s)
66#define sclose(s) ((s)->close)(s)
67
68#define salloc_r(s, len) ((s)->alloc_r_at)(s, len, -1)
69#define salloc_w(s, len) ((s)->alloc_w_at)(s, len, -1)
70
71#define salloc_r_at(s, len, where) ((s)->alloc_r_at)(s, len, where)
72#define salloc_w_at(s, len, where) ((s)->alloc_w_at)(s, len, where)
73
74#define sseek(s, pos) ((s)->seek)(s, pos)
75#define struncate(s) ((s)->truncate)(s)
76
77/* Namelist represent object */
78/*
79 Namelist Records
80 &groupname object=value [,object=value].../
81 or
82 &groupname object=value [,object=value]...&groupname
83
84 Even more complex, during the execution of a program containing a
85 namelist READ statement, you can specify a question mark character(?)
86 or a question mark character preceded by an equal sign(=?) to get
87 the information of the namelist group. By '?', the name of variables
88 in the namelist will be displayed, by '=?', the name and value of
89 variables will be displayed.
90
91 All these requirements need a new data structure to record all info
92 about the namelist.
93*/
94
95typedef struct namelist_type
96{
97 char * var_name;
98 void * mem_pos;
99 int value_acquired;
100 int len;
3bc268e6 101 int string_length;
6de9cd9a
DN
102 bt type;
103 struct namelist_type * next;
104}
105namelist_info;
106
107/* Options for the OPEN statement. */
108
109typedef enum
110{ ACCESS_SEQUENTIAL, ACCESS_DIRECT,
111 ACCESS_UNSPECIFIED
112}
113unit_access;
114
115typedef enum
116{ ACTION_READ, ACTION_WRITE, ACTION_READWRITE,
117 ACTION_UNSPECIFIED
118}
119unit_action;
120
121typedef enum
122{ BLANK_NULL, BLANK_ZERO, BLANK_UNSPECIFIED }
123unit_blank;
124
125typedef enum
126{ DELIM_NONE, DELIM_APOSTROPHE, DELIM_QUOTE,
127 DELIM_UNSPECIFIED
128}
129unit_delim;
130
131typedef enum
132{ FORM_FORMATTED, FORM_UNFORMATTED, FORM_UNSPECIFIED }
133unit_form;
134
135typedef enum
136{ POSITION_ASIS, POSITION_REWIND, POSITION_APPEND,
137 POSITION_UNSPECIFIED
138}
139unit_position;
140
141typedef enum
142{ STATUS_UNKNOWN, STATUS_OLD, STATUS_NEW, STATUS_SCRATCH,
143 STATUS_REPLACE, STATUS_UNSPECIFIED
144}
145unit_status;
146
147typedef enum
148{ PAD_YES, PAD_NO, PAD_UNSPECIFIED }
149unit_pad;
150
151typedef enum
152{ ADVANCE_YES, ADVANCE_NO, ADVANCE_UNSPECIFIED }
153unit_advance;
154
55948b69
BD
155typedef enum
156{READING, WRITING}
157unit_mode;
6de9cd9a
DN
158
159/* Statement parameters. These are all the things that can appear in
160 an I/O statement. Some are inputs and some are outputs, but none
161 are both. All of these values are initially zeroed and are zeroed
162 at the end of a library statement. The relevant values need to be
163 set before entry to an I/O statement. This structure needs to be
164 duplicated by the back end. */
165
166typedef struct
167{
b8d5e926
TS
168 GFC_INTEGER_4 unit;
169 GFC_INTEGER_4 err, end, eor, list_format; /* These are flags, not values. */
6de9cd9a
DN
170
171/* Return values from library statements. These are returned only if
172 the labels are specified in the statement itself and the condition
173 occurs. In most cases, none of the labels are specified and the
174 return value does not have to be checked. Must be consistent with
175 the front end. */
176
177 enum
178 {
179 LIBRARY_OK = 0,
180 LIBRARY_ERROR,
181 LIBRARY_END,
182 LIBRARY_EOR
183 }
184 library_return;
185
b8d5e926
TS
186 GFC_INTEGER_4 *iostat, *exist, *opened, *number, *named;
187 GFC_INTEGER_4 rec;
188 GFC_INTEGER_4 *nextrec, *size;
189
190 GFC_INTEGER_4 recl_in;
191 GFC_INTEGER_4 *recl_out;
192
193 GFC_INTEGER_4 *iolength;
194
195#define CHARACTER(name) \
196 char * name; \
197 gfc_charlen_type name ## _len
198 CHARACTER (file);
199 CHARACTER (status);
200 CHARACTER (access);
201 CHARACTER (form);
202 CHARACTER (blank);
203 CHARACTER (position);
204 CHARACTER (action);
205 CHARACTER (delim);
206 CHARACTER (pad);
207 CHARACTER (format);
208 CHARACTER (advance);
209 CHARACTER (name);
210 CHARACTER (internal_unit);
211 CHARACTER (sequential);
212 CHARACTER (direct);
213 CHARACTER (formatted);
214 CHARACTER (unformatted);
215 CHARACTER (read);
216 CHARACTER (write);
217 CHARACTER (readwrite);
6de9cd9a
DN
218
219/* namelist related data */
b8d5e926
TS
220 CHARACTER (namelist_name);
221 GFC_INTEGER_4 namelist_read_mode;
222
223#undef CHARACTER
6de9cd9a
DN
224}
225st_parameter;
226
6de9cd9a 227extern st_parameter ioparm;
7d7b8bfe 228iexport_data_proto(ioparm);
6de9cd9a 229
6de9cd9a 230extern namelist_info * ionml;
7d7b8bfe 231internal_proto(ionml);
6de9cd9a
DN
232
233typedef struct
234{
235 unit_access access;
236 unit_action action;
237 unit_blank blank;
238 unit_delim delim;
239 unit_form form;
240 int is_notpadded;
241 unit_position position;
242 unit_status status;
243 unit_pad pad;
244}
245unit_flags;
246
247
0376d694
FXC
248/* The default value of record length for preconnected units is defined
249 here. This value can be overriden by an environment variable.
250 Default value is 1 Gb. */
6de9cd9a 251
0376d694 252#define DEFAULT_RECL 1073741824
6de9cd9a
DN
253
254
909087e0 255typedef struct gfc_unit
6de9cd9a
DN
256{
257 int unit_number;
258
259 stream *s;
260
909087e0 261 struct gfc_unit *left, *right; /* Treap links. */
6de9cd9a
DN
262 int priority;
263
264 int read_bad, current_record;
265 enum
266 { NO_ENDFILE, AT_ENDFILE, AFTER_ENDFILE }
267 endfile;
268
55948b69 269 unit_mode mode;
6de9cd9a 270 unit_flags flags;
81f4be3c 271 gfc_offset recl, last_record, maxrec, bytes_left;
6de9cd9a
DN
272
273 /* recl -- Record length of the file.
274 last_record -- Last record number read or written
275 maxrec -- Maximum record number in a direct access file
276 bytes_left -- Bytes left in current record. */
277
278 int file_len;
279 char file[1]; /* Filename is allocated at the end of the structure. */
280}
909087e0 281gfc_unit;
6de9cd9a
DN
282
283/* Global variables. Putting these in a structure makes it easier to
284 maintain, particularly with the constraint of a prefix. */
285
286typedef struct
287{
288 int in_library; /* Nonzero if a library call is being processed. */
289 int size; /* Bytes processed by the current data-transfer statement. */
81f4be3c 290 gfc_offset max_offset; /* Maximum file offset. */
6de9cd9a
DN
291 int item_count; /* Item number in a formatted data transfer. */
292 int reversion_flag; /* Format reversion has occurred. */
293 int first_item;
294
909087e0 295 gfc_unit *unit_root;
6de9cd9a
DN
296 int seen_dollar;
297
55948b69 298 unit_mode mode;
6de9cd9a
DN
299
300 unit_blank blank_status;
301 enum {SIGN_S, SIGN_SS, SIGN_SP} sign_status;
302 int scale_factor;
303 jmp_buf eof_jump;
304}
305global_t;
306
6de9cd9a 307extern global_t g;
7d7b8bfe 308internal_proto(g);
6de9cd9a 309
909087e0 310extern gfc_unit *current_unit;
7d7b8bfe 311internal_proto(current_unit);
6de9cd9a
DN
312
313/* Format tokens. Only about half of these can be stored in the
314 format nodes. */
315
316typedef enum
317{
318 FMT_NONE = 0, FMT_UNKNOWN, FMT_SIGNED_INT, FMT_ZERO, FMT_POSINT, FMT_PERIOD,
319 FMT_COMMA, FMT_COLON, FMT_SLASH, FMT_DOLLAR, FMT_T, FMT_TR, FMT_TL,
320 FMT_LPAREN, FMT_RPAREN, FMT_X, FMT_S, FMT_SS, FMT_SP, FMT_STRING,
321 FMT_BADSTRING, FMT_P, FMT_I, FMT_B, FMT_BN, FMT_BZ, FMT_O, FMT_Z, FMT_F,
322 FMT_E, FMT_EN, FMT_ES, FMT_G, FMT_L, FMT_A, FMT_D, FMT_H, FMT_END
323}
324format_token;
325
326
327/* Format nodes. A format string is converted into a tree of these
328 structures, which is traversed as part of a data transfer statement. */
329
330typedef struct fnode
331{
332 format_token format;
333 int repeat;
334 struct fnode *next;
335 char *source;
336
337 union
338 {
339 struct
340 {
341 int w, d, e;
342 }
343 real;
344
345 struct
346 {
347 int length;
348 char *p;
349 }
350 string;
351
352 struct
353 {
354 int w, m;
355 }
356 integer;
357
358 int w;
359 int k;
360 int r;
361 int n;
362
363 struct fnode *child;
364 }
365 u;
366
367 /* Members for traversing the tree during data transfer. */
368
369 int count;
370 struct fnode *current;
371
372}
373fnode;
374
375
376/* unix.c */
377
7d7b8bfe
RH
378extern int move_pos_offset (stream *, int);
379internal_proto(move_pos_offset);
6de9cd9a 380
7d7b8bfe
RH
381extern int compare_files (stream *, stream *);
382internal_proto(compare_files);
6de9cd9a 383
7d7b8bfe
RH
384extern stream *init_error_stream (void);
385internal_proto(init_error_stream);
6de9cd9a 386
7d7b8bfe
RH
387extern stream *open_external (unit_flags *);
388internal_proto(open_external);
6de9cd9a 389
7d7b8bfe
RH
390extern stream *open_internal (char *, int);
391internal_proto(open_internal);
6de9cd9a 392
7d7b8bfe
RH
393extern stream *input_stream (void);
394internal_proto(input_stream);
6de9cd9a 395
7d7b8bfe
RH
396extern stream *output_stream (void);
397internal_proto(output_stream);
6de9cd9a 398
fbac3363
DE
399extern stream *error_stream (void);
400internal_proto(error_stream);
401
7d7b8bfe
RH
402extern int compare_file_filename (stream *, const char *, int);
403internal_proto(compare_file_filename);
6de9cd9a 404
7d7b8bfe
RH
405extern gfc_unit *find_file (void);
406internal_proto(find_file);
6de9cd9a 407
7d7b8bfe
RH
408extern int stream_at_bof (stream *);
409internal_proto(stream_at_bof);
6de9cd9a 410
7d7b8bfe
RH
411extern int stream_at_eof (stream *);
412internal_proto(stream_at_eof);
6de9cd9a 413
7d7b8bfe
RH
414extern int delete_file (gfc_unit *);
415internal_proto(delete_file);
6de9cd9a 416
7d7b8bfe
RH
417extern int file_exists (void);
418internal_proto(file_exists);
6de9cd9a 419
7d7b8bfe
RH
420extern const char *inquire_sequential (const char *, int);
421internal_proto(inquire_sequential);
6de9cd9a 422
7d7b8bfe
RH
423extern const char *inquire_direct (const char *, int);
424internal_proto(inquire_direct);
6de9cd9a 425
7d7b8bfe
RH
426extern const char *inquire_formatted (const char *, int);
427internal_proto(inquire_formatted);
6de9cd9a 428
7d7b8bfe
RH
429extern const char *inquire_unformatted (const char *, int);
430internal_proto(inquire_unformatted);
6de9cd9a 431
7d7b8bfe
RH
432extern const char *inquire_read (const char *, int);
433internal_proto(inquire_read);
6de9cd9a 434
7d7b8bfe
RH
435extern const char *inquire_write (const char *, int);
436internal_proto(inquire_write);
6de9cd9a 437
7d7b8bfe
RH
438extern const char *inquire_readwrite (const char *, int);
439internal_proto(inquire_readwrite);
6de9cd9a 440
7d7b8bfe
RH
441extern gfc_offset file_length (stream *);
442internal_proto(file_length);
6de9cd9a 443
7d7b8bfe
RH
444extern gfc_offset file_position (stream *);
445internal_proto(file_position);
6de9cd9a 446
7d7b8bfe
RH
447extern int is_seekable (stream *);
448internal_proto(is_seekable);
6de9cd9a 449
7d7b8bfe
RH
450extern void empty_internal_buffer(stream *);
451internal_proto(empty_internal_buffer);
6de9cd9a 452
7d7b8bfe
RH
453extern try flush (stream *);
454internal_proto(flush);
6de9cd9a 455
7d7b8bfe
RH
456extern int unit_to_fd (int);
457internal_proto(unit_to_fd);
6de9cd9a
DN
458
459/* unit.c */
460
7d7b8bfe
RH
461extern void insert_unit (gfc_unit *);
462internal_proto(insert_unit);
6de9cd9a 463
7d7b8bfe
RH
464extern int close_unit (gfc_unit *);
465internal_proto(close_unit);
6de9cd9a 466
7d7b8bfe
RH
467extern int is_internal_unit (void);
468internal_proto(is_internal_unit);
6de9cd9a 469
7d7b8bfe
RH
470extern gfc_unit *find_unit (int);
471internal_proto(find_unit);
6de9cd9a 472
7d7b8bfe
RH
473extern gfc_unit *get_unit (int);
474internal_proto(get_unit);
6de9cd9a
DN
475
476/* open.c */
477
7d7b8bfe
RH
478extern void test_endfile (gfc_unit *);
479internal_proto(test_endfile);
6de9cd9a 480
7d7b8bfe
RH
481extern void new_unit (unit_flags *);
482internal_proto(new_unit);
6de9cd9a
DN
483
484/* format.c */
485
7d7b8bfe
RH
486extern void parse_format (void);
487internal_proto(parse_format);
6de9cd9a 488
7d7b8bfe
RH
489extern fnode *next_format (void);
490internal_proto(next_format);
6de9cd9a 491
7d7b8bfe
RH
492extern void unget_format (fnode *);
493internal_proto(unget_format);
6de9cd9a 494
7d7b8bfe
RH
495extern void format_error (fnode *, const char *);
496internal_proto(format_error);
6de9cd9a 497
7d7b8bfe
RH
498extern void free_fnodes (void);
499internal_proto(free_fnodes);
6de9cd9a
DN
500
501/* transfer.c */
502
503#define SCRATCH_SIZE 300
504
6de9cd9a 505extern char scratch[];
7d7b8bfe 506internal_proto(scratch);
6de9cd9a 507
7d7b8bfe
RH
508extern const char *type_name (bt);
509internal_proto(type_name);
6de9cd9a 510
7d7b8bfe
RH
511extern void *read_block (int *);
512internal_proto(read_block);
6de9cd9a 513
7d7b8bfe
RH
514extern void *write_block (int);
515internal_proto(write_block);
6de9cd9a 516
7d7b8bfe
RH
517extern void next_record (int);
518internal_proto(next_record);
6de9cd9a
DN
519
520/* read.c */
521
7d7b8bfe
RH
522extern void set_integer (void *, int64_t, int);
523internal_proto(set_integer);
6de9cd9a 524
7d7b8bfe
RH
525extern uint64_t max_value (int, int);
526internal_proto(max_value);
6de9cd9a 527
7d7b8bfe
RH
528extern int convert_real (void *, const char *, int);
529internal_proto(convert_real);
6de9cd9a 530
7d7b8bfe
RH
531extern void read_a (fnode *, char *, int);
532internal_proto(read_a);
6de9cd9a 533
7d7b8bfe
RH
534extern void read_f (fnode *, char *, int);
535internal_proto(read_f);
6de9cd9a 536
7d7b8bfe
RH
537extern void read_l (fnode *, char *, int);
538internal_proto(read_l);
6de9cd9a 539
7d7b8bfe
RH
540extern void read_x (fnode *);
541internal_proto(read_x);
6de9cd9a 542
7d7b8bfe
RH
543extern void read_radix (fnode *, char *, int, int);
544internal_proto(read_radix);
6de9cd9a 545
7d7b8bfe
RH
546extern void read_decimal (fnode *, char *, int);
547internal_proto(read_decimal);
6de9cd9a
DN
548
549/* list_read.c */
550
7d7b8bfe
RH
551extern void list_formatted_read (bt, void *, int);
552internal_proto(list_formatted_read);
6de9cd9a 553
7d7b8bfe
RH
554extern void finish_list_read (void);
555internal_proto(finish_list_read);
6de9cd9a 556
7d7b8bfe
RH
557extern void init_at_eol();
558internal_proto(init_at_eol);
6de9cd9a 559
7d7b8bfe
RH
560extern void namelist_read();
561internal_proto(namelist_read);
6de9cd9a 562
7d7b8bfe
RH
563extern void namelist_write();
564internal_proto(namelist_write);
6de9cd9a
DN
565
566/* write.c */
567
7d7b8bfe
RH
568extern void write_a (fnode *, const char *, int);
569internal_proto(write_a);
6de9cd9a 570
7d7b8bfe
RH
571extern void write_b (fnode *, const char *, int);
572internal_proto(write_b);
6de9cd9a 573
7d7b8bfe
RH
574extern void write_d (fnode *, const char *, int);
575internal_proto(write_d);
6de9cd9a 576
7d7b8bfe
RH
577extern void write_e (fnode *, const char *, int);
578internal_proto(write_e);
6de9cd9a 579
7d7b8bfe
RH
580extern void write_en (fnode *, const char *, int);
581internal_proto(write_en);
6de9cd9a 582
7d7b8bfe
RH
583extern void write_es (fnode *, const char *, int);
584internal_proto(write_es);
6de9cd9a 585
7d7b8bfe
RH
586extern void write_f (fnode *, const char *, int);
587internal_proto(write_f);
6de9cd9a 588
7d7b8bfe
RH
589extern void write_i (fnode *, const char *, int);
590internal_proto(write_i);
6de9cd9a 591
7d7b8bfe
RH
592extern void write_l (fnode *, char *, int);
593internal_proto(write_l);
6de9cd9a 594
7d7b8bfe
RH
595extern void write_o (fnode *, const char *, int);
596internal_proto(write_o);
6de9cd9a 597
7d7b8bfe
RH
598extern void write_x (fnode *);
599internal_proto(write_x);
6de9cd9a 600
7d7b8bfe
RH
601extern void write_z (fnode *, const char *, int);
602internal_proto(write_z);
6de9cd9a 603
7d7b8bfe
RH
604extern void list_formatted_write (bt, void *, int);
605internal_proto(list_formatted_write);
6de9cd9a
DN
606
607#endif