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