Commit 6c5f9d14 authored by Daniel Veillard's avatar Daniel Veillard
Browse files

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
parent 7e8a4f7a
Sat Aug 25 15:30:17 CEST 2001 Daniel Veillard <daniel@veillard.com>
* 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.
2.4.3 got released at that point
Thu Aug 23 23:16:32 CEST 2001 Daniel Veillard <daniel@veillard.com>
* catalog.c xmlIO.c: started some serious testing and fixed
......
......@@ -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);
}
}
......@@ -2408,6 +2481,39 @@ xmlCatalogRemove(const xmlChar *value) {
return(res);
}
/**
* 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:
*
......@@ -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)
......
......@@ -69,6 +69,7 @@ int xmlCatalogAdd (const xmlChar *type,
const xmlChar *replace);
int xmlCatalogRemove (const xmlChar *value);
xmlDocPtr xmlParseCatalogFile (const char *filename);
int xmlCatalogConvert (void);
/*
* Strictly minimal interfaces for per-document catalogs used
......
......@@ -29,6 +29,7 @@ static int noout = 0;
static int create = 0;
static int add = 0;
static int del = 0;
static int convert = 0;
static int verbose = 0;
static char *filename;
......@@ -285,6 +286,8 @@ static void usage(const char *name) {
}
int main(int argc, char **argv) {
int i;
int ret;
if (argc <= 1) {
usage(argv[0]);
......@@ -313,6 +316,9 @@ int main(int argc, char **argv) {
} else if ((!strcmp(argv[i], "-create")) ||
(!strcmp(argv[i], "--create"))) {
create++;
} else if ((!strcmp(argv[i], "-convert")) ||
(!strcmp(argv[i], "--convert"))) {
convert++;
} else if ((!strcmp(argv[i], "-add")) ||
(!strcmp(argv[i], "--add"))) {
i += 3;
......@@ -340,17 +346,17 @@ int main(int argc, char **argv) {
} else if (argv[i][0] == '-')
continue;
filename = argv[i];
if (!create) {
xmlLoadCatalog(argv[i]);
} else {
ret = xmlLoadCatalog(argv[i]);
if ((ret < 0) && (create)) {
xmlCatalogAdd(BAD_CAST "catalog", BAD_CAST argv[i], NULL);
}
break;
}
if ((add) || (del)) {
int ret;
if (convert)
ret = xmlCatalogConvert();
if ((add) || (del)) {
for (i = 1; i < argc ; i++) {
if (!strcmp(argv[i], "-"))
break;
......@@ -404,7 +410,7 @@ int main(int argc, char **argv) {
}
}
}
if ((add) || (del) || (create)) {
if ((add) || (del) || (create) || (convert)) {
if (noout) {
FILE *out;
......
......@@ -975,7 +975,11 @@ main(int argc, char **argv) {
const char *catal;
catal = getenv("SGML_CATALOG_FILES");
xmlLoadCatalogs(catal);
if (catal != NULL) {
xmlLoadCatalogs(catal);
} else {
fprintf(stderr, "Variable $SGML_CATALOG_FILES not set\n");
}
}
}
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment