Commit cda96921 authored by Daniel Veillard's avatar Daniel Veillard

more work on the XML catalog support. small cleanup seems using list as a

* Makefile.am catalog.c xmlcatalog.c include/libxml/catalog.h:
  more work on the XML catalog support.
* parser.c include/libxml/parser.h: small cleanup seems using
  list as a public parameter name can give portability troubles
* trionan.c trionan.h xpath.c include/libxml/trionan.h
  include/libxml/xpath.h include/libxml/Makefile.am: removed
  trionan from the libxml API, added xmlXPathIsInf and xmlXPathIsNaN
  wrappers
Daniel
parent 45029607
Tue Aug 21 12:52:38 CEST 2001 Daniel Veillard <daniel@veillard.com>
* Makefile.am catalog.c xmlcatalog.c include/libxml/catalog.h:
more work on the XML catalog support.
* parser.c include/libxml/parser.h: small cleanup seems using
list as a public parameter name can give portability troubles
* trionan.c trionan.h xpath.c include/libxml/trionan.h
include/libxml/xpath.h include/libxml/Makefile.am: removed
trionan from the libxml API, added xmlXPathIsInf and xmlXPathIsNaN
wrappers
Tue Aug 21 11:18:45 CEST 2001 Bjorn Reese <breese@users.sourceforge.net>
* Makefile.am trio.c triodef.h trionan.c xpath.c
......
......@@ -23,14 +23,14 @@ libxml2_la_SOURCES = SAX.c entities.c encoding.c error.c parserInternals.c \
parser.c tree.c hash.c list.c xmlIO.c xmlmemory.c uri.c \
valid.c xlink.c HTMLparser.c HTMLtree.c debugXML.c xpath.c \
xpointer.c xinclude.c nanohttp.c nanoftp.c DOCBparser.c \
catalog.c trionan.c strio.c trio.c
catalog.c strio.c trio.c
else
libxml2_la_SOURCES = SAX.c entities.c encoding.c error.c parserInternals.c \
parser.c tree.c hash.c list.c xmlIO.c xmlmemory.c uri.c \
valid.c xlink.c HTMLparser.c HTMLtree.c debugXML.c xpath.c \
xpointer.c xinclude.c nanohttp.c nanoftp.c DOCBparser.c \
catalog.c trionan.c
catalog.c
endif
......@@ -81,7 +81,7 @@ check-local: tests
testall : tests SVGtests SAXtests
tests: XMLtests XMLenttests HTMLtests Validtests URItests XPathtests XPtrtests XIncludetests Scripttests
tests: XMLtests XMLenttests HTMLtests Validtests URItests XPathtests XPtrtests XIncludetests Scripttests Catatests
HTMLtests : testHTML
@(echo > .memdump)
......@@ -378,6 +378,26 @@ Scripttests : xmllint
rm result.$$name ; \
fi ; fi ; done)
Catatests : xmlcatalog
@(echo > .memdump)
@echo "##"
@echo "## Catalog regression tests"
@echo "##"
@(for i in $(srcdir)/test/catalogs/*.script ; do \
name=`basename $$i .script`; \
xml=$(srcdir)/test/catalogs/`basename $$i .script`.xml; \
if [ -f $$xml ] ; then \
if [ ! -f $(srcdir)/result/catalogs/$$name ] ; then \
echo New test file $$name ; \
$(top_builddir)/xmlcatalog --shell $$xml < $$i > $(srcdir)/result/catalogs/$$name ; \
else \
echo Testing $$name ; \
$(top_builddir)/xmlcatalog --shell $$xml < $$i > result.$$name ; \
grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0";\
diff $(srcdir)/result/catalogs/$$name result.$$name ; \
rm result.$$name ; \
fi ; fi ; done)
SVGtests : xmllint
@echo "##"
@echo "## SVG parsing regression tests"
......
This diff is collapsed.
......@@ -29,8 +29,7 @@ xmlinc_HEADERS = \
xmlversion.h \
xmlwin32version.h \
DOCBparser.h \
catalog.h \
trionan.h
catalog.h
install-exec-hook:
$(mkinstalldirs) $(DESTDIR)$(xmlincdir) $(DESTDIR)$(xmlincdir)/libxml
......
......@@ -42,7 +42,7 @@ void xmlCatalogCleanup (void);
void xmlCatalogDump (FILE *out);
const xmlChar * xmlCatalogGetSystem (const xmlChar *sysID);
const xmlChar * xmlCatalogGetPublic (const xmlChar *pubID);
const xmlChar * xmlCatalogResolve (const xmlChar *pubID,
xmlChar * xmlCatalogResolve (const xmlChar *pubID,
const xmlChar *sysID);
int xmlCatalogAdd (const xmlChar *type,
const xmlChar *orig,
......
......@@ -471,18 +471,18 @@ int xmlParseBalancedChunkMemory(xmlDocPtr doc,
void *user_data,
int depth,
const xmlChar *string,
xmlNodePtr *list);
xmlNodePtr *lst);
int xmlParseExternalEntity (xmlDocPtr doc,
xmlSAXHandlerPtr sax,
void *user_data,
int depth,
const xmlChar *URL,
const xmlChar *ID,
xmlNodePtr *list);
xmlNodePtr *lst);
int xmlParseCtxtExternalEntity(xmlParserCtxtPtr ctx,
const xmlChar *URL,
const xmlChar *ID,
xmlNodePtr *list);
xmlNodePtr *lst);
/*
* SAX initialization routines
......
......@@ -295,6 +295,9 @@ LIBXML_DLL_IMPORT extern double xmlXPathNAN;
LIBXML_DLL_IMPORT extern double xmlXPathPINF;
LIBXML_DLL_IMPORT extern double xmlXPathNINF;
int xmlXPathIsNaN (double val);
int xmlXPathIsInf (double val);
/* These macros may later turn into functions */
/**
* xmlXPathNodeSetGetLength:
......
......@@ -8921,7 +8921,7 @@ xmlParseDTD(const xmlChar *ExternalID, const xmlChar *SystemID) {
* @ctx: the existing parsing context
* @URL: the URL for the entity to load
* @ID: the System ID for the entity to load
* @list: the return value for the set of parsed nodes
* @lst: the return value for the set of parsed nodes
*
* Parse an external general entity within an existing parsing context
* An external general parsed entity is well-formed if it matches the
......@@ -8935,7 +8935,7 @@ xmlParseDTD(const xmlChar *ExternalID, const xmlChar *SystemID) {
int
xmlParseCtxtExternalEntity(xmlParserCtxtPtr ctx, const xmlChar *URL,
const xmlChar *ID, xmlNodePtr *list) {
const xmlChar *ID, xmlNodePtr *lst) {
xmlParserCtxtPtr ctxt;
xmlDocPtr newDoc;
xmlSAXHandlerPtr oldsax = NULL;
......@@ -8947,8 +8947,8 @@ xmlParseCtxtExternalEntity(xmlParserCtxtPtr ctx, const xmlChar *URL,
return(XML_ERR_ENTITY_LOOP);
}
if (list != NULL)
*list = NULL;
if (lst != NULL)
*lst = NULL;
if ((URL == NULL) && (ID == NULL))
return(-1);
if (ctx->myDoc == NULL) /* @@ relax but check for dereferences */
......@@ -9065,7 +9065,7 @@ xmlParseCtxtExternalEntity(xmlParserCtxtPtr ctx, const xmlChar *URL,
else
ret = ctxt->errNo;
} else {
if (list != NULL) {
if (lst != NULL) {
xmlNodePtr cur;
/*
......@@ -9073,7 +9073,7 @@ xmlParseCtxtExternalEntity(xmlParserCtxtPtr ctx, const xmlChar *URL,
* they pseudo parent.
*/
cur = newDoc->children->children;
*list = cur;
*lst = cur;
while (cur != NULL) {
cur->parent = NULL;
cur = cur->next;
......@@ -9282,7 +9282,7 @@ xmlParseExternalEntityPrivate(xmlDocPtr doc, xmlParserCtxtPtr oldctxt,
* @depth: Used for loop detection, use 0
* @URL: the URL for the entity to load
* @ID: the System ID for the entity to load
* @list: the return value for the set of parsed nodes
* @lst: the return value for the set of parsed nodes
*
* Parse an external general entity
* An external general parsed entity is well-formed if it matches the
......@@ -9296,9 +9296,9 @@ xmlParseExternalEntityPrivate(xmlDocPtr doc, xmlParserCtxtPtr oldctxt,
int
xmlParseExternalEntity(xmlDocPtr doc, xmlSAXHandlerPtr sax, void *user_data,
int depth, const xmlChar *URL, const xmlChar *ID, xmlNodePtr *list) {
int depth, const xmlChar *URL, const xmlChar *ID, xmlNodePtr *lst) {
return(xmlParseExternalEntityPrivate(doc, NULL, sax, user_data, depth, URL,
ID, list));
ID, lst));
}
/**
......@@ -9308,7 +9308,7 @@ xmlParseExternalEntity(xmlDocPtr doc, xmlSAXHandlerPtr sax, void *user_data,
* @user_data: The user data returned on SAX callbacks (possibly NULL)
* @depth: Used for loop detection, use 0
* @string: the input string in UTF8 or ISO-Latin (zero terminated)
* @list: the return value for the set of parsed nodes
* @lst: the return value for the set of parsed nodes
*
* Parse a well-balanced chunk of an XML document
* called by the parser
......@@ -9323,7 +9323,7 @@ xmlParseExternalEntity(xmlDocPtr doc, xmlSAXHandlerPtr sax, void *user_data,
int
xmlParseBalancedChunkMemory(xmlDocPtr doc, xmlSAXHandlerPtr sax,
void *user_data, int depth, const xmlChar *string, xmlNodePtr *list) {
void *user_data, int depth, const xmlChar *string, xmlNodePtr *lst) {
xmlParserCtxtPtr ctxt;
xmlDocPtr newDoc;
xmlSAXHandlerPtr oldsax = NULL;
......@@ -9335,8 +9335,8 @@ xmlParseBalancedChunkMemory(xmlDocPtr doc, xmlSAXHandlerPtr sax,
}
if (list != NULL)
*list = NULL;
if (lst != NULL)
*lst = NULL;
if (string == NULL)
return(-1);
......@@ -9418,7 +9418,7 @@ xmlParseBalancedChunkMemory(xmlDocPtr doc, xmlSAXHandlerPtr sax,
else
ret = ctxt->errNo;
} else {
if (list != NULL) {
if (lst != NULL) {
xmlNodePtr cur;
/*
......@@ -9426,7 +9426,7 @@ xmlParseBalancedChunkMemory(xmlDocPtr doc, xmlSAXHandlerPtr sax,
* they pseudo parent.
*/
cur = newDoc->children->children;
*list = cur;
*lst = cur;
while (cur != NULL) {
cur->parent = NULL;
cur = cur->next;
......
......@@ -200,7 +200,7 @@ trio_is_special_quantity(double number,
/*************************************************************************
* trio_pinf
*/
double
TRIO_PUBLIC double
trio_pinf(void)
{
/* Cache the result */
......@@ -242,7 +242,7 @@ trio_pinf(void)
/*************************************************************************
* trio_ninf
*/
double
TRIO_PUBLIC double
trio_ninf(void)
{
static double result = 0.0;
......@@ -261,7 +261,7 @@ trio_ninf(void)
/*************************************************************************
* trio_nan
*/
double
TRIO_PUBLIC double
trio_nan(void)
{
/* Cache the result */
......@@ -306,7 +306,7 @@ trio_nan(void)
/*************************************************************************
* trio_isnan
*/
int
TRIO_PUBLIC int
trio_isnan(volatile double number)
{
#if defined(isnan) || defined(TRIO_COMPILER_SUPPORTS_UNIX95)
......@@ -370,7 +370,7 @@ trio_isnan(volatile double number)
/*************************************************************************
* trio_isinf
*/
int
TRIO_PUBLIC int
trio_isinf(volatile double number)
{
#if defined(TRIO_COMPILER_DECC)
......
......@@ -21,30 +21,40 @@
#ifdef __cplusplus
extern "C" {
#endif
#ifndef TRIO_PUBLIC
#define TRIO_PUBLIC
#endif
/*
* Return NaN (Not-a-Number).
*/
TRIO_PUBLIC
double trio_nan(void);
/*
* Return positive infinity.
*/
TRIO_PUBLIC
double trio_pinf(void);
/*
* Return negative infinity.
*/
TRIO_PUBLIC
double trio_ninf(void);
/*
* If number is a NaN return non-zero, otherwise return zero.
*/
TRIO_PUBLIC
int trio_isnan(double number);
/*
* If number is positive infinity return 1, if number is negative
* infinity return -1, otherwise return 0.
*/
TRIO_PUBLIC
int trio_isinf(double number);
#ifdef __cplusplus
......
......@@ -26,7 +26,10 @@
static int shell = 0;
static int noout = 0;
static int add = 0;
static int del = 0;
static int verbose = 0;
static char *filename;
#ifdef LIBXML_CATALOG_ENABLED
/************************************************************************
......@@ -74,8 +77,10 @@ static void usershell(void) {
int nbargs;
char command[100];
char arg[400];
int i;
char *argv[20];
int i, ret;
const xmlChar *answer;
xmlChar *ans;
while (1) {
cmdline = xmlShellReadline("> ");
......@@ -100,8 +105,9 @@ static void usershell(void) {
nbargs++;
/*
* Parse the argument
* Parse the argument string
*/
memset(arg, 0, sizeof(arg));
while ((*cur == ' ') || (*cur == '\t')) cur++;
i = 0;
while ((*cur != '\n') && (*cur != '\r') && (*cur != 0)) {
......@@ -113,6 +119,46 @@ static void usershell(void) {
if (i != 0)
nbargs++;
/*
* Parse the arguments
*/
i = 0;
nbargs = 0;
cur = arg;
memset(argv, 0, sizeof(argv));
while (*cur != 0) {
while ((*cur == ' ') || (*cur == '\t')) cur++;
if (*cur == '\'') {
cur++;
argv[i] = cur;
while ((*cur != 0) && (*cur != '\'')) cur++;
if (*cur == '\'') {
*cur = 0;
nbargs++;
i++;
cur++;
}
} else if (*cur == '"') {
cur++;
argv[i] = cur;
while ((*cur != 0) && (*cur != '"')) cur++;
if (*cur == '"') {
*cur = 0;
nbargs++;
i++;
cur++;
}
} else {
argv[i] = cur;
while ((*cur != 0) && (*cur != ' ') && (*cur != '\t'))
cur++;
*cur = 0;
nbargs++;
i++;
cur++;
}
}
/*
* start interpreting the command
*/
......@@ -123,21 +169,68 @@ static void usershell(void) {
if (!strcmp(command, "bye"))
break;
if (!strcmp(command, "public")) {
answer = xmlCatalogGetPublic((const xmlChar *) arg);
if (answer == NULL) {
printf("No entry for PUBLIC %s\n", arg);
if (nbargs != 1) {
printf("public requires 1 arguments\n");
} else {
printf("%s\n", answer);
answer = xmlCatalogGetPublic((const xmlChar *) argv[0]);
if (answer == NULL) {
printf("No entry for PUBLIC %s\n", argv[0]);
} else {
printf("%s\n", answer);
}
}
} else if (!strcmp(command, "system")) {
answer = xmlCatalogGetSystem((const xmlChar *) arg);
if (answer == NULL) {
printf("No entry for SYSTEM %s\n", arg);
if (nbargs != 1) {
printf("system requires 1 arguments\n");
} else {
answer = xmlCatalogGetSystem((const xmlChar *) argv[0]);
if (answer == NULL) {
printf("No entry for SYSTEM %s\n", argv[0]);
} else {
printf("%s\n", answer);
}
}
} else if (!strcmp(command, "add")) {
if ((nbargs != 3) && (nbargs != 2)) {
printf("add requires 2 or 3 arguments\n");
} else {
if (argv[2] == NULL)
ret = xmlCatalogAdd(BAD_CAST argv[0], NULL,
BAD_CAST argv[1]);
else
ret = xmlCatalogAdd(BAD_CAST argv[0], BAD_CAST argv[1],
BAD_CAST argv[2]);
if (ret != 0)
printf("add command failed\n");
}
} else if (!strcmp(command, "del")) {
if (nbargs != 1) {
printf("del requires 1\n");
} else {
ret = xmlCatalogRemove(BAD_CAST argv[0]);
if (ret <= 0)
printf("del command failed\n");
}
} else if (!strcmp(command, "resolve")) {
if (nbargs != 2) {
printf("resolve requires 2 arguments\n");
} else {
printf("%s\n", answer);
ans = xmlCatalogResolve(BAD_CAST argv[0],
BAD_CAST argv[1]);
if (ans == NULL) {
printf("Resolver failed to find an answer\n");
} else {
printf("%s\n", ans);
xmlFree(ans);
}
}
} else if (!strcmp(command, "dump")) {
xmlCatalogDump(stdout);
if (nbargs != 0) {
printf("dump has no arguments\n");
} else {
xmlCatalogDump(stdout);
}
} else {
if (strcmp(command, "help")) {
printf("Unrecognized command %s\n", command);
......@@ -145,6 +238,9 @@ static void usershell(void) {
printf("Commands available:\n");
printf("\tpublic PublicID: make a PUBLIC identifier lookup\n");
printf("\tsystem SystemID: make a SYSTEM identifier lookup\n");
printf("\tresolve PublicID SystemID: do a full resolver lookup\n");
printf("\tadd 'type' 'orig' 'replace' : add an entry\n");
printf("\tdel 'values' : remove values\n");
printf("\tdump: print the current catalog state\n");
printf("\texit: quit the shell\n");
}
......@@ -158,9 +254,13 @@ static void usershell(void) {
* *
************************************************************************/
static void usage(const char *name) {
printf("Usage : %s [options] catalogfile ...\n", name);
printf("\tParse the catalog file(s) and output the result of the parsing\n");
printf("Usage : %s [options] catalogfile\n", name);
printf("\tParse the catalog file and output the result of the parsing\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");
printf("\t--noout: avoid dumping the result on stdout\n");
printf("\t used with add or del, it saves the catalog changes\n");
printf("\t-v --verbose : provide debug informations\n");
}
int main(int argc, char **argv) {
......@@ -183,10 +283,21 @@ int main(int argc, char **argv) {
(!strcmp(argv[i], "--verbose"))) {
verbose++;
xmlCatalogSetDebug(verbose);
} else if ((!strcmp(argv[i], "-noout")) ||
(!strcmp(argv[i], "--noout"))) {
noout = 1;
} else if ((!strcmp(argv[i], "-shell")) ||
(!strcmp(argv[i], "--shell"))) {
shell++;
noout = 1;
} else if ((!strcmp(argv[i], "-add")) ||
(!strcmp(argv[i], "--add"))) {
i += 3;
add++;
} else if ((!strcmp(argv[i], "-del")) ||
(!strcmp(argv[i], "--del"))) {
i += 1;
del++;
} else {
fprintf(stderr, "Unknown option %s\n", argv[i]);
usage(argv[0]);
......@@ -195,9 +306,60 @@ int main(int argc, char **argv) {
}
for (i = 1; i < argc; i++) {
if (argv[i][0] == '-')
if ((!strcmp(argv[i], "-add")) ||
(!strcmp(argv[i], "--add"))) {
i += 3;
continue;
} else if ((!strcmp(argv[i], "-del")) ||
(!strcmp(argv[i], "--del"))) {
i += 1;
continue;
} else if (argv[i][0] == '-')
continue;
filename = argv[i];
xmlLoadCatalog(argv[i]);
break;
}
if ((add) || (del)) {
int ret;
for (i = 1; i < argc ; i++) {
if (!strcmp(argv[i], "-"))
break;
if (argv[i][0] != '-')
continue;
if ((!strcmp(argv[i], "-add")) ||
(!strcmp(argv[i], "--add"))) {
if ((argv[i + 3] == NULL) || (argv[i + 3][0] == 0))
ret = xmlCatalogAdd(BAD_CAST argv[i + 1], NULL,
BAD_CAST argv[i + 2]);
else
ret = xmlCatalogAdd(BAD_CAST argv[i + 1],
BAD_CAST argv[i + 2],
BAD_CAST argv[i + 3]);
if (ret != 0)
printf("add command failed\n");
i += 3;
} else if ((!strcmp(argv[i], "-del")) ||
(!strcmp(argv[i], "--del"))) {
ret = xmlCatalogRemove(BAD_CAST argv[i + 1]);
i += 1;
}
}
if (noout) {
FILE *out;
out = fopen(filename, "w");
if (out == NULL) {
fprintf(stderr, "could not open %s for saving\n", filename);
noout = 0;
} else {
xmlCatalogDump(out);
}
}
}
if (shell) {
......
......@@ -51,7 +51,6 @@
#include <libxml/debugXML.h>
#endif
#include <libxml/xmlerror.h>
#include <libxml/trionan.h>
/* #define DEBUG */
/* #define DEBUG_STEP */
......@@ -69,6 +68,9 @@ double xmlXPathDivideBy(double f, double fzero);
* *
************************************************************************/
#define TRIO_PUBLIC static
#include "trionan.c"
/*
* The lack of portability of this section of the libc is annoying !
*/
......@@ -94,6 +96,36 @@ xmlXPathInit(void) {
initialized = 1;
}
/**
* xmlXPathIsNaN:
* @val: a double value
*
* Provides a portable isnan() function to detect whether a double
* is a NotaNumber. Based on trio code
* http://sourceforge.net/projects/ctrio/
*
* Returns 1 if the value is a NaN, 0 otherwise
*/
int
xmlXPathIsNaN(double val) {
return(trio_isnan(val));
}
/**
* xmlXPathIsInf:
* @val: a double value
*
* Provides a portable isinf() function to detect whether a double
* is a +Infinite or -Infinite. Based on trio code
* http://sourceforge.net/projects/ctrio/
*
* Returns 1 vi the value is +Infinite, -1 if -Infinite, 0 otherwise
*/
int
xmlXPathIsInf(double val) {
return(trio_isinf(val));
}