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