diff options
author | Burt P <pburt0@gmail.com> | 2017-07-14 23:31:56 -0500 |
---|---|---|
committer | Leandro Pereira <leandro@hardinfo.org> | 2017-07-19 07:20:33 -0700 |
commit | 155b9396011834c7385ef17da18f82d9d67748b6 (patch) | |
tree | f7ca0d8814742878f307a492422d94ecad2fabc7 | |
parent | 1be5e0da8da151fc4bd17ac9f8c335463977d509 (diff) |
Use const for gettext strings
Signed-off-by: Burt P <pburt0@gmail.com>
-rw-r--r-- | hardinfo/util.c | 33 | ||||
-rw-r--r-- | includes/cpu_util.h | 2 | ||||
-rw-r--r-- | modules/computer/uptime.c | 5 | ||||
-rw-r--r-- | modules/devices/cpu_util.c | 2 |
4 files changed, 26 insertions, 16 deletions
diff --git a/hardinfo/util.c b/hardinfo/util.c index dd5af1a4..e70120a4 100644 --- a/hardinfo/util.c +++ b/hardinfo/util.c @@ -91,26 +91,35 @@ gchar *find_program(gchar *program_name) gchar *seconds_to_string(unsigned int seconds) { unsigned int hours, minutes, days; + const gchar *days_fmt, *hours_fmt, *minutes_fmt, *seconds_fmt; + gchar *full_fmt, *ret = g_strdup(""); minutes = seconds / 60; + seconds %= 60; hours = minutes / 60; minutes %= 60; days = hours / 24; hours %= 24; - gchar *wminutes; - gchar *whours; - gchar *wdays; - - wdays = ngettext("%d day, ", "%d days, ", days); - whours = ngettext("%d hour, ", "%d hours, ", hours); - wminutes = ngettext("%d minute", "%d minutes", minutes); - if (days < 1) { - if (hours < 1) - return g_strdup_printf(ngettext("%d minute", "%d minutes", minutes), minutes); - return g_strdup_printf(whours, wminutes); + days_fmt = ngettext("%d day", "%d days", days); + hours_fmt = ngettext("%d hour", "%d hours", hours); + minutes_fmt = ngettext("%d minute", "%d minutes", minutes); + seconds_fmt = ngettext("%d second", "%d seconds", seconds); + + if (days) { + full_fmt = g_strdup_printf("%s %s %s %s", days_fmt, hours_fmt, minutes_fmt, seconds_fmt); + ret = g_strdup_printf(full_fmt, days, hours, minutes, seconds); + } else if (hours) { + full_fmt = g_strdup_printf("%s %s %s", hours_fmt, minutes_fmt, seconds_fmt); + ret = g_strdup_printf(full_fmt, hours, minutes, seconds); + } else if (minutes) { + full_fmt = g_strdup_printf("%s %s", minutes_fmt, seconds_fmt); + ret = g_strdup_printf(full_fmt, minutes, seconds); + } else { + ret = g_strdup_printf(seconds_fmt, seconds); } - return g_strdup_printf(wdays, whours, wminutes); + g_free(full_fmt); + return ret; } gchar *size_human_readable(gfloat size) diff --git a/includes/cpu_util.h b/includes/cpu_util.h index db72873a..36ca3c2d 100644 --- a/includes/cpu_util.h +++ b/includes/cpu_util.h @@ -12,7 +12,7 @@ #define UNKIFNULL(f) STRIFNULL(f, _("(Unknown)") ) #define EMPIFNULL(f) STRIFNULL(f, "") -gchar *byte_order_str(void); +const gchar *byte_order_str(void); /* from /sys/devices/system/cpu/cpu%d/%s */ gchar* get_cpu_str(const gchar* file, gint cpuid); diff --git a/modules/computer/uptime.c b/modules/computer/uptime.c index b81a041f..a7108d1d 100644 --- a/modules/computer/uptime.c +++ b/modules/computer/uptime.c @@ -45,7 +45,8 @@ gchar * computer_get_formatted_uptime() { UptimeInfo *ui; - gchar *days_fmt, *hours_fmt, *minutes_fmt, *full_fmt, *ret; + const gchar *days_fmt, *hours_fmt, *minutes_fmt; + gchar *full_fmt, *ret; ui = computer_get_uptime(); @@ -64,7 +65,7 @@ computer_get_formatted_uptime() full_fmt = g_strdup_printf("%s %s %s", days_fmt, hours_fmt, minutes_fmt); ret = g_strdup_printf(full_fmt, ui->days, ui->hours, ui->minutes); } - + g_free(full_fmt); g_free(ui); return ret; } diff --git a/modules/devices/cpu_util.c b/modules/devices/cpu_util.c index 6faa9811..123b325f 100644 --- a/modules/devices/cpu_util.c +++ b/modules/devices/cpu_util.c @@ -21,7 +21,7 @@ #include "hardinfo.h" #include "cpu_util.h" -gchar *byte_order_str() { +const gchar *byte_order_str() { #if G_BYTE_ORDER == G_LITTLE_ENDIAN return _("Little Endian"); #else |