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.
This commit is contained in:
Benjamin Otte 2012-04-18 19:43:24 +02:00
parent a65780902a
commit e1317268a3
5 changed files with 52 additions and 9 deletions

View File

@ -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;

View File

@ -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;

View 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,

View File

@ -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)

View File

@ -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;