Merge pull request #12 from mokulus/master
Remove newlines from command output
This commit is contained in:
commit
a46d090a2e
1 changed files with 15 additions and 0 deletions
15
dwmblocks.c
15
dwmblocks.c
|
@ -16,6 +16,7 @@ typedef struct {
|
||||||
void sighandler(int num);
|
void sighandler(int num);
|
||||||
void buttonhandler(int sig, siginfo_t *si, void *ucontext);
|
void buttonhandler(int sig, siginfo_t *si, void *ucontext);
|
||||||
void replace(char *str, char old, char new);
|
void replace(char *str, char old, char new);
|
||||||
|
void remove_all(char *str, char to_remove);
|
||||||
void getcmds(int time);
|
void getcmds(int time);
|
||||||
#ifndef __OpenBSD__
|
#ifndef __OpenBSD__
|
||||||
void getsigcmds(int signal);
|
void getsigcmds(int signal);
|
||||||
|
@ -48,6 +49,19 @@ void replace(char *str, char old, char new)
|
||||||
str[i] = new;
|
str[i] = new;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void remove_all(char *str, char to_remove) {
|
||||||
|
char *read = str;
|
||||||
|
char *write = str;
|
||||||
|
while (*read) {
|
||||||
|
if (*read == to_remove) {
|
||||||
|
read++;
|
||||||
|
*write = *read;
|
||||||
|
}
|
||||||
|
read++;
|
||||||
|
write++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//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)
|
||||||
{
|
{
|
||||||
|
@ -77,6 +91,7 @@ void getcmd(const Block *block, char *output)
|
||||||
char c;
|
char c;
|
||||||
int i = strlen(block->icon);
|
int i = strlen(block->icon);
|
||||||
fgets(output+i, CMDLENGTH-i, cmdf);
|
fgets(output+i, CMDLENGTH-i, cmdf);
|
||||||
|
remove_all(output, '\n');
|
||||||
i = strlen(output);
|
i = strlen(output);
|
||||||
if (delim != '\0' && i)
|
if (delim != '\0' && i)
|
||||||
output[i++] = delim;
|
output[i++] = delim;
|
||||||
|
|
Loading…
Reference in a new issue