commit 8e9d59f
uint
·
2026-05-04 10:30:35 +0000 UTC
parent cf58527
split main logic into init, run, add utils (die)
4 files changed,
+53,
-5
M
Makefile
+2,
-1
1@@ -3,7 +3,8 @@ CFLAGS = -std=c99 -Wall -Wextra
2 CPPFLAGS = -Isource/external -Isource/include
3 LDFLAGS = -framework Cocoa -framework CoreVideo -framework IOKit -framework CoreGraphics -framework CoreFoundation -framework Carbon
4
5-SRCS = source/cterm.c
6+SRCS = source/cterm.c \
7+ source/util.c
8 OUT = cterm
9
10 all:
+27,
-4
1@@ -5,18 +5,41 @@
2 #include <grapheme.h>
3 #include <schrift.h>
4
5-int main(int argc, char* argv[])
6+#include "util.h"
7+
8+RGFW_window* win = NULL;
9+
10+void init(void);
11+void run(void);
12+
13+/**
14+ * @brief initialise: window (TODO)
15+ */
16+void init(void)
17 {
18- RGFW_window* win = RGFW_createWindow("cterm", 0, 0, 800, 600, 0);
19- RGFW_event ev;
20+ if (!(win = RGFW_createWindow("cterm", 0, 0, 800, 600, 0)))
21+ die(1, "failed to create window");
22+}
23
24+/**
25+ * @brief program event loop (TODO)
26+ */
27+void run(void)
28+{
29+ RGFW_event ev;
30 while (!RGFW_window_shouldClose(win)) {
31 while (RGFW_window_checkEvent(win, &ev))
32 ;
33 }
34
35-
36 RGFW_window_close(win);
37+}
38+
39+int main(int argc, char* argv[])
40+{
41+ /* TODO: pledges */
42+ init();
43+ run();
44
45 return EXIT_SUCCESS;
46 (void) argc, (void) argv;
+13,
-0
1@@ -0,0 +1,13 @@
2+#ifndef UTIL_H
3+#define UTIL_H
4+
5+/**
6+ * @brief exit program after printing a message
7+ *
8+ * @param ec error code
9+ * @param msg message to print
10+ */
11+void die(int ec, const char* msg);
12+
13+#endif /* UTIL_H */
14+
+11,
-0
1@@ -0,0 +1,11 @@
2+#include <stdio.h>
3+#include <stdlib.h>
4+
5+#include "util.h"
6+
7+void die(int ec, const char* msg)
8+{
9+ perror(msg);
10+ exit(ec);
11+}
12+