diff options
author | Luke Smith <luke@lukesmith.xyz> | 2020-04-24 08:40:49 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-24 08:40:49 -0400 |
commit | a46d090a2eee02e9b1375a0a12636f873813b960 (patch) | |
tree | 8b1c52a0d7c3e8f883100e34ba8aea0c9ee15af1 | |
parent | cc1b97c7315aee3d9a25438cca32c6a4f3b25d9a (diff) | |
parent | 6bbd6545f422bab6dfd341d88e99316f4cdab7ac (diff) | |
download | dwmblocks-a46d090a2eee02e9b1375a0a12636f873813b960.tar.gz dwmblocks-a46d090a2eee02e9b1375a0a12636f873813b960.tar.bz2 dwmblocks-a46d090a2eee02e9b1375a0a12636f873813b960.zip |
Merge pull request #12 from mokulus/master
Remove newlines from command output
-rw-r--r-- | dwmblocks.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/dwmblocks.c b/dwmblocks.c index 0cd0b54..de872bf 100644 --- a/dwmblocks.c +++ b/dwmblocks.c @@ -16,6 +16,7 @@ typedef struct { void sighandler(int num); void buttonhandler(int sig, siginfo_t *si, void *ucontext); void replace(char *str, char old, char new); +void remove_all(char *str, char to_remove); void getcmds(int time); #ifndef __OpenBSD__ void getsigcmds(int signal); @@ -48,6 +49,19 @@ void replace(char *str, char old, char 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 void getcmd(const Block *block, char *output) { @@ -77,6 +91,7 @@ void getcmd(const Block *block, char *output) char c; int i = strlen(block->icon); fgets(output+i, CMDLENGTH-i, cmdf); + remove_all(output, '\n'); i = strlen(output); if (delim != '\0' && i) output[i++] = delim; |