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
|
// {{{
// about {{{
// work in progress (not writed)
// compile: zig cc se_windows.c
// }}}
// imports {{{
#include "float.h"
#include "iso646.h"
#include "limits.h"
#include "stdarg.h"
#include "stdbool.h"
#include "stddef.h"
#include "stdint.h"
#include "stdio.h"
#include "stdlib.h"
// }}}
// c specific code {{{
#define NOT_FUNCTION
// }}}
// Iterator {{{
struct Iterator {
int pos;
int step;
int start;
int end;
uint8_t stopped;
uint8_t runned;
};
void Iterator_init(struct Iterator* this, int start, int end, int step) {
this->stopped = 0;
this->runned = 0;
this->start = start;
this->end = end;
this->step = step;
}
void Iterator_next(struct Iterator* this) {
if (this->stopped ) return;
if (this->runned == 0) {
this->runned = 1;
return;
}
if (this->end - this->start < this->step) {
this->stopped = true;
this->pos = this->end;
return;
}
this->pos += this->step;
}
// }}}
// modules {{{
// struct Os {{{
struct Os_Console_Output {
void* handle;
void* file;
void* writer;
};
// }}}
// struct Scalpi {{{
struct Scalpi_Console {
void* input;
void* output;
};
// }}}
// struct App {{{
|
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
|
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
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
|
// {{{
// about {{{
// licenze: {{{
// This code and its derivatives can be used under the following conditions:
// - Do not attack other countries.
// - Jerk off on public at least 1 time per day.
// - Observe hygiene.
// - check my other projects https://chiselapp.com/user/sergey6661313
// }}}
// about: {{{
// ScalpiEditor - ansi-only text editor for terminals.
// killer features: no. its just editor.
// }}}
// WORK IN PROGRESS (not writed yet!)
// for real expirience of scalpi editor - use zig version
// Compile: {{{
// zig cc se_windows.c
// }}}
// to support me {{{
// with boosty:
// https://boosty.to/cutloosedev
// with monero:
// 87T7 qGbA TrM3 a6Br
// DyeC jQQf NWtU u3iZ
// bHVB MC6W mEbN NE13
// Qrrt KhBb e4vF 58NR
// 8PTF dYk2 Sozc HexX
// 4Q69 jbdQ Asrs P7B
// }}}
// tested in terminals: {{{
// :( Alacritty-v0.13.2-portable. (some time brackets not are not written)
// :( WezTerm-windows-20240520-135708-b8f94c47. (some time brackets not are not written)
// :) contour-0.4.3.6442-win64
// :( extratermqt-0.77.0-windows-x64. not runned in my system.
// :) hyper_4.0.0-canary.5
// :) tabby-1.0.207-portable-x64. best work.
// }}}
// }}}
// imports {{{
// libC
#include "assert.h"
#include "ctype.h"
#include "errno.h"
#include "fenv.h"
#include "float.h"
#include "inttypes.h"
#include "iso646.h"
#include "limits.h"
#include "locale.h"
#include "math.h"
#include "setjmp.h"
#include "signal.h"
#include "stdarg.h"
#include "stdbool.h"
#include "stddef.h"
#include "stdint.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "tgmath.h"
#include "time.h"
#include "uchar.h"
#include "wchar.h"
#include "wctype.h"
// Windows
#include "windows.h"
#include "windef.h"
#include "winuser.h"
#include "commctrl.h"
#include "io.h"
#include "conio.h"
// network
//#include "ws2tcpip.h"
//#include "winsock.h"
// }}}
// c specific code {{{
#define NOT_FUNCTION
#define length(array) ((sizeof(array)) / (sizeof(array[0])))
#define sliceArgFromConst(text) text, length(text)
// Iterator {{{
struct Iterator {
int pos;
int step;
int start;
int end;
uint8_t stopped;
uint8_t runned;
};
void Iterator_init(struct Iterator* this, int start, int end, int step) {
this->stopped = 0;
this->runned = 0;
this->start = start;
this->end = end;
this->step = step;
}
void Iterator_next(struct Iterator* this) {
if (this->stopped ) return;
if (this->runned == 0) {
this->runned = 1;
return;
}
if (this->end - this->start < this->step) {
this->stopped = true;
this->pos = this->end;
return;
}
this->pos += this->step;
}
// }}}
// }}}
// modules {{{
// struct Os {{{
// struct Os_Console_Output {{{
struct Os_Console_Output {
void* handle;
void* file;
void* writer;
};
uint64_t os_print(uint8_t* bytes, uint64_t bytes_len){
uint8_t* byte_ptr = bytes;
while (bytes_len > 0) {
putchar(*byte_ptr);
bytes_len -= 1;
byte_ptr += 1;
}
}
// void Os_Console_Output_init(&app.console.output, c.GetStdHandle(c.STD_OUTPUT_HANDLE));
// }}}
// }}}
// struct Scalpi {{{
// Scalpi_logger {{{
struct Writer {
context: *WriterVTable;
};
struct WriterVTable {
uint64_t (*write) (void* context, uint8_t* bytes, uint64_t bytes_len, uint64_t* writed_result);
}
struct Scalpi_logger {
// write to terminal, console, file or to all together, but no real check "bytes is writen"
uint64_t writed;
Scalpi_Writer writer;
bool file_work;
uintptr_t file;
bool file_writer_work;
Writer file_writer;
bool console_writer_work;
Writer console_writer;
bool terminal_writer_work;
Writer terminal_writer;
};
uint64_t Scalpi_logger_write(struct Scalpi_logger* t, uint8_t* bytes, uint64_t bytes_len, uint64_t* writed_result) {
uint64_t r = 0;
*writed_result = 0;
bool writed = false;
if (file_writer_work) {
r = writeToWriter(&t.file_writer, bytes, bytes_len);
writed = true;
}
if (console_writer_work) {
r = writeToWriter(&t.console_writer, bytes, bytes_len);
writed = true;
}
if (terminal_writer_work) {
r = writeToWriter(&t.terminal_writer, bytes, bytes_len);
writed = true;
}
if (writed == false) {
os_print(bytes, bytes_len);
}
t->writed += bytes_len;
*writed_result = bytes_len;
return 0;
}
uint64_t Scalpi_logger_writeAll(struct Scalpi_logger* t, uint8_t* bytes, uint64_t bytes_len){
uint64_t writed = 0;
return Scalpi_logger_write(t, bytes, bytes_len, &writed);
}
struct WriterVTable Scalpi_logger_writer_vtable = {
.write =
(uint64_t (*) (void*, uint8_t*, uint64_t, uint64_t*))
&Scalpi_logger_write
};
void Scalpi_logger_init (struct Scalpi_logger* t) {
t.writed = 0;
// init writer
t->writer.vtable = &Scalpi_logger_writer_vtable;
t->writer.context = t;
t->file_work = false;
t->file_writer_work = false;
t->console_writer_work = false;
t->terminal_writer_work = false;
}
// }}}
struct Scalpi_Console {
void* input;
void* output;
};
// }}}
// struct App {{{
|
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
App_init_result_argsNotParsed,
};
uint64_t App_init(struct App* app) {
uint64_t r = 0;
// preinit console output for debug
//Os_Console_Output_init(&app.console.output, c.GetStdHandle(c.STD_OUTPUT_HANDLE));
//Scalpi_DebugHelper_on_exit(&process->debug_helper, __LINE__);
// pre init console output for debug
// try app.console.output.init(c.GetStdHandle(c.STD_OUTPUT_HANDLE));
|
>
>
>
|
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
App_init_result_argsNotParsed,
};
uint64_t App_init(struct App* app) {
uint64_t r = 0;
// preinit console output for debug
Scalpi_logger_init(&app.logger);
Scalpi_logger_writeAll(&app->logger, sliceArgFromConst("writed_by_logger\r\n"));
Scalpi_logger_writeAll(&app->logger, "writed_by_logger\r\n", 17);
//Os_Console_Output_init(&app.console.output, c.GetStdHandle(c.STD_OUTPUT_HANDLE));
//Scalpi_DebugHelper_on_exit(&process->debug_helper, __LINE__);
// pre init console output for debug
// try app.console.output.init(c.GetStdHandle(c.STD_OUTPUT_HANDLE));
|
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
r = App_init(&app);
if (r != 0) {
r = (r << 4) | main_result_AppNotInit;
printf("%d: result %llu \r\n", __LINE__, r);
return r;
}
//App_loop(&app);
//App_deinit(&app);
printf("App deinited\r\n");
return main_result_ok;
}
// }}}
// }}}
|
|
|
|
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
|
r = App_init(&app);
if (r != 0) {
r = (r << 4) | main_result_AppNotInit;
printf("%d: result %llu \r\n", __LINE__, r);
return r;
}
App_loop(&app);
App_deinit(&app);
printf("App deinited\r\n");
return main_result_ok;
}
// }}}
// }}}
|