X-Git-Url: https://git.armaanb.net/?p=dwmblocks.git;a=blobdiff_plain;f=dwmblocks.c;h=e6c20dd37d44a682a80cda47c56afd2079abfaae;hp=64ad7a33e2d6b6acf39f28b899e1a74a23be9cee;hb=HEAD;hpb=b6b0be4f4fe77fea6f1aef07232a44abd0139098 diff --git a/dwmblocks.c b/dwmblocks.c index 64ad7a3..e6c20dd 100644 --- a/dwmblocks.c +++ b/dwmblocks.c @@ -48,7 +48,7 @@ static void (*writestatus) () = pstdout; #endif -#include "blocks.h" +#include "config.h" static char statusbar[LENGTH(blocks)][CMDLENGTH] = {0}; static char statusstr[2][STATUSLENGTH]; @@ -63,17 +63,15 @@ void getcmd(const Block *block, char *output) if (!cmdf) return; int i = strlen(block->icon); - fgets(output+i, CMDLENGTH-i-delimLen, cmdf); + fgets(output+i, CMDLENGTH-i, cmdf); i = strlen(output); - if (i == 0)//return if block and command output are both empty + if (i == 0) { + //return if block and command output are both empty + pclose(cmdf); return; - if (delim[0] != '\0') { - //only chop off newline if one is present at the end - i = output[i-1] == '\n' ? i-1 : i; - strncpy(output+i, delim, delimLen); + } else if (output[i-1] == '\n') { + output[i-1] = '\0'; } - else - output[i++] = '\0'; pclose(cmdf); } @@ -118,7 +116,7 @@ int getstatus(char *str, char *last) str[0] = '\0'; for (unsigned int i = 0; i < LENGTH(blocks); i++) strcat(str, statusbar[i]); - str[strlen(str)-strlen(delim)] = '\0'; + str[strlen(str)] = '\0'; return strcmp(str, last);//0 if they are the same } @@ -189,17 +187,13 @@ void termhandler() int main(int argc, char** argv) { for (int i = 0; i < argc; i++) {//Handle command line arguments - if (!strcmp("-d",argv[i])) - strncpy(delim, argv[++i], delimLen); - else if (!strcmp("-p",argv[i])) + if (!strcmp("-p",argv[i])) writestatus = pstdout; } #ifndef NO_X if (!setupX()) return 1; #endif - delimLen = MIN(delimLen, strlen(delim)); - delim[delimLen++] = '\0'; signal(SIGTERM, termhandler); signal(SIGINT, termhandler); statusloop();