version 1.10, 1999/09/01 00:20:45
|
version 1.11, 1999/09/02 16:30:54
|
Line 27
|
Line 27
|
#include <zlib.h> |
#include <zlib.h> |
#endif |
#endif |
|
|
|
#include "xmlmemory.h" |
#include "tree.h" |
#include "tree.h" |
#include "HTMLparser.h" |
#include "HTMLparser.h" |
#include "entities.h" |
#include "entities.h" |
Line 54
|
Line 55
|
int html##name##Push(htmlParserCtxtPtr ctxt, type value) { \ |
int html##name##Push(htmlParserCtxtPtr ctxt, type value) { \ |
if (ctxt->name##Nr >= ctxt->name##Max) { \ |
if (ctxt->name##Nr >= ctxt->name##Max) { \ |
ctxt->name##Max *= 2; \ |
ctxt->name##Max *= 2; \ |
ctxt->name##Tab = (void *) realloc(ctxt->name##Tab, \ |
ctxt->name##Tab = (void *) xmlRealloc(ctxt->name##Tab, \ |
ctxt->name##Max * sizeof(ctxt->name##Tab[0])); \ |
ctxt->name##Max * sizeof(ctxt->name##Tab[0])); \ |
if (ctxt->name##Tab == NULL) { \ |
if (ctxt->name##Tab == NULL) { \ |
fprintf(stderr, "realloc failed !\n"); \ |
fprintf(stderr, "realloc failed !\n"); \ |
Line 766 htmlEntityDesc html40EntitiesTable[] =
|
Line 767 htmlEntityDesc html40EntitiesTable[] =
|
*/ |
*/ |
#define growBuffer(buffer) { \ |
#define growBuffer(buffer) { \ |
buffer##_size *= 2; \ |
buffer##_size *= 2; \ |
buffer = (CHAR *) realloc(buffer, buffer##_size * sizeof(CHAR)); \ |
buffer = (CHAR *) xmlRealloc(buffer, buffer##_size * sizeof(CHAR)); \ |
if (buffer == NULL) { \ |
if (buffer == NULL) { \ |
perror("realloc failed"); \ |
perror("realloc failed"); \ |
exit(1); \ |
exit(1); \ |
Line 834 htmlDecodeEntities(htmlParserCtxtPtr ctx
|
Line 835 htmlDecodeEntities(htmlParserCtxtPtr ctx
|
* allocate a translation buffer. |
* allocate a translation buffer. |
*/ |
*/ |
buffer_size = 1000; |
buffer_size = 1000; |
buffer = (CHAR *) malloc(buffer_size * sizeof(CHAR)); |
buffer = (CHAR *) xmlMalloc(buffer_size * sizeof(CHAR)); |
if (buffer == NULL) { |
if (buffer == NULL) { |
perror("htmlDecodeEntities: malloc failed"); |
perror("htmlDecodeEntities: malloc failed"); |
return(NULL); |
return(NULL); |
Line 881 htmlDecodeEntities(htmlParserCtxtPtr ctx
|
Line 882 htmlDecodeEntities(htmlParserCtxtPtr ctx
|
} |
} |
} |
} |
nbchars += 2 + xmlStrlen(name); |
nbchars += 2 + xmlStrlen(name); |
free(name); |
xmlFree(name); |
} |
} |
} |
} |
} else { |
} else { |
Line 1114 htmlNewDoc(const CHAR *URI, const CHAR *
|
Line 1115 htmlNewDoc(const CHAR *URI, const CHAR *
|
/* |
/* |
* Allocate a new document and fill the fields. |
* Allocate a new document and fill the fields. |
*/ |
*/ |
cur = (xmlDocPtr) malloc(sizeof(xmlDoc)); |
cur = (xmlDocPtr) xmlMalloc(sizeof(xmlDoc)); |
if (cur == NULL) { |
if (cur == NULL) { |
fprintf(stderr, "xmlNewDoc : malloc failed\n"); |
fprintf(stderr, "xmlNewDoc : malloc failed\n"); |
return(NULL); |
return(NULL); |
Line 1340 htmlParseEntityRef(htmlParserCtxtPtr ctx
|
Line 1341 htmlParseEntityRef(htmlParserCtxtPtr ctx
|
ctxt->sax->characters(ctxt->userData, BAD_CAST "&", 1); |
ctxt->sax->characters(ctxt->userData, BAD_CAST "&", 1); |
ctxt->sax->characters(ctxt->userData, name, xmlStrlen(name)); |
ctxt->sax->characters(ctxt->userData, name, xmlStrlen(name)); |
} |
} |
free(name); |
xmlFree(name); |
} |
} |
} |
} |
} |
} |
Line 1674 htmlParseComment(htmlParserCtxtPtr ctxt,
|
Line 1675 htmlParseComment(htmlParserCtxtPtr ctxt,
|
val = xmlStrndup(start, q - start); |
val = xmlStrndup(start, q - start); |
if ((ctxt->sax != NULL) && (ctxt->sax->comment != NULL)) |
if ((ctxt->sax != NULL) && (ctxt->sax->comment != NULL)) |
ctxt->sax->comment(ctxt->userData, val); |
ctxt->sax->comment(ctxt->userData, val); |
free(val); |
xmlFree(val); |
} |
} |
} |
} |
} |
} |
Line 1817 htmlParseDocTypeDecl(htmlParserCtxtPtr c
|
Line 1818 htmlParseDocTypeDecl(htmlParserCtxtPtr c
|
/* |
/* |
* Cleanup, since we don't use all those identifiers |
* Cleanup, since we don't use all those identifiers |
*/ |
*/ |
if (URI != NULL) free(URI); |
if (URI != NULL) xmlFree(URI); |
if (ExternalID != NULL) free(ExternalID); |
if (ExternalID != NULL) xmlFree(ExternalID); |
if (name != NULL) free(name); |
if (name != NULL) xmlFree(name); |
} |
} |
|
|
/** |
/** |
Line 1945 htmlParseStartTag(htmlParserCtxtPtr ctxt
|
Line 1946 htmlParseStartTag(htmlParserCtxtPtr ctxt
|
ctxt->sax->error(ctxt->userData, "Attribute %s redefined\n", |
ctxt->sax->error(ctxt->userData, "Attribute %s redefined\n", |
name); |
name); |
ctxt->wellFormed = 0; |
ctxt->wellFormed = 0; |
free(attname); |
xmlFree(attname); |
free(attvalue); |
xmlFree(attvalue); |
break; |
break; |
} |
} |
} |
} |
Line 1956 htmlParseStartTag(htmlParserCtxtPtr ctxt
|
Line 1957 htmlParseStartTag(htmlParserCtxtPtr ctxt
|
*/ |
*/ |
if (atts == NULL) { |
if (atts == NULL) { |
maxatts = 10; |
maxatts = 10; |
atts = (const CHAR **) malloc(maxatts * sizeof(CHAR *)); |
atts = (const CHAR **) xmlMalloc(maxatts * sizeof(CHAR *)); |
if (atts == NULL) { |
if (atts == NULL) { |
fprintf(stderr, "malloc of %ld byte failed\n", |
fprintf(stderr, "malloc of %ld byte failed\n", |
maxatts * (long)sizeof(CHAR *)); |
maxatts * (long)sizeof(CHAR *)); |
Line 1964 htmlParseStartTag(htmlParserCtxtPtr ctxt
|
Line 1965 htmlParseStartTag(htmlParserCtxtPtr ctxt
|
} |
} |
} else if (nbatts + 2 < maxatts) { |
} else if (nbatts + 2 < maxatts) { |
maxatts *= 2; |
maxatts *= 2; |
atts = (const CHAR **) realloc(atts, maxatts * sizeof(CHAR *)); |
atts = (const CHAR **) xmlRealloc(atts, maxatts * sizeof(CHAR *)); |
if (atts == NULL) { |
if (atts == NULL) { |
fprintf(stderr, "realloc of %ld byte failed\n", |
fprintf(stderr, "realloc of %ld byte failed\n", |
maxatts * (long)sizeof(CHAR *)); |
maxatts * (long)sizeof(CHAR *)); |
Line 1994 htmlParseStartTag(htmlParserCtxtPtr ctxt
|
Line 1995 htmlParseStartTag(htmlParserCtxtPtr ctxt
|
ctxt->sax->startElement(ctxt->userData, name, atts); |
ctxt->sax->startElement(ctxt->userData, name, atts); |
|
|
if (atts != NULL) { |
if (atts != NULL) { |
for (i = 0;i < nbatts;i++) free((CHAR *) atts[i]); |
for (i = 0;i < nbatts;i++) xmlFree((CHAR *) atts[i]); |
free(atts); |
xmlFree(atts); |
} |
} |
return(name); |
return(name); |
} |
} |
Line 2054 htmlParseEndTag(htmlParserCtxtPtr ctxt,
|
Line 2055 htmlParseEndTag(htmlParserCtxtPtr ctxt,
|
ctxt->sax->error(ctxt->userData, |
ctxt->sax->error(ctxt->userData, |
"htmlParseEndTag: unexpected close for tag %s\n", |
"htmlParseEndTag: unexpected close for tag %s\n", |
tagname); |
tagname); |
free(name); |
xmlFree(name); |
ctxt->wellFormed = 0; |
ctxt->wellFormed = 0; |
return; |
return; |
} |
} |
Line 2087 htmlParseEndTag(htmlParserCtxtPtr ctxt,
|
Line 2088 htmlParseEndTag(htmlParserCtxtPtr ctxt,
|
ctxt->sax->endElement(ctxt->userData, name); |
ctxt->sax->endElement(ctxt->userData, name); |
|
|
if (name != NULL) |
if (name != NULL) |
free(name); |
xmlFree(name); |
|
|
return; |
return; |
} |
} |
Line 2132 htmlParseReference(htmlParserCtxtPtr ctx
|
Line 2133 htmlParseReference(htmlParserCtxtPtr ctx
|
if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL)) |
if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL)) |
ctxt->sax->characters(ctxt->userData, out, 1); |
ctxt->sax->characters(ctxt->userData, out, 1); |
} |
} |
free(name); |
xmlFree(name); |
} |
} |
} |
} |
|
|
Line 2261 htmlParseElement(htmlParserCtxtPtr ctxt)
|
Line 2262 htmlParseElement(htmlParserCtxtPtr ctxt)
|
SKIP(2); |
SKIP(2); |
if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL)) |
if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL)) |
ctxt->sax->endElement(ctxt->userData, name); |
ctxt->sax->endElement(ctxt->userData, name); |
free(name); |
xmlFree(name); |
return; |
return; |
} |
} |
|
|
Line 2277 htmlParseElement(htmlParserCtxtPtr ctxt)
|
Line 2278 htmlParseElement(htmlParserCtxtPtr ctxt)
|
* end of parsing of this node. |
* end of parsing of this node. |
*/ |
*/ |
nodePop(ctxt); |
nodePop(ctxt); |
free(name); |
xmlFree(name); |
|
|
/* |
/* |
* Capture end position and add node |
* Capture end position and add node |
Line 2298 htmlParseElement(htmlParserCtxtPtr ctxt)
|
Line 2299 htmlParseElement(htmlParserCtxtPtr ctxt)
|
if ((info != NULL) && (info->empty)) { |
if ((info != NULL) && (info->empty)) { |
if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL)) |
if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL)) |
ctxt->sax->endElement(ctxt->userData, name); |
ctxt->sax->endElement(ctxt->userData, name); |
free(name); |
xmlFree(name); |
return; |
return; |
} |
} |
|
|
Line 2313 htmlParseElement(htmlParserCtxtPtr ctxt)
|
Line 2314 htmlParseElement(htmlParserCtxtPtr ctxt)
|
* on start tag |
* on start tag |
*/ |
*/ |
if (currentNode != ctxt->node) { |
if (currentNode != ctxt->node) { |
free(name); |
xmlFree(name); |
return; |
return; |
} |
} |
|
|
Line 2327 htmlParseElement(htmlParserCtxtPtr ctxt)
|
Line 2328 htmlParseElement(htmlParserCtxtPtr ctxt)
|
* end of parsing of this node. |
* end of parsing of this node. |
*/ |
*/ |
nodePop(ctxt); |
nodePop(ctxt); |
free(name); |
xmlFree(name); |
return; |
return; |
} |
} |
|
|
free(name); |
xmlFree(name); |
|
|
/* |
/* |
* Capture end position and add node |
* Capture end position and add node |
Line 2439 htmlInitParserCtxt(htmlParserCtxtPtr ctx
|
Line 2440 htmlInitParserCtxt(htmlParserCtxtPtr ctx
|
{ |
{ |
htmlSAXHandler *sax; |
htmlSAXHandler *sax; |
|
|
sax = (htmlSAXHandler *) malloc(sizeof(htmlSAXHandler)); |
sax = (htmlSAXHandler *) xmlMalloc(sizeof(htmlSAXHandler)); |
if (sax == NULL) { |
if (sax == NULL) { |
fprintf(stderr, "htmlInitParserCtxt: out of memory\n"); |
fprintf(stderr, "htmlInitParserCtxt: out of memory\n"); |
} |
} |
|
|
/* Allocate the Input stack */ |
/* Allocate the Input stack */ |
ctxt->inputTab = (htmlParserInputPtr *) malloc(5 * sizeof(htmlParserInputPtr)); |
ctxt->inputTab = (htmlParserInputPtr *) xmlMalloc(5 * sizeof(htmlParserInputPtr)); |
ctxt->inputNr = 0; |
ctxt->inputNr = 0; |
ctxt->inputMax = 5; |
ctxt->inputMax = 5; |
ctxt->input = NULL; |
ctxt->input = NULL; |
Line 2454 htmlInitParserCtxt(htmlParserCtxtPtr ctx
|
Line 2455 htmlInitParserCtxt(htmlParserCtxtPtr ctx
|
ctxt->standalone = -1; |
ctxt->standalone = -1; |
|
|
/* Allocate the Node stack */ |
/* Allocate the Node stack */ |
ctxt->nodeTab = (htmlNodePtr *) malloc(10 * sizeof(htmlNodePtr)); |
ctxt->nodeTab = (htmlNodePtr *) xmlMalloc(10 * sizeof(htmlNodePtr)); |
ctxt->nodeNr = 0; |
ctxt->nodeNr = 0; |
ctxt->nodeMax = 10; |
ctxt->nodeMax = 10; |
ctxt->node = NULL; |
ctxt->node = NULL; |
Line 2492 htmlFreeParserCtxt(htmlParserCtxtPtr ctx
|
Line 2493 htmlFreeParserCtxt(htmlParserCtxtPtr ctx
|
xmlFreeInputStream(input); |
xmlFreeInputStream(input); |
} |
} |
|
|
if (ctxt->nodeTab != NULL) free(ctxt->nodeTab); |
if (ctxt->nodeTab != NULL) xmlFree(ctxt->nodeTab); |
if (ctxt->inputTab != NULL) free(ctxt->inputTab); |
if (ctxt->inputTab != NULL) xmlFree(ctxt->inputTab); |
if (ctxt->version != NULL) free((char *) ctxt->version); |
if (ctxt->version != NULL) xmlFree((char *) ctxt->version); |
if ((ctxt->sax != NULL) && (ctxt->sax != &htmlDefaultSAXHandler)) |
if ((ctxt->sax != NULL) && (ctxt->sax != &htmlDefaultSAXHandler)) |
free(ctxt->sax); |
xmlFree(ctxt->sax); |
free(ctxt); |
xmlFree(ctxt); |
} |
} |
|
|
/** |
/** |
Line 2515 htmlCreateDocParserCtxt(CHAR *cur, const
|
Line 2516 htmlCreateDocParserCtxt(CHAR *cur, const
|
htmlParserInputPtr input; |
htmlParserInputPtr input; |
/* htmlCharEncoding enc; */ |
/* htmlCharEncoding enc; */ |
|
|
ctxt = (htmlParserCtxtPtr) malloc(sizeof(htmlParserCtxt)); |
ctxt = (htmlParserCtxtPtr) xmlMalloc(sizeof(htmlParserCtxt)); |
if (ctxt == NULL) { |
if (ctxt == NULL) { |
perror("malloc"); |
perror("malloc"); |
return(NULL); |
return(NULL); |
} |
} |
htmlInitParserCtxt(ctxt); |
htmlInitParserCtxt(ctxt); |
input = (htmlParserInputPtr) malloc(sizeof(htmlParserInput)); |
input = (htmlParserInputPtr) xmlMalloc(sizeof(htmlParserInput)); |
if (input == NULL) { |
if (input == NULL) { |
perror("malloc"); |
perror("malloc"); |
free(ctxt); |
xmlFree(ctxt); |
return(NULL); |
return(NULL); |
} |
} |
|
|
Line 2632 htmlCreateFileParserCtxt(const char *fil
|
Line 2633 htmlCreateFileParserCtxt(const char *fil
|
buf = xmlParserInputBufferCreateFilename(filename, XML_CHAR_ENCODING_NONE); |
buf = xmlParserInputBufferCreateFilename(filename, XML_CHAR_ENCODING_NONE); |
if (buf == NULL) return(NULL); |
if (buf == NULL) return(NULL); |
|
|
ctxt = (htmlParserCtxtPtr) malloc(sizeof(htmlParserCtxt)); |
ctxt = (htmlParserCtxtPtr) xmlMalloc(sizeof(htmlParserCtxt)); |
if (ctxt == NULL) { |
if (ctxt == NULL) { |
perror("malloc"); |
perror("malloc"); |
return(NULL); |
return(NULL); |
} |
} |
htmlInitParserCtxt(ctxt); |
htmlInitParserCtxt(ctxt); |
inputStream = (htmlParserInputPtr) malloc(sizeof(htmlParserInput)); |
inputStream = (htmlParserInputPtr) xmlMalloc(sizeof(htmlParserInput)); |
if (inputStream == NULL) { |
if (inputStream == NULL) { |
perror("malloc"); |
perror("malloc"); |
free(ctxt); |
xmlFree(ctxt); |
return(NULL); |
return(NULL); |
} |
} |
|
|
inputStream->filename = strdup(filename); |
inputStream->filename = xmlMemStrdup(filename); |
inputStream->line = 1; |
inputStream->line = 1; |
inputStream->col = 1; |
inputStream->col = 1; |
inputStream->buf = buf; |
inputStream->buf = buf; |