author | unc0rr |
Mon, 10 Feb 2014 00:43:03 +0400 | |
changeset 10127 | 7f29a65aa1e4 |
parent 10124 | aabd1b75d5a3 |
child 10131 | 4b4a043111f4 |
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) |
|
33 |
void fpcrtl_delete__vars(string255 *s, SizeInt index, SizeInt count); |
|
34 |
||
35 |
string255 fpcrtl_floatToStr(double n); |
|
36 |
||
37 |
/* |
|
38 |
* Move data from one location in memory to another |
|
39 |
*/ |
|
40 |
void fpcrtl_move__vars(void *src, void *dst, SizeInt count); |
|
41 |
#define fpcrtl_move(src, dst, count) fpcrtl_move__vars(&(src), &(dst), count); |
|
42 |
#define fpcrtl_Move fpcrtl_move |
|
43 |
||
44 |
Integer __attribute__((overloadable)) fpcrtl_pos(Char c, string255 str); |
|
45 |
Integer __attribute__((overloadable)) fpcrtl_pos(string255 substr, string255 str); |
|
10127 | 46 |
Integer __attribute__((overloadable)) fpcrtl_pos(string255 substr, astring str); |
7983 | 47 |
|
48 |
Integer fpcrtl_length(string255 s); |
|
49 |
#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
|
50 |
Integer fpcrtl_lengthA(astring s); |
aabd1b75d5a3
Even more explicit type conversions and other stuff to help pas2c use ansistrings
unc0rr
parents:
8850
diff
changeset
|
51 |
#define fpcrtl_LengthA fpcrtl_lengthA |
7983 | 52 |
|
53 |
#define fpcrtl_sqr(x) ((x) * (x)) |
|
54 |
||
55 |
#define fpcrtl_odd(x) ((x) % 2 != 0 ? true : false) |
|
56 |
||
57 |
#define fpcrtl_StrLen strlen |
|
58 |
||
59 |
#define SizeOf sizeof |
|
60 |
||
61 |
string255 fpcrtl_lowerCase(string255 s); |
|
62 |
#define fpcrtl_LowerCase fpcrtl_lowerCase |
|
63 |
||
64 |
void fpcrtl_fillChar__vars(void *x, SizeInt count, Byte value); |
|
65 |
#define fpcrtl_fillChar(x, count, value) fpcrtl_fillChar__vars(&(x), count, value) |
|
66 |
#define fpcrtl_FillChar fpcrtl_fillChar |
|
67 |
||
68 |
void fpcrtl_new__vars(void **p, int size); |
|
69 |
#define fpcrtl_new(a) fpcrtl_new__vars((void **)&(a), sizeof(*(a))) |
|
70 |
||
71 |
#define fpcrtl_dispose free |
|
72 |
||
73 |
#define fpcrtl_freeMem(p, size) free(p) |
|
74 |
#define fpcrtl_FreeMem(p, size) free(p) |
|
75 |
||
76 |
#define fpcrtl_getMem(size) malloc(size) |
|
77 |
#define fpcrtl_GetMem fpcrtl_getMem |
|
78 |
||
79 |
#define fpcrtl_assigned(p) ((p) != NULL) |
|
80 |
#define fpcrtl_Assigned fpcrtl_assigned |
|
81 |
||
82 |
Integer fpcrtl_trunc(extended n); |
|
83 |
||
8850
ae8a957c69fd
engine to c now compiles with some manual intervention (as of bug 596)
koda
parents:
8047
diff
changeset
|
84 |
#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
|
85 |
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
|
86 |
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
|
87 |
void __attribute__((overloadable)) fpcrtl_val__vars(string255 s, LongWord *a); |
7983 | 88 |
|
89 |
#define fpcrtl_randomize() srand(time(NULL)) |
|
90 |
||
91 |
/* |
|
92 |
* Random returns a random number larger or equal to 0 and strictly less than L |
|
93 |
*/ |
|
94 |
LongInt fpcrtl_random(LongInt l); |
|
95 |
||
96 |
string255 fpcrtl_paramStr(LongInt); |
|
97 |
#define fpcrtl_ParamStr fpcrtl_paramStr |
|
98 |
||
99 |
/* |
|
100 |
* Str returns a string which represents the value of X. X can be any numerical type. |
|
101 |
*/ |
|
102 |
#define fpcrtl_str(x, s) fpcrtl_str__vars(x, &(s)) |
|
103 |
void __attribute__((overloadable)) fpcrtl_str__vars(float x, string255 *s); |
|
104 |
void __attribute__((overloadable)) fpcrtl_str__vars(double x, string255 *s); |
|
105 |
void __attribute__((overloadable)) fpcrtl_str__vars(uint8_t x, string255 *s); |
|
106 |
void __attribute__((overloadable)) fpcrtl_str__vars(int8_t x, string255 *s); |
|
107 |
void __attribute__((overloadable)) fpcrtl_str__vars(uint16_t x, string255 *s); |
|
108 |
void __attribute__((overloadable)) fpcrtl_str__vars(int16_t x, string255 *s); |
|
109 |
void __attribute__((overloadable)) fpcrtl_str__vars(uint32_t x, string255 *s); |
|
110 |
void __attribute__((overloadable)) fpcrtl_str__vars(int32_t x, string255 *s); |
|
111 |
void __attribute__((overloadable)) fpcrtl_str__vars(uint64_t x, string255 *s); |
|
112 |
void __attribute__((overloadable)) fpcrtl_str__vars(int64_t x, string255 *s); |
|
113 |
||
114 |
void fpcrtl_interlockedIncrement__vars(int *i); |
|
115 |
void fpcrtl_interlockedDecrement__vars(int *i); |
|
116 |
||
117 |
#define fpcrtl_interlockedIncrement(i) fpcrtl_interlockedIncrement__vars(&(i)) |
|
118 |
#define fpcrtl_interlockedDecrement(i) fpcrtl_interlockedDecrement__vars(&(i)) |
|
119 |
||
120 |
#define fpcrtl_InterlockedIncrement fpcrtl_interlockedIncrement |
|
121 |
#define fpcrtl_InterlockedDecrement fpcrtl_interlockedDecrement |
|
122 |
||
123 |
void fpcrtl_init(int argc, char** argv); |
|
124 |
||
125 |
int fpcrtl_paramCount(); |
|
126 |
#define fpcrtl_ParamCount fpcrtl_paramCount |
|
127 |
||
128 |
string255 fpcrtl_paramStr(int i); |
|
129 |
#define fpcrtl_ParamStr fpcrtl_paramStr |
|
130 |
||
131 |
int fpcrtl_UTF8ToUnicode(PWideChar dest, PChar src, SizeInt maxLen); |
|
132 |
||
133 |
#define fpcrtl_halt(t) assert(0) |
|
134 |
||
135 |
#define fpcrtl_Load_GL_VERSION_2_0() 1 |
|
136 |
||
137 |
uint32_t __attribute__((overloadable)) fpcrtl_lo(uint64_t); |
|
138 |
#define fpcrtl_Lo fpcrtl_lo |
|
139 |
||
140 |
#define __SET_LENGTH2(arr, d, b) do{\ |
|
141 |
d.dim = 1;\ |
|
142 |
arr = realloc(arr, b * sizeof(typeof(*arr)));\ |
|
143 |
d.a[0] = b;\ |
|
144 |
}while(0) |
|
145 |
||
146 |
#define SET_LENGTH2(arr, b) __SET_LENGTH2(arr, arr##_dimension_info, (b)) |
|
147 |
||
148 |
#define __SET_LENGTH3(arr, d, b, c) do{\ |
|
149 |
d.dim = 2;\ |
|
150 |
for (int i = 0; i < d.a[0]; i++) {\ |
|
151 |
arr[i] = realloc(arr[i], c * sizeof(typeof(**arr)));\ |
|
152 |
}\ |
|
153 |
if (d.a[0] > b) {\ |
|
154 |
for (int i = b; i < d.a[0]; i++) {\ |
|
155 |
free(arr[i]);\ |
|
156 |
}\ |
|
157 |
arr = realloc(arr, b * sizeof(typeof(*arr)));\ |
|
158 |
} else if (d.a[0] < b) {\ |
|
159 |
arr = realloc(arr, b * sizeof(typeof(*arr)));\ |
|
160 |
for (int i = d.a[0]; i < b; i++) {\ |
|
161 |
arr[i] = malloc(c * sizeof(typeof(**arr)));\ |
|
162 |
memset(arr[i], 0, c * sizeof(typeof(**arr)));\ |
|
163 |
}\ |
|
164 |
}\ |
|
165 |
d.a[0] = b;\ |
|
166 |
d.a[1] = c;\ |
|
167 |
}while(0) |
|
168 |
||
169 |
#define SET_LENGTH3(arr, b, c) __SET_LENGTH3(arr, arr##_dimension_info, (b), (c)) |
|
170 |
||
171 |
#define fpcrtl_SetLength(...) macro_dispatcher(SET_LENGTH, __VA_ARGS__)(__VA_ARGS__) |
|
172 |
||
173 |
#endif /* SYSTEM_H_ */ |