From 8fdc32abfe42f9f281cb9418789ddfa3cd8ccfa5 Mon Sep 17 00:00:00 2001 From: Aleksey Sanin Date: Wed, 5 Jan 2005 15:37:55 +0000 Subject: [PATCH] fixing col information in xmlParserInput and propagating column into xmlError --- ChangeLog | 9 ++++++++- error.c | 7 ++++--- include/libxml/xmlerror.h | 4 ++-- parser.c | 18 +++++++++++------- parserInternals.c | 6 ++---- 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index d9ab9d75..f92e877b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Tue Jan 4 17:08:45 PST 2005 Aleksey Sanin + + * parser.c, parserInternal.c: fixed "col" calculation for + struct _xmlParserInput (based on patch from Rob Richards) + * include/libxml/xmlerror.h, error.c: propagated error column + number in the xmlError structure + Tue Jan 4 22:47:22 CET 2005 Daniel Veillard * parser.c: fixed namespace bug in push mode reported by @@ -40,7 +47,7 @@ Tue Jan 4 15:30:15 CET 2005 Daniel Veillard Mon Jan 3 13:57:21 PST 2005 Aleksey Sanin - * Added GetLineNumber and GetColumnNumber functions for xmlReader + * parser.c: added GetLineNumber and GetColumnNumber functions for xmlReader Sun Jan 2 17:51:18 HKT 2005 William Brack diff --git a/error.c b/error.c index b4fed922..5ab1835d 100644 --- a/error.c +++ b/error.c @@ -429,7 +429,7 @@ xmlReportError(xmlErrorPtr err, xmlParserCtxtPtr ctxt, const char *str, * @str2: extra string info * @str3: extra string info * @int1: extra int info - * @int2: extra int info + * @col: column number of the error or 0 if N/A * @msg: the message to display/transmit * @...: extra parameters for the message display * @@ -442,7 +442,7 @@ __xmlRaiseError(xmlStructuredErrorFunc schannel, xmlGenericErrorFunc channel, void *data, void *ctx, void *nod, int domain, int code, xmlErrorLevel level, const char *file, int line, const char *str1, - const char *str2, const char *str3, int int1, int int2, + const char *str2, const char *str3, int int1, int col, const char *msg, ...) { xmlParserCtxtPtr ctxt = NULL; @@ -505,6 +505,7 @@ __xmlRaiseError(xmlStructuredErrorFunc schannel, if (input != NULL) { file = input->filename; line = input->line; + col = input->col; } } to = &ctxt->lastError; @@ -571,7 +572,7 @@ __xmlRaiseError(xmlStructuredErrorFunc schannel, if (str3 != NULL) to->str3 = (char *) xmlStrdup((const xmlChar *) str3); to->int1 = int1; - to->int2 = int2; + to->int2 = col; to->node = node; to->ctxt = ctx; diff --git a/include/libxml/xmlerror.h b/include/libxml/xmlerror.h index dd75f238..7a5df69e 100644 --- a/include/libxml/xmlerror.h +++ b/include/libxml/xmlerror.h @@ -82,7 +82,7 @@ struct _xmlError { char *str2; /* extra string information */ char *str3; /* extra string information */ int int1; /* extra number information */ - int int2; /* extra number information */ + int int2; /* column number of the error or 0 if N/A (todo: rename this field when we would break ABI) */ void *ctxt; /* the parser context if available */ void *node; /* the node in the tree */ }; @@ -889,7 +889,7 @@ XMLPUBFUN void XMLCALL const char *str2, const char *str3, int int1, - int int2, + int col, const char *msg, ...); XMLPUBFUN void XMLCALL diff --git a/parser.c b/parser.c index 02ccdb1e..d0210af7 100644 --- a/parser.c +++ b/parser.c @@ -2421,6 +2421,7 @@ xmlParseNameAndCompare(xmlParserCtxtPtr ctxt, xmlChar const *other) { while (*in != 0 && *in == *cmp) { ++in; ++cmp; + ctxt->input->col++; } if (*cmp == 0 && (*in == '>' || IS_BLANK_CH (*in))) { /* success */ @@ -3201,10 +3202,10 @@ xmlParseCharData(xmlParserCtxtPtr ctxt, int cdata) { get_more_space: while (*in == 0x20) in++; if (*in == 0xA) { - ctxt->input->line++; + ctxt->input->line++; ctxt->input->col = 1; in++; while (*in == 0xA) { - ctxt->input->line++; + ctxt->input->line++; ctxt->input->col = 1; in++; } goto get_more_space; @@ -3237,13 +3238,15 @@ get_more: ((*in > '&') && (*in < '<')) || ((*in > '<') && (*in < ']')) || ((*in >= 0x20) && (*in < '&')) || - (*in == 0x09)) - in++; + (*in == 0x09)) { + in++; + ctxt->input->col++; + } if (*in == 0xA) { - ctxt->input->line++; + ctxt->input->line++; ctxt->input->col = 1; in++; while (*in == 0xA) { - ctxt->input->line++; + ctxt->input->line++; ctxt->input->col = 1; in++; } goto get_more; @@ -3255,6 +3258,7 @@ get_more: return; } in++; + ctxt->input->col++; goto get_more; } nbchar = in - ctxt->input->cur; @@ -3288,7 +3292,7 @@ get_more: if (*in == 0xA) { ctxt->input->cur = in; in++; - ctxt->input->line++; + ctxt->input->line++; ctxt->input->col = 1; continue; /* while */ } in--; diff --git a/parserInternals.c b/parserInternals.c index 807169bd..27257fc7 100644 --- a/parserInternals.c +++ b/parserInternals.c @@ -473,8 +473,7 @@ xmlNextChar(xmlParserCtxtPtr ctxt) * the single character #xA. */ if (*(ctxt->input->cur) == '\n') { - ctxt->input->line++; - ctxt->input->col = 1; + ctxt->input->line++; ctxt->input->col = 1; } else ctxt->input->col++; @@ -551,8 +550,7 @@ xmlNextChar(xmlParserCtxtPtr ctxt) */ if (*(ctxt->input->cur) == '\n') { - ctxt->input->line++; - ctxt->input->col = 1; + ctxt->input->line++; ctxt->input->col = 1; } else ctxt->input->col++; ctxt->input->cur++;