summaryrefslogtreecommitdiff
path: root/catalog.c
diff options
context:
space:
mode:
authorDaniel Veillard <veillard@src.gnome.org>2001-08-25 13:33:14 +0000
committerDaniel Veillard <veillard@src.gnome.org>2001-08-25 13:33:14 +0000
commit6c5f9d14cc2bdf602b57499d001626176e409d1b (patch)
treef9386530431a475352b3b0220f4bd30993b48d21 /catalog.c
parent7e8a4f7a3111916508f3c9c345d266f8549d9f78 (diff)
downloadlibxml2-6c5f9d14cc2bdf602b57499d001626176e409d1b.tar.gz
added a --convert option to xmlcatalog to convert SGML ones to the XML
* include/libxml/catalog.h catalog.c xmlcatalog.c: added a --convert option to xmlcatalog to convert SGML ones to the XML syntax. * xmllint.c: small cleanup for $SGML_CATALOG_FILES support. Daniel
Diffstat (limited to 'catalog.c')
-rw-r--r--catalog.c124
1 files changed, 116 insertions, 8 deletions
diff --git a/catalog.c b/catalog.c
index bd120aea..734ef77f 100644
--- a/catalog.c
+++ b/catalog.c
@@ -49,7 +49,9 @@
#define XML_URN_PUBID "urn:publicid:"
#define XML_CATAL_BREAK ((xmlChar *) -1)
+#ifndef XML_DEFAULT_CATALOG
#define XML_DEFAULT_CATALOG "/etc/xml/catalog"
+#endif
/************************************************************************
* *
@@ -246,6 +248,71 @@ xmlCatalogDumpEntry(xmlCatalogEntryPtr entry, FILE *out) {
fprintf(out, "\n");
}
+/**
+ * xmlCatalogConvertEntry:
+ * @entry: the entry
+ * @res: pointer to te number converted
+ *
+ * Free up all the memory associated with catalogs
+ */
+static void
+xmlCatalogConvertEntry(xmlCatalogEntryPtr entry, int *res) {
+ if ((entry == NULL) || (xmlDefaultXMLCatalogList == NULL))
+ return;
+ switch (entry->type) {
+ case SGML_CATA_ENTITY:
+ entry->type = XML_CATA_PUBLIC;
+ break;
+ case SGML_CATA_PENTITY:
+ entry->type = XML_CATA_PUBLIC;
+ break;
+ case SGML_CATA_DOCTYPE:
+ entry->type = XML_CATA_PUBLIC;
+ break;
+ case SGML_CATA_LINKTYPE:
+ entry->type = XML_CATA_PUBLIC;
+ break;
+ case SGML_CATA_NOTATION:
+ entry->type = XML_CATA_PUBLIC;
+ break;
+ case SGML_CATA_PUBLIC:
+ entry->type = XML_CATA_PUBLIC;
+ break;
+ case SGML_CATA_SYSTEM:
+ entry->type = XML_CATA_SYSTEM;
+ break;
+ case SGML_CATA_DELEGATE:
+ entry->type = XML_CATA_DELEGATE_PUBLIC;
+ break;
+ case SGML_CATA_CATALOG:
+ entry->type = XML_CATA_CATALOG;
+ break;
+ default:
+ xmlHashRemoveEntry(xmlDefaultCatalog, entry->name,
+ (xmlHashDeallocator) xmlFreeCatalogEntry);
+ return;
+ }
+ /*
+ * Conversion successful, remove from the SGML catalog
+ * and add it to the default XML one
+ */
+ xmlHashRemoveEntry(xmlDefaultCatalog, entry->name, NULL);
+ entry->parent = xmlDefaultXMLCatalogList;
+ entry->next = NULL;
+ if (xmlDefaultXMLCatalogList->children == NULL)
+ xmlDefaultXMLCatalogList->children = entry;
+ else {
+ xmlCatalogEntryPtr prev;
+
+ prev = xmlDefaultXMLCatalogList->children;
+ while (prev->next != NULL)
+ prev = prev->next;
+ prev->next = entry;
+ }
+ if (res != NULL)
+ (*res)++;
+}
+
/************************************************************************
* *
* Helper function *
@@ -1939,7 +2006,7 @@ xmlInitializeCatalog(void) {
* @filename: a file path
*
* Load the catalog and makes its definitions effective for the default
- * external entity loader. It will recuse in CATALOG entries.
+ * external entity loader. It will recurse in SGML CATALOG entries.
* TODO: this function is not thread safe, catalog initialization should
* preferably be done once at startup
*
@@ -2052,6 +2119,9 @@ xmlLoadCatalogs(const char *pathss) {
const char *paths;
xmlChar *path;
+ if (pathss == NULL)
+ return;
+
cur = pathss;
while ((cur != NULL) && (*cur != 0)) {
while (IS_BLANK(*cur)) cur++;
@@ -2266,13 +2336,15 @@ xmlCatalogResolve(const xmlChar *pubID, const xmlChar *sysID) {
if (!xmlCatalogInitialized)
xmlInitializeCatalog();
- if (xmlDebugCatalogs)
- if (pubID != NULL)
+ if (xmlDebugCatalogs) {
+ if (pubID != NULL) {
xmlGenericError(xmlGenericErrorContext,
"Resolve: pubID %s\n", pubID);
- else
+ } else {
xmlGenericError(xmlGenericErrorContext,
"Resolve: sysID %s\n", sysID);
+ }
+ }
if (xmlDefaultXMLCatalogList != NULL) {
xmlChar *ret;
@@ -2378,7 +2450,8 @@ xmlCatalogAdd(const xmlChar *type, const xmlChar *orig, const xmlChar *replace)
typ = xmlGetSGMLCatalogEntryType(type);
if (type != XML_CATA_NONE) {
xmlCatalogEntryPtr entry;
- entry = xmlNewCatalogEntry(typ, orig, replace, XML_CATA_PREFER_NONE);
+ entry = xmlNewCatalogEntry(typ, orig, replace,
+ XML_CATA_PREFER_NONE);
res = xmlHashAddEntry(xmlDefaultCatalog, orig, entry);
}
}
@@ -2409,6 +2482,39 @@ xmlCatalogRemove(const xmlChar *value) {
}
/**
+ * xmlCatalogConvert:
+ *
+ * Convert all the SGML catalog entries as XML ones
+ *
+ * Returns the number of entries converted if successful, -1 otherwise
+ */
+int
+xmlCatalogConvert(void) {
+ int res = -1;
+
+ if (!xmlCatalogInitialized)
+ xmlInitializeCatalog();
+
+ if (xmlDebugCatalogs) {
+ xmlGenericError(xmlGenericErrorContext,
+ "Converting SGML catalog to XML\n");
+ }
+
+ if (xmlDefaultXMLCatalogList == NULL) {
+ xmlDefaultXMLCatalogList = xmlNewCatalogEntry(XML_CATA_CATALOG,
+ NULL, BAD_CAST "NewCatalog.xml",
+ xmlCatalogDefaultPrefer);
+ }
+ if (xmlDefaultCatalog != NULL) {
+ res = 0;
+
+ xmlHashScan(xmlDefaultCatalog,
+ (xmlHashScanner) xmlCatalogConvertEntry, &res);
+ }
+ return(res);
+}
+
+/**
* xmlCatalogGetDefaults:
*
* Used to get the user preference w.r.t. to what catalogs should
@@ -2588,13 +2694,15 @@ xmlCatalogLocalResolve(void *catalogs, const xmlChar *pubID,
if (!xmlCatalogInitialized)
xmlInitializeCatalog();
- if (xmlDebugCatalogs)
- if (pubID != NULL)
+ if (xmlDebugCatalogs) {
+ if (pubID != NULL) {
xmlGenericError(xmlGenericErrorContext,
"Local resolve: pubID %s\n", pubID);
- else
+ } else {
xmlGenericError(xmlGenericErrorContext,
"Local resolve: sysID %s\n", sysID);
+ }
+ }
catal = (xmlCatalogEntryPtr) catalogs;
if (catal == NULL)