Move install folder for geocode-parameters
authorColin Clark <colin.clark@cclark.uk>
Tue, 18 Jul 2017 18:39:58 +0000 (19:39 +0100)
committerColin Clark <colin.clark@cclark.uk>
Tue, 18 Jul 2017 18:39:58 +0000 (19:39 +0100)
Install geocode-parameters.awk in GQ_BIN_DIR.

User can put their own version in ~/.config/geeqie/applications/

configure.in
doc/docbook/GuideReferenceDecodeLatLong.xml
plugins/Makefile.am
plugins/geocode-parameters/Makefile.am [new file with mode: 0644]
plugins/geocode-parameters/geocode-parameters.awk [new file with mode: 0644]
src/misc.c

index d24e7f9..dfb4574 100644 (file)
@@ -562,6 +562,7 @@ AC_CONFIG_FILES([
     plugins/rotate/Makefile
     plugins/ufraw/Makefile
     plugins/import/Makefile
+    plugins/geocode-parameters/Makefile
     geeqie.spec
 ])
 
index 22b4c6a..55a34d0 100644 (file)
     <para />\r
     You may also drag-and-drop a URL of this type onto the map to cause the map to be re-centered.\r
     <para />\r
-    To enable this feature, create the file\r
+    This feature uses the file:\r
     <para />\r
-    <code>~/.config/geeqie/geocode-parameters.awk</code>\r
+    <code>/usr/local/lib/geeqie/geocode-parameters.awk</code>\r
     <para />\r
-    and copy the following text into it:\r
-  </para>\r
-  <para>\r
-    <programlisting xml:space="preserve">\r
-      # Store this file in:\r
-      # ~/.config/geeqie/geocode-parameters.awk\r
-      #\r
-      # This file is used to decode the results of internet or other searches\r
-      # to extract a geo-position from a text string. \r
-      # To include other searches, follow the examples below and\r
-      # ensure the returned value is either in the format:\r
-      # 89.123 179.123\r
-      # or\r
-      # Error: $0\r
-      #\r
-      \r
-      function check_parameters(latitude, longitude)\r
-      {\r
-      # Ensure the parameters are numbers    \r
-      if ((latitude == (latitude+0)) &amp;&amp; (longitude == (longitude+0)))\r
-      {\r
-      if (latitude &gt;= -90 &amp;&amp; latitude &lt;= 90 &amp;&amp;\r
-      longitude &gt;= -180 &amp;&amp; longitude &lt;= 180)\r
-      {\r
-      return latitude " " longitude\r
-      }\r
-      else\r
-      {\r
-      return "Error: " latitude " " longitude\r
-      }\r
-      }\r
-      else\r
-      {\r
-      return "Error: " latitude " " longitude\r
-      }\r
-      }\r
-      \r
-      # This awk file is accessed by an internal function.\r
-      # The call is of the format:\r
-      # echo "string_to_be_searched" | awk -f geocode-parameters.awk\r
-      #\r
-      # Search the input string for known formats.\r
-      {\r
-      if (index($0, "http://www.geonames.org/maps/google_"))\r
-      {\r
-      # This is a drag-and-drop or copy-paste from a geonames.org search\r
-      # in the format e.g.\r
-      # http://www.geonames.org/maps/google_51.513_-0.092.html\r
-      \r
-      gsub(/http:\/\/www.geonames.org\/maps\/google_/, "")\r
-      gsub(/.html/, "")\r
-      gsub(/_/, " ")\r
-      print check_parameters($1, $2)\r
-      }\r
-      \r
-      else if (index($0, "https://www.openstreetmap.org/search?query="))\r
-      {\r
-      # This is a copy-paste from an openstreetmap.org search\r
-      # in the format e.g.\r
-      # https://www.openstreetmap.org/search?query=51.4878%2C-0.1353#map=11/51.4880/-0.1356\r
-      \r
-      gsub(/https:\/\/www.openstreetmap.org\/search\?query=/, "")\r
-      gsub(/#map=.*/, "")\r
-      gsub(/%2C/, " ")\r
-      print check_parameters($1, $2)\r
-      }\r
-      \r
-      else if (index($0, "https://www.openstreetmap.org/#map="))\r
-      {\r
-      # This is a copy-paste from an openstreetmap.org search\r
-      # in the format e.g.\r
-      # https://www.openstreetmap.org/#map=5/18.271/16.084\r
-      \r
-      gsub(/https:\/\/www.openstreetmap.org\/#map=[^\/]*/,"")\r
-      gsub(/\//," ")\r
-      print check_parameters($1, $2)\r
-      }\r
-      \r
-      else if (index($0, "https://www.google.com/maps/"))\r
-      {\r
-      # This is a copy-paste from a google.com maps search\r
-      # in the format e.g.\r
-      # https://www.google.com/maps/place/London,+UK/@51.5283064,-0.3824815,10z/data=....\r
-      \r
-      gsub(/https:\/\/www.google.com\/maps.*@/,"")\r
-      sub(/,/," ")\r
-      gsub(/,.*/,"")\r
-      print check_parameters($1, $2)\r
-      }\r
-      \r
-      else if (index($0,".html"))\r
-      {\r
-      # This is an unknown html address\r
-      \r
-      print "Error: " $0\r
-      }\r
-      \r
-      else if (index($0,"http"))\r
-      {\r
-      # This is an unknown html address\r
-      \r
-      print "Error: " $0\r
-      }\r
-      \r
-      else if (index($0, ","))\r
-      {\r
-      # This is assumed to be a simple lat/long of the format:\r
-      # 89.123,179.123\r
-      \r
-      split($0, latlong, ",")\r
-      print check_parameters(latlong[1], latlong[2])\r
-      }\r
-      \r
-      else\r
-      {\r
-      # This is assumed to be a simple lat/long of the format:\r
-      # 89.123 179.123\r
-      \r
-      split($0, latlong, " ")\r
-      print check_parameters(latlong[1], latlong[2])\r
-      }\r
-      }\r
-\r
-    </programlisting>\r
+    You may create your own decodes by using the above file as an example, and storing the file in:\r
+    <para />\r
+    <code>~/.config/geeqie/applications/geocode-parameters.awk</code>\r
+    <para />\r
+    If a successful decode was not made from the first file, your local version will then be used.\r
   </para>\r
 </section>\r
index 3f6495c..9d1aaca 100644 (file)
@@ -1,6 +1,6 @@
 #FIXME enable or disable individual plugins from configure
 
-SUBDIRS = rotate symlink ufraw import
+SUBDIRS = rotate symlink ufraw import geocode-parameters
 qq_desktoptemplatedir = $(appdir)
 qq_desktoptemplate_DATA = template.desktop
 
diff --git a/plugins/geocode-parameters/Makefile.am b/plugins/geocode-parameters/Makefile.am
new file mode 100644 (file)
index 0000000..eab0c1d
--- /dev/null
@@ -0,0 +1 @@
+dist_gq_bin_SCRIPTS = geocode-parameters.awk
diff --git a/plugins/geocode-parameters/geocode-parameters.awk b/plugins/geocode-parameters/geocode-parameters.awk
new file mode 100644 (file)
index 0000000..81d17dc
--- /dev/null
@@ -0,0 +1,120 @@
+#
+# This file is used by the Search option "search on geo-position".
+# It is used to decode the results of internet or other searches
+# to extract a geo-position from a text string.
+#
+# To include other searches, follow the examples below and
+# store the file in:
+# ~/.config/geeqie/applications/geocode-parameters.awk
+# Ensure the returned value is either in the format:
+# 89.123 179.123
+# or
+# Error: $0
+#
+
+function check_parameters(latitude, longitude)
+    {
+    # Ensure the parameters are numbers
+    if ((latitude == (latitude+0)) && (longitude == (longitude+0)))
+        {
+        if (latitude >= -90 && latitude <= 90 &&
+                        longitude >= -180 && longitude <= 180)
+            {
+            return latitude " " longitude
+            }
+        else
+            {
+            return "Error: " latitude " " longitude
+            }
+        }
+    else
+        {
+        return "Error: " latitude " " longitude
+        }
+    }
+
+# This awk file is accessed by the decode_geo_parameters() function
+# in search.c. The call is of the format:
+# echo "string_to_be_searched" | awk -f geocode-parameters.awk
+#
+# Search the input string for known formats.
+{
+if (index($0, "http://www.geonames.org/maps/google_"))
+    {
+    # This is a drag-and-drop or copy-paste from a geonames.org search
+    # in the format e.g.
+    # http://www.geonames.org/maps/google_51.513_-0.092.html
+
+    gsub(/http:\/\/www.geoxxnames.org\/maps\/google_/, "")
+    gsub(/.html/, "")
+    gsub(/_/, " ")
+    print check_parameters($1, $2)
+    }
+
+else if (index($0, "https://www.openstreetmap.org/search?query="))
+    {
+    # This is a copy-paste from an openstreetmap.org search
+    # in the format e.g.
+    # https://www.openstreetmap.org/search?query=51.4878%2C-0.1353#map=11/51.4880/-0.1356
+
+    gsub(/https:\/\/www.openstreetmap.org\/search\?query=/, "")
+    gsub(/#map=.*/, "")
+    gsub(/%2C/, " ")
+    print check_parameters($1, $2)
+    }
+
+else if (index($0, "https://www.openstreetmap.org/#map="))
+    {
+    # This is a copy-paste from an openstreetmap.org search
+    # in the format e.g.
+    # https://www.openstreetmap.org/#map=5/18.271/16.084
+
+    gsub(/https:\/\/www.openstreetmap.org\/#map=[^\/]*/,"")
+    gsub(/\//," ")
+    print check_parameters($1, $2)
+    }
+
+else if (index($0, "https://www.google.com/maps/"))
+    {
+    # This is a copy-paste from a google.com maps search
+    # in the format e.g.
+    # https://www.google.com/maps/place/London,+UK/@51.5283064,-0.3824815,10z/data=....
+
+    gsub(/https:\/\/www.google.com\/maps.*@/,"")
+    sub(/,/," ")
+    gsub(/,.*/,"")
+    print check_parameters($1, $2)
+    }
+
+else if (index($0,".html"))
+    {
+    # This is an unknown html address
+
+    print "Error: " $0
+    }
+
+else if (index($0,"http"))
+    {
+    # This is an unknown html address
+
+    print "Error: " $0
+    }
+
+else if (index($0, ","))
+    {
+    # This is assumed to be a simple lat/long of the format:
+    # 89.123,179.123
+
+    split($0, latlong, ",")
+    print check_parameters(latlong[1], latlong[2])
+    }
+
+else
+    {
+    # This is assumed to be a simple lat/long of the format:
+    # 89.123 179.123
+
+    split($0, latlong, " ")
+    print check_parameters(latlong[1], latlong[2])
+    }
+}
index f0817c1..a06e791 100644 (file)
@@ -130,10 +130,10 @@ gchar *expand_tilde(const gchar *filename)
 #define GEOCODE_NAME "geocode-parameters.awk"
 #define BUFSIZE 128
 
-gchar *decode_geo_parameters(const gchar *input_text)
+gchar *decode_geo_script(const gchar *path_dir, const gchar *input_text)
 {
        gchar *message;
-       gchar *path = g_build_filename(get_rc_dir(), GEOCODE_NAME, NULL);
+       gchar *path = g_build_filename(path_dir, GEOCODE_NAME, NULL);
        gchar *cmd = g_strconcat("echo \'", input_text, "\'  | awk -f ", path, NULL);
 
        if (g_file_test(path, G_FILE_TEST_EXISTS))
@@ -170,6 +170,23 @@ gchar *decode_geo_parameters(const gchar *input_text)
        return message;
 }
 
+gchar *decode_geo_parameters(const gchar *input_text)
+{
+       gchar *message;
+       gchar *dir;
+
+       message = decode_geo_script(GQ_BIN_DIR, input_text);
+       if (strstr(message, "Error"))
+               {
+               g_free(message);
+               dir = g_build_filename(get_rc_dir(), "applications", NULL);
+               message = decode_geo_script(dir, input_text);
+               g_free(dir);
+               }
+
+       return message;
+}
+
 /* Run a command like system() but may output debug messages. */
 int runcmd(gchar *cmd)
 {