Browse Source

Merge pull request #71 from mehmetumit/master

master
torrinfail 7 months ago
committed by GitHub
parent
commit
8cedd22068
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 14 deletions
  1. +15
    -14
      dwmblocks.c

+ 15
- 14
dwmblocks.c View File

@ -58,25 +58,26 @@ static int returnStatus = 0;
//opens process *cmd and stores output in *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");
if (!cmdf)
return;
int i = strlen(block->icon);
fgets(output+i, CMDLENGTH-i-delimLen, cmdf);
i = strlen(output);
if (i == 0) {
//return if block and command output are both empty
pclose(cmdf);
return;
}
//only chop off newline if one is present at the end
i = output[i-1] == '\n' ? i-1 : i;
if (delim[0] != '\0') {
strncpy(output+i, delim, delimLen);
fgets(tempstatus+i, CMDLENGTH-i-delimLen, cmdf);
i = strlen(tempstatus);
//if block and command output are both not empty
if (i != 0) {
//only chop off newline if one is present at the end
i = tempstatus[i-1] == '\n' ? i-1 : i;
if (delim[0] != '\0') {
strncpy(tempstatus+i, delim, delimLen);
}
else
tempstatus[i++] = '\0';
}
else
output[i++] = '\0';
strcpy(output, tempstatus);
pclose(cmdf);
}


Loading…
Cancel
Save