]> git.street.me.uk Git - andy/viking.git/blobdiff - src/googlesearch.c
Fix parallel build (make -j8) on multi-processor machines. Based on a patch from...
[andy/viking.git] / src / googlesearch.c
index 3448200f15e7ba50450ca3e7ac34b8ac86e4677b..b7c7a72970c719c4cf10261a2eea3d3ef63994d6 100644 (file)
 #include "config.h"
 #endif
 #include <stdlib.h>
+#include <stdio.h>
 #include <string.h>
+#include <glib.h>
+#include <glib/gstdio.h>
 #include <glib/gprintf.h>
 #include <glib/gi18n.h>
 
 #define GOOGLE_SEARCH_URL_FMT "http://maps.google.com/maps?q=%s&output=js"
 #define GOOGLE_SEARCH_PATTERN_1 "{center:{lat:"
 #define GOOGLE_SEARCH_PATTERN_2 ",lng:"
-#define GOOGLE_SEARCH_NOT_FOUND "around this map area did not match any locations"
+#define GOOGLE_SEARCH_NOT_FOUND "not understand the location"
 
 static gchar *last_search_str = NULL;
 static VikCoord *last_coord = NULL;
 static gchar *last_successful_search_str = NULL;
 
-static DownloadOptions googlesearch_options = { "http://maps.google.com/", 0 };
+static DownloadOptions googlesearch_options = { "http://maps.google.com/", 0, a_check_map_file };
 
 gchar * a_googlesearch_get_search_string_for_this_place(VikWindow *vw)
 {
@@ -120,7 +123,7 @@ static gboolean parse_file_for_latlon(gchar *file_name, struct LatLon *ll)
   lat_buf[0] = lon_buf[0] = '\0';
 
   if ((mf = g_mapped_file_new(file_name, FALSE, NULL)) == NULL) {
-    g_critical(_("couldn't map temp file\n"));
+    g_critical(_("couldn't map temp file"));
     exit(1);
   }
   len = g_mapped_file_get_length(mf);
@@ -192,8 +195,9 @@ gchar *uri_escape(gchar *str)
       dst += 3;
     }
   }
+  *dst = '\0';
 
-    return(esc_str);
+  return(esc_str);
 }
 
 static int google_search_get_coord(VikWindow *vw, VikViewport *vvp, gchar *srch_str, VikCoord *coord)
@@ -206,10 +210,14 @@ static int google_search_get_coord(VikWindow *vw, VikViewport *vvp, gchar *srch_
   int ret = 0;  /* OK */
   struct LatLon ll;
 
+  g_debug("%s: raw search: %s", __FUNCTION__, srch_str);
+
   escaped_srch_str = uri_escape(srch_str);
 
+  g_debug("%s: escaped search: %s", __FUNCTION__, escaped_srch_str);
+
   if ((tmp_fd = g_file_open_tmp ("vikgsearch.XXXXXX", &tmpname, NULL)) == -1) {
-    g_critical(_("couldn't open temp file\n"));
+    g_critical(_("couldn't open temp file"));
     exit(1);
   }
 
@@ -220,11 +228,13 @@ static int google_search_get_coord(VikWindow *vw, VikViewport *vvp, gchar *srch_
   /* TODO: curl may not be available */
   if (curl_download_uri(uri, tmp_file, &googlesearch_options)) {  /* error */
     fclose(tmp_file);
+    tmp_file = NULL;
     ret = -1;
     goto done;
   }
 
   fclose(tmp_file);
+  tmp_file = NULL;
   if (!parse_file_for_latlon(tmpname, &ll)) {
     ret = -1;
     goto done;
@@ -243,7 +253,7 @@ static int google_search_get_coord(VikWindow *vw, VikViewport *vvp, gchar *srch_
 done:
   g_free(escaped_srch_str);
   g_free(uri);
-  remove(tmpname);
+  g_remove(tmpname);
   g_free(tmpname);
   return ret;
 }