[cairo-commit] libsvg/src Makefile.am, 1.7, 1.8 svg.c, 1.9,
1.10 svg_element.c, 1.34, 1.35 svg_hash.c, NONE,
1.1 svg_hash.h, NONE, 1.1 svg_parser.c, 1.32,
1.33 svg_parser_expat.c, NONE, 1.1 svg_parser_libxml.c, NONE,
1.1 svgint.h, 1.42, 1.43
Phil Blundell
commit at pdx.freedesktop.org
Mon Feb 14 09:26:28 PST 2005
Committed by: pb
Update of /cvs/cairo/libsvg/src
In directory gabe:/tmp/cvs-serv13324/src
Modified Files:
Makefile.am svg.c svg_element.c svg_parser.c svgint.h
Added Files:
svg_hash.c svg_hash.h svg_parser_expat.c svg_parser_libxml.c
Log Message:
2005-02-14 Phil Blundell <philb at gnu.org>
* configure.in: Add "--with-expat" flag.
(LIBSVG_PARSER_BACKEND, LIBSVG_REQUIRES): Define appropriately.
(EXPAT): New automake conditional.
* libsvg.pc.in (Requires): Use value from LIBSVG_REQUIRES.
* src/svgint.h (svg_xml_parser_context_t, svg_hash_table_t,
_svg_xml_hash_add_entry, _svg_xml_hash_lookup,
_svg_xml_hash_create, _svg_xml_hash_free, _svg_xml_strdup):
Declare.
(struct svg, struct svg_parser): Use svg_hash_table_t and
svg_xml_parser_context_t.
* src/svg.c (_svg_init, _svg_deinit, _svg_store_element_by_id,
_svg_fetch_element_by_id): Replace direct calls to xmlHash
functions with _svg_xml_hash equivalents.
* src/svg_element.c (_svg_element_apply_attributes): Use
_svg_xml_strdup in place of xmlMemStrdup.
(_svg_element_init_copy): Likewise.
* src/svg_parser.c (SVG_PARSER_SAX_HANDLER, _svg_parser_init,
_svg_parser_deinit, _svg_parser_begin, _svg_parser_parse_chunk,
_svg_parser_end, _svg_parser_sax_get_entity,
_svg_parser_sax_entity_decl, _svg_parser_sax_warning,
_svg_parser_sax_error, _svg_parser_sax_fatal_error): Move to
new file svg_parser_libxml.c.
(_svg_parser_sax_start_element, _svg_parser_sax_end_element,
_svg_parser_sax_characters): Make linkage global. Move
declarations to svgint.h.
* src/svg_parser_expat.c: New file.
* src/svg_hash.c, src/svg_hash.h: New files. Code supplied by
Chris Osgood.
* src/Makefile.am (LIBSVG_EXTRA_SOURCES): Select expat or libxml
parser backend as appropriate.
(libsvg_la_SOURCES): Include LIBSVG_EXTRA_SOURCES.
Index: Makefile.am
===================================================================
RCS file: /cvs/cairo/libsvg/src/Makefile.am,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- Makefile.am 30 Aug 2003 03:09:07 -0000 1.7
+++ Makefile.am 14 Feb 2005 17:26:26 -0000 1.8
@@ -1,6 +1,12 @@
lib_LTLIBRARIES = libsvg.la
include_HEADERS = svg.h
+if EXPAT
+LIBSVG_EXTRA_SOURCES = svg_parser_expat.c svg_hash.c svg_hash.h
+else
+LIBSVG_EXTRA_SOURCES = svg_parser_libxml.c
+endif
+
libsvg_la_SOURCES = \
svg.c \
svg.h \
@@ -22,7 +28,8 @@
svg_style.c \
svg_text.c \
svg_transform.c \
- svg_version.h
+ svg_version.h \
+ $(LIBSVG_EXTRA_SOURCES)
libsvg_la_LDFLAGS = -version-info @VERSION_INFO@
Index: svg.c
===================================================================
RCS file: /cvs/cairo/libsvg/src/svg.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- svg.c 15 Nov 2003 15:48:50 -0000 1.9
+++ svg.c 14 Feb 2005 17:26:26 -0000 1.10
@@ -56,7 +56,7 @@
svg->engine = NULL;
- svg->element_ids = xmlHashCreate (100);
+ svg->element_ids = _svg_xml_hash_create (100);
return SVG_STATUS_SUCCESS;
}
@@ -74,7 +74,7 @@
svg->engine = NULL;
- xmlHashFree (svg->element_ids, NULL);
+ _svg_xml_hash_free (svg->element_ids);
return SVG_STATUS_SUCCESS;
}
@@ -232,7 +232,7 @@
svg_status_t
_svg_store_element_by_id (svg_t *svg, svg_element_t *element)
{
- xmlHashAddEntry (svg->element_ids, element->id, element);
+ _svg_xml_hash_add_entry (svg->element_ids, element->id, element);
return SVG_STATUS_SUCCESS;
}
@@ -240,7 +240,7 @@
svg_status_t
_svg_fetch_element_by_id (svg_t *svg, const xmlChar *id, svg_element_t **element_ret)
{
- *element_ret = xmlHashLookup (svg->element_ids, id);
+ *element_ret = _svg_xml_hash_lookup (svg->element_ids, id);
return SVG_STATUS_SUCCESS;
}
Index: svg_element.c
===================================================================
RCS file: /cvs/cairo/libsvg/src/svg_element.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- svg_element.c 7 May 2004 03:56:43 -0000 1.34
+++ svg_element.c 14 Feb 2005 17:26:26 -0000 1.35
@@ -110,7 +110,7 @@
element->type = other->type;
element->parent = other->parent;
if (other->id)
- element->id = xmlMemStrdup (other->id);
+ element->id = _svg_xml_strdup (other->id);
else
element->id = NULL;
@@ -474,7 +474,7 @@
_svg_attribute_get_string (attributes, "id", &id, NULL);
if (id)
- element->id = xmlMemStrdup (id);
+ element->id = _svg_xml_strdup (id);
switch (element->type) {
case SVG_ELEMENT_TYPE_SVG_GROUP:
--- NEW FILE: svg_hash.c ---
/*
** This file is part of the C Utility Toolkit (CUTK)
** Copyright (C) 2002-2005 Chris Osgood
** http://www.cutk.org
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; either
** version 2.1 of the License, or (at your option) any later version.
**
** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public
** License along with this library; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
**
** Please report all bugs and problems to "bugs at cutk.org".
*/
/*
** See StrHmap.h for more information.
**
** $Id: svg_hash.c,v 1.1 2005/02/14 17:26:26 pb Exp $
*/
/* Inline */
#ifdef _MSC_VER
#define INLINE_X static __inline
#else
#define INLINE_X static inline
#endif
#ifdef NO_INLINE
#define INLINE static
#else
#define INLINE INLINE_X
#endif
#include <stdlib.h>
#include "svg_hash.h"
#ifndef SIZE_MAX
#define SIZE_MAX ((size_t)-1)
#endif
/* Utility macro for getting the element size */
#define _svg_hash_aryesize(x) ((*((svg_array_t**)(void*)(x))-1)->esize)
/* Macros for low overhead API calls */
#define _svg_hash_arysize(x) ((*((svg_array_t**)(void*)(x))-1)->size)
#define _svg_hash_arymax(x) ((*((svg_array_t**)(void*)(x))-1)->max)
#define _svg_hash_aryalloc(x) _svg_hash_aryalloc_(sizeof(x))
#define _svg_hash_aryallocsize(x,y) _svg_hash_aryallocsize_(sizeof(x),y)
#define _svg_hash_aryclear(x) (((*((svg_array_t**)(void*)(x))-1)->size)=0)
/* Main array type (not used externally but arysize/max macros use it) */
typedef struct svg_array_t
{
size_t size; /* Number of elements in array */
size_t max; /* Allocated memory (max # elements) */
size_t esize; /* Element size; sizeof(ElementType) */
char ary[]; /* Raw array data */
} svg_array_t;
/**
* Allocate a new empty array. Normally this function is not called directly.
* Use the aryalloc() macro instead. This allows you to specify the element
* type rather than the element size. Example: "int* array = aryalloc(int);"
*
* @param esize Element size. This is the size (in bytes) of each element in
* the array. This is normally just the sizeof(ElementType).
* @return This returns a pointer to the array data (not the array structure)
* or NULL on failure.
*/
static void *
_svg_hash_aryalloc_(size_t esize)
{
svg_array_t* ary = (svg_array_t*)malloc(sizeof(svg_array_t));
if (ary == NULL)
return NULL;
ary->max = 0;
ary->size = 0;
ary->esize = esize;
return &ary->ary;
}
/**
* Allocate a new array of a specified size. Normally this function is not
* called directly. Use the aryallocsize() macro instead.
* Example: "int* array = aryallocsize(int, 2000);"
*
* @param esize Element size. This is the size (in bytes) of each element in
* the array. This is normally just the sizeof(ElementType).
* @param size Number of items in array
* @return This returns a pointer to the array data (not the array structure)
* or NULL on failure.
*/
static void *
_svg_hash_aryallocsize_(size_t esize, size_t size)
{
svg_array_t* ary = (svg_array_t*)malloc(sizeof(svg_array_t) + esize * size);
if (ary == NULL)
return NULL;
ary->max = size;
ary->size = size;
ary->esize = esize;
return &ary->ary;
}
/**
* This releases all memory held by an array.
*
* @param ary Pointer to an array pointer
*/
static void
_svg_hash_aryfree(void* ary)
{
free(*(svg_array_t**)ary - 1);
*(void**)ary = NULL;
}
/**
* This preallocates memory for a certain maximum number of elements.
* Note that this does not change the size of the array unless max
* is less than the current size of the array.
*
* @param ary Pointer to an array pointer
* @param max Number of elements to preallocate
* @return 0 on success; non-zero on failure
*/
static int
_svg_hash_aryreserve (void* ary, size_t max)
{
if (_svg_hash_arymax (ary) == max)
return 0;
else
{
void* temp = realloc( *(svg_array_t**)ary - 1,
sizeof(svg_array_t) + max * _svg_hash_aryesize(ary) );
if (temp == 0)
return 1;
*(void**)ary = &((svg_array_t*)temp)->ary;
}
_svg_hash_arymax(ary) = max;
if (_svg_hash_arymax(ary) < _svg_hash_arysize(ary))
_svg_hash_arysize(ary) = _svg_hash_arymax(ary);
return 0;
}
/**
* This resizes an array. Note that this does not free any memory
* held by the array if the size is smaller than the current size.
*
* @param ary Pointer to an array pointer
* @param size New size of array
* @return 0 on success; non-zero on failure
*/
static int
_svg_hash_aryresize(void* ary, size_t size)
{
if (size > _svg_hash_arymax(ary) && _svg_hash_aryreserve (ary, size) != 0)
return 1;
_svg_hash_arysize(ary) = size;
return 0;
}
/**
* This adds and copies a new element to the end of the array.
*
* @param ary Pointer to an array pointer
* @param element This value is copied into the new value at the end of the
* array
* @return 0 on success; non-zero on failure
*/
static int
_svg_hash_aryappend(void* ary, const void* element)
{
if ((_svg_hash_arysize(ary) + 1 > _svg_hash_arymax(ary) &&
_svg_hash_aryreserve(ary, _svg_hash_arysize(ary) * 2) != 0) ||
_svg_hash_aryresize(ary, _svg_hash_arysize(ary) + 1) != 0)
{
return 1;
}
memcpy (*(char**)ary + (_svg_hash_arysize(ary) - 1) * _svg_hash_aryesize(ary),
element, _svg_hash_aryesize(ary));
return 0;
}
/* Some prime values to use when sizing the internal hash table */
static const size_t hash_primelist[] =
{
53u, 97u, 193u, 389u, 769u, 1543u, 3079u, 6151u, 12289u, 24593u,
49157u, 98317u, 196613u, 393241u, 786433u, 1572869u, 3145739u,
6291469u, 12582917u, 25165843u, 50331653u, 100663319u, 201326611u,
402653189u, 805306457u, 1610612741u, 3221225473u, 4294967291u
};
/* Returns the next prime larger than the specified size */
INLINE size_t
_svg_hash_next_prime (size_t size)
{
size_t i;
for(i = 0; hash_primelist[i] < size &&
i < sizeof (hash_primelist) / sizeof (size_t); i++);
return hash_primelist[i];
}
/* Fast string hashing routine */
INLINE size_t
_svg_hash_str_hash (const svg_xml_hash_table_t * map, const char* s)
{
size_t i;
for (i = 0; *s; s++)
i = 31 * i + *s;
return i % _svg_hash_arysize (&map->hash_tbl);
}
/* Fast string equality test. In most cases this is faster than strcmp */
INLINE char
_svg_hash_streq (const char* s1, const char* s2)
{
if (s1 == s2) return 1;
if (!s1 || !s2) return 0;
while (*s1 != '\0' && *s1 == *s2)
s1++, s2++;
return *s1 == *s2;
}
/**
* Reallocates a hash map. If the size is smaller than the actual
* number of elements in the hash map then the effect will be to reduce
* memory usage if possible. The size can be larger than the actual number
* of elements in the hash map which will allow lots of insertions to go
* faster since the table won't need to be resized as often.
* @param hashmap Pointer to hash map
* @param size Number of elements to preallocate
* @return 0 on success; non-zero on failure
*/
static int
_svg_hash_table_realloc (svg_xml_hash_table_t *hashmap, size_t size)
{
size_t i;
size_t hash;
if (size <= _svg_hash_arysize(&hashmap->hash_tbl))
return 0;
if (_svg_hash_aryresize(&hashmap->hash_tbl, _svg_hash_next_prime (size)))
return 1;
memset(hashmap->hash_tbl, 0xFF,
_svg_hash_arysize(&hashmap->hash_tbl) * sizeof(size_t));
for (i = 0; i < _svg_hash_arysize(&hashmap->items); i++)
{
if (hashmap->items[i].key != NULL)
{
hash = _svg_hash_str_hash (hashmap, hashmap->items[i].key);
hashmap->items[i].next = hashmap->hash_tbl[hash];
hashmap->hash_tbl[hash] = i;
}
}
return 0;
}
/* Internal function used by StrHmapInsert and StrHmapReplace */
INLINE int
_str_hash_insert_new (svg_xml_hash_table_t * hashmap, const char* key, const void* item, size_t hash)
{
size_t newitemnum;
svg_hash_item_t newitem;
newitem.key = key;
newitem.item = item;
if (hashmap->deleted != SIZE_MAX)
{
newitemnum = hashmap->deleted;
hashmap->deleted = hashmap->items[newitemnum].next;
hashmap->items[newitemnum] = newitem;
}
else
{
newitemnum = _svg_hash_arysize(&hashmap->items);
if (_svg_hash_aryappend(&hashmap->items, &newitem))
return 1;
}
hashmap->items[newitemnum].next = hashmap->hash_tbl[hash];
hashmap->hash_tbl[hash] = newitemnum;
/* For the following it's not really an insert error if rehash fails
so we don't return an error if it does. However, the hash table will
become slow if rehash keeps failing. Not sure how to notify the
application of such a condition. Other more serious errors will
probably be happening if rehash fails (eg. out of memory). */
if (_svg_hash_arysize(&hashmap->items) > _svg_hash_arysize(&hashmap->hash_tbl))
_svg_hash_table_realloc (hashmap, _svg_hash_arysize (&hashmap->items));
return 0;
}
/* External API */
/**
* Allocate a new empty hash map.
* @param size Specifies intial expected number of items in the hash map (can
* be 0).
* @return Returns a pointer to the new hash map or NULL on failure.
*/
svg_xml_hash_table_t *
_svg_xml_hash_create (size_t size)
{
svg_xml_hash_table_t * hashmap = (svg_xml_hash_table_t *)malloc (sizeof (svg_xml_hash_table_t));
if (hashmap == NULL)
return NULL;
hashmap->items = _svg_hash_aryalloc(svg_hash_item_t);
if (hashmap->items == NULL)
{
free(hashmap);
return NULL;
}
hashmap->hash_tbl = _svg_hash_aryallocsize(size_t, _svg_hash_next_prime(size));
if (hashmap->hash_tbl != NULL)
memset(hashmap->hash_tbl, 0xFF,
_svg_hash_arysize(&hashmap->hash_tbl) * sizeof(size_t));
if (hashmap->hash_tbl == NULL)
{
_svg_hash_aryfree(&hashmap->items);
free(hashmap);
return NULL;
}
hashmap->deleted = SIZE_MAX;
return hashmap;
}
/**
* Releases all memory held by a hash map.
* @param hashmap Pointer to a hash map
*/
void
_svg_xml_hash_free (svg_xml_hash_table_t * hashmap)
{
_svg_hash_aryfree(&hashmap->hash_tbl);
_svg_hash_aryfree(&hashmap->items);
hashmap->hash_tbl = NULL;
hashmap->items = NULL;
free(hashmap);
}
/**
* Finds an element in the hash map.
* @param hashmap Pointer to hash map
* @param key Key to search for
* @return Pointer to element in hash map or NULL if key not found
*/
void *
_svg_xml_hash_lookup (svg_xml_hash_table_t * hashmap, const char* key)
{
size_t hash = _svg_hash_str_hash (hashmap, key);
size_t itemnum = hashmap->hash_tbl[hash];
for (; itemnum != SIZE_MAX; itemnum = hashmap->items[itemnum].next)
{
if (_svg_hash_streq (hashmap->items[itemnum].key, key))
return (void*)hashmap->items[itemnum].item;
}
return NULL;
}
/**
* Inserts a new element into the hash map. This will return an error if the
* key already exists.
* @param hashmap Pointer to hash map
* @param key Key to insert element under
* @param item Item pointer to insert into hash map
* @return 0 on success; non-zero on failure
*/
int
_svg_xml_hash_add_entry (svg_xml_hash_table_t *hashmap, const char* key, const void* item)
{
size_t hash = _svg_hash_str_hash (hashmap, key);
size_t itemnum = hashmap->hash_tbl[hash];
for (; itemnum != SIZE_MAX; itemnum = hashmap->items[itemnum].next)
{
if (_svg_hash_streq (hashmap->items[itemnum].key, key))
return 1; /* key exists */
}
return _str_hash_insert_new (hashmap, key, item, hash);
}
--- NEW FILE: svg_hash.h ---
/*
** This file is part of the C Utility Toolkit (CUTK)
** Copyright (C) 2002-2005 Chris Osgood
** http://www.cutk.org
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; either
** version 2.1 of the License, or (at your option) any later version.
**
** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public
** License along with this library; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
**
** Please report all bugs and problems to "bugs at cutk.org".
*/
/*
** A fast hash map implementation similar to STL hash_map<char*,void*>. It's
** very important to note that the keys in the hash map are just stored as
** pointers, therefore you can't reuse the same string pointer for inserting
** different keys. It's also not a good idea to change the value of a key
** while it's still in a hash map.
**
** $Id: svg_hash.h,v 1.1 2005/02/14 17:26:26 pb Exp $
*/
#ifndef _STRHMAP_H
#define _STRHMAP_H
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Type used to store items in the hash map */
typedef struct svg_hash_item
{
const char* key;
const void* item;
size_t next;
} svg_hash_item_t;
/* Hash map type. "items" is an array that can be used for iteration. */
/* When iterating, test the item->key value for NULL (erased items). */
typedef struct svg_xml_hash_table
{
size_t* hash_tbl;
svg_hash_item_t *items;
size_t deleted;
} svg_xml_hash_table_t;
svg_xml_hash_table_t *_svg_xml_hash_create (size_t size);
void _svg_xml_hash_free (svg_xml_hash_table_t *hashmap);
void* _svg_xml_hash_lookup (svg_xml_hash_table_t *hashmap, const char *key);
int _svg_xml_hash_add_entry (svg_xml_hash_table_t *hashmap, const char *key, const void *item);
#ifdef __cplusplus
}
#endif
#endif /* _STRHMAP_H */
Index: svg_parser.c
===================================================================
RCS file: /cvs/cairo/libsvg/src/svg_parser.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- svg_parser.c 7 Jun 2004 16:00:17 -0000 1.32
+++ svg_parser.c 14 Feb 2005 17:26:26 -0000 1.33
@@ -28,73 +28,6 @@
#include "svgint.h"
-static xmlEntity *
-_svg_parser_sax_get_entity (void *closure,
- const xmlChar *name);
-
-static void
-_svg_parser_sax_entity_decl (void *closure,
- const xmlChar *name,
- int type,
- const xmlChar *publicId,
- const xmlChar *systemId,
- xmlChar *content);
-
-
-static void
-_svg_parser_sax_start_element (void *closure,
- const xmlChar *name,
- const xmlChar **atts);
-
-static void
-_svg_parser_sax_end_element (void *closure,
- const xmlChar *name);
-
-static void
-_svg_parser_sax_characters (void *closure,
- const xmlChar *ch,
- int len);
-
-static void
-_svg_parser_sax_warning (void *closure,
- const char *msg, ...);
-
-static void
-_svg_parser_sax_error (void *closure,
- const char *msg, ...);
-
-static void
-_svg_parser_sax_fatal_error (void *closure,
- const char *msg, ...);
-
-static xmlSAXHandler SVG_PARSER_SAX_HANDLER = {
- NULL, /* internalSubset */
- NULL, /* isStandalone */
- NULL, /* hasInternalSubset */
- NULL, /* hasExternalSubset */
- NULL, /* resolveEntity */
- _svg_parser_sax_get_entity, /* getEntity */
- _svg_parser_sax_entity_decl, /* entityDecl */
- NULL, /* notationDecl */
- NULL, /* attributeDecl */
- NULL, /* elementDecl */
- NULL, /* unparsedEntityDecl */
- NULL, /* setDocumentLocator */
- NULL, /* startDocument */
- NULL, /* endDocument */
- _svg_parser_sax_start_element, /* startElement */
- _svg_parser_sax_end_element, /* endElement */
- NULL, /* reference */
- _svg_parser_sax_characters, /* characters */
- _svg_parser_sax_characters, /* ignorableWhitespace */
- NULL, /* processingInstruction */
- NULL, /* comment */
- _svg_parser_sax_warning, /* xmlParserWarning */
- _svg_parser_sax_error, /* xmlParserError */
- _svg_parser_sax_fatal_error, /* xmlParserFatalError */
- NULL, /* getParameterEntity */
-};
-
static svg_status_t
_svg_parser_push_state (svg_parser_t *parser,
const svg_parser_cb_t *cb);
@@ -243,140 +176,7 @@
{"pattern", {_svg_parser_parse_pattern, NULL }},
};
-svg_status_t
-_svg_parser_init (svg_parser_t *parser, svg_t *svg)
-{
- parser->svg = svg;
- parser->ctxt = NULL;
-
- parser->unknown_element_depth = 0;
-
- parser->state = NULL;
-
- parser->status = SVG_STATUS_SUCCESS;
-
- return parser->status;
-}
-
-svg_status_t
-_svg_parser_deinit (svg_parser_t *parser)
-{
- parser->svg = NULL;
- parser->ctxt = NULL;
-
- parser->status = SVG_STATUS_SUCCESS;
-
- return parser->status;
-}
-
-svg_status_t
-_svg_parser_begin (svg_parser_t *parser)
-{
- /* Innocent until proven guilty */
- parser->status = SVG_STATUS_SUCCESS;
-
- if (parser->ctxt)
- parser->status = SVG_STATUS_INVALID_CALL;
-
- parser->ctxt = xmlCreatePushParserCtxt (&SVG_PARSER_SAX_HANDLER,
- parser, NULL, 0, NULL);
- if (parser->ctxt == NULL)
- parser->status = SVG_STATUS_NO_MEMORY;
-
- parser->ctxt->replaceEntities = 1;
-
- parser->entities = xmlHashCreate (100);
- return parser->status;
-}
-
-svg_status_t
-_svg_parser_parse_chunk (svg_parser_t *parser, const char *buf, size_t count)
-{
- if (parser->status)
- return parser->status;
-
- if (parser->ctxt == NULL)
- return SVG_STATUS_INVALID_CALL;
-
- xmlParseChunk (parser->ctxt, buf, count, 0);
-
- return parser->status;
-}
-
-svg_status_t
-_svg_parser_end (svg_parser_t *parser)
-{
- if (parser->ctxt == NULL)
- return SVG_STATUS_INVALID_CALL;
-
- if (! parser->ctxt->wellFormed)
- parser->status = SVG_STATUS_PARSE_ERROR;
-
- xmlFreeParserCtxt (parser->ctxt);
- parser->ctxt = NULL;
-
- xmlHashFree (parser->entities, (xmlHashDeallocator) xmlFree);
- parser->entities = NULL;
-
- return parser->status;
-}
-
-static xmlEntity *
-_svg_parser_sax_get_entity (void *closure,
- const xmlChar *name)
-{
- svg_parser_t *parser = closure;
-
- return xmlHashLookup (parser->entities, name);
-}
-
-/* XXX: It's not clear to my why we have to do this. libxml2 has all
- * of this code internally, so we should be able to access a hash of
- * entities automatically rather than maintaining our own. */
-static void
-_svg_parser_sax_entity_decl (void *closure,
- const xmlChar *name,
- int type,
- const xmlChar *publicId,
- const xmlChar *systemId,
- xmlChar *content)
-{
- svg_parser_t *parser = closure;
- xmlEntityPtr entity;
-
- entity = malloc (sizeof(xmlEntity));
-
- entity->type = XML_ENTITY_DECL;
- entity->name = xmlMemStrdup (name);
- entity->etype = type;
- if (publicId)
- entity->ExternalID = xmlMemStrdup (publicId);
- else
- entity->ExternalID = NULL;
- if (systemId)
- entity->SystemID = xmlMemStrdup (systemId);
- else
- entity->SystemID = NULL;
-
- if (content) {
- entity->length = xmlStrlen (content);
- entity->content = xmlStrndup (content, entity->length);
- } else {
- entity->length = 0;
- entity->content = NULL;
- }
- entity->URI = NULL;
- entity->orig = NULL;
- entity->owner = 0;
- entity->children = NULL;
-
- if (xmlHashAddEntry (parser->entities, name, entity)) {
- /* Entity was already defined at another level. */
- free (entity);
- }
-}
-
-static void
+void
_svg_parser_sax_start_element (void *closure,
const xmlChar *name,
const xmlChar **attributes)
@@ -425,7 +225,7 @@
return;
}
-static void
+void
_svg_parser_sax_end_element (void *closure,
const xmlChar *name)
{
@@ -443,7 +243,7 @@
return;
}
-static void
+void
_svg_parser_sax_characters (void *closure,
const xmlChar *ch,
int len)
@@ -491,36 +291,6 @@
return;
}
-static void
-_svg_parser_sax_warning (void *closure, const char *msg, ...)
-{
- va_list args;
-
- va_start (args, msg);
- vfprintf (stderr, msg, args);
- va_end (args);
-}
-
-static void
-_svg_parser_sax_error (void *closure, const char *msg, ...)
-{
- va_list args;
-
- va_start (args, msg);
- vfprintf (stderr, msg, args);
- va_end (args);
-}
-
-static void
-_svg_parser_sax_fatal_error (void *closure, const char *msg, ...)
-{
- va_list args;
-
- va_start (args, msg);
- vfprintf (stderr, msg, args);
- va_end (args);
-}
-
static svg_status_t
_svg_parser_push_state (svg_parser_t *parser,
const svg_parser_cb_t *cb)
--- NEW FILE: svg_parser_expat.c ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: svg_parser_libxml.c ---
(This appears to be a binary file; contents omitted.)
Index: svgint.h
===================================================================
RCS file: /cvs/cairo/libsvg/src/svgint.h,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- svgint.h 7 Jun 2004 16:00:17 -0000 1.42
+++ svgint.h 14 Feb 2005 17:26:26 -0000 1.43
@@ -23,10 +23,33 @@
#ifndef SVGINT_H
#define SVGINT_H
+#ifdef LIBSVG_EXPAT
+
+#include <expat.h>
+#include "svg_hash.h"
+
+typedef XML_Char xmlChar;
+typedef XML_Parser svg_xml_parser_context_t;
+
+#define _svg_xml_strdup strdup
+
+#else
+
#include <libxml/SAX.h>
#include <libxml/xmlmemory.h>
#include <libxml/hash.h>
+typedef xmlParserCtxtPtr svg_xml_parser_context_t;
+typedef xmlHashTable svg_xml_hash_table_t;
+
+#define _svg_xml_hash_add_entry xmlHashAddEntry
+#define _svg_xml_hash_lookup xmlHashLookup
+#define _svg_xml_hash_create xmlHashCreate
+#define _svg_xml_hash_free(_table) xmlHashFree(_table, NULL)
+#define _svg_xml_strdup xmlMemStrdup
+
+#endif
+
#include "config.h"
#include "svg_version.h"
#include "svg.h"
@@ -330,12 +353,12 @@
svg_t *svg;
- xmlParserCtxtPtr ctxt;
+ svg_xml_parser_context_t ctxt;
unsigned int unknown_element_depth;
svg_parser_state_t *state;
- xmlHashTable *entities;
+ svg_xml_hash_table_t *entities;
svg_status_t status;
};
@@ -347,7 +370,7 @@
svg_element_t *group_element;
- xmlHashTable *element_ids;
+ svg_xml_hash_table_t *element_ids;
svg_parser_t parser;
More information about the cairo-commit
mailing list