1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-10-26 12:25:09 +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:
Daniel Veillard 2003-09-07 09:14:37 +00:00
parent 4811ba3bc2
commit 0fb1893539
6 changed files with 1119 additions and 145 deletions

View File

@ -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>
* SAX2.c, xmlIO.c: fixed bug #121210 (callback to sax->error,

9
dict.c
View File

@ -256,7 +256,7 @@ xmlDictFree(xmlDictPtr dict) {
* xmlDictLookup:
* @dict: the dictionnary
* @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.
*
@ -269,7 +269,12 @@ xmlDictLookup(xmlDictPtr dict, const xmlChar *name, int len) {
xmlDictEntryPtr insert;
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);
/*

View File

@ -240,6 +240,20 @@ struct _xmlParserCtxt {
const xmlChar * *atts; /* array for the attributes callbacks */
int maxatts; /* the size of the array */
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 */
};
/**

1008
parser.c

File diff suppressed because it is too large Load Diff

View File

@ -2373,6 +2373,8 @@ xmlFreeParserCtxt(xmlParserCtxtPtr ctxt)
if (ctxt->vctxt.nodeTab != NULL) xmlFree(ctxt->vctxt.nodeTab);
if (ctxt->atts != NULL) xmlFree((xmlChar * *)ctxt->atts);
if (ctxt->dict != NULL) xmlDictFree(ctxt->dict);
if (ctxt->nsTab != NULL) xmlFree(ctxt->nsTab);
#ifdef LIBXML_CATALOG_ENABLED
if (ctxt->catalogs != NULL)
xmlCatalogFreeLocal(ctxt->catalogs);

223
testSAX.c
View File

@ -46,6 +46,8 @@ static int push = 0;
static int speed = 0;
static int noent = 0;
static int quiet = 0;
static int nonull = 0;
static int sax2 = 0;
static int callbacks = 0;
xmlSAXHandler emptySAXHandlerStruct = {
@ -75,8 +77,12 @@ xmlSAXHandler emptySAXHandlerStruct = {
NULL, /* xmlParserError */
NULL, /* getParameterEntity */
NULL, /* cdataBlock; */
NULL, /* externalSubset; */
1
NULL, /* externalSubset; */
1,
NULL,
NULL, /* startElementNs */
NULL, /* endElementNs */
NULL /* attributeNs */
};
xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct;
@ -684,11 +690,159 @@ xmlSAXHandler debugSAXHandlerStruct = {
getParameterEntityDebug,
cdataBlockDebug,
externalSubsetDebug,
1
1,
NULL,
NULL,
NULL,
NULL
};
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 *
@ -702,29 +856,31 @@ parseAndPrintFile(char *filename) {
if (push) {
FILE *f;
/*
* Empty callbacks for checking
*/
f = fopen(filename, "r");
if (f != NULL) {
int ret;
char chars[10];
xmlParserCtxtPtr ctxt;
if ((!quiet) && (!nonull)) {
/*
* Empty callbacks for checking
*/
f = fopen(filename, "r");
if (f != NULL) {
int ret;
char chars[10];
xmlParserCtxtPtr ctxt;
ret = fread(chars, 1, 4, f);
if (ret > 0) {
ctxt = xmlCreatePushParserCtxt(emptySAXHandler, NULL,
chars, ret, filename);
while ((ret = fread(chars, 1, 3, f)) > 0) {
xmlParseChunk(ctxt, chars, ret, 0);
ret = fread(chars, 1, 4, f);
if (ret > 0) {
ctxt = xmlCreatePushParserCtxt(emptySAXHandler, NULL,
chars, ret, filename);
while ((ret = fread(chars, 1, 3, f)) > 0) {
xmlParseChunk(ctxt, chars, ret, 0);
}
xmlParseChunk(ctxt, chars, 0, 1);
xmlFreeParserCtxt(ctxt);
}
xmlParseChunk(ctxt, chars, 0, 1);
xmlFreeParserCtxt(ctxt);
fclose(f);
} else {
xmlGenericError(xmlGenericErrorContext,
"Cannot read file %s\n", filename);
}
fclose(f);
} else {
xmlGenericError(xmlGenericErrorContext,
"Cannot read file %s\n", filename);
}
/*
* Debug callback
@ -737,8 +893,12 @@ parseAndPrintFile(char *filename) {
ret = fread(chars, 1, 4, f);
if (ret > 0) {
ctxt = xmlCreatePushParserCtxt(debugSAXHandler, NULL,
chars, ret, filename);
if (sax2)
ctxt = xmlCreatePushParserCtxt(debugSAX2Handler, NULL,
chars, ret, filename);
else
ctxt = xmlCreatePushParserCtxt(debugSAXHandler, NULL,
chars, ret, filename);
while ((ret = fread(chars, 1, 3, f)) > 0) {
xmlParseChunk(ctxt, chars, ret, 0);
}
@ -756,7 +916,7 @@ parseAndPrintFile(char *filename) {
/*
* Empty callbacks for checking
*/
if (!quiet) {
if ((!quiet) && (!nonull)) {
res = xmlSAXUserParseFile(emptySAXHandler, NULL, filename);
if (res != 0) {
fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res);
@ -767,7 +927,10 @@ parseAndPrintFile(char *filename) {
* Debug callback
*/
callbacks = 0;
res = xmlSAXUserParseFile(debugSAXHandler, NULL, filename);
if (sax2)
res = xmlSAXUserParseFile(debugSAX2Handler, NULL, filename);
else
res = xmlSAXUserParseFile(debugSAXHandler, NULL, filename);
if (res != 0) {
fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res);
}
@ -813,6 +976,12 @@ int main(int argc, char **argv) {
else if ((!strcmp(argv[i], "-quiet")) ||
(!strcmp(argv[i], "--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);
for (i = 1; i < argc ; i++) {