[gtk+/gtk-style-context: 244/533] GtkCssProvider: improve file paths parser.
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gtk-style-context: 244/533] GtkCssProvider: improve file paths parser.
- Date: Wed, 1 Dec 2010 02:26:19 +0000 (UTC)
commit c4411ae5f3d15e85d3716b5d3810886a4ded46c3
Author: Carlos Garnacho <carlosg gnome org>
Date: Fri Oct 8 18:27:22 2010 +0200
GtkCssProvider: improve file paths parser.
It will now return a full path, and check about the file being sane.
gtk/gtkcssprovider.c | 72 ++++++++++++++++++++++++++++++++++++--------------
1 files changed, 52 insertions(+), 20 deletions(-)
---
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index 2dd42c0..36ef361 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -1571,8 +1571,9 @@ gradient_parse (const gchar *str)
}
static gchar *
-url_parse_str (const gchar *str,
- gchar **end_ptr)
+path_parse_str (GtkCssProvider *css_provider,
+ const gchar *str,
+ gchar **end_ptr)
{
gchar *path, *chr;
@@ -1607,6 +1608,54 @@ url_parse_str (const gchar *str,
*end_ptr = chr + 1;
+ /* Always return an absolute path */
+ if (!g_path_is_absolute (path))
+ {
+ GtkCssProviderPrivate *priv;
+ gchar *dirname, *full_path;
+
+ priv = css_provider->priv;
+
+ /* Use relative path to the current CSS file path, if any */
+ dirname = g_path_get_dirname (priv->filename);
+
+ full_path = g_build_filename (dirname, path, NULL);
+ g_free (path);
+ g_free (dirname);
+
+ path = full_path;
+ }
+
+ if (!g_file_test (path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR))
+ {
+ g_warning ("File doesn't exist: %s\n", path);
+ g_free (path);
+ path = NULL;
+ }
+
+ return path;
+}
+
+static gchar *
+path_parse (GtkCssProvider *css_provider,
+ const gchar *str)
+{
+ gchar *path, *end;
+
+ path = path_parse_str (css_provider, str, &end);
+
+ if (*end != '\0')
+ {
+ g_warning ("Error parsing file path \"%s\", stopped at char %ld : '%c'",
+ str, end - str, *end);
+
+ if (path)
+ {
+ g_free (path);
+ path = NULL;
+ }
+ }
+
return path;
}
@@ -1627,28 +1676,11 @@ slice_parse_str (GtkCssProvider *css_provider,
SKIP_SPACES (str);
/* Parse image url */
- path = url_parse_str (str, end_ptr);
+ path = path_parse_str (css_provider, str, end_ptr);
if (!path)
return NULL;
- if (!g_path_is_absolute (path))
- {
- GtkCssProviderPrivate *priv;
- gchar *dirname, *full_path;
-
- priv = css_provider->priv;
-
- /* Use relative path to the current CSS file path, if any */
- dirname = g_path_get_dirname (priv->filename);
-
- full_path = g_build_filename (dirname, path, NULL);
- g_free (path);
- g_free (dirname);
-
- path = full_path;
- }
-
str = *end_ptr;
SKIP_SPACES (str);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]