s2dblocks

statusbar blocks for dwm
Log | Files | Refs

commit b3d37a31b88f1bf1bb297c5994961efff0ba7937
parent 716610af5291e311a921a3e683914d4332b894a0
Author: hhvn <dev@hhvn.uk>
Date:   Thu, 14 Apr 2022 14:49:16 +0100

Prevent corrupt status2d codes being printed

Diffstat:
Mstatus2d.c | 14++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/status2d.c b/status2d.c @@ -3,6 +3,7 @@ #include <string.h> #include <stdarg.h> #include <stdlib.h> +#include <unistd.h> #include "dwmbar.h" static int needforwarding = 0; @@ -10,11 +11,12 @@ static int initialized = 0; static char *curfg = NULL; static char *curbg = NULL; -#define s2d_init() (initialized ? s2d_init_() : ((void)0)) +#define s2d_init() (!initialized ? s2d_init_() : ((void)0)) static void s2d_init_(void) { s2d_reset(1, 1); + initialized = 1; } void @@ -174,12 +176,20 @@ s2d_forward(int px) { void s2d_print(char *fmt, ...) { + char buf[BUFSIZ], *p; va_list ap; s2d_init(); s2d_forward(-1); va_start(ap, fmt); - vprintf(fmt, ap); + vsnprintf(buf, sizeof(buf), fmt, ap); va_end(ap); + + for (p = buf; *p; p++) + if (*p == '^') + *p = '.'; + + fwrite(buf, sizeof(char), strlen(buf), stdout); + fflush(stdout); }