diff --git a/expat/examples/elements.c b/expat/examples/elements.c index 42f0889e..4ed4da6a 100644 --- a/expat/examples/elements.c +++ b/expat/examples/elements.c @@ -37,7 +37,7 @@ main(int argc, char *argv[]) do { size_t len = fread(buf, 1, sizeof(buf), stdin); done = len < sizeof(buf); - if (!XML_Parse(parser, buf, len, done)) { + if (XML_Parse(parser, buf, len, done) == XML_STATUS_ERROR) { fprintf(stderr, "%s at line %d\n", XML_ErrorString(XML_GetErrorCode(parser)), diff --git a/expat/examples/outline.c b/expat/examples/outline.c index 2eeca066..10f6d1db 100644 --- a/expat/examples/outline.c +++ b/expat/examples/outline.c @@ -76,7 +76,7 @@ main(int argc, char *argv[]) } done = feof(stdin); - if (! XML_Parse(p, Buff, len, done)) { + if (XML_Parse(p, Buff, len, done) == XML_STATUS_ERROR) { fprintf(stderr, "Parse error at line %d:\n%s\n", XML_GetCurrentLineNumber(p), XML_ErrorString(XML_GetErrorCode(p))); diff --git a/expat/lib/expat.h b/expat/lib/expat.h index 5d1aa890..44c08581 100644 --- a/expat/lib/expat.h +++ b/expat/lib/expat.h @@ -648,17 +648,39 @@ XML_GetSpecifiedAttributeCount(XML_Parser parser); XMLPARSEAPI(int) XML_GetIdAttributeIndex(XML_Parser parser); -/* Parses some input. Returns 0 if a fatal error is detected. The - last call to XML_Parse must have isFinal true; len may be zero for - this call (or any other). +/* Parses some input. Returns XML_STATUS_ERROR if a fatal error is + detected. The last call to XML_Parse must have isFinal true; len + may be zero for this call (or any other). + + The XML_Status enum gives the possible return values for the + XML_Parse and XML_ParseBuffer functions. Though the return values + for these functions has always been described as a Boolean value, + the implementation, at least for the 1.95.x series, has always + returned exactly one of these values. The preprocessor #defines + are included so this stanza can be added to code that still needs + to support older versions of Expat 1.95.x: + + #ifndef XML_STATUS_OK + #define XML_STATUS_OK 1 + #define XML_STATUS_ERROR 0 + #endif + + Otherwise, the #define hackery is quite ugly and would have been dropped. */ -XMLPARSEAPI(int) +enum XML_Status { + XML_STATUS_ERROR = 0, +#define XML_STATUS_ERROR XML_STATUS_ERROR + XML_STATUS_OK = 1 +#define XML_STATUS_OK XML_STATUS_OK +}; + +XMLPARSEAPI(enum XML_Status) XML_Parse(XML_Parser parser, const char *s, int len, int isFinal); XMLPARSEAPI(void *) XML_GetBuffer(XML_Parser parser, int len); -XMLPARSEAPI(int) +XMLPARSEAPI(enum XML_Status) XML_ParseBuffer(XML_Parser parser, int len, int isFinal); /* Creates an XML_Parser object that can parse an external general diff --git a/expat/tests/runtests.c b/expat/tests/runtests.c index f62ad5a5..aab08169 100644 --- a/expat/tests/runtests.c +++ b/expat/tests/runtests.c @@ -55,7 +55,7 @@ START_TEST(test_nul_byte) char text[] = "\0"; /* test that a NUL byte (in US-ASCII data) is an error */ - if (XML_Parse(parser, text, sizeof(text) - 1, 1)) + if (XML_Parse(parser, text, sizeof(text) - 1, 1) == XML_STATUS_OK) fail("Parser did not report error on NUL-byte."); if (XML_GetErrorCode(parser) != XML_ERROR_INVALID_TOKEN) xml_failure(parser); @@ -68,7 +68,7 @@ START_TEST(test_u0000_char) char *text = ""; /* test that a NUL byte (in US-ASCII data) is an error */ - if (XML_Parse(parser, text, strlen(text), 1)) + if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_OK) fail("Parser did not report error on NUL-byte."); if (XML_GetErrorCode(parser) != XML_ERROR_BAD_CHAR_REF) xml_failure(parser); @@ -80,7 +80,7 @@ START_TEST(test_bom_utf8) /* This test is really just making sure we don't core on a UTF-8 BOM. */ char *text = "\357\273\277"; - if (!XML_Parse(parser, text, strlen(text), 1)) + if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_ERROR) xml_failure(parser); } END_TEST @@ -89,7 +89,7 @@ START_TEST(test_bom_utf16_be) { char text[] = "\376\377\0<\0e\0/\0>"; - if (!XML_Parse(parser, text, sizeof(text) - 1, 1)) + if (XML_Parse(parser, text, sizeof(text) - 1, 1) == XML_STATUS_ERROR) xml_failure(parser); } END_TEST @@ -98,7 +98,7 @@ START_TEST(test_bom_utf16_le) { char text[] = "\377\376<\0e\0/\0>\0"; - if (!XML_Parse(parser, text, sizeof(text) - 1, 1)) + if (XML_Parse(parser, text, sizeof(text) - 1, 1) == XML_STATUS_ERROR) xml_failure(parser); } END_TEST @@ -129,7 +129,7 @@ run_character_check(XML_Char *text, XML_Char *expected) CharData_Init(&storage); XML_SetUserData(parser, &storage); XML_SetCharacterDataHandler(parser, accumulate_characters); - if (!XML_Parse(parser, text, strlen(text), 1)) + if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_ERROR) xml_failure(parser); CharData_CheckXMLChars(&storage, expected); } @@ -142,7 +142,7 @@ run_attribute_check(XML_Char *text, XML_Char *expected) CharData_Init(&storage); XML_SetUserData(parser, &storage); XML_SetStartElementHandler(parser, accumulate_attribute); - if (!XML_Parse(parser, text, strlen(text), 1)) + if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_ERROR) xml_failure(parser); CharData_CheckXMLChars(&storage, expected); } @@ -211,7 +211,7 @@ START_TEST(test_illegal_utf8) for (i = 128; i <= 255; ++i) { sprintf(text, "%ccd", i); - if (XML_Parse(parser, text, strlen(text), 1)) { + if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_OK) { sprintf(text, "expected token error for '%c' (ordinal %d) in UTF-8 text", i, i); @@ -238,7 +238,7 @@ START_TEST(test_utf16) "\000<\000d\000o\000c\000 \000a\000=\000'\0001\0002\0003\000'" "\000>\000s\000o\000m\000e\000 \000t\000e\000x\000t\000<\000/" "\000d\000o\000c\000>"; - if (!XML_Parse(parser, text, sizeof(text) - 1, 1)) + if (XML_Parse(parser, text, sizeof(text) - 1, 1) == XML_STATUS_ERROR) xml_failure(parser); } END_TEST @@ -271,7 +271,7 @@ START_TEST(test_line_count) " \n" ""; int lineno; - if (!XML_Parse(parser, text, strlen(text), 1)) + if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_ERROR) xml_failure(parser); lineno = XML_GetCurrentLineNumber(parser); if (lineno != 3) { @@ -312,7 +312,7 @@ START_TEST(test_really_long_lines) "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" ""; - if (!XML_Parse(parser, text, strlen(text), 1)) + if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_ERROR) xml_failure(parser); } END_TEST @@ -339,7 +339,7 @@ START_TEST(test_end_element_events) CharData_Init(&storage); XML_SetUserData(parser, &storage); XML_SetEndElementHandler(parser, end_element_event_handler); - if (!XML_Parse(parser, text, strlen(text), 1)) + if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_ERROR) xml_failure(parser); CharData_CheckString(&storage, expected); } @@ -452,7 +452,7 @@ START_TEST(test_attr_whitespace_normalization) XML_SetStartElementHandler(parser, check_attr_contains_normalized_whitespace); - if (!XML_Parse(parser, text, strlen(text), 1)) + if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_ERROR) xml_failure(parser); } END_TEST @@ -469,7 +469,7 @@ START_TEST(test_xmldecl_misplaced) "\n" "&eee;"; - if (!XML_Parse(parser, text, strlen(text), 1)) { + if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_ERROR) { if (XML_GetErrorCode(parser) != XML_ERROR_MISPLACED_XML_PI) xml_failure(parser); } @@ -503,7 +503,7 @@ START_TEST(test_unknown_encoding_internal_entity) ""; XML_SetUnknownEncodingHandler(parser, UnknownEncodingHandler, NULL); - if (!XML_Parse(parser, text, strlen(text), 1)) + if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_ERROR) xml_failure(parser); } END_TEST @@ -575,7 +575,7 @@ START_TEST(test_return_ns_triplet) XML_SetReturnNSTriplet(parser, 1); XML_SetUserData(parser, elemstr); XML_SetElementHandler(parser, triplet_start_checker, triplet_end_checker); - if (!XML_Parse(parser, text, strlen(text), 1)) + if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_ERROR) xml_failure(parser); } END_TEST @@ -612,7 +612,7 @@ run_ns_tagname_overwrite_test(char *text, char *result) XML_SetUserData(parser, &storage); XML_SetElementHandler(parser, overwrite_start_checker, overwrite_end_checker); - if (!XML_Parse(parser, text, strlen(text), 1)) + if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_ERROR) xml_failure(parser); CharData_CheckString(&storage, result); } diff --git a/expat/xmlwf/xmlfile.c b/expat/xmlwf/xmlfile.c index 6bf1535f..690be523 100755 --- a/expat/xmlwf/xmlfile.c +++ b/expat/xmlwf/xmlfile.c @@ -66,7 +66,7 @@ processFile(const void *data, size_t size, { XML_Parser parser = ((PROCESS_ARGS *)args)->parser; int *retPtr = ((PROCESS_ARGS *)args)->retPtr; - if (!XML_Parse(parser, data, size, 1)) { + if (XML_Parse(parser, data, size, 1) == XML_STATUS_ERROR) { reportError(parser, filename); *retPtr = 0; } @@ -167,7 +167,7 @@ processStream(const XML_Char *filename, XML_Parser parser) close(fd); return 0; } - if (!XML_ParseBuffer(parser, nread, nread == 0)) { + if (XML_ParseBuffer(parser, nread, nread == 0) == XML_STATUS_ERROR) { reportError(parser, filename != NULL ? filename : "STDIN"); if (filename != NULL) close(fd);