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