summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Light <sam@lightscale.co.uk>2025-09-10 19:37:28 +0100
committerSam Light <sam@lightscale.co.uk>2025-09-10 19:37:28 +0100
commit49590ebb174f8436d0f85af8e4f24bcb6f346b1d (patch)
treeb078a006ed285bd3440c919c91abac5915ca20ce
parent970dcc487d7a6a6bc99e37b65ee512a2d651a583 (diff)
Created fifoinfo and sandbarinfoHEADmaster
-rw-r--r--.gitignore2
-rw-r--r--Makefile.am6
-rw-r--r--config.h.in6
-rw-r--r--src/fifoinfo.c94
-rw-r--r--src/sandbarinfo.c91
5 files changed, 195 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore
index d6d8760..3e477d8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,7 @@
somebarinfo
+sandbarinfo
dwminfo
+fifoinfo
*.o
diff --git a/Makefile.am b/Makefile.am
index f04c219..6669d47 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,4 +1,4 @@
-bin_PROGRAMS=somebarinfo dwminfo
+bin_PROGRAMS=somebarinfo sandbarinfo dwminfo fifoinfo
CFLAGS=$(LIBPULSE_CFLAGS)
LDADD=$(LIBPULSE_LIBS) -lm
@@ -14,5 +14,9 @@ COMMON_SOURCES=src/text.c \
somebarinfo_SOURCES=src/somebarinfo.c $(COMMON_SOURCES)
+sandbarinfo_SOURCES=src/sandbarinfo.c $(COMMON_SOURCES)
+
+fifoinfo_SOURCES=src/fifoinfo.c $(COMMON_SOURCES)
+
dwminfo_LDADD=$(LDADD) -lX11
dwminfo_SOURCES=src/dwminfo.c $(COMMON_SOURCES)
diff --git a/config.h.in b/config.h.in
index 8929c27..5096dd2 100644
--- a/config.h.in
+++ b/config.h.in
@@ -6,7 +6,7 @@
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
-/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
+/* Define to 1 if your system has a GNU libc compatible 'malloc' function, and
to 0 otherwise. */
#undef HAVE_MALLOC
@@ -55,7 +55,7 @@
/* Define to the version of this package. */
#undef PACKAGE_VERSION
-/* Define to 1 if all of the C90 standard headers exist (not just the ones
+/* Define to 1 if all of the C89 standard headers exist (not just the ones
required in a freestanding environment). This macro is provided for
backward compatibility; new code need not use it. */
#undef STDC_HEADERS
@@ -67,7 +67,7 @@
compiler does not already define this. */
#undef __STDC_NO_VLA__
-/* Define to empty if `const' does not conform to ANSI C. */
+/* Define to empty if 'const' does not conform to ANSI C. */
#undef const
/* Define to rpl_malloc if the replacement function should be used. */
diff --git a/src/fifoinfo.c b/src/fifoinfo.c
new file mode 100644
index 0000000..f4cc349
--- /dev/null
+++ b/src/fifoinfo.c
@@ -0,0 +1,94 @@
+#include "signal.h"
+#include "text.h"
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <assert.h>
+
+struct state {
+ int fd;
+ struct text * text;
+};
+
+static int
+open_fifo(const char * path)
+{
+ if (access(path, F_OK) != 0) {
+ printf("FIFO doesn't exist\n");
+ return -1;
+ }
+
+ if (access(path, W_OK) != 0) {
+ printf("FIFO not writable\n");
+ return -1;
+ }
+
+ return open(path, O_WRONLY);
+}
+
+
+static int
+init_state(struct state * s, const char * path)
+{
+ s->text = NULL;
+
+ s->fd = open_fifo(path);
+ if(s->fd < 1) return -1;
+
+ s->text = text_new();
+ return 0;
+}
+
+static void
+deinit_state(struct state * s)
+{
+ if(s->fd > 0) close(s->fd);
+ if(s->text) text_free(s->text);
+}
+
+static void
+update_status(struct state * s)
+{
+ const size_t
+ msg_len = TEXT_SIZE + 3;
+
+ size_t actual_len;
+
+ char msg[msg_len];
+
+ text_update(s->text);
+ snprintf(msg, msg_len, " %s\n", text_get_val(s->text));
+
+ actual_len = strlen(msg);
+ write(s->fd, msg, actual_len);
+}
+
+static void
+run_loop(struct state * s)
+{
+ while(signal_running) {
+ update_status(s);
+ usleep(1000 * 800);
+ }
+}
+
+int main(int argc, char ** argv)
+{
+ int rc;
+ struct state s;
+
+ assert(argc == 2);
+
+ signal_setup_actions();
+
+ rc = init_state(&s, argv[1]);
+
+ if(rc == 0) run_loop(&s);
+
+ deinit_state(&s);
+
+ return 0;
+}
diff --git a/src/sandbarinfo.c b/src/sandbarinfo.c
new file mode 100644
index 0000000..c2c5022
--- /dev/null
+++ b/src/sandbarinfo.c
@@ -0,0 +1,91 @@
+#include "signal.h"
+#include "text.h"
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <assert.h>
+
+struct state {
+ int fd;
+ struct text * text;
+};
+
+static int
+open_fifo(const char * path)
+{
+ if (access(path, F_OK) != 0) {
+ printf("FIFO doesn't exist\n");
+ return -1;
+ }
+
+ if (access(path, W_OK) != 0) {
+ printf("FIFO not writable\n");
+ return -1;
+ }
+
+ return open(path, O_WRONLY);
+}
+
+
+static int
+init_state(struct state * s, const char * path)
+{
+ s->text = NULL;
+
+ s->fd = open_fifo(path);
+ if(s->fd < 1) return -1;
+
+ s->text = text_new();
+ return 0;
+}
+
+static void
+deinit_state(struct state * s)
+{
+ if(s->fd > 0) close(s->fd);
+ if(s->text) text_free(s->text);
+}
+
+static void
+update_status(struct state * s)
+{
+ const size_t msg_len = TEXT_SIZE + 15;
+ size_t actual_len;
+ char msg[msg_len];
+
+ text_update(s->text);
+ snprintf(msg, msg_len, "all status %s\n", text_get_val(s->text));
+
+ actual_len = strlen(msg);
+ write(s->fd, msg, actual_len);
+}
+
+static void
+run_loop(struct state * s)
+{
+ while(signal_running) {
+ update_status(s);
+ usleep(1000 * 800);
+ }
+}
+
+int main(int argc, char ** argv)
+{
+ int rc;
+ struct state s;
+
+ assert(argc == 2);
+
+ signal_setup_actions();
+
+ rc = init_state(&s, argv[1]);
+
+ if(rc == 0) run_loop(&s);
+
+ deinit_state(&s);
+
+ return 0;
+}