author | Wuzzy <Wuzzy2@mail.ru> |
Sun, 07 Jun 2020 00:44:13 +0200 | |
changeset 15604 | 22d0a3d6e2be |
parent 14249 | 06f2dc4deab2 |
child 16018 | 692903667ece |
permissions | -rw-r--r-- |
7983 | 1 |
#include "system.h" |
2 |
#include <string.h> |
|
3 |
#include <stdio.h> |
|
4 |
#include <stdlib.h> |
|
5 |
#include <wchar.h> |
|
11655 | 6 |
#include "pmath.h" |
7983 | 7 |
|
8053 | 8 |
#ifndef M_PI |
9 |
// some math.h do not have M_PI macros |
|
10 |
# define M_PI 3.14159265358979323846 /* pi */ |
|
11 |
# define M_PI_2 1.57079632679489661923 /* pi/2 */ |
|
12 |
# define M_PI_4 0.78539816339744830962 /* pi/4 */ |
|
13 |
# define M_PIl 3.1415926535897932384626433832795029L /* pi */ |
|
14 |
# define M_PI_2l 1.5707963267948966192313216916397514L /* pi/2 */ |
|
15 |
# define M_PI_4l 0.7853981633974483096156608458198757L /* pi/4 */ |
|
16 |
#endif |
|
17 |
||
18 |
double pi = M_PI; |
|
19 |
||
7983 | 20 |
int paramCount; |
21 |
string255 params[MAX_PARAMS]; |
|
22 |
||
23 |
string255 fpcrtl_copy(string255 s, Integer index, Integer count) { |
|
24 |
string255 result = STRINIT(""); |
|
25 |
||
26 |
if (count < 1) { |
|
27 |
return result; |
|
28 |
} |
|
29 |
||
30 |
if (index < 1) { |
|
31 |
index = 1; |
|
32 |
} |
|
33 |
||
34 |
if (index > s.len) { |
|
35 |
return result; |
|
36 |
} |
|
37 |
||
38 |
if (index + count > s.len + 1) { |
|
39 |
count = s.len + 1 - index; |
|
40 |
} |
|
41 |
||
42 |
memcpy(result.str, s.str + index - 1, count); |
|
43 |
||
10128 | 44 |
result.len = count; |
45 |
||
46 |
return result; |
|
47 |
} |
|
48 |
||
49 |
astring fpcrtl_copyA(astring s, Integer index, Integer count) { |
|
50 |
astring result; |
|
51 |
||
52 |
result.len = 0; |
|
53 |
||
54 |
if (count < 1) { |
|
55 |
return result; |
|
56 |
} |
|
57 |
||
58 |
if (index < 1) { |
|
59 |
index = 1; |
|
60 |
} |
|
61 |
||
62 |
if (index > s.len) { |
|
63 |
return result; |
|
64 |
} |
|
65 |
||
66 |
if (index + count > s.len + 1) { |
|
67 |
count = s.len + 1 - index; |
|
68 |
} |
|
69 |
||
10131
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
70 |
memcpy(result.s + 1, s.s + index, count); |
10128 | 71 |
|
7983 | 72 |
result.len = count; |
73 |
||
74 |
return result; |
|
75 |
} |
|
76 |
||
13920
7173b702e8db
tag both as overloadable - seems to satisfy clang 3.4
nemo
parents:
13880
diff
changeset
|
77 |
void __attribute__((overloadable)) fpcrtl_insert__vars(string255 *src, string255 *dst, SizeInt index) { |
10838 | 78 |
int num_insert; |
79 |
int num_shift; |
|
80 |
int num_preshift; |
|
81 |
||
82 |
// nothing to do if empty string is inserted or index invalid |
|
83 |
if ((src->len == 0) || (index < 1) || (index > 255)) { |
|
84 |
return; |
|
85 |
} |
|
86 |
||
87 |
num_insert = src->len; |
|
88 |
// number of chars from start of destination string to end of insertion |
|
89 |
num_preshift = index - 1 + num_insert; |
|
90 |
||
91 |
// don't overflow on insert |
|
92 |
if (num_preshift > 255) { |
|
13880 | 93 |
num_preshift = 255; |
10838 | 94 |
num_insert = 255 - (index - 1); |
95 |
num_shift = 0; |
|
96 |
} |
|
97 |
// shift trailing chars |
|
98 |
else { |
|
99 |
// number of bytes to be shifted |
|
100 |
num_shift = dst->len - (index - 1); |
|
101 |
||
102 |
if (num_shift > 0) { |
|
103 |
// don't overflow when shifting |
|
104 |
if (num_shift + num_preshift > 255) |
|
105 |
num_shift = 255 - num_preshift; |
|
106 |
||
107 |
// time to move some bytes! |
|
108 |
memmove(dst->str + num_preshift, dst->str + index - 1, num_shift); |
|
109 |
} |
|
110 |
} |
|
111 |
||
112 |
// actual byte insertion |
|
113 |
memmove(dst->str + index - 1, src->str, num_insert); |
|
114 |
// store new length |
|
115 |
dst->len = num_shift + num_preshift; |
|
116 |
} |
|
117 |
||
13880 | 118 |
void __attribute__((overloadable)) fpcrtl_insert__vars(astring *src, astring *dst, SizeInt index) { |
119 |
int num_insert; |
|
120 |
int num_shift; |
|
121 |
int num_preshift; |
|
122 |
||
123 |
// nothing to do if empty string is inserted or index invalid |
|
124 |
if ((src->len == 0) || (index < 1) || (index > MAX_ANSISTRING_LENGTH)) { |
|
125 |
return; |
|
126 |
} |
|
127 |
||
128 |
num_insert = src->len; |
|
129 |
// number of chars from start of destination string to end of insertion |
|
130 |
num_preshift = index - 1 + num_insert; |
|
131 |
||
132 |
// don't overflow on insert |
|
133 |
if (num_preshift > MAX_ANSISTRING_LENGTH) { |
|
134 |
num_preshift = MAX_ANSISTRING_LENGTH; |
|
135 |
num_insert = MAX_ANSISTRING_LENGTH - (index - 1); |
|
136 |
num_shift = 0; |
|
137 |
} |
|
138 |
// shift trailing chars |
|
139 |
else { |
|
140 |
// number of bytes to be shifted |
|
141 |
num_shift = dst->len - (index - 1); |
|
142 |
||
143 |
if (num_shift > 0) { |
|
144 |
// don't overflow when shifting |
|
145 |
if (num_shift + num_preshift > MAX_ANSISTRING_LENGTH) |
|
146 |
num_shift = MAX_ANSISTRING_LENGTH - num_preshift; |
|
147 |
||
148 |
// time to move some bytes! |
|
149 |
memmove(dst->str + num_preshift, dst->str + index - 1, num_shift); |
|
150 |
} |
|
151 |
} |
|
152 |
||
153 |
// actual byte insertion |
|
154 |
memmove(dst->str + index - 1, src->str, num_insert); |
|
155 |
// store new length |
|
156 |
dst->len = num_shift + num_preshift; |
|
157 |
} |
|
158 |
||
10131
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
159 |
void __attribute__((overloadable)) fpcrtl_delete__vars(string255 *s, SizeInt index, SizeInt count) { |
7983 | 160 |
// number of chars to be move |
161 |
int num_move; |
|
162 |
int new_length; |
|
163 |
||
164 |
if (index < 1) { |
|
165 |
// in fpc, if index < 1, the string won't be modified |
|
166 |
return; |
|
167 |
} |
|
168 |
||
169 |
if(index > s->len){ |
|
170 |
return; |
|
171 |
} |
|
172 |
||
173 |
if (count > s->len - index + 1) { |
|
174 |
s->len = index - 1; |
|
175 |
return; |
|
176 |
} |
|
177 |
||
178 |
num_move = s->len - index + 1 - count; |
|
179 |
new_length = s->len - count; |
|
180 |
||
10131
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
181 |
memmove(s->str + index - 1, s->str + index - 1 + count, num_move); |
7983 | 182 |
s->str[new_length] = 0; |
183 |
||
184 |
s->len = new_length; |
|
185 |
||
186 |
} |
|
187 |
||
10131
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
188 |
void __attribute__((overloadable)) fpcrtl_delete__vars(astring *s, SizeInt index, SizeInt count) { |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
189 |
// number of chars to be move |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
190 |
int num_move; |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
191 |
int new_length; |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
192 |
|
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
193 |
if (index < 1) { |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
194 |
// in fpc, if index < 1, the string won't be modified |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
195 |
return; |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
196 |
} |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
197 |
|
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
198 |
if(index > s->len){ |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
199 |
return; |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
200 |
} |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
201 |
|
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
202 |
if (count > s->len - index + 1) { |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
203 |
s->len = index - 1; |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
204 |
return; |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
205 |
} |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
206 |
|
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
207 |
num_move = s->len - index + 1 - count; |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
208 |
new_length = s->len - count; |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
209 |
|
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
210 |
memmove(s->s + index, s->s + index + count, num_move); |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
211 |
|
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
212 |
s->len = new_length; |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
213 |
|
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
214 |
} |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
215 |
|
7983 | 216 |
string255 fpcrtl_floatToStr(double n) { |
217 |
string255 t; |
|
218 |
sprintf(t.str, "%f", n); |
|
219 |
t.len = strlen(t.str); |
|
220 |
||
221 |
return t; |
|
222 |
} |
|
223 |
||
224 |
void fpcrtl_move__vars(void *src, void *dst, SizeInt count) { |
|
225 |
memmove(dst, src, count); |
|
226 |
} |
|
227 |
||
228 |
Integer __attribute__((overloadable)) fpcrtl_pos(Char c, string255 str) { |
|
10134
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
229 |
|
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
230 |
unsigned char* p; |
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
231 |
|
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
232 |
if (str.len == 0) { |
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
233 |
return 0; |
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
234 |
} |
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
235 |
|
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
236 |
FIX_STRING(str); |
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
237 |
|
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
238 |
p = strchr(str.str, c); |
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
239 |
|
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
240 |
if (p == NULL) { |
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
241 |
return 0; |
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
242 |
} |
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
243 |
|
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
244 |
return p - (unsigned char*)&str.s; |
7983 | 245 |
} |
246 |
||
247 |
Integer __attribute__((overloadable)) fpcrtl_pos(string255 substr, string255 str) { |
|
248 |
||
10131
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
249 |
unsigned char* p; |
7983 | 250 |
|
251 |
if (str.len == 0) { |
|
252 |
return 0; |
|
253 |
} |
|
254 |
||
255 |
if (substr.len == 0) { |
|
256 |
return 0; |
|
257 |
} |
|
258 |
||
10128 | 259 |
FIX_STRING(substr); |
260 |
FIX_STRING(str); |
|
7983 | 261 |
|
262 |
p = strstr(str.str, substr.str); |
|
263 |
||
264 |
if (p == NULL) { |
|
265 |
return 0; |
|
266 |
} |
|
267 |
||
10131
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
268 |
return p - (unsigned char*)&str.s; |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
269 |
} |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
270 |
|
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
271 |
Integer __attribute__((overloadable)) fpcrtl_pos(Char c, astring str) { |
10134
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
272 |
unsigned char* p; |
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
273 |
|
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
274 |
if (str.len == 0) { |
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
275 |
return 0; |
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
276 |
} |
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
277 |
|
14159 | 278 |
FIX_STRINGA(str); |
279 |
||
14249
06f2dc4deab2
Remove erroneous code duplicating FIX_STRING functionality, adjust ansistring array size
unc0rr
parents:
14190
diff
changeset
|
280 |
p = strchr(str.str, c); |
10134
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
281 |
|
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
282 |
if (p == NULL) { |
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
283 |
return 0; |
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
284 |
} |
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
285 |
|
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
286 |
return p - (unsigned char*)&str.s; |
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
287 |
|
7983 | 288 |
} |
289 |
||
10128 | 290 |
Integer __attribute__((overloadable)) fpcrtl_pos(string255 substr, astring str) { |
291 |
||
10131
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
292 |
unsigned char* p; |
10128 | 293 |
|
294 |
if (str.len == 0) { |
|
295 |
return 0; |
|
296 |
} |
|
297 |
||
298 |
if (substr.len == 0) { |
|
299 |
return 0; |
|
300 |
} |
|
301 |
||
302 |
FIX_STRING(substr); |
|
14159 | 303 |
FIX_STRINGA(str); |
304 |
||
14249
06f2dc4deab2
Remove erroneous code duplicating FIX_STRING functionality, adjust ansistring array size
unc0rr
parents:
14190
diff
changeset
|
305 |
p = strstr(str.str, substr.str); |
10128 | 306 |
|
307 |
if (p == NULL) { |
|
308 |
return 0; |
|
309 |
} |
|
310 |
||
10131
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
311 |
return p - (unsigned char *)&str.s; |
10128 | 312 |
} |
313 |
||
7983 | 314 |
Integer fpcrtl_length(string255 s) { |
315 |
return s.len; |
|
316 |
} |
|
317 |
||
10128 | 318 |
Integer fpcrtl_lengthA(astring s) |
319 |
{ |
|
320 |
return s.len; |
|
321 |
} |
|
322 |
||
323 |
||
7983 | 324 |
string255 fpcrtl_lowerCase(string255 s) { |
325 |
int i; |
|
326 |
||
327 |
for (i = 0; i < s.len; i++) { |
|
328 |
if (s.str[i] >= 'A' && s.str[i] <= 'Z') { |
|
329 |
s.str[i] += 'a' - 'A'; |
|
330 |
} |
|
331 |
} |
|
332 |
||
333 |
return s; |
|
334 |
} |
|
335 |
||
336 |
void fpcrtl_fillChar__vars(void *x, SizeInt count, Byte value) { |
|
337 |
memset(x, value, count); |
|
338 |
} |
|
339 |
||
340 |
void fpcrtl_new__vars(void **p, int size) { |
|
341 |
*p = malloc(size); |
|
342 |
} |
|
343 |
||
14168
5c6f947c342c
Pas2C: Fix data types of Trunc and Ceil
Wuzzy <Wuzzy2@mail.ru>
parents:
14159
diff
changeset
|
344 |
Int64 fpcrtl_trunc(extended n) { |
5c6f947c342c
Pas2C: Fix data types of Trunc and Ceil
Wuzzy <Wuzzy2@mail.ru>
parents:
14159
diff
changeset
|
345 |
return (Int64) n; |
7983 | 346 |
} |
347 |
||
10910 | 348 |
Integer fpcrtl_ceil(extended n) { |
14168
5c6f947c342c
Pas2C: Fix data types of Trunc and Ceil
Wuzzy <Wuzzy2@mail.ru>
parents:
14159
diff
changeset
|
349 |
return (Integer) (ceil(n)); |
10910 | 350 |
} |
351 |
||
7983 | 352 |
LongInt str_to_int(char *src) |
353 |
{ |
|
354 |
int i; |
|
355 |
int len = strlen(src); |
|
356 |
char *end; |
|
357 |
for(i = 0; i < len; i++) |
|
358 |
{ |
|
14190 | 359 |
if(src[i] == '$'){ |
7983 | 360 |
// hex |
361 |
return strtol(src + i + 1, &end, 16); |
|
362 |
} |
|
363 |
} |
|
364 |
||
365 |
// decimal |
|
366 |
return atoi(src); |
|
367 |
} |
|
8850
ae8a957c69fd
engine to c now compiles with some manual intervention (as of bug 596)
koda
parents:
8053
diff
changeset
|
368 |
|
ae8a957c69fd
engine to c now compiles with some manual intervention (as of bug 596)
koda
parents:
8053
diff
changeset
|
369 |
void __attribute__((overloadable)) fpcrtl_val__vars(string255 s, LongInt *a) |
ae8a957c69fd
engine to c now compiles with some manual intervention (as of bug 596)
koda
parents:
8053
diff
changeset
|
370 |
{ |
7983 | 371 |
FIX_STRING(s); |
372 |
*a = str_to_int(s.str); |
|
373 |
} |
|
374 |
||
8850
ae8a957c69fd
engine to c now compiles with some manual intervention (as of bug 596)
koda
parents:
8053
diff
changeset
|
375 |
void __attribute__((overloadable)) fpcrtl_val__vars(string255 s, Byte *a) |
ae8a957c69fd
engine to c now compiles with some manual intervention (as of bug 596)
koda
parents:
8053
diff
changeset
|
376 |
{ |
7983 | 377 |
FIX_STRING(s); |
378 |
*a = str_to_int(s.str); |
|
379 |
} |
|
380 |
||
8850
ae8a957c69fd
engine to c now compiles with some manual intervention (as of bug 596)
koda
parents:
8053
diff
changeset
|
381 |
void __attribute__((overloadable)) fpcrtl_val__vars(string255 s, LongWord *a) |
ae8a957c69fd
engine to c now compiles with some manual intervention (as of bug 596)
koda
parents:
8053
diff
changeset
|
382 |
{ |
7983 | 383 |
FIX_STRING(s); |
384 |
*a = str_to_int(s.str); |
|
385 |
} |
|
386 |
||
387 |
LongInt fpcrtl_random(LongInt l) { |
|
10625
125e120165aa
flake FrameTicks value of 0 now indicades that the frame should not be changed
sheepluva
parents:
10134
diff
changeset
|
388 |
// random(0) is undefined in docs but effectively returns 0 in free pascal |
125e120165aa
flake FrameTicks value of 0 now indicades that the frame should not be changed
sheepluva
parents:
10134
diff
changeset
|
389 |
if (l == 0) { |
10840 | 390 |
printf("WARNING: random(0) called!\n"); |
10625
125e120165aa
flake FrameTicks value of 0 now indicades that the frame should not be changed
sheepluva
parents:
10134
diff
changeset
|
391 |
return 0; |
125e120165aa
flake FrameTicks value of 0 now indicades that the frame should not be changed
sheepluva
parents:
10134
diff
changeset
|
392 |
} |
7983 | 393 |
return (LongInt) (rand() / (double) RAND_MAX * l); |
394 |
} |
|
395 |
||
396 |
void __attribute__((overloadable)) fpcrtl_str__vars(float x, string255 *s) { |
|
397 |
sprintf(s->str, "%f", x); |
|
398 |
s->len = strlen(s->str); |
|
399 |
} |
|
400 |
void __attribute__((overloadable)) fpcrtl_str__vars(double x, string255 *s) { |
|
401 |
sprintf(s->str, "%f", x); |
|
402 |
s->len = strlen(s->str); |
|
403 |
} |
|
404 |
void __attribute__((overloadable)) fpcrtl_str__vars(uint8_t x, string255 *s) { |
|
405 |
sprintf(s->str, "%u", x); |
|
406 |
s->len = strlen(s->str); |
|
407 |
} |
|
408 |
void __attribute__((overloadable)) fpcrtl_str__vars(int8_t x, string255 *s) { |
|
409 |
sprintf(s->str, "%d", x); |
|
410 |
s->len = strlen(s->str); |
|
411 |
} |
|
412 |
void __attribute__((overloadable)) fpcrtl_str__vars(uint16_t x, string255 *s) { |
|
413 |
sprintf(s->str, "%u", x); |
|
414 |
s->len = strlen(s->str); |
|
415 |
} |
|
416 |
void __attribute__((overloadable)) fpcrtl_str__vars(int16_t x, string255 *s) { |
|
417 |
sprintf(s->str, "%d", x); |
|
418 |
s->len = strlen(s->str); |
|
419 |
} |
|
420 |
void __attribute__((overloadable)) fpcrtl_str__vars(uint32_t x, string255 *s) { |
|
421 |
sprintf(s->str, "%u", x); |
|
422 |
s->len = strlen(s->str); |
|
423 |
} |
|
424 |
void __attribute__((overloadable)) fpcrtl_str__vars(int32_t x, string255 *s) { |
|
425 |
sprintf(s->str, "%d", x); |
|
426 |
s->len = strlen(s->str); |
|
427 |
} |
|
428 |
void __attribute__((overloadable)) fpcrtl_str__vars(uint64_t x, string255 *s) { |
|
429 |
sprintf(s->str, "%llu", x); |
|
430 |
s->len = strlen(s->str); |
|
431 |
} |
|
432 |
void __attribute__((overloadable)) fpcrtl_str__vars(int64_t x, string255 *s) { |
|
433 |
sprintf(s->str, "%lld", x); |
|
434 |
s->len = strlen(s->str); |
|
435 |
} |
|
436 |
||
437 |
/* |
|
438 |
* XXX No protection currently! |
|
439 |
*/ |
|
440 |
void fpcrtl_interlockedIncrement__vars(int *i) { |
|
441 |
(*i)++; |
|
442 |
} |
|
443 |
||
444 |
void fpcrtl_interlockedDecrement__vars(int *i) { |
|
445 |
(*i)--; |
|
446 |
} |
|
447 |
||
448 |
/* |
|
449 |
* This function should be called when entering main |
|
450 |
*/ |
|
451 |
void fpcrtl_init(int argc, char** argv) { |
|
452 |
int i; |
|
453 |
paramCount = argc; |
|
454 |
||
455 |
printf("ARGC = %d\n", paramCount); |
|
456 |
||
457 |
for (i = 0; i < argc; i++) { |
|
458 |
if (strlen(argv[i]) > 255) { |
|
459 |
assert(0); |
|
460 |
} |
|
461 |
strcpy(params[i].str, argv[i]); |
|
462 |
params[i].len = strlen(params[i].str); |
|
463 |
} |
|
464 |
||
465 |
} |
|
466 |
||
467 |
int fpcrtl_paramCount() { |
|
468 |
return paramCount - 1; // ignore the first one |
|
469 |
} |
|
470 |
||
471 |
string255 fpcrtl_paramStr(int i) { |
|
472 |
return params[i]; |
|
473 |
} |
|
474 |
||
475 |
int fpcrtl_UTF8ToUnicode(PWideChar dest, PChar src, SizeInt maxLen) { |
|
476 |
//return swprintf(dest, maxLen, L"%hs", "src"); //doesn't work in emscripten |
|
477 |
return 0; |
|
478 |
} |
|
479 |
||
480 |
uint32_t __attribute__((overloadable)) fpcrtl_lo(uint64_t i) { |
|
481 |
return (i & 0xFFFFFFFF); |
|
482 |
} |
|
483 |