Commit e2940ddb authored by Daniel Veillard's avatar Daniel Veillard
Browse files

starts to look okay, really plugged the new framework, cleaned a lot of

* catalog.c parser.c xmlIO.c xmlcatalog.c xmllint.c
  include/libxml/catalog.h: starts to look okay, really
  plugged the new framework, cleaned a lot of stuff,
  added some APIs, except the PI's support missing this
  should be mostly complete
* result/catalogs/* test/catalogs/*: added new test, enriched
  the existing one with URN ID tests
Daniel
parent 64339546
Wed Aug 22 02:03:31 CEST 2001 Daniel Veillard <daniel@veillard.com>
* catalog.c parser.c xmlIO.c xmlcatalog.c xmllint.c
include/libxml/catalog.h: starts to look okay, really
plugged the new framework, cleaned a lot of stuff,
added some APIs, except the PI's support missing this
should be mostly complete
* result/catalogs/* test/catalogs/*: added new test, enriched
the existing one with URN ID tests
Tue Aug 21 14:56:18 CEST 2001 Daniel Veillard <daniel@veillard.com>
* catalog.c: fixed nextCatalog
......
This diff is collapsed.
......@@ -36,19 +36,34 @@ extern "C" {
#define XML_CATALOGS_NAMESPACE \
(const xmlChar *) "urn:oasis:names:tc:entity:xmlns:xml:catalog"
/*
* The API is voluntarily limited to general cataloging
*/
typedef enum {
XML_CATA_PREFER_NONE = 0,
XML_CATA_PREFER_PUBLIC = 1,
XML_CATA_PREFER_SYSTEM
} xmlCatalogPrefer;
void xmlInitializeCatalog (void);
int xmlLoadCatalog (const char *filename);
void xmlLoadCatalogs (const char *paths);
void xmlCatalogCleanup (void);
void xmlCatalogDump (FILE *out);
const xmlChar * xmlCatalogGetSystem (const xmlChar *sysID);
const xmlChar * xmlCatalogGetPublic (const xmlChar *pubID);
xmlChar * xmlCatalogResolve (const xmlChar *pubID,
const xmlChar *sysID);
xmlChar * xmlCatalogResolveSystem (const xmlChar *sysID);
xmlChar * xmlCatalogResolvePublic (const xmlChar *pubID);
int xmlCatalogAdd (const xmlChar *type,
const xmlChar *orig,
const xmlChar *replace);
int xmlCatalogRemove (const xmlChar *value);
int xmlCatalogSetDebug (int level);
xmlCatalogPrefer xmlCatalogSetDefaultPrefer(xmlCatalogPrefer prefer);
/* DEPRECATED interfaces */
const xmlChar * xmlCatalogGetSystem (const xmlChar *sysID);
const xmlChar * xmlCatalogGetPublic (const xmlChar *pubID);
#ifdef __cplusplus
}
......
......@@ -10100,5 +10100,8 @@ xmlCleanupParser(void) {
xmlParserInitialized = 0;
xmlCleanupCharEncodingHandlers();
xmlCleanupPredefinedEntities();
#ifdef LIBXML_CATALOG_ENABLED
xmlCatalogCleanup();
#endif
}
> /usr/share/xml/docbook/xml/4.1.2/dbpoolx.mod
> http://www.oasis-open.org/docbook/xml/4.1.2/dbcentx.mod
> http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd
> http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd
> file:///usr/share/xml/toto/toto.dtd
>
\ No newline at end of file
> /usr/share/xml/docbook/xml/4.1.2/dbpoolx.mod
> http://www.oasis-open.org/docbook/xml/4.1.2/dbcentx.mod
> /usr/share/xml/docbook/xml/4.1.2/dbpoolx.mod
> http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd
>
\ No newline at end of file
resolve toto http://www.oasis-open.org/docbook/xml/4.1.2/dbpoolx.mod
public "-//OASIS//ENTITIES DocBook XML Character Entities V4.1.2//EN"
system urn:publicid:-:OASIS:DTD+DocBook+XML+V4.1.2:EN
public urn:publicid:-:OASIS:DTD+DocBook+XML+V4.1.2:EN
resolve toto toto
resolve toto http://www.oasis-open.org/docbook/xml/4.1.2/dbpoolx.mod
public "-//OASIS//ENTITIES DocBook XML Character Entities V4.1.2//EN"
system http://www.oasis-open.org/docbook/xml/4.1.2/dbpoolx.mod
system urn:publicid:-:OASIS:DTD+DocBook+XML+V4.1.2:EN
<?xml version="1.0"?>
<!DOCTYPE catalog PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN" "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd">
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<delegatePublic publicIdStartString="-//OASIS//"
catalog="oasis.xml"/>
<delegateSystem systemIdStartString="http://www.oasis-open.org/"
catalog="oasis.xml"/>
<delegateURI uriStartString="http://www.oasis-open.org/"
catalog="oasis.xml"/>
<delegatePublic publicIdStartString="-//OASIS//DTD XML Catalog //"
catalog="docbook.xml"/>
<delegatePublic publicIdStartString="-//OASIS//ENTITIES DocBook XML"
catalog="docbook.xml"/>
<delegatePublic publicIdStartString="-//OASIS//DTD DocBook XML"
catalog="docbook.xml"/>
<delegateSystem systemIdStartString="http://www.oasis-open.org/docbook/"
catalog="docbook.xml"/>
<delegateURI uriStartString="http://www.oasis-open.org/docbook/"
catalog="docbook.xml"/>
</catalog>
......@@ -2371,7 +2371,10 @@ xmlParserInputPtr
xmlDefaultExternalEntityLoader(const char *URL, const char *ID,
xmlParserCtxtPtr ctxt) {
xmlParserInputPtr ret = NULL;
const xmlChar *resource = NULL;
xmlChar *resource = NULL;
#ifdef LIBXML_CATALOG_ENABLED
struct stat info;
#endif
#ifdef DEBUG_EXTERNAL_ENTITIES
xmlGenericError(xmlGenericErrorContext,
......@@ -2379,16 +2382,18 @@ xmlDefaultExternalEntityLoader(const char *URL, const char *ID,
#endif
#ifdef LIBXML_CATALOG_ENABLED
/*
* Try to load it from the resource pointed in the catalog
* If the resource doesn't exists as a file,
* try to load it from the resource pointed in the catalog
*/
if (ID != NULL)
resource = xmlCatalogGetPublic((const xmlChar *)ID);
if ((resource == NULL) && (URL != NULL))
resource = xmlCatalogGetSystem((const xmlChar *)URL);
#ifdef HAVE_STAT
if ((URL == NULL) || (stat(URL, &info) < 0))
#endif
resource = xmlCatalogResolve((const xmlChar *)ID,
(const xmlChar *)URL);
#endif
if (resource == NULL)
resource = (const xmlChar *)URL;
resource = (xmlChar *) URL;
if (resource == NULL) {
if ((ctxt->validate) && (ctxt->sax != NULL) &&
......@@ -2410,6 +2415,8 @@ xmlDefaultExternalEntityLoader(const char *URL, const char *ID,
ctxt->sax->warning(ctxt,
"failed to load external entity \"%s\"\n", resource);
}
if (resource != (xmlChar *) URL)
xmlFree(resource);
return(ret);
}
......
......@@ -79,7 +79,6 @@ static void usershell(void) {
char arg[400];
char *argv[20];
int i, ret;
const xmlChar *answer;
xmlChar *ans;
while (1) {
......@@ -172,22 +171,24 @@ static void usershell(void) {
if (nbargs != 1) {
printf("public requires 1 arguments\n");
} else {
answer = xmlCatalogGetPublic((const xmlChar *) argv[0]);
if (answer == NULL) {
ans = xmlCatalogResolvePublic((const xmlChar *) argv[0]);
if (ans == NULL) {
printf("No entry for PUBLIC %s\n", argv[0]);
} else {
printf("%s\n", answer);
printf("%s\n", ans);
xmlFree(ans);
}
}
} else if (!strcmp(command, "system")) {
if (nbargs != 1) {
printf("system requires 1 arguments\n");
} else {
answer = xmlCatalogGetSystem((const xmlChar *) argv[0]);
if (answer == NULL) {
ans = xmlCatalogResolveSystem((const xmlChar *) argv[0]);
if (ans == NULL) {
printf("No entry for SYSTEM %s\n", argv[0]);
} else {
printf("%s\n", answer);
printf("%s\n", ans);
xmlFree(ans);
}
}
} else if (!strcmp(command, "add")) {
......@@ -231,6 +232,21 @@ static void usershell(void) {
} else {
xmlCatalogDump(stdout);
}
} else if (!strcmp(command, "debug")) {
if (nbargs != 0) {
printf("debug has no arguments\n");
} else {
verbose++;
xmlCatalogSetDebug(verbose);
}
} else if (!strcmp(command, "quiet")) {
if (nbargs != 0) {
printf("quiet has no arguments\n");
} else {
if (verbose > 0)
verbose--;
xmlCatalogSetDebug(verbose);
}
} else {
if (strcmp(command, "help")) {
printf("Unrecognized command %s\n", command);
......@@ -242,6 +258,8 @@ static void usershell(void) {
printf("\tadd 'type' 'orig' 'replace' : add an entry\n");
printf("\tdel 'values' : remove values\n");
printf("\tdump: print the current catalog state\n");
printf("\tdebug: increase the verbosity level\n");
printf("\tquiet: decrease the verbosity level\n");
printf("\texit: quit the shell\n");
}
free(cmdline); /* not xmlFree here ! */
......@@ -254,8 +272,8 @@ static void usershell(void) {
* *
************************************************************************/
static void usage(const char *name) {
printf("Usage : %s [options] catalogfile\n", name);
printf("\tParse the catalog file and output the result of the parsing\n");
printf("Usage : %s [options] catalogfile entities...\n", name);
printf("\tParse the catalog file and query it for the entities\n");
printf("\t--shell : run a shell allowing interactive queries\n");
printf("\t--add 'type' 'orig' 'replace' : add an entry\n");
printf("\t--del 'values' : remove values\n");
......@@ -277,7 +295,7 @@ int main(int argc, char **argv) {
break;
if (argv[i][0] != '-')
continue;
break;
if ((!strcmp(argv[i], "-verbose")) ||
(!strcmp(argv[i], "-v")) ||
(!strcmp(argv[i], "--verbose"))) {
......@@ -360,19 +378,38 @@ int main(int argc, char **argv) {
xmlCatalogDump(out);
}
}
}
if (shell) {
} else if (shell) {
usershell();
}
if (!noout) {
xmlCatalogDump(stdout);
} else {
for (i++; i < argc; i++) {
xmlURIPtr uri;
xmlChar *ans;
uri = xmlParseURI(argv[i]);
if (uri == NULL) {
ans = xmlCatalogResolvePublic((const xmlChar *) argv[i]);
if (ans == NULL) {
printf("No entry for PUBLIC %s\n", argv[i]);
} else {
printf("%s\n", ans);
xmlFree(ans);
}
} else {
xmlFreeURI(uri);
ans = xmlCatalogResolveSystem((const xmlChar *) argv[i]);
if (ans == NULL) {
printf("No entry for SYSTEM %s\n", argv[i]);
} else {
printf("%s\n", ans);
xmlFree(ans);
}
}
}
}
/*
* Cleanup and check for memory leaks
*/
xmlCatalogCleanup();
xmlCleanupParser();
xmlMemoryDump();
return(0);
......
......@@ -104,6 +104,10 @@ static int progresult = 0;
static int timing = 0;
static int generate = 0;
static struct timeval begin, end;
#ifdef LIBXML_CATALOG_ENABLED
static int catalogs = 0;
static int nocatalogs = 0;
#endif
/************************************************************************
* *
......@@ -798,6 +802,8 @@ static void usage(const char *name) {
printf("\t--encode encoding : output in the given encoding\n");
#ifdef LIBXML_CATALOG_ENABLED
printf("\t--catalogs : use the catalogs from $SGML_CATALOG_FILES\n");
printf("\t otherwise /etc/xml/catalog is activated by default\n");
printf("\t--nocatalogs: desactivate all catalogs\n");
#endif
printf("\t--auto : generate a small doc on the fly\n");
#ifdef LIBXML_XINCLUDE_ENABLED
......@@ -931,14 +937,10 @@ main(int argc, char **argv) {
#ifdef LIBXML_CATALOG_ENABLED
else if ((!strcmp(argv[i], "-catalogs")) ||
(!strcmp(argv[i], "--catalogs"))) {
const char *catalogs;
catalogs = getenv("SGML_CATALOG_FILES");
if (catalogs == NULL) {
fprintf(stderr, "Variable $SGML_CATALOG_FILES not set\n");
} else {
xmlLoadCatalogs(catalogs);
}
catalogs++;
} else if ((!strcmp(argv[i], "-nocatalogs")) ||
(!strcmp(argv[i], "--nocatalogs"))) {
nocatalogs++;
}
#endif
else if ((!strcmp(argv[i], "-encode")) ||
......@@ -966,6 +968,17 @@ main(int argc, char **argv) {
return(1);
}
}
#ifdef LIBXML_CATALOG_ENABLED
if (nocatalogs == 0) {
if (catalogs) {
const char *catal;
catal = getenv("SGML_CATALOG_FILES");
xmlLoadCatalogs(catal);
}
}
#endif
xmlLineNumbersDefault(1);
if (loaddtd != 0)
xmlLoadExtDtdDefaultValue |= XML_DETECT_IDS;
......
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