]>
Commit | Line | Data |
---|---|---|
1eee94d3 GM |
1 | /* do not edit automatically generated by mc from DynamicStrings. */ |
2 | /* DynamicStrings.def provides a dynamic string type and procedures. | |
3 | ||
a945c346 | 4 | Copyright (C) 2001-2024 Free Software Foundation, Inc. |
1eee94d3 GM |
5 | Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>. |
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 | ||
29 | #if !defined (_DynamicStrings_H) | |
30 | # define _DynamicStrings_H | |
31 | ||
32 | #include "config.h" | |
33 | #include "system.h" | |
34 | # ifdef __cplusplus | |
35 | extern "C" { | |
36 | # endif | |
9525daf0 | 37 | #include <stdbool.h> |
1eee94d3 GM |
38 | # if !defined (PROC_D) |
39 | # define PROC_D | |
40 | typedef void (*PROC_t) (void); | |
41 | typedef struct { PROC_t proc; } PROC; | |
42 | # endif | |
43 | ||
44 | # include "GSYSTEM.h" | |
45 | ||
46 | # if defined (_DynamicStrings_C) | |
47 | # define EXTERN | |
48 | # else | |
49 | # define EXTERN extern | |
50 | # endif | |
51 | ||
52 | #if !defined (DynamicStrings_String_D) | |
53 | # define DynamicStrings_String_D | |
54 | typedef void *DynamicStrings_String; | |
55 | #endif | |
56 | ||
57 | ||
58 | /* | |
59 | InitString - creates and returns a String type object. | |
60 | Initial contents are, a. | |
61 | */ | |
62 | ||
63 | EXTERN DynamicStrings_String DynamicStrings_InitString (const char *a_, unsigned int _a_high); | |
64 | ||
65 | /* | |
66 | KillString - frees String, s, and its contents. | |
67 | NIL is returned. | |
68 | */ | |
69 | ||
70 | EXTERN DynamicStrings_String DynamicStrings_KillString (DynamicStrings_String s); | |
71 | ||
72 | /* | |
73 | Fin - finishes with a string, it calls KillString with, s. | |
74 | The purpose of the procedure is to provide a short cut | |
75 | to calling KillString and then testing the return result. | |
76 | */ | |
77 | ||
78 | EXTERN void DynamicStrings_Fin (DynamicStrings_String s); | |
79 | ||
80 | /* | |
81 | InitStringCharStar - initializes and returns a String to contain | |
82 | the C string. | |
83 | */ | |
84 | ||
85 | EXTERN DynamicStrings_String DynamicStrings_InitStringCharStar (void * a); | |
86 | ||
87 | /* | |
88 | InitStringChar - initializes and returns a String to contain the | |
89 | single character, ch. | |
90 | */ | |
91 | ||
92 | EXTERN DynamicStrings_String DynamicStrings_InitStringChar (char ch); | |
93 | ||
94 | /* | |
95 | Mark - marks String, s, ready for garbage collection. | |
96 | */ | |
97 | ||
98 | EXTERN DynamicStrings_String DynamicStrings_Mark (DynamicStrings_String s); | |
99 | ||
100 | /* | |
101 | Length - returns the length of the String, s. | |
102 | */ | |
103 | ||
104 | EXTERN unsigned int DynamicStrings_Length (DynamicStrings_String s); | |
105 | ||
106 | /* | |
107 | ConCat - returns String, a, after the contents of, b, | |
108 | have been appended. | |
109 | */ | |
110 | ||
111 | EXTERN DynamicStrings_String DynamicStrings_ConCat (DynamicStrings_String a, DynamicStrings_String b); | |
112 | ||
113 | /* | |
114 | ConCatChar - returns String, a, after character, ch, | |
115 | has been appended. | |
116 | */ | |
117 | ||
118 | EXTERN DynamicStrings_String DynamicStrings_ConCatChar (DynamicStrings_String a, char ch); | |
119 | ||
120 | /* | |
121 | Assign - assigns the contents of, b, into, a. | |
122 | String, a, is returned. | |
123 | */ | |
124 | ||
125 | EXTERN DynamicStrings_String DynamicStrings_Assign (DynamicStrings_String a, DynamicStrings_String b); | |
126 | ||
127 | /* | |
128 | Dup - duplicate a String, s, returning the copy of s. | |
129 | */ | |
130 | ||
131 | EXTERN DynamicStrings_String DynamicStrings_Dup (DynamicStrings_String s); | |
132 | ||
133 | /* | |
134 | Add - returns a new String which contains the contents of a and b. | |
135 | */ | |
136 | ||
137 | EXTERN DynamicStrings_String DynamicStrings_Add (DynamicStrings_String a, DynamicStrings_String b); | |
138 | ||
139 | /* | |
140 | Equal - returns TRUE if String, a, and, b, are equal. | |
141 | */ | |
142 | ||
9525daf0 | 143 | EXTERN bool DynamicStrings_Equal (DynamicStrings_String a, DynamicStrings_String b); |
1eee94d3 GM |
144 | |
145 | /* | |
146 | EqualCharStar - returns TRUE if contents of String, s, is | |
147 | the same as the string, a. | |
148 | */ | |
149 | ||
9525daf0 | 150 | EXTERN bool DynamicStrings_EqualCharStar (DynamicStrings_String s, void * a); |
1eee94d3 GM |
151 | |
152 | /* | |
153 | EqualArray - returns TRUE if contents of String, s, is the | |
154 | same as the string, a. | |
155 | */ | |
156 | ||
9525daf0 | 157 | EXTERN bool DynamicStrings_EqualArray (DynamicStrings_String s, const char *a_, unsigned int _a_high); |
1eee94d3 GM |
158 | |
159 | /* | |
160 | Mult - returns a new string which is n concatenations of String, s. | |
161 | If n<=0 then an empty string is returned. | |
162 | */ | |
163 | ||
164 | EXTERN DynamicStrings_String DynamicStrings_Mult (DynamicStrings_String s, unsigned int n); | |
165 | ||
166 | /* | |
167 | Slice - returns a new string which contains the elements | |
168 | low..high-1 | |
169 | ||
170 | strings start at element 0 | |
171 | Slice(s, 0, 2) will return elements 0, 1 but not 2 | |
172 | Slice(s, 1, 3) will return elements 1, 2 but not 3 | |
173 | Slice(s, 2, 0) will return elements 2..max | |
174 | Slice(s, 3, -1) will return elements 3..max-1 | |
175 | Slice(s, 4, -2) will return elements 4..max-2 | |
176 | */ | |
177 | ||
178 | EXTERN DynamicStrings_String DynamicStrings_Slice (DynamicStrings_String s, int low, int high); | |
179 | ||
180 | /* | |
181 | Index - returns the indice of the first occurance of, ch, in | |
182 | String, s. -1 is returned if, ch, does not exist. | |
183 | The search starts at position, o. | |
184 | */ | |
185 | ||
186 | EXTERN int DynamicStrings_Index (DynamicStrings_String s, char ch, unsigned int o); | |
187 | ||
188 | /* | |
189 | RIndex - returns the indice of the last occurance of, ch, | |
190 | in String, s. The search starts at position, o. | |
191 | -1 is returned if, ch, is not found. | |
192 | */ | |
193 | ||
194 | EXTERN int DynamicStrings_RIndex (DynamicStrings_String s, char ch, unsigned int o); | |
195 | ||
196 | /* | |
197 | RemoveComment - assuming that, comment, is a comment delimiter | |
198 | which indicates anything to its right is a comment | |
199 | then strip off the comment and also any white space | |
200 | on the remaining right hand side. | |
201 | It leaves any white space on the left hand side | |
202 | alone. | |
203 | */ | |
204 | ||
205 | EXTERN DynamicStrings_String DynamicStrings_RemoveComment (DynamicStrings_String s, char comment); | |
206 | ||
207 | /* | |
208 | RemoveWhitePrefix - removes any leading white space from String, s. | |
209 | A new string is returned. | |
210 | */ | |
211 | ||
212 | EXTERN DynamicStrings_String DynamicStrings_RemoveWhitePrefix (DynamicStrings_String s); | |
213 | ||
214 | /* | |
215 | RemoveWhitePostfix - removes any leading white space from String, s. | |
216 | A new string is returned. | |
217 | */ | |
218 | ||
219 | EXTERN DynamicStrings_String DynamicStrings_RemoveWhitePostfix (DynamicStrings_String s); | |
220 | ||
221 | /* | |
222 | ToUpper - returns string, s, after it has had its lower case | |
223 | characters replaced by upper case characters. | |
224 | The string, s, is not duplicated. | |
225 | */ | |
226 | ||
227 | EXTERN DynamicStrings_String DynamicStrings_ToUpper (DynamicStrings_String s); | |
228 | ||
229 | /* | |
230 | ToLower - returns string, s, after it has had its upper case | |
231 | characters replaced by lower case characters. | |
232 | The string, s, is not duplicated. | |
233 | */ | |
234 | ||
235 | EXTERN DynamicStrings_String DynamicStrings_ToLower (DynamicStrings_String s); | |
236 | ||
237 | /* | |
238 | CopyOut - copies string, s, to a. | |
239 | */ | |
240 | ||
241 | EXTERN void DynamicStrings_CopyOut (char *a, unsigned int _a_high, DynamicStrings_String s); | |
242 | ||
243 | /* | |
244 | char - returns the character, ch, at position, i, in String, s. | |
245 | As Slice the index can be negative so: | |
246 | ||
247 | char(s, 0) will return the first character | |
248 | char(s, 1) will return the second character | |
249 | char(s, -1) will return the last character | |
250 | char(s, -2) will return the penultimate character | |
251 | ||
252 | a nul character is returned if the index is out of range. | |
253 | */ | |
254 | ||
255 | EXTERN char DynamicStrings_char (DynamicStrings_String s, int i); | |
256 | ||
257 | /* | |
258 | string - returns the C style char * of String, s. | |
259 | */ | |
260 | ||
261 | EXTERN void * DynamicStrings_string (DynamicStrings_String s); | |
262 | ||
263 | /* | |
264 | InitStringDB - the debug version of InitString. | |
265 | */ | |
266 | ||
267 | EXTERN DynamicStrings_String DynamicStrings_InitStringDB (const char *a_, unsigned int _a_high, const char *file_, unsigned int _file_high, unsigned int line); | |
268 | ||
269 | /* | |
270 | InitStringCharStarDB - the debug version of InitStringCharStar. | |
271 | */ | |
272 | ||
273 | EXTERN DynamicStrings_String DynamicStrings_InitStringCharStarDB (void * a, const char *file_, unsigned int _file_high, unsigned int line); | |
274 | ||
275 | /* | |
276 | InitStringCharDB - the debug version of InitStringChar. | |
277 | */ | |
278 | ||
279 | EXTERN DynamicStrings_String DynamicStrings_InitStringCharDB (char ch, const char *file_, unsigned int _file_high, unsigned int line); | |
280 | ||
281 | /* | |
282 | MultDB - the debug version of MultDB. | |
283 | */ | |
284 | ||
285 | EXTERN DynamicStrings_String DynamicStrings_MultDB (DynamicStrings_String s, unsigned int n, const char *file_, unsigned int _file_high, unsigned int line); | |
286 | ||
287 | /* | |
288 | DupDB - the debug version of Dup. | |
289 | */ | |
290 | ||
291 | EXTERN DynamicStrings_String DynamicStrings_DupDB (DynamicStrings_String s, const char *file_, unsigned int _file_high, unsigned int line); | |
292 | ||
293 | /* | |
294 | SliceDB - debug version of Slice. | |
295 | */ | |
296 | ||
297 | EXTERN DynamicStrings_String DynamicStrings_SliceDB (DynamicStrings_String s, int low, int high, const char *file_, unsigned int _file_high, unsigned int line); | |
298 | ||
299 | /* | |
300 | PushAllocation - pushes the current allocation/deallocation lists. | |
301 | */ | |
302 | ||
303 | EXTERN void DynamicStrings_PushAllocation (void); | |
304 | ||
305 | /* | |
306 | PopAllocation - test to see that all strings are deallocated since | |
307 | the last push. Then it pops to the previous | |
308 | allocation/deallocation lists. | |
309 | ||
310 | If halt is true then the application terminates | |
311 | with an exit code of 1. | |
312 | */ | |
313 | ||
9525daf0 | 314 | EXTERN void DynamicStrings_PopAllocation (bool halt); |
1eee94d3 GM |
315 | |
316 | /* | |
317 | PopAllocationExemption - test to see that all strings are | |
9525daf0 | 318 | deallocated, except string e since |
1eee94d3 | 319 | the last push. |
9525daf0 | 320 | Post-condition: it pops to the previous |
1eee94d3 GM |
321 | allocation/deallocation lists. |
322 | ||
323 | If halt is true then the application | |
324 | terminates with an exit code of 1. | |
325 | ||
326 | The string, e, is returned unmodified, | |
327 | */ | |
328 | ||
9525daf0 | 329 | EXTERN DynamicStrings_String DynamicStrings_PopAllocationExemption (bool halt, DynamicStrings_String e); |
1eee94d3 GM |
330 | # ifdef __cplusplus |
331 | } | |
332 | # endif | |
333 | ||
334 | # undef EXTERN | |
335 | #endif |