From: Timo Sirainen Date: Fri, 1 Oct 2010 17:58:47 +0000 (+0100) Subject: config: Show time/size setting values as more human readable. X-Git-Tag: 2.0.5~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ca7e608c21bdfd7b6a2e7fcb2678ade4c1c1972c;p=thirdparty%2Fdovecot%2Fcore.git config: Show time/size setting values as more human readable. --- diff --git a/src/config/config-request.c b/src/config/config-request.c index dbce8be434..40afd76d14 100644 --- a/src/config/config-request.c +++ b/src/config/config-request.c @@ -30,6 +30,52 @@ struct config_export_context { bool failed; }; +static void config_export_size(string_t *str, uoff_t size) +{ + static const char suffixes[] = { 'B', 'k', 'M', 'G', 'T' }; + char suffix = suffixes[0]; + unsigned int i; + + if (size == 0) { + str_append_c(str, '0'); + return; + } + for (i = 1; i < N_ELEMENTS(suffixes) && (size % 1024) == 0; i++) { + suffix = suffixes[i]; + size /= 1024; + } + str_printfa(str, "%llu %c", (unsigned long long)size, suffix); +} + +static void config_export_time(string_t *str, unsigned int stamp) +{ + const char *suffix = "secs"; + + if (stamp == 0) { + str_append_c(str, '0'); + return; + } + + if (stamp % 60 == 0) { + stamp /= 60; + suffix = "mins"; + if (stamp % 60 == 0) { + stamp /= 60; + suffix = "hours"; + if (stamp % 24 == 0) { + stamp /= 24; + suffix = "days"; + if (stamp % 7 == 0) { + stamp /= 7; + suffix = "weeks"; + } + } + } + } + + str_printfa(str, "%u %s", stamp, suffix); +} + bool config_export_type(string_t *str, const void *value, const void *default_value, enum setting_type type, bool dump_default, @@ -47,7 +93,7 @@ bool config_export_type(string_t *str, const void *value, const uoff_t *val = value, *dval = default_value; if (dump_default || dval == NULL || *val != *dval) - str_printfa(str, "%llu", (unsigned long long)*val); + config_export_size(str, *val); break; } case SET_UINT: @@ -61,7 +107,7 @@ bool config_export_type(string_t *str, const void *value, str_printfa(str, "0%o", *val); break; case SET_TIME: - str_printfa(str, "%u s", *val); + config_export_time(str, *val); break; default: str_printfa(str, "%u", *val);