]> git.street.me.uk Git - andy/viking.git/blobdiff - src/util.c
SF#3608411: Part 1 - Avoid warning about unbuffer on Windows Systems.
[andy/viking.git] / src / util.c
index 079ccc9c9e61fb4509b3aeeef5b9af6cfd9b9d1c..92457b82526049bd3e44c22050a0a29a38300179 100644 (file)
@@ -1,8 +1,8 @@
 /*
  *    Viking - GPS data editor
- *    Copyright (C) 2007 Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
+ *    Copyright (C) 2007, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
  *    Based on:
- *    Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@linuxmag.com.br>
+ *    Copyright (C) 2003-2007, Leandro A. F. Pereira <leandro@linuxmag.com.br>
  *
  *    This program is free software; you can redistribute it and/or modify
  *    it under the terms of the GNU General Public License as published by
 #endif
 
 #include <glib/gi18n.h>
+#include <glib/gprintf.h>
 
+#include "util.h"
 #include "dialog.h"
 
+#ifndef WINDOWS
 static gboolean spawn_command_line_async(const gchar * cmd,
                                          const gchar * arg)
 {
@@ -42,7 +45,9 @@ static gboolean spawn_command_line_async(const gchar * cmd,
 
   g_free(cmdline);
  
+  return status;
 }
+#endif
 
 void open_url(GtkWindow *parent, const gchar * url)
 {
@@ -54,6 +59,8 @@ void open_url(GtkWindow *parent, const gchar * url)
     "sensible-browser", "firefox", "epiphany",
     "iceweasel", "seamonkey", "galeon", "mozilla",
     "opera", "konqueror", "netscape", "links -g",
+    "chromium-browser", "chromium", "chrome",
+    "safari", "camino", "omniweb", "icab",
     NULL
   };
   gint i=0;
@@ -87,3 +94,80 @@ void new_email(GtkWindow *parent, const gchar * address)
   g_free(uri);
   uri = NULL;
 }
+
+gchar *uri_escape(gchar *str)
+{
+  gchar *esc_str = g_malloc(3*strlen(str));
+  gchar *dst = esc_str;
+  gchar *src;
+
+  for (src = str; *src; src++) {
+    if (*src == ' ')
+     *dst++ = '+';
+    else if (g_ascii_isalnum(*src))
+     *dst++ = *src;
+    else {
+      g_sprintf(dst, "%%%02hhX", *src);
+      dst += 3;
+    }
+  }
+  *dst = '\0';
+
+  return(esc_str);
+}
+
+
+GList * str_array_to_glist(gchar* data[])
+{
+  GList *gl = NULL;
+  gpointer * p;
+  for (p = (gpointer)data; *p; p++)
+    gl = g_list_prepend(gl, *p);
+  return g_list_reverse(gl);
+}
+
+/**
+ * split_string_from_file_on_equals:
+ *
+ * @buf: the input string
+ * @key: newly allocated string that is before the '='
+ * @val: newly allocated string after the '='
+ *
+ * Designed for file line processing, so it ignores strings beginning with special
+ *  characters, such as '#'; returns false in such situations.
+ * Also returns false if no equals character is found
+ *
+ * e.g. if buf = "GPS.parameter=42"
+ *   key = "GPS.parameter"
+ *   val = "42"
+ */
+gboolean split_string_from_file_on_equals ( const gchar *buf, gchar **key, gchar **val )
+{
+  // comments, special characters in viking file format
+  if ( buf == NULL || buf[0] == '\0' || buf[0] == '~' || buf[0] == '=' || buf[0] == '#' )
+    return FALSE;
+
+  if ( ! strchr ( buf, '=' ) )
+    return FALSE;
+
+  gchar **strv = g_strsplit ( buf, "=", 2 );
+
+  gint gi = 0;
+  gchar *str = strv[gi];
+  while ( str ) {
+       if ( gi == 0 )
+         *key = g_strdup ( str );
+       else
+         *val = g_strdup ( str );
+    gi++;
+    str = strv[gi];
+  }
+
+  g_strfreev ( strv );
+
+  // Remove newline from val and also any other whitespace
+  *key = g_strstrip ( *key );
+  *val = g_strstrip ( *val );
+
+  return TRUE;
+}