author | sheepluva |
Fri, 29 Apr 2016 13:12:26 +0200 | |
changeset 11777 | 927c45b83496 |
parent 11660 | e15eb10f1703 |
child 13885 | 5f819b90d479 |
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> |
|
11660 | 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) { |
|
93 |
num_insert = 255 - (index - 1); |
|
94 |
num_shift = 0; |
|
95 |
} |
|
96 |
// shift trailing chars |
|
97 |
else { |
|
98 |
// number of bytes to be shifted |
|
99 |
num_shift = dst->len - (index - 1); |
|
100 |
||
101 |
if (num_shift > 0) { |
|
102 |
// don't overflow when shifting |
|
103 |
if (num_shift + num_preshift > 255) |
|
104 |
num_shift = 255 - num_preshift; |
|
105 |
||
106 |
// time to move some bytes! |
|
107 |
memmove(dst->str + num_preshift, dst->str + index - 1, num_shift); |
|
108 |
} |
|
109 |
} |
|
110 |
||
111 |
// actual byte insertion |
|
112 |
memmove(dst->str + index - 1, src->str, num_insert); |
|
113 |
// store new length |
|
114 |
dst->len = num_shift + num_preshift; |
|
115 |
} |
|
116 |
||
10131
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
117 |
void __attribute__((overloadable)) fpcrtl_delete__vars(string255 *s, SizeInt index, SizeInt count) { |
7983 | 118 |
// number of chars to be move |
119 |
int num_move; |
|
120 |
int new_length; |
|
121 |
||
122 |
if (index < 1) { |
|
123 |
// in fpc, if index < 1, the string won't be modified |
|
124 |
return; |
|
125 |
} |
|
126 |
||
127 |
if(index > s->len){ |
|
128 |
return; |
|
129 |
} |
|
130 |
||
131 |
if (count > s->len - index + 1) { |
|
132 |
s->len = index - 1; |
|
133 |
return; |
|
134 |
} |
|
135 |
||
136 |
num_move = s->len - index + 1 - count; |
|
137 |
new_length = s->len - count; |
|
138 |
||
10131
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
139 |
memmove(s->str + index - 1, s->str + index - 1 + count, num_move); |
7983 | 140 |
s->str[new_length] = 0; |
141 |
||
142 |
s->len = new_length; |
|
143 |
||
144 |
} |
|
145 |
||
10131
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
146 |
void __attribute__((overloadable)) fpcrtl_delete__vars(astring *s, SizeInt index, SizeInt count) { |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
147 |
// number of chars to be move |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
148 |
int num_move; |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
149 |
int new_length; |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
150 |
|
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
151 |
if (index < 1) { |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
152 |
// in fpc, if index < 1, the string won't be modified |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
153 |
return; |
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 |
|
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
156 |
if(index > s->len){ |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
157 |
return; |
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 |
|
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
160 |
if (count > s->len - index + 1) { |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
161 |
s->len = index - 1; |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
162 |
return; |
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 |
|
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
165 |
num_move = s->len - index + 1 - count; |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
166 |
new_length = s->len - count; |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
167 |
|
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
168 |
memmove(s->s + index, s->s + index + count, num_move); |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
169 |
|
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
170 |
s->len = new_length; |
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 |
} |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
173 |
|
7983 | 174 |
string255 fpcrtl_floatToStr(double n) { |
175 |
string255 t; |
|
176 |
sprintf(t.str, "%f", n); |
|
177 |
t.len = strlen(t.str); |
|
178 |
||
179 |
return t; |
|
180 |
} |
|
181 |
||
182 |
void fpcrtl_move__vars(void *src, void *dst, SizeInt count) { |
|
183 |
memmove(dst, src, count); |
|
184 |
} |
|
185 |
||
186 |
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
|
187 |
|
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
188 |
unsigned char* p; |
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
189 |
|
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
190 |
if (str.len == 0) { |
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
191 |
return 0; |
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 |
|
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
194 |
FIX_STRING(str); |
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
195 |
|
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
196 |
p = strchr(str.str, c); |
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
197 |
|
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
198 |
if (p == NULL) { |
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
199 |
return 0; |
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 |
|
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
202 |
return p - (unsigned char*)&str.s; |
7983 | 203 |
} |
204 |
||
205 |
Integer __attribute__((overloadable)) fpcrtl_pos(string255 substr, string255 str) { |
|
206 |
||
10131
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
207 |
unsigned char* p; |
7983 | 208 |
|
209 |
if (str.len == 0) { |
|
210 |
return 0; |
|
211 |
} |
|
212 |
||
213 |
if (substr.len == 0) { |
|
214 |
return 0; |
|
215 |
} |
|
216 |
||
10128 | 217 |
FIX_STRING(substr); |
218 |
FIX_STRING(str); |
|
7983 | 219 |
|
220 |
p = strstr(str.str, substr.str); |
|
221 |
||
222 |
if (p == NULL) { |
|
223 |
return 0; |
|
224 |
} |
|
225 |
||
10131
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
226 |
return p - (unsigned char*)&str.s; |
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 |
|
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
229 |
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
|
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 |
p = strchr(str.s + 1, c); |
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 |
if (p == NULL) { |
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
239 |
return 0; |
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 |
|
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
242 |
return p - (unsigned char*)&str.s; |
81d733899e06
Use strchr instead of strstr with specially constructed string255 struct (not tested)
unc0rr
parents:
10131
diff
changeset
|
243 |
|
7983 | 244 |
} |
245 |
||
10128 | 246 |
Integer __attribute__((overloadable)) fpcrtl_pos(string255 substr, astring str) { |
247 |
||
10131
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
248 |
unsigned char* p; |
10128 | 249 |
|
250 |
if (str.len == 0) { |
|
251 |
return 0; |
|
252 |
} |
|
253 |
||
254 |
if (substr.len == 0) { |
|
255 |
return 0; |
|
256 |
} |
|
257 |
||
258 |
FIX_STRING(substr); |
|
259 |
str.s[str.len] = 0; |
|
260 |
||
261 |
p = strstr(str.s + 1, substr.str); |
|
262 |
||
263 |
if (p == NULL) { |
|
264 |
return 0; |
|
265 |
} |
|
266 |
||
10131
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10128
diff
changeset
|
267 |
return p - (unsigned char *)&str.s; |
10128 | 268 |
} |
269 |
||
7983 | 270 |
Integer fpcrtl_length(string255 s) { |
271 |
return s.len; |
|
272 |
} |
|
273 |
||
10128 | 274 |
Integer fpcrtl_lengthA(astring s) |
275 |
{ |
|
276 |
return s.len; |
|
277 |
} |
|
278 |
||
279 |
||
7983 | 280 |
string255 fpcrtl_lowerCase(string255 s) { |
281 |
int i; |
|
282 |
||
283 |
for (i = 0; i < s.len; i++) { |
|
284 |
if (s.str[i] >= 'A' && s.str[i] <= 'Z') { |
|
285 |
s.str[i] += 'a' - 'A'; |
|
286 |
} |
|
287 |
} |
|
288 |
||
289 |
return s; |
|
290 |
} |
|
291 |
||
292 |
void fpcrtl_fillChar__vars(void *x, SizeInt count, Byte value) { |
|
293 |
memset(x, value, count); |
|
294 |
} |
|
295 |
||
296 |
void fpcrtl_new__vars(void **p, int size) { |
|
297 |
*p = malloc(size); |
|
298 |
} |
|
299 |
||
300 |
Integer fpcrtl_trunc(extended n) { |
|
301 |
return (int) n; |
|
302 |
} |
|
303 |
||
10910 | 304 |
Integer fpcrtl_ceil(extended n) { |
305 |
return (int) (ceil(n)); |
|
306 |
} |
|
307 |
||
7983 | 308 |
LongInt str_to_int(char *src) |
309 |
{ |
|
310 |
int i; |
|
311 |
int len = strlen(src); |
|
312 |
char *end; |
|
313 |
for(i = 0; i < len; i++) |
|
314 |
{ |
|
315 |
if(src[i] == '$'){ |
|
316 |
// hex |
|
317 |
return strtol(src + i + 1, &end, 16); |
|
318 |
} |
|
319 |
} |
|
320 |
||
321 |
// decimal |
|
322 |
return atoi(src); |
|
323 |
} |
|
8850
ae8a957c69fd
engine to c now compiles with some manual intervention (as of bug 596)
koda
parents:
8053
diff
changeset
|
324 |
|
ae8a957c69fd
engine to c now compiles with some manual intervention (as of bug 596)
koda
parents:
8053
diff
changeset
|
325 |
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
|
326 |
{ |
7983 | 327 |
FIX_STRING(s); |
328 |
*a = str_to_int(s.str); |
|
329 |
} |
|
330 |
||
8850
ae8a957c69fd
engine to c now compiles with some manual intervention (as of bug 596)
koda
parents:
8053
diff
changeset
|
331 |
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
|
332 |
{ |
7983 | 333 |
FIX_STRING(s); |
334 |
*a = str_to_int(s.str); |
|
335 |
} |
|
336 |
||
8850
ae8a957c69fd
engine to c now compiles with some manual intervention (as of bug 596)
koda
parents:
8053
diff
changeset
|
337 |
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
|
338 |
{ |
7983 | 339 |
FIX_STRING(s); |
340 |
*a = str_to_int(s.str); |
|
341 |
} |
|
342 |
||
343 |
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
|
344 |
// 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
|
345 |
if (l == 0) { |
10840 | 346 |
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
|
347 |
return 0; |
125e120165aa
flake FrameTicks value of 0 now indicades that the frame should not be changed
sheepluva
parents:
10134
diff
changeset
|
348 |
} |
7983 | 349 |
return (LongInt) (rand() / (double) RAND_MAX * l); |
350 |
} |
|
351 |
||
352 |
void __attribute__((overloadable)) fpcrtl_str__vars(float x, string255 *s) { |
|
353 |
sprintf(s->str, "%f", x); |
|
354 |
s->len = strlen(s->str); |
|
355 |
} |
|
356 |
void __attribute__((overloadable)) fpcrtl_str__vars(double x, string255 *s) { |
|
357 |
sprintf(s->str, "%f", x); |
|
358 |
s->len = strlen(s->str); |
|
359 |
} |
|
360 |
void __attribute__((overloadable)) fpcrtl_str__vars(uint8_t x, string255 *s) { |
|
361 |
sprintf(s->str, "%u", x); |
|
362 |
s->len = strlen(s->str); |
|
363 |
} |
|
364 |
void __attribute__((overloadable)) fpcrtl_str__vars(int8_t x, string255 *s) { |
|
365 |
sprintf(s->str, "%d", x); |
|
366 |
s->len = strlen(s->str); |
|
367 |
} |
|
368 |
void __attribute__((overloadable)) fpcrtl_str__vars(uint16_t x, string255 *s) { |
|
369 |
sprintf(s->str, "%u", x); |
|
370 |
s->len = strlen(s->str); |
|
371 |
} |
|
372 |
void __attribute__((overloadable)) fpcrtl_str__vars(int16_t x, string255 *s) { |
|
373 |
sprintf(s->str, "%d", x); |
|
374 |
s->len = strlen(s->str); |
|
375 |
} |
|
376 |
void __attribute__((overloadable)) fpcrtl_str__vars(uint32_t x, string255 *s) { |
|
377 |
sprintf(s->str, "%u", x); |
|
378 |
s->len = strlen(s->str); |
|
379 |
} |
|
380 |
void __attribute__((overloadable)) fpcrtl_str__vars(int32_t x, string255 *s) { |
|
381 |
sprintf(s->str, "%d", x); |
|
382 |
s->len = strlen(s->str); |
|
383 |
} |
|
384 |
void __attribute__((overloadable)) fpcrtl_str__vars(uint64_t x, string255 *s) { |
|
385 |
sprintf(s->str, "%llu", x); |
|
386 |
s->len = strlen(s->str); |
|
387 |
} |
|
388 |
void __attribute__((overloadable)) fpcrtl_str__vars(int64_t x, string255 *s) { |
|
389 |
sprintf(s->str, "%lld", x); |
|
390 |
s->len = strlen(s->str); |
|
391 |
} |
|
392 |
||
393 |
/* |
|
394 |
* XXX No protection currently! |
|
395 |
*/ |
|
396 |
void fpcrtl_interlockedIncrement__vars(int *i) { |
|
397 |
(*i)++; |
|
398 |
} |
|
399 |
||
400 |
void fpcrtl_interlockedDecrement__vars(int *i) { |
|
401 |
(*i)--; |
|
402 |
} |
|
403 |
||
404 |
/* |
|
405 |
* This function should be called when entering main |
|
406 |
*/ |
|
407 |
void fpcrtl_init(int argc, char** argv) { |
|
408 |
int i; |
|
409 |
paramCount = argc; |
|
410 |
||
411 |
printf("ARGC = %d\n", paramCount); |
|
412 |
||
413 |
for (i = 0; i < argc; i++) { |
|
414 |
if (strlen(argv[i]) > 255) { |
|
415 |
assert(0); |
|
416 |
} |
|
417 |
strcpy(params[i].str, argv[i]); |
|
418 |
params[i].len = strlen(params[i].str); |
|
419 |
} |
|
420 |
||
421 |
} |
|
422 |
||
423 |
int fpcrtl_paramCount() { |
|
424 |
return paramCount - 1; // ignore the first one |
|
425 |
} |
|
426 |
||
427 |
string255 fpcrtl_paramStr(int i) { |
|
428 |
return params[i]; |
|
429 |
} |
|
430 |
||
431 |
int fpcrtl_UTF8ToUnicode(PWideChar dest, PChar src, SizeInt maxLen) { |
|
432 |
//return swprintf(dest, maxLen, L"%hs", "src"); //doesn't work in emscripten |
|
433 |
return 0; |
|
434 |
} |
|
435 |
||
436 |
uint32_t __attribute__((overloadable)) fpcrtl_lo(uint64_t i) { |
|
437 |
return (i & 0xFFFFFFFF); |
|
438 |
} |
|
439 |