| 1 |
/* do not edit automatically generated by mc from StringConvert. */ |
| 2 |
/* StringConvert.def provides functions to convert numbers to and from strings. |
| 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 |
|
| 29 |
#if !defined (_StringConvert_H) |
| 30 |
# define _StringConvert_H |
| 31 |
|
| 32 |
# ifdef __cplusplus |
| 33 |
extern "C" { |
| 34 |
# endif |
| 35 |
#include <stdbool.h> |
| 36 |
# if !defined (PROC_D) |
| 37 |
# define PROC_D |
| 38 |
typedef void (*PROC_t) (void); |
| 39 |
typedef struct { PROC_t proc; } PROC; |
| 40 |
# endif |
| 41 |
|
| 42 |
# include "GDynamicStrings.h" |
| 43 |
|
| 44 |
# if defined (_StringConvert_C) |
| 45 |
# define EXTERN |
| 46 |
# else |
| 47 |
# define EXTERN extern |
| 48 |
# endif |
| 49 |
|
| 50 |
|
| 51 |
/* |
| 52 |
IntegerToString - converts INTEGER, i, into a String. The field with |
| 53 |
can be specified if non zero. Leading characters |
| 54 |
are defined by padding and this function will |
| 55 |
prepend a + if sign is set to TRUE. |
| 56 |
The base allows the caller to generate binary, |
| 57 |
octal, decimal, hexidecimal numbers. |
| 58 |
The value of lower is only used when hexidecimal |
| 59 |
numbers are generated and if TRUE then digits |
| 60 |
abcdef are used, and if FALSE then ABCDEF are used. |
| 61 |
*/ |
| 62 |
|
| 63 |
EXTERN DynamicStrings_String StringConvert_IntegerToString (int i, unsigned int width, char padding, bool sign, unsigned int base, bool lower); |
| 64 |
|
| 65 |
/* |
| 66 |
CardinalToString - converts CARDINAL, c, into a String. The field |
| 67 |
width can be specified if non zero. Leading |
| 68 |
characters are defined by padding. |
| 69 |
The base allows the caller to generate binary, |
| 70 |
octal, decimal, hexidecimal numbers. |
| 71 |
The value of lower is only used when hexidecimal |
| 72 |
numbers are generated and if TRUE then digits |
| 73 |
abcdef are used, and if FALSE then ABCDEF are used. |
| 74 |
*/ |
| 75 |
|
| 76 |
EXTERN DynamicStrings_String StringConvert_CardinalToString (unsigned int c, unsigned int width, char padding, unsigned int base, bool lower); |
| 77 |
|
| 78 |
/* |
| 79 |
StringToInteger - converts a string, s, of, base, into an INTEGER. |
| 80 |
Leading white space is ignored. It stops converting |
| 81 |
when either the string is exhausted or if an illegal |
| 82 |
numeral is found. |
| 83 |
The parameter found is set TRUE if a number was found. |
| 84 |
*/ |
| 85 |
|
| 86 |
EXTERN int StringConvert_StringToInteger (DynamicStrings_String s, unsigned int base, bool *found); |
| 87 |
|
| 88 |
/* |
| 89 |
StringToCardinal - converts a string, s, of, base, into a CARDINAL. |
| 90 |
Leading white space is ignored. It stops converting |
| 91 |
when either the string is exhausted or if an illegal |
| 92 |
numeral is found. |
| 93 |
The parameter found is set TRUE if a number was found. |
| 94 |
*/ |
| 95 |
|
| 96 |
EXTERN unsigned int StringConvert_StringToCardinal (DynamicStrings_String s, unsigned int base, bool *found); |
| 97 |
|
| 98 |
/* |
| 99 |
LongIntegerToString - converts LONGINT, i, into a String. The field with |
| 100 |
can be specified if non zero. Leading characters |
| 101 |
are defined by padding and this function will |
| 102 |
prepend a + if sign is set to TRUE. |
| 103 |
The base allows the caller to generate binary, |
| 104 |
octal, decimal, hexidecimal numbers. |
| 105 |
The value of lower is only used when hexidecimal |
| 106 |
numbers are generated and if TRUE then digits |
| 107 |
abcdef are used, and if FALSE then ABCDEF are used. |
| 108 |
*/ |
| 109 |
|
| 110 |
EXTERN DynamicStrings_String StringConvert_LongIntegerToString (long int i, unsigned int width, char padding, bool sign, unsigned int base, bool lower); |
| 111 |
|
| 112 |
/* |
| 113 |
StringToLongInteger - converts a string, s, of, base, into an LONGINT. |
| 114 |
Leading white space is ignored. It stops converting |
| 115 |
when either the string is exhausted or if an illegal |
| 116 |
numeral is found. |
| 117 |
The parameter found is set TRUE if a number was found. |
| 118 |
*/ |
| 119 |
|
| 120 |
EXTERN long int StringConvert_StringToLongInteger (DynamicStrings_String s, unsigned int base, bool *found); |
| 121 |
|
| 122 |
/* |
| 123 |
LongCardinalToString - converts LONGCARD, c, into a String. The field |
| 124 |
width can be specified if non zero. Leading |
| 125 |
characters are defined by padding. |
| 126 |
The base allows the caller to generate binary, |
| 127 |
octal, decimal, hexidecimal numbers. |
| 128 |
The value of lower is only used when hexidecimal |
| 129 |
numbers are generated and if TRUE then digits |
| 130 |
abcdef are used, and if FALSE then ABCDEF are used. |
| 131 |
*/ |
| 132 |
|
| 133 |
EXTERN DynamicStrings_String StringConvert_LongCardinalToString (long unsigned int c, unsigned int width, char padding, unsigned int base, bool lower); |
| 134 |
|
| 135 |
/* |
| 136 |
StringToLongCardinal - converts a string, s, of, base, into a LONGCARD. |
| 137 |
Leading white space is ignored. It stops converting |
| 138 |
when either the string is exhausted or if an illegal |
| 139 |
numeral is found. |
| 140 |
The parameter found is set TRUE if a number was found. |
| 141 |
*/ |
| 142 |
|
| 143 |
EXTERN long unsigned int StringConvert_StringToLongCardinal (DynamicStrings_String s, unsigned int base, bool *found); |
| 144 |
|
| 145 |
/* |
| 146 |
ShortCardinalToString - converts SHORTCARD, c, into a String. The field |
| 147 |
width can be specified if non zero. Leading |
| 148 |
characters are defined by padding. |
| 149 |
The base allows the caller to generate binary, |
| 150 |
octal, decimal, hexidecimal numbers. |
| 151 |
The value of lower is only used when hexidecimal |
| 152 |
numbers are generated and if TRUE then digits |
| 153 |
abcdef are used, and if FALSE then ABCDEF are used. |
| 154 |
*/ |
| 155 |
|
| 156 |
EXTERN DynamicStrings_String StringConvert_ShortCardinalToString (short unsigned int c, unsigned int width, char padding, unsigned int base, bool lower); |
| 157 |
|
| 158 |
/* |
| 159 |
StringToShortCardinal - converts a string, s, of, base, into a SHORTCARD. |
| 160 |
Leading white space is ignored. It stops converting |
| 161 |
when either the string is exhausted or if an illegal |
| 162 |
numeral is found. |
| 163 |
The parameter found is set TRUE if a number was found. |
| 164 |
*/ |
| 165 |
|
| 166 |
EXTERN short unsigned int StringConvert_StringToShortCardinal (DynamicStrings_String s, unsigned int base, bool *found); |
| 167 |
|
| 168 |
/* |
| 169 |
stoi - decimal string to INTEGER |
| 170 |
*/ |
| 171 |
|
| 172 |
EXTERN int StringConvert_stoi (DynamicStrings_String s); |
| 173 |
|
| 174 |
/* |
| 175 |
itos - integer to decimal string. |
| 176 |
*/ |
| 177 |
|
| 178 |
EXTERN DynamicStrings_String StringConvert_itos (int i, unsigned int width, char padding, bool sign); |
| 179 |
|
| 180 |
/* |
| 181 |
ctos - cardinal to decimal string. |
| 182 |
*/ |
| 183 |
|
| 184 |
EXTERN DynamicStrings_String StringConvert_ctos (unsigned int c, unsigned int width, char padding); |
| 185 |
|
| 186 |
/* |
| 187 |
stoc - decimal string to CARDINAL |
| 188 |
*/ |
| 189 |
|
| 190 |
EXTERN unsigned int StringConvert_stoc (DynamicStrings_String s); |
| 191 |
|
| 192 |
/* |
| 193 |
hstoi - hexidecimal string to INTEGER |
| 194 |
*/ |
| 195 |
|
| 196 |
EXTERN int StringConvert_hstoi (DynamicStrings_String s); |
| 197 |
|
| 198 |
/* |
| 199 |
ostoi - octal string to INTEGER |
| 200 |
*/ |
| 201 |
|
| 202 |
EXTERN int StringConvert_ostoi (DynamicStrings_String s); |
| 203 |
|
| 204 |
/* |
| 205 |
bstoi - binary string to INTEGER |
| 206 |
*/ |
| 207 |
|
| 208 |
EXTERN int StringConvert_bstoi (DynamicStrings_String s); |
| 209 |
|
| 210 |
/* |
| 211 |
hstoc - hexidecimal string to CARDINAL |
| 212 |
*/ |
| 213 |
|
| 214 |
EXTERN unsigned int StringConvert_hstoc (DynamicStrings_String s); |
| 215 |
|
| 216 |
/* |
| 217 |
ostoc - octal string to CARDINAL |
| 218 |
*/ |
| 219 |
|
| 220 |
EXTERN unsigned int StringConvert_ostoc (DynamicStrings_String s); |
| 221 |
|
| 222 |
/* |
| 223 |
bstoc - binary string to CARDINAL |
| 224 |
*/ |
| 225 |
|
| 226 |
EXTERN unsigned int StringConvert_bstoc (DynamicStrings_String s); |
| 227 |
|
| 228 |
/* |
| 229 |
StringToLongreal - returns a LONGREAL and sets found to TRUE |
| 230 |
if a legal number is seen. |
| 231 |
*/ |
| 232 |
|
| 233 |
EXTERN long double StringConvert_StringToLongreal (DynamicStrings_String s, bool *found); |
| 234 |
|
| 235 |
/* |
| 236 |
LongrealToString - converts a LONGREAL number, Real, which has, |
| 237 |
TotalWidth, and FractionWidth into a string. |
| 238 |
|
| 239 |
So for example: |
| 240 |
|
| 241 |
LongrealToString(1.0, 4, 2) -> '1.00' |
| 242 |
LongrealToString(12.3, 5, 2) -> '12.30' |
| 243 |
LongrealToString(12.3, 6, 2) -> ' 12.30' |
| 244 |
LongrealToString(12.3, 6, 3) -> '12.300' |
| 245 |
|
| 246 |
if total width is too small then the fraction |
| 247 |
becomes truncated. |
| 248 |
|
| 249 |
LongrealToString(12.3, 5, 3) -> '12.30' |
| 250 |
|
| 251 |
If TotalWidth is 0 then the function |
| 252 |
will return the value of x which is converted |
| 253 |
into as a fixed point number with exhaustive |
| 254 |
precision. |
| 255 |
*/ |
| 256 |
|
| 257 |
EXTERN DynamicStrings_String StringConvert_LongrealToString (long double x, unsigned int TotalWidth, unsigned int FractionWidth); |
| 258 |
|
| 259 |
/* |
| 260 |
stor - returns a REAL given a string. |
| 261 |
*/ |
| 262 |
|
| 263 |
EXTERN double StringConvert_stor (DynamicStrings_String s); |
| 264 |
|
| 265 |
/* |
| 266 |
stolr - returns a LONGREAL given a string. |
| 267 |
*/ |
| 268 |
|
| 269 |
EXTERN long double StringConvert_stolr (DynamicStrings_String s); |
| 270 |
|
| 271 |
/* |
| 272 |
ToSigFig - returns a floating point or base 10 integer |
| 273 |
string which is accurate to, n, significant |
| 274 |
figures. It will return a new String |
| 275 |
and, s, will be destroyed. |
| 276 |
|
| 277 |
|
| 278 |
So: 12.345 |
| 279 |
|
| 280 |
rounded to the following significant figures yields |
| 281 |
|
| 282 |
5 12.345 |
| 283 |
4 12.34 |
| 284 |
3 12.3 |
| 285 |
2 12 |
| 286 |
1 10 |
| 287 |
*/ |
| 288 |
|
| 289 |
EXTERN DynamicStrings_String StringConvert_ToSigFig (DynamicStrings_String s, unsigned int n); |
| 290 |
|
| 291 |
/* |
| 292 |
ToDecimalPlaces - returns a floating point or base 10 integer |
| 293 |
string which is accurate to, n, decimal |
| 294 |
places. It will return a new String |
| 295 |
and, s, will be destroyed. |
| 296 |
Decimal places yields, n, digits after |
| 297 |
the . |
| 298 |
|
| 299 |
So: 12.345 |
| 300 |
|
| 301 |
rounded to the following decimal places yields |
| 302 |
|
| 303 |
5 12.34500 |
| 304 |
4 12.3450 |
| 305 |
3 12.345 |
| 306 |
2 12.34 |
| 307 |
1 12.3 |
| 308 |
*/ |
| 309 |
|
| 310 |
EXTERN DynamicStrings_String StringConvert_ToDecimalPlaces (DynamicStrings_String s, unsigned int n); |
| 311 |
# ifdef __cplusplus |
| 312 |
} |
| 313 |
# endif |
| 314 |
|
| 315 |
# undef EXTERN |
| 316 |
#endif |