summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/print_cpu_temperature.c21
-rw-r--r--testcases/020-percentliteral-cpu_temperature/expected_output.txt1
-rw-r--r--testcases/020-percentliteral-cpu_temperature/i3status.conf10
-rw-r--r--testcases/020-percentliteral-cpu_temperature/temp1_input1
4 files changed, 21 insertions, 12 deletions
diff --git a/src/print_cpu_temperature.c b/src/print_cpu_temperature.c
index 01744a1..f94d1a7 100644
--- a/src/print_cpu_temperature.c
+++ b/src/print_cpu_temperature.c
@@ -10,6 +10,8 @@
#include "i3status.h"
+#define STRING_SIZE 20
+
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
#include <err.h>
#include <sys/types.h>
@@ -213,7 +215,6 @@ void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const
char *outwalk = buffer;
#ifdef THERMAL_ZONE
const char *selected_format = format;
- const char *walk;
bool colorful_output = false;
char *thermal_zone;
temperature_t temperature;
@@ -248,18 +249,13 @@ void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const
selected_format = format_above_threshold;
}
- for (walk = selected_format; *walk != '\0'; walk++) {
- if (*walk != '%') {
- *(outwalk++) = *walk;
-
- } else if (BEGINS_WITH(walk + 1, "degrees")) {
- outwalk += sprintf(outwalk, "%s", temperature.formatted_value);
- walk += strlen("degrees");
+ char string_degrees[STRING_SIZE];
+ snprintf(string_degrees, STRING_SIZE, "%s", temperature.formatted_value);
+ placeholder_t placeholders[] = {
+ {.name = "%degrees", .value = string_degrees}};
- } else {
- *(outwalk++) = '%';
- }
- }
+ const size_t num = sizeof(placeholders) / sizeof(placeholder_t);
+ buffer = format_placeholders(selected_format, &placeholders[0], num);
if (colorful_output) {
END_COLOR;
@@ -269,6 +265,7 @@ void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const
free(thermal_zone);
OUTPUT_FULL_TEXT(buffer);
+ free(buffer);
return;
error:
free(thermal_zone);
diff --git a/testcases/020-percentliteral-cpu_temperature/expected_output.txt b/testcases/020-percentliteral-cpu_temperature/expected_output.txt
new file mode 100644
index 0000000..a0c0525
--- /dev/null
+++ b/testcases/020-percentliteral-cpu_temperature/expected_output.txt
@@ -0,0 +1 @@
+I can %haz literal% % ?
diff --git a/testcases/020-percentliteral-cpu_temperature/i3status.conf b/testcases/020-percentliteral-cpu_temperature/i3status.conf
new file mode 100644
index 0000000..b1c4008
--- /dev/null
+++ b/testcases/020-percentliteral-cpu_temperature/i3status.conf
@@ -0,0 +1,10 @@
+general {
+ output_format = "none"
+}
+
+order += "cpu_temperature 0"
+
+cpu_temperature 0 {
+ format = "I can %haz literal% % ?"
+ path = "testcases/020-percentliteral-cpu_temperature/temp1_input"
+} \ No newline at end of file
diff --git a/testcases/020-percentliteral-cpu_temperature/temp1_input b/testcases/020-percentliteral-cpu_temperature/temp1_input
new file mode 100644
index 0000000..a90c8f8
--- /dev/null
+++ b/testcases/020-percentliteral-cpu_temperature/temp1_input
@@ -0,0 +1 @@
+37000 \ No newline at end of file