From 7e2051e60d44fee587a00a8478c5e218dea80cbe Mon Sep 17 00:00:00 2001 From: Joshua Sled Date: Sun, 21 Apr 2002 17:55:49 +0000 Subject: [PATCH] 2002-04-21 Joshua Sled * src/backend/file/sixtp.c (sixtp_parse_file): Explicitly create an xmlParserCtxt and keep it in the sixtp_sax_data, so we can... (sixtp_sax_start_handler): retain line/column numbers for stack frames, which pays off in... * src/backend/file/sixtp-stack.c (sixtp_stack_frame_print): printing the line/column numbers of parsing errors when they occur. * src/backend/file/sixtp.c (sixtp_parse_buffer): Analagous change for in-memory-buffer parsing. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6817 57a11ea4-9604-0410-9ed3-97b8803252fd --- ChangeLog | 12 ++++++++++++ src/backend/file/sixtp-stack.c | 2 ++ src/backend/file/sixtp-stack.h | 4 ++++ src/backend/file/sixtp.c | 17 +++++++++++++++-- src/backend/file/sixtp.h | 3 +++ 5 files changed, 36 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index caa6c1b646..406685df72 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2002-04-21 Joshua Sled + + * src/backend/file/sixtp.c (sixtp_parse_file): Explicitly create + an xmlParserCtxt and keep it in the sixtp_sax_data, so we can... + (sixtp_sax_start_handler): retain line/column numbers for stack + frames, which pays off in... + * src/backend/file/sixtp-stack.c (sixtp_stack_frame_print): + printing the line/column numbers of parsing errors when they + occur. + * src/backend/file/sixtp.c (sixtp_parse_buffer): Analagous change + for in-memory-buffer parsing. + 2002-04-20 Joshua Sled * src/gnome/dialog-sxsincelast.c (process_auto_create_list): Added diff --git a/src/backend/file/sixtp-stack.c b/src/backend/file/sixtp-stack.c index 5898e9c23b..12dd0ee0a4 100644 --- a/src/backend/file/sixtp-stack.c +++ b/src/backend/file/sixtp-stack.c @@ -53,6 +53,7 @@ sixtp_stack_frame_new(sixtp* next_parser, char *tag) new_frame->data_for_children = NULL; new_frame->data_from_children = NULL; new_frame->frame_data = NULL; + new_frame->line = new_frame->col = -1; return new_frame; } @@ -63,6 +64,7 @@ sixtp_stack_frame_print(sixtp_stack_frame *sf, gint indent, FILE *f) gchar *is = g_strnfill(indent, ' '); 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, diff --git a/src/backend/file/sixtp-stack.h b/src/backend/file/sixtp-stack.h index c360f701e6..d6d5e0b12e 100644 --- a/src/backend/file/sixtp-stack.h +++ b/src/backend/file/sixtp-stack.h @@ -34,6 +34,10 @@ typedef struct sixtp_stack_frame { gpointer data_for_children; GSList *data_from_children; /* in reverse chronological order */ gpointer frame_data; + + /* Line and column [of the start tag]; set during parsing. */ + int line; + int col; } sixtp_stack_frame; struct _sixtp_parser_context_struct diff --git a/src/backend/file/sixtp.c b/src/backend/file/sixtp.c index 8e424865d2..a842d1f11c 100644 --- a/src/backend/file/sixtp.c +++ b/src/backend/file/sixtp.c @@ -29,6 +29,9 @@ #include #include +#include "libxml/SAX.h" +#include "libxml/parser.h" + #include "sixtp.h" #include "sixtp-stack.h" @@ -444,6 +447,9 @@ sixtp_sax_start_handler(void *user_data, /* now allocate the new stack frame and shift to it */ new_frame = sixtp_stack_frame_new(next_parser, g_strdup(name)); + + new_frame->line = getLineNumber( pdata->saxParserCtxt ); + new_frame->col = getColumnNumber( pdata->saxParserCtxt ); pdata->stack = g_slist_prepend(pdata->stack, (gpointer) new_frame); @@ -700,7 +706,11 @@ sixtp_parse_file(sixtp *sixtp, return FALSE; } - xmlSAXUserParseFile(&ctxt->handler, &ctxt->data, filename); + ctxt->data.saxParserCtxt = xmlCreateFileParserCtxt( filename ); + ctxt->data.saxParserCtxt->sax = &ctxt->handler; + ctxt->data.saxParserCtxt->userData = &ctxt->data; + xmlParseDocument( ctxt->data.saxParserCtxt ); + //xmlSAXUserParseFile(&ctxt->handler, &ctxt->data, filename); if(ctxt->data.parsing_ok) { @@ -736,7 +746,10 @@ sixtp_parse_buffer(sixtp *sixtp, return FALSE; } - xmlSAXUserParseMemory(&ctxt->handler, &ctxt->data, bufp, bufsz); + ctxt->data.saxParserCtxt = xmlCreateMemoryParserCtxt( bufp, bufsz ); + ctxt->data.saxParserCtxt->sax = &ctxt->handler; + ctxt->data.saxParserCtxt->userData = &ctxt->data; + xmlParseDocument( ctxt->data.saxParserCtxt ); sixtp_context_run_end_handler(ctxt); diff --git a/src/backend/file/sixtp.h b/src/backend/file/sixtp.h index d5e4ff8e20..6b18b1d8ed 100644 --- a/src/backend/file/sixtp.h +++ b/src/backend/file/sixtp.h @@ -29,6 +29,8 @@ #include +#include "libxml/SAX.h" + #include "gnc-xml-helper.h" typedef struct _sixtp_child_result sixtp_child_result; @@ -150,6 +152,7 @@ typedef struct sixtp_sax_data { gboolean parsing_ok; GSList *stack; gpointer global_data; + xmlParserCtxtPtr saxParserCtxt; } sixtp_sax_data;