commit 4c038d5

wf  ·  2026-03-25 20:13:55 +0000 UTC
parent f6933e0
Basic IPC parsing
4 files changed,  +24, -5
M README
M howl.c
+1, -1
1@@ -1,5 +1,5 @@
2 CC        ?= cc
3-CFLAGS    := -std=c99 -Wall -O3 -pedantic
4+CFLAGS    := -std=c99 -Wall -Wimplicit-function-declaration -O3 -pedantic
5 LDFLAGS   := `pkg-config --cflags --libs swc` -Iinclude/
6 LDLIBS    := `pkg-config --libs swc`
7 PREFIX    ?= /usr/local
M README
+0, -2
 1@@ -12,9 +12,7 @@ dependencies
 2 todo
 3 ----
 4 
 5- - parse IPC commands
 6  - configuration
 7- - IPC keybinding command
 8  - document IPC interface
 9 
10 [1]: https://git.sr.ht/~shrub900/neuswc
M howl.c
+22, -2
 1@@ -21,6 +21,7 @@ static void on_scr_destroy(void *);
 2 static bool is_ws_client(const struct client *, const struct screen *);
 3 
 4 struct wm wm;
 5+
 6 struct swc_manager mgr = {
 7 	.new_screen = &new_screen,
 8 	.new_window = &new_window
 9@@ -40,7 +41,7 @@ handler(int fd, uint32_t mask, void *data) {
10 	UNUSED(mask);
11 	UNUSED(data);
12 
13-	char buf[256];
14+	char buf[MAXSIZE];
15 	ssize_t res = read(fd, buf, sizeof(buf) - 1);
16 
17 	if (res < 0) {
18@@ -49,7 +50,26 @@ handler(int fd, uint32_t mask, void *data) {
19 	}
20 	buf[res] = '\0';
21 
22-	/* TODO: Parse response. */
23+	char *tok;
24+	int argc = 0;
25+	char **argv;
26+
27+	tok = strtok(buf, " ");
28+	argv[argc] = tok;
29+	argc++;
30+
31+	while (tok != NULL) {
32+		argv[argc] = tok;
33+		argc++;
34+		tok = strtok(NULL, " ");
35+	}
36+
37+	for (int i = 0; i < (sizeof commands / sizeof commands[0]); i++) {
38+		if (strcmp(commands[i].name, argv[0]) == 0) {
39+			argv++;
40+			commands[i].fn(argv);
41+		}
42+	}
43 
44 	return 0;
45 }
+1, -0
1@@ -3,6 +3,7 @@
2 
3 #define UNUSED(x) (void)x
4 #define SOCK_PATH "/tmp/.howl.sock"
5+#define MAXSIZE   256
6 
7 /* IPC socket */
8 static int sock;