Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove unused int, and optimize getcmd func #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 16 additions & 22 deletions dwmblocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,32 +53,26 @@ static void (*writestatus) () = pstdout;
static char statusbar[LENGTH(blocks)][CMDLENGTH] = {0};
static char statusstr[2][STATUSLENGTH];
static int statusContinue = 1;
static int returnStatus = 0;

//opens process *cmd and stores output in *output
void getcmd(const Block *block, char *output)
{
//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(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';
}
strcpy(output, tempstatus);
pclose(cmdf);
strcpy(output, 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) {
if (output[i-1] == '\n')
i--;
if (delim[0] != '\0')
strncpy(output + i, delim, delimLen);
else
output[i] = '\0';
}
pclose(cmdf);
}

void getcmds(int time)
Expand Down