OSDN Git Service

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