[xml] error.c; xmlParserPrintFileContex
- From: "Chuck Griffith" <chuck griffith nwa com>
- To: <xml gnome org>
- Subject: [xml] error.c; xmlParserPrintFileContex
- Date: Thu, 22 Mar 2001 10:10:29 -0600
here is my revised suggestion for changing xmlParserPrintFileContex:
*** ../error.c Wed Mar 21 19:47:40 2001
--- error.c Thu Mar 22 15:29:57 2001
***************
*** 107,140 ****
xmlParserPrintFileContext(xmlParserInputPtr input) {
const xmlChar *cur, *base;
int n;
if (input == NULL) return;
cur = input->cur;
base = input->base;
while ((cur > base) && ((*cur == '\n') || (*cur == '\r'))) {
cur--;
}
n = 0;
! while ((n++ < 80) && (cur > base) && (*cur != '\n') && (*cur != '\r'))
cur--;
if ((*cur == '\n') || (*cur == '\r')) cur++;
! base = cur;
n = 0;
while ((*cur != 0) && (*cur != '\n') && (*cur != '\r') && (n < 79)) {
! xmlGenericError(xmlGenericErrorContext,
! "%c", (unsigned char) *cur++);
n++;
}
! xmlGenericError(xmlGenericErrorContext, "\n");
cur = input->cur;
! while ((*cur == '\n') || (*cur == '\r'))
! cur--;
n = 0;
! while ((cur != base) && (n++ < 80)) {
! xmlGenericError(xmlGenericErrorContext, " ");
! base++;
}
! xmlGenericError(xmlGenericErrorContext,"^\n");
}
/**
--- 107,150 ----
xmlParserPrintFileContext(xmlParserInputPtr input) {
const xmlChar *cur, *base;
int n;
+ xmlChar content[80];
+ xmlChar *ctnt;
if (input == NULL) return;
cur = input->cur;
base = input->base;
+ /* skip backwards over any end-of-lines */
while ((cur > base) && ((*cur == '\n') || (*cur == '\r'))) {
cur--;
}
n = 0;
! /* search backwards for beginning-of-line maximum 79 characters */
! while ((n++ < 79) && (cur > base) && (*cur != '\n') && (*cur != '\r'))
cur--;
if ((*cur == '\n') || (*cur == '\r')) cur++;
! /* search forward for end-of-line maximum 79 characters */
n = 0;
+ ctnt = content;
while ((*cur != 0) && (*cur != '\n') && (*cur != '\r') && (n < 79)) {
! *ctnt++ = *cur++;
n++;
}
! *ctnt = NULL;
! xmlGenericError(xmlGenericErrorContext,"%s\n", content);
! /* create blank line with problem pointer */
cur = input->cur;
! while ((cur > base) && ((*cur == '\n') || (*cur == '\r'))) {
! cur--;
! }
n = 0;
! ctnt = content;
! while ((n++ < 79) && (cur > base) && (*cur != '\n') && (*cur != '\r'))
{
! *ctnt++ = ' ';
! cur--;
}
! *(--ctnt) = '^';
! *(++ctnt) = NULL;
! xmlGenericError(xmlGenericErrorContext,"%s\n", content);
}
/**
I did two things:
1. changed the calls to xmlGenericError to be one string call instead of
multiple character calls.
2. I noticed that the error pointer could get thrown off in some situations
because the character counting in the sections I marked "/* skip backwards"
and "/* search backwards" was different that the section I marked "/* create
blank line". I unified the two methods.
Test results:
----------------------------
new line at point of problem:
Entity: line 3: error: Opening and ending tag mismatch: CLBSolution and asef
<CLBSolution></asef>
^
Entity: line 4: error: Extra content at the end of the document
<AirlineSpecific>
^
------------------------------------------
newline within 80 chars at left of problem:
Entity: line 3: error: Opening and ending tag mismatch: CLBSolution and asef
<CLBSolution></asef><AirlineSpecific><NWA></asdf><UID>1234</UID><Password>he
ll
^
Entity: line 3: error: Extra content at the end of the document
<CLBSolution></asef><AirlineSpecific><NWA></asdf><UID>1234</UID><Password>he
ll
^
---------------------------------------------
no newline within 80 chars at left of problem:
Entity: line 1: error: Opening and ending tag mismatch: CLBSolution and asef
encoding="UTF-8"?><!DOCTYPE CLBSolution SYSTEM
"solution"><CLBSolution></asef>
^
Entity: line 1: error: Extra content at the end of the document
encoding="UTF-8"?><!DOCTYPE CLBSolution SYSTEM
"solution"><CLBSolution></asef>
^
-----------------------------------------------------------
newline within 80 characters of left _and_ right of problem:
Entity: line 3: error: Opening and ending tag mismatch: CLBSolution and asef
<CLBSolution></asef><AirlineSpecific>
^
Entity: line 3: error: Extra content at the end of the document
<CLBSolution></asef><AirlineSpecific>
^
Not an revolutionary addition to the code but it will make my life easier.
chuck griffith nwa com
ovid = cgriffi
612-727-4681
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]