Improved delimiter handling

This commit is contained in:
Ashish Kumar Yadav 2020-12-05 03:07:20 +05:30
parent c8fc778841
commit 37557a90bd
2 changed files with 12 additions and 5 deletions

View file

@ -30,4 +30,5 @@ static Block blocks[] = {
{ NULL } /* just to mark the end of the array */ { NULL } /* just to mark the end of the array */
}; };
static const char *delim = " "; /* default delimiter string */
#define DELIMITER " "

View file

@ -14,6 +14,8 @@
#define NILL INT_MIN #define NILL INT_MIN
#define LOCKFILE "/tmp/dwmblocks.pid" #define LOCKFILE "/tmp/dwmblocks.pid"
#define LENGTH(X) (sizeof X / sizeof X[0])
typedef struct { typedef struct {
char *pathu; char *pathu;
char *pathc; char *pathc;
@ -37,6 +39,7 @@ static int updatestatus();
static void writepid(); static void writepid();
static char statustext[STTLENGTH]; static char statustext[STTLENGTH];
static char *delim;
static size_t delimlength; static size_t delimlength;
static Display *dpy; static Display *dpy;
static sigset_t blocksigmask; static sigset_t blocksigmask;
@ -352,10 +355,13 @@ int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
writepid(); writepid();
if (argc > 2) if (argc == 3 && strcmp(argv[1], "-d") == 0) {
if (strcmp(argv[1], "-d") == 0)
delim = argv[2]; delim = argv[2];
delimlength = strlen(delim) + 1; delimlength = strlen(delim) + 1;
} else {
delim = DELIMITER;
delimlength = LENGTH(DELIMITER);
}
if (!(dpy = XOpenDisplay(NULL))) { if (!(dpy = XOpenDisplay(NULL))) {
fputs("Error: could not open display.\n", stderr); fputs("Error: could not open display.\n", stderr);
return 1; return 1;