applied patch from Alfred Mickautsch for better DTD support. fixed bug

* xmlwriter.c include/libxml/xmlwriter.h doc/* : applied patch from
  Alfred Mickautsch for better DTD support.
* SAX2.c HTMLparser.c parser.c xinclude.c xmllint.c xmlreader.c
  xmlschemas.c: fixed bug #137867 i.e. fixed properly the way
  reference counting is handled in the XML parser which had the
  side effect of removing a lot of hazardous cruft added to try
  to fix the problems associated as they popped up.
* xmlIO.c: FILE * close fixup for stderr/stdout
Daniel
diff --git a/SAX2.c b/SAX2.c
index d27d574..e6e310e 100644
--- a/SAX2.c
+++ b/SAX2.c
@@ -839,8 +839,10 @@
 	    ctxt->disableSAX = 1;
 	    return;
 	}
-	if ((ctxt->dictNames) && (doc != NULL))
+	if ((ctxt->dictNames) && (doc != NULL)) {
 	    doc->dict = ctxt->dict;
+	    xmlDictReference(doc->dict);
+	}
     }
     if ((ctxt->myDoc != NULL) && (ctxt->myDoc->URL == NULL) &&
 	(ctxt->input != NULL) && (ctxt->input->filename != NULL)) {