[atomix/wip/kill-libxml] Libxml deprecation complete
- From: Robert Roth <robertroth src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [atomix/wip/kill-libxml] Libxml deprecation complete
- Date: Mon, 30 Mar 2015 07:32:56 +0000 (UTC)
commit 25f39fd69cfb08a5c3d15c02cb1a539cbe3abbb8
Author: Robert Roth <robert roth off gmail com>
Date: Mon Mar 30 10:32:22 2015 +0300
Libxml deprecation complete
src/goal.c | 3 -
src/level-manager.c | 99 +++++++++-----------------------------------
src/playfield.c | 64 ++++++-----------------------
src/playfield.h | 4 +-
src/theme-manager.c | 1 +
src/tile.c | 113 +++++++++++++++++++++++++--------------------------
src/tile.h | 12 +-----
7 files changed, 93 insertions(+), 203 deletions(-)
---
diff --git a/src/goal.c b/src/goal.c
index e291b8a..bb2b4a0 100644
--- a/src/goal.c
+++ b/src/goal.c
@@ -17,9 +17,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#include <libxml/parser.h>
-#include <libxml/tree.h>
-
#include "main.h"
#include "theme.h"
#include "goal.h"
diff --git a/src/level-manager.c b/src/level-manager.c
index 8805e7c..4c12bd1 100644
--- a/src/level-manager.c
+++ b/src/level-manager.c
@@ -22,8 +22,6 @@
#include <sys/stat.h>
#include <dirent.h>
#include <fcntl.h>
-#include <libxml/parser.h>
-#include <libxml/tree.h>
#include "level-manager.h"
#include "level-private.h"
@@ -151,15 +149,6 @@ static GMarkupParser sequence_parser =
xml_parser_log_error
};
-static GMarkupParser level_parser =
-{
- level_parser_start_element,
- level_parser_end_element,
- NULL,
- NULL,
- xml_parser_log_error
-};
-
static void create_level_sequence (LevelManager *lm, gchar *file)
{
g_return_if_fail (IS_LEVEL_MANAGER (lm));
@@ -278,7 +267,7 @@ static gchar *lookup_level_name (gchar *filename)
{
gchar *name = NULL;
- Theme *level = NULL;
+ Level *level = NULL;
g_return_val_if_fail (filename != NULL, NULL);
g_return_val_if_fail (g_file_test (filename, G_FILE_TEST_EXISTS), NULL);
@@ -372,18 +361,28 @@ GList *level_manager_get_available_levels (LevelManager *lm)
return list;
}
+/*=================================================================
+
+ Level_Manager level parsing
+
+ ---------------------------------------------------------------*/
+
+static GMarkupParser level_parser =
+{
+ level_parser_start_element,
+ level_parser_end_element,
+ NULL,
+ NULL,
+ xml_parser_log_error
+};
+
static Level *load_level (gchar *filename)
{
- xmlDocPtr doc;
- xmlNodePtr node;
- Level *level = NULL;
- gchar *prop_value;
- // declarations for markup-based-loading
GFile *level_file;
gchar *level_contents;
gsize level_length;
GMarkupParseContext *parse_context;
- Level *level2 = NULL;
+ Level *level = NULL;
g_return_val_if_fail (filename != NULL, NULL);
@@ -396,73 +395,17 @@ static Level *load_level (gchar *filename)
// markup-based loading here
level_file = g_file_new_for_path (filename);
if (g_file_load_contents (level_file, NULL, &level_contents, &level_length, NULL, NULL)) {
- level2 = level_new ();
+ level = level_new ();
parse_context = g_markup_parse_context_new (&level_parser,
G_MARKUP_TREAT_CDATA_AS_TEXT,
- level2,
+ level,
NULL);
g_markup_parse_context_parse (parse_context, level_contents, level_length, NULL);
g_markup_parse_context_unref (parse_context);
g_free (level_contents);
+ level->priv->file_name = g_path_get_basename (filename);
}
- // xml-based loading starts here
- doc = xmlParseFile (filename);
-
- if (doc == NULL)
- {
- g_warning ("XML file %s couldn't be parsed.", filename);
- return NULL;
- }
-
- level = level_new ();
-
- node = doc->xmlRootNode;
-
- while (node != NULL)
- {
- if (!g_ascii_strcasecmp (node->name, "level"))
- {
- prop_value = xmlGetProp (node, "_name");
- level->priv->name = g_strdup (prop_value);
-
- prop_value = xmlGetProp (node, "formula");
- level->priv->formula = g_strdup (prop_value);
-
- node = node->xmlChildrenNode;
- }
- else
- {
- if (!g_ascii_strcasecmp (node->name, "environment"))
- {
- level->priv->environment =
- playfield_new_from_xml (node);
- }
-
- else if (!g_ascii_strcasecmp (node->name, "goal"))
- {
- level->priv->goal =
- playfield_new_from_xml (node);
- }
- else if (!g_ascii_strcasecmp (node->name, "scenario"))
- {
- level->priv->scenario =
- playfield_new_from_xml (node);
- }
- else if (!g_ascii_strcasecmp (node->name, "text"))
- {
- }
- else
- {
- g_message ("Skipping unknown tag %s.", node->name);
- }
-
- node = node->next;
- }
- }
- xmlFreeDoc (doc);
-
- level->priv->file_name = g_path_get_basename (filename);
-
return level;
+
}
diff --git a/src/playfield.c b/src/playfield.c
index 859b057..7942adf 100644
--- a/src/playfield.c
+++ b/src/playfield.c
@@ -23,7 +23,6 @@
Tile *get_tile (PlayField *pf, gint row, gint col);
void set_tile (PlayField *pf, gint row, gint col, Tile *tile);
-static void read_tile (PlayField *pf, guint row, guint col, xmlNodePtr node);
static GObjectClass *parent_class = NULL;
@@ -450,54 +449,6 @@ void playfield_print (PlayField *pf)
g_print ("\n");
}
-PlayField *playfield_new_from_xml (xmlNodePtr node)
-{
- xmlNodePtr child_node;
- PlayField *pf;
- gint row, col;
- gint n_rows, n_cols;
-
- g_return_val_if_fail (node != NULL, NULL);
-
- pf = playfield_new ();
- row = 0;
- col = 0;
-
- n_rows = atoi (xmlGetProp (node, "n_rows"));
- n_cols = atoi (xmlGetProp (node, "n_columns"));
-
- playfield_set_matrix_size (pf, n_rows, n_cols);
-
- /* reading non empty tiles */
- for (child_node = node->xmlChildrenNode;
- child_node != NULL; child_node = child_node->next)
- {
- if (!g_ascii_strcasecmp (child_node->name, "position"))
- {
- row = atoi (xmlGetProp (child_node, "row"));
- col = atoi (xmlGetProp (child_node, "col"));
- read_tile (pf, row, col, child_node->xmlChildrenNode);
- }
- }
-
- return pf;
-}
-
-static void read_tile (PlayField *pf, guint row, guint col, xmlNodePtr node)
-{
- Tile *tile;
-
- for (; node != NULL; node = node->next)
- {
- if (!g_ascii_strcasecmp (node->name, "tile"))
- {
- tile = tile_new_from_xml (node);
- playfield_set_tile (pf, row, col, tile);
- g_object_unref (tile);
- }
- }
-}
-
/*=================================================================
Functions for generating playfields from basic level descriptions.
@@ -817,11 +768,17 @@ PlayField *playfield_generate_shadow (PlayField *pf)
return env_pf;
}
+/*=================================================================
+
+ Functions and structures for parsing playfields from files.
+
+ -----------------------------------------------------------------*/
+
static GMarkupParser tile_parser =
{
tile_parser_start_element,
tile_parser_end_element,
- tile_parser_text,
+ NULL,
NULL,
xml_parser_log_error
};
@@ -844,10 +801,15 @@ position_parser_start_element (GMarkupParseContext *context,
GError **error)
{
Tile *tile = NULL;
+ TileType type = TILE_TYPE_UNKNOWN;
+ gint base_id = 0;
if (!g_strcmp0 (element_name, "tile"))
{
- tile = tile_new (TILE_TYPE_UNKNOWN);
+ type = tile_type_from_string (get_attribute_value ("type", attribute_names, attribute_values));
+ tile = tile_new (type);
+ base_id = g_quark_from_string (get_attribute_value ("base", attribute_names, attribute_values));
+ tile_set_base_id (tile, base_id);
g_markup_parse_context_push (context, &tile_parser, tile);
} else
{
diff --git a/src/playfield.h b/src/playfield.h
index b25c76e..b5f477c 100644
--- a/src/playfield.h
+++ b/src/playfield.h
@@ -20,7 +20,7 @@
#ifndef _ATOMIX_PLAY_FIELD_H
#define _ATOMIX_PLAY_FIELD_H
-#include <libxml/tree.h>
+#include <stdlib.h>
#include "tile.h"
#include "theme.h"
@@ -49,8 +49,6 @@ GType playfield_get_type (void);
PlayField *playfield_new (void);
-PlayField *playfield_new_from_xml (xmlNodePtr node);
-
guint playfield_get_n_rows (PlayField * pf);
guint playfield_get_n_cols (PlayField * pf);
diff --git a/src/theme-manager.c b/src/theme-manager.c
index 78bb497..2ebb787 100644
--- a/src/theme-manager.c
+++ b/src/theme-manager.c
@@ -20,6 +20,7 @@
#include <glib/gi18n.h>
#include <glib.h>
+#include <stdlib.h>
#include "theme-manager.h"
#include "theme-private.h"
diff --git a/src/tile.c b/src/tile.c
index 770ae91..a6d3536 100644
--- a/src/tile.c
+++ b/src/tile.c
@@ -17,10 +17,11 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#include "tile.h"
-
#include <string.h>
+#include "tile.h"
+#include "xml-util.h"
+
#define GPOINTER_TO_QUARK(p) ((GQuark) (p))
#define GQUARK_TO_POINTER(p) ((gpointer) (p))
@@ -279,11 +280,11 @@ void tile_print (Tile *tile)
/*=================================================================
- Tile load/save functions
+ Tile load/parse functions
---------------------------------------------------------------*/
-static TileType string_to_tile_type (gchar *str)
+TileType tile_type_from_string (const gchar *str)
{
TileType tile_type = TILE_TYPE_UNKNOWN;
static int prefix_len = 0;
@@ -310,51 +311,32 @@ static TileType string_to_tile_type (gchar *str)
return tile_type;
}
-Tile *tile_new_from_xml (xmlNodePtr node)
+typedef struct
{
- xmlNodePtr child;
- Tile *tile = NULL;
- TileType type;
- GQuark base_id;
- GQuark sub_id;
- gchar *content;
-
- g_return_val_if_fail (node != NULL, NULL);
- g_return_val_if_fail (!g_ascii_strcasecmp (node->name, "tile"), NULL);
-
- type = string_to_tile_type (xmlGetProp (node, "type"));
- tile = tile_new (type);
- base_id = g_quark_from_string (xmlGetProp (node, "base"));
- tile_set_base_id (tile, base_id);
-
- for (child = node->xmlChildrenNode; child != NULL; child = child->next)
- {
- if (!g_ascii_strcasecmp (child->name, "underlay"))
- {
- g_assert (tile != NULL);
- content = xmlNodeGetContent (child);
- sub_id = g_quark_from_string (content);
- tile_add_sub_id (tile, sub_id, TILE_SUB_UNDERLAY);
- }
- else if (!g_ascii_strcasecmp (child->name, "overlay"))
- {
- g_assert (tile != NULL);
- content = xmlNodeGetContent (child);
- base_id = g_quark_from_string (content);
- tile_add_sub_id (tile, base_id, TILE_SUB_OVERLAY);
- }
- else if (!g_ascii_strcasecmp (child->name, "text"))
- {
- }
- else
- {
- g_warning ("Skipping unknown tag: %s.", child->name);
- }
- }
-
- return tile;
+ gchar* text;
+} TextData;
+
+static void
+single_tag_parser_text (GMarkupParseContext *context,
+ const gchar *text,
+ gsize text_len,
+ gpointer user_data,
+ GError **error)
+{
+// printf ("tile: text %s\n", text);
+ TextData *text_data = user_data;
+ text_data->text = g_strdup(text);
}
+static GMarkupParser text_parser =
+{
+ NULL,
+ NULL,
+ single_tag_parser_text,
+ NULL,
+ xml_parser_log_error
+};
+
void
tile_parser_start_element (GMarkupParseContext *context,
const gchar *element_name,
@@ -363,17 +345,15 @@ tile_parser_start_element (GMarkupParseContext *context,
gpointer user_data,
GError **error)
{
-// printf ("tile: text %s\n", element_name);
-}
-
-void
-tile_parser_text (GMarkupParseContext *context,
- const gchar *text,
- gsize text_len,
- gpointer user_data,
- GError **error)
-{
-// printf ("tile: text %s\n", text);
+ TextData *text_data = NULL;
+
+ if (!g_strcmp0 (element_name, "underlay") ||
+ !g_strcmp0 (element_name, "overlay"))
+ {
+ text_data = g_slice_new (TextData);
+ g_markup_parse_context_push(context, &text_parser, text_data);
+ } else
+ g_print ("tile: starting %s\n", element_name);
}
void
@@ -382,5 +362,22 @@ tile_parser_end_element (GMarkupParseContext *context,
gpointer user_data,
GError **error)
{
-// printf ("tile: ending %s\n", element_name);
+ TextData *text_data;
+ GQuark sub_id;
+ Tile *tile = user_data;
+
+ if (!g_strcmp0 (element_name, "underlay") ||
+ !g_strcmp0 (element_name, "overlay"))
+ {
+ text_data = g_markup_parse_context_pop (context);
+ sub_id = g_quark_from_string (text_data->text);
+ g_free (text_data->text);
+ g_slice_free (TextData, text_data);
+
+ if (!g_strcmp0 (element_name, "underlay"))
+ tile_add_sub_id (tile, sub_id, TILE_SUB_UNDERLAY);
+ else
+ tile_add_sub_id (tile, sub_id, TILE_SUB_OVERLAY);
+ } else
+ g_print ("tile: ending %s\n", element_name);
}
diff --git a/src/tile.h b/src/tile.h
index 8166625..856f941 100644
--- a/src/tile.h
+++ b/src/tile.h
@@ -21,7 +21,6 @@
#define _TILE_H_
#include <glib-object.h>
-#include <libxml/tree.h>
#define TILE_TYPE (tile_get_type ())
#define TILE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TILE_TYPE, Tile))
@@ -64,8 +63,6 @@ GType tile_get_type (void);
Tile *tile_new (TileType type);
-Tile *tile_new_from_xml (xmlNodePtr node);
-
Tile *tile_copy (Tile * tile);
GSList *tile_get_sub_ids (Tile * tile, TileSubType sub_type);
@@ -88,6 +85,8 @@ void tile_print (Tile * tile);
gboolean tile_is_equal (Tile * tile, Tile * comp);
+TileType tile_type_from_string (const gchar *str);
+
void
tile_parser_start_element (GMarkupParseContext *context,
const gchar *element_name,
@@ -97,13 +96,6 @@ tile_parser_start_element (GMarkupParseContext *context,
GError **error);
void
-tile_parser_text (GMarkupParseContext *context,
- const gchar *text,
- gsize text_len,
- gpointer user_data,
- GError **error);
-
-void
tile_parser_end_element (GMarkupParseContext *context,
const gchar *element_name,
gpointer user_data,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]