[gtk+] cssparser: Change APIs that work with files
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] cssparser: Change APIs that work with files
- Date: Fri, 11 May 2012 14:44:47 +0000 (UTC)
commit e1317268a338589fd6fa01c303569cdc111b3f5e
Author: Benjamin Otte <otte redhat com>
Date: Wed Apr 18 19:43:24 2012 +0200
cssparser: Change APIs that work with files
Now that we keep track of the parser's file, we don't require it to be
passed anymore.
gtk/gtkcssimageurl.c | 2 +-
gtk/gtkcssparser.c | 48 ++++++++++++++++++++++++++++++++++++++++++--
gtk/gtkcssparserprivate.h | 6 +++-
gtk/gtkcssprovider.c | 3 +-
gtk/gtkcssstylefuncs.c | 2 +-
5 files changed, 52 insertions(+), 9 deletions(-)
---
diff --git a/gtk/gtkcssimageurl.c b/gtk/gtkcssimageurl.c
index 8fa2965..b12d8c5 100644
--- a/gtk/gtkcssimageurl.c
+++ b/gtk/gtkcssimageurl.c
@@ -72,7 +72,7 @@ gtk_css_image_url_parse (GtkCssImage *image,
GError *error = NULL;
GFileInputStream *input;
- file = _gtk_css_parser_read_url (parser, base);
+ file = _gtk_css_parser_read_url (parser);
if (file == NULL)
return FALSE;
diff --git a/gtk/gtkcssparser.c b/gtk/gtkcssparser.c
index 7d3fa95..bedfdec 100644
--- a/gtk/gtkcssparser.c
+++ b/gtk/gtkcssparser.c
@@ -125,6 +125,49 @@ _gtk_css_parser_get_position (GtkCssParser *parser)
return parser->data - parser->line_start;
}
+static GFile *
+gtk_css_parser_get_base_file (GtkCssParser *parser)
+{
+ GFile *base;
+
+ if (parser->file)
+ {
+ base = g_file_get_parent (parser->file);
+ }
+ else
+ {
+ char *dir = g_get_current_dir ();
+ base = g_file_new_for_path (dir);
+ g_free (dir);
+ }
+
+ return base;
+}
+
+GFile *
+_gtk_css_parser_get_file_for_path (GtkCssParser *parser,
+ const char *path)
+{
+ GFile *base, *file;
+
+ g_return_val_if_fail (parser != NULL, NULL);
+ g_return_val_if_fail (path != NULL, NULL);
+
+ base = gtk_css_parser_get_base_file (parser);
+ file = g_file_resolve_relative_path (base, path);
+ g_object_unref (base);
+
+ return file;
+}
+
+GFile *
+_gtk_css_parser_get_file (GtkCssParser *parser)
+{
+ g_return_val_if_fail (parser != NULL, NULL);
+
+ return parser->file;
+}
+
void
_gtk_css_parser_take_error (GtkCssParser *parser,
GError *error)
@@ -781,8 +824,7 @@ _gtk_css_parser_try_hash_color (GtkCssParser *parser,
}
GFile *
-_gtk_css_parser_read_url (GtkCssParser *parser,
- GFile *base)
+_gtk_css_parser_read_url (GtkCssParser *parser)
{
gchar *path;
char *scheme;
@@ -836,7 +878,7 @@ _gtk_css_parser_read_url (GtkCssParser *parser,
}
}
- file = g_file_resolve_relative_path (base, path);
+ file = _gtk_css_parser_get_file_for_path (parser, path);
g_free (path);
return file;
diff --git a/gtk/gtkcssparserprivate.h b/gtk/gtkcssparserprivate.h
index 8609531..3c6f3ba 100644
--- a/gtk/gtkcssparserprivate.h
+++ b/gtk/gtkcssparserprivate.h
@@ -47,6 +47,9 @@ void _gtk_css_parser_error_full (GtkCssParser *parser
guint _gtk_css_parser_get_line (GtkCssParser *parser);
guint _gtk_css_parser_get_position (GtkCssParser *parser);
+GFile * _gtk_css_parser_get_file (GtkCssParser *parser);
+GFile * _gtk_css_parser_get_file_for_path (GtkCssParser *parser,
+ const char *path);
gboolean _gtk_css_parser_is_eof (GtkCssParser *parser);
gboolean _gtk_css_parser_begins_with (GtkCssParser *parser,
@@ -87,8 +90,7 @@ gboolean _gtk_css_parser_try_hash_color (GtkCssParser *parser
gboolean _gtk_css_parser_has_number (GtkCssParser *parser);
char * _gtk_css_parser_read_string (GtkCssParser *parser);
char * _gtk_css_parser_read_value (GtkCssParser *parser);
-GFile * _gtk_css_parser_read_url (GtkCssParser *parser,
- GFile *base);
+GFile * _gtk_css_parser_read_url (GtkCssParser *parser);
void _gtk_css_parser_skip_whitespace (GtkCssParser *parser);
void _gtk_css_parser_resync (GtkCssParser *parser,
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index 6ed7dde..31bf889 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -1899,8 +1899,7 @@ parse_import (GtkCssScanner *scanner)
}
else
{
- file = _gtk_css_parser_read_url (scanner->parser,
- gtk_css_scanner_get_base_url (scanner));
+ file = _gtk_css_parser_read_url (scanner->parser);
}
if (file == NULL)
diff --git a/gtk/gtkcssstylefuncs.c b/gtk/gtkcssstylefuncs.c
index 7456442..538079d 100644
--- a/gtk/gtkcssstylefuncs.c
+++ b/gtk/gtkcssstylefuncs.c
@@ -725,7 +725,7 @@ pattern_value_parse (GtkCssParser *parser,
cairo_t *cr;
cairo_matrix_t matrix;
- file = _gtk_css_parser_read_url (parser, base);
+ file = _gtk_css_parser_read_url (parser);
if (file == NULL)
return FALSE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]