// work in progress
// compile: zig cc se_windows.c
// basic c headers {{{
#include "float.h"
#include "iso646.h"
#include "limits.h"
#include "stdarg.h"
#include "stdbool.h"
#include "stddef.h"
#include "stdint.h"
// }}}
#include "stdio.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;
}
// }}}
// struct DebugHelper {{{
#define DebugHelper_max 250
#define DebugHelperTraces_last NOT_FUNCTION (DebugHelper_max - 1)
// DebugHelperTraces {{{
struct DebugHelperTraces {
int lines[DebugHelper_max];
int count;
};
void DebugHelperTraces_init(struct DebugHelperTraces* dh) {
dh->count = 0;
}
void DebugHelperTraces_add(struct DebugHelperTraces* dh, int line) {
if (dh->count == DebugHelperTraces_last) {
int a = 0;
int b = a / a;
return;
}
dh->lines[dh->count] = line;
dh->count += 1;
}
void DebugHelperTraces_print(struct DebugHelperTraces* t) {
// for(int count = t->count; count != 0; count -= 1)
struct Iterator iter;
Iterator_init(&iter, 0, t->count - 1, 1);
while(true) {
Iterator_next(&iter);
if (iter.stopped) break;
printf("line: %d\r\n", t->lines[iter.pos]);
}
}
// }}}
struct DebugHelper {
struct DebugHelperTraces stack;
struct DebugHelperTraces error;
};
void DebugHelper_init(struct DebugHelper* t) {
DebugHelperTraces_init(&t->stack);
DebugHelperTraces_init(&t->error);
}
void DebugHelper_print(struct DebugHelper* t) {
if(t->stack.count > 0) {
printf("- - stack trace: - -\r\n");
DebugHelperTraces_print(&t->stack);
}
if(t->error.count > 0) {
printf("- - error trace: - -\r\n");
DebugHelperTraces_print(&t->error);
}
}
void DebugHelper_on_enter(struct DebugHelper* t, int line) {
DebugHelperTraces_add(&t->stack, line);
}
void DebugHelper_on_exit(struct DebugHelper* t) {
t->stack.count -= 1;
}
// }}}
// modules {{{
// struct Os {{{
struct Os_Console_Output {
void* handle;
void* file;
void* writer;
};
// }}}
// struct Scalpi {{{
struct Scalpi_Console {
void* input;
void* output;
};
// }}}
// struct App {{{
struct App {
struct DebugHelper dh;
struct Scalpi_Console console;
};
void App_init(struct App* app) {
DebugHelper_init(&app->dh);
//DebugHelper_on_enter(&app->dh, __LINE__);
//example(dh);
//DebugHelper_on_exit(&app->dh);
// pre init console output for debug
// try app.console.output.init(c.GetStdHandle(c.STD_OUTPUT_HANDLE));
// t.logger.console_writer = &t.console.output.writer;
// mem
// try t.mem.init();
// errdefer t.mem.deinit();
// const allocator = &t.mem.allocator;
// fuck(allocator);
// Os init
// try t.winapi.init();
// errdefer t.winapi.deinit();
// console
// try t.console.init(t.winapi.console_input_handle, t.winapi.console_output_handle);
// try log.writeAll(" - - - OwO - - -\r");
// terminal
// t.terminal.init(&t.console) catch return error.TerminalNotInit;
// errdefer t.terminal.deinit();
//t.terminal.output.convert_t = true;
//t.terminal.output.convert_n_to_rn = true;
//t.terminal.output.apply_r = true;
//t.terminal.output.apply_n = true;
// editor
// try t.editor.init(allocator);
// errdefer t.editor.deinit();
// parse_args
// try t.parseArgs();
// t.editor.views.flat.setAsView() catch return error.AnViewFlatSetAsView;
// try t.editor.views.flat.fold();
// try t.editor.views.folded.markThisLine();
//
// t.logger.terminal_writer = &t.terminal.output.writer;
// t.logger.console_writer = null;
// t.working = true;
return ok;
}
void App_deinit(struct App* app) {
DebugHelper_print(&app->dh);
}
void App_loop(struct App* app) {
DebugHelper_print(&app->dh);
}
// }}}
// }}}
// main {{{
int main() {
struct App app_on_stack;
struct App* app = &app_on_stack;
int try = App_init(app);
if (try != EXIT_SUCCESS) return init_status;
printf("App inited\r\n");
App_loop(app);
App_deinit(app);
printf("App deinited\r\n");
printf("OwO");
return EXIT_SUCCESS;
}
// }}}