-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.c
277 lines (214 loc) · 7.46 KB
/
demo.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
// jgabaut @ github.com/jgabaut
// SPDX-License-Identifier: GPL-3.0-only
#include <stdio.h>
#include <locale.h>
#include "../src/koliseo.h"
#include "./kls_banner.h"
#include "amboso.h"
void usage(char *progname)
{
fprintf(stderr, "Usage: %s [-a]\n\n", progname);
fprintf(stderr, " [-a] Makes the demo not interactive.\n");
}
int main(int argc, char **argv)
{
int is_interactive = 1;
if (argc > 2) {
fprintf(stderr, "Too many arguments.\n");
usage(argv[0]);
exit(EXIT_FAILURE);
} else if (argc == 2) {
if ((strcmp(argv[1], "-a")) == 0) {
is_interactive = 0;
} else {
fprintf(stderr, "Invalid argument: [%s].\n", argv[1]);
usage(argv[0]);
exit(EXIT_FAILURE);
}
}
kls_print_title();
printf("\n\nDemo for Koliseo, using API lvl [%i], version %s \n",
int_koliseo_version(), string_koliseo_version());
printf("Supporting Amboso API version %s\n\n", getAmbosoVersion());
#ifndef KOLISEO_HAS_REGION
int KLS_REGLIST_ALLOC_KLS_BASIC = -1;
#endif
int block_usage_with_open_temp = 0;
KLS_Conf kls_config = kls_conf_init(1, KLS_REGLIST_ALLOC_KLS_BASIC, KLS_DEFAULT_SIZE, 1, 1, 1, block_usage_with_open_temp, NULL, "./static/debug_log.txt");
printf("[Init Koliseo] [size: %i]\n", KLS_DEFAULT_SIZE);
Koliseo *kls = kls_new_conf(KLS_DEFAULT_SIZE, kls_config);
#ifdef KOLISEO_HAS_EXPER
char* demo_str = KLS_STRDUP(kls, "\nKoliseo demo\n");
printf("%s\n", demo_str);
#endif // KOLISEO_HAS_EXPER
#ifdef KOLISEO_HAS_REGION
#ifndef _WIN32
printf("kls size: (%li) kls_region size: (%li)\n", kls->size,
sizeof(KLS_Region));
printf
("Max KLS_Region on this size, when reglist alloc backend is KLS_BASIC: %i\n",
kls_get_maxRegions_KLS_BASIC(kls));
#else
printf("kls size: (%lli) kls_region size: (%lli)\n", kls->size,
sizeof(KLS_Region));
printf
("Max KLS_Region on this size, when reglist alloc backend is KLS_BASIC: %i\n",
kls_get_maxRegions_KLS_BASIC(kls));
#endif
#endif // KOLISEO_HAS_REGION
int* pex = KLS_PUSH_EX(kls, int, "foo");
*pex = 3;
printf("*pex is {%i}\n", *pex);
char* pt_ex = KLS_PUSH_TYPED_EX(kls, char, 42, "foo_2");
*pt_ex = 'w';
printf("*pt_ex is {%c}\n", *pt_ex);
char* pt_nm = KLS_PUSH_ARR_NAMED(kls, char, 10, "char array", "Named array");
pt_nm[0] = 'W';
printf("pt_nm[0] is {%c}\n", pt_nm[0]);
char* pt_tp = KLS_PUSH_ARR_TYPED(kls, char, 10, 42, "char array, typed \"42\"", "Typed chararray");
pt_tp[0] = 'W';
pt_tp[1] = 'W';
pt_tp[2] = '\0';
printf("pt_tp is {%s}\n", pt_tp);
printf(KLS_Conf_Fmt "\n", KLS_Conf_Arg(kls->conf));
#ifndef _WIN32
printf("[Current position in Koliseo] [pos: %li]\n", kls_get_pos(kls));
#else
printf("[Current position in Koliseo] [pos: %lli]\n", kls_get_pos(kls));
#endif
print_dbg_kls(kls);
#ifdef KOLISEO_HAS_REGION
#ifndef _WIN32
printf("[Show Region list for Koliseo] [pos: %li]\n", kls_get_pos(kls));
#else
printf("[Show Region list for Koliseo] [pos: %lli]\n", kls_get_pos(kls));
#endif
KLS_RL_ECHOLIST(kls->regs);
#endif // KOLISEO_HAS_REGION
Koliseo_Temp *temp_kls = kls_temp_start(kls);
//temp_kls->conf.kls_autoset_regions = 1; TODO why does this crash?
#ifndef _WIN32
printf("[Started Koliseo_Temp] [pos: %li]\n", kls_get_pos(temp_kls->kls));
#else
printf("[Started Koliseo_Temp] [pos: %lli]\n", kls_get_pos(temp_kls->kls));
#endif
#ifdef KOLISEO_HAS_REGION
// TODO: still declare KLS_Temp_Conf
printf(KLS_Temp_Conf_Fmt "\n", KLS_Temp_Conf_Arg(temp_kls->conf));
#endif
int minusone = -1;
int *p = &minusone;
int *p2 = &minusone;
int *p3 = &minusone;
printf("\n*p is [%i] before KLS_PUSH\n", *p);
printf("\n*p2 is [%i] before KLS_PUSH_T\n", *p2);
printf("\n*p3 is [%i] before KLS_PUSH_T\n", *p3);
#ifndef _WIN32
printf("[KLS_PUSH for a int to Koliseo] [size: %li]\n", sizeof(int));
#else
printf("[KLS_PUSH for a int to Koliseo] [size: %lli]\n", sizeof(int));
#endif
printf
("[This handles the Koliseo directly while we have an open Koliseo_Temp.]\n");
p = (int *)KLS_PUSH(kls, int);
#ifdef KOLISEO_HAS_REGION
#ifndef _WIN32
printf("[KLS_PUSH_T_NAMED for a int to Koliseo_Temp] [size: %li]\n",
sizeof(int));
#else
printf("[KLS_PUSH_T_NAMED for a int to Koliseo_Temp] [size: %lli]\n",
sizeof(int));
#endif
p2 = (int *)KLS_PUSH_T_NAMED(temp_kls, int, "int", "Another int");
#endif // KOLISEO_HAS_REGION
#ifndef _WIN32
printf("[KLS_PUSH_T for a int to Koliseo_Temp] [size: %li]\n", sizeof(int));
#else
printf("[KLS_PUSH_T for a int to Koliseo_Temp] [size: %lli]\n",
sizeof(int));
#endif
p3 = (int *)KLS_PUSH_T(temp_kls, int);
#ifndef _WIN32
printf("[Current position in Koliseo] [pos: %li]\n", kls_get_pos(kls));
#else
printf("[Current position in Koliseo] [pos: %lli]\n", kls_get_pos(kls));
#endif
#ifndef _WIN32
printf("[Current position in Koliseo_Temp] [pos: %li]\n", temp_kls->offset);
#else
printf("[Current position in Koliseo_Temp] [pos: %lli]\n",
temp_kls->offset);
#endif
print_dbg_kls(kls);
*p = 1;
printf("\n*p is [%i] after KLS_PUSH\n", *p);
*p2 = 2;
printf("\n*p2 is [%i] after KLS_PUSH\n", *p2);
*p2 = 3;
printf("\n*p3 is [%i] after KLS_PUSH\n", *p3);
#ifdef KOLISEO_HAS_REGION
#ifndef _WIN32
printf("[Show Region list for Koliseo] [pos: %li]\n", kls_get_pos(kls));
#else
printf("[Show Region list for Koliseo] [pos: %lli]\n", kls_get_pos(kls));
#endif
KLS_RL_ECHOLIST(kls->regs);
printf("[%i] List size\n", kls_rl_length(kls->regs));
KLS_RL_ECHOLIST(temp_kls->t_regs);
printf("[%i] Temp List size\n", kls_rl_length(temp_kls->t_regs));
printf("[Usage report for Koliseo]\n");
kls_usageReport(kls);
#endif // KOLISEO_HAS_REGION
#ifdef KOLISEO_HAS_EXPER
int *z = &minusone;
printf("\n*z is [%i] before KLS_POP\n", *z);
#ifndef _WIN32
printf("[KLS_POP a int from Koliseo] [size: %li]\n", sizeof(int));
#else
printf("[KLS_POP a int from Koliseo] [size: %lli]\n", sizeof(int));
#endif
z = KLS_POP(kls, int);
printf("\n*z is [%i] after KLS_POP\n", *z);
#endif // KOLISEO_HAS_EXPER
#ifndef _WIN32
printf("[Current position in Koliseo] [pos: %li]\n", kls_get_pos(kls));
#else
printf("[Current position in Koliseo] [pos: %lli]\n", kls_get_pos(kls));
#endif
print_dbg_kls(kls);
print_dbg_temp_kls(temp_kls);
//We may forget to end the Koliseo_Temp...
//kls_temp_end(temp_kls);
//printf("[Ended Koliseo_Temp]\n");
print_dbg_kls(kls);
printf(KLSFmt "\n", KLS_Arg(kls));
printf(KLS_Stats_Fmt "\n", KLS_Stats_Arg(kls->stats));
printf("[Koliseo Info]\n");
print_dbg_kls(kls);
#ifdef KOLISEO_HAS_REGION
print_dbg_kls(kls->reglist_kls);
KLS_RL_ECHOLIST(kls->regs);
printf("[Koliseo_Temp Info]\n");
KLS_RL_ECHOLIST(temp_kls->t_regs);
print_dbg_kls(temp_kls->reglist_kls);
printf("[%i] List size for Koliseo\n", kls_rl_length(kls->regs));
printf("[%i] List size for Koliseo_Temp\n", kls_rl_length(temp_kls->t_regs));
#endif // KOLISEO_HAS_REGION
printf("[Clear Koliseo]\n");
kls_clear(kls);
print_dbg_kls(kls);
//This should also clean up an eventual Koliseo_Temp
printf("[Free Koliseo]\n");
kls_free(kls);
printf("[End of demo]\n");
printf("[End of demo for Koliseo, API lvl [%i] v%s ]\n",
int_koliseo_version(), string_koliseo_version());
printf("Press Enter to quit.\n");
int sc_res = -1;
if (is_interactive == 1) {
sc_res = scanf("%*c");
} else {
sc_res = 0;
}
return sc_res;
}