From 37557a90bdca7980788bbce30ea888fbca0f9d32 Mon Sep 17 00:00:00 2001 From: Ashish Kumar Yadav Date: Sat, 5 Dec 2020 03:07:20 +0530 Subject: [PATCH] Improved delimiter handling --- blocks.h | 3 ++- dwmblocks.c | 14 ++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/blocks.h b/blocks.h index dc9ec26..2128836 100644 --- a/blocks.h +++ b/blocks.h @@ -30,4 +30,5 @@ static Block blocks[] = { { NULL } /* just to mark the end of the array */ }; -static const char *delim = " "; +/* default delimiter string */ +#define DELIMITER " " diff --git a/dwmblocks.c b/dwmblocks.c index 5b7fd20..98cf673 100644 --- a/dwmblocks.c +++ b/dwmblocks.c @@ -14,6 +14,8 @@ #define NILL INT_MIN #define LOCKFILE "/tmp/dwmblocks.pid" +#define LENGTH(X) (sizeof X / sizeof X[0]) + typedef struct { char *pathu; char *pathc; @@ -37,6 +39,7 @@ static int updatestatus(); static void writepid(); static char statustext[STTLENGTH]; +static char *delim; static size_t delimlength; static Display *dpy; static sigset_t blocksigmask; @@ -352,10 +355,13 @@ int main(int argc, char *argv[]) { writepid(); - if (argc > 2) - if (strcmp(argv[1], "-d") == 0) - delim = argv[2]; - delimlength = strlen(delim) + 1; + if (argc == 3 && strcmp(argv[1], "-d") == 0) { + delim = argv[2]; + delimlength = strlen(delim) + 1; + } else { + delim = DELIMITER; + delimlength = LENGTH(DELIMITER); + } if (!(dpy = XOpenDisplay(NULL))) { fputs("Error: could not open display.\n", stderr); return 1;