Fix win32 build after removing gnulib
authorAndy Spencer <andy753421@gmail.com>
Wed, 2 Nov 2011 06:44:53 +0000 (06:44 +0000)
committerAndy Spencer <andy753421@gmail.com>
Wed, 2 Nov 2011 08:01:01 +0000 (08:01 +0000)
src/main.c
src/plugins/alert.c
src/plugins/radar.c

index 6d335af..3c2e57b 100644 (file)
@@ -58,9 +58,9 @@ static void set_location_time(AWeatherGui *gui, char *site, char *time)
        /* Set time
         *   Do this before setting setting location
         *   so that it doesn't refresh twice */
-       struct tm tm = {};
-       strptime(time, "%Y-%m-%d %H:%M", &tm);
-       time_t sec = mktime(&tm);
+       int year, mon, day, hour, min;
+       sscanf(time, "%d-%d-%d %d:%d", &year, &mon, &day, &hour, &min);
+       time_t sec = mktime(&(struct tm){0, year-1900, mon-1, day, hour, min});
        if (sec > 0)
                grits_viewer_set_time(gui->viewer, sec);
        g_debug("date = [%s] == %lu\n", time, sec);
index 379a45e..4bd68d3 100644 (file)
@@ -699,11 +699,10 @@ static gboolean _update_buttons(GritsPluginAlert *alert)
        }
 
        /* Set time widget */
-       struct tm tm;
-       gmtime_r(&alert->updated, &tm);
+       struct tm *tm = gmtime(&alert->updated);
        gchar *date_str = g_strdup_printf(" <b><i>%04d-%02d-%02d %02d:%02d</i></b>",
-                       tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
-                       tm.tm_hour,      tm.tm_min);
+                       tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
+                       tm->tm_hour,      tm->tm_min);
        gtk_label_set_markup(GTK_LABEL(updated), date_str);
        g_free(date_str);
 
index 8c4d969..62b55c0 100644 (file)
@@ -41,7 +41,7 @@ static void _gtk_bin_set_child(GtkBin *bin, GtkWidget *new)
 }
 
 static gchar *_find_nearest(time_t time, GList *files,
-               gsize offset, gchar *format)
+               gsize offset)
 {
        g_debug("RadarSite: find_nearest ...");
        time_t  nearest_time = 0;
@@ -50,7 +50,11 @@ static gchar *_find_nearest(time_t time, GList *files,
        struct tm tm = {};
        for (GList *cur = files; cur; cur = cur->next) {
                gchar *file = cur->data;
-               strptime(file+offset, format, &tm);
+               sscanf(file+offset, "%4d%2d%2d_%2d%2d",
+                               &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
+                               &tm.tm_hour, &tm.tm_min);
+               tm.tm_year -= 1900;
+               tm.tm_mon  -= 1;
                if (ABS(time - mktime(&tm)) <
                    ABS(time - nearest_time)) {
                        nearest_file = file;
@@ -144,7 +148,7 @@ gpointer _site_update_thread(gpointer _site)
                        "^\\w{4}_\\d{8}_\\d{4}$", site->city->code,
                        "\\d+ (.*)", (offline ? NULL : dir_list));
        g_free(dir_list);
-       gchar *nearest = _find_nearest(site->time, files, 5, "%Y%m%d_%H%M");
+       gchar *nearest = _find_nearest(site->time, files, 5);
        g_list_foreach(files, (GFunc)g_free, NULL);
        g_list_free(files);
        if (!nearest) {
@@ -493,17 +497,18 @@ gpointer _conus_update_thread(gpointer _conus)
        if (time(NULL) - conus->time < 60*60*5 && !offline) {
                /* radar.weather.gov is full of lies.
                 * the index pages get cached and out of date */
-               struct tm tm;
-               gmtime_r(&conus->time, &tm);
-               time_t onthe8 = conus->time - 60*((tm.tm_min+1)%10+1);
-               gmtime_r(&onthe8, &tm);
+               /* gmtime is not thread safe, but it's not used very often so
+                * hopefully it'll be alright for now... :-( */
+               struct tm *tm = gmtime(&conus->time);
+               time_t onthe8 = conus->time - 60*((tm->tm_min+1)%10+1);
+               tm = gmtime(&onthe8);
                nearest = g_strdup_printf("Conus_%04d%02d%02d_%02d%02d_N0Ronly.gif",
-                               tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
-                               tm.tm_hour, tm.tm_min);
+                               tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
+                               tm->tm_hour, tm->tm_min);
        } else {
                GList *files = grits_http_available(conus->http,
                                "^Conus_[^\"]*_N0Ronly.gif$", "", NULL, NULL);
-               nearest = _find_nearest(conus->time, files, 6, "%Y%m%d_%H%M");
+               nearest = _find_nearest(conus->time, files, 6);
                g_list_foreach(files, (GFunc)g_free, NULL);
                g_list_free(files);
                if (!nearest) {