comment fix migrating the catalog code to the new infrastructure Daniel

* xinclude.c: comment fix
* catalog.c include/libxml/xmlerror.h: migrating the catalog code
  to the new infrastructure
Daniel
diff --git a/ChangeLog b/ChangeLog
index 6ec9d9e..31fc99b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Thu Oct  9 13:44:57 CEST 2003 Daniel Veillard <daniel@veillard.com>
+
+	* xinclude.c: comment fix
+	* catalog.c include/libxml/xmlerror.h: migrating the catalog code
+	  to the new infrastructure
+
 Thu Oct  9 00:36:03 CEST 2003 Daniel Veillard <daniel@veillard.com>
 
 	* xmlIO.c: final error handling cleanup
diff --git a/catalog.c b/catalog.c
index 6ff22a1..c013c97 100644
--- a/catalog.c
+++ b/catalog.c
@@ -182,6 +182,48 @@
  */
 static int xmlCatalogInitialized = 0;
 
+/************************************************************************
+ *									*
+ * 			Catalog error handlers				*
+ *									*
+ ************************************************************************/
+
+/**
+ * xmlCatalogErrMemory:
+ * @extra:  extra informations
+ *
+ * Handle an out of memory condition
+ */
+static void
+xmlCatalogErrMemory(const char *extra)
+{
+    __xmlRaiseError(NULL, NULL, NULL, NULL, XML_FROM_CATALOG,
+                    XML_ERR_NO_MEMORY, XML_ERR_ERROR, NULL, 0,
+		    extra, NULL, NULL, 0, 0,
+		    "Memory allocation failed : %s\n", extra);
+}
+
+/**
+ * xmlCatalogErr:
+ * @catal: the Catalog entry
+ * @node: the context node
+ * @msg:  the error message
+ * @extra:  extra informations
+ *
+ * Handle a catalog error
+ */
+static void
+xmlCatalogErr(xmlCatalogEntryPtr catal, xmlNodePtr node, int error,
+               const char *msg, const xmlChar *str1, const xmlChar *str2,
+	       const xmlChar *str3)
+{
+    __xmlRaiseError(NULL, NULL, catal, node, XML_FROM_CATALOG,
+                    error, XML_ERR_ERROR, NULL, 0,
+		    (const char *) str1, (const char *) str2,
+		    (const char *) str3, 0, 0,
+		    msg, str1, str2, str3);
+}
+
 
 /************************************************************************
  *									*
@@ -208,8 +250,7 @@
 
     ret = (xmlCatalogEntryPtr) xmlMalloc(sizeof(xmlCatalogEntry));
     if (ret == NULL) {
-	xmlGenericError(xmlGenericErrorContext,
-		"malloc of %d byte failed\n", sizeof(xmlCatalogEntry));
+        xmlCatalogErrMemory("allocating catalog entry");
 	return(NULL);
     }
     ret->next = NULL;
@@ -336,8 +377,7 @@
 
     ret = (xmlCatalogPtr) xmlMalloc(sizeof(xmlCatalog));
     if (ret == NULL) {
-	xmlGenericError(xmlGenericErrorContext,
-		"malloc of %d byte failed\n", sizeof(xmlCatalog));
+        xmlCatalogErrMemory("allocating catalog");
 	return(NULL);
     }
     memset(ret, 0, sizeof(xmlCatalog));
@@ -874,8 +914,7 @@
 #endif
     content = xmlMallocAtomic(size + 10);
     if (content == NULL) {
-        xmlGenericError(xmlGenericErrorContext,
-                        "malloc of %d byte failed\n", size + 10);
+        xmlCatalogErrMemory("allocating catalog data");
         return (NULL);
     }
 #ifdef HAVE_STAT
@@ -977,15 +1016,15 @@
     if (attrName != NULL) {
 	nameValue = xmlGetProp(cur, attrName);
 	if (nameValue == NULL) {
-	    xmlGenericError(xmlGenericErrorContext,
-		    "%s entry lacks '%s'\n", name, attrName);
+	    xmlCatalogErr(ret, cur, XML_CATALOG_MISSING_ATTR,
+			  "%s entry lacks '%s'\n", name, attrName, NULL);
 	    ok = 0;
 	}
     }
     uriValue = xmlGetProp(cur, uriAttrName);
     if (uriValue == NULL) {
-	xmlGenericError(xmlGenericErrorContext,
-		"%s entry lacks '%s'\n", name, uriAttrName);
+	xmlCatalogErr(ret, cur, XML_CATALOG_MISSING_ATTR,
+		"%s entry lacks '%s'\n", name, uriAttrName, NULL);
 	ok = 0;
     }
     if (!ok) {
@@ -1009,7 +1048,7 @@
 	}
 	ret = xmlNewCatalogEntry(type, nameValue, uriValue, URL, prefer);
     } else {
-	xmlGenericError(xmlGenericErrorContext,
+	xmlCatalogErr(ret, cur, XML_CATALOG_ENTRY_BROKEN,
 		"%s entry '%s' broken ?: %s\n", name, uriAttrName, uriValue);
     }
     if (nameValue != NULL)
@@ -1054,8 +1093,9 @@
             } else if (xmlStrEqual(prop, BAD_CAST "public")) {
                 prefer = XML_CATA_PREFER_PUBLIC;
             } else {
-                xmlGenericError(xmlGenericErrorContext,
-                                "Invalid value for prefer: '%s'\n", prop);
+		xmlCatalogErr(parent, cur, XML_CATALOG_PREFER_VALUE,
+                              "Invalid value for prefer: '%s'\n",
+			      prop, NULL, NULL);
             }
             xmlFree(prop);
         }
@@ -1194,17 +1234,18 @@
 	    } else if (xmlStrEqual(prop, BAD_CAST "public")) {
 		prefer = XML_CATA_PREFER_PUBLIC;
 	    } else {
-		xmlGenericError(xmlGenericErrorContext,
-			"Invalid value for prefer: '%s'\n",
-			        prop);
+		xmlCatalogErr(NULL, cur, XML_CATALOG_PREFER_VALUE,
+			      "Invalid value for prefer: '%s'\n",
+			      prop, NULL, NULL);
 	    }
 	    xmlFree(prop);
 	}
 	cur = cur->children;
 	xmlParseXMLCatalogNodeList(cur, prefer, parent);
     } else {
-	xmlGenericError(xmlGenericErrorContext,
-			"File %s is not an XML Catalog\n", filename);
+	xmlCatalogErr(NULL, (xmlNodePtr) doc, XML_CATALOG_NOT_CATALOG,
+		      "File %s is not an XML Catalog\n",
+		      filename, NULL, NULL);
 	xmlFreeDoc(doc);
 	return(NULL);
     }
@@ -1451,12 +1492,9 @@
      * protection against loops
      */
     if (catal->depth > MAX_CATAL_DEPTH) {
-        if (catal->name != NULL)
-	    xmlGenericError(xmlGenericErrorContext,
-		    "Detected recursion in catalog %s\n", catal->name);
-	else
-	    xmlGenericError(xmlGenericErrorContext,
-		    "Detected recursion in catalog\n");
+	xmlCatalogErr(catal, NULL, XML_CATALOG_RECURSION,
+		      "Detected recursion in catalog %s\n",
+		      catal->name, NULL, NULL);
 	return(NULL);
     }
     catal->depth++;
@@ -1969,7 +2007,7 @@
  */
 static const xmlChar *
 xmlParseSGMLCatalogPubid(const xmlChar *cur, xmlChar **id) {
-    xmlChar *buf = NULL;
+    xmlChar *buf = NULL, *tmp;
     int len = 0;
     int size = 50;
     xmlChar stop;
@@ -1988,8 +2026,7 @@
     }
     buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar));
     if (buf == NULL) {
-	xmlGenericError(xmlGenericErrorContext,
-		"malloc of %d byte failed\n", size);
+        xmlCatalogErrMemory("allocating public ID");
 	return(NULL);
     }
     while (xmlIsPubidChar(*cur) || (*cur == '?')) {
@@ -1999,12 +2036,13 @@
 	    break;
 	if (len + 1 >= size) {
 	    size *= 2;
-	    buf = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar));
-	    if (buf == NULL) {
-		xmlGenericError(xmlGenericErrorContext,
-			"realloc of %d byte failed\n", size);
+	    tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar));
+	    if (tmp == NULL) {
+		xmlCatalogErrMemory("allocating public ID");
+		xmlFree(buf);
 		return(NULL);
 	    }
+	    buf = tmp;
 	}
 	buf[len++] = *cur;
 	count++;
diff --git a/include/libxml/xmlerror.h b/include/libxml/xmlerror.h
index b3ba285..fcfc877 100644
--- a/include/libxml/xmlerror.h
+++ b/include/libxml/xmlerror.h
@@ -472,7 +472,12 @@
     XML_XINCLUDE_XPTR_RESULT,
     XML_XINCLUDE_INCLUDE_IN_INCLUDE,
     XML_XINCLUDE_FALLBACKS_IN_INCLUDE,
-    XML_XINCLUDE_FALLBACK_NOT_IN_INCLUDE
+    XML_XINCLUDE_FALLBACK_NOT_IN_INCLUDE,
+    XML_CATALOG_MISSING_ATTR = 1650,
+    XML_CATALOG_ENTRY_BROKEN,
+    XML_CATALOG_PREFER_VALUE,
+    XML_CATALOG_NOT_CATALOG,
+    XML_CATALOG_RECURSION
 } xmlParserErrors;
 
 /**
diff --git a/xinclude.c b/xinclude.c
index 8a336dc..04d827f 100644
--- a/xinclude.c
+++ b/xinclude.c
@@ -96,7 +96,7 @@
 
 /************************************************************************
  *									*
- * 		Tree memory error handler				*
+ * 			XInclude error handler				*
  *									*
  ************************************************************************/