author | Wuzzy <Wuzzy2@mail.ru> |
Thu, 11 Jul 2019 00:53:29 +0200 | |
changeset 15224 | f16376e9374f |
parent 14168 | 5c6f947c342c |
permissions | -rw-r--r-- |
7983 | 1 |
#ifndef SYSTEM_H_ |
2 |
#define SYSTEM_H_ |
|
3 |
||
10566
cc90ea6448c7
map halt(t) to exit(t) rather than assert(0). all test cases except gravity pass with pas2c now
sheepluva
parents:
10131
diff
changeset
|
4 |
#include <stdlib.h> |
7983 | 5 |
#include <time.h> |
8047
25a4daa6473c
cleanup headers, remove -I . from rtl lib to save a few warnings
koda
parents:
7983
diff
changeset
|
6 |
#include "Types.h" |
7983 | 7 |
#include "misc.h" |
8 |
||
9 |
extern double pi; |
|
10 |
||
11 |
typedef TDate* PDate; |
|
12 |
||
13 |
// dimension info for dynamic arrays |
|
14 |
typedef struct { |
|
15 |
int dim; |
|
16 |
int a[4]; // at most 4 |
|
17 |
} fpcrtl_dimension_t; |
|
18 |
||
19 |
/* |
|
20 |
* Copy returns a string which is a copy if the Count characters in S, starting at position Index. |
|
21 |
* If Count is larger than the length of the string S, the result is truncated. |
|
22 |
* If Index is larger than the length of the string S, then an empty string is returned. |
|
23 |
* Index is 1-based. |
|
24 |
*/ |
|
25 |
string255 fpcrtl_copy(string255 s, Integer Index, Integer Count); |
|
10127 | 26 |
astring fpcrtl_copyA(astring s, Integer Index, Integer Count); |
7983 | 27 |
|
28 |
/* |
|
10838 | 29 |
* Insert a shortstring in another at a specified index |
30 |
*/ |
|
13920
7173b702e8db
tag both as overloadable - seems to satisfy clang 3.4
nemo
parents:
13880
diff
changeset
|
31 |
void __attribute__((overloadable)) fpcrtl_insert__vars(string255 *src, string255 *dst, SizeInt index); |
13880 | 32 |
void __attribute__((overloadable)) fpcrtl_insert__vars(astring *src, astring *dst, SizeInt index); |
33 |
||
10838 | 34 |
#define fpcrtl_insert(src, dst, index) fpcrtl_insert__vars(&(src), &(dst), index); |
35 |
#define fpcrtl_Insert fpcrtl_insert |
|
36 |
||
37 |
/* |
|
7983 | 38 |
* Delete removes Count characters from string S, starting at position Index. |
39 |
* All characters after the deleted characters are shifted Count positions to the left, |
|
40 |
* and the length of the string is adjusted. |
|
41 |
*/ |
|
42 |
#define fpcrtl_delete(s, index, count) fpcrtl_delete__vars(&(s), index, count) |
|
10131
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10127
diff
changeset
|
43 |
void __attribute__((overloadable)) fpcrtl_delete__vars(string255 *s, SizeInt index, SizeInt count); |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10127
diff
changeset
|
44 |
void __attribute__((overloadable)) fpcrtl_delete__vars(astring *s, SizeInt index, SizeInt count); |
10838 | 45 |
#define fpcrtl_Delete fpcrtl_delete |
7983 | 46 |
|
47 |
string255 fpcrtl_floatToStr(double n); |
|
48 |
||
49 |
/* |
|
50 |
* Move data from one location in memory to another |
|
51 |
*/ |
|
52 |
void fpcrtl_move__vars(void *src, void *dst, SizeInt count); |
|
53 |
#define fpcrtl_move(src, dst, count) fpcrtl_move__vars(&(src), &(dst), count); |
|
54 |
#define fpcrtl_Move fpcrtl_move |
|
55 |
||
56 |
Integer __attribute__((overloadable)) fpcrtl_pos(Char c, string255 str); |
|
57 |
Integer __attribute__((overloadable)) fpcrtl_pos(string255 substr, string255 str); |
|
10127 | 58 |
Integer __attribute__((overloadable)) fpcrtl_pos(string255 substr, astring str); |
10131
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10127
diff
changeset
|
59 |
Integer __attribute__((overloadable)) fpcrtl_pos(Char c, astring str); |
7983 | 60 |
|
61 |
Integer fpcrtl_length(string255 s); |
|
62 |
#define fpcrtl_Length fpcrtl_length |
|
10124
aabd1b75d5a3
Even more explicit type conversions and other stuff to help pas2c use ansistrings
unc0rr
parents:
8850
diff
changeset
|
63 |
Integer fpcrtl_lengthA(astring s); |
aabd1b75d5a3
Even more explicit type conversions and other stuff to help pas2c use ansistrings
unc0rr
parents:
8850
diff
changeset
|
64 |
#define fpcrtl_LengthA fpcrtl_lengthA |
7983 | 65 |
|
10131
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10127
diff
changeset
|
66 |
#define fpcrtl_SetLengthA(s, l) do{(s).len = (l);}while(0) |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10127
diff
changeset
|
67 |
|
7983 | 68 |
#define fpcrtl_sqr(x) ((x) * (x)) |
69 |
||
70 |
#define fpcrtl_odd(x) ((x) % 2 != 0 ? true : false) |
|
71 |
||
72 |
#define fpcrtl_StrLen strlen |
|
73 |
||
74 |
#define SizeOf sizeof |
|
75 |
||
76 |
string255 fpcrtl_lowerCase(string255 s); |
|
77 |
#define fpcrtl_LowerCase fpcrtl_lowerCase |
|
78 |
||
79 |
void fpcrtl_fillChar__vars(void *x, SizeInt count, Byte value); |
|
80 |
#define fpcrtl_fillChar(x, count, value) fpcrtl_fillChar__vars(&(x), count, value) |
|
81 |
#define fpcrtl_FillChar fpcrtl_fillChar |
|
82 |
||
83 |
void fpcrtl_new__vars(void **p, int size); |
|
84 |
#define fpcrtl_new(a) fpcrtl_new__vars((void **)&(a), sizeof(*(a))) |
|
85 |
||
86 |
#define fpcrtl_dispose free |
|
87 |
||
88 |
#define fpcrtl_freeMem(p, size) free(p) |
|
89 |
#define fpcrtl_FreeMem(p, size) free(p) |
|
90 |
||
91 |
#define fpcrtl_getMem(size) malloc(size) |
|
92 |
#define fpcrtl_GetMem fpcrtl_getMem |
|
93 |
||
94 |
#define fpcrtl_assigned(p) ((p) != NULL) |
|
95 |
#define fpcrtl_Assigned fpcrtl_assigned |
|
96 |
||
14168
5c6f947c342c
Pas2C: Fix data types of Trunc and Ceil
Wuzzy <Wuzzy2@mail.ru>
parents:
13920
diff
changeset
|
97 |
Int64 fpcrtl_trunc(extended n); |
10910 | 98 |
Integer fpcrtl_ceil(extended n); |
7983 | 99 |
|
8850
ae8a957c69fd
engine to c now compiles with some manual intervention (as of bug 596)
koda
parents:
8047
diff
changeset
|
100 |
#define fpcrtl_val(s, a) fpcrtl_val__vars(s, &(a)) |
ae8a957c69fd
engine to c now compiles with some manual intervention (as of bug 596)
koda
parents:
8047
diff
changeset
|
101 |
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:
8047
diff
changeset
|
102 |
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:
8047
diff
changeset
|
103 |
void __attribute__((overloadable)) fpcrtl_val__vars(string255 s, LongWord *a); |
7983 | 104 |
|
105 |
#define fpcrtl_randomize() srand(time(NULL)) |
|
106 |
||
107 |
/* |
|
108 |
* Random returns a random number larger or equal to 0 and strictly less than L |
|
109 |
*/ |
|
110 |
LongInt fpcrtl_random(LongInt l); |
|
111 |
||
112 |
string255 fpcrtl_paramStr(LongInt); |
|
113 |
#define fpcrtl_ParamStr fpcrtl_paramStr |
|
114 |
||
115 |
/* |
|
116 |
* Str returns a string which represents the value of X. X can be any numerical type. |
|
117 |
*/ |
|
118 |
#define fpcrtl_str(x, s) fpcrtl_str__vars(x, &(s)) |
|
119 |
void __attribute__((overloadable)) fpcrtl_str__vars(float x, string255 *s); |
|
120 |
void __attribute__((overloadable)) fpcrtl_str__vars(double x, string255 *s); |
|
121 |
void __attribute__((overloadable)) fpcrtl_str__vars(uint8_t x, string255 *s); |
|
122 |
void __attribute__((overloadable)) fpcrtl_str__vars(int8_t x, string255 *s); |
|
123 |
void __attribute__((overloadable)) fpcrtl_str__vars(uint16_t x, string255 *s); |
|
124 |
void __attribute__((overloadable)) fpcrtl_str__vars(int16_t x, string255 *s); |
|
125 |
void __attribute__((overloadable)) fpcrtl_str__vars(uint32_t x, string255 *s); |
|
126 |
void __attribute__((overloadable)) fpcrtl_str__vars(int32_t x, string255 *s); |
|
127 |
void __attribute__((overloadable)) fpcrtl_str__vars(uint64_t x, string255 *s); |
|
128 |
void __attribute__((overloadable)) fpcrtl_str__vars(int64_t x, string255 *s); |
|
129 |
||
130 |
void fpcrtl_interlockedIncrement__vars(int *i); |
|
131 |
void fpcrtl_interlockedDecrement__vars(int *i); |
|
132 |
||
133 |
#define fpcrtl_interlockedIncrement(i) fpcrtl_interlockedIncrement__vars(&(i)) |
|
134 |
#define fpcrtl_interlockedDecrement(i) fpcrtl_interlockedDecrement__vars(&(i)) |
|
135 |
||
136 |
#define fpcrtl_InterlockedIncrement fpcrtl_interlockedIncrement |
|
137 |
#define fpcrtl_InterlockedDecrement fpcrtl_interlockedDecrement |
|
138 |
||
139 |
void fpcrtl_init(int argc, char** argv); |
|
140 |
||
141 |
int fpcrtl_paramCount(); |
|
142 |
#define fpcrtl_ParamCount fpcrtl_paramCount |
|
143 |
||
144 |
string255 fpcrtl_paramStr(int i); |
|
145 |
#define fpcrtl_ParamStr fpcrtl_paramStr |
|
146 |
||
147 |
int fpcrtl_UTF8ToUnicode(PWideChar dest, PChar src, SizeInt maxLen); |
|
148 |
||
10566
cc90ea6448c7
map halt(t) to exit(t) rather than assert(0). all test cases except gravity pass with pas2c now
sheepluva
parents:
10131
diff
changeset
|
149 |
// #define fpcrtl_halt(t) assert(0) |
cc90ea6448c7
map halt(t) to exit(t) rather than assert(0). all test cases except gravity pass with pas2c now
sheepluva
parents:
10131
diff
changeset
|
150 |
#define fpcrtl_halt(t) exit(t) |
7983 | 151 |
|
152 |
#define fpcrtl_Load_GL_VERSION_2_0() 1 |
|
153 |
||
154 |
uint32_t __attribute__((overloadable)) fpcrtl_lo(uint64_t); |
|
155 |
#define fpcrtl_Lo fpcrtl_lo |
|
156 |
||
157 |
#define __SET_LENGTH2(arr, d, b) do{\ |
|
158 |
d.dim = 1;\ |
|
159 |
arr = realloc(arr, b * sizeof(typeof(*arr)));\ |
|
160 |
d.a[0] = b;\ |
|
161 |
}while(0) |
|
162 |
||
163 |
#define SET_LENGTH2(arr, b) __SET_LENGTH2(arr, arr##_dimension_info, (b)) |
|
164 |
||
165 |
#define __SET_LENGTH3(arr, d, b, c) do{\ |
|
166 |
d.dim = 2;\ |
|
167 |
for (int i = 0; i < d.a[0]; i++) {\ |
|
168 |
arr[i] = realloc(arr[i], c * sizeof(typeof(**arr)));\ |
|
169 |
}\ |
|
170 |
if (d.a[0] > b) {\ |
|
171 |
for (int i = b; i < d.a[0]; i++) {\ |
|
172 |
free(arr[i]);\ |
|
173 |
}\ |
|
174 |
arr = realloc(arr, b * sizeof(typeof(*arr)));\ |
|
175 |
} else if (d.a[0] < b) {\ |
|
176 |
arr = realloc(arr, b * sizeof(typeof(*arr)));\ |
|
177 |
for (int i = d.a[0]; i < b; i++) {\ |
|
178 |
arr[i] = malloc(c * sizeof(typeof(**arr)));\ |
|
179 |
memset(arr[i], 0, c * sizeof(typeof(**arr)));\ |
|
180 |
}\ |
|
181 |
}\ |
|
182 |
d.a[0] = b;\ |
|
183 |
d.a[1] = c;\ |
|
184 |
}while(0) |
|
185 |
||
186 |
#define SET_LENGTH3(arr, b, c) __SET_LENGTH3(arr, arr##_dimension_info, (b), (c)) |
|
187 |
||
188 |
#define fpcrtl_SetLength(...) macro_dispatcher(SET_LENGTH, __VA_ARGS__)(__VA_ARGS__) |
|
189 |
||
190 |
#endif /* SYSTEM_H_ */ |