author | unc0rr |
Thu, 11 Oct 2018 23:43:31 +0200 | |
changeset 13880 | 5f819b90d479 |
parent 11655 | e15eb10f1703 |
child 13920 | 7173b702e8db |
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 |
||
10838 | 77 |
void fpcrtl_insert__vars(string255 *src, string255 *dst, SizeInt index) { |
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 |
|
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
278 |
p = strchr(str.s + 1, c); |
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
279 |
|
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
280 |
if (p == NULL) { |
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
281 |
return 0; |
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
282 |
} |
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
283 |
|
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
284 |
return p - (unsigned char*)&str.s; |
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
285 |
|
7983 | 286 |
} |
287 |
||
10128 | 288 |
Integer __attribute__((overloadable)) fpcrtl_pos(string255 substr, astring str) { |
289 |
||
10131
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
290 |
unsigned char* p; |
10128 | 291 |
|
292 |
if (str.len == 0) { |
|
293 |
return 0; |
|
294 |
} |
|
295 |
||
296 |
if (substr.len == 0) { |
|
297 |
return 0; |
|
298 |
} |
|
299 |
||
300 |
FIX_STRING(substr); |
|
301 |
str.s[str.len] = 0; |
|
302 |
||
303 |
p = strstr(str.s + 1, substr.str); |
|
304 |
||
305 |
if (p == NULL) { |
|
306 |
return 0; |
|
307 |
} |
|
308 |
||
10131
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
309 |
return p - (unsigned char *)&str.s; |
10128 | 310 |
} |
311 |
||
7983 | 312 |
Integer fpcrtl_length(string255 s) { |
313 |
return s.len; |
|
314 |
} |
|
315 |
||
10128 | 316 |
Integer fpcrtl_lengthA(astring s) |
317 |
{ |
|
318 |
return s.len; |
|
319 |
} |
|
320 |
||
321 |
||
7983 | 322 |
string255 fpcrtl_lowerCase(string255 s) { |
323 |
int i; |
|
324 |
||
325 |
for (i = 0; i < s.len; i++) { |
|
326 |
if (s.str[i] >= 'A' && s.str[i] <= 'Z') { |
|
327 |
s.str[i] += 'a' - 'A'; |
|
328 |
} |
|
329 |
} |
|
330 |
||
331 |
return s; |
|
332 |
} |
|
333 |
||
334 |
void fpcrtl_fillChar__vars(void *x, SizeInt count, Byte value) { |
|
335 |
memset(x, value, count); |
|
336 |
} |
|
337 |
||
338 |
void fpcrtl_new__vars(void **p, int size) { |
|
339 |
*p = malloc(size); |
|
340 |
} |
|
341 |
||
342 |
Integer fpcrtl_trunc(extended n) { |
|
343 |
return (int) n; |
|
344 |
} |
|
345 |
||
10910 | 346 |
Integer fpcrtl_ceil(extended n) { |
347 |
return (int) (ceil(n)); |
|
348 |
} |
|
349 |
||
7983 | 350 |
LongInt str_to_int(char *src) |
351 |
{ |
|
352 |
int i; |
|
353 |
int len = strlen(src); |
|
354 |
char *end; |
|
355 |
for(i = 0; i < len; i++) |
|
356 |
{ |
|
357 |
if(src[i] == '$'){ |
|
358 |
// hex |
|
359 |
return strtol(src + i + 1, &end, 16); |
|
360 |
} |
|
361 |
} |
|
362 |
||
363 |
// decimal |
|
364 |
return atoi(src); |
|
365 |
} |
|
8850
ae8a957c69fd
engine to c now compiles with some manual intervention (as of bug 596)
koda
parents:
8053
diff
changeset
|
366 |
|
ae8a957c69fd
engine to c now compiles with some manual intervention (as of bug 596)
koda
parents:
8053
diff
changeset
|
367 |
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
|
368 |
{ |
7983 | 369 |
FIX_STRING(s); |
370 |
*a = str_to_int(s.str); |
|
371 |
} |
|
372 |
||
8850
ae8a957c69fd
engine to c now compiles with some manual intervention (as of bug 596)
koda
parents:
8053
diff
changeset
|
373 |
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
|
374 |
{ |
7983 | 375 |
FIX_STRING(s); |
376 |
*a = str_to_int(s.str); |
|
377 |
} |
|
378 |
||
8850
ae8a957c69fd
engine to c now compiles with some manual intervention (as of bug 596)
koda
parents:
8053
diff
changeset
|
379 |
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
|
380 |
{ |
7983 | 381 |
FIX_STRING(s); |
382 |
*a = str_to_int(s.str); |
|
383 |
} |
|
384 |
||
385 |
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
|
386 |
// 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
|
387 |
if (l == 0) { |
10840 | 388 |
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
|
389 |
return 0; |
125e120165aa
flake FrameTicks value of 0 now indicades that the frame should not be changed
sheepluva
parents:
10134
diff
changeset
|
390 |
} |
7983 | 391 |
return (LongInt) (rand() / (double) RAND_MAX * l); |
392 |
} |
|
393 |
||
394 |
void __attribute__((overloadable)) fpcrtl_str__vars(float x, string255 *s) { |
|
395 |
sprintf(s->str, "%f", x); |
|
396 |
s->len = strlen(s->str); |
|
397 |
} |
|
398 |
void __attribute__((overloadable)) fpcrtl_str__vars(double x, string255 *s) { |
|
399 |
sprintf(s->str, "%f", x); |
|
400 |
s->len = strlen(s->str); |
|
401 |
} |
|
402 |
void __attribute__((overloadable)) fpcrtl_str__vars(uint8_t x, string255 *s) { |
|
403 |
sprintf(s->str, "%u", x); |
|
404 |
s->len = strlen(s->str); |
|
405 |
} |
|
406 |
void __attribute__((overloadable)) fpcrtl_str__vars(int8_t x, string255 *s) { |
|
407 |
sprintf(s->str, "%d", x); |
|
408 |
s->len = strlen(s->str); |
|
409 |
} |
|
410 |
void __attribute__((overloadable)) fpcrtl_str__vars(uint16_t x, string255 *s) { |
|
411 |
sprintf(s->str, "%u", x); |
|
412 |
s->len = strlen(s->str); |
|
413 |
} |
|
414 |
void __attribute__((overloadable)) fpcrtl_str__vars(int16_t x, string255 *s) { |
|
415 |
sprintf(s->str, "%d", x); |
|
416 |
s->len = strlen(s->str); |
|
417 |
} |
|
418 |
void __attribute__((overloadable)) fpcrtl_str__vars(uint32_t x, string255 *s) { |
|
419 |
sprintf(s->str, "%u", x); |
|
420 |
s->len = strlen(s->str); |
|
421 |
} |
|
422 |
void __attribute__((overloadable)) fpcrtl_str__vars(int32_t x, string255 *s) { |
|
423 |
sprintf(s->str, "%d", x); |
|
424 |
s->len = strlen(s->str); |
|
425 |
} |
|
426 |
void __attribute__((overloadable)) fpcrtl_str__vars(uint64_t x, string255 *s) { |
|
427 |
sprintf(s->str, "%llu", x); |
|
428 |
s->len = strlen(s->str); |
|
429 |
} |
|
430 |
void __attribute__((overloadable)) fpcrtl_str__vars(int64_t x, string255 *s) { |
|
431 |
sprintf(s->str, "%lld", x); |
|
432 |
s->len = strlen(s->str); |
|
433 |
} |
|
434 |
||
435 |
/* |
|
436 |
* XXX No protection currently! |
|
437 |
*/ |
|
438 |
void fpcrtl_interlockedIncrement__vars(int *i) { |
|
439 |
(*i)++; |
|
440 |
} |
|
441 |
||
442 |
void fpcrtl_interlockedDecrement__vars(int *i) { |
|
443 |
(*i)--; |
|
444 |
} |
|
445 |
||
446 |
/* |
|
447 |
* This function should be called when entering main |
|
448 |
*/ |
|
449 |
void fpcrtl_init(int argc, char** argv) { |
|
450 |
int i; |
|
451 |
paramCount = argc; |
|
452 |
||
453 |
printf("ARGC = %d\n", paramCount); |
|
454 |
||
455 |
for (i = 0; i < argc; i++) { |
|
456 |
if (strlen(argv[i]) > 255) { |
|
457 |
assert(0); |
|
458 |
} |
|
459 |
strcpy(params[i].str, argv[i]); |
|
460 |
params[i].len = strlen(params[i].str); |
|
461 |
} |
|
462 |
||
463 |
} |
|
464 |
||
465 |
int fpcrtl_paramCount() { |
|
466 |
return paramCount - 1; // ignore the first one |
|
467 |
} |
|
468 |
||
469 |
string255 fpcrtl_paramStr(int i) { |
|
470 |
return params[i]; |
|
471 |
} |
|
472 |
||
473 |
int fpcrtl_UTF8ToUnicode(PWideChar dest, PChar src, SizeInt maxLen) { |
|
474 |
//return swprintf(dest, maxLen, L"%hs", "src"); //doesn't work in emscripten |
|
475 |
return 0; |
|
476 |
} |
|
477 |
||
478 |
uint32_t __attribute__((overloadable)) fpcrtl_lo(uint64_t i) { |
|
479 |
return (i & 0xFFFFFFFF); |
|
480 |
} |
|
481 |