summaryrefslogtreecommitdiff
path: root/ted-base.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-12-30 11:55:58 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2020-12-30 11:55:58 -0500
commitf10f07553e599f1320afbaa2dfeb0b267139cd74 (patch)
tree760536d599c667f703013feffac1574893aa5a7c /ted-base.c
parent642b09558e586d47f172fcfd18c296d400317708 (diff)
more config
Diffstat (limited to 'ted-base.c')
-rw-r--r--ted-base.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/ted-base.c b/ted-base.c
new file mode 100644
index 0000000..5ed6469
--- /dev/null
+++ b/ted-base.c
@@ -0,0 +1,49 @@
+typedef struct {
+ Command cmd;
+ i64 argument;
+} KeyAction;
+
+#define SCANCODE_COUNT 0x120 // SDL scancodes should be less than this value.
+// a "key combo" is some subset of {control, shift, alt} + some key.
+#define KEY_COMBO_COUNT (SCANCODE_COUNT << 3)
+
+typedef struct {
+ TextBuffer *active_buffer;
+ KeyAction key_actions[KEY_COMBO_COUNT];
+ char error[256];
+} Ted;
+
+// this is a macro so we get -Wformat warnings
+#define ted_seterr(buffer, ...) \
+ snprintf(ted->error, sizeof ted->error - 1, __VA_ARGS__)
+
+bool ted_haserr(Ted *ted) {
+ return ted->error[0] != '\0';
+}
+
+char const *ted_geterr(Ted *ted) {
+ return ted->error;
+}
+
+static void ted_out_of_mem(Ted *ted) {
+ ted_seterr(ted, "Out of memory.");
+}
+
+static void *ted_malloc(Ted *ted, size_t size) {
+ void *ret = malloc(size);
+ if (!ret) ted_out_of_mem(ted);
+ return ret;
+}
+
+static void *ted_calloc(Ted *ted, size_t n, size_t size) {
+ void *ret = calloc(n, size);
+ if (!ret) ted_out_of_mem(ted);
+ return ret;
+}
+
+static void *ted_realloc(Ted *ted, void *p, size_t new_size) {
+ void *ret = realloc(p, new_size);
+ if (!ret) ted_out_of_mem(ted);
+ return ret;
+}
+