]>
Commit | Line | Data |
---|---|---|
5d723e54 FXC |
1 | /* Implementation of the FGET, FGETC, FPUT and FPUTC intrinsics. |
2 | Copyright (C) 2005 Free Software Foundation, Inc. | |
3 | Contributed by François-Xavier Coudert <coudert@clipper.ens.fr> | |
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 | |
8 | modify it under the terms of the GNU General Public | |
9 | License as published by the Free Software Foundation; either | |
10 | version 2 of the License, or (at your option) any later version. | |
11 | ||
12 | In addition to the permissions in the GNU General Public License, the | |
13 | Free Software Foundation gives you unlimited permission to link the | |
14 | compiled version of this file into combinations with other programs, | |
15 | and to distribute those combinations without any restriction coming | |
16 | from the use of this file. (The General Public License restrictions | |
17 | do apply in other respects; for example, they cover modification of | |
18 | the file, and distribution when not linked into a combine | |
19 | executable.) | |
20 | ||
21 | Libgfortran is distributed in the hope that it will be useful, | |
22 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 | GNU General Public License for more details. | |
25 | ||
26 | You should have received a copy of the GNU General Public | |
27 | License along with libgfortran; see the file COPYING. If not, | |
28 | write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
29 | Boston, MA 02110-1301, USA. */ | |
30 | ||
31 | #include "config.h" | |
32 | #include "libgfortran.h" | |
33 | ||
34 | #include <string.h> | |
35 | ||
36 | #include "../io/io.h" | |
37 | ||
38 | static const int five = 5; | |
39 | static const int six = 6; | |
40 | ||
41 | extern int PREFIX(fgetc) (const int *, char *, gfc_charlen_type); | |
42 | export_proto_np(PREFIX(fgetc)); | |
43 | ||
44 | int | |
45 | PREFIX(fgetc) (const int * unit, char * c, gfc_charlen_type c_len) | |
46 | { | |
47 | int ret; | |
48 | size_t s; | |
49 | gfc_unit * u = find_unit (*unit); | |
50 | ||
51 | if (u == NULL) | |
52 | return -1; | |
53 | ||
54 | s = 1; | |
55 | memset (c, ' ', c_len); | |
56 | ret = sread (u->s, c, &s); | |
401cd90a | 57 | unlock_unit (u); |
5d723e54 FXC |
58 | |
59 | if (ret != 0) | |
60 | return ret; | |
61 | ||
62 | if (s != 1) | |
63 | return -1; | |
64 | else | |
65 | return 0; | |
66 | } | |
67 | ||
68 | ||
69 | #define FGETC_SUB(kind) \ | |
70 | extern void fgetc_i ## kind ## _sub \ | |
71 | (const int *, char *, GFC_INTEGER_ ## kind *, gfc_charlen_type); \ | |
72 | export_proto(fgetc_i ## kind ## _sub); \ | |
73 | void fgetc_i ## kind ## _sub \ | |
74 | (const int * unit, char * c, GFC_INTEGER_ ## kind * st, gfc_charlen_type c_len) \ | |
75 | { if (st != NULL) \ | |
76 | *st = PREFIX(fgetc) (unit, c, c_len); \ | |
77 | else \ | |
78 | PREFIX(fgetc) (unit, c, c_len); } | |
79 | ||
80 | FGETC_SUB(1) | |
81 | FGETC_SUB(2) | |
82 | FGETC_SUB(4) | |
83 | FGETC_SUB(8) | |
84 | ||
85 | ||
86 | extern int PREFIX(fget) (char *, gfc_charlen_type); | |
87 | export_proto_np(PREFIX(fget)); | |
88 | ||
89 | int | |
90 | PREFIX(fget) (char * c, gfc_charlen_type c_len) | |
91 | { | |
92 | return PREFIX(fgetc) (&five, c, c_len); | |
93 | } | |
94 | ||
95 | ||
96 | #define FGET_SUB(kind) \ | |
97 | extern void fget_i ## kind ## _sub \ | |
98 | (char *, GFC_INTEGER_ ## kind *, gfc_charlen_type); \ | |
99 | export_proto(fget_i ## kind ## _sub); \ | |
100 | void fget_i ## kind ## _sub \ | |
101 | (char * c, GFC_INTEGER_ ## kind * st, gfc_charlen_type c_len) \ | |
102 | { if (st != NULL) \ | |
103 | *st = PREFIX(fgetc) (&five, c, c_len); \ | |
104 | else \ | |
105 | PREFIX(fgetc) (&five, c, c_len); } | |
106 | ||
107 | FGET_SUB(1) | |
108 | FGET_SUB(2) | |
109 | FGET_SUB(4) | |
110 | FGET_SUB(8) | |
111 | ||
112 | ||
113 | ||
114 | extern int PREFIX(fputc) (const int *, char *, gfc_charlen_type); | |
115 | export_proto_np(PREFIX(fputc)); | |
116 | ||
117 | int | |
118 | PREFIX(fputc) (const int * unit, char * c, | |
119 | gfc_charlen_type c_len __attribute__((unused))) | |
120 | { | |
121 | size_t s; | |
401cd90a | 122 | int ret; |
5d723e54 FXC |
123 | gfc_unit * u = find_unit (*unit); |
124 | ||
125 | if (u == NULL) | |
126 | return -1; | |
127 | ||
128 | s = 1; | |
401cd90a JJ |
129 | ret = swrite (u->s, c, &s); |
130 | unlock_unit (u); | |
131 | return ret; | |
5d723e54 FXC |
132 | } |
133 | ||
134 | ||
135 | #define FPUTC_SUB(kind) \ | |
136 | extern void fputc_i ## kind ## _sub \ | |
137 | (const int *, char *, GFC_INTEGER_ ## kind *, gfc_charlen_type); \ | |
138 | export_proto(fputc_i ## kind ## _sub); \ | |
139 | void fputc_i ## kind ## _sub \ | |
140 | (const int * unit, char * c, GFC_INTEGER_ ## kind * st, gfc_charlen_type c_len) \ | |
141 | { if (st != NULL) \ | |
142 | *st = PREFIX(fputc) (unit, c, c_len); \ | |
143 | else \ | |
144 | PREFIX(fputc) (unit, c, c_len); } | |
145 | ||
146 | FPUTC_SUB(1) | |
147 | FPUTC_SUB(2) | |
148 | FPUTC_SUB(4) | |
149 | FPUTC_SUB(8) | |
150 | ||
151 | ||
152 | extern int PREFIX(fput) (char *, gfc_charlen_type); | |
153 | export_proto_np(PREFIX(fput)); | |
154 | ||
155 | int | |
156 | PREFIX(fput) (char * c, gfc_charlen_type c_len) | |
157 | { | |
158 | return PREFIX(fputc) (&six, c, c_len); | |
159 | } | |
160 | ||
161 | ||
162 | #define FPUT_SUB(kind) \ | |
163 | extern void fput_i ## kind ## _sub \ | |
164 | (char *, GFC_INTEGER_ ## kind *, gfc_charlen_type); \ | |
165 | export_proto(fput_i ## kind ## _sub); \ | |
166 | void fput_i ## kind ## _sub \ | |
167 | (char * c, GFC_INTEGER_ ## kind * st, gfc_charlen_type c_len) \ | |
168 | { if (st != NULL) \ | |
169 | *st = PREFIX(fputc) (&six, c, c_len); \ | |
170 | else \ | |
171 | PREFIX(fputc) (&six, c, c_len); } | |
172 | ||
173 | FPUT_SUB(1) | |
174 | FPUT_SUB(2) | |
175 | FPUT_SUB(4) | |
176 | FPUT_SUB(8) | |
177 |