Merge pull request #71 from mehmetumit/master
This commit is contained in:
29
dwmblocks.c
29
dwmblocks.c
@ -58,25 +58,26 @@ static int returnStatus = 0;
|
|||||||
//opens process *cmd and stores output in *output
|
//opens process *cmd and stores output in *output
|
||||||
void getcmd(const Block *block, char *output)
|
void getcmd(const Block *block, char *output)
|
||||||
{
|
{
|
||||||
strcpy(output, block->icon);
|
//make sure status is same until output is ready
|
||||||
|
char tempstatus[CMDLENGTH] = {0};
|
||||||
|
strcpy(tempstatus, block->icon);
|
||||||
FILE *cmdf = popen(block->command, "r");
|
FILE *cmdf = popen(block->command, "r");
|
||||||
if (!cmdf)
|
if (!cmdf)
|
||||||
return;
|
return;
|
||||||
int i = strlen(block->icon);
|
int i = strlen(block->icon);
|
||||||
fgets(output+i, CMDLENGTH-i-delimLen, cmdf);
|
fgets(tempstatus+i, CMDLENGTH-i-delimLen, cmdf);
|
||||||
i = strlen(output);
|
i = strlen(tempstatus);
|
||||||
if (i == 0) {
|
//if block and command output are both not empty
|
||||||
//return if block and command output are both empty
|
if (i != 0) {
|
||||||
pclose(cmdf);
|
//only chop off newline if one is present at the end
|
||||||
return;
|
i = tempstatus[i-1] == '\n' ? i-1 : i;
|
||||||
|
if (delim[0] != '\0') {
|
||||||
|
strncpy(tempstatus+i, delim, delimLen);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
tempstatus[i++] = '\0';
|
||||||
}
|
}
|
||||||
//only chop off newline if one is present at the end
|
strcpy(output, tempstatus);
|
||||||
i = output[i-1] == '\n' ? i-1 : i;
|
|
||||||
if (delim[0] != '\0') {
|
|
||||||
strncpy(output+i, delim, delimLen);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
output[i++] = '\0';
|
|
||||||
pclose(cmdf);
|
pclose(cmdf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user