summaryrefslogtreecommitdiff
path: root/ted-base.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-01-19 10:22:52 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-01-19 10:22:52 -0500
commit7ba80aaa38c95fdb84cd8fb51d51b5d897c5de95 (patch)
tree3bc8daa12db1b25301e775967f2b423386f11e9b /ted-base.c
parent8a4984e0e15fcfb0be6db242ab3f60325b80abd8 (diff)
opening files by clicking on them
Diffstat (limited to 'ted-base.c')
-rw-r--r--ted-base.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/ted-base.c b/ted-base.c
index e00a70a..2eac197 100644
--- a/ted-base.c
+++ b/ted-base.c
@@ -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);