1 /* Copyright (C) 2009-2019 Free Software Foundation, Inc. 2 Contributed by Janne Blomqvist 3 4 This file is part of the GNU Fortran 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 3, 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 Under Section 7 of GPL version 3, you are granted additional 17 permissions described in the GCC Runtime Library Exception, version 18 3.1, as published by the Free Software Foundation. 19 20 You should have received a copy of the GNU General Public License and 21 a copy of the GCC Runtime Library Exception along with this program; 22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 23 <http://www.gnu.org/licenses/>. */ 24 25 #ifndef GFOR_FORMAT_H 26 #define GFOR_FORMAT_H 27 28 #include "io.h" 29 30 31 /* Format tokens. Only about half of these can be stored in the 32 format nodes. */ 33 34 typedef enum 35 { 36 FMT_NONE = 0, FMT_UNKNOWN, FMT_SIGNED_INT, FMT_ZERO, FMT_POSINT, FMT_PERIOD, 37 FMT_COMMA, FMT_COLON, FMT_SLASH, FMT_DOLLAR, FMT_T, FMT_TR, FMT_TL, 38 FMT_LPAREN, FMT_RPAREN, FMT_X, FMT_S, FMT_SS, FMT_SP, FMT_STRING, 39 FMT_BADSTRING, FMT_P, FMT_I, FMT_B, FMT_BN, FMT_BZ, FMT_O, FMT_Z, FMT_F, 40 FMT_E, FMT_EN, FMT_ES, FMT_G, FMT_L, FMT_A, FMT_D, FMT_H, FMT_END, FMT_DC, 41 FMT_DP, FMT_STAR, FMT_RC, FMT_RD, FMT_RN, FMT_RP, FMT_RU, FMT_RZ, FMT_DT 42 } 43 format_token; 44 45 46 /* Format nodes. A format string is converted into a tree of these 47 structures, which is traversed as part of a data transfer statement. */ 48 49 struct fnode 50 { 51 format_token format; 52 int repeat; 53 struct fnode *next; 54 char *source; 55 56 union 57 { 58 struct 59 { 60 int w, d, e; 61 } 62 real; 63 64 struct 65 { 66 int length; 67 char *p; 68 } 69 string; 70 71 struct 72 { 73 int w, m; 74 } 75 integer; 76 77 struct 78 { 79 char *string; 80 int string_len; 81 gfc_full_array_i4 *vlist; 82 } 83 udf; /* User Defined Format. */ 84 85 int w; 86 int k; 87 int r; 88 int n; 89 90 struct fnode *child; 91 } 92 u; 93 94 /* Members for traversing the tree during data transfer. */ 95 96 int count; 97 struct fnode *current; 98 99 }; 100 101 102 /* A storage structures for format node data. */ 103 104 #define FARRAY_SIZE 64 105 106 typedef struct fnode_array 107 { 108 struct fnode_array *next; 109 fnode array[FARRAY_SIZE]; 110 } 111 fnode_array; 112 113 114 typedef struct format_data 115 { 116 char *format_string, *string; 117 const char *error; 118 char error_element; 119 format_token saved_token; 120 int value, format_string_len, reversion_ok; 121 fnode *avail; 122 const fnode *saved_format; 123 fnode_array *last; 124 fnode_array array; 125 } 126 format_data; 127 128 extern void parse_format (st_parameter_dt *); 129 internal_proto(parse_format); 130 131 extern const fnode *next_format (st_parameter_dt *); 132 internal_proto(next_format); 133 134 extern void unget_format (st_parameter_dt *, const fnode *); 135 internal_proto(unget_format); 136 137 extern void format_error (st_parameter_dt *, const fnode *, const char *); 138 internal_proto(format_error); 139 140 extern void free_format_data (struct format_data *); 141 internal_proto(free_format_data); 142 143 extern void free_format (st_parameter_dt *); 144 internal_proto(free_format); 145 146 extern void free_format_hash_table (gfc_unit *); 147 internal_proto(free_format_hash_table); 148 149 extern void init_format_hash (st_parameter_dt *); 150 internal_proto(init_format_hash); 151 152 extern void free_format_hash (st_parameter_dt *); 153 internal_proto(free_format_hash); 154 155 #endif 156