1
0
mirror of https://github.com/GNOME/libxml2.git synced 2025-10-14 02:58:39 +08:00

catalog: Prepare to make SGML catalog support optional

This commit is contained in:
Nick Wellnhofer
2025-08-17 15:58:09 +02:00
parent e2fdef4510
commit 56199b5c08
10 changed files with 228 additions and 103 deletions

View File

@@ -182,6 +182,7 @@ if WITH_DEBUG_SOURCES
endif
if WITH_CATALOG_SOURCES
ASAN_OPTIONS=detect_leaks=0 test/catalogs/test.sh ./xmlcatalog$(EXEEXT)
ASAN_OPTIONS=detect_leaks=0 test/catalogs/test_sgml.sh ./xmlcatalog$(EXEEXT)
endif
endif

179
catalog.c
View File

@@ -57,9 +57,12 @@
#ifndef XML_XML_DEFAULT_CATALOG
#define XML_XML_DEFAULT_CATALOG "file://" XML_SYSCONFDIR "/xml/catalog"
#endif
#ifdef LIBXML_SGML_CATALOG_ENABLED
#ifndef XML_SGML_DEFAULT_CATALOG
#define XML_SGML_DEFAULT_CATALOG "file://" XML_SYSCONFDIR "/sgml/catalog"
#endif
#endif
static xmlChar *xmlCatalogNormalizePublic(const xmlChar *pubID);
static int xmlExpandCatalog(xmlCatalogPtr catal, const char *filename);
@@ -84,7 +87,9 @@ typedef enum {
XML_CATA_DELEGATE_SYSTEM,
XML_CATA_URI,
XML_CATA_REWRITE_URI,
XML_CATA_DELEGATE_URI,
XML_CATA_DELEGATE_URI
#ifdef LIBXML_SGML_CATALOG_ENABLED
,
SGML_CATA_SYSTEM,
SGML_CATA_PUBLIC,
SGML_CATA_ENTITY,
@@ -97,6 +102,7 @@ typedef enum {
SGML_CATA_CATALOG,
SGML_CATA_DOCUMENT,
SGML_CATA_SGMLDECL
#endif
} xmlCatalogEntryType;
typedef struct _xmlCatalogEntry xmlCatalogEntry;
@@ -116,14 +122,20 @@ struct _xmlCatalogEntry {
};
typedef enum {
XML_XML_CATALOG_TYPE = 1,
XML_XML_CATALOG_TYPE = 1
#ifdef LIBXML_SGML_CATALOG_ENABLED
,
XML_SGML_CATALOG_TYPE
#endif
} xmlCatalogType;
#ifdef LIBXML_SGML_CATALOG_ENABLED
#define XML_MAX_SGML_CATA_DEPTH 10
#endif
struct _xmlCatalog {
xmlCatalogType type; /* either XML or SGML */
#ifdef LIBXML_SGML_CATALOG_ENABLED
/*
* SGML Catalogs are stored as a simple hash table of catalog entries
* Catalog stack to check against overflows when building the
@@ -133,6 +145,7 @@ struct _xmlCatalog {
int catalNr; /* Number of current catal streams */
int catalMax; /* Max number of catal streams */
xmlHashTablePtr sgml;
#endif
/*
* XML Catalogs are stored as a tree of Catalog entries
@@ -396,11 +409,13 @@ xmlCreateNewCatalog(xmlCatalogType type, xmlCatalogPrefer prefer) {
}
memset(ret, 0, sizeof(xmlCatalog));
ret->type = type;
ret->prefer = prefer;
#ifdef LIBXML_SGML_CATALOG_ENABLED
ret->catalNr = 0;
ret->catalMax = XML_MAX_SGML_CATA_DEPTH;
ret->prefer = prefer;
if (ret->type == XML_SGML_CATALOG_TYPE)
ret->sgml = xmlHashCreate(10);
#endif
return(ret);
}
@@ -417,8 +432,10 @@ xmlFreeCatalog(xmlCatalog *catal) {
return;
if (catal->xml != NULL)
xmlFreeCatalogEntryList(catal->xml);
#ifdef LIBXML_SGML_CATALOG_ENABLED
if (catal->sgml != NULL)
xmlHashFree(catal->sgml, xmlFreeCatalogEntry);
#endif
xmlFree(catal);
}
@@ -429,6 +446,7 @@ xmlFreeCatalog(xmlCatalog *catal) {
************************************************************************/
#ifdef LIBXML_OUTPUT_ENABLED
#ifdef LIBXML_SGML_CATALOG_ENABLED
/**
* Serialize an SGML Catalog entry
*
@@ -504,6 +522,7 @@ xmlCatalogDumpEntry(void *payload, void *data,
}
fprintf(out, "\n");
}
#endif /* LIBXML_SGML_CATALOG_ENABLED */
/**
* Serializes a Catalog entry, called by xmlDumpXMLCatalog and recursively
@@ -613,18 +632,7 @@ static void xmlDumpXMLCatalogNode(xmlCatalogEntryPtr catal, xmlNodePtr catalog,
xmlSetProp(node, BAD_CAST "catalog", cur->value);
xmlAddChild(catalog, node);
break;
case SGML_CATA_SYSTEM:
case SGML_CATA_PUBLIC:
case SGML_CATA_ENTITY:
case SGML_CATA_PENTITY:
case SGML_CATA_DOCTYPE:
case SGML_CATA_LINKTYPE:
case SGML_CATA_NOTATION:
case SGML_CATA_DELEGATE:
case SGML_CATA_BASE:
case SGML_CATA_CATALOG:
case SGML_CATA_DOCUMENT:
case SGML_CATA_SGMLDECL:
default:
break;
}
}
@@ -694,6 +702,8 @@ BAD_CAST "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd");
* *
************************************************************************/
#ifdef LIBXML_SGML_CATALOG_ENABLED
/**
* Convert one entry from the catalog
*
@@ -782,6 +792,8 @@ xmlConvertSGMLCatalog(xmlCatalog *catal) {
return(0);
}
#endif /* LIBXML_SGML_CATALOG_ENABLED */
/************************************************************************
* *
* Helper function *
@@ -2050,6 +2062,8 @@ xmlCatalogListXMLResolveURI(xmlCatalogEntryPtr catal, const xmlChar *URI) {
return(ret);
}
#ifdef LIBXML_SGML_CATALOG_ENABLED
/************************************************************************
* *
* The SGML Catalog parser *
@@ -2534,12 +2548,15 @@ xmlCatalogSGMLResolve(xmlCatalogPtr catal, const xmlChar *pubID,
return(NULL);
}
#endif /* LIBXML_SGML_CATALOG_ENABLED */
/************************************************************************
* *
* Specific Public interfaces *
* *
************************************************************************/
#ifdef LIBXML_SGML_CATALOG_ENABLED
/**
* Load an SGML super catalog. It won't expand CATALOG or DELEGATE
* references. This is only needed for manipulating SGML Super Catalogs
@@ -2575,6 +2592,7 @@ xmlLoadSGMLSuperCatalog(const char *filename)
}
return (catal);
}
#endif /* LIBXML_SGML_CATALOG_ENABLED */
/**
* Load the catalog and build the associated data structures.
@@ -2593,7 +2611,6 @@ xmlLoadACatalog(const char *filename)
xmlChar *content;
xmlChar *first;
xmlCatalogPtr catal;
int ret;
content = xmlLoadFileContent(filename);
if (content == NULL)
@@ -2607,7 +2624,10 @@ xmlLoadACatalog(const char *filename)
((*first >= 'a') && (*first <= 'z')))))
first++;
#ifdef LIBXML_SGML_CATALOG_ENABLED
if (*first != '<') {
int ret;
catal = xmlCreateNewCatalog(XML_SGML_CATALOG_TYPE, xmlCatalogDefaultPrefer);
if (catal == NULL) {
xmlFree(content);
@@ -2619,7 +2639,9 @@ xmlLoadACatalog(const char *filename)
xmlFree(content);
return(NULL);
}
} else {
} else
#endif /* LIBXML_SGML_CATALOG_ENABLED */
{
catal = xmlCreateNewCatalog(XML_XML_CATALOG_TYPE, xmlCatalogDefaultPrefer);
if (catal == NULL) {
xmlFree(content);
@@ -2643,14 +2665,13 @@ xmlLoadACatalog(const char *filename)
static int
xmlExpandCatalog(xmlCatalogPtr catal, const char *filename)
{
int ret;
if ((catal == NULL) || (filename == NULL))
return(-1);
#ifdef LIBXML_SGML_CATALOG_ENABLED
if (catal->type == XML_SGML_CATALOG_TYPE) {
xmlChar *content;
int ret;
content = xmlLoadFileContent(filename);
if (content == NULL)
@@ -2662,7 +2683,9 @@ xmlExpandCatalog(xmlCatalogPtr catal, const char *filename)
return(-1);
}
xmlFree(content);
} else {
} else
#endif /* LIBXML_SGML_CATALOG_ENABLED */
{
xmlCatalogEntryPtr tmp, cur;
tmp = xmlNewCatalogEntry(XML_CATA_CATALOG, NULL,
NULL, BAD_CAST filename, xmlCatalogDefaultPrefer, NULL);
@@ -2699,16 +2722,19 @@ xmlACatalogResolveSystem(xmlCatalog *catal, const xmlChar *sysID) {
xmlCatalogPrintDebug(
"Resolve sysID %s\n", sysID);
if (catal->type == XML_XML_CATALOG_TYPE) {
ret = xmlCatalogListXMLResolve(catal->xml, NULL, sysID);
if (ret == XML_CATAL_BREAK)
ret = NULL;
} else {
#ifdef LIBXML_SGML_CATALOG_ENABLED
if (catal->type == XML_SGML_CATALOG_TYPE) {
const xmlChar *sgml;
sgml = xmlCatalogGetSGMLSystem(catal->sgml, sysID);
if (sgml != NULL)
ret = xmlStrdup(sgml);
} else
#endif /* LIBXML_SGML_CATALOG_ENABLED */
{
ret = xmlCatalogListXMLResolve(catal->xml, NULL, sysID);
if (ret == XML_CATAL_BREAK)
ret = NULL;
}
return(ret);
}
@@ -2734,16 +2760,19 @@ xmlACatalogResolvePublic(xmlCatalog *catal, const xmlChar *pubID) {
xmlCatalogPrintDebug(
"Resolve pubID %s\n", pubID);
if (catal->type == XML_XML_CATALOG_TYPE) {
ret = xmlCatalogListXMLResolve(catal->xml, pubID, NULL);
if (ret == XML_CATAL_BREAK)
ret = NULL;
} else {
#ifdef LIBXML_SGML_CATALOG_ENABLED
if (catal->type == XML_SGML_CATALOG_TYPE) {
const xmlChar *sgml;
sgml = xmlCatalogGetSGMLPublic(catal->sgml, pubID);
if (sgml != NULL)
ret = xmlStrdup(sgml);
} else
#endif /* LIBXML_SGML_CATALOG_ENABLED */
{
ret = xmlCatalogListXMLResolve(catal->xml, pubID, NULL);
if (ret == XML_CATAL_BREAK)
ret = NULL;
}
return(ret);
}
@@ -2781,16 +2810,19 @@ xmlACatalogResolve(xmlCatalog *catal, const xmlChar * pubID,
}
}
if (catal->type == XML_XML_CATALOG_TYPE) {
ret = xmlCatalogListXMLResolve(catal->xml, pubID, sysID);
if (ret == XML_CATAL_BREAK)
ret = NULL;
} else {
#ifdef LIBXML_SGML_CATALOG_ENABLED
if (catal->type == XML_SGML_CATALOG_TYPE) {
const xmlChar *sgml;
sgml = xmlCatalogSGMLResolve(catal, pubID, sysID);
if (sgml != NULL)
ret = xmlStrdup(sgml);
} else
#endif /* LIBXML_SGML_CATALOG_ENABLED */
{
ret = xmlCatalogListXMLResolve(catal->xml, pubID, sysID);
if (ret == XML_CATAL_BREAK)
ret = NULL;
}
return (ret);
}
@@ -2816,16 +2848,19 @@ xmlACatalogResolveURI(xmlCatalog *catal, const xmlChar *URI) {
xmlCatalogPrintDebug(
"Resolve URI %s\n", URI);
if (catal->type == XML_XML_CATALOG_TYPE) {
ret = xmlCatalogListXMLResolveURI(catal->xml, URI);
if (ret == XML_CATAL_BREAK)
ret = NULL;
} else {
#ifdef LIBXML_SGML_CATALOG_ENABLED
if (catal->type == XML_SGML_CATALOG_TYPE) {
const xmlChar *sgml;
sgml = xmlCatalogSGMLResolve(catal, NULL, URI);
if (sgml != NULL)
ret = xmlStrdup(sgml);
} else
#endif /* LIBXML_SGML_CATALOG_ENABLED */
{
ret = xmlCatalogListXMLResolveURI(catal->xml, URI);
if (ret == XML_CATAL_BREAK)
ret = NULL;
}
return(ret);
}
@@ -2844,10 +2879,13 @@ xmlACatalogDump(xmlCatalog *catal, FILE *out) {
if ((out == NULL) || (catal == NULL))
return;
if (catal->type == XML_XML_CATALOG_TYPE) {
xmlDumpXMLCatalog(out, catal->xml);
} else {
#ifdef LIBXML_SGML_CATALOG_ENABLED
if (catal->type == XML_SGML_CATALOG_TYPE) {
xmlHashScan(catal->sgml, xmlCatalogDumpEntry, out);
} else
#endif /* LIBXML_SGML_CATALOG_ENABLED */
{
xmlDumpXMLCatalog(out, catal->xml);
}
}
#endif /* LIBXML_OUTPUT_ENABLED */
@@ -2873,9 +2911,8 @@ xmlACatalogAdd(xmlCatalog *catal, const xmlChar * type,
if (catal == NULL)
return(-1);
if (catal->type == XML_XML_CATALOG_TYPE) {
res = xmlAddXMLCatalog(catal->xml, type, orig, replace);
} else {
#ifdef LIBXML_SGML_CATALOG_ENABLED
if (catal->type == XML_SGML_CATALOG_TYPE) {
xmlCatalogEntryType cattype;
cattype = xmlGetSGMLCatalogEntryType(type);
@@ -2890,6 +2927,10 @@ xmlACatalogAdd(xmlCatalog *catal, const xmlChar * type,
if (res < 0)
xmlFreeCatalogEntry(entry, NULL);
}
} else
#endif /* LIBXML_SGML_CATALOG_ENABLED */
{
res = xmlAddXMLCatalog(catal->xml, type, orig, replace);
}
return (res);
}
@@ -2910,12 +2951,15 @@ xmlACatalogRemove(xmlCatalog *catal, const xmlChar *value) {
if ((catal == NULL) || (value == NULL))
return(-1);
if (catal->type == XML_XML_CATALOG_TYPE) {
res = xmlDelXMLCatalog(catal->xml, value);
} else {
#ifdef LIBXML_SGML_CATALOG_ENABLED
if (catal->type == XML_SGML_CATALOG_TYPE) {
res = xmlHashRemoveEntry(catal->sgml, value, xmlFreeCatalogEntry);
if (res == 0)
res = 1;
} else
#endif /* LIBXML_SGML_CATALOG_ENABLED */
{
res = xmlDelXMLCatalog(catal->xml, value);
}
return(res);
}
@@ -2932,14 +2976,20 @@ xmlCatalog *
xmlNewCatalog(int sgml) {
xmlCatalogPtr catal = NULL;
(void) sgml;
#ifdef LIBXML_SGML_CATALOG_ENABLED
if (sgml) {
catal = xmlCreateNewCatalog(XML_SGML_CATALOG_TYPE,
xmlCatalogDefaultPrefer);
if ((catal != NULL) && (catal->sgml == NULL))
catal->sgml = xmlHashCreate(10);
} else
#endif /* LIBXML_SGML_CATALOG_ENABLED */
{
catal = xmlCreateNewCatalog(XML_XML_CATALOG_TYPE,
xmlCatalogDefaultPrefer);
}
return(catal);
}
@@ -2956,16 +3006,8 @@ xmlCatalogIsEmpty(xmlCatalog *catal) {
if (catal == NULL)
return(-1);
if (catal->type == XML_XML_CATALOG_TYPE) {
if (catal->xml == NULL)
return(1);
if ((catal->xml->type != XML_CATA_CATALOG) &&
(catal->xml->type != XML_CATA_BROKEN_CATALOG))
return(-1);
if (catal->xml->children == NULL)
return(1);
return(0);
} else {
#ifdef LIBXML_SGML_CATALOG_ENABLED
if (catal->type == XML_SGML_CATALOG_TYPE) {
int res;
if (catal->sgml == NULL)
@@ -2975,6 +3017,17 @@ xmlCatalogIsEmpty(xmlCatalog *catal) {
return(1);
if (res < 0)
return(-1);
} else
#endif /* LIBXML_SGML_CATALOG_ENABLED */
{
if (catal->xml == NULL)
return(1);
if ((catal->xml->type != XML_CATA_CATALOG) &&
(catal->xml->type != XML_CATA_BROKEN_CATALOG))
return(-1);
if (catal->xml->children == NULL)
return(1);
return(0);
}
return(0);
}
@@ -3314,6 +3367,7 @@ xmlCatalogRemove(const xmlChar *value) {
return(res);
}
#ifdef LIBXML_SGML_CATALOG_ENABLED
/**
* Convert all the SGML catalog entries as XML ones
*
@@ -3331,6 +3385,7 @@ xmlCatalogConvert(void) {
xmlRMutexUnlock(&xmlCatalogMutex);
return(res);
}
#endif /* LIBXML_SGML_CATALOG_ENABLED */
/************************************************************************
* *
@@ -3609,8 +3664,10 @@ xmlCatalogGetSystem(const xmlChar *sysID) {
}
}
#ifdef LIBXML_SGML_CATALOG_ENABLED
if (xmlDefaultCatalog != NULL)
return(xmlCatalogGetSGMLSystem(xmlDefaultCatalog->sgml, sysID));
#endif
return(NULL);
}
@@ -3652,8 +3709,10 @@ xmlCatalogGetPublic(const xmlChar *pubID) {
}
}
#ifdef LIBXML_SGML_CATALOG_ENABLED
if (xmlDefaultCatalog != NULL)
return(xmlCatalogGetSGMLPublic(xmlDefaultCatalog->sgml, pubID));
#endif
return(NULL);
}

View File

@@ -63,6 +63,10 @@ symbolMap1 = {
'xmlCtxtGetValidCtxt': 'VALID',
'xmlFreeValidCtxt': 'VALID',
'xmlNewValidCtxt': 'VALID',
'xmlCatalogConvert': 'SGML_CATALOG',
'xmlConvertSGMLCatalog': 'SGML_CATALOG',
'xmlLoadSGMLSuperCatalog': 'SGML_CATALOG',
}
symbolMap2 = {

View File

@@ -76,12 +76,14 @@ XMLPUBFUN xmlCatalog *
XML_DEPRECATED
XMLPUBFUN xmlCatalog *
xmlLoadACatalog (const char *filename);
#ifdef LIBXML_SGML_CATALOG_ENABLED
XML_DEPRECATED
XMLPUBFUN xmlCatalog *
xmlLoadSGMLSuperCatalog (const char *filename);
XML_DEPRECATED
XMLPUBFUN int
xmlConvertSGMLCatalog (xmlCatalog *catal);
#endif /* LIBXML_SGML_CATALOG_ENABLED */
XML_DEPRECATED
XMLPUBFUN int
xmlACatalogAdd (xmlCatalog *catal,
@@ -155,9 +157,11 @@ XMLPUBFUN int
XML_DEPRECATED
XMLPUBFUN xmlDoc *
xmlParseCatalogFile (const char *filename);
#ifdef LIBXML_SGML_CATALOG_ENABLED
XML_DEPRECATED
XMLPUBFUN int
xmlCatalogConvert (void);
#endif /* LIBXML_SGML_CATALOG_ENABLED */
/*
* Strictly minimal interfaces for per-document catalogs used

View File

@@ -138,6 +138,7 @@
* Whether the Catalog support is configured in
*/
#define LIBXML_CATALOG_ENABLED
#define LIBXML_SGML_CATALOG_ENABLED
#endif
#if @WITH_XPATH@

View File

@@ -548,6 +548,9 @@ if want_output
test('xmlcatalog shell', sh,
args: [ 'test/catalogs/test.sh', xmlcatalog.full_path() ],
workdir: meson.current_source_dir())
test('xmlcatalog shell SGML', sh,
args: [ 'test/catalogs/test_sgml.sh', xmlcatalog.full_path() ],
workdir: meson.current_source_dir())
endif
endif
endif

View File

@@ -33,27 +33,6 @@ for i in test/catalogs/*.script ; do
fi
done
for i in test/catalogs/*.script ; do
name=$(basename $i .script)
sgml="./test/catalogs/$name.sgml"
if [ -f $sgml ] ; then
if [ ! -f result/catalogs/$name ] ; then
echo New test file $name
$xmlcatalog --shell $sgml < $i > result/catalogs/$name
else
$xmlcatalog --shell $sgml < $i > catalog.out
log=$(diff result/catalogs/$name catalog.out)
if [ -n "$log" ] ; then
echo $name result
echo "$log"
exitcode=1
fi
rm catalog.out
fi
fi
done
# Add and del operations on XML Catalogs
$xmlcatalog --create --noout mycatalog

36
test/catalogs/test_sgml.sh Executable file
View File

@@ -0,0 +1,36 @@
#!/bin/sh
set -e
echo "## SGML catalog regression tests"
if [ -n "$1" ]; then
xmlcatalog=$1
else
xmlcatalog=./xmlcatalog
fi
exitcode=0
for i in test/catalogs/*.script ; do
name=$(basename $i .script)
sgml="./test/catalogs/$name.sgml"
if [ -f $sgml ] ; then
if [ ! -f result/catalogs/$name ] ; then
echo New test file $name
$xmlcatalog --shell $sgml < $i > result/catalogs/$name
else
$xmlcatalog --shell $sgml < $i > catalog_sgml.out
log=$(diff result/catalogs/$name catalog_sgml.out)
if [ -n "$log" ] ; then
echo $name result
echo "$log"
exitcode=1
fi
rm catalog_sgml.out
fi
fi
done
exit $exitcode

View File

@@ -625,7 +625,6 @@ main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
xmlCatalogAdd(NULL, NULL, NULL);
xmlCatalogAddLocal(NULL, NULL);
xmlCatalogCleanup();
xmlCatalogConvert();
xmlCatalogFreeLocal(NULL);
xmlCatalogGetDefaults();
xmlCatalogIsEmpty(NULL);
@@ -639,13 +638,11 @@ main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
xmlCatalogSetDebug(0);
xmlCatalogSetDefaultPrefer(0);
xmlCatalogSetDefaults(0);
xmlConvertSGMLCatalog(NULL);
xmlFreeCatalog(NULL);
xmlInitializeCatalog();
xmlFreeCatalog(xmlLoadACatalog(NULL));
xmlLoadCatalog(NULL);
xmlLoadCatalogs(NULL);
xmlFreeCatalog(xmlLoadSGMLSuperCatalog(NULL));
xmlFreeCatalog(xmlNewCatalog(0));
xmlFreeDoc(xmlParseCatalogFile(NULL));
#ifdef LIBXML_OUTPUT_ENABLED
@@ -1096,6 +1093,12 @@ main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
xmlSchematronValidateDoc(NULL, NULL);
#endif /* LIBXML_SCHEMATRON_ENABLED */
#ifdef LIBXML_SGML_CATALOG_ENABLED
xmlCatalogConvert();
xmlConvertSGMLCatalog(NULL);
xmlFreeCatalog(xmlLoadSGMLSuperCatalog(NULL));
#endif /* LIBXML_SGML_CATALOG_ENABLED */
#ifdef LIBXML_VALID_ENABLED
xmlFreeValidCtxt(xmlCtxtGetValidCtxt(NULL));
xmlFreeDtd(xmlCtxtParseDtd(NULL, NULL, NULL, NULL));

View File

@@ -40,20 +40,26 @@
#if defined(LIBXML_CATALOG_ENABLED) && defined(LIBXML_OUTPUT_ENABLED)
static int shell = 0;
#ifdef LIBXML_SGML_CATALOG_ENABLED
static int sgml = 0;
#endif
static int noout = 0;
static int create = 0;
static int add = 0;
static int del = 0;
#ifdef LIBXML_SGML_CATALOG_ENABLED
static int convert = 0;
static int no_super_update = 0;
#endif
static int verbose = 0;
static char *filename = NULL;
#ifdef LIBXML_SGML_CATALOG_ENABLED
#ifndef XML_SGML_DEFAULT_CATALOG
#define XML_SGML_DEFAULT_CATALOG XML_SYSCONFDIR "/sgml/catalog"
#endif
#endif
/************************************************************************
* *
@@ -306,22 +312,26 @@ static void usershell(void) {
************************************************************************/
static void usage(const char *name) {
/* split into 2 printf's to avoid overly long string (gcc warning) */
printf("\
Usage : %s [options] catalogfile entities...\n\
\tParse the catalog file (void specification possibly expressed as \"\"\n\
\tappoints the default system one) and query it for the entities\n\
\t--sgml : handle SGML Super catalogs for --add and --del\n\
\t--shell : run a shell allowing interactive queries\n\
\t--create : create a new catalog\n\
\t--add 'type' 'orig' 'replace' : add an XML entry\n\
\t--add 'entry' : add an SGML entry\n", name);
printf("\
\t--del 'values' : remove values\n\
\t--noout: avoid dumping the result on stdout\n\
\t used with --add or --del, it saves the catalog changes\n\
\t and with --sgml it automatically updates the super catalog\n\
\t--no-super-update: do not update the SGML super catalog\n\
\t-v --verbose : provide debug information\n");
printf(
"Usage : %s [options] catalogfile entities...\n"
"\tParse the catalog file (void specification possibly expressed as \"\"\n"
"\tappoints the default system one) and query it for the entities\n"
#ifdef LIBXML_SGML_CATALOG_ENABLED
"\t--sgml : handle SGML Super catalogs for --add and --del\n"
#endif
"\t--shell : run a shell allowing interactive queries\n"
"\t--create : create a new catalog\n"
"\t--add 'type' 'orig' 'replace' : add an XML entry\n"
"\t--add 'entry' : add an SGML entry\n", name);
printf(
"\t--del 'values' : remove values\n"
"\t--noout: avoid dumping the result on stdout\n"
"\t used with --add or --del, it saves the catalog changes\n"
"\t and with --sgml it automatically updates the super catalog\n"
#ifdef LIBXML_SGML_CATALOG_ENABLED
"\t--no-super-update: do not update the SGML super catalog\n"
#endif
"\t-v --verbose : provide debug information\n");
}
int main(int argc, char **argv) {
int i;
@@ -358,23 +368,29 @@ int main(int argc, char **argv) {
(!strcmp(argv[i], "--shell"))) {
shell++;
noout = 1;
#ifdef LIBXML_SGML_CATALOG_ENABLED
} else if ((!strcmp(argv[i], "-sgml")) ||
(!strcmp(argv[i], "--sgml"))) {
sgml++;
#endif
} else if ((!strcmp(argv[i], "-create")) ||
(!strcmp(argv[i], "--create"))) {
create++;
#ifdef LIBXML_SGML_CATALOG_ENABLED
} else if ((!strcmp(argv[i], "-convert")) ||
(!strcmp(argv[i], "--convert"))) {
convert++;
} else if ((!strcmp(argv[i], "-no-super-update")) ||
(!strcmp(argv[i], "--no-super-update"))) {
no_super_update++;
#endif
} else if ((!strcmp(argv[i], "-add")) ||
(!strcmp(argv[i], "--add"))) {
#ifdef LIBXML_SGML_CATALOG_ENABLED
if (sgml)
i += 2;
else
#endif
i += 3;
add++;
} else if ((!strcmp(argv[i], "-del")) ||
@@ -391,9 +407,11 @@ int main(int argc, char **argv) {
for (i = 1; i < argc; i++) {
if ((!strcmp(argv[i], "-add")) ||
(!strcmp(argv[i], "--add"))) {
#ifdef LIBXML_SGML_CATALOG_ENABLED
if (sgml)
i += 2;
else
#endif
i += 3;
continue;
} else if ((!strcmp(argv[i], "-del")) ||
@@ -401,7 +419,11 @@ int main(int argc, char **argv) {
i += 1;
/* No catalog entry specified */
if (i == argc || (sgml && i + 1 == argc)) {
if (i == argc
#ifdef LIBXML_SGML_CATALOG_ENABLED
|| (sgml && i + 1 == argc)
#endif
) {
fprintf(stderr, "No catalog entry specified to remove from\n");
usage (argv[0]);
return(1);
@@ -432,8 +454,10 @@ int main(int argc, char **argv) {
break;
}
#ifdef LIBXML_SGML_CATALOG_ENABLED
if (convert)
ret = xmlCatalogConvert();
#endif
if ((add) || (del)) {
for (i = 1; i < argc ; i++) {
@@ -446,6 +470,7 @@ int main(int argc, char **argv) {
strcmp(argv[i], "-del") && strcmp(argv[i], "--del"))
continue;
#ifdef LIBXML_SGML_CATALOG_ENABLED
if (sgml) {
/*
* Maintenance of SGML catalogs.
@@ -538,7 +563,9 @@ int main(int argc, char **argv) {
xmlFreeCatalog(catal);
xmlFreeCatalog(super);
} else {
} else
#endif /* LIBXML_SGML_CATALOG_ENABLED */
{
if ((!strcmp(argv[i], "-add")) ||
(!strcmp(argv[i], "--add"))) {
if ((argv[i + 3] == NULL) || (argv[i + 3][0] == 0))
@@ -603,7 +630,15 @@ int main(int argc, char **argv) {
}
}
}
if ((!sgml) && ((add) || (del) || (create) || (convert))) {
if (
#ifdef LIBXML_SGML_CATALOG_ENABLED
(!sgml) &&
#endif
((add) || (del) || (create)
#ifdef LIBXML_SGML_CATALOG_ENABLED
|| (convert)
#endif
)) {
if (noout && filename && *filename) {
FILE *out;