mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-29 11:41:22 +03:00
allow to give -1 for undefined length in lookups first round of work on
* dict.c: allow to give -1 for undefined length in lookups * include/libxml/parser.h parser.c parserInternals.c testSAX.c: first round of work on the new SAX2 interfaces, the API will change but commiting before changing for historical reference. Daniel
This commit is contained in:
@ -1,3 +1,11 @@
|
|||||||
|
Sun Sep 7 11:11:45 CEST 2003 Daniel Veillard <daniel@veillard.com>
|
||||||
|
|
||||||
|
* dict.c: allow to give -1 for undefined length in lookups
|
||||||
|
* include/libxml/parser.h parser.c parserInternals.c testSAX.c:
|
||||||
|
first round of work on the new SAX2 interfaces, the API
|
||||||
|
will change but commiting before changing for historical
|
||||||
|
reference.
|
||||||
|
|
||||||
Sat Sep 6 10:55:01 PTD 2003 William Brack <wbrack@mmm.com.hk>
|
Sat Sep 6 10:55:01 PTD 2003 William Brack <wbrack@mmm.com.hk>
|
||||||
|
|
||||||
* SAX2.c, xmlIO.c: fixed bug #121210 (callback to sax->error,
|
* SAX2.c, xmlIO.c: fixed bug #121210 (callback to sax->error,
|
||||||
|
9
dict.c
9
dict.c
@ -256,7 +256,7 @@ xmlDictFree(xmlDictPtr dict) {
|
|||||||
* xmlDictLookup:
|
* xmlDictLookup:
|
||||||
* @dict: the dictionnary
|
* @dict: the dictionnary
|
||||||
* @name: the name of the userdata
|
* @name: the name of the userdata
|
||||||
* @len: the length of the name
|
* @len: the length of the name, if -1 it is recomputed
|
||||||
*
|
*
|
||||||
* Add the @name to the hash @dict if not present.
|
* Add the @name to the hash @dict if not present.
|
||||||
*
|
*
|
||||||
@ -269,7 +269,12 @@ xmlDictLookup(xmlDictPtr dict, const xmlChar *name, int len) {
|
|||||||
xmlDictEntryPtr insert;
|
xmlDictEntryPtr insert;
|
||||||
const xmlChar *ret;
|
const xmlChar *ret;
|
||||||
|
|
||||||
if ((dict == NULL) || (name == NULL) || (len <= 0))
|
if ((dict == NULL) || (name == NULL))
|
||||||
|
return(NULL);
|
||||||
|
|
||||||
|
if (len < 0)
|
||||||
|
len = xmlStrlen(name);
|
||||||
|
if (len <= 0)
|
||||||
return(NULL);
|
return(NULL);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -240,6 +240,20 @@ struct _xmlParserCtxt {
|
|||||||
const xmlChar * *atts; /* array for the attributes callbacks */
|
const xmlChar * *atts; /* array for the attributes callbacks */
|
||||||
int maxatts; /* the size of the array */
|
int maxatts; /* the size of the array */
|
||||||
int docdict; /* use strings from dict to build tree */
|
int docdict; /* use strings from dict to build tree */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* pre-interned strings
|
||||||
|
*/
|
||||||
|
const xmlChar *str_xml;
|
||||||
|
const xmlChar *str_xmlns;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Everything below is related to the new SAX mode
|
||||||
|
*/
|
||||||
|
int sax2; /* operating in the new SAX mode */
|
||||||
|
int nsNr; /* the number of inherited namespaces */
|
||||||
|
int nsMax; /* the size of the arrays */
|
||||||
|
const xmlChar * *nsTab; /* the array of prefix/namespace name */
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2373,6 +2373,8 @@ xmlFreeParserCtxt(xmlParserCtxtPtr ctxt)
|
|||||||
if (ctxt->vctxt.nodeTab != NULL) xmlFree(ctxt->vctxt.nodeTab);
|
if (ctxt->vctxt.nodeTab != NULL) xmlFree(ctxt->vctxt.nodeTab);
|
||||||
if (ctxt->atts != NULL) xmlFree((xmlChar * *)ctxt->atts);
|
if (ctxt->atts != NULL) xmlFree((xmlChar * *)ctxt->atts);
|
||||||
if (ctxt->dict != NULL) xmlDictFree(ctxt->dict);
|
if (ctxt->dict != NULL) xmlDictFree(ctxt->dict);
|
||||||
|
if (ctxt->nsTab != NULL) xmlFree(ctxt->nsTab);
|
||||||
|
|
||||||
#ifdef LIBXML_CATALOG_ENABLED
|
#ifdef LIBXML_CATALOG_ENABLED
|
||||||
if (ctxt->catalogs != NULL)
|
if (ctxt->catalogs != NULL)
|
||||||
xmlCatalogFreeLocal(ctxt->catalogs);
|
xmlCatalogFreeLocal(ctxt->catalogs);
|
||||||
|
223
testSAX.c
223
testSAX.c
@ -46,6 +46,8 @@ static int push = 0;
|
|||||||
static int speed = 0;
|
static int speed = 0;
|
||||||
static int noent = 0;
|
static int noent = 0;
|
||||||
static int quiet = 0;
|
static int quiet = 0;
|
||||||
|
static int nonull = 0;
|
||||||
|
static int sax2 = 0;
|
||||||
static int callbacks = 0;
|
static int callbacks = 0;
|
||||||
|
|
||||||
xmlSAXHandler emptySAXHandlerStruct = {
|
xmlSAXHandler emptySAXHandlerStruct = {
|
||||||
@ -75,8 +77,12 @@ xmlSAXHandler emptySAXHandlerStruct = {
|
|||||||
NULL, /* xmlParserError */
|
NULL, /* xmlParserError */
|
||||||
NULL, /* getParameterEntity */
|
NULL, /* getParameterEntity */
|
||||||
NULL, /* cdataBlock; */
|
NULL, /* cdataBlock; */
|
||||||
NULL, /* externalSubset; */
|
NULL, /* externalSubset; */
|
||||||
1
|
1,
|
||||||
|
NULL,
|
||||||
|
NULL, /* startElementNs */
|
||||||
|
NULL, /* endElementNs */
|
||||||
|
NULL /* attributeNs */
|
||||||
};
|
};
|
||||||
|
|
||||||
xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct;
|
xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct;
|
||||||
@ -684,11 +690,159 @@ xmlSAXHandler debugSAXHandlerStruct = {
|
|||||||
getParameterEntityDebug,
|
getParameterEntityDebug,
|
||||||
cdataBlockDebug,
|
cdataBlockDebug,
|
||||||
externalSubsetDebug,
|
externalSubsetDebug,
|
||||||
1
|
1,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
xmlSAXHandlerPtr debugSAXHandler = &debugSAXHandlerStruct;
|
xmlSAXHandlerPtr debugSAXHandler = &debugSAXHandlerStruct;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* SAX2 specific callbacks
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* startElementDebug:
|
||||||
|
* @ctxt: An XML parser context
|
||||||
|
* @name: The element name
|
||||||
|
*
|
||||||
|
* called when an opening tag has been processed.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
startElementNsDebug(void *ctx ATTRIBUTE_UNUSED,
|
||||||
|
const xmlChar *localname,
|
||||||
|
const xmlChar *prefix,
|
||||||
|
const xmlChar *URI,
|
||||||
|
int nb_namespaces,
|
||||||
|
const xmlChar **namespaces,
|
||||||
|
int nb_attributes)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
callbacks++;
|
||||||
|
if (quiet)
|
||||||
|
return;
|
||||||
|
fprintf(stdout, "SAX.startElementNs(%s", (char *) localname);
|
||||||
|
if (prefix == NULL)
|
||||||
|
fprintf(stdout, ", NULL");
|
||||||
|
else
|
||||||
|
fprintf(stdout, ", %s", (char *) prefix);
|
||||||
|
if (URI == NULL)
|
||||||
|
fprintf(stdout, ", NULL");
|
||||||
|
else
|
||||||
|
fprintf(stdout, ", '%s'", (char *) URI);
|
||||||
|
fprintf(stdout, ", %d", nb_namespaces);
|
||||||
|
|
||||||
|
if (namespaces != NULL) {
|
||||||
|
for (i = 0;i < nb_namespaces * 2;i++) {
|
||||||
|
fprintf(stdout, ", xmlns");
|
||||||
|
if (namespaces[i] != NULL)
|
||||||
|
fprintf(stdout, ":%s", namespaces[i]);
|
||||||
|
i++;
|
||||||
|
fprintf(stdout, "='%s'", namespaces[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fprintf(stdout, ", %d)\n", nb_attributes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* endElementDebug:
|
||||||
|
* @ctxt: An XML parser context
|
||||||
|
* @name: The element name
|
||||||
|
*
|
||||||
|
* called when the end of an element has been detected.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
endElementNsDebug(void *ctx ATTRIBUTE_UNUSED,
|
||||||
|
const xmlChar *localname,
|
||||||
|
const xmlChar *prefix,
|
||||||
|
const xmlChar *URI)
|
||||||
|
{
|
||||||
|
callbacks++;
|
||||||
|
if (quiet)
|
||||||
|
return;
|
||||||
|
fprintf(stdout, "SAX.endElementNs(%s", (char *) localname);
|
||||||
|
if (prefix == NULL)
|
||||||
|
fprintf(stdout, ", NULL");
|
||||||
|
else
|
||||||
|
fprintf(stdout, ", %s", (char *) prefix);
|
||||||
|
if (URI == NULL)
|
||||||
|
fprintf(stdout, ", NULL)\n");
|
||||||
|
else
|
||||||
|
fprintf(stdout, ", '%s')\n", (char *) URI);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* attributeNsDebug:
|
||||||
|
* @ctxt: An XML parser context
|
||||||
|
* @name: The element name
|
||||||
|
*
|
||||||
|
* called when the end of an element has been detected.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
attributeNsDebug(void *ctx ATTRIBUTE_UNUSED,
|
||||||
|
const xmlChar *localname,
|
||||||
|
const xmlChar *prefix,
|
||||||
|
const xmlChar *URI,
|
||||||
|
const xmlChar *value,
|
||||||
|
int valuelen)
|
||||||
|
{
|
||||||
|
callbacks++;
|
||||||
|
if (quiet)
|
||||||
|
return;
|
||||||
|
fprintf(stdout, "SAX.attributeNs(%s", (char *) localname);
|
||||||
|
if (prefix == NULL)
|
||||||
|
fprintf(stdout, ", NULL");
|
||||||
|
else
|
||||||
|
fprintf(stdout, ", %s", (char *) prefix);
|
||||||
|
if (URI == NULL)
|
||||||
|
fprintf(stdout, ", NULL");
|
||||||
|
else
|
||||||
|
fprintf(stdout, ", '%s'", (char *) URI);
|
||||||
|
if (valuelen > 13)
|
||||||
|
fprintf(stdout, ", %10s..., %d)\n", value, valuelen);
|
||||||
|
else
|
||||||
|
fprintf(stdout, ", %s, %d)\n", value, valuelen);
|
||||||
|
}
|
||||||
|
|
||||||
|
xmlSAXHandler debugSAX2HandlerStruct = {
|
||||||
|
internalSubsetDebug,
|
||||||
|
isStandaloneDebug,
|
||||||
|
hasInternalSubsetDebug,
|
||||||
|
hasExternalSubsetDebug,
|
||||||
|
resolveEntityDebug,
|
||||||
|
getEntityDebug,
|
||||||
|
entityDeclDebug,
|
||||||
|
notationDeclDebug,
|
||||||
|
attributeDeclDebug,
|
||||||
|
elementDeclDebug,
|
||||||
|
unparsedEntityDeclDebug,
|
||||||
|
setDocumentLocatorDebug,
|
||||||
|
startDocumentDebug,
|
||||||
|
endDocumentDebug,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
referenceDebug,
|
||||||
|
charactersDebug,
|
||||||
|
ignorableWhitespaceDebug,
|
||||||
|
processingInstructionDebug,
|
||||||
|
commentDebug,
|
||||||
|
warningDebug,
|
||||||
|
errorDebug,
|
||||||
|
fatalErrorDebug,
|
||||||
|
getParameterEntityDebug,
|
||||||
|
cdataBlockDebug,
|
||||||
|
externalSubsetDebug,
|
||||||
|
1,
|
||||||
|
NULL,
|
||||||
|
startElementNsDebug,
|
||||||
|
endElementNsDebug,
|
||||||
|
attributeNsDebug
|
||||||
|
};
|
||||||
|
|
||||||
|
xmlSAXHandlerPtr debugSAX2Handler = &debugSAX2HandlerStruct;
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* *
|
* *
|
||||||
* Debug *
|
* Debug *
|
||||||
@ -702,29 +856,31 @@ parseAndPrintFile(char *filename) {
|
|||||||
if (push) {
|
if (push) {
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
/*
|
if ((!quiet) && (!nonull)) {
|
||||||
* Empty callbacks for checking
|
/*
|
||||||
*/
|
* Empty callbacks for checking
|
||||||
f = fopen(filename, "r");
|
*/
|
||||||
if (f != NULL) {
|
f = fopen(filename, "r");
|
||||||
int ret;
|
if (f != NULL) {
|
||||||
char chars[10];
|
int ret;
|
||||||
xmlParserCtxtPtr ctxt;
|
char chars[10];
|
||||||
|
xmlParserCtxtPtr ctxt;
|
||||||
|
|
||||||
ret = fread(chars, 1, 4, f);
|
ret = fread(chars, 1, 4, f);
|
||||||
if (ret > 0) {
|
if (ret > 0) {
|
||||||
ctxt = xmlCreatePushParserCtxt(emptySAXHandler, NULL,
|
ctxt = xmlCreatePushParserCtxt(emptySAXHandler, NULL,
|
||||||
chars, ret, filename);
|
chars, ret, filename);
|
||||||
while ((ret = fread(chars, 1, 3, f)) > 0) {
|
while ((ret = fread(chars, 1, 3, f)) > 0) {
|
||||||
xmlParseChunk(ctxt, chars, ret, 0);
|
xmlParseChunk(ctxt, chars, ret, 0);
|
||||||
|
}
|
||||||
|
xmlParseChunk(ctxt, chars, 0, 1);
|
||||||
|
xmlFreeParserCtxt(ctxt);
|
||||||
}
|
}
|
||||||
xmlParseChunk(ctxt, chars, 0, 1);
|
fclose(f);
|
||||||
xmlFreeParserCtxt(ctxt);
|
} else {
|
||||||
|
xmlGenericError(xmlGenericErrorContext,
|
||||||
|
"Cannot read file %s\n", filename);
|
||||||
}
|
}
|
||||||
fclose(f);
|
|
||||||
} else {
|
|
||||||
xmlGenericError(xmlGenericErrorContext,
|
|
||||||
"Cannot read file %s\n", filename);
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Debug callback
|
* Debug callback
|
||||||
@ -737,8 +893,12 @@ parseAndPrintFile(char *filename) {
|
|||||||
|
|
||||||
ret = fread(chars, 1, 4, f);
|
ret = fread(chars, 1, 4, f);
|
||||||
if (ret > 0) {
|
if (ret > 0) {
|
||||||
ctxt = xmlCreatePushParserCtxt(debugSAXHandler, NULL,
|
if (sax2)
|
||||||
chars, ret, filename);
|
ctxt = xmlCreatePushParserCtxt(debugSAX2Handler, NULL,
|
||||||
|
chars, ret, filename);
|
||||||
|
else
|
||||||
|
ctxt = xmlCreatePushParserCtxt(debugSAXHandler, NULL,
|
||||||
|
chars, ret, filename);
|
||||||
while ((ret = fread(chars, 1, 3, f)) > 0) {
|
while ((ret = fread(chars, 1, 3, f)) > 0) {
|
||||||
xmlParseChunk(ctxt, chars, ret, 0);
|
xmlParseChunk(ctxt, chars, ret, 0);
|
||||||
}
|
}
|
||||||
@ -756,7 +916,7 @@ parseAndPrintFile(char *filename) {
|
|||||||
/*
|
/*
|
||||||
* Empty callbacks for checking
|
* Empty callbacks for checking
|
||||||
*/
|
*/
|
||||||
if (!quiet) {
|
if ((!quiet) && (!nonull)) {
|
||||||
res = xmlSAXUserParseFile(emptySAXHandler, NULL, filename);
|
res = xmlSAXUserParseFile(emptySAXHandler, NULL, filename);
|
||||||
if (res != 0) {
|
if (res != 0) {
|
||||||
fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res);
|
fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res);
|
||||||
@ -767,7 +927,10 @@ parseAndPrintFile(char *filename) {
|
|||||||
* Debug callback
|
* Debug callback
|
||||||
*/
|
*/
|
||||||
callbacks = 0;
|
callbacks = 0;
|
||||||
res = xmlSAXUserParseFile(debugSAXHandler, NULL, filename);
|
if (sax2)
|
||||||
|
res = xmlSAXUserParseFile(debugSAX2Handler, NULL, filename);
|
||||||
|
else
|
||||||
|
res = xmlSAXUserParseFile(debugSAXHandler, NULL, filename);
|
||||||
if (res != 0) {
|
if (res != 0) {
|
||||||
fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res);
|
fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res);
|
||||||
}
|
}
|
||||||
@ -813,6 +976,12 @@ int main(int argc, char **argv) {
|
|||||||
else if ((!strcmp(argv[i], "-quiet")) ||
|
else if ((!strcmp(argv[i], "-quiet")) ||
|
||||||
(!strcmp(argv[i], "--quiet")))
|
(!strcmp(argv[i], "--quiet")))
|
||||||
quiet++;
|
quiet++;
|
||||||
|
else if ((!strcmp(argv[i], "-sax2")) ||
|
||||||
|
(!strcmp(argv[i], "--sax2")))
|
||||||
|
sax2++;
|
||||||
|
else if ((!strcmp(argv[i], "-nonull")) ||
|
||||||
|
(!strcmp(argv[i], "--nonull")))
|
||||||
|
nonull++;
|
||||||
}
|
}
|
||||||
if (noent != 0) xmlSubstituteEntitiesDefault(1);
|
if (noent != 0) xmlSubstituteEntitiesDefault(1);
|
||||||
for (i = 1; i < argc ; i++) {
|
for (i = 1; i < argc ; i++) {
|
||||||
|
Reference in New Issue
Block a user