another set of patches from Anthony Jones for copy operations cleanup and

* valid.c tree.c entities.c: another set of patches from
  Anthony Jones for copy operations cleanup and robustness
Daniel
diff --git a/ChangeLog b/ChangeLog
index 8aafc1f..d67a9c8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Thu Jan 24 16:00:53 CET 2002 Daniel Veillard <daniel@veillard.com>
+
+	* valid.c tree.c entities.c: another set of patches from
+	  Anthony Jones for copy operations cleanup and robustness
+
 Wed Jan 23 18:53:55 CET 2002 Daniel Veillard <daniel@veillard.com>
 
 	* doc/APIchunk*.html doc/parsedecl.py doc/api.xsl: generated
diff --git a/Makefile.am b/Makefile.am
index b604a33..b81584a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -91,7 +91,7 @@
 	@echo "##"
 	@echo "## HTML regression tests"
 	@echo "##"
-	@(for i in $(srcdir)/test/HTML/* ; do \
+	-@(for i in $(srcdir)/test/HTML/* ; do \
 	  name=`basename $$i`; \
 	  if [ ! -d $$i ] ; then \
 	  if [ ! -f $(srcdir)/result/HTML/$$name ] ; then \
@@ -110,7 +110,7 @@
 	@echo "##"
 	@echo "## Push HTML regression tests"
 	@echo "##"
-	@(for i in $(srcdir)/test/HTML/* ; do \
+	-@(for i in $(srcdir)/test/HTML/* ; do \
 	  name=`basename $$i`; \
 	  if [ ! -d $$i ] ; then \
 	  if [ ! -f $(srcdir)/result/HTML/$$name ] ; then \
@@ -131,7 +131,7 @@
 	@echo "##"
 	@echo "## HTML SAX regression tests"
 	@echo "##"
-	@(for i in $(srcdir)/test/HTML/* ; do \
+	-@(for i in $(srcdir)/test/HTML/* ; do \
 	  name=`basename $$i`; \
 	  if [ ! -d $$i ] ; then \
 	  if [ ! -f $(srcdir)/result/HTML/$$name.sax ] ; then \
@@ -147,7 +147,7 @@
 	@echo "##"
 	@echo "## Push HTML SAX regression tests"
 	@echo "##"
-	@(for i in $(srcdir)/test/HTML/* ; do \
+	-@(for i in $(srcdir)/test/HTML/* ; do \
 	  name=`basename $$i`; \
 	  if [ ! -d $$i ] ; then \
 	  if [ ! -f $(srcdir)/result/HTML/$$name ] ; then \
@@ -169,7 +169,7 @@
 	@echo "##"
 	@echo "## You should see one warning on entity 'title.xml' for ent2"
 	@echo "##"
-	@(for i in $(srcdir)/test/* ; do \
+	-@(for i in $(srcdir)/test/* ; do \
 	  name=`basename $$i`; \
 	  if [ ! -d $$i ] ; then \
 	  if [ ! -f $(srcdir)/result/$$name ] ; then \
@@ -189,7 +189,7 @@
 	@echo "##"
 	@echo "## You should see one warning on entity 'title.xml' for ent2"
 	@echo "##"
-	@(for i in $(srcdir)/test/* ; do \
+	-@(for i in $(srcdir)/test/* ; do \
 	  name=`basename $$i`; \
 	  if [ ! -d $$i ] ; then \
 	  if [ ! -f $(srcdir)/result/$$name ] ; then \
@@ -208,7 +208,7 @@
 	@echo "##"
 	@echo "## You should see two warnings on entity 'title.xml' for ent2"
 	@echo "##"
-	@(for i in $(srcdir)/test/* ; do \
+	-@(for i in $(srcdir)/test/* ; do \
 	  name=`basename $$i`; \
 	  if [ ! -d $$i ] ; then \
 	  if [ ! -f $(srcdir)/result/$$name ] ; then \
@@ -229,7 +229,7 @@
 	@echo "##"
 	@echo "## SGML DocBook regression tests"
 	@echo "##"
-	@(for i in $(srcdir)/test/DocBook/*.sgm ; do \
+	-@(for i in $(srcdir)/test/DocBook/*.sgm ; do \
 	  name=`basename $$i .sgm`; \
 	  if [ ! -d $$i ] ; then \
 	  if [ ! -f $(srcdir)/result/DocBook/$$name.xml ] ; then \
@@ -249,7 +249,7 @@
 	@echo "##"
 	@echo "## XML entity subst regression tests"
 	@echo "##"
-	@(for i in $(srcdir)/test/* ; do \
+	-@(for i in $(srcdir)/test/* ; do \
 	  name=`basename $$i`; \
 	  if [ ! -d $$i ] ; then \
 	  if [ ! -f $(srcdir)/result/noent/$$name ] ; then \
@@ -269,7 +269,7 @@
 	@echo "##"
 	@echo "## URI module regression tests"
 	@echo "##"
-	@(for i in $(srcdir)/test/URI/*.data ; do \
+	-@(for i in $(srcdir)/test/URI/*.data ; do \
 	  name=`basename $$i`; \
 	  if [ ! -d $$i ] ; then \
 	  if [ ! -f $(srcdir)/result/URI/$$name ] ; then \
@@ -282,7 +282,7 @@
 	      diff $(srcdir)/result/URI/$$name result.$$name ; \
 	      rm result.$$name ; \
 	  fi ; fi ; done)
-	@(for i in $(srcdir)/test/URI/*.uri ; do \
+	-@(for i in $(srcdir)/test/URI/*.uri ; do \
 	  name=`basename $$i`; \
 	  if [ ! -d $$i ] ; then \
 	  if [ ! -f $(srcdir)/result/URI/$$name ] ; then \
@@ -301,7 +301,7 @@
 	@echo "##"
 	@echo "## XPath regression tests"
 	@echo "##"
-	@(if [ "`$(top_builddir)/testXPath | grep 'support not compiled in'`" != "" ] ; \
+	-@(if [ "`$(top_builddir)/testXPath | grep 'support not compiled in'`" != "" ] ; \
 	  then echo Skipping debug not compiled in ; exit 0 ; fi ; \
 	  for i in $(srcdir)/test/XPath/expr/* ; do \
 	  name=`basename $$i`; \
@@ -341,7 +341,7 @@
 	@echo "##"
 	@echo "## XPointer regression tests"
 	@echo "##"
-	@(if [ "`$(top_builddir)/testXPath | grep 'support not compiled in'`" != "" ] ; \
+	-@(if [ "`$(top_builddir)/testXPath | grep 'support not compiled in'`" != "" ] ; \
 	  then echo Skipping debug not compiled in ; exit 0 ; fi ; \
 	  for i in $(srcdir)/test/XPath/docs/* ; do \
 	  if [ ! -d $$i ] ; then \
@@ -366,7 +366,7 @@
 	@echo "##"
 	@echo "## XInclude regression tests"
 	@echo "##"
-	@(for i in $(srcdir)/test/XInclude/docs/* ; do \
+	-@(for i in $(srcdir)/test/XInclude/docs/* ; do \
 	  name=`basename $$i`; \
 	  if [ ! -d $$i ] ; then \
 	  if [ ! -f $(srcdir)/result/XInclude/$$name ] ; then \
@@ -386,7 +386,7 @@
 	@echo "## Scripts regression tests"
 	@echo "## Some of the base computations may be different if srcdir != ."
 	@echo "##"
-	@(for i in $(srcdir)/test/scripts/*.script ; do \
+	-@(for i in $(srcdir)/test/scripts/*.script ; do \
 	  name=`basename $$i .script`; \
 	  xml=$(srcdir)/test/scripts/`basename $$i .script`.xml; \
 	  if [ -f $$xml ] ; then \
@@ -406,7 +406,7 @@
 	@echo "##"
 	@echo "## Catalog regression tests"
 	@echo "##"
-	@(for i in $(srcdir)/test/catalogs/*.script ; do \
+	-@(for i in $(srcdir)/test/catalogs/*.script ; do \
 	  name=`basename $$i .script`; \
 	  xml=$(srcdir)/test/catalogs/`basename $$i .script`.xml; \
 	  if [ -f $$xml ] ; then \
@@ -420,7 +420,7 @@
 	      diff $(srcdir)/result/catalogs/$$name result.$$name ; \
 	      rm result.$$name ; \
 	  fi ; fi ; done)
-	@(for i in $(srcdir)/test/catalogs/*.script ; do \
+	-@(for i in $(srcdir)/test/catalogs/*.script ; do \
 	  name=`basename $$i .script`; \
 	  sgml=$(srcdir)/test/catalogs/`basename $$i .script`.sgml; \
 	  if [ -f $$sgml ] ; then \
@@ -435,7 +435,7 @@
 	      rm result.$$name ; \
 	  fi ; fi ; done)
 	@echo "Add and del operations on XML Catalogs"
-	@($(top_builddir)/xmlcatalog --create --noout result/catalogs/mycatalog; \
+	-@($(top_builddir)/xmlcatalog --create --noout result/catalogs/mycatalog; \
 	grep "MORY ALLO" .memdump  | grep -v "MEMORY ALLOCATED : 0"; \
 	$(top_builddir)/xmlcatalog --noout --add public Pubid sysid result/catalogs/mycatalog; \
 	grep "MORY ALLO" .memdump  | grep -v "MEMORY ALLOCATED : 0"; \
@@ -459,7 +459,7 @@
 	@echo "##"
 	@echo "## SVG parsing regression tests"
 	@echo "##"
-	@(for i in $(srcdir)/test/SVG/* ; do \
+	-@(for i in $(srcdir)/test/SVG/* ; do \
 	  name=`basename $$i`; \
 	  if [ ! -d $$i ] ; then \
 	  if [ ! -f $(srcdir)/result/SVG/$$name ] ; then \
@@ -485,7 +485,7 @@
 	@echo "##"
 	@echo "## SAX callbacks regression tests"
 	@echo "##"
-	@(for i in $(srcdir)/test/* ; do \
+	-@(for i in $(srcdir)/test/* ; do \
 	  name=`basename $$i`; \
 	  if [ ! -d $$i ] ; then \
 	  if [ ! -f $(srcdir)/SAXresult/$$name ] ; then \
@@ -504,7 +504,7 @@
 	@echo "##"
 	@echo "## Valid documents regression tests"
 	@echo "##"
-	@(for i in $(srcdir)/test/VCM/* ; do \
+	-@(for i in $(srcdir)/test/VCM/* ; do \
 	  name=`basename $$i`; \
 	  if [ ! -d $$i ] ; then \
 	      echo Testing $$name ; \
@@ -514,7 +514,7 @@
 	@echo "##"
 	@echo "## Validity checking regression tests"
 	@echo "##"
-	@(for i in $(srcdir)/test/VC/* ; do \
+	-@(for i in $(srcdir)/test/VC/* ; do \
 	  name=`basename $$i`; \
 	  if [ ! -d $$i ] ; then \
 	  if [ ! -f $(srcdir)/result/VC/$$name ] ; then \
@@ -530,7 +530,7 @@
 	@echo "##"
 	@echo "## General documents valid regression tests"
 	@echo "##"
-	@(for i in $(srcdir)/test/valid/* ; do \
+	-@(for i in $(srcdir)/test/valid/* ; do \
 	  name=`basename $$i`; \
 	  if [ ! -d $$i ] ; then \
 	  if [ ! -f $(srcdir)/result/valid/$$name ] ; then \
@@ -575,11 +575,16 @@
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = libxml-2.0.pc
 
-#xml2Conf.sh: xml2Conf.sh.in Makefile
-### Use sed and then mv to avoid problems if the user interrupts.
-#	sed -e 's?\@XML_LIBDIR\@?$(XML_LIBDIR)?g' \
-#	    -e 's?\@XML_INCLUDEDIR\@?$(XML_INCLUDEDIR)?g' \
-#	    -e 's?\@XML_LIBS\@?$(XML_LIBS)?g' \
-#	    -e 's?\@VERSION\@?$(VERSION)?g' \
-#	      < $(srcdir)/xml2Conf.sh.in > xml2Conf.tmp \
-#	  && mv xml2Conf.tmp xml2Conf.sh
+#
+# Instll the tests program sources as examples 
+#
+BASE_DIR=@HTML_DIR@
+DOC_MODULE=libxml2-$(VERSION)
+EXAMPLES_DIR=$(BASE_DIR)/$(DOC_MODULE)/examples
+
+install-data-local: 
+	$(mkinstalldirs) $(DESTDIR)$(EXAMPLES_DIR)
+	-@INSTALL@ -m 0644 $(srcdir)/xmllint.c $(DESTDIR)$(EXAMPLES_DIR)
+	-@INSTALL@ -m 0644 $(srcdir)/testSAX.c $(DESTDIR)$(EXAMPLES_DIR)
+	-@INSTALL@ -m 0644 $(srcdir)/testHTML.c $(DESTDIR)$(EXAMPLES_DIR)
+	-@INSTALL@ -m 0644 $(srcdir)/testXPath.c $(DESTDIR)$(EXAMPLES_DIR)
diff --git a/entities.c b/entities.c
index b2cb3d4..9d5937a 100644
--- a/entities.c
+++ b/entities.c
@@ -323,6 +323,8 @@
     xmlEntitiesTablePtr table;
     xmlEntityPtr ret;
 
+    if (doc == NULL)
+	return(NULL);
     if ((doc->intSubset != NULL) && (doc->intSubset->pentities != NULL)) {
 	table = (xmlEntitiesTablePtr) doc->intSubset->pentities;
 	ret = xmlGetEntityFromTable(table, name);
@@ -343,6 +345,7 @@
  *
  * Do an entity lookup in the DTD entity hash table and
  * returns the corresponding entity, if found.
+ * Note: the first argument is the document node, not the DTD node.
  * 
  * Returns A pointer to the entity structure or NULL if not found.
  */
@@ -350,6 +353,8 @@
 xmlGetDtdEntity(xmlDocPtr doc, const xmlChar *name) {
     xmlEntitiesTablePtr table;
 
+    if (doc == NULL)
+	return(NULL);
     if ((doc->extSubset != NULL) && (doc->extSubset->entities != NULL)) {
 	table = (xmlEntitiesTablePtr) doc->extSubset->entities;
 	return(xmlGetEntityFromTable(table, name));
diff --git a/tree.c b/tree.c
index 241bd08..50a7e1e 100644
--- a/tree.c
+++ b/tree.c
@@ -1824,11 +1824,13 @@
     if (tree->type == XML_ENTITY_DECL)
 	return;
     if (tree->doc != doc) {
-	prop = tree->properties;
-	while (prop != NULL) {
-	    prop->doc = doc;
-	    xmlSetListDoc(prop->children, doc);
-	    prop = prop->next;
+	if(tree->type == XML_ELEMENT_NODE) {
+	    prop = tree->properties;
+	    while (prop != NULL) {
+		prop->doc = doc;
+		xmlSetListDoc(prop->children, doc);
+		prop = prop->next;
+	    }
 	}
 	if (tree->children != NULL)
 	    xmlSetListDoc(tree->children, doc);
diff --git a/valid.c b/valid.c
index 55c7b9e..79f4cf9 100644
--- a/valid.c
+++ b/valid.c
@@ -1436,6 +1436,7 @@
 	return(NULL);
     }
     memset(cur, 0, sizeof(xmlAttribute));
+    cur->type = XML_ATTRIBUTE_DECL;
     cur->atype = attr->atype;
     cur->def = attr->def;
     cur->tree = xmlCopyEnumeration(attr->tree);
@@ -1443,6 +1444,8 @@
 	cur->elem = xmlStrdup(attr->elem);
     if (attr->name != NULL)
 	cur->name = xmlStrdup(attr->name);
+    if (attr->prefix != NULL)
+	cur->prefix = xmlStrdup(attr->prefix);
     if (attr->defaultValue != NULL)
 	cur->defaultValue = xmlStrdup(attr->defaultValue);
     return(cur);