Commit e1317268 authored by Benjamin Otte's avatar Benjamin Otte

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.
parent a6578090
......@@ -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;
......
......@@ -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;
......
......@@ -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,
......
......@@ -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)
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment