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