aboutsummaryrefslogtreecommitdiffstats
path: root/lib/xmltree.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/xmltree.c')
-rw-r--r--lib/xmltree.c50
1 files changed, 42 insertions, 8 deletions
diff --git a/lib/xmltree.c b/lib/xmltree.c
index b0a945ce..5fd43014 100644
--- a/lib/xmltree.c
+++ b/lib/xmltree.c
@@ -140,7 +140,7 @@ void xt_reset( struct xt_parser *xt )
/* Feed the parser, don't execute any handler. Returns -1 on errors, 0 on
end-of-stream and 1 otherwise. */
-int xt_feed( struct xt_parser *xt, char *text, int text_len )
+int xt_feed( struct xt_parser *xt, const char *text, int text_len )
{
if( !g_markup_parse_context_parse( xt->parser, text, text_len, &xt->gerr ) )
{
@@ -173,20 +173,20 @@ int xt_handle( struct xt_parser *xt, struct xt_node *node, int depth )
if( node->flags & XT_COMPLETE && !( node->flags & XT_SEEN ) )
{
- for( i = 0; xt->handlers[i].func; i ++ )
+ if( xt->handlers ) for( i = 0; xt->handlers[i].func; i ++ )
{
/* This one is fun! \o/ */
- /* If handler.name == NULL it means it should always match. */
+ /* If handler.name == NULL it means it should always match. */
if( ( xt->handlers[i].name == NULL ||
- /* If it's not, compare. There should always be a name. */
+ /* If it's not, compare. There should always be a name. */
g_strcasecmp( xt->handlers[i].name, node->name ) == 0 ) &&
- /* If handler.parent == NULL, it's a match. */
+ /* If handler.parent == NULL, it's a match. */
( xt->handlers[i].parent == NULL ||
- /* If there's a parent node, see if the name matches. */
+ /* If there's a parent node, see if the name matches. */
( node->parent ? g_strcasecmp( xt->handlers[i].parent, node->parent->name ) == 0 :
- /* If there's no parent, the handler should mention <root> as a parent. */
- g_strcasecmp( xt->handlers[i].parent, "<root>" ) == 0 ) ) )
+ /* If there's no parent, the handler should mention <root> as a parent. */
+ strcmp( xt->handlers[i].parent, "<root>" ) == 0 ) ) )
{
st = xt->handlers[i].func( node, xt->data );
@@ -259,6 +259,20 @@ void xt_cleanup( struct xt_parser *xt, struct xt_node *node, int depth )
}
}
+struct xt_node *xt_from_string( const char *in )
+{
+ struct xt_parser *parser;
+ struct xt_node *ret;
+
+ parser = xt_new( NULL, NULL );
+ xt_feed( parser, in, strlen( in ) );
+ ret = parser->root;
+ parser->root = NULL;
+ xt_free( parser );
+
+ return ret;
+}
+
static void xt_to_string_real( struct xt_node *node, GString *str )
{
char *buf;
@@ -549,6 +563,26 @@ void xt_add_child( struct xt_node *parent, struct xt_node *child )
}
}
+/* Same, but at the beginning. */
+void xt_insert_child( struct xt_node *parent, struct xt_node *child )
+{
+ struct xt_node *node, *last;
+
+ for( node = child; node; node = node->next )
+ {
+ if( node->parent != NULL )
+ {
+ /* ERROR CONDITION: They seem to have a parent already??? */
+ }
+
+ node->parent = parent;
+ last = node;
+ }
+
+ last->next = parent->children;
+ parent->children = child;
+}
+
void xt_add_attr( struct xt_node *node, const char *key, const char *value )
{
int i;