25 #include "sixtp-stack.h" 33 for (lp = sf->data_from_children; lp; lp = lp->next)
35 sixtp_child_result_destroy ((sixtp_child_result*) lp->data);
37 g_slist_free (sf->data_from_children);
38 sf->data_from_children = NULL;
44 sixtp_stack_frame_new (
sixtp* next_parser,
char* tag)
49 new_frame->parser = next_parser;
51 new_frame->data_for_children = NULL;
52 new_frame->data_from_children = NULL;
53 new_frame->frame_data = NULL;
54 new_frame->line = new_frame->col = -1;
62 gchar* is = g_strnfill (indent,
' ');
64 fprintf (f,
"%s(stack-frame %p\n", is, sf);
65 fprintf (f,
"%s (line %d) (col %d)\n", is, sf->line, sf->col);
66 fprintf (f,
"%s (parser %p)\n", is, sf->parser);
67 fprintf (f,
"%s (tag %s)\n", is, sf->tag ? sf->tag :
"(null)");
68 fprintf (f,
"%s (data-for-children %p)\n", is,
69 sf->data_for_children);
73 fprintf (f,
"%s (data-from-children", is);
74 for (lp = sf->data_from_children; lp; lp = lp->next)
77 sixtp_child_result_print ((sixtp_child_result*) lp->data, f);
82 fprintf (f,
"%s (frame-data %p))\n", is, sf->frame_data);
88 sixtp_pop_and_destroy_frame (GSList* frame_stack)
93 result = g_slist_next (frame_stack);
94 sixtp_stack_frame_destroy (dead_frame);
95 g_slist_free_1 (frame_stack);
100 sixtp_print_frame_stack (GSList* stack, FILE* f)
103 GSList* printcopy = g_slist_reverse (g_slist_copy (stack));
107 for (lp = printcopy; lp; lp = lp->next)
110 sixtp_stack_frame_print (frame, indent, f);
118 sixtp_parser_context*
119 sixtp_context_new (
sixtp* initial_parser, gpointer global_data,
120 gpointer top_level_data)
122 sixtp_parser_context* ret;
124 ret = g_new0 (sixtp_parser_context, 1);
126 ret->handler.startElement = sixtp_sax_start_handler;
127 ret->handler.endElement = sixtp_sax_end_handler;
128 ret->handler.characters = sixtp_sax_characters_handler;
129 ret->handler.getEntity = sixtp_sax_get_entity_handler;
131 ret->data.parsing_ok = TRUE;
132 ret->data.stack = NULL;
133 ret->data.global_data = global_data;
135 ret->top_frame = sixtp_stack_frame_new (initial_parser, NULL);
137 ret->top_frame_data = top_level_data;
139 ret->data.stack = g_slist_prepend (ret->data.stack,
140 (gpointer) ret->top_frame);
142 if (initial_parser->start_handler)
144 if (!initial_parser->start_handler (NULL,
145 &ret->top_frame_data,
146 &ret->data.global_data,
147 &ret->top_frame->data_for_children,
148 &ret->top_frame->frame_data,
151 sixtp_handle_catastrophe (&ret->data);
152 sixtp_context_destroy (ret);
161 sixtp_context_run_end_handler (sixtp_parser_context* ctxt)
163 if (ctxt->top_frame->parser->end_handler)
165 ctxt->data.parsing_ok &=
166 ctxt->top_frame->parser->end_handler (
167 ctxt->top_frame->data_for_children,
168 ctxt->top_frame->data_from_children,
170 ctxt->top_frame_data,
171 ctxt->data.global_data,
172 &ctxt->top_frame->frame_data,
178 sixtp_context_destroy (sixtp_parser_context* context)
180 sixtp_stack_frame_destroy (context->top_frame);
181 g_slist_free (context->data.stack);
182 context->data.saxParserCtxt->userData = NULL;
183 context->data.saxParserCtxt->sax = NULL;
184 xmlFreeParserCtxt (context->data.saxParserCtxt);
185 context->data.saxParserCtxt = NULL;