summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfdrake <fdrake>2002-08-02 19:40:09 +0000
committerfdrake <fdrake>2002-08-02 19:40:09 +0000
commitd0591f8989f4b72e3eeb9175bfa91ed021a1832e (patch)
tree0b14128672259f70e561c1f6b36791ae3751562a
parentdacd0925da4bf3b76ee6ead71c2efd969eef4aec (diff)
downloadlibexpat-d0591f8989f4b72e3eeb9175bfa91ed021a1832e.tar.gz
Define specific return values for the XML_Parse*() functions, and use them
to test all XML_Parse*() return values in the test and sample code. This is binary-compatible with previous Expat 1.95.x releases.
-rw-r--r--examples/elements.c2
-rw-r--r--examples/outline.c2
-rw-r--r--lib/expat.h34
-rw-r--r--tests/runtests.c34
-rwxr-xr-xxmlwf/xmlfile.c4
5 files changed, 49 insertions, 27 deletions
diff --git a/examples/elements.c b/examples/elements.c
index 42f0889..4ed4da6 100644
--- a/examples/elements.c
+++ b/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/examples/outline.c b/examples/outline.c
index 2eeca06..10f6d1d 100644
--- a/examples/outline.c
+++ b/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/lib/expat.h b/lib/expat.h
index 5d1aa89..44c0858 100644
--- a/lib/expat.h
+++ b/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).
-*/
-XMLPARSEAPI(int)
+/* 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.
+*/
+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/tests/runtests.c b/tests/runtests.c
index f62ad5a..aab0816 100644
--- a/tests/runtests.c
+++ b/tests/runtests.c
@@ -55,7 +55,7 @@ START_TEST(test_nul_byte)
char text[] = "<doc>\0</doc>";
/* 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 = "<doc>&#0;</doc>";
/* 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<e/>";
- 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, "<e>%ccd</e>", 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)
" <e/>\n"
"</e>";
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-+"
"</e>";
- 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)
"<?xml version='1.0'?>\n"
"<a>&eee;</a>";
- 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)
"<test a='&foo;'/>";
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/xmlwf/xmlfile.c b/xmlwf/xmlfile.c
index 6bf1535..690be52 100755
--- a/xmlwf/xmlfile.c
+++ b/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);