diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2021-01-19 10:22:52 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2021-01-19 10:22:52 -0500 |
commit | 7ba80aaa38c95fdb84cd8fb51d51b5d897c5de95 (patch) | |
tree | 3bc8daa12db1b25301e775967f2b423386f11e9b /ted-base.c | |
parent | 8a4984e0e15fcfb0be6db242ab3f60325b80abd8 (diff) |
opening files by clicking on them
Diffstat (limited to 'ted-base.c')
-rw-r--r-- | ted-base.c | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -2,6 +2,12 @@ #define ted_seterr(buffer, ...) \ snprintf(ted->error, sizeof ted->error - 1, __VA_ARGS__) +void ted_seterr_to_buferr(Ted *ted, TextBuffer *buffer) { + size_t size = sizeof ted->error; + if (sizeof buffer->error < size) size = sizeof buffer->error; + memcpy(ted->error, buffer->error, size); +} + bool ted_haserr(Ted *ted) { return ted->error[0] != '\0'; } @@ -80,5 +86,19 @@ static void ted_load_font(Ted *ted) { } } +// returns buffer of new file +static TextBuffer *ted_open_file(Ted *ted, char const *filename) { + TextBuffer *open_to = &ted->main_buffer; + buffer_load_file(open_to, filename); + if (buffer_haserr(open_to)) { + // @TODO: something + ted_seterr_to_buferr(ted, open_to); + return NULL; + } else { + ted->active_buffer = open_to; + return open_to; + } +} + static void menu_open(Ted *ted, Menu menu); static void menu_close(Ted *ted, bool restore_prev_active_buffer); |