From e3bffb99347d1a023584be9a270a46c708416a2a Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Sun, 8 Nov 1998 14:40:56 +0000 Subject: [PATCH] Redirect all errors reporting through the SAX error function, Daniel. --- ChangeLog | 5 + parser.c | 297 ++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 192 insertions(+), 110 deletions(-) diff --git a/ChangeLog b/ChangeLog index 23fe4dd1..9627b1f5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sun Nov 8 09:39:17 EST 1998 Daniel Veillard + + * parser.c: redirrect all errors reporting through the SAX + error function + Wed Nov 4 14:21:54 EST 1998 Daniel Veillard * entities.c: rather use HAVE_SNPRINTF and not depend on glib diff --git a/parser.c b/parser.c index aa76cc66..472090de 100644 --- a/parser.c +++ b/parser.c @@ -157,18 +157,21 @@ xmlNewEntityInputStream(xmlParserCtxtPtr ctxt, xmlEntityPtr entity) { xmlParserInputPtr input; if (entity == NULL) { - xmlParserError(ctxt, + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt, "internal: xmlNewEntityInputStream entity = NULL\n"); return(NULL); } if (entity->content == NULL) { - xmlParserError(ctxt, + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt, "internal: xmlNewEntityInputStream entity->input = NULL\n"); return(NULL); } input = (xmlParserInputPtr) malloc(sizeof(xmlParserInput)); if (input == NULL) { - xmlParserError(ctxt, "malloc: couldn't allocate a new input stream\n"); + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt, "malloc: couldn't allocate a new input stream\n"); return(NULL); } input->filename = entity->SystemID; /* TODO !!! char <- CHAR */ @@ -929,7 +932,8 @@ xmlHandleEntity(xmlParserCtxtPtr ctxt, xmlEntityPtr entity) { xmlParserInputPtr input; if (entity->content == NULL) { - xmlParserError(ctxt, "xmlHandleEntity %s: content == NULL\n", + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt, "xmlHandleEntity %s: content == NULL\n", entity->name); return; } @@ -1074,9 +1078,10 @@ xmlParseQuotedString(xmlParserCtxtPtr ctxt) { NEXT; q = CUR_PTR; while (IS_CHAR(CUR) && (CUR != '"')) NEXT; - if (CUR != '"') - xmlParserError(ctxt, "String not closed\"%.50s\n", q); - else { + if (CUR != '"') { + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt, "String not closed\"%.50s\n", q); + } else { ret = xmlStrndup(q, CUR_PTR - q); NEXT; } @@ -1084,9 +1089,10 @@ xmlParseQuotedString(xmlParserCtxtPtr ctxt) { NEXT; q = CUR_PTR; while (IS_CHAR(CUR) && (CUR != '\'')) NEXT; - if (CUR != '\'') - xmlParserError(ctxt, "String not closed\"%.50s\n", q); - else { + if (CUR != '\'') { + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt, "String not closed\"%.50s\n", q); + } else { ret = xmlStrndup(q, CUR_PTR - q); NEXT; } @@ -1176,7 +1182,8 @@ xmlParseNamespace(xmlParserCtxtPtr ctxt) { * Found garbage when parsing the namespace */ if (!garbage) - xmlParserError(ctxt, "xmlParseNamespace found garbage\n"); + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt, "xmlParseNamespace found garbage\n"); NEXT; } } @@ -1312,7 +1319,8 @@ xmlParseEntityValue(xmlParserCtxtPtr ctxt) { NEXT; } if (!IS_CHAR(CUR)) { - xmlParserError(ctxt, "Unfinished EntityValue\n"); + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt, "Unfinished EntityValue\n"); } else { ret = xmlStrncat(ret, q, CUR_PTR - q); NEXT; @@ -1344,13 +1352,15 @@ xmlParseEntityValue(xmlParserCtxtPtr ctxt) { NEXT; } if (!IS_CHAR(CUR)) { - xmlParserError(ctxt, "Unfinished EntityValue\n"); + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt, "Unfinished EntityValue\n"); } else { ret = xmlStrncat(ret, q, CUR_PTR - q); NEXT; } } else { - xmlParserError(ctxt, "xmlParseEntityValue \" or ' expected\n"); + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt, "xmlParseEntityValue \" or ' expected\n"); } return(ret); @@ -1407,7 +1417,8 @@ xmlParseAttValue(xmlParserCtxtPtr ctxt) { } } if (!IS_CHAR(CUR)) { - xmlParserError(ctxt, "Unfinished AttValue\n"); + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt, "Unfinished AttValue\n"); } else { ret = xmlStrncat(ret, q, CUR_PTR - q); NEXT; @@ -1446,13 +1457,15 @@ xmlParseAttValue(xmlParserCtxtPtr ctxt) { } } if (!IS_CHAR(CUR)) { - xmlParserError(ctxt, "Unfinished AttValue\n"); + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt, "Unfinished AttValue\n"); } else { ret = xmlStrncat(ret, q, CUR_PTR - q); NEXT; } } else { - xmlParserError(ctxt, "AttValue: \" or ' expected\n"); + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt, "AttValue: \" or ' expected\n"); } return(ret); @@ -1479,7 +1492,8 @@ xmlParseSystemLiteral(xmlParserCtxtPtr ctxt) { while ((IS_CHAR(CUR)) && (CUR != '"')) NEXT; if (!IS_CHAR(CUR)) { - xmlParserError(ctxt, "Unfinished SystemLiteral\n"); + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt, "Unfinished SystemLiteral\n"); } else { ret = xmlStrndup(q, CUR_PTR - q); NEXT; @@ -1490,13 +1504,15 @@ xmlParseSystemLiteral(xmlParserCtxtPtr ctxt) { while ((IS_CHAR(CUR)) && (CUR != '\'')) NEXT; if (!IS_CHAR(CUR)) { - xmlParserError(ctxt, "Unfinished SystemLiteral\n"); + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt, "Unfinished SystemLiteral\n"); } else { ret = xmlStrndup(q, CUR_PTR - q); NEXT; } } else { - xmlParserError(ctxt, "SystemLiteral \" or ' expected\n"); + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt, "SystemLiteral \" or ' expected\n"); } return(ret); @@ -1522,7 +1538,8 @@ xmlParsePubidLiteral(xmlParserCtxtPtr ctxt) { q = CUR_PTR; while (IS_PUBIDCHAR(CUR)) NEXT; if (CUR != '"') { - xmlParserError(ctxt, "Unfinished PubidLiteral\n"); + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt, "Unfinished PubidLiteral\n"); } else { ret = xmlStrndup(q, CUR_PTR - q); NEXT; @@ -1533,13 +1550,15 @@ xmlParsePubidLiteral(xmlParserCtxtPtr ctxt) { while ((IS_LETTER(CUR)) && (CUR != '\'')) NEXT; if (!IS_LETTER(CUR)) { - xmlParserError(ctxt, "Unfinished PubidLiteral\n"); + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt, "Unfinished PubidLiteral\n"); } else { ret = xmlStrndup(q, CUR_PTR - q); NEXT; } } else { - xmlParserError(ctxt, "SystemLiteral \" or ' expected\n"); + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt, "SystemLiteral \" or ' expected\n"); } return(ret); @@ -1605,7 +1624,8 @@ xmlParseExternalID(xmlParserCtxtPtr ctxt, CHAR **publicID) { SKIP_BLANKS; URI = xmlParseSystemLiteral(ctxt); if (URI == NULL) - xmlParserError(ctxt, + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt, "xmlParseExternalID: SYSTEM, no URI\n"); } else if ((CUR == 'P') && (NXT(1) == 'U') && (NXT(2) == 'B') && (NXT(3) == 'L') && @@ -1614,12 +1634,14 @@ xmlParseExternalID(xmlParserCtxtPtr ctxt, CHAR **publicID) { SKIP_BLANKS; *publicID = xmlParsePubidLiteral(ctxt); if (*publicID == NULL) - xmlParserError(ctxt, + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt, "xmlParseExternalID: PUBLIC, no Public Identifier\n"); SKIP_BLANKS; URI = xmlParseSystemLiteral(ctxt); if (URI == NULL) - xmlParserError(ctxt, + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt, "xmlParseExternalID: PUBLIC, no URI\n"); } return(URI); @@ -1661,12 +1683,14 @@ xmlNodePtr xmlParseComment(xmlParserCtxtPtr ctxt, int create) { ((CUR == ':') || (CUR != '>') || (*r != '-') || (*q != '-'))) { if ((*r == '-') && (*q == '-')) - xmlParserError(ctxt, + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt, "Comment must not contain '--' (double-hyphen)`\n"); NEXT;r++;q++; } if (!IS_CHAR(CUR)) { - xmlParserError(ctxt, "Comment not terminated \n