Branch: refs/heads/master Author: Enrico Tröger enrico.troeger@uvena.de Committer: Enrico Tröger enrico.troeger@uvena.de Date: Sun, 17 Mar 2013 16:17:09 UTC Commit: fbce36418256cacee6d52e535e8ee41bfc76db39 https://github.com/geany/geany/commit/fbce36418256cacee6d52e535e8ee41bfc76db...
Log Message: ----------- Improve build date conversion code
Don't use strptime() as it is not very portable, instead use a GDate and use the code also for the date output in --version.
Modified Paths: -------------- src/about.c src/main.c src/utils.c src/utils.h
Modified: src/about.c 10 files changed, 4 insertions(+), 6 deletions(-) =================================================================== @@ -153,8 +153,7 @@ static GtkWidget *create_dialog(void) gchar buffer[512]; gchar buffer2[128]; guint i, row = 0; - struct tm builddate_tm; - char builddate_local[255]; + gchar *build_date;
dialog = gtk_dialog_new();
@@ -227,10 +226,9 @@ static GtkWidget *create_dialog(void) gtk_label_set_justify(GTK_LABEL(builddate_label), GTK_JUSTIFY_CENTER); gtk_label_set_selectable(GTK_LABEL(builddate_label), TRUE); gtk_label_set_use_markup(GTK_LABEL(builddate_label), TRUE); - memset(&builddate_tm, 0, sizeof(struct tm)); - strptime(__DATE__, "%b %d %Y", &builddate_tm); - strftime(builddate_local, sizeof(builddate_local), GEANY_TEMPLATES_FORMAT_DATE, &builddate_tm); - g_snprintf(buffer2, sizeof(buffer2), _("(built on or after %s)"), builddate_local); + build_date = utils_parse_and_format_build_date(__DATE__); + g_snprintf(buffer2, sizeof(buffer2), _("(built on or after %s)"), build_date); + g_free(build_date); g_snprintf(buffer, sizeof(buffer), BUILDDATE, buffer2); gtk_label_set_markup(GTK_LABEL(builddate_label), buffer); gtk_misc_set_padding(GTK_MISC(builddate_label), 2, 2);
Modified: src/main.c 5 files changed, 4 insertions(+), 1 deletions(-) =================================================================== @@ -568,13 +568,16 @@ static void parse_command_line_options(gint *argc, gchar ***argv)
if (show_version) { + gchar *build_date = utils_parse_and_format_build_date(__DATE__); + printf(PACKAGE " %s (", main_get_version_string()); /* note for translators: library versions are printed after this */ - printf(_("built on %s with "), __DATE__); + printf(_("built on %s with "), build_date); printf(geany_lib_versions, GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION, GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION); printf(")\n"); + g_free(build_date); wait_for_input_on_windows(); exit(0); }
Modified: src/utils.c 31 files changed, 31 insertions(+), 0 deletions(-) =================================================================== @@ -52,6 +52,7 @@ #include "win32.h" #include "project.h" #include "ui_utils.h" +#include "templates.h"
#include "utils.h"
@@ -2100,3 +2101,33 @@ gchar **utils_strv_join(gchar **first, gchar **second) g_free(second); return strv; } + + +/* Try to parse a date using g_date_set_parse(). It doesn't take any format hint, + * obviously g_date_set_parse() uses some magic. + * The returned GDate object must be freed. */ +GDate *utils_parse_date(const gchar *input) +{ + GDate *date = g_date_new(); + + g_date_set_parse(date, input); + + if (g_date_valid(date)) + return date; + + g_date_free(date); + return NULL; +} + + +gchar *utils_parse_and_format_build_date(const gchar *input) +{ + gchar date_buf[255]; + GDate *date = utils_parse_date(input); + + if (date != NULL) + g_date_strftime(date_buf, sizeof(date_buf), GEANY_TEMPLATES_FORMAT_DATE, date); + return g_strdup(date_buf); + + return g_strdup(input); +}
Modified: src/utils.h 4 files changed, 4 insertions(+), 0 deletions(-) =================================================================== @@ -277,6 +277,10 @@ gboolean utils_spawn_async(const gchar *dir, gchar **argv, gchar **env, GSpawnFl
gchar **utils_copy_environment(const gchar **exclude_vars, const gchar *first_varname, ...) G_GNUC_NULL_TERMINATED;
+GDate *utils_parse_date(const gchar *input); + +gchar *utils_parse_and_format_build_date(const gchar *input); + G_END_DECLS
#endif
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).