Debian Codegraph @

gcc/m2/mc-boot/GSFIO.cc

raw
1 /* do not edit automatically generated by mc from SFIO. */
2 /* SFIO.mod provides a String interface to the opening routines of FIO.
3
4 Copyright (C) 2001-2025 Free Software Foundation, Inc.
5 Contributed by Gaius Mulley <[email protected]>.
6
7 This file is part of GNU Modula-2.
8
9 GNU Modula-2 is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
12 any later version.
13
14 GNU Modula-2 is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
18
19 Under Section 7 of GPL version 3, you are granted additional
20 permissions described in the GCC Runtime Library Exception, version
21 3.1, as published by the Free Software Foundation.
22
23 You should have received a copy of the GNU General Public License and
24 a copy of the GCC Runtime Library Exception along with this program;
25 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
26 <http://www.gnu.org/licenses/>. */
27
28 #include "config.h"
29 #include "system.h"
30 #include <stdbool.h>
31 # if !defined (PROC_D)
32 # define PROC_D
33 typedef void (*PROC_t) (void);
34 typedef struct { PROC_t proc; } PROC;
35 # endif
36
37 #if defined(__cplusplus)
38 # undef NULL
39 # define NULL 0
40 #endif
41 #define _SFIO_C
42
43 #include "GSFIO.h"
44 # include "GASCII.h"
45 # include "GDynamicStrings.h"
46 # include "GFIO.h"
47
48
49 /*
50 Exists - returns TRUE if a file named, fname exists for reading.
51 */
52
53 extern "C" bool SFIO_Exists (DynamicStrings_String fname);
54
55 /*
56 OpenToRead - attempts to open a file, fname, for reading and
57 it returns this file.
58 The success of this operation can be checked by
59 calling IsNoError.
60 */
61
62 extern "C" FIO_File SFIO_OpenToRead (DynamicStrings_String fname);
63
64 /*
65 OpenToWrite - attempts to open a file, fname, for write and
66 it returns this file.
67 The success of this operation can be checked by
68 calling IsNoError.
69 */
70
71 extern "C" FIO_File SFIO_OpenToWrite (DynamicStrings_String fname);
72
73 /*
74 OpenForRandom - attempts to open a file, fname, for random access
75 read or write and it returns this file.
76 The success of this operation can be checked by
77 calling IsNoError.
78 towrite, determines whether the file should be
79 opened for writing or reading.
80 if towrite is TRUE or whether the previous file should
81 be left alone, allowing this descriptor to seek
82 and modify an existing file.
83 */
84
85 extern "C" FIO_File SFIO_OpenForRandom (DynamicStrings_String fname, bool towrite, bool newfile);
86
87 /*
88 WriteS - writes a string, s, to, file. It returns the String, s.
89 */
90
91 extern "C" DynamicStrings_String SFIO_WriteS (FIO_File file, DynamicStrings_String s);
92
93 /*
94 ReadS - reads and returns a string from, file.
95 It stops reading the string at the end of line or end of file.
96 It consumes the newline at the end of line but does not place
97 this into the returned string.
98 */
99
100 extern "C" DynamicStrings_String SFIO_ReadS (FIO_File file);
101
102
103 /*
104 Exists - returns TRUE if a file named, fname exists for reading.
105 */
106
107 extern "C" bool SFIO_Exists (DynamicStrings_String fname)
108 {
109 return FIO_exists (DynamicStrings_string (fname), DynamicStrings_Length (fname));
110 /* static analysis guarentees a RETURN statement will be used before here. */
111 __builtin_unreachable ();
112 }
113
114
115 /*
116 OpenToRead - attempts to open a file, fname, for reading and
117 it returns this file.
118 The success of this operation can be checked by
119 calling IsNoError.
120 */
121
122 extern "C" FIO_File SFIO_OpenToRead (DynamicStrings_String fname)
123 {
124 return FIO_openToRead (DynamicStrings_string (fname), DynamicStrings_Length (fname));
125 /* static analysis guarentees a RETURN statement will be used before here. */
126 __builtin_unreachable ();
127 }
128
129
130 /*
131 OpenToWrite - attempts to open a file, fname, for write and
132 it returns this file.
133 The success of this operation can be checked by
134 calling IsNoError.
135 */
136
137 extern "C" FIO_File SFIO_OpenToWrite (DynamicStrings_String fname)
138 {
139 return FIO_openToWrite (DynamicStrings_string (fname), DynamicStrings_Length (fname));
140 /* static analysis guarentees a RETURN statement will be used before here. */
141 __builtin_unreachable ();
142 }
143
144
145 /*
146 OpenForRandom - attempts to open a file, fname, for random access
147 read or write and it returns this file.
148 The success of this operation can be checked by
149 calling IsNoError.
150 towrite, determines whether the file should be
151 opened for writing or reading.
152 if towrite is TRUE or whether the previous file should
153 be left alone, allowing this descriptor to seek
154 and modify an existing file.
155 */
156
157 extern "C" FIO_File SFIO_OpenForRandom (DynamicStrings_String fname, bool towrite, bool newfile)
158 {
159 return FIO_openForRandom (DynamicStrings_string (fname), DynamicStrings_Length (fname), towrite, newfile);
160 /* static analysis guarentees a RETURN statement will be used before here. */
161 __builtin_unreachable ();
162 }
163
164
165 /*
166 WriteS - writes a string, s, to, file. It returns the String, s.
167 */
168
169 extern "C" DynamicStrings_String SFIO_WriteS (FIO_File file, DynamicStrings_String s)
170 {
171 unsigned int nBytes;
172
173 if (s != NULL)
174 {
175 nBytes = FIO_WriteNBytes (file, DynamicStrings_Length (s), DynamicStrings_string (s));
176 }
177 return s;
178 /* static analysis guarentees a RETURN statement will be used before here. */
179 __builtin_unreachable ();
180 }
181
182
183 /*
184 ReadS - reads and returns a string from, file.
185 It stops reading the string at the end of line or end of file.
186 It consumes the newline at the end of line but does not place
187 this into the returned string.
188 */
189
190 extern "C" DynamicStrings_String SFIO_ReadS (FIO_File file)
191 {
192 DynamicStrings_String s;
193
194 s = DynamicStrings_InitString ((const char *) "", 0);
195 while (((! (FIO_EOLN (file))) && (! (FIO_EOF (file)))) && (FIO_IsNoError (file)))
196 {
197 s = DynamicStrings_ConCatChar (s, FIO_ReadChar (file));
198 }
199 if (FIO_EOLN (file))
200 {
201 /* consume nl */
202 if ((FIO_ReadChar (file)) == ASCII_nul)
203 {} /* empty. */
204 }
205 return s;
206 /* static analysis guarentees a RETURN statement will be used before here. */
207 __builtin_unreachable ();
208 }
209
210 extern "C" void _M2_SFIO_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
211 {
212 }
213
214 extern "C" void _M2_SFIO_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
215 {
216 }