Debian Codegraph @

gcc/m2/pge-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 <stdbool.h>
29 # if !defined (PROC_D)
30 # define PROC_D
31 typedef void (*PROC_t) (void);
32 typedef struct { PROC_t proc; } PROC;
33 # endif
34
35 #include <stddef.h>
36 #if defined(__cplusplus)
37 # undef NULL
38 # define NULL 0
39 #endif
40 #define _SFIO_C
41
42 #include "GSFIO.h"
43 # include "GASCII.h"
44 # include "GDynamicStrings.h"
45 # include "GFIO.h"
46
47
48 /*
49 Exists - returns TRUE if a file named, fname exists for reading.
50 */
51
52 extern "C" bool SFIO_Exists (DynamicStrings_String fname);
53
54 /*
55 OpenToRead - attempts to open a file, fname, for reading and
56 it returns this file.
57 The success of this operation can be checked by
58 calling IsNoError.
59 */
60
61 extern "C" FIO_File SFIO_OpenToRead (DynamicStrings_String fname);
62
63 /*
64 OpenToWrite - attempts to open a file, fname, for write and
65 it returns this file.
66 The success of this operation can be checked by
67 calling IsNoError.
68 */
69
70 extern "C" FIO_File SFIO_OpenToWrite (DynamicStrings_String fname);
71
72 /*
73 OpenForRandom - attempts to open a file, fname, for random access
74 read or write and it returns this file.
75 The success of this operation can be checked by
76 calling IsNoError.
77 towrite, determines whether the file should be
78 opened for writing or reading.
79 if towrite is TRUE or whether the previous file should
80 be left alone, allowing this descriptor to seek
81 and modify an existing file.
82 */
83
84 extern "C" FIO_File SFIO_OpenForRandom (DynamicStrings_String fname, bool towrite, bool newfile);
85
86 /*
87 WriteS - writes a string, s, to, file. It returns the String, s.
88 */
89
90 extern "C" DynamicStrings_String SFIO_WriteS (FIO_File file, DynamicStrings_String s);
91
92 /*
93 ReadS - reads and returns a string from, file.
94 It stops reading the string at the end of line or end of file.
95 It consumes the newline at the end of line but does not place
96 this into the returned string.
97 */
98
99 extern "C" DynamicStrings_String SFIO_ReadS (FIO_File file);
100
101
102 /*
103 Exists - returns TRUE if a file named, fname exists for reading.
104 */
105
106 extern "C" bool SFIO_Exists (DynamicStrings_String fname)
107 {
108 return FIO_exists (DynamicStrings_string (fname), DynamicStrings_Length (fname));
109 /* static analysis guarentees a RETURN statement will be used before here. */
110 __builtin_unreachable ();
111 }
112
113
114 /*
115 OpenToRead - attempts to open a file, fname, for reading and
116 it returns this file.
117 The success of this operation can be checked by
118 calling IsNoError.
119 */
120
121 extern "C" FIO_File SFIO_OpenToRead (DynamicStrings_String fname)
122 {
123 return FIO_openToRead (DynamicStrings_string (fname), DynamicStrings_Length (fname));
124 /* static analysis guarentees a RETURN statement will be used before here. */
125 __builtin_unreachable ();
126 }
127
128
129 /*
130 OpenToWrite - attempts to open a file, fname, for write and
131 it returns this file.
132 The success of this operation can be checked by
133 calling IsNoError.
134 */
135
136 extern "C" FIO_File SFIO_OpenToWrite (DynamicStrings_String fname)
137 {
138 return FIO_openToWrite (DynamicStrings_string (fname), DynamicStrings_Length (fname));
139 /* static analysis guarentees a RETURN statement will be used before here. */
140 __builtin_unreachable ();
141 }
142
143
144 /*
145 OpenForRandom - attempts to open a file, fname, for random access
146 read or write and it returns this file.
147 The success of this operation can be checked by
148 calling IsNoError.
149 towrite, determines whether the file should be
150 opened for writing or reading.
151 if towrite is TRUE or whether the previous file should
152 be left alone, allowing this descriptor to seek
153 and modify an existing file.
154 */
155
156 extern "C" FIO_File SFIO_OpenForRandom (DynamicStrings_String fname, bool towrite, bool newfile)
157 {
158 return FIO_openForRandom (DynamicStrings_string (fname), DynamicStrings_Length (fname), towrite, newfile);
159 /* static analysis guarentees a RETURN statement will be used before here. */
160 __builtin_unreachable ();
161 }
162
163
164 /*
165 WriteS - writes a string, s, to, file. It returns the String, s.
166 */
167
168 extern "C" DynamicStrings_String SFIO_WriteS (FIO_File file, DynamicStrings_String s)
169 {
170 unsigned int nBytes;
171
172 if (s != NULL)
173 {
174 nBytes = FIO_WriteNBytes (file, DynamicStrings_Length (s), DynamicStrings_string (s));
175 }
176 return s;
177 /* static analysis guarentees a RETURN statement will be used before here. */
178 __builtin_unreachable ();
179 }
180
181
182 /*
183 ReadS - reads and returns a string from, file.
184 It stops reading the string at the end of line or end of file.
185 It consumes the newline at the end of line but does not place
186 this into the returned string.
187 */
188
189 extern "C" DynamicStrings_String SFIO_ReadS (FIO_File file)
190 {
191 DynamicStrings_String s;
192
193 s = DynamicStrings_InitString ((const char *) "", 0);
194 while (((! (FIO_EOLN (file))) && (! (FIO_EOF (file)))) && (FIO_IsNoError (file)))
195 {
196 s = DynamicStrings_ConCatChar (s, FIO_ReadChar (file));
197 }
198 if (FIO_EOLN (file))
199 {
200 /* consume nl */
201 if ((FIO_ReadChar (file)) == ASCII_nul)
202 {} /* empty. */
203 }
204 return s;
205 /* static analysis guarentees a RETURN statement will be used before here. */
206 __builtin_unreachable ();
207 }
208
209 extern "C" void _M2_SFIO_init (__attribute__((unused)) int argc,__attribute__((unused)) char *argv[],__attribute__((unused)) char *envp[])
210 {
211 }
212
213 extern "C" void _M2_SFIO_fini (__attribute__((unused)) int argc,__attribute__((unused)) char *argv[],__attribute__((unused)) char *envp[])
214 {
215 }