Revision: 7402
http://winmerge.svn.sourceforge.net/winmerge/?rev=7402&view=rev
Author: gerundt
Date: 2010-11-01 14:59:25 +0000 (Mon, 01 Nov 2010)
Log Message:
-----------
Add missing SCEW files to R2_14
Added Paths:
-----------
branches/R2_14/Externals/scew/scew/bool.h
branches/R2_14/Externals/scew/scew/element_attribute.c
branches/R2_14/Externals/scew/scew/element_compare.c
branches/R2_14/Externals/scew/scew/element_copy.c
branches/R2_14/Externals/scew/scew/element_search.c
branches/R2_14/Externals/scew/scew/export.h
branches/R2_14/Externals/scew/scew/list.c
branches/R2_14/Externals/scew/scew/list.h
branches/R2_14/Externals/scew/scew/printer.c
branches/R2_14/Externals/scew/scew/printer.h
branches/R2_14/Externals/scew/scew/reader.c
branches/R2_14/Externals/scew/scew/reader.h
branches/R2_14/Externals/scew/scew/reader_buffer.c
branches/R2_14/Externals/scew/scew/reader_buffer.h
branches/R2_14/Externals/scew/scew/reader_file.c
branches/R2_14/Externals/scew/scew/reader_file.h
branches/R2_14/Externals/scew/scew/writer_buffer.c
branches/R2_14/Externals/scew/scew/writer_buffer.h
branches/R2_14/Externals/scew/scew/writer_file.c
branches/R2_14/Externals/scew/scew/writer_file.h
Added: branches/R2_14/Externals/scew/scew/bool.h
===================================================================
--- branches/R2_14/Externals/scew/scew/bool.h (rev 0)
+++ branches/R2_14/Externals/scew/scew/bool.h 2010-11-01 14:59:25 UTC (rev 7402)
@@ -0,0 +1,40 @@
+/**
+ * @file bool.h
+ * @brief SCEW boolean type declaration
+ * @author Aleix Conchillo Flaque <al...@me...>
+ * @date Thu Sep 04, 2008 11:42
+ *
+ * @if copyright
+ *
+ * Copyright (C) 2008, 2009 Aleix Conchillo Flaque
+ *
+ * SCEW 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.
+ *
+ * SCEW 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., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * @endif
+ **/
+
+#ifndef BOOL_H_0809041142
+#define BOOL_H_0809041142
+
+/**
+ * This should be defined using stdbool.h when C99 is available.
+ */
+typedef unsigned char scew_bool;
+
+#define SCEW_TRUE ((scew_bool) 1) /**< True */
+#define SCEW_FALSE ((scew_bool) 0) /**< False */
+
+#endif /* BOOL_H_0809041142 */
Property changes on: branches/R2_14/Externals/scew/scew/bool.h
___________________________________________________________________
Added: svn:eol-style
+ native
Added: branches/R2_14/Externals/scew/scew/element_attribute.c
===================================================================
--- branches/R2_14/Externals/scew/scew/element_attribute.c (rev 0)
+++ branches/R2_14/Externals/scew/scew/element_attribute.c 2010-11-01 14:59:25 UTC (rev 7402)
@@ -0,0 +1,308 @@
+/**
+ * @file element_attribute.c
+ * @brief element.h implementation
+ * @author Aleix Conchillo Flaque <al...@me...>
+ * @date Thu Aug 27, 2009 01:43
+ *
+ * @if copyright
+ *
+ * Copyright (C) 2009 Aleix Conchillo Flaque
+ *
+ * SCEW 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.
+ *
+ * SCEW 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., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * @endif
+ */
+
+#include "xelement.h"
+
+#include "str.h"
+
+#include "xattribute.h"
+#include "xerror.h"
+
+#include <assert.h>
+
+
+
+/* Private */
+
+static scew_bool cmp_attr_name_ (void const *attribute, void const *name);
+
+static scew_attribute* add_new_attribute_ (scew_element *element,
+ scew_attribute *attribute);
+
+static scew_attribute* update_attribute_ (scew_element *element,
+ scew_attribute *attribute,
+ XML_Char const *value);
+
+
+/* Public */
+
+unsigned int
+scew_element_attribute_count (scew_element const *element)
+{
+ assert (element != NULL);
+
+ return element->n_attributes;
+}
+
+scew_list*
+scew_element_attributes (scew_element const *element)
+{
+ assert (element != NULL);
+
+ return element->attributes;
+}
+
+scew_attribute*
+scew_element_attribute_by_name (scew_element const *element,
+ XML_Char const *name)
+{
+ scew_list *item = NULL;
+
+ assert (element != NULL);
+ assert (name != NULL);
+
+ if (element->attributes != NULL)
+ {
+ item = scew_list_find_custom (element->attributes, name, cmp_attr_name_);
+ }
+
+ return (NULL == item) ? NULL : (scew_attribute *) scew_list_data (item);
+}
+
+scew_attribute*
+scew_element_attribute_by_index (scew_element const *element,
+ unsigned int index)
+{
+ scew_list *item = NULL;
+
+ assert (element != NULL);
+ assert (index < element->n_attributes);
+
+ if (element->attributes != NULL)
+ {
+ item = scew_list_index (element->attributes, index);
+ }
+
+ return (NULL == item) ? NULL : (scew_attribute *) scew_list_data (item);
+}
+
+scew_attribute*
+scew_element_add_attribute (scew_element *element, scew_attribute *attribute)
+{
+ scew_attribute *new_attribute = NULL;
+
+ assert (element != NULL);
+ assert (attribute != NULL);
+
+ if (scew_attribute_parent (attribute) == NULL)
+ {
+ XML_Char const *name = scew_attribute_name (attribute);
+ XML_Char const *value = scew_attribute_value (attribute);
+
+ /* Try to find an existent attribute. */
+ scew_attribute *old_attribute = scew_element_attribute_by_name (element,
+ name);
+
+ /* Add new attribute or update existent one. */
+ new_attribute = (NULL == old_attribute)
+ ? add_new_attribute_ (element, attribute)
+ : update_attribute_ (element, old_attribute, value);
+ }
+
+ return new_attribute;
+}
+
+
+scew_attribute*
+scew_element_add_attribute_pair (scew_element *element,
+ XML_Char const *name,
+ XML_Char const *value)
+{
+ scew_attribute *old_attribute = NULL;
+ scew_attribute *new_attribute = NULL;
+
+ assert (element != NULL);
+ assert (name != NULL);
+ assert (value != NULL);
+
+ /* Try to find an existent attribute. */
+ old_attribute = scew_element_attribute_by_name (element, name);
+
+ if (NULL == old_attribute)
+ {
+ /**
+ * If the attribute does not exist, create a new one and try to
+ * add it.
+ */
+ scew_attribute *attribute = scew_attribute_create (name, value);
+
+ if (attribute != NULL)
+ {
+ new_attribute = add_new_attribute_ (element, attribute);
+
+ if (NULL == new_attribute)
+ {
+ /* The new attribute could not be added, free it. */
+ scew_attribute_free (attribute);
+ }
+ }
+ }
+ else
+ {
+ /* If the attribtue already exists we update its value. */
+ new_attribute = update_attribute_ (element, old_attribute, value);
+ }
+
+ return new_attribute;
+}
+
+void
+scew_element_delete_attribute (scew_element *element,
+ scew_attribute *attribute)
+{
+ assert (element != NULL);
+ assert (attribute != NULL);
+
+ element->attributes = scew_list_delete (element->attributes, attribute);
+ element->n_attributes -= 1;
+
+ scew_attribute_free (attribute);
+}
+
+void
+scew_element_delete_attribute_all (scew_element *element)
+{
+ scew_list *list = NULL;
+
+ assert (element != NULL);
+
+ /* Free all attributes. */
+ list = element->attributes;
+ while (list != NULL)
+ {
+ scew_attribute *aux = scew_list_data (list);
+ list = scew_list_next (list);
+ scew_attribute_free (aux);
+ }
+ scew_list_free (element->attributes);
+
+ element->attributes = NULL;
+ element->last_attribute = NULL;
+ element->n_attributes = 0;
+}
+
+void
+scew_element_delete_attribute_by_name (scew_element *element,
+ XML_Char const* name)
+{
+ assert (element != NULL);
+ assert (name != NULL);
+
+ if (element->attributes != NULL)
+ {
+ scew_list *item =
+ scew_list_find_custom (element->attributes, name, cmp_attr_name_);
+
+ if (item != NULL)
+ {
+ scew_attribute *attribute = scew_list_data (item);
+ scew_element_delete_attribute (element, attribute);
+ }
+ }
+}
+
+void
+scew_element_delete_attribute_by_index (scew_element *element,
+ unsigned int index)
+{
+ assert (element != NULL);
+ assert (index < element->n_attributes);
+
+ if (element->attributes != NULL)
+ {
+ scew_list *item = scew_list_index (element->attributes, index);
+
+ if (item != NULL)
+ {
+ scew_attribute *attribute = scew_list_data (item);
+ scew_element_delete_attribute (element, attribute);
+ }
+ }
+}
+
+
+/* Private */
+
+scew_bool
+cmp_attr_name_ (void const *attribute, void const *name)
+{
+ return (scew_strcmp (scew_attribute_name ((scew_attribute *) attribute),
+ (XML_Char *) name) == 0);
+}
+
+scew_attribute*
+add_new_attribute_ (scew_element *element, scew_attribute *attribute)
+{
+ scew_list *item = NULL;
+ scew_attribute *new_attribute = NULL;
+
+ assert (element != NULL);
+ assert (attribute != NULL);
+
+ item = scew_list_append (element->last_attribute, attribute);
+
+ if (item != NULL)
+ {
+ /* Initialise attributes list. */
+ if (NULL == element->attributes)
+ {
+ element->attributes = item;
+ }
+
+ scew_attribute_set_parent_ (attribute, element);
+
+ /* Update performance variables. */
+ element->last_attribute = item;
+ element->n_attributes += 1;
+
+ /* Update the return value. */
+ new_attribute = attribute;
+ }
+ else
+ {
+ scew_error_set_last_error_ (scew_error_no_memory);
+ }
+
+ return new_attribute;
+}
+
+scew_attribute*
+update_attribute_ (scew_element *element,
+ scew_attribute *attribute,
+ XML_Char const *value)
+{
+ XML_Char const *new_value = NULL;
+
+ assert (element != NULL);
+ assert (attribute != NULL);
+ assert (value != NULL);
+
+ new_value = scew_attribute_set_value (attribute, value);
+
+ return (NULL == new_value) ? NULL : attribute;
+}
Property changes on: branches/R2_14/Externals/scew/scew/element_attribute.c
___________________________________________________________________
Added: svn:eol-style
+ native
Added: branches/R2_14/Externals/scew/scew/element_compare.c
===================================================================
--- branches/R2_14/Externals/scew/scew/element_compare.c (rev 0)
+++ branches/R2_14/Externals/scew/scew/element_compare.c 2010-11-01 14:59:25 UTC (rev 7402)
@@ -0,0 +1,137 @@
+/**
+ * @file element_compare.c
+ * @brief element.h implementation
+ * @author Aleix Conchillo Flaque <al...@me...>
+ * @date Thu Aug 27, 2009 01:38
+ *
+ * @if copyright
+ *
+ * Copyright (C) 2009 Aleix Conchillo Flaque
+ *
+ * SCEW 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.
+ *
+ * SCEW 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., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * @endif
+ */
+
+#include "xelement.h"
+
+#include "attribute.h"
+#include "str.h"
+
+#include <assert.h>
+
+
+
+/* Private */
+
+static scew_bool compare_element_ (scew_element const *a,
+ scew_element const *b);
+static scew_bool compare_children_ (scew_element const *a,
+ scew_element const *b,
+ scew_element_cmp_hook hook);
+static scew_bool compare_attributes_ (scew_element const *a,
+ scew_element const *b);
+
+
+
+/* Public */
+
+scew_bool
+scew_element_compare (scew_element const *a,
+ scew_element const *b,
+ scew_element_cmp_hook hook)
+{
+ scew_element_cmp_hook cmp_hook = NULL;
+
+ assert (a != NULL);
+ assert (b != NULL);
+
+ cmp_hook = (NULL == hook) ? compare_element_ : hook;
+
+ return (cmp_hook (a, b) && compare_children_ (a, b, cmp_hook));
+}
+
+
+/* Private */
+
+scew_bool
+compare_element_ (scew_element const *a, scew_element const *b)
+{
+ scew_bool equal = SCEW_FALSE;
+
+ assert (a != NULL);
+ assert (b != NULL);
+
+ equal = (scew_strcmp (a->name, b->name) == 0)
+ && (scew_strcmp (a->contents, b->contents) == 0)
+ && compare_attributes_ (a, b);
+
+ return equal;
+}
+
+scew_bool
+compare_attributes_ (scew_element const *a, scew_element const *b)
+{
+ scew_bool equal = SCEW_TRUE;
+ scew_list *list_a = NULL;
+ scew_list *list_b = NULL;
+
+ assert (a != NULL);
+ assert (b != NULL);
+
+ equal = (a->n_attributes == b->n_attributes);
+
+ list_a = a->attributes;
+ list_b = b->attributes;
+ while (equal && (list_a != NULL) && (list_b != NULL))
+ {
+ scew_attribute *attr_a = scew_list_data (list_a);
+ scew_attribute *attr_b = scew_list_data (list_b);
+ equal = scew_attribute_compare (attr_a, attr_b);
+ list_a = scew_list_next (list_a);
+ list_b = scew_list_next (list_b);
+ }
+
+ return equal;
+}
+
+scew_bool
+compare_children_ (scew_element const *a,
+ scew_element const *b,
+ scew_element_cmp_hook hook)
+{
+ scew_bool equal = SCEW_TRUE;
+ scew_list *list_a = NULL;
+ scew_list *list_b = NULL;
+
+ assert (a != NULL);
+ assert (b != NULL);
+
+ equal = (a->n_children == b->n_children);
+
+ list_a = a->children;
+ list_b = b->children;
+ while (equal && (list_a != NULL) && (list_b != NULL))
+ {
+ scew_element *child_a = scew_list_data (list_a);
+ scew_element *child_b = scew_list_data (list_b);
+ equal = scew_element_compare (child_a, child_b, hook);
+ list_a = scew_list_next (list_a);
+ list_b = scew_list_next (list_b);
+ }
+
+ return equal;
+}
Property changes on: branches/R2_14/Externals/scew/scew/element_compare.c
___________________________________________________________________
Added: svn:eol-style
+ native
Added: branches/R2_14/Externals/scew/scew/element_copy.c
===================================================================
--- branches/R2_14/Externals/scew/scew/element_copy.c (rev 0)
+++ branches/R2_14/Externals/scew/scew/element_copy.c 2010-11-01 14:59:25 UTC (rev 7402)
@@ -0,0 +1,126 @@
+/**
+ * @file element_search.c
+ * @brief element.h implementation
+ * @author Aleix Conchillo Flaque <al...@me...>
+ * @date Thu Aug 27, 2009 01:53
+ *
+ * @if copyright
+ *
+ * Copyright (C) 2009 Aleix Conchillo Flaque
+ *
+ * SCEW 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.
+ *
+ * SCEW 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., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * @endif
+ */
+
+#include "xelement.h"
+
+#include "attribute.h"
+
+#include <assert.h>
+
+
+
+/* Private */
+
+static scew_bool copy_children_ (scew_element *new_element,
+ scew_element const *element);
+static scew_bool copy_attributes_ (scew_element *new_element,
+ scew_element const *element);
+
+
+
+/* Public */
+
+scew_element*
+scew_element_copy (scew_element const *element)
+{
+ scew_element *new_elem = NULL;
+
+ assert (element != NULL);
+
+ new_elem = calloc (1, sizeof (scew_element));
+
+ if (new_elem != NULL)
+ {
+ scew_bool copied =
+ ((NULL == element->contents)
+ || (scew_element_set_contents (new_elem, element->contents) != NULL));
+
+ copied = copied
+ && (scew_element_set_name (new_elem, element->name) != NULL)
+ && copy_children_ (new_elem, element)
+ && copy_attributes_ (new_elem, element);
+
+ if (!copied)
+ {
+ scew_element_free (new_elem);
+ new_elem = NULL;
+ }
+ }
+
+ return new_elem;
+}
+
+
+
+/* Private */
+
+scew_bool
+copy_children_ (scew_element *new_element, scew_element const *element)
+{
+ scew_bool copied = SCEW_TRUE;
+ scew_list *list = NULL;
+
+ assert (new_element != NULL);
+ assert (element != NULL);
+
+ list = element->children;
+ while (copied && (list != NULL))
+ {
+ scew_element *child = scew_list_data (list);
+ scew_element *new_child = scew_element_copy (child);
+ copied =
+ ((new_child != NULL)
+ && (scew_element_add_element (new_element, new_child) != NULL));
+ list = scew_list_next (list);
+ }
+
+ return copied;
+}
+
+scew_bool
+copy_attributes_ (scew_element *new_element, scew_element const *element)
+{
+ scew_bool copied = SCEW_TRUE;
+ scew_list *list = NULL;
+
+ assert (new_element != NULL);
+ assert (element != NULL);
+
+ list = element->attributes;
+ while (copied && (list != NULL))
+ {
+ scew_attribute *attr = scew_list_data (list);
+ scew_attribute *new_attr = scew_attribute_copy (attr);
+ copied =
+ ((new_attr != NULL)
+ && (scew_element_add_attribute (new_element, new_attr) != NULL));
+ list = scew_list_next (list);
+ }
+
+ return copied;
+}
Property changes on: branches/R2_14/Externals/scew/scew/element_copy.c
___________________________________________________________________
Added: svn:eol-style
+ native
Added: branches/R2_14/Externals/scew/scew/element_search.c
===================================================================
--- branches/R2_14/Externals/scew/scew/element_search.c (rev 0)
+++ branches/R2_14/Externals/scew/scew/element_search.c 2010-11-01 14:59:25 UTC (rev 7402)
@@ -0,0 +1,110 @@
+/**
+ * @file element_search.c
+ * @brief element.h implementation
+ * @author Aleix Conchillo Flaque <al...@me...>
+ * @date Thu Aug 27, 2009 01:36
+ *
+ * @if copyright
+ *
+ * Copyright (C) 2009 Aleix Conchillo Flaque
+ *
+ * SCEW 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.
+ *
+ * SCEW 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., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * @endif
+ */
+
+#include "xelement.h"
+
+#include "str.h"
+
+#include <assert.h>
+
+
+
+/* Private */
+
+static scew_bool cmp_name_ (void const *element, void const *name);
+
+
+
+/* Public */
+
+scew_element*
+scew_element_by_name (scew_element const *element, XML_Char const *name)
+{
+ scew_list *item = NULL;
+
+ assert (element != NULL);
+ assert (name != NULL);
+
+ if (element->children != NULL)
+ {
+ item = scew_list_find_custom (element->children, name, cmp_name_);
+ }
+
+ return (NULL == item) ? NULL : (scew_element *) scew_list_data (item);
+}
+
+scew_element*
+scew_element_by_index (scew_element const *element, unsigned int index)
+{
+ scew_list *item = NULL;
+
+ assert (element != NULL);
+ assert (index < element->n_children);
+
+ item = scew_list_index (element->children, index);
+
+ return (NULL == item) ? NULL : (scew_element *) scew_list_data (item);
+}
+
+scew_list*
+scew_element_list_by_name (scew_element const *element, XML_Char const *name)
+{
+ scew_list *list = NULL;
+ scew_list *last = NULL;
+ scew_list *item = NULL;
+
+ assert (element != NULL);
+ assert (name != NULL);
+
+ item = element->children;
+ while (item != NULL)
+ {
+ item = scew_list_find_custom (item, name, cmp_name_);
+ if (item != NULL)
+ {
+ last = scew_list_append (last, scew_list_data (item));
+ if (NULL == list)
+ {
+ list = last;
+ }
+ item = scew_list_next (item);
+ }
+ }
+
+ return list;
+}
+
+
+/* Private */
+
+scew_bool
+cmp_name_ (void const *element, void const *name)
+{
+ return (scew_strcmp (((scew_element *) element)->name,
+ (XML_Char *) name) == 0);
+}
Property changes on: branches/R2_14/Externals/scew/scew/element_search.c
___________________________________________________________________
Added: svn:eol-style
+ native
Added: branches/R2_14/Externals/scew/scew/export.h
===================================================================
--- branches/R2_14/Externals/scew/scew/export.h (rev 0)
+++ branches/R2_14/Externals/scew/scew/export.h 2010-11-01 14:59:25 UTC (rev 7402)
@@ -0,0 +1,77 @@
+/**
+ * @file export.h
+ * @brief SCEW shared library support
+ * @author Aleix Conchillo Flaque <al...@me...>
+ * @date Fri Sep 04, 2009 00:14
+ *
+ * @if copyright
+ *
+ * Copyright (C) 2009 Aleix Conchillo Flaque
+ *
+ * SCEW 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.
+ *
+ * SCEW 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., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * @endif
+ */
+
+#ifndef EXPORT_H_0909040014
+#define EXPORT_H_0909040014
+
+#if !defined (_MSC_VER) && defined (XML_UNICODE_WCHAR_T)
+#error UTF-16 support is only available in Windows platforms
+#endif
+
+#if defined (_MSC_VER) || defined (__CYGWIN__)
+
+ #define SCEW_DLL_IMPORT __declspec(dllimport)
+ #define SCEW_DLL_EXPORT __declspec(dllexport)
+ #define SCEW_DLL_LOCAL
+
+#else
+
+ #if __GNUC__ >= 4
+ #define SCEW_DLL_IMPORT __attribute__ ((visibility("default")))
+ #define SCEW_DLL_EXPORT __attribute__ ((visibility("default")))
+ #define SCEW_DLL_LOCAL __attribute__ ((visibility("hidden")))
+ #else
+ #define SCEW_DLL_IMPORT
+ #define SCEW_DLL_EXPORT
+ #define SCEW_DLL_LOCAL
+ #endif /* __GNUC__ >= 4 */
+
+ #ifdef PIC /* This will tell us if we are building a shared library. */
+ #define SCEW_DLL
+ #endif /* PIC */
+
+#endif /* _MSC_VER || __CYGWIN__ */
+
+#ifdef SCEW_DLL /* Defined if SCEW is compiled as a DLL. */
+
+ #ifdef DLL_EXPORTS /* Defined if we are building the SCEW DLL. */
+ #define SCEW_API SCEW_DLL_EXPORT
+ #else
+ #define SCEW_API SCEW_DLL_IMPORT
+ #endif /* DLL_EXPORTS */
+
+ #define SCEW_LOCAL SCEW_DLL_LOCAL
+
+#else /* SCEW_DLL is not defined: this means SCEW is a static lib. */
+
+ #define SCEW_API
+ #define SCEW_LOCAL
+
+#endif /* SCEW_DLL */
+
+#endif /* EXPORT_H_0909040014 */
Property changes on: branches/R2_14/Externals/scew/scew/export.h
___________________________________________________________________
Added: svn:eol-style
+ native
Added: branches/R2_14/Externals/scew/scew/list.c
===================================================================
--- branches/R2_14/Externals/scew/scew/list.c (rev 0)
+++ branches/R2_14/Externals/scew/scew/list.c 2010-11-01 14:59:25 UTC (rev 7402)
@@ -0,0 +1,321 @@
+/**
+ * @file list.c
+ * @brief list.h implementation
+ * @author Aleix Conchillo Flaque <al...@me...>
+ * @date Thu Jul 12, 2007 20:09
+ *
+ * @if copyright
+ *
+ * Copyright (C) 2007-2009 Aleix Conchillo Flaque
+ *
+ * SCEW 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.
+ *
+ * SCEW 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., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * @endif
+ **/
+
+#include "list.h"
+
+#include <assert.h>
+#include <stdlib.h>
+
+
+/* Private */
+
+struct scew_list
+{
+ void *data;
+ scew_list *prev;
+ scew_list *next;
+};
+
+
+/* Public */
+
+
+/* Allocation */
+
+scew_list*
+scew_list_create (void *data)
+{
+ scew_list *list = NULL;
+
+ assert (data != NULL);
+
+ list = calloc (1, sizeof (scew_list));
+
+ if (list != NULL)
+ {
+ list->data = data;
+ }
+
+ return list;
+}
+
+void
+scew_list_free (scew_list *list)
+{
+ while (list != NULL)
+ {
+ scew_list *tmp = list;
+ list = list->next;
+ free (tmp);
+ }
+}
+
+
+/* Accessors */
+
+void*
+scew_list_data (scew_list *list)
+{
+ assert (list != NULL);
+
+ return list->data;
+}
+
+unsigned int
+scew_list_size (scew_list *list)
+{
+ unsigned int total = 0;
+
+ while (list != NULL)
+ {
+ ++total;
+ list = list->next;
+ }
+
+ return total;
+}
+
+
+/* Modifiers */
+
+scew_list*
+scew_list_append (scew_list *list, void *data)
+{
+ scew_list *item = NULL;
+
+ assert (data != NULL);
+
+ item = scew_list_create (data);
+
+ if ((item != NULL) && (list != NULL))
+ {
+ scew_list *last = scew_list_last (list);
+ last->next = item;
+ item->prev = last;
+ }
+
+ return item;
+}
+
+scew_list*
+scew_list_prepend (scew_list *list, void *data)
+{
+ scew_list *item = NULL;
+
+ assert (data != NULL);
+
+ item = scew_list_create (data);
+
+ if ((item != NULL) && (list != NULL))
+ {
+ scew_list *first = scew_list_first (list);
+ first->prev = item;
+ item->next = first;
+ }
+
+ return item;
+}
+
+scew_list*
+scew_list_delete (scew_list *list, void *data)
+{
+ scew_list *tmp = list;
+
+ assert (list != NULL);
+ assert (data != NULL);
+
+ while (tmp != NULL)
+ {
+ if (tmp->data != data)
+ {
+ tmp = tmp->next;
+ }
+ else
+ {
+ if (tmp->prev)
+ {
+ tmp->prev->next = tmp->next;
+ }
+ if (tmp->next)
+ {
+ tmp->next->prev = tmp->prev;
+ }
+
+ if (list == tmp)
+ {
+ list = list->next;
+ }
+ break;
+ }
+ }
+
+ return list;
+}
+
+scew_list*
+scew_list_delete_item (scew_list *list, scew_list *item)
+{
+ assert (list != NULL);
+
+ if (item != NULL)
+ {
+ if (item->prev != NULL)
+ {
+ item->prev->next = item->next;
+ }
+ if (item->next != NULL)
+ {
+ item->next->prev = item->prev;
+ }
+
+ if (item == list)
+ {
+ list = list->next;
+ }
+
+ free (item);
+ }
+
+ return list;
+}
+
+
+/* Traverse */
+
+scew_list*
+scew_list_first (scew_list *list)
+{
+ assert (list != NULL);
+
+ while (list->prev != NULL)
+ {
+ list = list->prev;
+ }
+
+ return list;
+}
+
+scew_list*
+scew_list_last (scew_list *list)
+{
+ assert (list != NULL);
+
+ while (list->next != NULL)
+ {
+ list = list->next;
+ }
+
+ return list;
+}
+
+scew_list*
+scew_list_next (scew_list *list)
+{
+ assert (list != NULL);
+
+ return list->next;
+}
+
+scew_list*
+scew_list_previous (scew_list *list)
+{
+ assert (list != NULL);
+
+ return list->prev;
+}
+
+scew_list*
+scew_list_index (scew_list *list, unsigned int index)
+{
+ unsigned int count = 0;
+
+ assert (list != NULL);
+
+ while ((list != NULL) && (count < index))
+ {
+ list = list->next;
+ ++count;
+ }
+
+ return list;
+}
+
+void
+scew_list_foreach (scew_list *list, scew_list_hook hook, void *user_data)
+{
+ assert (list != NULL);
+ assert (hook != NULL);
+
+ while (list != NULL)
+ {
+ hook (list, user_data);
+ list = list->next;
+ }
+}
+
+
+/* Search */
+
+scew_list*
+scew_list_find (scew_list *list, void *data)
+{
+ assert (list != NULL);
+ assert (data != NULL);
+
+ while (list != NULL)
+ {
+ if (list->data == data)
+ {
+ break;
+ }
+ list = list->next;
+ }
+
+ return list;
+}
+
+scew_list*
+scew_list_find_custom (scew_list *list,
+ void const *data,
+ scew_cmp_hook hook)
+{
+ assert (list != NULL);
+ assert (data != NULL);
+ assert (hook != NULL);
+
+ while (list != NULL)
+ {
+ if (hook (list->data, data))
+ {
+ break;
+ }
+ list = list->next;
+ }
+
+ return list;
+}
Property changes on: branches/R2_14/Externals/scew/scew/list.c
___________________________________________________________________
Added: svn:eol-style
+ native
Added: branches/R2_14/Externals/scew/scew/list.h
===================================================================
--- branches/R2_14/Externals/scew/scew/list.h (rev 0)
+++ branches/R2_14/Externals/scew/scew/list.h 2010-11-01 14:59:25 UTC (rev 7402)
@@ -0,0 +1,342 @@
+/**
+ * @file list.h
+ * @brief SCEW general list implementation
+ * @author Aleix Conchillo Flaque <al...@me...>
+ * @date Thu Jul 12, 2007 20:09
+ * @ingroup SCEWList, SCEWListAlloc, SCEWListAcc, SCEWListMod
+ * @ingroup SCEWListTrav, SCEWListSearch, SCEWList
+ *
+ * @if copyright
+ *
+ * Copyright (C) 2007-2009 Aleix Conchillo Flaque
+ *
+ * SCEW 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.
+ *
+ * SCEW 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., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * @endif
+ **/
+
+/**
+ * @defgroup SCEWList Lists
+ *
+ * This is a generic list implementation currenlty used by element's
+ * children and attributes, though, as a generic list, it can be used
+ * with any other type of data.
+ */
+
+#ifndef LIST_H_0707122009
+#define LIST_H_0707122009
+
+#include "export.h"
+
+#include "bool.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+ * This is the type delcaration for SCEW lists.
+ *
+ * @ingroup SCEWList
+ */
+typedef struct scew_list scew_list;
+
+/**
+ * SCEW lists hooks (functions) are used by #scew_list_foreach. The
+ * hook will be used to perform some custom action, defined by the
+ * hook, to every list item. These functions take two arguments, the
+ * list item where the action should be performed and an additional
+ * argument for any data that could be of use to the action.
+ *
+ * @param item the list item currently being traversed.
+ * @param user_data an optional user data pointer to be used by the
+ * hook (might be NULL).
+ *
+ * @ingroup SCEWList
+ */
+typedef void (*scew_list_hook) (scew_list *, void *);
+
+/**
+ * SCEW lists comparison hooks are used by #scew_list_find_custom. The
+ * hook takes the two arguments to be compared (of the same type).
+ *
+ * @return true if the given arguments are considered (by the provided
+ * comparison hook) equal, false otherwise.
+ *
+ * @ingroup SCEWList
+ */
+typedef scew_bool (*scew_cmp_hook) (void const *, void const *);
+
+
+/**
+ * @defgroup SCEWListAlloc Allocation
+ * Allocate and free new lists.
+ * @ingroup SCEWList
+ */
+
+/**
+ * Creates a new list item with the given @a data. Note that there is
+ * no difference between list items and lists, that is, a list item is
+ * a list itself.
+ *
+ * @pre data != NULL
+ *
+ * @return a new list, or NULL if the list could not be created.
+ *
+ * @ingroup SCEWListAlloc
+ */
+extern SCEW_API scew_list* scew_list_create (void *data);
+
+/**
+ * Frees all the items from the given @a list. The data pointers are
+ * not freed, thus they need to be freed separately.
+ *
+ * @ingroup SCEWListAlloc
+ */
+extern SCEW_API void scew_list_free (scew_list *list);
+
+
+/**
+ * @defgroup SCEWListAcc Accessors
+ * Access lists' data and information.
+ * @ingroup SCEWList
+ */
+
+/**
+ * Returns the data pointer of the given @a list item. Note that this
+ * routine does not know if the data pointed by the @a list item has
+ * been freed, so it might return a valid address without useful
+ * content.
+ *
+ * @pre list != NULL
+ *
+ * @return the data pointer for the given @a list.
+ *
+ * @ingroup SCEWListAcc
+ */
+extern SCEW_API void* scew_list_data (scew_list *list);
+
+/**
+ * Returns the number of items in the given @a list.
+ *
+ * @return the number of items in the given @a list or 0 if @a list is
+ * NULL.
+ *
+ * @ingroup SCEWListAcc
+ */
+extern SCEW_API unsigned int scew_list_size (scew_list *list);
+
+
+/**
+ * @defgroup SCEWListMod Modifiers
+ * Add and remove items from lists.
+ * @ingroup SCEWList
+ */
+
+/**
+ * Creates a new list item with the given @a data and appends it to @a
+ * list. If the given @a list is NULL this function acts like
+ * #scew_list_create.
+ *
+ * @pre data != NULL
+ *
+ * @return the item appended to @a list or NULL if an item could not
+ * be created.
+ *
+ * @ingroup SCEWListMod
+ */
+extern SCEW_API scew_list* scew_list_append (scew_list *list, void *data);
+
+/**
+ * Creates a new list item with the given @a data and prepends it to
+ * @a list. If the given @a list is NULL this function acts like
+ * #scew_list_create.
+ *
+ * @pre data != NULL
+ *
+ * @return the item prepended to @a list or NULL if an item could not
+ * be created.
+ *
+ * @ingroup SCEWListMod
+ */
+extern SCEW_API scew_list* scew_list_prepend (scew_list *list, void *data);
+
+/**
+ * Deletes the first item pointing to @a data from the given @a
+ * list. This function will search from the given item list, not from
+ * the beginning.
+ *
+ * @pre list != NULL
+ * @pre data != NULL
+ *
+ * @return @a list if the item found was not the first list item, or
+ * the new first item otherwise.
+ *
+ * @ingroup SCEWListMod
+ */
+extern SCEW_API scew_list* scew_list_delete (scew_list *list, void *data);
+
+/**
+ * Deletes the given list @a item from @a list.
+ *
+ * @pre list != NULL
+ *
+ * @return @a list if @a item was not the first list item, or the new
+ * first item otherwise.
+ *
+ * @ingroup SCEWListMod
+ */
+extern SCEW_API scew_list* scew_list_delete_item (scew_list *list,
+ scew_list *item);
+
+
+/**
+ * @defgroup SCEWListTrav Traverse
+ * Traverse list items.
+ * @ingroup SCEWList
+ */
+
+/**
+ * Finds the first item of the given @a list. This function traverses
+ * all the @a list backwards until it finds an item whose previous
+ * item is NULL.
+ *
+ * @pre list != NULL
+ *
+ * @return the first item of the given @a list or NULL if @a list is
+ * NULL.
+ *
+ * @ingroup SCEWListTrav
+ */
+extern SCEW_API scew_list* scew_list_first (scew_list *list);
+
+/**
+ * Finds the last item of the given @a list. This function traverses
+ * all the @a list forwards until it finds an item whose next item is
+ * NULL.
+ *
+ * @pre list != NULL
+ *
+ * @return the last item of the given @a list or NULL if @a list is
+ * NULL.
+ *
+ * @ingroup SCEWListTrav
+ */
+extern SCEW_API scew_list* scew_list_last (scew_list *list);
+
+/**
+ * Obtains the next item of the given @a list item.
+ *
+ * @pre list != NULL
+ *
+ * @return the next @a list item or NULL if @a list is the last item.
+ *
+ * @ingroup SCEWListTrav
+ */
+extern SCEW_API scew_list* scew_list_next (scew_list *list);
+
+/**
+ * Obtains the previous item of the given @a list item.
+ *
+ * @pre list != NULL
+ *
+ * @return the previous @a list item or NULL if @a list is the first
+ * item.
+ *
+ * @ingroup SCEWListTrav
+ */
+extern SCEW_API scew_list* scew_list_previous (scew_list *list);
+
+/**
+ * Gets the @a list item at the given @a index.
+ *
+ * @pre list != NULL
+ *
+ * @return the @a list item at @a index, or NULL if @a list does not
+ * contain sufficient items.
+ *
+ * @ingroup SCEWListSearch
+ */
+extern SCEW_API scew_list* scew_list_index (scew_list *list,
+ unsigned int index);
+
+/**
+ * Traverses all @a list items and executes the given @a hook for each
+ * item found. The hook takes an extra paramter, @a user_data, which
+ * might be NULL.
+ *
+ * @pre list != NULL
+ * @pre func != NULL
+ *
+ * @param list the list to traverse.
+ * @param hook the action to be executed for every traversed item.
+ * @param user_data an optional user data pointer (might be NULL).
+ *
+ * @ingroup SCEWListTrav
+ */
+extern SCEW_API void scew_list_foreach (scew_list *list,
+ scew_list_hook hook,
+ void *user_data);
+
+/**
+ * @defgroup SCEWListSearch Search
+ * Search for list items.
+ * @ingroup SCEWList
+ */
+
+/**
+ * Finds the first @a list item that contains @a data.
+ *
+ * @pre list != NULL
+ * @pre data != NULL
+ *
+ * @return the first @a list item that cointains @a data, or NULL if
+ * @a data is not found.
+ *
+ * @ingroup SCEWListSearch
+ */
+extern SCEW_API scew_list* scew_list_find (scew_list *list, void *data);
+
+/**
+ * Finds the first @a list item that matches the given predicate, @a
+ * hook. That is, all the @a list will be traversed calling the
+ * comparison hook for every @a list item. The comparison hook takes
+ * two parameters, the first one is the data of current traversed
+ * item, the second is @a data.
+ *
+ * @pre list != NULL
+ * @pre data != NULL
+ * @pre func != NULL
+ *
+ * @param list the list to traverse.
+ * @param data the user data to be used as one of the arguments for
+ * the comparison.
+ * @param hook the comparison function.
+ *
+ * @return the first @a list item that matches the predicate @a func,
+ * or NULL if the predicate is never true.
+ *
+ * @ingroup SCEWListSearch
+ */
+extern SCEW_API scew_list* scew_list_find_custom (scew_list *list,
+ void const *data,
+ scew_cmp_hook hook);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* LIST_H_0707122009 */
Property changes on: branches/R2_14/Externals/scew/scew/list.h
___________________________________________________________________
Added: svn:eol-style
+ native
Added: branches/R2_14/Externals/scew/scew/printer.c
===================================================================
--- branches/R2_14/Externals/scew/scew/printer.c (rev 0)
+++ branches/R2_14/Externals/scew/scew/printer.c 2010-11-01 14:59:25 UTC (rev 7402)
@@ -0,0 +1,528 @@
+/**
+ * @file printer.c
+ * @brief printer.h implementation
+ * @author Aleix Conchillo Flaque <al...@me...>
+ * @date Fri Jan 16, 2009 22:38
+ *
+ * @if copyright
+ *
+ * Copyright (C) 2003-2009 Aleix Conchillo Flaque
+ *
+ * SCEW 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.
+ *
+ * SCEW 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., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * @endif
+ **/
+
+#include "printer.h"
+
+#include "xerror.h"
+
+#include "str.h"
+
+#include <assert.h>
+
+
+/* Private */
+
+#define STR_XML_ _XT("xml")
+#define STR_VERSION_ _XT("version")
+#define STR_ENCODING_ _XT("encoding")
+#define STR_STANDALONE_ _XT("standalone")
+#define STR_YES_ _XT("yes")
+#define STR_NO_ _XT("no")
+
+enum
+ {
+ DEFAULT_INDENT_SPACES_ = 3 /**< Default number of indent spaces */
+ };
+
+struct scew_printer
+{
+ scew_bool indented;
+ unsigned int indent;
+ unsigned int spaces;
+ scew_writer *writer;
+};
+
+static scew_bool print_pi_start_ (scew_printer *printer, XML_Char const *pi);
+static scew_bool print_pi_end_ (scew_printer *printer);
+static scew_bool print_attribute_ (scew_printer *printer,
+ XML_Char const* name,
+ XML_Char const* value);
+static scew_bool print_eol_ (scew_printer *printer);
+static scew_bool print_current_indent_ (scew_printer *printer);
+static scew_bool print_next_indent_ (scew_printer *printer);
+static scew_bool print_indent_ (scew_printer *printer, unsigned int indent);
+static scew_bool print_element_start_ (scew_printer *printer,
+ scew_element const *element,
+ scew_bool *closed);
+static scew_bool print_element_end_ (scew_printer *printer,
+ scew_element const *element);
+static scew_bool print_escaped_ (scew_printer *printer,
+ XML_Char const *string);
+
+
+/* Public */
+
+scew_printer*
+scew_printer_create (scew_writer *writer)
+{
+ scew_printer *printer = NULL;
+
+ assert (writer != NULL);
+
+ printer = calloc (1, sizeof (scew_printer));
+
+ if (printer != NULL)
+ {
+ printer->writer = writer;
+
+ scew_printer_set_indented (printer, SCEW_TRUE);
+ scew_printer_set_indentation (printer, DEFAULT_INDENT_SPACES_);
+ }
+
+ return printer;
+}
+
+void
+scew_printer_free (scew_printer *printer)
+{
+ if (printer != NULL)
+ {
+ free (printer);
+ }
+}
+
+scew_writer*
+scew_printer_set_writer (scew_printer *printer, scew_writer *writer)
+{
+ scew_writer *old_writer = NULL;
+
+ assert (printer != NULL);
+ assert (writer != NULL);
+
+ old_writer = printer->writer;
+ printer->writer = writer;
+
+ return old_writer;
+}
+
+void
+scew_printer_set_indented (scew_printer *printer, scew_bool indented)
+{
+ assert (printer != NULL);
+
+ printer->indented = indented;
+}
+
+void
+scew_printer_set_indentation (scew_printer *printer, unsigned int spaces)
+{
+ assert (printer != NULL);
+
+ printer->spaces = spaces;
+}
+
+scew_bool
+scew_printer_print_tree (scew_printer *printer, scew_tree const *tree)
+{
+ scew_bool result = SCEW_TRUE;
+ XML_Char const *version = NULL;
+ XML_Char const *encoding = NULL;
+ XML_Char const *preamble = NULL;
+ scew_tree_standalone standalone = scew_tree_standalone_unknown;
+
+ assert (printer != NULL);
+ assert (tree != NULL);
+
+ version = scew_tree_xml_version (tree);
+ encoding = scew_tree_xml_encoding (tree);
+ standalone = scew_tree_xml_standalone (tree);
+ preamble = scew_tree_xml_preamble (tree);
+
+ /* Start XML declaration. */
+ result = print_pi_start_ (printer, STR_XML_);
+ result = result && print_attribute_ (printer, STR_VERSION_, version);
+
+ if (encoding)
+ {
+ result = result && print_attribute_ (printer, STR_ENCODING_, encoding);
+ }
+
+ if (result)
+ {
+ switch (standalone)
+ {
+ case scew_tree_standalone_unknown:
+ break;
+ case scew_tree_standalone_no:
+ result = print_attribute_ (printer, STR_STANDALONE_, STR_NO_);
+ break;
+ case scew_tree_standalone_yes:
+ result = print_attribute_ (printer, STR_STANDALONE_, STR_YES_);
+ break;
+ };
+ }
+
+ /* End XML declaration. */
+ result = result && print_pi_end_ (printer) && print_eol_ (printer);
+
+ /* XML preamble (DOCTYPE...). */
+ if (preamble != NULL)
+ {
+ result = result && scew_writer_write (printer->writer,
+ preamble,
+ scew_strlen (preamble));
+ result = result && print_eol_ (printer);
+ result = result && print_eol_ (printer);
+ }
+
+ /* Print XML document. */
+ result = result && scew_printer_print_element (printer,
+ scew_tree_root (tree));
+
+ if (!result)
+ {
+ scew_error_set_last_error_ (scew_error_io);
+ }
+
+ return result;
+}
+
+scew_bool
+scew_printer_print_element (scew_printer *printer, scew_element const *element)
+{
+ scew_bool result = SCEW_TRUE;
+ scew_bool closed = SCEW_TRUE;
+
+ assert (printer != NULL);
+ assert (element != NULL);
+
+ result = print_element_start_ (printer, element, &closed);
+
+ if (!closed)
+ {
+ XML_Char const *contents = scew_element_contents (element);
+
+ if (contents != NULL)
+ {
+ unsigned int children_no = scew_element_count (element);
+
+ /* Only indent contents if we have children elements. */
+ if (children_no > 0)
+ {
+ result = result && print_next_indent_ (printer);
+ }
+
+ /* Only write contents if non zero-length string. */
+ if (scew_strlen (contents) > 0)
+ {
+ result = result && print_escaped_ (printer, contents);
+ }
+
+ if (children_no > 0)
+ {
+ result = result && print_eol_ (printer);
+ }
+ }
+
+ result = result && scew_printer_print_element_children (printer,
+ element);
+ result = result && print_element_end_ (printer, element);
+ result = result && print_eol_ (printer);
+ }
+
+ if (!result)
+ {
+ scew_error_set_last_error_ (scew_error_io);
+ }
+
+ return result;
+}
+
+scew_bool
+scew_printer_print_element_children (scew_printer *printer,
+ scew_element const *element)
+{
+ unsigned int indent = 0;
+ scew_list *list = NULL;
+ scew_bool result = SCEW_TRUE;
+
+ assert (printer != NULL);
+ assert (element != NULL);
+
+ indent = printer->indent;
+
+ list = scew_element_children (element);
+ while (result && (list != NULL))
+ {
+ scew_element *child = scew_list_data (list);
+
+ printer->indent = indent + 1;
+
+ result = scew_printer_print_element (printer, child);
+ list = scew_list_next (list);
+ }
+
+ printer->indent = indent;
+
+ if (!result)
+ {
+ scew_error_set_last_error_ (scew_error_io);
+ }
+
+ return result;
+}
+
+
+scew_bool
+scew_printer_print_element_attributes (scew_printer *printer,
+ scew_element const *element)
+{
+ scew_bool result = SCEW_TRUE;
+ scew_list *list = NULL;
+
+ assert (printer != NULL);
+ assert (element != NULL);
+
+ list = scew_element_attributes (element);
+ while (result && (list != NULL))
+ {
+ scew_attribute *attribute = scew_list_data (list);
+ result = scew_printer_print_attribute (printer, attribute);
+ list = scew_list_next (list);
+ }
+
+ if (!result)
+ {
+ scew_error_set_last_error_ (scew_error_io);
+ }
+
+ return result;
+}
+
+scew_bool
+scew_printer_print_attribute (scew_printer *printer,
+ scew_attribute const *attribute)
+{
+ scew_bool result = SCEW_TRUE;
+
+ assert (printer != NULL);
+ assert (attribute != NULL);
+
+ result = print_attribute_ (printer,
+ scew_attribute_name (attribute),
+ scew_attribute_value (attribute));
+
+ if (!result)
+ {
+ scew_error_set_last_error_ (scew_error_io);
+ }
+
+ return result;
+}
+
+
+
+/* Private */
+
+scew_bool
+print_pi_start_ (scew_printer *printer, XML_Char const *pi)
+{
+ static XML_Char const *PI_START = _XT("<?");
+ scew_bool result = SCEW_FALSE;
+
+ scew_writer *writer = printer->writer;
+
+ result = scew_writer_write (writer, PI_START, scew_strlen (PI_START));
+ result = result && scew_writer_write (writer, pi, scew_strlen (pi));
+
+ return result;
+}
+
+scew_bool
+print_pi_end_ (scew_printer *printer)
+{
+ static XML_Char const *PI_END = _XT("?>");
+ scew_bool result = SCEW_FALSE;
+
+ result = scew_writer_write (printer->writer, PI_END, scew_strlen (PI_END));
+ result = result && print_eol_ (printer);
+
+ return result;
+}
+
+scew_bool
+print_attribute_ (scew_printer *printer,
+ XML_Char const* name,
+ XML_Char const* value)
+{
+ scew_bool result = SCEW_FALSE;
+
+ scew_writer *writer = printer->writer;
+
+ result = scew_writer_write (writer, _XT(" "), 1);
+ result = result && scew_writer_write (writer, name, scew_strlen (name));
+ result = result && scew_writer_write (writer, _XT("=\""), 2);
+
+ /* It is possible that an attribute's value is empty. */
+ if (scew_strlen (value) > 0)
+ {
+ result = result && print_escaped_ (printer, value);
+ }
+
+ result = result && scew_writer_write (writer, _XT("\""), 1);
+
+ return result;
+}
+
+scew_bool
+print_eol_ (scew_printer *printer)
+{
+ scew_bool result = SCEW_TRUE;
+
+ assert (printer != NULL);
+
+ if (printer->indented)
+ {
+ result = scew_writer_write (printer->writer, _XT("\n"), 1);
+ }
+
+ return result;
+}
+
+scew_bool
+print_current_indent_ (scew_printer *printer)
+{
+ return print_indent_ (printer, printer->indent);
+}
+
+scew_bool
+print_next_indent_ (scew_printer *printer)
+{
+ return print_indent_ (printer, printer->indent + 1);
+}
+
+scew_bool
+print_indent_ (scew_printer *printer, unsigned int indent)
+{
+ scew_bool result = SCEW_TRUE;
+
+ assert (printer != NULL);
+
+ if (printer->indented)
+ {
+ unsigned int i = 0;
+ unsigned int spaces = indent * printer->spaces;
+ for (i = 0; result && (i < spaces); ++i)
+ {
+ result = scew_writer_write (printer->writer, _XT(" "), 1);
+ }
+ }
+
+ return result;
+}
+
+scew_bool
+print_element_start_ (scew_printer *printer,
+ scew_element const *element,
+ scew_bool *closed)
+{
+ static XML_Char const *START = _XT("<");
+ static XML_Char const *END_1 = _XT(">");
+ static XML_Char const *END_2 = _XT("/>");
+
+ scew_list *list = NULL;
+ scew_writer *writer = NULL;
+ XML_Char const *name = NULL;
+ XML_Char const *contents = NULL;
+ scew_bool result = SCEW_TRUE;
+
+ assert (printer != NULL);
+ assert (element != NULL);
+
+ writer = printer->writer;
+
+ name = scew_element_name (element);
+
+ result = print_current_indent_ (printer);
+ result = result && scew_writer_write (writer, START, 1);
+ result = result && scew_writer_write (writer, name, scew_strlen (name));
+ result = result && scew_printer_print_element_attributes (printer, element);
+
+ contents = scew_element_contents (element);
+
+ *closed = SCEW_FALSE;
+ list = scew_element_children (element);
+ if (((NULL == contents) || (scew_strlen (contents) == 0)) && (NULL == list))
+ {
+ result = result && scew_writer_write (writer, END_2, 2);
+ result = result && print_eol_ (printer);
+ *closed = SCEW_TRUE;
+ }
+ else
+ {
+ result = result && scew_writer_write (writer, END_1, 1);
+ if (list != NULL)
+ {
+ result = result && print_eol_ (printer);
+ }
+ }
+
+ return result;
+}
+
+scew_bool
+print_element_end_ (scew_printer *printer, scew_element const *element)
+{
+ static XML_Char const *START = _XT("</");
+ static XML_Char const *END = _XT(">");
+
+ scew_writer *writer = NULL;
+ scew_bool result = SCEW_TRUE;
+
+ XML_Char const *name = scew_element_name (element);
+
+ assert (printer != NULL);
+
+ writer = printer->writer;
+
+ if (scew_element_count (element) > 0)
+ {
+ result = print_current_indent_ (printer);
+ }
+ result = result && scew_writer_write (writer, START, 2);
+ result = result && scew_writer_write (writer, name, scew_strlen (name));
+ result = result && scew_writer_write (writer, END, 1);
+
+ return result;
+}
+
+scew_bool
+print_escaped_ (scew_printer *printer, XML_Char const *string)
+{
+ scew_bool result = SCEW_TRUE;
+
+ /* Get escaped string. */
+ XML_Char *escaped = scew_strescape (string);
+
+ result = scew_writer_write (printer->writer, escaped, scew_strlen (escaped));
+
+ /* Free escaped string. */
+ free (escaped);
+
+ return result;
+}
Property changes on: branches/R2_14/Externals/scew/scew/printer.c
___________________________________________________________________
Added: svn:eol-style
+ native
Added: branches/R2_14/Externals/scew/scew/printer.h
===================================================================
--- branches/R2_14/Externals/scew/scew/printer.h (rev 0)
+++ branches/R2_14/Externals/scew/scew/printer.h 2010-11-01 14:59:25 UTC (rev 7402)
@@ -0,0 +1,256 @@
+/**
+ * @file printer.h
+ * @brief SCEW printer routines for XML output
+ * @author Aleix Conchillo Flaque <al...@me...>
+ * @date Fri Jan 16, 2009 22:34
+ * @ingroup SCEWPrinter, SCEWPrinterAlloc, SCEWPrinterProp, SCEWPrinterOutput
+ *
+ * @if copyright
+ *
+ * Copyright (C) 2009 Aleix Conchillo Flaque
+ *
+ * SCEW 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.
+ *
+ * SCEW 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., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * @endif
+ **/
+
+/**
+ * @defgroup SCEWIO Input/Output
+ *
+ * The SCEW I/O system is based on SCEW @ref SCEWReader, @ref
+ * SCEWWriter and @ref SCEWPrinter. A reader is a common mechanism to
+ * load data from different sources (files, memory, ...). A common
+ * mechanism means that the functions to read data, for example, from
+ * a file or from a memory buffer, are the same. SCEW writers follows
+ * the same idea behind the readers, that is, common routines are used
+ * to write data to any kind of sources (files, memory, ...).
+ *
+ * It is worth mentioning that a user might implement its own SCEW
+ * readers and writers.
+ *
+ * The SCEW printer provides routines to write SCEW XML data (trees,
+ * elements and attributes) to a SCEW writer.
+ */
+
+/**
+ * @defgroup SCEWPrinter Printer
+ *
+ * A SCEW printer provides a set of routines to send XML data to a
+ * given SCEW writer.
+ *
+ * @ingroup SCEWIO
+ */
+
+#ifndef PRINTER_H_0901162234
+#define PRINTER_H_0901162234
+
+#include "export.h"
+
+#include "writer.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+ * This is the type delcaration for the SCEW printer.
+ *
+ * @ingroup SCEWPrinter
+ */
+typedef struct scew_printer scew_printer;
+
+
+/**
+ * @defgroup SCEWPrinterAlloc Allocation
+ * Allocate and free printers.
+ * @ingroup SCEWPrinter
+ */
+
+/**
+ * Creates a new SCEW printer that will use the given @a writer by
+ * default. The SCEW writer will be used by the @ref SCEWPrinterOutput
+ * calls. It is possible to re-use a SCEW printer by setting a new
+ * writer via #scew_printer_set_writer.
+ *
+ * @pre writer != NULL
+ *
+ * @param writer the SCEW writer to be used by the putput functions.
+ *
+ * @return a new SCEW printer or NULL if the printer could not be
+ * created.
+ *
+ * @ingroup SCEWPrinterAlloc
+ */
+extern SCEW_API scew_printer* scew_printer_create (scew_writer *writer);
+
+/**
+ * Frees the given SCEW @a printer. This will not free the writer
+ * being used by the printer.
+ *
+ * @param printer the SCEW printer to free.
+ *
+ * @ingroup SCEWPrinterAlloc
+ */
+extern SCEW_API void scew_printer_free (scew_printer *printer);
+
+
+/**
+ * @defgroup SCEWPrinterProp Properties
+ * Set printer properties.
+ * @ingroup SCEWPrinter
+ */
+
+/**
+ * Tells whether the output sent to the given SCEW @a printer should be
+ * @a indented or not.
+ *
+ * @pre printer != NULL
+ *
+ * @param printer the SCEW printer to change its indentation for.
+ * @param indented true if the output should be indented, false
+ * otherwise.
+ *
+ * @ingroup SCEWPrinterProp
+ */
+extern SCEW_API void scew_printer_set_indented (scew_printer *printer,
+ scew_bool indented);
+
+/**
+ * Sets the number of @a spaces to use when indenting output for the
+ * given SCEW @a printer.
+ *
+ * @pre printer != NULL
+ *
+ * @param printer the SCEW printer to change its indentation spaces for.
+ * @param spaces the number of spaces to use for indentation.
+ *
+ * @ingroup SCEWPrinterProp
+ */
+extern SCEW_API void scew_printer_set_indentation (scew_printer *printer,
+ unsigned int spaces);
+
+
+/**
+ * @defgroup SCEWPrinterOutput Output
+ * A set of routines to print XML data.
+ * @ingroup SCEWPrinter
+ */
+
+/**
+ * Sets the given SCEW @a writer to the specified @a printer. After
+ * this call, subsequent calls to output functions will use the given
+ * writer internally. This means that the printer can be used to
+ * writer to a file or memory buffer indistinctly.
+ *
+ * @param printer the SCEW printer to change its writer for.
+ * @param writer the SCEW writer to be used in next...
[truncated message content] |