aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClaudio Saavedra <csaavedra@igalia.com>2011-06-08 19:28:10 +0800
committerClaudio Saavedra <csaavedra@igalia.com>2011-06-09 00:24:01 +0800
commit82088320c652f34543c82b790adf82019320d5a4 (patch)
tree92bc124c04be56d4c6733f7ef52b8b978fa3da59
parent99193c87cd59cf1d913c7b9840148956d619c91c (diff)
downloadgsoc2013-epiphany-82088320c652f34543c82b790adf82019320d5a4.tar
gsoc2013-epiphany-82088320c652f34543c82b790adf82019320d5a4.tar.gz
gsoc2013-epiphany-82088320c652f34543c82b790adf82019320d5a4.tar.bz2
gsoc2013-epiphany-82088320c652f34543c82b790adf82019320d5a4.tar.lz
gsoc2013-epiphany-82088320c652f34543c82b790adf82019320d5a4.tar.xz
gsoc2013-epiphany-82088320c652f34543c82b790adf82019320d5a4.tar.zst
gsoc2013-epiphany-82088320c652f34543c82b790adf82019320d5a4.zip
Add ephy_string_commandline_args_to_uris() to ephy string utilities
This is the first patch in an attempt to simplify epiphany's main() method, which is quite bulky by now. https://bugzilla.gnome.org/show_bug.cgi?id=652119
-rw-r--r--lib/ephy-string.c71
-rw-r--r--lib/ephy-string.h3
-rw-r--r--src/ephy-main.c68
3 files changed, 86 insertions, 56 deletions
diff --git a/lib/ephy-string.c b/lib/ephy-string.c
index 0b07dc794..72aa582be 100644
--- a/lib/ephy-string.c
+++ b/lib/ephy-string.c
@@ -497,3 +497,74 @@ ephy_string_expand_initial_tilde (const char *path)
slash_after_user_name,
NULL);
}
+
+/**
+ * ephy_string_commandline_args_to_uris:
+ * @arguments: a %NULL-terminated array of chars.
+ *
+ * Transform commandline arguments to URIs if they exist,
+ * otherwise simply transform them to UTF-8.
+ *
+ * Returns: a newly allocated array with the URIs and
+ * UTF-8 strings.
+ **/
+char **
+ephy_string_commandline_args_to_uris (char **arguments, GError **error)
+{
+ gchar **args;
+ guint i;
+
+ if (arguments == NULL)
+ return NULL;
+
+ args = g_malloc0 (sizeof (gchar *) * (g_strv_length (arguments) + 1));
+
+ for (i = 0; arguments[i] != NULL; ++i)
+ {
+ char *uri, *path;
+#ifdef PATH_MAX
+ char rpath[PATH_MAX];
+#else
+ char *rpath = NULL;
+#endif
+
+ path = realpath (arguments[i], rpath);
+ if (path != NULL)
+ {
+ uri = g_locale_to_utf8 (path, -1,
+ NULL, NULL, error);
+#ifndef PATH_MAX
+ free (path);
+#endif
+ }
+ else
+ {
+ uri = g_locale_to_utf8 (arguments[i], -1,
+ NULL, NULL, error);
+ }
+
+ if (uri != NULL)
+ {
+ /* If it's a file, use g_file_new_for_commandline_arg,
+ * so we get the right escaping.
+ */
+ if (path != NULL)
+ {
+ GFile *file;
+ file = g_file_new_for_commandline_arg (uri);
+ args[i] = g_file_get_uri (file);
+ g_object_unref (file);
+ g_free (uri);
+ }
+ else
+ {
+ args[i] = uri;
+ }
+ } else {
+ g_strfreev (args);
+ return NULL;
+ }
+ }
+
+ return args;
+}
diff --git a/lib/ephy-string.h b/lib/ephy-string.h
index d825a5b82..1f5f98659 100644
--- a/lib/ephy-string.h
+++ b/lib/ephy-string.h
@@ -58,6 +58,9 @@ char *ephy_string_get_host_name (const char *url);
char *ephy_string_expand_initial_tilde (const char *path);
+char **ephy_string_commandline_args_to_uris (char **arguments, GError **error);
+
+
G_END_DECLS
#endif
diff --git a/src/ephy-main.c b/src/ephy-main.c
index f59ab23f9..5e1a8428b 100644
--- a/src/ephy-main.c
+++ b/src/ephy-main.c
@@ -34,6 +34,7 @@
#include "ephy-prefs.h"
#include "ephy-profile-utils.h"
#include "ephy-debug.h"
+#include "ephy-string.h"
#include "eggsmclient.h"
#include <libxml/xmlversion.h>
@@ -578,63 +579,18 @@ main (int argc,
exit (1);
}
- /* Make URIs from arguments, to support filename args */
- if (arguments != NULL)
- {
- guint i;
-
- for (i = 0; arguments[i] != NULL; ++i)
- {
- char *uri, *path;
-#ifdef PATH_MAX
- char rpath[PATH_MAX];
-#else
- char *rpath = NULL;
-#endif
-
- path = realpath (arguments[i], rpath);
- if (path != NULL)
- {
- uri = g_locale_to_utf8 (path, -1,
- NULL, NULL, &error);
-#ifndef PATH_MAX
- free (path);
-#endif
- }
- else
- {
- uri = g_locale_to_utf8 (arguments[i], -1,
- NULL, NULL, &error);
- }
-
- if (uri != NULL)
- {
- g_free (arguments[i]);
-
- /* If it's a file, use g_file_new_for_commandline_arg,
- * so we get the right escaping.
- */
- if (path != NULL)
- {
- GFile *file;
- file = g_file_new_for_commandline_arg (uri);
- arguments[i] = g_file_get_uri (file);
- g_object_unref (file);
- g_free (uri);
- }
- else
- {
- arguments[i] = uri;
- }
- }
- else
- {
- g_print ("Could not convert '%s' to UTF-8: %s!\n",
- arguments[i], error->message);
- g_error_free (error);
- exit (1);
- }
+ /* convert arguments to uris or at least to utf8 */
+ if (arguments != NULL) {
+ char **args = ephy_string_commandline_args_to_uris (arguments,
+ &error);
+ if (error) {
+ g_print ("Could not convert to UTF-8: %s!\n",
+ error->message);
+ g_error_free (error);
+ exit (1);
}
+ g_strfreev (arguments);
+ arguments = args;
}
/* Get a timestamp manually if need be */