From 161e0f5615ff1ea1ee99cfb91c01366ea3d7da0a Mon Sep 17 00:00:00 2001 From: Ashish Kumar Yadav <ashishkumar.yadav@students.iiserpune.ac.in> Date: Tue, 9 Feb 2021 12:34:20 +0530 Subject: [PATCH] updateblock - nullterminate --- blocks.h | 1 - blocks/battery.sh | 2 +- blocks/calendar.sh | 2 +- blocks/cpu_temp.sh | 4 ++-- dwmblocks.c | 5 +++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/blocks.h b/blocks.h index 57c0b73..41e7638 100644 --- a/blocks.h +++ b/blocks.h @@ -23,7 +23,6 @@ delivered first. */ /* pathu - path of the program whose output is used as status text of the block - (output of the program should end in a null or newline character) * pathc - path of the program used for handling clicks on the block */ /* 1 interval = INTERVALs seconds, INTERVALn nanoseconds */ diff --git a/blocks/battery.sh b/blocks/battery.sh index 6106114..df98fc8 100755 --- a/blocks/battery.sh +++ b/blocks/battery.sh @@ -1,4 +1,4 @@ #!/bin/sh ICON="" read -r capacity </sys/class/power_supply/BAT0/capacity -printf "$ICON%s%%\n" "$capacity" +printf "$ICON%s%%" "$capacity" diff --git a/blocks/calendar.sh b/blocks/calendar.sh index 52f2106..72a0a5b 100755 --- a/blocks/calendar.sh +++ b/blocks/calendar.sh @@ -1,3 +1,3 @@ #!/bin/sh ICON="" -printf "$ICON%s\n" "$(date '+%a, %b %d, %R')" +printf "$ICON%s" "$(date '+%a, %b %d, %R')" diff --git a/blocks/cpu_temp.sh b/blocks/cpu_temp.sh index 2af2b89..e660639 100755 --- a/blocks/cpu_temp.sh +++ b/blocks/cpu_temp.sh @@ -9,7 +9,7 @@ read -r temp </sys/class/thermal/thermal_zone0/temp temp=${temp%???} if [ "$temp" -lt "$crit" ] ; then - printf "$ICONn%s°C\n" "$temp" + printf "$ICONn%s°C" "$temp" else - printf "$ICONc%s°C\n" "$temp" + printf "$ICONc%s°C" "$temp" fi diff --git a/dwmblocks.c b/dwmblocks.c index 5fb6278..96cfb6f 100644 --- a/dwmblocks.c +++ b/dwmblocks.c @@ -234,6 +234,7 @@ updateblock(Block *block, int sigval) exit(1); } close(fd[0]); + block->curcmdout[block->curcmdout[trd - 1] == '\n' ? trd - 1 : trd] = '\0'; } } } @@ -249,7 +250,7 @@ updatestatus() /* checking half of the function */ for (; block->pathu; block++) { c = block->curcmdout, p = block->prvcmdout; - for (; *c == *p && *c != '\n' && *c != '\0'; c++, p++); + for (; *c != '\0' && *c == *p; c++, p++); s += c - block->curcmdout; if (*c != *p) goto update; @@ -265,7 +266,7 @@ updatestatus() for (; block->pathu; block++) { c = block->curcmdout, p = block->prvcmdout; update: - for (; *p = *c, *c != '\n' && *c != '\0'; c++, p++) + for (; (*p = *c) != '\0'; c++, p++) *(s++) = *c; if (c == block->curcmdout) continue;