diff options
| author | WormHeamer | 2025-12-31 01:35:56 -0500 |
|---|---|---|
| committer | WormHeamer | 2025-12-31 01:35:56 -0500 |
| commit | a06101376e750a7ba57857a6ed6917e9e5503d71 (patch) | |
| tree | 0166a4385bbbf9499285531fe4edb9f2e24cef4a | |
| parent | 9038e28aa6ca684128e3870c49ad68223c9da2f8 (diff) | |
get ready to start moving globals into Editor
| -rw-r--r-- | main.c | 63 |
1 files changed, 63 insertions, 0 deletions
@@ -22,12 +22,75 @@ #include "utf8.h" #include "str.h" +#define ED_BUF_MAX 1024 + +typedef enum { + ED_BUF_SCRATCH, + ED_BUF_FILE +} EditBufType; + +typedef struct { + EditBufType type; + Arena arena; + Str path; + Txt txt; + TxtLoc cur; +} EditBuf; + +typedef enum { + MODE_NORMAL, + MODE_INSERT +} EditMode; + +typedef struct { + Arena scratch; + EditBuf buf[ED_BUF_MAX]; + u32 bufn, bufi; + EditMode mode; + u32 count; +} Editor; + Arena scratch = { 0 }; Txt txt = { 0 }; TxtLoc cur = { 0 }; int mode = 0; u32 count = 0; +int ed_buf_new(Editor *e, const char *path) { + if (e->bufn == ED_BUF_MAX) return -1; + u32 i = e->bufn; + EditBuf b = { 0 }; + b.arena = arena_init(1L << 30); + if (path) { + b.path = str_dup(str_from_cstr(path), &b.arena); + b.type = ED_BUF_FILE; + txt_load(&b.txt, path); + } else { + b.path = S("*scratch*"); + b.type = ED_BUF_SCRATCH; + txt_load_empty(&b.txt); + } + b.cur = txt_end(&b.txt); + return i; +} + +void ed_buf_free(EditBuf *b) { + txt_free(&b->txt); + arena_free(&b->arena); +} + +void ed_init(Editor *e) { + memset(e, 0, sizeof(Editor)); + e->scratch = arena_init(1L << 30), + e->bufi = ed_buf_new(e, NULL); +} + +void ed_fini(Editor *e) { + for (u32 i = 0; i < e->bufn; i++) { + ed_buf_free(&e->buf[i]); + } +} + static inline int is_space(u32 c) { return c <= 0x20 && c != 0; } |
