diff options
Diffstat (limited to 'dwmblocks.c')
-rw-r--r-- | dwmblocks.c | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/dwmblocks.c b/dwmblocks.c index 0186eff..773e36f 100644 --- a/dwmblocks.c +++ b/dwmblocks.c @@ -20,7 +20,7 @@ void buttonhandler(int sig, siginfo_t *si, void *ucontext); void replace(char *str, char old, char new); void remove_all(char *str, char to_remove); void getcmds(int time); -#ifndef __OpenBSD__ +#ifndef BSD void getsigcmds(int signal); void setupsignals(); void sighandler(int signum); @@ -78,11 +78,11 @@ int gcd(int a, int b) //opens process *cmd and stores output in *output void getcmd(const Block *block, char *output) { - if (block->signal) - { - output[0] = block->signal; - output++; - } + /* if (block->signal) */ + /* { */ + /* output[0] = block->signal; */ + /* output++; */ + /* } */ char *cmd = block->command; FILE *cmdf = popen(cmd,"r"); if (!cmdf){ @@ -100,19 +100,25 @@ void getcmd(const Block *block, char *output) int e; do { errno = 0; - s = fgets(tmpstr, CMDLENGTH-(strlen(delim)+1), cmdf); + s = fgets(tmpstr, CMDLENGTH-(strlen(postdelim)+1), cmdf); e = errno; } while (!s && e == EINTR); pclose(cmdf); - int i = strlen(block->icon); - strcpy(output, block->icon); - strcpy(output+i, tmpstr); + if (s == NULL) { + output[0] = '\0'; + return; + } + int i = strlen(predelim); + strlcpy(output, predelim, CMDLENGTH); + strlcpy(output + i, block->icon, CMDLENGTH); + i += strlen(block->icon); + strlcpy(output + i, tmpstr, CMDLENGTH); remove_all(output, '\n'); i = strlen(output); - if ((i > 0 && block != &blocks[LENGTH(blocks) - 1])){ - strcat(output, delim); + if (i > 0){ + strcat(output, postdelim); } - i+=strlen(delim); + i += strlen(postdelim); output[i++] = '\0'; } @@ -128,7 +134,7 @@ void getcmds(int time) } } -#ifndef __OpenBSD__ +#ifndef BSD void getsigcmds(int signal) { const Block *current; @@ -221,7 +227,7 @@ void pstdout() void statusloop() { -#ifndef __OpenBSD__ +#ifndef BSD setupsignals(); #endif // first figure out the default wait interval by finding the @@ -255,7 +261,7 @@ void statusloop() } } -#ifndef __OpenBSD__ +#ifndef BSD void sighandler(int signum) { getsigcmds(signum-SIGRTMIN); @@ -299,7 +305,7 @@ int main(int argc, char** argv) for(int i = 0; i < argc; i++) { if (!strcmp("-d",argv[i])) - delim = argv[++i]; + postdelim = argv[++i]; else if(!strcmp("-p",argv[i])) writestatus = pstdout; } |