author | koda |
Tue, 13 Nov 2012 23:56:50 +0100 | |
branch | webgl |
changeset 8050 | c82b68016c68 |
parent 8047 | 25a4daa6473c |
child 8850 | ae8a957c69fd |
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); |
|
25 |
||
26 |
/* |
|
27 |
* Delete removes Count characters from string S, starting at position Index. |
|
28 |
* All characters after the deleted characters are shifted Count positions to the left, |
|
29 |
* and the length of the string is adjusted. |
|
30 |
*/ |
|
31 |
#define fpcrtl_delete(s, index, count) fpcrtl_delete__vars(&(s), index, count) |
|
32 |
void fpcrtl_delete__vars(string255 *s, SizeInt index, SizeInt count); |
|
33 |
||
34 |
string255 fpcrtl_floatToStr(double n); |
|
35 |
||
36 |
/* |
|
37 |
* Move data from one location in memory to another |
|
38 |
*/ |
|
39 |
void fpcrtl_move__vars(void *src, void *dst, SizeInt count); |
|
40 |
#define fpcrtl_move(src, dst, count) fpcrtl_move__vars(&(src), &(dst), count); |
|
41 |
#define fpcrtl_Move fpcrtl_move |
|
42 |
||
43 |
Integer __attribute__((overloadable)) fpcrtl_pos(Char c, string255 str); |
|
44 |
Integer __attribute__((overloadable)) fpcrtl_pos(string255 substr, string255 str); |
|
45 |
||
46 |
Integer fpcrtl_length(string255 s); |
|
47 |
#define fpcrtl_Length fpcrtl_length |
|
48 |
||
49 |
#define fpcrtl_sqr(x) ((x) * (x)) |
|
50 |
||
51 |
#define fpcrtl_odd(x) ((x) % 2 != 0 ? true : false) |
|
52 |
||
53 |
#define fpcrtl_StrLen strlen |
|
54 |
||
55 |
#define SizeOf sizeof |
|
56 |
||
57 |
string255 fpcrtl_lowerCase(string255 s); |
|
58 |
#define fpcrtl_LowerCase fpcrtl_lowerCase |
|
59 |
||
60 |
void fpcrtl_fillChar__vars(void *x, SizeInt count, Byte value); |
|
61 |
#define fpcrtl_fillChar(x, count, value) fpcrtl_fillChar__vars(&(x), count, value) |
|
62 |
#define fpcrtl_FillChar fpcrtl_fillChar |
|
63 |
||
64 |
void fpcrtl_new__vars(void **p, int size); |
|
65 |
#define fpcrtl_new(a) fpcrtl_new__vars((void **)&(a), sizeof(*(a))) |
|
66 |
||
67 |
#define fpcrtl_dispose free |
|
68 |
||
69 |
#define fpcrtl_freeMem(p, size) free(p) |
|
70 |
#define fpcrtl_FreeMem(p, size) free(p) |
|
71 |
||
72 |
#define fpcrtl_getMem(size) malloc(size) |
|
73 |
#define fpcrtl_GetMem fpcrtl_getMem |
|
74 |
||
75 |
#define fpcrtl_assigned(p) ((p) != NULL) |
|
76 |
#define fpcrtl_Assigned fpcrtl_assigned |
|
77 |
||
78 |
Integer fpcrtl_trunc(extended n); |
|
79 |
||
80 |
#define fpcrtl_val(s, a, c) fpcrtl_val__vars(s, &(a), &(c)) |
|
81 |
void __attribute__((overloadable)) fpcrtl_val__vars(string255 s, LongInt *a, LongInt *c); |
|
82 |
void __attribute__((overloadable)) fpcrtl_val__vars(string255 s, Byte *a, LongInt *c); |
|
83 |
void __attribute__((overloadable)) fpcrtl_val__vars(string255 s, LongWord *a, LongInt *c); |
|
84 |
||
85 |
#define fpcrtl_randomize() srand(time(NULL)) |
|
86 |
||
87 |
/* |
|
88 |
* Random returns a random number larger or equal to 0 and strictly less than L |
|
89 |
*/ |
|
90 |
LongInt fpcrtl_random(LongInt l); |
|
91 |
||
92 |
string255 fpcrtl_paramStr(LongInt); |
|
93 |
#define fpcrtl_ParamStr fpcrtl_paramStr |
|
94 |
||
95 |
/* |
|
96 |
* Str returns a string which represents the value of X. X can be any numerical type. |
|
97 |
*/ |
|
98 |
#define fpcrtl_str(x, s) fpcrtl_str__vars(x, &(s)) |
|
99 |
void __attribute__((overloadable)) fpcrtl_str__vars(float x, string255 *s); |
|
100 |
void __attribute__((overloadable)) fpcrtl_str__vars(double x, string255 *s); |
|
101 |
void __attribute__((overloadable)) fpcrtl_str__vars(uint8_t x, string255 *s); |
|
102 |
void __attribute__((overloadable)) fpcrtl_str__vars(int8_t x, string255 *s); |
|
103 |
void __attribute__((overloadable)) fpcrtl_str__vars(uint16_t x, string255 *s); |
|
104 |
void __attribute__((overloadable)) fpcrtl_str__vars(int16_t x, string255 *s); |
|
105 |
void __attribute__((overloadable)) fpcrtl_str__vars(uint32_t x, string255 *s); |
|
106 |
void __attribute__((overloadable)) fpcrtl_str__vars(int32_t x, string255 *s); |
|
107 |
void __attribute__((overloadable)) fpcrtl_str__vars(uint64_t x, string255 *s); |
|
108 |
void __attribute__((overloadable)) fpcrtl_str__vars(int64_t x, string255 *s); |
|
109 |
||
110 |
void fpcrtl_interlockedIncrement__vars(int *i); |
|
111 |
void fpcrtl_interlockedDecrement__vars(int *i); |
|
112 |
||
113 |
#define fpcrtl_interlockedIncrement(i) fpcrtl_interlockedIncrement__vars(&(i)) |
|
114 |
#define fpcrtl_interlockedDecrement(i) fpcrtl_interlockedDecrement__vars(&(i)) |
|
115 |
||
116 |
#define fpcrtl_InterlockedIncrement fpcrtl_interlockedIncrement |
|
117 |
#define fpcrtl_InterlockedDecrement fpcrtl_interlockedDecrement |
|
118 |
||
119 |
void fpcrtl_init(int argc, char** argv); |
|
120 |
||
121 |
int fpcrtl_paramCount(); |
|
122 |
#define fpcrtl_ParamCount fpcrtl_paramCount |
|
123 |
||
124 |
string255 fpcrtl_paramStr(int i); |
|
125 |
#define fpcrtl_ParamStr fpcrtl_paramStr |
|
126 |
||
127 |
int fpcrtl_UTF8ToUnicode(PWideChar dest, PChar src, SizeInt maxLen); |
|
128 |
||
129 |
#define fpcrtl_halt(t) assert(0) |
|
130 |
||
131 |
#define fpcrtl_Load_GL_VERSION_2_0() 1 |
|
132 |
||
133 |
uint32_t __attribute__((overloadable)) fpcrtl_lo(uint64_t); |
|
134 |
#define fpcrtl_Lo fpcrtl_lo |
|
135 |
||
136 |
#define __SET_LENGTH2(arr, d, b) do{\ |
|
137 |
d.dim = 1;\ |
|
138 |
arr = realloc(arr, b * sizeof(typeof(*arr)));\ |
|
139 |
d.a[0] = b;\ |
|
140 |
}while(0) |
|
141 |
||
142 |
#define SET_LENGTH2(arr, b) __SET_LENGTH2(arr, arr##_dimension_info, (b)) |
|
143 |
||
144 |
#define __SET_LENGTH3(arr, d, b, c) do{\ |
|
145 |
d.dim = 2;\ |
|
146 |
for (int i = 0; i < d.a[0]; i++) {\ |
|
147 |
arr[i] = realloc(arr[i], c * sizeof(typeof(**arr)));\ |
|
148 |
}\ |
|
149 |
if (d.a[0] > b) {\ |
|
150 |
for (int i = b; i < d.a[0]; i++) {\ |
|
151 |
free(arr[i]);\ |
|
152 |
}\ |
|
153 |
arr = realloc(arr, b * sizeof(typeof(*arr)));\ |
|
154 |
} else if (d.a[0] < b) {\ |
|
155 |
arr = realloc(arr, b * sizeof(typeof(*arr)));\ |
|
156 |
for (int i = d.a[0]; i < b; i++) {\ |
|
157 |
arr[i] = malloc(c * sizeof(typeof(**arr)));\ |
|
158 |
memset(arr[i], 0, c * sizeof(typeof(**arr)));\ |
|
159 |
}\ |
|
160 |
}\ |
|
161 |
d.a[0] = b;\ |
|
162 |
d.a[1] = c;\ |
|
163 |
}while(0) |
|
164 |
||
165 |
#define SET_LENGTH3(arr, b, c) __SET_LENGTH3(arr, arr##_dimension_info, (b), (c)) |
|
166 |
||
167 |
#define fpcrtl_SetLength(...) macro_dispatcher(SET_LENGTH, __VA_ARGS__)(__VA_ARGS__) |
|
168 |
||
169 |
#endif /* SYSTEM_H_ */ |