diff options
author | Ingo Bürk <admin@airblader.de> | 2020-04-03 08:38:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-03 08:38:30 +0200 |
commit | 1858cd8dfb8df43e332acdf7984a1ad26ceecab4 (patch) | |
tree | 8cdee82cfda12256201e354c928aa4545e262cf1 | |
parent | 4980193dc7be7ef78f3bc51cf1432a1e5a37d37e (diff) | |
parent | 7418b5bebbcf40a298c3bd6178ea3917ef065225 (diff) |
Merge pull request #401 from Stunkymonkey/format_placeholder-time
use format_placeholder for time
-rw-r--r-- | src/print_time.c | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/src/print_time.c b/src/print_time.c index 5133c51..67930b7 100644 --- a/src/print_time.c +++ b/src/print_time.c @@ -10,6 +10,8 @@ #include "i3status.h" +#define STRING_SIZE 50 + static bool local_timezone_init = false; static const char *local_timezone = NULL; static const char *current_timezone = NULL; @@ -36,10 +38,8 @@ void set_timezone(const char *tz) { } void print_time(yajl_gen json_gen, char *buffer, const char *title, const char *format, const char *tz, const char *locale, const char *format_time, bool hide_if_equals_localtime, time_t t) { - const char *walk; char *outwalk = buffer; struct tm local_tm, tm; - char timebuf[1024]; if (title != NULL) INSTANCE(title); @@ -61,23 +61,18 @@ void print_time(yajl_gen json_gen, char *buffer, const char *title, const char * setlocale(LC_ALL, locale); } + char string_time[STRING_SIZE]; + if (format_time == NULL) { - strftime(timebuf, sizeof(timebuf), format, &tm); - maybe_escape_markup(timebuf, &outwalk); + strftime(string_time, sizeof(string_time), format, &tm); + maybe_escape_markup(string_time, &outwalk); } else { - for (walk = format; *walk != '\0'; walk++) { - if (*walk != '%') { - *(outwalk++) = *walk; + strftime(string_time, sizeof(string_time), format_time, &tm); + placeholder_t placeholders[] = { + {.name = "%time", .value = string_time}}; - } else if (BEGINS_WITH(walk + 1, "time")) { - strftime(timebuf, sizeof(timebuf), format_time, &tm); - maybe_escape_markup(timebuf, &outwalk); - walk += strlen("time"); - - } else { - *(outwalk++) = '%'; - } - } + const size_t num = sizeof(placeholders) / sizeof(placeholder_t); + buffer = format_placeholders(format_time, &placeholders[0], num); } if (locale != NULL) { |