added 2 new configure option: --with-reader --with-sax1 to allow removing

* Makefile.am SAX.c SAX2.c configure.in globals.c parser.c
  parserInternals.c testReader.c testSAX.c xmlIO.c xmllint.c
  xmlreader.c example/gjobread.c include/libxml/xmlversion.h.in:
  added 2 new configure option: --with-reader --with-sax1
  to allow removing the reader or non-xmlReadxxx() interfaces.
Daniel
diff --git a/ChangeLog b/ChangeLog
index 404a920..77773a7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Tue Sep 30 02:38:16 CEST 2003 Daniel Veillard <daniel@veillard.com>
+
+	* Makefile.am SAX.c SAX2.c configure.in globals.c parser.c
+	  parserInternals.c testReader.c testSAX.c xmlIO.c xmllint.c
+	  xmlreader.c example/gjobread.c include/libxml/xmlversion.h.in:
+	  added 2 new configure option: --with-reader --with-sax1
+	  to allow removing the reader or non-xmlReadxxx() interfaces.
+
 Mon Sep 29 19:58:26 CEST 2003 Daniel Veillard <daniel@veillard.com>
 
 	* configure.in entities.c tree.c valid.c xmllint.c
diff --git a/Makefile.am b/Makefile.am
index 8fb810b..3263f4d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -122,7 +122,7 @@
 
 testall : tests SVGtests SAXtests
 
-tests: XMLtests XMLenttests NStests Readertests SAXtests @TEST_HTML@ @TEST_VALID@ URItests @TEST_XPATH@ @TEST_XPTR@ @TEST_XINCLUDE@ @TEST_C14N@ @TEST_DEBUG@ @TEST_CATALOG@ @TEST_REGEXPS@ @TEST_SCHEMAS@ @TEST_THREADS@ Timingtests @TEST_VTIME@
+tests: XMLtests XMLenttests NStests Readertests @TEST_SAX@ @TEST_HTML@ @TEST_VALID@ URItests @TEST_XPATH@ @TEST_XPTR@ @TEST_XINCLUDE@ @TEST_C14N@ @TEST_DEBUG@ @TEST_CATALOG@ @TEST_REGEXPS@ @TEST_SCHEMAS@ @TEST_THREADS@ Timingtests @TEST_VTIME@
 	@(if [ "@PYTHON_SUBDIR@" != "" ] ; then cd python ; $(MAKE) tests ; fi)
 
 valgrind:
diff --git a/SAX.c b/SAX.c
index b4a1aac..0ff2017 100644
--- a/SAX.c
+++ b/SAX.c
@@ -28,6 +28,7 @@
 #include <libxml/globals.h>
 #include <libxml/SAX2.h>
 
+#ifdef LIBXML_SAX1_ENABLED
 /**
  * initxmlDefaultSAXHandler:
  * @hdlr:  the SAX handler
@@ -75,6 +76,7 @@
 
     hdlr->initialized = 1;
 }
+#endif /* LIBXML_SAX1_ENABLED */
 
 #ifdef LIBXML_HTML_ENABLED
 
diff --git a/SAX2.c b/SAX2.c
index 450db5b..2f97d5e 100644
--- a/SAX2.c
+++ b/SAX2.c
@@ -857,6 +857,7 @@
     }
 }
 
+#if defined(LIBXML_SAX1_ENABLED) || defined(LIBXML_HTML_ENABLED)
 /**
  * xmlSAX2AttributeInternal:
  * @ctx: the user data (XML parser context)
@@ -1588,8 +1589,8 @@
 #endif
     nodePop(ctxt);
 }
+#endif /* LIBXML_SAX1_ENABLED || LIBXML_HTML_ENABLE */
 
-int nb_interned = 0;
 /*
  * xmlSAX2TextNode:
  * @ctxt:  the parser context
@@ -2429,6 +2430,7 @@
 
 static int xmlSAX2DefaultVersionValue = 2;
 
+#ifdef LIBXML_SAX1_ENABLED
 /**
  * xmlSAXDefaultVersion:
  * @version:  the version, 1 or 2
@@ -2450,6 +2452,7 @@
     xmlSAX2DefaultVersionValue = version;
     return(ret);
 }
+#endif /* LIBXML_SAX1_ENABLED */
 
 /**
  * xmlSAXVersion:
@@ -2464,16 +2467,18 @@
 xmlSAXVersion(xmlSAXHandler *hdlr, int version)
 {
     if (hdlr == NULL) return(-1);
-    if (version == 1) {
-	hdlr->startElement = xmlSAX2StartElement;
-	hdlr->endElement = xmlSAX2EndElement;
-	hdlr->initialized = 1;
-    } else if (version == 2) {
+    if (version == 2) {
 	hdlr->startElement = NULL;
 	hdlr->endElement = NULL;
 	hdlr->startElementNs = xmlSAX2StartElementNs;
 	hdlr->endElementNs = xmlSAX2EndElementNs;
 	hdlr->initialized = XML_SAX2_MAGIC;
+#ifdef LIBXML_SAX1_ENABLED
+    } else if (version == 1) {
+	hdlr->startElement = xmlSAX2StartElement;
+	hdlr->endElement = xmlSAX2EndElement;
+	hdlr->initialized = 1;
+#endif /* LIBXML_SAX1_ENABLED */
     } else
         return(-1);
     hdlr->internalSubset = xmlSAX2InternalSubset;
@@ -2533,7 +2538,9 @@
 void
 xmlDefaultSAXHandlerInit(void)
 {
+#ifdef LIBXML_SAX1_ENABLED
     xmlSAXVersion((xmlSAXHandlerPtr) &xmlDefaultSAXHandler, 1);
+#endif /* LIBXML_SAX1_ENABLED */
 }
 
 #ifdef LIBXML_HTML_ENABLED
diff --git a/configure.in b/configure.in
index 16176cc..1ef229d 100644
--- a/configure.in
+++ b/configure.in
@@ -623,6 +623,37 @@
 fi
 AC_SUBST(WITH_LEGACY)
 
+AC_ARG_WITH(reader,
+[  --with-reader           add the xmlReader parsing interface (on)])
+if test "$with_minimum" = "yes" -a "$with_reader" = ""
+then
+    with_reader=no
+fi
+if test "$with_reader" = "no" ; then
+    echo Disabling the xmlReader parsing interface
+    WITH_READER=0
+else    
+    WITH_READER=1
+fi
+AC_SUBST(WITH_READER)
+
+AC_ARG_WITH(sax1,
+[  --with-sax1             add the older SAX1 interface (on)])
+if test "$with_minimum" = "yes" -a "$with_sax1" = ""
+then
+    with_sax1=no
+fi
+if test "$with_sax1" = "no" ; then
+    echo Disabling the older SAX1 interface
+    WITH_SAX1=0
+    TEST_SAX=
+else    
+    WITH_SAX1=1
+    TEST_SAX=SAXtests
+fi
+AC_SUBST(WITH_SAX1)
+AC_SUBST(TEST_SAX)
+
 AC_ARG_WITH(valid,
 [  --with-valid            add the DTD validation support (on)])
 if test "$with_minimum" = "yes" -a "$with_valid" = ""
diff --git a/example/gjobread.c b/example/gjobread.c
index a447959..b192bf4 100644
--- a/example/gjobread.c
+++ b/example/gjobread.c
@@ -184,11 +184,18 @@
     xmlNsPtr ns;
     xmlNodePtr cur;
 
+#ifdef LIBXML_SAX1_ENABLED
     /*
      * build an XML tree from a the file;
      */
     doc = xmlParseFile(filename);
     if (doc == NULL) return(NULL);
+#else
+    /*
+     * the library has been compiled without some of the old interfaces
+     */
+    return(NULL);
+#endif /* LIBXML_SAX1_ENABLED */
 
     /*
      * Check the document is of the right kind
diff --git a/globals.c b/globals.c
index 070c1e4..140bc89 100644
--- a/globals.c
+++ b/globals.c
@@ -325,6 +325,7 @@
 int xmlSaveNoEmptyTags = 0;
 int xmlSaveNoEmptyTagsThrDef = 0;
 
+#ifdef LIBXML_SAX1_ENABLED
 /**
  * xmlDefaultSAXHandler:
  *
@@ -360,6 +361,7 @@
     xmlSAX2ExternalSubset,
     0,
 };
+#endif /* LIBXML_SAX1_ENABLED */
 
 /**
  * xmlDefaultSAXLocator:
@@ -483,7 +485,9 @@
     gs->oldXMLWDcompatibility = 0;
     gs->xmlBufferAllocScheme = xmlBufferAllocSchemeThrDef;
     gs->xmlDefaultBufferSize = xmlDefaultBufferSizeThrDef;
+#ifdef LIBXML_SAX1_ENABLED
     initxmlDefaultSAXHandler(&gs->xmlDefaultSAXHandler, 1);
+#endif /* LIBXML_SAX1_ENABLED */
     gs->xmlDefaultSAXLocator.getPublicId = xmlSAX2GetPublicId;
     gs->xmlDefaultSAXLocator.getSystemId = xmlSAX2GetSystemId;
     gs->xmlDefaultSAXLocator.getLineNumber = xmlSAX2GetLineNumber;
@@ -674,6 +678,7 @@
     return ret;
 }
 
+#ifdef LIBXML_SAX1_ENABLED
 #undef	xmlDefaultSAXHandler
 xmlSAXHandlerV1 *
 __xmlDefaultSAXHandler(void) {
@@ -682,6 +687,7 @@
     else
 	return (&xmlGetGlobalState()->xmlDefaultSAXHandler);
 }
+#endif /* LIBXML_SAX1_ENABLED */
 
 #undef	xmlDefaultSAXLocator
 xmlSAXLocator *
diff --git a/include/libxml/xmlversion.h.in b/include/libxml/xmlversion.h.in
index cc4be5e..ee09346 100644
--- a/include/libxml/xmlversion.h.in
+++ b/include/libxml/xmlversion.h.in
@@ -102,6 +102,24 @@
 #endif
 
 /**
+ * LIBXML_READER_ENABLED:
+ *
+ * Whether the xmlReader parsing interface is configured in
+ */
+#if @WITH_READER@
+#define LIBXML_READER_ENABLED
+#endif
+
+/**
+ * LIBXML_SAX1_ENABLED:
+ *
+ * Whether the older SAX1 interface is configured in
+ */
+#if @WITH_SAX1@
+#define LIBXML_SAX1_ENABLED
+#endif
+
+/**
  * LIBXML_FTP_ENABLED:
  *
  * Whether the FTP support is configured in
diff --git a/parser.c b/parser.c
index 438dd3c..9e34792 100644
--- a/parser.c
+++ b/parser.c
@@ -111,9 +111,11 @@
 		      void *user_data, int depth, const xmlChar *URL,
 		      const xmlChar *ID, xmlNodePtr *list);
 
+#ifdef LIBXML_LEGACY_ENABLED
 static void
 xmlAddEntityReference(xmlEntityPtr ent, xmlNodePtr firstNode,
                       xmlNodePtr lastNode);
+#endif /* LIBXML_LEGACY_ENABLED */
 
 static xmlParserErrors
 xmlParseBalancedChunkMemoryInternal(xmlParserCtxtPtr oldctxt,
@@ -520,16 +522,19 @@
 static void
 xmlDetectSAX2(xmlParserCtxtPtr ctxt) {
     if (ctxt == NULL) return;
+#ifdef LIBXML_SAX1_ENABLED
     if ((ctxt->sax) &&  (ctxt->sax->initialized == XML_SAX2_MAGIC) &&
         ((ctxt->sax->startElementNs != NULL) ||
          (ctxt->sax->endElementNs != NULL))) ctxt->sax2 = 1;
+#else
+    ctxt->sax2 = 1;
+#endif /* LIBXML_SAX1_ENABLED */
 
     ctxt->str_xml = xmlDictLookup(ctxt->dict, BAD_CAST "xml", 3);
     ctxt->str_xmlns = xmlDictLookup(ctxt->dict, BAD_CAST "xmlns", 5);
     ctxt->str_xml_ns = xmlDictLookup(ctxt->dict, XML_XML_NAMESPACE, 36);
 }
 
-#ifdef SAX2
 typedef struct _xmlDefAttrs xmlDefAttrs;
 typedef xmlDefAttrs *xmlDefAttrsPtr;
 struct _xmlDefAttrs {
@@ -537,7 +542,6 @@
     int maxAttrs;       /* the size of the array */
     const xmlChar *values[4]; /* array of localname/prefix/values */
 };
-#endif
 
 /**
  * xmlAddDefAttrs:
@@ -5884,8 +5888,10 @@
 					list = list->next;
 			 	    }
 				    list = ent->children;
+#ifdef LIBXML_LEGACY_ENABLED
 				    if (ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)
 				      xmlAddEntityReference(ent, list, NULL);
+#endif /* LIBXML_LEGACY_ENABLED */
 				}
 			    } else {
 				ent->owner = 1;
@@ -5939,8 +5945,10 @@
 				break;
 			    cur = cur->next;
 			}
+#ifdef LIBXML_LEGACY_ENABLED
 			if (ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)			      
 			  xmlAddEntityReference(ent, firstChild, nw);
+#endif /* LIBXML_LEGACY_ENABLED */
 		    } else if (list == NULL) {
 			xmlNodePtr nw = NULL, cur, next, last,
 			           firstChild = NULL;
@@ -5972,8 +5980,10 @@
 			    cur = next;
 			}
 			ent->owner = 1;
+#ifdef LIBXML_LEGACY_ENABLED
 			if (ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)			      
 			  xmlAddEntityReference(ent, firstChild, nw);
+#endif /* LIBXML_LEGACY_ENABLED */
 		    } else {
 			/*
 			 * the name change is to avoid coalescing of the
@@ -6738,6 +6748,7 @@
     NEXT;
 }
 
+#ifdef LIBXML_SAX1_ENABLED
 /**
  * xmlParseAttribute:
  * @ctxt:  an XML parser context
@@ -7079,6 +7090,7 @@
 xmlParseEndTag(xmlParserCtxtPtr ctxt) {
     xmlParseEndTag1(ctxt, 0);
 }
+#endif /* LIBXML_SAX1_ENABLED */
 
 /************************************************************************
  *									*
@@ -8246,10 +8258,14 @@
 	spacePush(ctxt, *ctxt->space);
 
     line = ctxt->input->line;
+#ifdef LIBXML_SAX1_ENABLED
     if (ctxt->sax2)
+#endif /* LIBXML_SAX1_ENABLED */
         name = xmlParseStartTag2(ctxt, &prefix, &URI);
+#ifdef LIBXML_SAX1_ENABLED
     else
 	name = xmlParseStartTag(ctxt);
+#endif /* LIBXML_SAX1_ENABLED */
     if (name == NULL) {
 	spacePop(ctxt);
         return;
@@ -8277,10 +8293,12 @@
 	    if ((ctxt->sax != NULL) && (ctxt->sax->endElementNs != NULL) &&
 		(!ctxt->disableSAX))
 		ctxt->sax->endElementNs(ctxt->userData, name, prefix, URI);
+#ifdef LIBXML_SAX1_ENABLED
 	} else {
 	    if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL) &&
 		(!ctxt->disableSAX))
 		ctxt->sax->endElement(ctxt->userData, name);
+#endif /* LIBXML_SAX1_ENABLED */
 	}
 	namePop(ctxt);
 	spacePop(ctxt);
@@ -8357,8 +8375,11 @@
     if (ctxt->sax2) {
 	xmlParseEndTag2(ctxt, prefix, URI, line, ctxt->nsNr - nsNr);
 	namePop(ctxt);
-    } else
+    }
+#ifdef LIBXML_SAX1_ENABLED
+      else
 	xmlParseEndTag1(ctxt, line);
+#endif /* LIBXML_SAX1_ENABLED */
 
     /*
      * Capture end position and add node
@@ -9469,10 +9490,14 @@
 		    spacePush(ctxt, -1);
 		else
 		    spacePush(ctxt, *ctxt->space);
+#ifdef LIBXML_SAX1_ENABLED
 		if (ctxt->sax2)
+#endif /* LIBXML_SAX1_ENABLED */
 		    name = xmlParseStartTag2(ctxt, &prefix, &URI);
+#ifdef LIBXML_SAX1_ENABLED
 		else
 		    name = xmlParseStartTag(ctxt);
+#endif /* LIBXML_SAX1_ENABLED */
 		if (name == NULL) {
 		    spacePop(ctxt);
 		    ctxt->instate = XML_PARSER_EOF;
@@ -9503,11 +9528,13 @@
 			    (!ctxt->disableSAX))
 			    ctxt->sax->endElementNs(ctxt->userData, name,
 			                            prefix, URI);
+#ifdef LIBXML_SAX1_ENABLED
 		    } else {
 			if ((ctxt->sax != NULL) &&
 			    (ctxt->sax->endElement != NULL) &&
 			    (!ctxt->disableSAX))
 			    ctxt->sax->endElement(ctxt->userData, name);
+#endif /* LIBXML_SAX1_ENABLED */
 		    }
 		    spacePop(ctxt);
 		    if (ctxt->nameNr == 0) {
@@ -9528,8 +9555,10 @@
 		}
 		if (ctxt->sax2)
 		    nameNsPush(ctxt, name, prefix, URI, ctxt->nsNr - nsNr);
+#ifdef LIBXML_SAX1_ENABLED
 		else
 		    namePush(ctxt, name);
+#endif /* LIBXML_SAX1_ENABLED */
 
 		ctxt->instate = XML_PARSER_CONTENT;
                 break;
@@ -9641,8 +9670,11 @@
 		           (void *) ctxt->pushTab[ctxt->nameNr * 3 - 2], 0,
 		       (int) (long) ctxt->pushTab[ctxt->nameNr * 3 - 1]);
 		    nameNsPop(ctxt);
-		} else
+		}
+#ifdef LIBXML_SAX1_ENABLED
+		  else
 		    xmlParseEndTag1(ctxt, 0);
+#endif /* LIBXML_SAX1_ENABLED */
 		if (ctxt->nameNr == 0) {
 		    ctxt->instate = XML_PARSER_EPILOG;
 		} else {
@@ -10179,7 +10211,9 @@
 	return(NULL);
     }
     if (sax != NULL) {
+#ifdef LIBXML_SAX1_ENABLED
 	if (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler)
+#endif /* LIBXML_SAX1_ENABLED */
 	    xmlFree(ctxt->sax);
 	ctxt->sax = (xmlSAXHandlerPtr) xmlMalloc(sizeof(xmlSAXHandler));
 	if (ctxt->sax == NULL) {
@@ -10272,7 +10306,9 @@
 	return(NULL);
     }
     if (sax != NULL) {
+#ifdef LIBXML_SAX1_ENABLED
 	if (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler)
+#endif /* LIBXML_SAX1_ENABLED */
 	    xmlFree(ctxt->sax);
 	ctxt->sax = (xmlSAXHandlerPtr) xmlMalloc(sizeof(xmlSAXHandler));
 	if (ctxt->sax == NULL) {
@@ -10887,6 +10923,7 @@
     return(ret);
 }
 
+#ifdef LIBXML_SAX1_ENABLED
 /**
  * xmlParseExternalEntity:
  * @doc:  the document the chunk pertains to
@@ -10940,6 +10977,7 @@
     return xmlParseBalancedChunkMemoryRecover( doc, sax, user_data,
                                                 depth, string, lst, 0 );
 }
+#endif /* LIBXML_SAX1_ENABLED */
 
 /**
  * xmlParseBalancedChunkMemoryInternal:
@@ -11090,6 +11128,7 @@
     return(ret);
 }
 
+#ifdef LIBXML_SAX1_ENABLED
 /**
  * xmlParseBalancedChunkMemoryRecover:
  * @doc:  the document the chunk pertains to
@@ -11300,6 +11339,7 @@
 xmlParseEntity(const char *filename) {
     return(xmlSAXParseEntity(NULL, filename));
 }
+#endif /* LIBXML_SAX1_ENABLED */
 
 /**
  * xmlCreateEntityParserCtxt:
@@ -11385,9 +11425,7 @@
 
     ctxt = xmlNewParserCtxt();
     if (ctxt == NULL) {
-	if (xmlDefaultSAXHandler.error != NULL) {
-	    xmlDefaultSAXHandler.error(NULL, "out of memory\n");
-	}
+	xmlErrMemory(NULL, "cannot allocate parser context");
 	return(NULL);
     }
 
@@ -11407,6 +11445,7 @@
     return(ctxt);
 }
 
+#ifdef LIBXML_SAX1_ENABLED
 /**
  * xmlSAXParseFileWithData:
  * @sax:  the SAX handler block
@@ -11598,7 +11637,9 @@
     
     ctxt = xmlCreateFileParserCtxt(filename);
     if (ctxt == NULL) return -1;
+#ifdef LIBXML_SAX1_ENABLED
     if (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler)
+#endif /* LIBXML_SAX1_ENABLED */
 	xmlFree(ctxt->sax);
     ctxt->sax = sax;
     xmlDetectSAX2(ctxt);
@@ -11622,6 +11663,7 @@
     
     return ret;
 }
+#endif /* LIBXML_SAX1_ENABLED */
 
 /************************************************************************
  *									*
@@ -11677,6 +11719,7 @@
     return(ctxt);
 }
 
+#ifdef LIBXML_SAX1_ENABLED
 /**
  * xmlSAXParseMemoryWithData:
  * @sax:  the SAX handler block
@@ -11822,6 +11865,7 @@
     
     return ret;
 }
+#endif /* LIBXML_SAX1_ENABLED */
 
 /**
  * xmlCreateDocParserCtxt:
@@ -11841,6 +11885,7 @@
     return(xmlCreateMemoryParserCtxt((const char *)cur, len));
 }
 
+#ifdef LIBXML_SAX1_ENABLED
 /**
  * xmlSAXParseDoc:
  * @sax:  the SAX handler block
@@ -11898,7 +11943,9 @@
 xmlParseDoc(xmlChar *cur) {
     return(xmlSAXParseDoc(NULL, cur, 0));
 }
+#endif /* LIBXML_SAX1_ENABLED */
 
+#ifdef LIBXML_LEGACY_ENABLED
 /************************************************************************
  *									*
  * 	Specific function to keep track of entities references		*
@@ -11937,6 +11984,7 @@
 {
     xmlEntityRefFunc = func;
 }
+#endif /* LIBXML_LEGACY_ENABLED */
 
 /************************************************************************
  *									*
@@ -12175,6 +12223,7 @@
         options -= XML_PARSE_DTDVALID;
     } else
         ctxt->validate = 0;
+#ifdef LIBXML_SAX1_ENABLED
     if (options & XML_PARSE_SAX1) {
         ctxt->sax->startElement = xmlSAX2StartElement;
         ctxt->sax->endElement = xmlSAX2EndElement;
@@ -12183,6 +12232,7 @@
         ctxt->sax->initialized = 1;
         options -= XML_PARSE_SAX1;
     }
+#endif /* LIBXML_SAX1_ENABLED */
     if (options & XML_PARSE_NODICT) {
         ctxt->dictNames = 0;
         options -= XML_PARSE_NODICT;
diff --git a/parserInternals.c b/parserInternals.c
index 0ab1c81..b767ed5 100644
--- a/parserInternals.c
+++ b/parserInternals.c
@@ -2369,8 +2369,12 @@
     if (ctxt->encoding != NULL) xmlFree((char *) ctxt->encoding);
     if (ctxt->extSubURI != NULL) xmlFree((char *) ctxt->extSubURI);
     if (ctxt->extSubSystem != NULL) xmlFree((char *) ctxt->extSubSystem);
+#ifdef LIBXML_SAX1_ENABLED
     if ((ctxt->sax != NULL) &&
         (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler))
+#else
+    if (ctxt->sax != NULL)
+#endif /* LIBXML_SAX1_ENABLED */
         xmlFree(ctxt->sax);
     if (ctxt->directory != NULL) xmlFree((char *) ctxt->directory);
     if (ctxt->vctxt.nodeTab != NULL) xmlFree(ctxt->vctxt.nodeTab);
diff --git a/testReader.c b/testReader.c
index 7b19bb2..a874250 100644
--- a/testReader.c
+++ b/testReader.c
@@ -8,6 +8,7 @@
 
 #include "libxml.h"
 
+#ifdef LIBXML_READER_ENABLED
 #include <string.h>
 #include <stdarg.h>
 
@@ -130,3 +131,9 @@
 
     return(0);
 }
+#else
+int main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
+    printf("%s : xmlReader parser support not compiled in\n", argv[0]);
+    return(0);
+}
+#endif /* LIBXML_READER_ENABLED */
diff --git a/testSAX.c b/testSAX.c
index 0a742a2..edd6d6a 100644
--- a/testSAX.c
+++ b/testSAX.c
@@ -8,6 +8,7 @@
 
 #include "libxml.h"
 
+#ifdef LIBXML_SAX1_ENABLED
 #include <string.h>
 #include <stdarg.h>
 
@@ -973,3 +974,9 @@
 
     return(0);
 }
+#else
+int main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
+    printf("%s : SAX1 parsing support not compiled in\n", argv[0]);
+    return(0);
+}
+#endif /* LIBXML_SAX1_ENABLED */
diff --git a/xmlIO.c b/xmlIO.c
index c1eb358..26203a6 100644
--- a/xmlIO.c
+++ b/xmlIO.c
@@ -2781,9 +2781,12 @@
 
 	canonicFilename = (char *) xmlCanonicPath((const xmlChar *) URL);
 	if (canonicFilename == NULL) {
-	    if (xmlDefaultSAXHandler.error != NULL) {
-		xmlDefaultSAXHandler.error(NULL, "out of memory\n");
-	    }
+#if 0
+	    xmlErrMemory(NULL, "failed to load entity");
+#else
+            xmlGenericError(xmlGenericErrorContext,
+		    "Memory allocation failed ! : failed to load entity\n");
+#endif
 	    return(NULL);
 	}
 
diff --git a/xmllint.c b/xmllint.c
index 981c1a1..fad050a 100644
--- a/xmllint.c
+++ b/xmllint.c
@@ -149,9 +149,13 @@
 static int catalogs = 0;
 static int nocatalogs = 0;
 #endif
+#ifdef LIBXML_READER_ENABLED
 static int stream = 0;
+#endif /* LIBXML_READER_ENABLED */
 static int chkregister = 0;
+#ifdef LIBXML_SAX1_ENABLED
 static int sax1 = 0;
+#endif /* LIBXML_SAX1_ENABLED */
 static int options = 0;
 
 /*
@@ -586,6 +590,7 @@
   }
 }
 
+#ifdef LIBXML_READER_ENABLED
 /************************************************************************
  * 									*
  * 			Stream Test processing				*
@@ -728,6 +733,7 @@
     }
 #endif
 }
+#endif /* LIBXML_READER_ENABLED */
 
 /************************************************************************
  * 									*
@@ -1302,7 +1308,9 @@
     printf("\t--shell : run a navigating shell\n");
     printf("\t--debugent : debug the entities defined in the document\n");
 #else
+#ifdef LIBXML_READER_ENABLED
     printf("\t--debug : dump the nodes content when using --stream\n");
+#endif /* LIBXML_READER_ENABLED */
 #endif
 #ifdef LIBXML_TREE_ENABLED
     printf("\t--copy : used to test the internal copy implementation\n");
@@ -1357,7 +1365,9 @@
 #endif
     printf("\t--loaddtd : fetch external DTD\n");
     printf("\t--dtdattr : loaddtd + populate the tree with inherited attributes \n");
+#ifdef LIBXML_READER_ENABLED
     printf("\t--stream : use the streaming interface to process very large files\n");
+#endif /* LIBXML_READER_ENABLED */
     printf("\t--chkregister : verify the node registration code\n");
 #ifdef LIBXML_SCHEMAS_ENABLED
     printf("\t--relaxng schema : do RelaxNG validation against the schema\n");
@@ -1583,14 +1593,18 @@
 #endif /* LIBXML_OUTPUT_ENABLED */
 	     xmlKeepBlanksDefault(0);
 	}
+#ifdef LIBXML_READER_ENABLED
 	else if ((!strcmp(argv[i], "-stream")) ||
 	         (!strcmp(argv[i], "--stream"))) {
 	     stream++;
 	}
+#endif /* LIBXML_READER_ENABLED */
+#ifdef LIBXML_SAX1_ENABLED
 	else if ((!strcmp(argv[i], "-sax1")) ||
 	         (!strcmp(argv[i], "--sax1"))) {
 	     sax1++;
 	}
+#endif /* LIBXML_SAX1_ENABLED */
 	else if ((!strcmp(argv[i], "-chkregister")) ||
 	         (!strcmp(argv[i], "--chkregister"))) {
 	     chkregister++;
@@ -1632,10 +1646,12 @@
     }
 #endif
 
+#ifdef LIBXML_SAX1_ENABLED
     if (sax1)
         xmlSAXDefaultVersion(1);
     else
         xmlSAXDefaultVersion(2);
+#endif /* LIBXML_SAX1_ENABLED */
 
     if (chkregister) {
 	xmlRegisterNodeDefault(registerNode);
@@ -1671,7 +1687,11 @@
     }
 
 #ifdef LIBXML_SCHEMAS_ENABLED
-    if ((relaxng != NULL) && (stream == 0)) {
+    if ((relaxng != NULL)
+#ifdef LIBXML_READER_ENABLED
+        && (stream == 0)
+#endif /* LIBXML_READER_ENABLED */
+	) {
 	xmlRelaxNGParserCtxtPtr ctxt;
 
         /* forces loading the DTDs */
@@ -1759,20 +1779,26 @@
 		xmlParserCtxtPtr ctxt = NULL;
 
 		for (acount = 0;acount < repeat;acount++) {
+#ifdef LIBXML_READER_ENABLED
 		    if (stream != 0)
 			streamFile(argv[i]);
 		    else {
+#endif /* LIBXML_READER_ENABLED */
 		        if (ctxt == NULL)
 			    ctxt = xmlNewParserCtxt();
 			parseAndPrintFile(argv[i], ctxt);
+#ifdef LIBXML_READER_ENABLED
 		    }
+#endif /* LIBXML_READER_ENABLED */
 		}
 		if (ctxt != NULL)
 		    xmlFreeParserCtxt(ctxt);
 	    } else {
+#ifdef LIBXML_READER_ENABLED
 		if (stream != 0)
 		    streamFile(argv[i]);
 		else
+#endif /* LIBXML_READER_ENABLED */
 		    parseAndPrintFile(argv[i], NULL);
 	    }
 	    files ++;
diff --git a/xmlreader.c b/xmlreader.c
index 2900a4c..662ee26 100644
--- a/xmlreader.c
+++ b/xmlreader.c
@@ -21,6 +21,7 @@
 #define IN_LIBXML
 #include "libxml.h"
 
+#ifdef LIBXML_READER_ENABLED
 #include <string.h> /* for memset() only ! */
 #include <stdarg.h>
 
@@ -1501,20 +1502,24 @@
 		"xmlNewTextReader : malloc failed\n");
 	return(NULL);
     }
-    memcpy(ret->sax, &xmlDefaultSAXHandler, sizeof(xmlSAXHandler));
+    xmlSAXVersion(ret->sax, 2);
     ret->startElement = ret->sax->startElement;
     ret->sax->startElement = xmlTextReaderStartElement;
     ret->endElement = ret->sax->endElement;
     ret->sax->endElement = xmlTextReaderEndElement;
+#ifdef LIBXML_SAX1_ENABLED
     if (ret->sax->initialized == XML_SAX2_MAGIC) {
+#endif /* LIBXML_SAX1_ENABLED */
 	ret->startElementNs = ret->sax->startElementNs;
 	ret->sax->startElementNs = xmlTextReaderStartElementNs;
 	ret->endElementNs = ret->sax->endElementNs;
 	ret->sax->endElementNs = xmlTextReaderEndElementNs;
+#ifdef LIBXML_SAX1_ENABLED
     } else {
 	ret->startElementNs = NULL;
 	ret->endElementNs = NULL;
     }
+#endif /* LIBXML_SAX1_ENABLED */
     ret->characters = ret->sax->characters;
     ret->sax->characters = xmlTextReaderCharacters;
     ret->sax->ignorableWhitespace = xmlTextReaderCharacters;
@@ -3698,3 +3703,4 @@
 }
 #endif
 #endif /* NOT_USED_YET */
+#endif /* LIBXML_READER_ENABLED */