Add yxml_eof() function to detect unexpected EOF errors
diff --git a/yxml.c b/yxml.c
index 6b7f7ae..901b314 100644
--- a/yxml.c
+++ b/yxml.c
@@ -871,4 +871,11 @@
 }
 
 
+yxml_ret_t yxml_eof(yxml_t *x) {
+	if(!x->afterelem || x->state != YXMLS_misc2)
+		return YXML_EEOF;
+	return YXML_OK;
+}
+
+
 /* vim: set noet sw=4 ts=4: */
diff --git a/yxml.c.in b/yxml.c.in
index b655d5f..3871742 100644
--- a/yxml.c.in
+++ b/yxml.c.in
@@ -267,4 +267,11 @@
 }
 
 
+yxml_ret_t yxml_eof(yxml_t *x) {
+	if(!x->afterelem || x->state != YXMLS_misc2)
+		return YXML_EEOF;
+	return YXML_OK;
+}
+
+
 /* vim: set noet sw=4 ts=4: */
diff --git a/yxml.h b/yxml.h
index 1f0684d..a43ca81 100644
--- a/yxml.h
+++ b/yxml.h
@@ -25,6 +25,7 @@
 
 
 typedef enum {
+	YXML_EEOF        = -7, /* Unexpected EOF                             */
 	YXML_EMULROOT    = -6, /* Document contains more than a single root element */
 	YXML_EREF        = -5, /* Invalid character or entity reference (&whatever;) */
 	YXML_ECLOSE      = -4, /* Close tag does not match open tag (<Tag> .. </OtherTag>) */
@@ -108,4 +109,13 @@
 yxml_ret_t yxml_parse(yxml_t *x, int ch);
 
 
+/* May be called after the last character has been given to yxml_parse().
+ * Returns YXML_OK if the XML document is valid, YXML_EEOF otherwise.  Using
+ * this function isn't really necessary, but can be used to detect documents
+ * that don't end correctly. In particular, an error is returned when the XML
+ * document did not contain a (complete) root element, or when the document
+ * ended while in a comment or processing instruction. */
+yxml_ret_t yxml_eof(yxml_t *x);
+
+
 /* vim: set noet sw=4 ts=4: */