OSDN Git Service

2005-12-05 Richard Guenther <rguenther@suse.de>
[pf3gnuchains/gcc-fork.git] / libgfortran / io / io.h
1 /* Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
2    Contributed by Andy Vaught
3
4 This file is part of the GNU Fortran 95 runtime library (libgfortran).
5
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)
9 any later version.
10
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.
15
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, 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.  */
20
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
28 #ifndef GFOR_IO_H
29 #define GFOR_IO_H
30
31 /* IO library include.  */
32
33 #include <setjmp.h>
34 #include "libgfortran.h"
35
36 #include <gthr.h>
37
38 #define DEFAULT_TEMPDIR "/tmp"
39
40 /* Basic types used in data transfers.  */
41
42 typedef enum
43 { BT_NULL, BT_INTEGER, BT_LOGICAL, BT_CHARACTER, BT_REAL,
44   BT_COMPLEX
45 }
46 bt;
47
48
49 typedef enum
50 { SUCCESS = 1, FAILURE }
51 try;
52
53 struct st_parameter_dt;
54
55 typedef struct stream
56 {
57   char *(*alloc_w_at) (struct stream *, int *, gfc_offset);
58   char *(*alloc_r_at) (struct stream *, int *, gfc_offset);
59   try (*sfree) (struct stream *);
60   try (*close) (struct stream *);
61   try (*seek) (struct stream *, gfc_offset);
62   try (*truncate) (struct stream *);
63   int (*read) (struct stream *, void *, size_t *);
64   int (*write) (struct stream *, const void *, size_t *);
65 }
66 stream;
67
68
69 /* Macros for doing file I/O given a stream.  */
70
71 #define sfree(s) ((s)->sfree)(s)
72 #define sclose(s) ((s)->close)(s)
73
74 #define salloc_r(s, len) ((s)->alloc_r_at)(s, len, -1)
75 #define salloc_w(s, len) ((s)->alloc_w_at)(s, len, -1)
76
77 #define salloc_r_at(s, len, where) ((s)->alloc_r_at)(s, len, where)
78 #define salloc_w_at(s, len, where) ((s)->alloc_w_at)(s, len, where)
79
80 #define sseek(s, pos) ((s)->seek)(s, pos)
81 #define struncate(s) ((s)->truncate)(s)
82 #define sread(s, buf, nbytes) ((s)->read)(s, buf, nbytes)
83 #define swrite(s, buf, nbytes) ((s)->write)(s, buf, nbytes)
84
85 /* The array_loop_spec contains the variables for the loops over index ranges
86    that are encountered.  Since the variables can be negative, ssize_t
87    is used.  */
88
89 typedef struct array_loop_spec
90 {
91   /* Index counter for this dimension.  */
92   ssize_t idx;
93
94   /* Start for the index counter.  */
95   ssize_t start;
96
97   /* End for the index counter.  */
98   ssize_t end;
99
100   /* Step for the index counter.  */
101   ssize_t step;
102 }
103 array_loop_spec;
104
105 /* Representation of a namelist object in libgfortran
106
107    Namelist Records
108       &GROUPNAME  OBJECT=value[s] [,OBJECT=value[s]].../
109      or
110       &GROUPNAME  OBJECT=value[s] [,OBJECT=value[s]]...&END
111
112    The object can be a fully qualified, compound name for an instrinsic
113    type, derived types or derived type components.  So, a substring
114    a(:)%b(4)%ch(2:4)(1:7) has to be treated correctly in namelist
115    read. Hence full information about the structure of the object has
116    to be available to list_read.c and write.
117
118    These requirements are met by the following data structures.
119
120    namelist_info type contains all the scalar information about the
121    object and arrays of descriptor_dimension and array_loop_spec types for
122    arrays.  */
123
124 typedef struct namelist_type
125 {
126
127   /* Object type, stored as GFC_DTYPE_xxxx.  */
128   bt type;
129
130   /* Object name.  */
131   char * var_name;
132
133   /* Address for the start of the object's data.  */
134   void * mem_pos;
135
136   /* Flag to show that a read is to be attempted for this node.  */
137   int touched;
138
139   /* Length of intrinsic type in bytes.  */
140   int len;
141
142   /* Rank of the object.  */
143   int var_rank;
144
145   /* Overall size of the object in bytes.  */
146   index_type size;
147
148   /* Length of character string.  */
149   index_type string_length;
150
151   descriptor_dimension * dim;
152   array_loop_spec * ls;
153   struct namelist_type * next;
154 }
155 namelist_info;
156
157 /* Options for the OPEN statement.  */
158
159 typedef enum
160 { ACCESS_SEQUENTIAL, ACCESS_DIRECT, ACCESS_APPEND,
161   ACCESS_UNSPECIFIED
162 }
163 unit_access;
164
165 typedef enum
166 { ACTION_READ, ACTION_WRITE, ACTION_READWRITE,
167   ACTION_UNSPECIFIED
168 }
169 unit_action;
170
171 typedef enum
172 { BLANK_NULL, BLANK_ZERO, BLANK_UNSPECIFIED }
173 unit_blank;
174
175 typedef enum
176 { DELIM_NONE, DELIM_APOSTROPHE, DELIM_QUOTE,
177   DELIM_UNSPECIFIED
178 }
179 unit_delim;
180
181 typedef enum
182 { FORM_FORMATTED, FORM_UNFORMATTED, FORM_UNSPECIFIED }
183 unit_form;
184
185 typedef enum
186 { POSITION_ASIS, POSITION_REWIND, POSITION_APPEND,
187   POSITION_UNSPECIFIED
188 }
189 unit_position;
190
191 typedef enum
192 { STATUS_UNKNOWN, STATUS_OLD, STATUS_NEW, STATUS_SCRATCH,
193   STATUS_REPLACE, STATUS_UNSPECIFIED
194 }
195 unit_status;
196
197 typedef enum
198 { PAD_YES, PAD_NO, PAD_UNSPECIFIED }
199 unit_pad;
200
201 typedef enum
202 { ADVANCE_YES, ADVANCE_NO, ADVANCE_UNSPECIFIED }
203 unit_advance;
204
205 typedef enum
206 {READING, WRITING}
207 unit_mode;
208
209 #define CHARACTER1(name) \
210               char * name; \
211               gfc_charlen_type name ## _len
212 #define CHARACTER2(name) \
213               gfc_charlen_type name ## _len; \
214               char * name
215
216 #define IOPARM_LIBRETURN_MASK           (3 << 0)
217 #define IOPARM_LIBRETURN_OK             (0 << 0)
218 #define IOPARM_LIBRETURN_ERROR          (1 << 0)
219 #define IOPARM_LIBRETURN_END            (2 << 0)
220 #define IOPARM_LIBRETURN_EOR            (3 << 0)
221 #define IOPARM_ERR                      (1 << 2)
222 #define IOPARM_END                      (1 << 3)
223 #define IOPARM_EOR                      (1 << 4)
224 #define IOPARM_HAS_IOSTAT               (1 << 5)
225 #define IOPARM_HAS_IOMSG                (1 << 6)
226
227 #define IOPARM_COMMON_MASK              ((1 << 7) - 1)
228
229 typedef struct st_parameter_common
230 {
231   GFC_INTEGER_4 flags;
232   GFC_INTEGER_4 unit;
233   const char *filename;
234   GFC_INTEGER_4 line;
235   CHARACTER2 (iomsg);
236   GFC_INTEGER_4 *iostat;
237 }
238 st_parameter_common;
239
240 #define IOPARM_OPEN_HAS_RECL_IN         (1 << 7)
241 #define IOPARM_OPEN_HAS_FILE            (1 << 8)
242 #define IOPARM_OPEN_HAS_STATUS          (1 << 9)
243 #define IOPARM_OPEN_HAS_ACCESS          (1 << 10)
244 #define IOPARM_OPEN_HAS_FORM            (1 << 11)
245 #define IOPARM_OPEN_HAS_BLANK           (1 << 12)
246 #define IOPARM_OPEN_HAS_POSITION        (1 << 13)
247 #define IOPARM_OPEN_HAS_ACTION          (1 << 14)
248 #define IOPARM_OPEN_HAS_DELIM           (1 << 15)
249 #define IOPARM_OPEN_HAS_PAD             (1 << 16)
250
251 typedef struct
252 {
253   st_parameter_common common;
254   GFC_INTEGER_4 recl_in;
255   CHARACTER2 (file);
256   CHARACTER1 (status);
257   CHARACTER2 (access);
258   CHARACTER1 (form);
259   CHARACTER2 (blank);
260   CHARACTER1 (position);
261   CHARACTER2 (action);
262   CHARACTER1 (delim);
263   CHARACTER2 (pad);
264 }
265 st_parameter_open;
266
267 #define IOPARM_CLOSE_HAS_STATUS         (1 << 7)
268
269 typedef struct
270 {
271   st_parameter_common common;
272   CHARACTER1 (status);
273 }
274 st_parameter_close;
275
276 typedef struct
277 {
278   st_parameter_common common;
279 }
280 st_parameter_filepos;
281
282 #define IOPARM_INQUIRE_HAS_EXIST        (1 << 7)
283 #define IOPARM_INQUIRE_HAS_OPENED       (1 << 8)
284 #define IOPARM_INQUIRE_HAS_NUMBER       (1 << 9)
285 #define IOPARM_INQUIRE_HAS_NAMED        (1 << 10)
286 #define IOPARM_INQUIRE_HAS_NEXTREC      (1 << 11)
287 #define IOPARM_INQUIRE_HAS_RECL_OUT     (1 << 12)
288 #define IOPARM_INQUIRE_HAS_FILE         (1 << 13)
289 #define IOPARM_INQUIRE_HAS_ACCESS       (1 << 14)
290 #define IOPARM_INQUIRE_HAS_FORM         (1 << 15)
291 #define IOPARM_INQUIRE_HAS_BLANK        (1 << 16)
292 #define IOPARM_INQUIRE_HAS_POSITION     (1 << 17)
293 #define IOPARM_INQUIRE_HAS_ACTION       (1 << 18)
294 #define IOPARM_INQUIRE_HAS_DELIM        (1 << 19)
295 #define IOPARM_INQUIRE_HAS_PAD          (1 << 20)
296 #define IOPARM_INQUIRE_HAS_NAME         (1 << 21)
297 #define IOPARM_INQUIRE_HAS_SEQUENTIAL   (1 << 22)
298 #define IOPARM_INQUIRE_HAS_DIRECT       (1 << 23)
299 #define IOPARM_INQUIRE_HAS_FORMATTED    (1 << 24)
300 #define IOPARM_INQUIRE_HAS_UNFORMATTED  (1 << 25)
301 #define IOPARM_INQUIRE_HAS_READ         (1 << 26)
302 #define IOPARM_INQUIRE_HAS_WRITE        (1 << 27)
303 #define IOPARM_INQUIRE_HAS_READWRITE    (1 << 28)
304
305 typedef struct
306 {
307   st_parameter_common common;
308   GFC_INTEGER_4 *exist, *opened, *number, *named;
309   GFC_INTEGER_4 *nextrec, *recl_out;
310   CHARACTER1 (file);
311   CHARACTER2 (access);
312   CHARACTER1 (form);
313   CHARACTER2 (blank);
314   CHARACTER1 (position);
315   CHARACTER2 (action);
316   CHARACTER1 (delim);
317   CHARACTER2 (pad);
318   CHARACTER1 (name);
319   CHARACTER2 (sequential);
320   CHARACTER1 (direct);
321   CHARACTER2 (formatted);
322   CHARACTER1 (unformatted);
323   CHARACTER2 (read);
324   CHARACTER1 (write);
325   CHARACTER2 (readwrite);
326 }
327 st_parameter_inquire;
328
329 struct gfc_unit;
330 struct format_data;
331
332 #define IOPARM_DT_LIST_FORMAT                   (1 << 7)
333 #define IOPARM_DT_NAMELIST_READ_MODE            (1 << 8)
334 #define IOPARM_DT_HAS_REC                       (1 << 9)
335 #define IOPARM_DT_HAS_SIZE                      (1 << 10)
336 #define IOPARM_DT_HAS_IOLENGTH                  (1 << 11)
337 #define IOPARM_DT_HAS_FORMAT                    (1 << 12)
338 #define IOPARM_DT_HAS_ADVANCE                   (1 << 13)
339 #define IOPARM_DT_HAS_INTERNAL_UNIT             (1 << 14)
340 #define IOPARM_DT_HAS_NAMELIST_NAME             (1 << 15)
341 /* Internal use bit.  */
342 #define IOPARM_DT_IONML_SET                     (1 << 31)
343
344 typedef struct st_parameter_dt
345 {
346   st_parameter_common common;
347   GFC_INTEGER_4 rec;
348   GFC_INTEGER_4 *size, *iolength;
349   gfc_array_char *internal_unit_desc;
350   CHARACTER1 (format);
351   CHARACTER2 (advance);
352   CHARACTER1 (internal_unit);
353   CHARACTER2 (namelist_name);
354   /* Private part of the structure.  The compiler just needs
355      to reserve enough space.  */
356   union
357     {
358       struct
359         {
360           void (*transfer) (struct st_parameter_dt *, bt, void *, int,
361                             size_t, size_t);
362           struct gfc_unit *current_unit;
363           int item_count; /* Item number in a formatted data transfer.  */
364           unit_mode mode;
365           unit_blank blank_status;
366           enum {SIGN_S, SIGN_SS, SIGN_SP} sign_status;
367           int scale_factor;
368           int max_pos; /* Maximum righthand column written to.  */
369           /* Number of skips + spaces to be done for T and X-editing.  */
370           int skips;
371           /* Number of spaces to be done for T and X-editing.  */
372           int pending_spaces;
373           /* Whether an EOR condition was encountered. Value is:
374                0 if no EOR was encountered
375                1 if an EOR was encountered due to a 1-byte marker (LF)
376                2 if an EOR was encountered due to a 2-bytes marker (CRLF) */
377           int sf_seen_eor;
378           unit_advance advance_status;
379
380           unsigned reversion_flag : 1; /* Format reversion has occurred.  */
381           unsigned first_item : 1;
382           unsigned seen_dollar : 1;
383           unsigned eor_condition : 1;
384           unsigned no_leading_blank : 1;
385           unsigned char_flag : 1;
386           unsigned input_complete : 1;
387           unsigned at_eol : 1;
388           unsigned comma_flag : 1;
389           /* A namelist specific flag used in the list directed library
390              to flag that calls are being made from namelist read (eg. to
391              ignore comments or to treat '/' as a terminator)  */
392           unsigned namelist_mode : 1;
393           /* A namelist specific flag used in the list directed library
394              to flag read errors and return, so that an attempt can be
395              made to read a new object name.  */
396           unsigned nml_read_error : 1;
397           /* 20 unused bits.  */
398
399           char last_char;
400           char nml_delim;
401
402           int repeat_count;
403           int saved_length;
404           int saved_used;
405           bt saved_type;
406           char *saved_string;
407           char *scratch;
408           char *line_buffer;
409           struct format_data *fmt;
410           jmp_buf *eof_jump;
411           namelist_info *ionml;
412
413           /* Storage area for values except for strings.  Must be large
414              enough to hold a complex value (two reals) of the largest
415              kind.  */
416           char value[32];
417         } p;
418       char pad[16 * sizeof (char *) + 32 * sizeof (int)];
419     } u;
420 }
421 st_parameter_dt;
422
423 #undef CHARACTER1
424 #undef CHARACTER2
425
426 typedef struct
427 {
428   unit_access access;
429   unit_action action;
430   unit_blank blank;
431   unit_delim delim;
432   unit_form form;
433   int is_notpadded;
434   unit_position position;
435   unit_status status;
436   unit_pad pad;
437 }
438 unit_flags;
439
440
441 /* The default value of record length for preconnected units is defined
442    here. This value can be overriden by an environment variable.
443    Default value is 1 Gb.  */
444
445 #define DEFAULT_RECL 1073741824
446
447
448 typedef struct gfc_unit
449 {
450   int unit_number;
451   stream *s;
452   
453   /* Treap links.  */
454   struct gfc_unit *left, *right;
455   int priority;
456
457   int read_bad, current_record;
458   enum
459   { NO_ENDFILE, AT_ENDFILE, AFTER_ENDFILE }
460   endfile;
461
462   unit_mode mode;
463   unit_flags flags;
464
465   /* recl           -- Record length of the file.
466      last_record    -- Last record number read or written
467      maxrec         -- Maximum record number in a direct access file
468      bytes_left     -- Bytes left in current record.  */
469   gfc_offset recl, last_record, maxrec, bytes_left;
470
471   __gthread_mutex_t lock;
472   /* Number of threads waiting to acquire this unit's lock.
473      When non-zero, close_unit doesn't only removes the unit
474      from the UNIT_ROOT tree, but doesn't free it and the
475      last of the waiting threads will do that.
476      This must be either atomically increased/decreased, or
477      always guarded by UNIT_LOCK.  */
478   int waiting;
479   /* Flag set by close_unit if the unit as been closed.
480      Must be manipulated under unit's lock.  */
481   int closed;
482
483   /* For traversing arrays */
484   array_loop_spec *ls;
485   int rank;
486
487   int file_len;
488   char *file;
489 }
490 gfc_unit;
491
492 /* Format tokens.  Only about half of these can be stored in the
493    format nodes.  */
494
495 typedef enum
496 {
497   FMT_NONE = 0, FMT_UNKNOWN, FMT_SIGNED_INT, FMT_ZERO, FMT_POSINT, FMT_PERIOD,
498   FMT_COMMA, FMT_COLON, FMT_SLASH, FMT_DOLLAR, FMT_T, FMT_TR, FMT_TL,
499   FMT_LPAREN, FMT_RPAREN, FMT_X, FMT_S, FMT_SS, FMT_SP, FMT_STRING,
500   FMT_BADSTRING, FMT_P, FMT_I, FMT_B, FMT_BN, FMT_BZ, FMT_O, FMT_Z, FMT_F,
501   FMT_E, FMT_EN, FMT_ES, FMT_G, FMT_L, FMT_A, FMT_D, FMT_H, FMT_END
502 }
503 format_token;
504
505
506 /* Format nodes.  A format string is converted into a tree of these
507    structures, which is traversed as part of a data transfer statement.  */
508
509 typedef struct fnode
510 {
511   format_token format;
512   int repeat;
513   struct fnode *next;
514   char *source;
515
516   union
517   {
518     struct
519     {
520       int w, d, e;
521     }
522     real;
523
524     struct
525     {
526       int length;
527       char *p;
528     }
529     string;
530
531     struct
532     {
533       int w, m;
534     }
535     integer;
536
537     int w;
538     int k;
539     int r;
540     int n;
541
542     struct fnode *child;
543   }
544   u;
545
546   /* Members for traversing the tree during data transfer.  */
547
548   int count;
549   struct fnode *current;
550
551 }
552 fnode;
553
554
555 /* unix.c */
556
557 extern int move_pos_offset (stream *, int);
558 internal_proto(move_pos_offset);
559
560 extern int compare_files (stream *, stream *);
561 internal_proto(compare_files);
562
563 extern stream *open_external (st_parameter_open *, unit_flags *);
564 internal_proto(open_external);
565
566 extern stream *open_internal (char *, int);
567 internal_proto(open_internal);
568
569 extern stream *input_stream (void);
570 internal_proto(input_stream);
571
572 extern stream *output_stream (void);
573 internal_proto(output_stream);
574
575 extern stream *error_stream (void);
576 internal_proto(error_stream);
577
578 extern int compare_file_filename (gfc_unit *, const char *, int);
579 internal_proto(compare_file_filename);
580
581 extern gfc_unit *find_file (const char *file, gfc_charlen_type file_len);
582 internal_proto(find_file);
583
584 extern void flush_all_units (void);
585 internal_proto(flush_all_units);
586
587 extern int stream_at_bof (stream *);
588 internal_proto(stream_at_bof);
589
590 extern int stream_at_eof (stream *);
591 internal_proto(stream_at_eof);
592
593 extern int delete_file (gfc_unit *);
594 internal_proto(delete_file);
595
596 extern int file_exists (const char *file, gfc_charlen_type file_len);
597 internal_proto(file_exists);
598
599 extern const char *inquire_sequential (const char *, int);
600 internal_proto(inquire_sequential);
601
602 extern const char *inquire_direct (const char *, int);
603 internal_proto(inquire_direct);
604
605 extern const char *inquire_formatted (const char *, int);
606 internal_proto(inquire_formatted);
607
608 extern const char *inquire_unformatted (const char *, int);
609 internal_proto(inquire_unformatted);
610
611 extern const char *inquire_read (const char *, int);
612 internal_proto(inquire_read);
613
614 extern const char *inquire_write (const char *, int);
615 internal_proto(inquire_write);
616
617 extern const char *inquire_readwrite (const char *, int);
618 internal_proto(inquire_readwrite);
619
620 extern gfc_offset file_length (stream *);
621 internal_proto(file_length);
622
623 extern gfc_offset file_position (stream *);
624 internal_proto(file_position);
625
626 extern int is_seekable (stream *);
627 internal_proto(is_seekable);
628
629 extern int is_preconnected (stream *);
630 internal_proto(is_preconnected);
631
632 extern void flush_if_preconnected (stream *);
633 internal_proto(flush_if_preconnected);
634
635 extern void empty_internal_buffer(stream *);
636 internal_proto(empty_internal_buffer);
637
638 extern try flush (stream *);
639 internal_proto(flush);
640
641 extern int stream_isatty (stream *);
642 internal_proto(stream_isatty);
643
644 extern char * stream_ttyname (stream *);
645 internal_proto(stream_ttyname);
646
647 extern gfc_offset stream_offset (stream *s);
648 internal_proto(stream_offset);
649
650 extern int unit_to_fd (int);
651 internal_proto(unit_to_fd);
652
653 extern int unpack_filename (char *, const char *, int);
654 internal_proto(unpack_filename);
655
656 /* unit.c */
657
658 /* Maximum file offset, computed at library initialization time.  */
659 extern gfc_offset max_offset;
660 internal_proto(max_offset);
661
662 /* Unit tree root.  */
663 extern gfc_unit *unit_root;
664 internal_proto(unit_root);
665
666 extern __gthread_mutex_t unit_lock;
667 internal_proto(unit_lock);
668
669 extern int close_unit (gfc_unit *);
670 internal_proto(close_unit);
671
672 extern int is_internal_unit (st_parameter_dt *);
673 internal_proto(is_internal_unit);
674
675 extern int is_array_io (st_parameter_dt *);
676 internal_proto(is_array_io);
677
678 extern gfc_unit *find_unit (int);
679 internal_proto(find_unit);
680
681 extern gfc_unit *find_or_create_unit (int);
682 internal_proto(find_unit);
683
684 extern gfc_unit *get_unit (st_parameter_dt *, int);
685 internal_proto(get_unit);
686
687 extern void unlock_unit (gfc_unit *);
688 internal_proto(unlock_unit);
689
690 /* open.c */
691
692 extern void test_endfile (gfc_unit *);
693 internal_proto(test_endfile);
694
695 extern gfc_unit *new_unit (st_parameter_open *, gfc_unit *, unit_flags *);
696 internal_proto(new_unit);
697
698 /* format.c */
699
700 extern void parse_format (st_parameter_dt *);
701 internal_proto(parse_format);
702
703 extern const fnode *next_format (st_parameter_dt *);
704 internal_proto(next_format);
705
706 extern void unget_format (st_parameter_dt *, const fnode *);
707 internal_proto(unget_format);
708
709 extern void format_error (st_parameter_dt *, const fnode *, const char *);
710 internal_proto(format_error);
711
712 extern void free_format_data (st_parameter_dt *);
713 internal_proto(free_format_data);
714
715 /* transfer.c */
716
717 #define SCRATCH_SIZE 300
718
719 extern const char *type_name (bt);
720 internal_proto(type_name);
721
722 extern void *read_block (st_parameter_dt *, int *);
723 internal_proto(read_block);
724
725 extern void *write_block (st_parameter_dt *, int);
726 internal_proto(write_block);
727
728 extern gfc_offset next_array_record (st_parameter_dt *, array_loop_spec *);
729 internal_proto(next_array_record);
730
731 extern gfc_offset init_loop_spec (gfc_array_char *, array_loop_spec *);
732 internal_proto(init_loop_spec);
733
734 extern void next_record (st_parameter_dt *, int);
735 internal_proto(next_record);
736
737 /* read.c */
738
739 extern void set_integer (void *, GFC_INTEGER_LARGEST, int);
740 internal_proto(set_integer);
741
742 extern GFC_UINTEGER_LARGEST max_value (int, int);
743 internal_proto(max_value);
744
745 extern int convert_real (st_parameter_dt *, void *, const char *, int);
746 internal_proto(convert_real);
747
748 extern void read_a (st_parameter_dt *, const fnode *, char *, int);
749 internal_proto(read_a);
750
751 extern void read_f (st_parameter_dt *, const fnode *, char *, int);
752 internal_proto(read_f);
753
754 extern void read_l (st_parameter_dt *, const fnode *, char *, int);
755 internal_proto(read_l);
756
757 extern void read_x (st_parameter_dt *, int);
758 internal_proto(read_x);
759
760 extern void read_radix (st_parameter_dt *, const fnode *, char *, int, int);
761 internal_proto(read_radix);
762
763 extern void read_decimal (st_parameter_dt *, const fnode *, char *, int);
764 internal_proto(read_decimal);
765
766 /* list_read.c */
767
768 extern void list_formatted_read (st_parameter_dt *, bt, void *, int, size_t,
769                                  size_t);
770 internal_proto(list_formatted_read);
771
772 extern void finish_list_read (st_parameter_dt *);
773 internal_proto(finish_list_read);
774
775 extern void namelist_read (st_parameter_dt *);
776 internal_proto(namelist_read);
777
778 extern void namelist_write (st_parameter_dt *);
779 internal_proto(namelist_write);
780
781 /* write.c */
782
783 extern void write_a (st_parameter_dt *, const fnode *, const char *, int);
784 internal_proto(write_a);
785
786 extern void write_b (st_parameter_dt *, const fnode *, const char *, int);
787 internal_proto(write_b);
788
789 extern void write_d (st_parameter_dt *, const fnode *, const char *, int);
790 internal_proto(write_d);
791
792 extern void write_e (st_parameter_dt *, const fnode *, const char *, int);
793 internal_proto(write_e);
794
795 extern void write_en (st_parameter_dt *, const fnode *, const char *, int);
796 internal_proto(write_en);
797
798 extern void write_es (st_parameter_dt *, const fnode *, const char *, int);
799 internal_proto(write_es);
800
801 extern void write_f (st_parameter_dt *, const fnode *, const char *, int);
802 internal_proto(write_f);
803
804 extern void write_i (st_parameter_dt *, const fnode *, const char *, int);
805 internal_proto(write_i);
806
807 extern void write_l (st_parameter_dt *, const fnode *, char *, int);
808 internal_proto(write_l);
809
810 extern void write_o (st_parameter_dt *, const fnode *, const char *, int);
811 internal_proto(write_o);
812
813 extern void write_x (st_parameter_dt *, int, int);
814 internal_proto(write_x);
815
816 extern void write_z (st_parameter_dt *, const fnode *, const char *, int);
817 internal_proto(write_z);
818
819 extern void list_formatted_write (st_parameter_dt *, bt, void *, int, size_t,
820                                   size_t);
821 internal_proto(list_formatted_write);
822
823 /* error.c */
824 extern try notify_std (int, const char *);
825 internal_proto(notify_std);
826
827 /* size_from_kind.c */
828 extern size_t size_from_real_kind (int);
829 internal_proto(size_from_real_kind);
830
831 extern size_t size_from_complex_kind (int);
832 internal_proto(size_from_complex_kind);
833
834 /* lock.c */
835 extern void free_ionml (st_parameter_dt *);
836 internal_proto(free_ionml);
837
838 static inline void
839 inc_waiting_locked (gfc_unit *u)
840 {
841 #ifdef HAVE_SYNC_FETCH_AND_ADD
842   (void) __sync_fetch_and_add (&u->waiting, 1);
843 #else
844   u->waiting++;
845 #endif
846 }
847
848 static inline int
849 predec_waiting_locked (gfc_unit *u)
850 {
851 #ifdef HAVE_SYNC_FETCH_AND_ADD
852   return __sync_add_and_fetch (&u->waiting, -1);
853 #else
854   return --u->waiting;
855 #endif
856 }
857
858 static inline void
859 dec_waiting_unlocked (gfc_unit *u)
860 {
861 #ifdef HAVE_SYNC_FETCH_AND_ADD
862   (void) __sync_fetch_and_add (&u->waiting, -1);
863 #else
864   __gthread_mutex_lock (&unit_lock);
865   u->waiting--;
866   __gthread_mutex_unlock (&unit_lock);
867 #endif
868 }
869
870 #endif