7983
|
1 |
#ifndef SYSTEM_H_
|
|
2 |
#define SYSTEM_H_
|
|
3 |
|
|
4 |
#include <time.h>
|
|
5 |
#include <math.h>
|
|
6 |
#include "types.h"
|
|
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);
|
|
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);
|
|
46 |
|
|
47 |
Integer fpcrtl_length(string255 s);
|
|
48 |
#define fpcrtl_Length fpcrtl_length
|
|
49 |
|
|
50 |
#define fpcrtl_sqr(x) ((x) * (x))
|
|
51 |
|
|
52 |
#define fpcrtl_odd(x) ((x) % 2 != 0 ? true : false)
|
|
53 |
|
|
54 |
#define fpcrtl_StrLen strlen
|
|
55 |
|
|
56 |
#define SizeOf sizeof
|
|
57 |
|
|
58 |
string255 fpcrtl_lowerCase(string255 s);
|
|
59 |
#define fpcrtl_LowerCase fpcrtl_lowerCase
|
|
60 |
|
|
61 |
void fpcrtl_fillChar__vars(void *x, SizeInt count, Byte value);
|
|
62 |
#define fpcrtl_fillChar(x, count, value) fpcrtl_fillChar__vars(&(x), count, value)
|
|
63 |
#define fpcrtl_FillChar fpcrtl_fillChar
|
|
64 |
|
|
65 |
void fpcrtl_new__vars(void **p, int size);
|
|
66 |
#define fpcrtl_new(a) fpcrtl_new__vars((void **)&(a), sizeof(*(a)))
|
|
67 |
|
|
68 |
#define fpcrtl_dispose free
|
|
69 |
|
|
70 |
#define fpcrtl_freeMem(p, size) free(p)
|
|
71 |
#define fpcrtl_FreeMem(p, size) free(p)
|
|
72 |
|
|
73 |
#define fpcrtl_getMem(size) malloc(size)
|
|
74 |
#define fpcrtl_GetMem fpcrtl_getMem
|
|
75 |
|
|
76 |
#define fpcrtl_assigned(p) ((p) != NULL)
|
|
77 |
#define fpcrtl_Assigned fpcrtl_assigned
|
|
78 |
|
|
79 |
Integer fpcrtl_trunc(extended n);
|
|
80 |
|
|
81 |
#define fpcrtl_val(s, a, c) fpcrtl_val__vars(s, &(a), &(c))
|
|
82 |
void __attribute__((overloadable)) fpcrtl_val__vars(string255 s, LongInt *a, LongInt *c);
|
|
83 |
void __attribute__((overloadable)) fpcrtl_val__vars(string255 s, Byte *a, LongInt *c);
|
|
84 |
void __attribute__((overloadable)) fpcrtl_val__vars(string255 s, LongWord *a, LongInt *c);
|
|
85 |
|
|
86 |
#define fpcrtl_randomize() srand(time(NULL))
|
|
87 |
|
|
88 |
/*
|
|
89 |
* Random returns a random number larger or equal to 0 and strictly less than L
|
|
90 |
*/
|
|
91 |
LongInt fpcrtl_random(LongInt l);
|
|
92 |
|
|
93 |
string255 fpcrtl_paramStr(LongInt);
|
|
94 |
#define fpcrtl_ParamStr fpcrtl_paramStr
|
|
95 |
|
|
96 |
/*
|
|
97 |
* Str returns a string which represents the value of X. X can be any numerical type.
|
|
98 |
*/
|
|
99 |
#define fpcrtl_str(x, s) fpcrtl_str__vars(x, &(s))
|
|
100 |
void __attribute__((overloadable)) fpcrtl_str__vars(float x, string255 *s);
|
|
101 |
void __attribute__((overloadable)) fpcrtl_str__vars(double x, string255 *s);
|
|
102 |
void __attribute__((overloadable)) fpcrtl_str__vars(uint8_t x, string255 *s);
|
|
103 |
void __attribute__((overloadable)) fpcrtl_str__vars(int8_t x, string255 *s);
|
|
104 |
void __attribute__((overloadable)) fpcrtl_str__vars(uint16_t x, string255 *s);
|
|
105 |
void __attribute__((overloadable)) fpcrtl_str__vars(int16_t x, string255 *s);
|
|
106 |
void __attribute__((overloadable)) fpcrtl_str__vars(uint32_t x, string255 *s);
|
|
107 |
void __attribute__((overloadable)) fpcrtl_str__vars(int32_t x, string255 *s);
|
|
108 |
void __attribute__((overloadable)) fpcrtl_str__vars(uint64_t x, string255 *s);
|
|
109 |
void __attribute__((overloadable)) fpcrtl_str__vars(int64_t x, string255 *s);
|
|
110 |
|
|
111 |
void fpcrtl_interlockedIncrement__vars(int *i);
|
|
112 |
void fpcrtl_interlockedDecrement__vars(int *i);
|
|
113 |
|
|
114 |
#define fpcrtl_interlockedIncrement(i) fpcrtl_interlockedIncrement__vars(&(i))
|
|
115 |
#define fpcrtl_interlockedDecrement(i) fpcrtl_interlockedDecrement__vars(&(i))
|
|
116 |
|
|
117 |
#define fpcrtl_InterlockedIncrement fpcrtl_interlockedIncrement
|
|
118 |
#define fpcrtl_InterlockedDecrement fpcrtl_interlockedDecrement
|
|
119 |
|
|
120 |
void fpcrtl_init(int argc, char** argv);
|
|
121 |
|
|
122 |
int fpcrtl_paramCount();
|
|
123 |
#define fpcrtl_ParamCount fpcrtl_paramCount
|
|
124 |
|
|
125 |
string255 fpcrtl_paramStr(int i);
|
|
126 |
#define fpcrtl_ParamStr fpcrtl_paramStr
|
|
127 |
|
|
128 |
int fpcrtl_UTF8ToUnicode(PWideChar dest, PChar src, SizeInt maxLen);
|
|
129 |
|
|
130 |
#define fpcrtl_halt(t) assert(0)
|
|
131 |
|
|
132 |
#define fpcrtl_Load_GL_VERSION_2_0() 1
|
|
133 |
|
|
134 |
uint32_t __attribute__((overloadable)) fpcrtl_lo(uint64_t);
|
|
135 |
#define fpcrtl_Lo fpcrtl_lo
|
|
136 |
|
|
137 |
#define __SET_LENGTH2(arr, d, b) do{\
|
|
138 |
d.dim = 1;\
|
|
139 |
arr = realloc(arr, b * sizeof(typeof(*arr)));\
|
|
140 |
d.a[0] = b;\
|
|
141 |
}while(0)
|
|
142 |
|
|
143 |
#define SET_LENGTH2(arr, b) __SET_LENGTH2(arr, arr##_dimension_info, (b))
|
|
144 |
|
|
145 |
#define __SET_LENGTH3(arr, d, b, c) do{\
|
|
146 |
d.dim = 2;\
|
|
147 |
for (int i = 0; i < d.a[0]; i++) {\
|
|
148 |
arr[i] = realloc(arr[i], c * sizeof(typeof(**arr)));\
|
|
149 |
}\
|
|
150 |
if (d.a[0] > b) {\
|
|
151 |
for (int i = b; i < d.a[0]; i++) {\
|
|
152 |
free(arr[i]);\
|
|
153 |
}\
|
|
154 |
arr = realloc(arr, b * sizeof(typeof(*arr)));\
|
|
155 |
} else if (d.a[0] < b) {\
|
|
156 |
arr = realloc(arr, b * sizeof(typeof(*arr)));\
|
|
157 |
for (int i = d.a[0]; i < b; i++) {\
|
|
158 |
arr[i] = malloc(c * sizeof(typeof(**arr)));\
|
|
159 |
memset(arr[i], 0, c * sizeof(typeof(**arr)));\
|
|
160 |
}\
|
|
161 |
}\
|
|
162 |
d.a[0] = b;\
|
|
163 |
d.a[1] = c;\
|
|
164 |
}while(0)
|
|
165 |
|
|
166 |
#define SET_LENGTH3(arr, b, c) __SET_LENGTH3(arr, arr##_dimension_info, (b), (c))
|
|
167 |
|
|
168 |
#define fpcrtl_SetLength(...) macro_dispatcher(SET_LENGTH, __VA_ARGS__)(__VA_ARGS__)
|
|
169 |
|
|
170 |
#endif /* SYSTEM_H_ */
|