1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-29 11:41:22 +03:00

fixing the script replace sequences of RAW && NXT(.) == '.' with memcmp

* check-xml-test-suite.py: fixing the script
* parser.c: replace sequences of RAW && NXT(.) == '.' with
  memcmp calls, seems to not break conformance, slightly inflate
  the size of the gcc generated code though.
Daniel
This commit is contained in:
Daniel Veillard
2003-10-06 08:19:27 +00:00
parent ce9457f3aa
commit 8f597c3bf5
3 changed files with 150 additions and 234 deletions

View File

@ -1,3 +1,10 @@
Mon Oct 6 10:16:30 CEST 2003 Daniel Veillard <daniel@veillard.com>
* check-xml-test-suite.py: fixing the script
* parser.c: replace sequences of RAW && NXT(.) == '.' with
memcmp calls, seems to not break conformance, slightly inflate
the size of the gcc generated code though.
Sun Oct 5 23:30:48 CEST 2003 Daniel Veillard <daniel@veillard.com> Sun Oct 5 23:30:48 CEST 2003 Daniel Veillard <daniel@veillard.com>
* parserInternals.c parser.c valid.c include/libxml/parserInternals.h: * parserInternals.c parser.c valid.c include/libxml/parserInternals.h:

View File

@ -23,8 +23,7 @@ def errorHandler(ctx, str):
global error_nr global error_nr
global error_msg global error_msg
if string.find(str, "error:") >= 0: error_nr = error_nr + 1
error_nr = error_nr + 1
if len(error_msg) < 300: if len(error_msg) < 300:
if len(error_msg) == 0 or error_msg[-1] == '\n': if len(error_msg) == 0 or error_msg[-1] == '\n':
error_msg = error_msg + " >>" + str error_msg = error_msg + " >>" + str
@ -77,16 +76,17 @@ def testNotWf(filename, id):
ctxt = libxml2.createFileParserCtxt(filename) ctxt = libxml2.createFileParserCtxt(filename)
if ctxt == None: if ctxt == None:
return -1 return -1
ctxt.parseDocument() ret = ctxt.parseDocument()
try: try:
doc = ctxt.doc() doc = ctxt.doc()
except: except:
doc = None doc = None
if error_nr == 0 or ctxt.wellFormed() != 0: if doc != None:
doc.freeDoc()
if ret == 0 or ctxt.wellFormed() != 0:
print "%s: error: Well Formedness error not detected" % (id) print "%s: error: Well Formedness error not detected" % (id)
log.write("%s: error: Well Formedness error not detected\n" % (id)) log.write("%s: error: Well Formedness error not detected\n" % (id))
doc.freeDoc()
return 0 return 0
return 1 return 1
@ -102,16 +102,17 @@ def testNotWfEnt(filename, id):
if ctxt == None: if ctxt == None:
return -1 return -1
ctxt.replaceEntities(1) ctxt.replaceEntities(1)
ctxt.parseDocument() ret = ctxt.parseDocument()
try: try:
doc = ctxt.doc() doc = ctxt.doc()
except: except:
doc = None doc = None
if error_nr == 0 or ctxt.wellFormed() != 0: if doc != None:
doc.freeDoc()
if ret == 0 or ctxt.wellFormed() != 0:
print "%s: error: Well Formedness error not detected" % (id) print "%s: error: Well Formedness error not detected" % (id)
log.write("%s: error: Well Formedness error not detected\n" % (id)) log.write("%s: error: Well Formedness error not detected\n" % (id))
doc.freeDoc()
return 0 return 0
return 1 return 1
@ -128,16 +129,17 @@ def testNotWfEntDtd(filename, id):
return -1 return -1
ctxt.replaceEntities(1) ctxt.replaceEntities(1)
ctxt.loadSubset(1) ctxt.loadSubset(1)
ctxt.parseDocument() ret = ctxt.parseDocument()
try: try:
doc = ctxt.doc() doc = ctxt.doc()
except: except:
doc = None doc = None
if error_nr == 0 or ctxt.wellFormed() != 0: if doc != None:
doc.freeDoc()
if ret == 0 or ctxt.wellFormed() != 0:
print "%s: error: Well Formedness error not detected" % (id) print "%s: error: Well Formedness error not detected" % (id)
log.write("%s: error: Well Formedness error not detected\n" % (id)) log.write("%s: error: Well Formedness error not detected\n" % (id))
doc.freeDoc()
return 0 return 0
return 1 return 1
@ -154,15 +156,17 @@ def testWfEntDtd(filename, id):
return -1 return -1
ctxt.replaceEntities(1) ctxt.replaceEntities(1)
ctxt.loadSubset(1) ctxt.loadSubset(1)
ctxt.parseDocument() ret = ctxt.parseDocument()
try: try:
doc = ctxt.doc() doc = ctxt.doc()
except: except:
doc = None doc = None
if ctxt.wellFormed() == 0: if doc == None or ret != 0 or ctxt.wellFormed() == 0:
print "%s: error: wrongly failed to parse the document" % (id) print "%s: error: wrongly failed to parse the document" % (id)
log.write("%s: error: wrongly failed to parse the document\n" % (id)) log.write("%s: error: wrongly failed to parse the document\n" % (id))
if doc != None:
doc.freeDoc()
return 0 return 0
if error_nr != 0: if error_nr != 0:
print "%s: warning: WF document generated an error msg" % (id) print "%s: warning: WF document generated an error msg" % (id)
@ -185,12 +189,14 @@ def testError(filename, id):
return -1 return -1
ctxt.replaceEntities(1) ctxt.replaceEntities(1)
ctxt.loadSubset(1) ctxt.loadSubset(1)
ctxt.parseDocument() ret = ctxt.parseDocument()
try: try:
doc = ctxt.doc() doc = ctxt.doc()
except: except:
doc = None doc = None
if doc != None:
doc.freeDoc()
if ctxt.wellFormed() == 0: if ctxt.wellFormed() == 0:
print "%s: warning: failed to parse the document but accepted" % (id) print "%s: warning: failed to parse the document but accepted" % (id)
log.write("%s: warning: failed to parse the document but accepte\n" % (id)) log.write("%s: warning: failed to parse the document but accepte\n" % (id))
@ -198,9 +204,7 @@ def testError(filename, id):
if error_nr != 0: if error_nr != 0:
print "%s: warning: WF document generated an error msg" % (id) print "%s: warning: WF document generated an error msg" % (id)
log.write("%s: error: WF document generated an error msg\n" % (id)) log.write("%s: error: WF document generated an error msg\n" % (id))
doc.freeDoc()
return 2 return 2
doc.freeDoc()
return 1 return 1
def testInvalid(filename, id): def testInvalid(filename, id):
@ -215,7 +219,7 @@ def testInvalid(filename, id):
if ctxt == None: if ctxt == None:
return -1 return -1
ctxt.validate(1) ctxt.validate(1)
ctxt.parseDocument() ret = ctxt.parseDocument()
try: try:
doc = ctxt.doc() doc = ctxt.doc()

339
parser.c
View File

@ -1766,9 +1766,7 @@ xmlParserHandlePEReference(xmlParserCtxtPtr ctxt) {
} }
if ((entity->etype == XML_EXTERNAL_PARAMETER_ENTITY) && if ((entity->etype == XML_EXTERNAL_PARAMETER_ENTITY) &&
(RAW == '<') && (NXT(1) == '?') && (memcmp(CUR_PTR, "<?xml", 5) == 0) && (IS_BLANK(NXT(5)))) {
(NXT(2) == 'x') && (NXT(3) == 'm') &&
(NXT(4) == 'l') && (IS_BLANK(NXT(5)))) {
xmlParseTextDecl(ctxt); xmlParseTextDecl(ctxt);
} }
} else { } else {
@ -3708,9 +3706,7 @@ xmlParseExternalID(xmlParserCtxtPtr ctxt, xmlChar **publicID, int strict) {
SHRINK; SHRINK;
*publicID = NULL; *publicID = NULL;
if ((RAW == 'S') && (NXT(1) == 'Y') && if (memcmp(CUR_PTR, "SYSTEM", 6) == 0) {
(NXT(2) == 'S') && (NXT(3) == 'T') &&
(NXT(4) == 'E') && (NXT(5) == 'M')) {
SKIP(6); SKIP(6);
if (!IS_BLANK(CUR)) { if (!IS_BLANK(CUR)) {
xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
@ -3721,9 +3717,7 @@ xmlParseExternalID(xmlParserCtxtPtr ctxt, xmlChar **publicID, int strict) {
if (URI == NULL) { if (URI == NULL) {
xmlFatalErr(ctxt, XML_ERR_URI_REQUIRED, NULL); xmlFatalErr(ctxt, XML_ERR_URI_REQUIRED, NULL);
} }
} else if ((RAW == 'P') && (NXT(1) == 'U') && } else if (memcmp(CUR_PTR, "PUBLIC", 6) == 0) {
(NXT(2) == 'B') && (NXT(3) == 'L') &&
(NXT(4) == 'I') && (NXT(5) == 'C')) {
SKIP(6); SKIP(6);
if (!IS_BLANK(CUR)) { if (!IS_BLANK(CUR)) {
xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
@ -4120,11 +4114,7 @@ xmlParseNotationDecl(xmlParserCtxtPtr ctxt) {
xmlChar *Pubid; xmlChar *Pubid;
xmlChar *Systemid; xmlChar *Systemid;
if ((RAW == '<') && (NXT(1) == '!') && if (memcmp(CUR_PTR, "<!NOTATION", 10) == 0) {
(NXT(2) == 'N') && (NXT(3) == 'O') &&
(NXT(4) == 'T') && (NXT(5) == 'A') &&
(NXT(6) == 'T') && (NXT(7) == 'I') &&
(NXT(8) == 'O') && (NXT(9) == 'N')) {
xmlParserInputPtr input = ctxt->input; xmlParserInputPtr input = ctxt->input;
SHRINK; SHRINK;
SKIP(10); SKIP(10);
@ -4203,10 +4193,7 @@ xmlParseEntityDecl(xmlParserCtxtPtr ctxt) {
int skipped; int skipped;
GROW; GROW;
if ((RAW == '<') && (NXT(1) == '!') && if (memcmp(CUR_PTR, "<!ENTITY", 8) == 0) {
(NXT(2) == 'E') && (NXT(3) == 'N') &&
(NXT(4) == 'T') && (NXT(5) == 'I') &&
(NXT(6) == 'T') && (NXT(7) == 'Y')) {
xmlParserInputPtr input = ctxt->input; xmlParserInputPtr input = ctxt->input;
SHRINK; SHRINK;
SKIP(8); SKIP(8);
@ -4344,9 +4331,7 @@ xmlParseEntityDecl(xmlParserCtxtPtr ctxt) {
"Space required before 'NDATA'\n"); "Space required before 'NDATA'\n");
} }
SKIP_BLANKS; SKIP_BLANKS;
if ((RAW == 'N') && (NXT(1) == 'D') && if (memcmp(CUR_PTR, "NDATA", 5) == 0) {
(NXT(2) == 'A') && (NXT(3) == 'T') &&
(NXT(4) == 'A')) {
SKIP(5); SKIP(5);
if (!IS_BLANK(CUR)) { if (!IS_BLANK(CUR)) {
xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
@ -4463,25 +4448,16 @@ xmlParseDefaultDecl(xmlParserCtxtPtr ctxt, xmlChar **value) {
xmlChar *ret; xmlChar *ret;
*value = NULL; *value = NULL;
if ((RAW == '#') && (NXT(1) == 'R') && if (memcmp(CUR_PTR, "#REQUIRED", 9) == 0) {
(NXT(2) == 'E') && (NXT(3) == 'Q') &&
(NXT(4) == 'U') && (NXT(5) == 'I') &&
(NXT(6) == 'R') && (NXT(7) == 'E') &&
(NXT(8) == 'D')) {
SKIP(9); SKIP(9);
return(XML_ATTRIBUTE_REQUIRED); return(XML_ATTRIBUTE_REQUIRED);
} }
if ((RAW == '#') && (NXT(1) == 'I') && if (memcmp(CUR_PTR, "#IMPLIED", 8) == 0) {
(NXT(2) == 'M') && (NXT(3) == 'P') &&
(NXT(4) == 'L') && (NXT(5) == 'I') &&
(NXT(6) == 'E') && (NXT(7) == 'D')) {
SKIP(8); SKIP(8);
return(XML_ATTRIBUTE_IMPLIED); return(XML_ATTRIBUTE_IMPLIED);
} }
val = XML_ATTRIBUTE_NONE; val = XML_ATTRIBUTE_NONE;
if ((RAW == '#') && (NXT(1) == 'F') && if (memcmp(CUR_PTR, "#FIXED", 6) == 0) {
(NXT(2) == 'I') && (NXT(3) == 'X') &&
(NXT(4) == 'E') && (NXT(5) == 'D')) {
SKIP(6); SKIP(6);
val = XML_ATTRIBUTE_FIXED; val = XML_ATTRIBUTE_FIXED;
if (!IS_BLANK(CUR)) { if (!IS_BLANK(CUR)) {
@ -4623,10 +4599,7 @@ xmlParseEnumerationType(xmlParserCtxtPtr ctxt) {
int int
xmlParseEnumeratedType(xmlParserCtxtPtr ctxt, xmlEnumerationPtr *tree) { xmlParseEnumeratedType(xmlParserCtxtPtr ctxt, xmlEnumerationPtr *tree) {
if ((RAW == 'N') && (NXT(1) == 'O') && if (memcmp(CUR_PTR, "NOTATION", 8) == 0) {
(NXT(2) == 'T') && (NXT(3) == 'A') &&
(NXT(4) == 'T') && (NXT(5) == 'I') &&
(NXT(6) == 'O') && (NXT(7) == 'N')) {
SKIP(8); SKIP(8);
if (!IS_BLANK(CUR)) { if (!IS_BLANK(CUR)) {
xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
@ -4691,45 +4664,28 @@ xmlParseEnumeratedType(xmlParserCtxtPtr ctxt, xmlEnumerationPtr *tree) {
int int
xmlParseAttributeType(xmlParserCtxtPtr ctxt, xmlEnumerationPtr *tree) { xmlParseAttributeType(xmlParserCtxtPtr ctxt, xmlEnumerationPtr *tree) {
SHRINK; SHRINK;
if ((RAW == 'C') && (NXT(1) == 'D') && if (memcmp(CUR_PTR, "CDATA", 5) == 0) {
(NXT(2) == 'A') && (NXT(3) == 'T') &&
(NXT(4) == 'A')) {
SKIP(5); SKIP(5);
return(XML_ATTRIBUTE_CDATA); return(XML_ATTRIBUTE_CDATA);
} else if ((RAW == 'I') && (NXT(1) == 'D') && } else if (memcmp(CUR_PTR, "IDREFS", 6) == 0) {
(NXT(2) == 'R') && (NXT(3) == 'E') &&
(NXT(4) == 'F') && (NXT(5) == 'S')) {
SKIP(6); SKIP(6);
return(XML_ATTRIBUTE_IDREFS); return(XML_ATTRIBUTE_IDREFS);
} else if ((RAW == 'I') && (NXT(1) == 'D') && } else if (memcmp(CUR_PTR, "IDREF", 5) == 0) {
(NXT(2) == 'R') && (NXT(3) == 'E') &&
(NXT(4) == 'F')) {
SKIP(5); SKIP(5);
return(XML_ATTRIBUTE_IDREF); return(XML_ATTRIBUTE_IDREF);
} else if ((RAW == 'I') && (NXT(1) == 'D')) { } else if ((RAW == 'I') && (NXT(1) == 'D')) {
SKIP(2); SKIP(2);
return(XML_ATTRIBUTE_ID); return(XML_ATTRIBUTE_ID);
} else if ((RAW == 'E') && (NXT(1) == 'N') && } else if (memcmp(CUR_PTR, "ENTITY", 6) == 0) {
(NXT(2) == 'T') && (NXT(3) == 'I') &&
(NXT(4) == 'T') && (NXT(5) == 'Y')) {
SKIP(6); SKIP(6);
return(XML_ATTRIBUTE_ENTITY); return(XML_ATTRIBUTE_ENTITY);
} else if ((RAW == 'E') && (NXT(1) == 'N') && } else if (memcmp(CUR_PTR, "ENTITIES", 8) == 0) {
(NXT(2) == 'T') && (NXT(3) == 'I') &&
(NXT(4) == 'T') && (NXT(5) == 'I') &&
(NXT(6) == 'E') && (NXT(7) == 'S')) {
SKIP(8); SKIP(8);
return(XML_ATTRIBUTE_ENTITIES); return(XML_ATTRIBUTE_ENTITIES);
} else if ((RAW == 'N') && (NXT(1) == 'M') && } else if (memcmp(CUR_PTR, "NMTOKENS", 8) == 0) {
(NXT(2) == 'T') && (NXT(3) == 'O') &&
(NXT(4) == 'K') && (NXT(5) == 'E') &&
(NXT(6) == 'N') && (NXT(7) == 'S')) {
SKIP(8); SKIP(8);
return(XML_ATTRIBUTE_NMTOKENS); return(XML_ATTRIBUTE_NMTOKENS);
} else if ((RAW == 'N') && (NXT(1) == 'M') && } else if (memcmp(CUR_PTR, "NMTOKEN", 7) == 0) {
(NXT(2) == 'T') && (NXT(3) == 'O') &&
(NXT(4) == 'K') && (NXT(5) == 'E') &&
(NXT(6) == 'N')) {
SKIP(7); SKIP(7);
return(XML_ATTRIBUTE_NMTOKEN); return(XML_ATTRIBUTE_NMTOKEN);
} }
@ -4753,11 +4709,7 @@ xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) {
const xmlChar *attrName; const xmlChar *attrName;
xmlEnumerationPtr tree; xmlEnumerationPtr tree;
if ((RAW == '<') && (NXT(1) == '!') && if (memcmp(CUR_PTR, "<!ATTLIST", 9) == 0) {
(NXT(2) == 'A') && (NXT(3) == 'T') &&
(NXT(4) == 'T') && (NXT(5) == 'L') &&
(NXT(6) == 'I') && (NXT(7) == 'S') &&
(NXT(8) == 'T')) {
xmlParserInputPtr input = ctxt->input; xmlParserInputPtr input = ctxt->input;
SKIP(9); SKIP(9);
@ -4902,10 +4854,7 @@ xmlParseElementMixedContentDecl(xmlParserCtxtPtr ctxt, int inputchk) {
const xmlChar *elem = NULL; const xmlChar *elem = NULL;
GROW; GROW;
if ((RAW == '#') && (NXT(1) == 'P') && if (memcmp(CUR_PTR, "#PCDATA", 7) == 0) {
(NXT(2) == 'C') && (NXT(3) == 'D') &&
(NXT(4) == 'A') && (NXT(5) == 'T') &&
(NXT(6) == 'A')) {
SKIP(7); SKIP(7);
SKIP_BLANKS; SKIP_BLANKS;
SHRINK; SHRINK;
@ -5287,10 +5236,7 @@ xmlParseElementContentDecl(xmlParserCtxtPtr ctxt, const xmlChar *name,
NEXT; NEXT;
GROW; GROW;
SKIP_BLANKS; SKIP_BLANKS;
if ((RAW == '#') && (NXT(1) == 'P') && if (memcmp(CUR_PTR, "#PCDATA", 7) == 0) {
(NXT(2) == 'C') && (NXT(3) == 'D') &&
(NXT(4) == 'A') && (NXT(5) == 'T') &&
(NXT(6) == 'A')) {
tree = xmlParseElementMixedContentDecl(ctxt, inputid); tree = xmlParseElementMixedContentDecl(ctxt, inputid);
res = XML_ELEMENT_TYPE_MIXED; res = XML_ELEMENT_TYPE_MIXED;
} else { } else {
@ -5322,11 +5268,7 @@ xmlParseElementDecl(xmlParserCtxtPtr ctxt) {
xmlElementContentPtr content = NULL; xmlElementContentPtr content = NULL;
GROW; GROW;
if ((RAW == '<') && (NXT(1) == '!') && if (memcmp(CUR_PTR, "<!ELEMENT", 9) == 0) {
(NXT(2) == 'E') && (NXT(3) == 'L') &&
(NXT(4) == 'E') && (NXT(5) == 'M') &&
(NXT(6) == 'E') && (NXT(7) == 'N') &&
(NXT(8) == 'T')) {
xmlParserInputPtr input = ctxt->input; xmlParserInputPtr input = ctxt->input;
SKIP(9); SKIP(9);
@ -5348,9 +5290,7 @@ xmlParseElementDecl(xmlParserCtxtPtr ctxt) {
"Space required after the element name\n"); "Space required after the element name\n");
} }
SKIP_BLANKS; SKIP_BLANKS;
if ((RAW == 'E') && (NXT(1) == 'M') && if (memcmp(CUR_PTR, "EMPTY", 5) == 0) {
(NXT(2) == 'P') && (NXT(3) == 'T') &&
(NXT(4) == 'Y')) {
SKIP(5); SKIP(5);
/* /*
* Element must always be empty. * Element must always be empty.
@ -5424,9 +5364,7 @@ static void
xmlParseConditionalSections(xmlParserCtxtPtr ctxt) { xmlParseConditionalSections(xmlParserCtxtPtr ctxt) {
SKIP(3); SKIP(3);
SKIP_BLANKS; SKIP_BLANKS;
if ((RAW == 'I') && (NXT(1) == 'N') && (NXT(2) == 'C') && if (memcmp(CUR_PTR, "INCLUDE", 7) == 0) {
(NXT(3) == 'L') && (NXT(4) == 'U') && (NXT(5) == 'D') &&
(NXT(6) == 'E')) {
SKIP(7); SKIP(7);
SKIP_BLANKS; SKIP_BLANKS;
if (RAW != '[') { if (RAW != '[') {
@ -5477,8 +5415,7 @@ xmlParseConditionalSections(xmlParserCtxtPtr ctxt) {
"Leaving INCLUDE Conditional Section\n"); "Leaving INCLUDE Conditional Section\n");
} }
} else if ((RAW == 'I') && (NXT(1) == 'G') && (NXT(2) == 'N') && } else if (memcmp(CUR_PTR, "IGNORE", 6) == 0) {
(NXT(3) == 'O') && (NXT(4) == 'R') && (NXT(5) == 'E')) {
int state; int state;
xmlParserInputState instate; xmlParserInputState instate;
int depth = 0; int depth = 0;
@ -5617,9 +5554,7 @@ xmlParseTextDecl(xmlParserCtxtPtr ctxt) {
/* /*
* We know that '<?xml' is here. * We know that '<?xml' is here.
*/ */
if ((RAW == '<') && (NXT(1) == '?') && if ((memcmp(CUR_PTR, "<?xml", 5) == 0) && (IS_BLANK(NXT(5)))) {
(NXT(2) == 'x') && (NXT(3) == 'm') &&
(NXT(4) == 'l') && (IS_BLANK(NXT(5)))) {
SKIP(5); SKIP(5);
} else { } else {
xmlFatalErr(ctxt, XML_ERR_XMLDECL_NOT_STARTED, NULL); xmlFatalErr(ctxt, XML_ERR_XMLDECL_NOT_STARTED, NULL);
@ -5688,9 +5623,7 @@ xmlParseExternalSubset(xmlParserCtxtPtr ctxt, const xmlChar *ExternalID,
const xmlChar *SystemID) { const xmlChar *SystemID) {
xmlDetectSAX2(ctxt); xmlDetectSAX2(ctxt);
GROW; GROW;
if ((RAW == '<') && (NXT(1) == '?') && if (memcmp(CUR_PTR, "<?xml", 5) == 0) {
(NXT(2) == 'x') && (NXT(3) == 'm') &&
(NXT(4) == 'l')) {
xmlParseTextDecl(ctxt); xmlParseTextDecl(ctxt);
if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) { if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) {
/* /*
@ -6047,9 +5980,7 @@ xmlParseReference(xmlParserCtxtPtr ctxt) {
input = xmlNewEntityInputStream(ctxt, ent); input = xmlNewEntityInputStream(ctxt, ent);
xmlPushInput(ctxt, input); xmlPushInput(ctxt, input);
if ((ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY) && if ((ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY) &&
(RAW == '<') && (NXT(1) == '?') && (memcmp(CUR_PTR, "<?xml", 5) == 0) && (IS_BLANK(NXT(5)))) {
(NXT(2) == 'x') && (NXT(3) == 'm') &&
(NXT(4) == 'l') && (IS_BLANK(NXT(5)))) {
xmlParseTextDecl(ctxt); xmlParseTextDecl(ctxt);
if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) { if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) {
/* /*
@ -6436,7 +6367,8 @@ xmlParseStringEntityRef(xmlParserCtxtPtr ctxt, const xmlChar ** str) {
* NOTE: misleading but this is handled. * NOTE: misleading but this is handled.
*/ */
void void
xmlParsePEReference(xmlParserCtxtPtr ctxt) { xmlParsePEReference(xmlParserCtxtPtr ctxt)
{
const xmlChar *name; const xmlChar *name;
xmlEntityPtr entity = NULL; xmlEntityPtr entity = NULL;
xmlParserInputPtr input; xmlParserInputPtr input;
@ -6444,84 +6376,86 @@ xmlParsePEReference(xmlParserCtxtPtr ctxt) {
if (RAW == '%') { if (RAW == '%') {
NEXT; NEXT;
name = xmlParseName(ctxt); name = xmlParseName(ctxt);
if (name == NULL) { if (name == NULL) {
xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED, xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED,
"xmlParsePEReference: no name\n"); "xmlParsePEReference: no name\n");
} else { } else {
if (RAW == ';') { if (RAW == ';') {
NEXT; NEXT;
if ((ctxt->sax != NULL) && if ((ctxt->sax != NULL) &&
(ctxt->sax->getParameterEntity != NULL)) (ctxt->sax->getParameterEntity != NULL))
entity = ctxt->sax->getParameterEntity(ctxt->userData, entity = ctxt->sax->getParameterEntity(ctxt->userData,
name); name);
if (entity == NULL) { if (entity == NULL) {
/* /*
* [ WFC: Entity Declared ] * [ WFC: Entity Declared ]
* In a document without any DTD, a document with only an * In a document without any DTD, a document with only an
* internal DTD subset which contains no parameter entity * internal DTD subset which contains no parameter entity
* references, or a document with "standalone='yes'", ... * references, or a document with "standalone='yes'", ...
* ... The declaration of a parameter entity must precede * ... The declaration of a parameter entity must precede
* any reference to it... * any reference to it...
*/ */
if ((ctxt->standalone == 1) || if ((ctxt->standalone == 1) ||
((ctxt->hasExternalSubset == 0) && ((ctxt->hasExternalSubset == 0) &&
(ctxt->hasPErefs == 0))) { (ctxt->hasPErefs == 0))) {
xmlFatalErrMsgStr(ctxt, XML_ERR_UNDECLARED_ENTITY, xmlFatalErrMsgStr(ctxt, XML_ERR_UNDECLARED_ENTITY,
"PEReference: %%%s; not found\n", name); "PEReference: %%%s; not found\n",
} else { name);
/* } else {
* [ VC: Entity Declared ] /*
* In a document with an external subset or external * [ VC: Entity Declared ]
* parameter entities with "standalone='no'", ... * In a document with an external subset or external
* ... The declaration of a parameter entity must precede * parameter entities with "standalone='no'", ...
* any reference to it... * ... The declaration of a parameter entity must
*/ * precede any reference to it...
xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY, */
"PEReference: %%%s; not found\n", xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY,
name, NULL); "PEReference: %%%s; not found\n",
ctxt->valid = 0; name, NULL);
} ctxt->valid = 0;
} else { }
/* } else {
* Internal checking in case the entity quest barfed /*
*/ * Internal checking in case the entity quest barfed
if ((entity->etype != XML_INTERNAL_PARAMETER_ENTITY) && */
(entity->etype != XML_EXTERNAL_PARAMETER_ENTITY)) { if ((entity->etype != XML_INTERNAL_PARAMETER_ENTITY) &&
xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY, (entity->etype != XML_EXTERNAL_PARAMETER_ENTITY)) {
"Internal: %%%s; is not a parameter entity\n", xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY,
name, NULL); "Internal: %%%s; is not a parameter entity\n",
} else if (ctxt->input->free != deallocblankswrapper) { name, NULL);
input = xmlNewBlanksWrapperInputStream(ctxt, entity); } else if (ctxt->input->free != deallocblankswrapper) {
xmlPushInput(ctxt, input); input =
} else { xmlNewBlanksWrapperInputStream(ctxt, entity);
/* xmlPushInput(ctxt, input);
* TODO !!! } else {
* handle the extra spaces added before and after /*
* c.f. http://www.w3.org/TR/REC-xml#as-PE * TODO !!!
*/ * handle the extra spaces added before and after
input = xmlNewEntityInputStream(ctxt, entity); * c.f. http://www.w3.org/TR/REC-xml#as-PE
xmlPushInput(ctxt, input); */
if ((entity->etype == XML_EXTERNAL_PARAMETER_ENTITY) && input = xmlNewEntityInputStream(ctxt, entity);
(RAW == '<') && (NXT(1) == '?') && xmlPushInput(ctxt, input);
(NXT(2) == 'x') && (NXT(3) == 'm') && if ((entity->etype == XML_EXTERNAL_PARAMETER_ENTITY) &&
(NXT(4) == 'l') && (IS_BLANK(NXT(5)))) { (memcmp(CUR_PTR, "<?xml", 5) == 0) &&
xmlParseTextDecl(ctxt); (IS_BLANK(NXT(5)))) {
if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) { xmlParseTextDecl(ctxt);
/* if (ctxt->errNo ==
* The XML REC instructs us to stop parsing XML_ERR_UNSUPPORTED_ENCODING) {
* right here /*
*/ * The XML REC instructs us to stop parsing
ctxt->instate = XML_PARSER_EOF; * right here
return; */
} ctxt->instate = XML_PARSER_EOF;
} return;
} }
} }
ctxt->hasPErefs = 1; }
} else { }
xmlFatalErr(ctxt, XML_ERR_ENTITYREF_SEMICOL_MISSING, NULL); ctxt->hasPErefs = 1;
} } else {
} xmlFatalErr(ctxt, XML_ERR_ENTITYREF_SEMICOL_MISSING, NULL);
}
}
} }
} }
@ -8052,11 +7986,8 @@ xmlParseCDSect(xmlParserCtxtPtr ctxt) {
int cur, l; int cur, l;
int count = 0; int count = 0;
if ((NXT(0) == '<') && (NXT(1) == '!') && /* Check 2.6.0 was NXT(0) not RAW */
(NXT(2) == '[') && (NXT(3) == 'C') && if (memcmp(CUR_PTR, "<![CDATA[", 9) == 0) {
(NXT(4) == 'D') && (NXT(5) == 'A') &&
(NXT(6) == 'T') && (NXT(7) == 'A') &&
(NXT(8) == '[')) {
SKIP(9); SKIP(9);
} else } else
return; return;
@ -8155,11 +8086,8 @@ xmlParseContent(xmlParserCtxtPtr ctxt) {
/* /*
* Second case : a CDSection * Second case : a CDSection
*/ */
else if ((*cur == '<') && (NXT(1) == '!') && /* 2.6.0 test was *cur not RAW */
(NXT(2) == '[') && (NXT(3) == 'C') && else if (memcmp(CUR_PTR, "<![CDATA[", 9) == 0) {
(NXT(4) == 'D') && (NXT(5) == 'A') &&
(NXT(6) == 'T') && (NXT(7) == 'A') &&
(NXT(8) == '[')) {
xmlParseCDSect(ctxt); xmlParseCDSect(ctxt);
} }
@ -8439,10 +8367,7 @@ xmlChar *
xmlParseVersionInfo(xmlParserCtxtPtr ctxt) { xmlParseVersionInfo(xmlParserCtxtPtr ctxt) {
xmlChar *version = NULL; xmlChar *version = NULL;
if ((RAW == 'v') && (NXT(1) == 'e') && if (memcmp(CUR_PTR, "version", 7) == 0) {
(NXT(2) == 'r') && (NXT(3) == 's') &&
(NXT(4) == 'i') && (NXT(5) == 'o') &&
(NXT(6) == 'n')) {
SKIP(7); SKIP(7);
SKIP_BLANKS; SKIP_BLANKS;
if (RAW != '=') { if (RAW != '=') {
@ -8548,10 +8473,7 @@ xmlParseEncodingDecl(xmlParserCtxtPtr ctxt) {
xmlChar *encoding = NULL; xmlChar *encoding = NULL;
SKIP_BLANKS; SKIP_BLANKS;
if ((RAW == 'e') && (NXT(1) == 'n') && if (memcmp(CUR_PTR, "encoding", 8) == 0) {
(NXT(2) == 'c') && (NXT(3) == 'o') &&
(NXT(4) == 'd') && (NXT(5) == 'i') &&
(NXT(6) == 'n') && (NXT(7) == 'g')) {
SKIP(8); SKIP(8);
SKIP_BLANKS; SKIP_BLANKS;
if (RAW != '=') { if (RAW != '=') {
@ -8649,11 +8571,7 @@ xmlParseSDDecl(xmlParserCtxtPtr ctxt) {
int standalone = -1; int standalone = -1;
SKIP_BLANKS; SKIP_BLANKS;
if ((RAW == 's') && (NXT(1) == 't') && if (memcmp(CUR_PTR, "standalone", 10) == 0) {
(NXT(2) == 'a') && (NXT(3) == 'n') &&
(NXT(4) == 'd') && (NXT(5) == 'a') &&
(NXT(6) == 'l') && (NXT(7) == 'o') &&
(NXT(8) == 'n') && (NXT(9) == 'e')) {
SKIP(10); SKIP(10);
SKIP_BLANKS; SKIP_BLANKS;
if (RAW != '=') { if (RAW != '=') {
@ -8802,8 +8720,7 @@ xmlParseXMLDecl(xmlParserCtxtPtr ctxt) {
void void
xmlParseMisc(xmlParserCtxtPtr ctxt) { xmlParseMisc(xmlParserCtxtPtr ctxt) {
while (((RAW == '<') && (NXT(1) == '?')) || while (((RAW == '<') && (NXT(1) == '?')) ||
((RAW == '<') && (NXT(1) == '!') && (memcmp(CUR_PTR, "<!--", 4) == 0) ||
(NXT(2) == '-') && (NXT(3) == '-')) ||
IS_BLANK(CUR)) { IS_BLANK(CUR)) {
if ((RAW == '<') && (NXT(1) == '?')) { if ((RAW == '<') && (NXT(1) == '?')) {
xmlParsePI(ctxt); xmlParsePI(ctxt);
@ -8874,9 +8791,7 @@ xmlParseDocument(xmlParserCtxtPtr ctxt) {
* Check for the XMLDecl in the Prolog. * Check for the XMLDecl in the Prolog.
*/ */
GROW; GROW;
if ((RAW == '<') && (NXT(1) == '?') && if ((memcmp(CUR_PTR, "<?xml", 5) == 0) && (IS_BLANK(NXT(5)))) {
(NXT(2) == 'x') && (NXT(3) == 'm') &&
(NXT(4) == 'l') && (IS_BLANK(NXT(5)))) {
/* /*
* Note that we will switch encoding on the fly. * Note that we will switch encoding on the fly.
@ -8907,11 +8822,7 @@ xmlParseDocument(xmlParserCtxtPtr ctxt) {
* (doctypedecl Misc*)? * (doctypedecl Misc*)?
*/ */
GROW; GROW;
if ((RAW == '<') && (NXT(1) == '!') && if (memcmp(CUR_PTR, "<!DOCTYPE", 9) == 0) {
(NXT(2) == 'D') && (NXT(3) == 'O') &&
(NXT(4) == 'C') && (NXT(5) == 'T') &&
(NXT(6) == 'Y') && (NXT(7) == 'P') &&
(NXT(8) == 'E')) {
ctxt->inSubset = 1; ctxt->inSubset = 1;
xmlParseDocTypeDecl(ctxt); xmlParseDocTypeDecl(ctxt);
@ -9035,9 +8946,7 @@ xmlParseExtParsedEnt(xmlParserCtxtPtr ctxt) {
* Check for the XMLDecl in the Prolog. * Check for the XMLDecl in the Prolog.
*/ */
GROW; GROW;
if ((RAW == '<') && (NXT(1) == '?') && if ((memcmp(CUR_PTR, "<?xml", 5) == 0) && (IS_BLANK(NXT(5)))) {
(NXT(2) == 'x') && (NXT(3) == 'm') &&
(NXT(4) == 'l') && (IS_BLANK(NXT(5)))) {
/* /*
* Note that we will switch encoding on the fly. * Note that we will switch encoding on the fly.
@ -10653,9 +10562,7 @@ xmlParseCtxtExternalEntity(xmlParserCtxtPtr ctx, const xmlChar *URL,
/* /*
* Parse a possible text declaration first * Parse a possible text declaration first
*/ */
if ((RAW == '<') && (NXT(1) == '?') && if ((memcmp(CUR_PTR, "<?xml", 5) == 0) && (IS_BLANK(NXT(5)))) {
(NXT(2) == 'x') && (NXT(3) == 'm') &&
(NXT(4) == 'l') && (IS_BLANK(NXT(5)))) {
xmlParseTextDecl(ctxt); xmlParseTextDecl(ctxt);
} }
@ -10851,9 +10758,7 @@ xmlParseExternalEntityPrivate(xmlDocPtr doc, xmlParserCtxtPtr oldctxt,
/* /*
* Parse a possible text declaration first * Parse a possible text declaration first
*/ */
if ((RAW == '<') && (NXT(1) == '?') && if ((memcmp(CUR_PTR, "<?xml", 5) == 0) && (IS_BLANK(NXT(5)))) {
(NXT(2) == 'x') && (NXT(3) == 'm') &&
(NXT(4) == 'l') && (IS_BLANK(NXT(5)))) {
xmlParseTextDecl(ctxt); xmlParseTextDecl(ctxt);
} }