2001-03-04 05:09:23 -06:00
|
|
|
/********************************************************************
|
|
|
|
* sixtp-stack.c *
|
|
|
|
* Copyright 2001 Gnumatic, Inc. *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License as *
|
|
|
|
* published by the Free Software Foundation; either version 2 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License*
|
|
|
|
* along with this program; if not, contact: *
|
|
|
|
* *
|
|
|
|
* Free Software Foundation Voice: +1-617-542-5942 *
|
2005-11-16 23:35:02 -06:00
|
|
|
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
|
|
|
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
2001-03-04 05:09:23 -06:00
|
|
|
* *
|
|
|
|
********************************************************************/
|
2015-11-29 19:11:29 -06:00
|
|
|
extern "C"
|
|
|
|
{
|
2017-10-26 04:14:21 -05:00
|
|
|
#include <config.h>
|
2015-11-29 19:11:29 -06:00
|
|
|
}
|
2001-01-24 01:18:17 -06:00
|
|
|
#include "sixtp.h"
|
|
|
|
#include "sixtp-stack.h"
|
|
|
|
|
|
|
|
void
|
2016-03-12 16:04:40 -06:00
|
|
|
sixtp_stack_frame_destroy (sixtp_stack_frame* sf)
|
2001-12-30 11:25:30 -06:00
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
GSList* lp;
|
2001-01-24 01:18:17 -06:00
|
|
|
|
2009-12-29 14:12:48 -06:00
|
|
|
/* cleanup all the child data */
|
|
|
|
for (lp = sf->data_from_children; lp; lp = lp->next)
|
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
sixtp_child_result_destroy ((sixtp_child_result*) lp->data);
|
2009-12-29 14:12:48 -06:00
|
|
|
}
|
2016-03-12 16:04:40 -06:00
|
|
|
g_slist_free (sf->data_from_children);
|
2009-12-29 14:12:48 -06:00
|
|
|
sf->data_from_children = NULL;
|
2001-01-24 01:18:17 -06:00
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
g_free (sf);
|
2001-01-24 01:18:17 -06:00
|
|
|
}
|
|
|
|
|
2001-02-07 22:08:50 -06:00
|
|
|
sixtp_stack_frame*
|
2016-03-12 16:04:40 -06:00
|
|
|
sixtp_stack_frame_new (sixtp* next_parser, char* tag)
|
2001-02-07 22:08:50 -06:00
|
|
|
{
|
|
|
|
sixtp_stack_frame* new_frame;
|
2009-12-29 14:12:48 -06:00
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
new_frame = g_new0 (sixtp_stack_frame, 1);
|
2001-02-07 22:08:50 -06:00
|
|
|
new_frame->parser = next_parser;
|
|
|
|
new_frame->tag = tag;
|
|
|
|
new_frame->data_for_children = NULL;
|
|
|
|
new_frame->data_from_children = NULL;
|
|
|
|
new_frame->frame_data = NULL;
|
2002-04-21 12:55:49 -05:00
|
|
|
new_frame->line = new_frame->col = -1;
|
2001-02-07 22:08:50 -06:00
|
|
|
|
|
|
|
return new_frame;
|
|
|
|
}
|
|
|
|
|
2001-01-24 01:18:17 -06:00
|
|
|
void
|
2016-03-12 16:04:40 -06:00
|
|
|
sixtp_stack_frame_print (sixtp_stack_frame* sf, gint indent, FILE* f)
|
2001-12-30 11:25:30 -06:00
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
gchar* is = g_strnfill (indent, ' ');
|
2001-01-24 01:18:17 -06:00
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
fprintf (f, "%s(stack-frame %p\n", is, sf);
|
|
|
|
fprintf (f, "%s (line %d) (col %d)\n", is, sf->line, sf->col);
|
|
|
|
fprintf (f, "%s (parser %p)\n", is, sf->parser);
|
|
|
|
fprintf (f, "%s (tag %s)\n", is, sf->tag ? sf->tag : "(null)");
|
|
|
|
fprintf (f, "%s (data-for-children %p)\n", is,
|
|
|
|
sf->data_for_children);
|
2001-01-24 01:18:17 -06:00
|
|
|
|
2001-12-30 11:25:30 -06:00
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
GSList* lp;
|
|
|
|
fprintf (f, "%s (data-from-children", is);
|
2009-12-29 14:12:48 -06:00
|
|
|
for (lp = sf->data_from_children; lp; lp = lp->next)
|
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
fputc (' ', f);
|
|
|
|
sixtp_child_result_print ((sixtp_child_result*) lp->data, f);
|
2009-12-29 14:12:48 -06:00
|
|
|
}
|
2016-03-12 16:04:40 -06:00
|
|
|
fprintf (f, ")\n");
|
2001-01-24 01:18:17 -06:00
|
|
|
}
|
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
fprintf (f, "%s (frame-data %p))\n", is, sf->frame_data);
|
|
|
|
fflush (f);
|
|
|
|
g_free (is);
|
2001-01-24 01:18:17 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
GSList*
|
2016-03-12 16:04:40 -06:00
|
|
|
sixtp_pop_and_destroy_frame (GSList* frame_stack)
|
2001-12-30 11:25:30 -06:00
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
sixtp_stack_frame* dead_frame = (sixtp_stack_frame*) frame_stack->data;
|
2009-12-29 14:12:48 -06:00
|
|
|
GSList* result;
|
2001-01-24 01:18:17 -06:00
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
result = g_slist_next (frame_stack);
|
|
|
|
sixtp_stack_frame_destroy (dead_frame);
|
|
|
|
g_slist_free_1 (frame_stack);
|
|
|
|
return (result);
|
2001-01-24 01:18:17 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-03-12 16:04:40 -06:00
|
|
|
sixtp_print_frame_stack (GSList* stack, FILE* f)
|
2001-12-30 11:25:30 -06:00
|
|
|
{
|
2009-12-29 14:12:48 -06:00
|
|
|
/* first, some debugging output */
|
2016-03-12 16:04:40 -06:00
|
|
|
GSList* printcopy = g_slist_reverse (g_slist_copy (stack));
|
|
|
|
GSList* lp;
|
2009-12-29 14:12:48 -06:00
|
|
|
int indent = 0;
|
|
|
|
|
|
|
|
for (lp = printcopy; lp; lp = lp->next)
|
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
sixtp_stack_frame* frame = (sixtp_stack_frame*) lp->data;
|
|
|
|
sixtp_stack_frame_print (frame, indent, f);
|
2009-12-29 14:12:48 -06:00
|
|
|
indent += 2;
|
|
|
|
}
|
2001-01-24 01:18:17 -06:00
|
|
|
|
|
|
|
}
|
2001-02-07 22:08:50 -06:00
|
|
|
|
|
|
|
|
|
|
|
/* Parser context */
|
|
|
|
sixtp_parser_context*
|
2016-03-12 16:04:40 -06:00
|
|
|
sixtp_context_new (sixtp* initial_parser, gpointer global_data,
|
|
|
|
gpointer top_level_data)
|
2001-02-07 22:08:50 -06:00
|
|
|
{
|
|
|
|
sixtp_parser_context* ret;
|
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
ret = g_new0 (sixtp_parser_context, 1);
|
2001-02-07 22:08:50 -06:00
|
|
|
|
|
|
|
ret->handler.startElement = sixtp_sax_start_handler;
|
|
|
|
ret->handler.endElement = sixtp_sax_end_handler;
|
|
|
|
ret->handler.characters = sixtp_sax_characters_handler;
|
|
|
|
ret->handler.getEntity = sixtp_sax_get_entity_handler;
|
|
|
|
|
|
|
|
ret->data.parsing_ok = TRUE;
|
|
|
|
ret->data.stack = NULL;
|
|
|
|
ret->data.global_data = global_data;
|
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
ret->top_frame = sixtp_stack_frame_new (initial_parser, NULL);
|
2009-12-29 14:12:48 -06:00
|
|
|
|
2001-02-07 22:08:50 -06:00
|
|
|
ret->top_frame_data = top_level_data;
|
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
ret->data.stack = g_slist_prepend (ret->data.stack,
|
|
|
|
(gpointer) ret->top_frame);
|
2001-02-07 22:08:50 -06:00
|
|
|
|
2009-12-29 14:12:48 -06:00
|
|
|
if (initial_parser->start_handler)
|
2001-02-07 22:08:50 -06:00
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
if (!initial_parser->start_handler (NULL,
|
|
|
|
&ret->top_frame_data,
|
|
|
|
&ret->data.global_data,
|
|
|
|
&ret->top_frame->data_for_children,
|
|
|
|
&ret->top_frame->frame_data,
|
|
|
|
NULL, NULL))
|
2001-02-07 22:08:50 -06:00
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
sixtp_handle_catastrophe (&ret->data);
|
|
|
|
sixtp_context_destroy (ret);
|
2001-02-07 22:08:50 -06:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2009-12-29 14:12:48 -06:00
|
|
|
|
2001-02-07 22:08:50 -06:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-03-12 16:04:40 -06:00
|
|
|
sixtp_context_run_end_handler (sixtp_parser_context* ctxt)
|
2001-02-07 22:08:50 -06:00
|
|
|
{
|
2009-12-29 14:12:48 -06:00
|
|
|
if (ctxt->top_frame->parser->end_handler)
|
2001-02-07 22:08:50 -06:00
|
|
|
{
|
2002-12-23 20:27:10 -06:00
|
|
|
ctxt->data.parsing_ok &=
|
2016-03-12 16:04:40 -06:00
|
|
|
ctxt->top_frame->parser->end_handler (
|
2009-12-29 14:12:48 -06:00
|
|
|
ctxt->top_frame->data_for_children,
|
|
|
|
ctxt->top_frame->data_from_children,
|
|
|
|
NULL,
|
|
|
|
ctxt->top_frame_data,
|
|
|
|
ctxt->data.global_data,
|
|
|
|
&ctxt->top_frame->frame_data,
|
|
|
|
NULL);
|
2001-02-07 22:08:50 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-03-12 16:04:40 -06:00
|
|
|
sixtp_context_destroy (sixtp_parser_context* context)
|
2001-02-07 22:08:50 -06:00
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
sixtp_stack_frame_destroy (context->top_frame);
|
|
|
|
g_slist_free (context->data.stack);
|
2005-11-01 21:32:36 -06:00
|
|
|
context->data.saxParserCtxt->userData = NULL;
|
2009-12-29 14:12:48 -06:00
|
|
|
context->data.saxParserCtxt->sax = NULL;
|
2016-03-12 16:04:40 -06:00
|
|
|
xmlFreeParserCtxt (context->data.saxParserCtxt);
|
2005-11-01 21:32:36 -06:00
|
|
|
context->data.saxParserCtxt = NULL;
|
2016-03-12 16:04:40 -06:00
|
|
|
g_free (context);
|
2001-02-07 22:08:50 -06:00
|
|
|
}
|