You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by su...@apache.org on 2008/05/15 07:04:02 UTC

svn commit: r656508 - in /webservices/axis2/trunk/c/guththila: include/guththila.h include/guththila_buffer.h include/guththila_xml_writer.h src/guththila_xml_parser.c src/guththila_xml_writer.c

Author: supun
Date: Wed May 14 22:04:02 2008
New Revision: 656508

URL: http://svn.apache.org/viewvc?rev=656508&view=rev
Log:
Added comments and code formatting for guththila_xml_writer.c and guththila_xml_parser.c and corresponding header

Modified:
    webservices/axis2/trunk/c/guththila/include/guththila.h
    webservices/axis2/trunk/c/guththila/include/guththila_buffer.h
    webservices/axis2/trunk/c/guththila/include/guththila_xml_writer.h
    webservices/axis2/trunk/c/guththila/src/guththila_xml_parser.c
    webservices/axis2/trunk/c/guththila/src/guththila_xml_writer.c

Modified: webservices/axis2/trunk/c/guththila/include/guththila.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/guththila/include/guththila.h?rev=656508&r1=656507&r2=656508&view=diff
==============================================================================
--- webservices/axis2/trunk/c/guththila/include/guththila.h (original)
+++ webservices/axis2/trunk/c/guththila/include/guththila.h Wed May 14 22:04:02 2008
@@ -34,7 +34,9 @@
 All the functions in this library does not check weather the given arguments are NULL.
 It is the responsblity of the user to check weather the arguments contain NULL values.
 */
-EXTERN_C_START()  enum guththila_status
+EXTERN_C_START()  
+
+enum guththila_status
 {
     S_0 = 0, 
 	S_1, 
@@ -70,158 +72,273 @@
 };
 
 typedef struct guththila_s
-{
+{    
+    guththila_tok_list_t tokens; /* Token cache */
 
-    guththila_tok_list_t tokens;
-
-    guththila_buffer_t buffer;
-    
-    guththila_reader_t *reader;
+    guththila_buffer_t buffer;  /* Holding incoming xml string */  
 
-    guththila_token_t *prefix;
+    guththila_reader_t *reader; /* Reading the data */
 
-    guththila_token_t *name;
+    guththila_token_t *prefix; /* Prefix of the xml element */
 
-    guththila_token_t *value;
-    
-    guththila_stack_t elem;
+    guththila_token_t *name; /* xml element local name */
 
-    guththila_stack_t attrib;
+    guththila_token_t *value; /* text of a xml element */    
 
-    guththila_stack_t namesp;
-    
-	int is_whitespace;
+    guththila_stack_t elem; /* elements are put in a stack */
 
-    int is_char;
+    guththila_stack_t attrib; /* Attributes are put in a stack */
 
-    int unicode_state;
+    guththila_stack_t namesp; /* namespaces are put in a stack */    
 
     int status;
 
-    int guththila_event;
+    int guththila_event; /* Current event */
 
-    size_t next;
+    size_t next;    /* Keep track of the position in the xml string */
 
-    int last_start;
+    int last_start; /* Keep track of the starting position of the last token */
 
-    guththila_token_t *temp_prefix;
+    guththila_token_t *temp_prefix; /* Temporery location for prefixes */
 
-    guththila_token_t *temp_name;
-
-    guththila_token_t *temp_tok;
+    guththila_token_t *temp_name;   /* Temporery location for names */
+    
+    guththila_token_t *temp_tok;   /* We don't know this until we close it */
 } guththila_t;
 
-
+/* 
+ * An element will contain one of these things if it has namespaces 
+ * */
 typedef struct guththila_elem_namesp_s
 {
-    guththila_namespace_t *namesp;
-    int no;
-    int size;    
+    guththila_namespace_t *namesp; /* Array of namespaces */
+    int no;                        /*Number of namespace in the element */
+    int size;                      /* Allocated size */
 } guththila_elem_namesp_t;
 
+/*
+ * Element.
+ */
 typedef struct guththila_element_s
 {
-    guththila_token_t *name;
+    guththila_token_t *name;    /* local name */
 
-    guththila_token_t *prefix;
+    guththila_token_t *prefix;  /* prefix */
     
-	int is_namesp;    
+	int is_namesp;              /* Positive if a namespace is present */
 } guththila_element_t;
 
+/* Initialize the parser */
 GUTHTHILA_EXPORT int GUTHTHILA_CALL
 guththila_init(guththila_t * m, void *reader, 
 			   const axutil_env_t * env);
 
-GUTHTHILA_EXPORT guththila_t * GUTHTHILA_CALL 
-guththila_create(void *reader, const axutil_env_t *env);
-
-GUTHTHILA_EXPORT void GUTHTHILA_CALL
-guththila_free(guththila_t * m, const axutil_env_t * env);
-
+/* Uninitialize the parser */
 GUTHTHILA_EXPORT int GUTHTHILA_CALL
 guththila_un_init(guththila_t * m, const axutil_env_t * env);
 
+/* Still not used */
 typedef void(GUTHTHILA_CALL * guththila_error_func)(void *arg, 
 													const guththila_char_t *msg, 
 													guththila_error_level level, 
 													void *locator);
 
-/*
-Public functions for reading XML documents
-*/
+/* 
+ * Parse the xml and return an event. If something went wrong it will return -1. 
+ * The events are of the type guththila_event_types. According to the event 
+ * user can get the required information using the appriate functions.
+ * @param g pointer to a guththila_t structure
+ * @param env the environment
+ */
 GUTHTHILA_EXPORT int GUTHTHILA_CALL
-guththila_next(guththila_t * p, const axutil_env_t * env);
+guththila_next(guththila_t * g, const axutil_env_t * env);
 
+/*
+ * Return the number of attributes in the current element. 
+ * @param g pointer to a guththila_t structure
+ * @param env the environment
+ */
 GUTHTHILA_EXPORT int GUTHTHILA_CALL
-guththila_get_attribute_count(guththila_t * p, const axutil_env_t * env);
+guththila_get_attribute_count(guththila_t * g, const axutil_env_t * env);
 
+/*
+ * Return the attribute name.
+ * @param g pointer to a guththila_t structure
+ * @param att pointer to a attribute
+ * @param env the environment
+ */
 GUTHTHILA_EXPORT guththila_char_t * GUTHTHILA_CALL
-guththila_get_attribute_name(guththila_t * p, guththila_attr_t * att, 
+guththila_get_attribute_name(guththila_t * g, guththila_attr_t * att, 
 							 const axutil_env_t * env);
 
+/*
+ * Return the attribute value.
+ * @param g pointer to a guththila_t structure
+ * @param att pointer to a attribute
+ * @param env the environment
+ */
 GUTHTHILA_EXPORT guththila_char_t * GUTHTHILA_CALL  
-guththila_get_attribute_value(guththila_t * p, 
+guththila_get_attribute_value(guththila_t * g, 
 							  guththila_attr_t * att, 
 							  const axutil_env_t * env);
 
+/*
+ * Return the attribute prefix.
+ * @param g pointer to a guththila_t structure
+ * @param att pointer to a attribute
+ * @param env the environment
+ */
 GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL  
-guththila_get_attribute_prefix(guththila_t * p, 
+guththila_get_attribute_prefix(guththila_t * g, 
 							   guththila_attr_t * att, 
 							   const axutil_env_t * env);
 
+/* 
+ * Return the attribute 
+ * @param g pointer to a guththila_t structure
+ * @param env the environment
+ */
 GUTHTHILA_EXPORT guththila_attr_t *GUTHTHILA_CALL  
-guththila_get_attribute(guththila_t * p, const axutil_env_t * env);
+guththila_get_attribute(guththila_t * g, const axutil_env_t * env);
 
+/*
+ * Return the name of the attribute by the attribute bumber. 
+ * First attribute will be 1.
+ * @param g pointer to a guththila_t structure
+ * @param index position of the attribute
+ * @param env the environment
+ */
 GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL  
-guththila_get_attribute_name_by_number(guththila_t * p, int i, 
+guththila_get_attribute_name_by_number(guththila_t * g, int index, 
 									   const axutil_env_t *env);
 
+/*
+ * Return the attribute value by number.
+ * First attribute will be 1.
+ * @param g pointer to a guththila_t structure
+ * @param index position of the attribute
+ * @param env the environment
+ */
 GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL  
-guththila_get_attribute_value_by_number(guththila_t * p, int i, 
+guththila_get_attribute_value_by_number(guththila_t * g, int index, 
 										const axutil_env_t *env);
 
+/* 
+ * Return the prefix of the attribute.
+ * First attribute will be 1.
+ * @param g pointer to a guththila_t structure
+ * @param index position of the attribute
+ * @param env the environment
+ */
 GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL  
-guththila_get_attribute_prefix_by_number(guththila_t * p, int i, 
+guththila_get_attribute_prefix_by_number(guththila_t * g, int index, 
 										 const axutil_env_t *env);
 
+/*
+ * Return the name of the element.
+ * @param g pointer to a guththila_t structure
+ * @param env the environment
+ */
 GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL  
-guththila_get_name(guththila_t * p, const axutil_env_t * env);
+guththila_get_name(guththila_t * g, const axutil_env_t * env);
 
+/*
+ * Return the prefix of the element.
+ * @param g pointer to a guththila_t structure
+ * @param env the environment
+ */
 GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL  
-guththila_get_prefix(guththila_t * p, const axutil_env_t * env);
+guththila_get_prefix(guththila_t * g, const axutil_env_t * env);
 
+/*
+ * Return the text of the element.
+ * @param g pointer to a guththila_t structure
+ * @param env the environment
+ */
 GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL  
-guththila_get_value(guththila_t * p, const axutil_env_t * env);
+guththila_get_value(guththila_t * g, const axutil_env_t * env);
 
+/*
+ * Return the namespace of the element.
+ * @param g pointer to a guththila_t structure
+ * @param env the environment
+ */
 GUTHTHILA_EXPORT guththila_namespace_t *GUTHTHILA_CALL  
-guththila_get_namespace(guththila_t * p, const axutil_env_t * env);
+guththila_get_namespace(guththila_t * g, const axutil_env_t * env);
 
+/*
+ * Return the number of namespaces in the element.
+ * @param g pointer to a guththila_t structure
+ * @param env the environment
+ */
 GUTHTHILA_EXPORT int GUTHTHILA_CALL
-guththila_get_namespace_count(guththila_t * p, const axutil_env_t * env);
+guththila_get_namespace_count(guththila_t * g, const axutil_env_t * env);
 
+/*
+ * Return the namespace uri of the given namespace.
+ * @param g pointer to a guththila_t structure
+ * @param ns pointer to a namespace
+ * @param env the environment
+ */
 GUTHTHILA_EXPORT guththila_char_t * GUTHTHILA_CALL
-guththila_get_namespace_uri(guththila_t * p, guththila_namespace_t * ns, 
+guththila_get_namespace_uri(guththila_t * g, guththila_namespace_t * ns, 
 							const axutil_env_t * env);
 
+/* 
+ * Return the prefix of the namespace.
+ * @param g pointer to a guththila_t structure
+ * @param ns pointer to a namespace
+ * @param env the environment
+ */
 GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL  
 guththila_get_namespace_prefix(guththila_t * p, guththila_namespace_t * ns, 
 							   const axutil_env_t * env);
 
+/*
+ * Return the prefix of the namespace at the given position.
+ * First namespace will have the value 1.
+ * @param g pointer to a guththila_t structure
+ * @param index position of the namespace
+ * @param env the environment
+ */
 GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL  
-guththila_get_namespace_prefix_by_number(guththila_t * p, int i, 
+guththila_get_namespace_prefix_by_number(guththila_t * g, int index, 
 										 const axutil_env_t *env);
 
+/*
+ * Get the uri of the namespace at the given position.
+ * First namespace will have the value 1.
+ * @param g pointer to a guththila_t structure
+ * @param index position of the namespace
+ * @param env the environment
+ */
 GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL  
-guththila_get_namespace_uri_by_number(guththila_t * p, int i, 
+guththila_get_namespace_uri_by_number(guththila_t * g, int index, 
 									  const axutil_env_t *env);
 
+/*
+ * Get the attribute namespace of the attribute at the given position.
+ * @param g pointer to a guththila_t structure
+ * @param index position of the namespace
+ * @param env the environment
+ */
 GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL  
-guththila_get_attribute_namespace_by_number(guththila_t *p, int i, 
+guththila_get_attribute_namespace_by_number(guththila_t *g, int index, 
 											const axutil_env_t *env);
 
+/*
+ * Get the encoding. at the moment we don't support UNICODE
+ * @param g pointer to a guththila_t structure
+ * @param env the environment
+ */
 GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL  
 guththila_get_encoding(guththila_t * p, const axutil_env_t * env);
 
+/* 
+ * To do. Implement a proper error handling mechanism.
+ * @param g pointer to a guththila_t structure
+ * @param env the environment
+ */
 GUTHTHILA_EXPORT void GUTHTHILA_CALL
 guththila_set_error_handler(guththila_t * m, guththila_error_func, 
 							const axutil_env_t * env);

Modified: webservices/axis2/trunk/c/guththila/include/guththila_buffer.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/guththila/include/guththila_buffer.h?rev=656508&r1=656507&r2=656508&view=diff
==============================================================================
--- webservices/axis2/trunk/c/guththila/include/guththila_buffer.h (original)
+++ webservices/axis2/trunk/c/guththila/include/guththila_buffer.h Wed May 14 22:04:02 2008
@@ -44,8 +44,8 @@
 }
 guththila_buffer_t;
 
-#define GUTHTHILA_BUFFER_DEF_SIZE 16984
-#define GUTHTHILA_BUFFER_NUMBER_OF_BUFFERS 4
+#define GUTHTHILA_BUFFER_DEF_SIZE 16384
+#define GUTHTHILA_BUFFER_NUMBER_OF_BUFFERS 16
 
 #ifndef GUTHTHILA_BUFFER_SIZE
 #define GUTHTHILA_BUFFER_SIZE(_buffer) (_buffer.size)

Modified: webservices/axis2/trunk/c/guththila/include/guththila_xml_writer.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/guththila/include/guththila_xml_writer.h?rev=656508&r1=656507&r2=656508&view=diff
==============================================================================
--- webservices/axis2/trunk/c/guththila/include/guththila_xml_writer.h (original)
+++ webservices/axis2/trunk/c/guththila/include/guththila_xml_writer.h Wed May 14 22:04:02 2008
@@ -119,86 +119,190 @@
 #define GUTHTHILA_XML_WRITER_NAMESP_DEF_SIZE 4
 
 /*Writer functions*/
+
+/* 
+ * Create a writer which writes to a file.
+ * @param file_name name of the file
+ * @param env pointer to the environment
+ */
 GUTHTHILA_EXPORT guththila_xml_writer_t *GUTHTHILA_CALL
 guththila_create_xml_stream_writer(
     char *file_name,
     const axutil_env_t * env);
 
+/* 
+ * Create a writer which writes to a memory buffer.
+ * @param env pointer to the environment
+ */
 GUTHTHILA_EXPORT guththila_xml_writer_t *GUTHTHILA_CALL
 guththila_create_xml_stream_writer_for_memory(
     const axutil_env_t * env);
 
+/* 
+ * Jus write what ever the content in the buffer. If the writer was in 
+ * a start of a element it will close it.
+ * @param wr pointer to the writer
+ * @param buff buffer containing the data
+ * @param size size of the buffer
+ * @param env pointer to the environment
+ */
 GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_write_to_buffer(
     guththila_xml_writer_t * wr,
     char *buff,
     int size,
     const axutil_env_t * env);
 
+/*
+ * Write the name space with the given prifix and namespace.
+ * @param wr pointer to the writer
+ * @param prefix prefix of the namespace
+ * @param uri uri of the namespace
+ * @param env pointer to the environment 
+ */
 GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_write_namespace(
     guththila_xml_writer_t * wr,
     char *prefix,
     char *uri,
     const axutil_env_t * env);
 
+/*
+ * Write the name space with the given prifix and namespace.
+ * @param wr pointer to the writer
+ * @param prefix prefix of the namespace
+ * @param uri uri of the namespace
+ * @param local_name name of the attribute
+ * @param value value of the attribute
+ * @param env pointer to the environment 
+ */
 GUTHTHILA_EXPORT int GUTHTHILA_CALL
 guththila_do_write_attribute_with_prefix_and_namespace(
     guththila_xml_writer_t * wr,
     char *prefix,
-    char *namespace_uri,
+    char *uri,
     char *local_name,
     char *value,
     const axutil_env_t * env);
 
+
+/*
+ * Write the start document element with the xml version and encoding.
+ * @param wr pointer to the writer
+ * @param env pointer to the environment 
+ * @param encoding encoding of the XML.
+ * @param version xml version
+ */
 GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_write_start_document(
     guththila_xml_writer_t * wr,
     const axutil_env_t * env,
     char *encoding,
     char *version);
 
+/*
+ * Write the start element.
+ * @param wr pointer to the writer
+ * @param name name of the element
+ * @param env pointer to the environment 
+ */
 GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_write_start_element(
     guththila_xml_writer_t * wr,
-    char *start_element,
+    char *name,
     const axutil_env_t * env);
 
+/*
+ * Write the end element. 
+ * @param wr pointer to the writer
+ * @param env pointer to the environment 
+ */
 GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_write_end_element(
     guththila_xml_writer_t * wr,
     const axutil_env_t * env);
 
+/*
+ * Not implemented.
+ * @param wr pointer to the writer
+ * @param env pointer to the environment 
+ */
 GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_close(
     guththila_xml_writer_t * wr,
     const axutil_env_t * env);
 
+/*
+ * Write the text content of a element. 
+ * @param wr pointer to the writer
+ * @param buff character string
+ * @param env pointer to the environment 
+ */
 GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_write_characters(
     guththila_xml_writer_t * wr,
     char *buff,
     const axutil_env_t * env);
 
+/*
+ * Write comment with the given text data. 
+ * @param wr pointer to the writer
+ * @param buff character string
+ * @param env pointer to the environment
+ */ 
 GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_write_comment(
     guththila_xml_writer_t * wr,
     char *buff,
     const axutil_env_t * env);
 
+/*
+ * Write scape character. 
+ * @param wr pointer to the writer
+ * @param buff character string
+ * @param env pointer to the environment
+ */ 
 GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_write_escape_character(
     guththila_xml_writer_t * wr,
     char *buff,
     const axutil_env_t * env);
 
+/*
+ * Start to write an empty element with the given name. 
+ * @param wr pointer to the writer
+ * @param name name of the element
+ * @param env pointer to the environment
+ */ 
 GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_write_empty_element(
     guththila_xml_writer_t * wr,
-    char *empty_element,
+    char *name,
     const axutil_env_t * env);
 
+/*
+ * Write a defualt namespace. 
+ * @param wr pointer to the writer
+ * @param uri uri of the namespace
+ * @param env pointer to the environment
+ */ 
 GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_write_default_namespace(
     guththila_xml_writer_t * wr,
-    char *namespace_uri,
+    char *uri,
     const axutil_env_t * env);
 
+/*
+ * Write a attribute with the given name and value. 
+ * @param wr pointer to the writer
+ * @param localname name of the attribute
+ * @param value value of the attribute
+ * @param env pointer to the environment
+ */ 
 GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_write_attribute(
     guththila_xml_writer_t * wr,
     char *localname,
     char *value,
     const axutil_env_t * env);
 
+/*
+ * Write a attribute with the given name and value and namespace. 
+ * @param wr pointer to the writer
+ * @param prefix prefix of the attribute
+ * @param namespace_uri uri of the namespace
+ * @param localname name of the attribute
+ * @param value value of the attribute
+ * @param env pointer to the environment
+ */ 
 GUTHTHILA_EXPORT int GUTHTHILA_CALL
 guththila_write_attribute_with_prefix_and_namespace(
     guththila_xml_writer_t * wr,
@@ -208,6 +312,15 @@
     char *value,
     const axutil_env_t * env);
 
+/*
+ * Write a attribute with the given name, value and prefix. If the prefix 
+ * is not defined previously as a namespace this method will fail. 
+ * @param wr pointer to the writer
+ * @param prefix prefix of the attribute
+ * @param localname name of the attribute
+ * @param value value of the attribute
+ * @param env pointer to the environment
+ */ 
 GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_write_attribute_with_prefix(
     guththila_xml_writer_t * wr,
     char *prefix,
@@ -215,6 +328,17 @@
     char *value,
     const axutil_env_t * env);
 
+/*
+ * Write a attribute with the given name, value and namespace uri.  
+ * If the namespace is not defined previously as a namespace this 
+ * method will fail. The prefix corresponding to the namespace uri 
+ * will be used. 
+ * @param wr pointer to the writer
+ * @param namesp namespace uri
+ * @param localname name of the attribute
+ * @param value value of the attribute
+ * @param env pointer to the environment
+ */ 
 GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_write_attribute_with_namespace(
     guththila_xml_writer_t * wr,
     char *namesp,
@@ -222,6 +346,15 @@
     char *value,
     const axutil_env_t * env);
 
+/*
+ * Write a start element with prefix and namespace. If the namespace is not 
+ * defined previoully new namespace will be written. 
+ * @param wr pointer to the writer
+ * @param prefix prefix of the attribute
+ * @param namespace_uri uri
+ * @param localname name of the attribute
+ * @param env pointer to the environment
+ */ 
 GUTHTHILA_EXPORT int GUTHTHILA_CALL
 guththila_write_start_element_with_prefix_and_namespace(
     guththila_xml_writer_t * wr,
@@ -230,6 +363,14 @@
     char *local_name,
     const axutil_env_t * env);
 
+/*
+ * Write a start element with the namespace. If the namespace is not 
+ * defined previously method will fail. 
+ * @param wr pointer to the writer
+ * @param namespace_uri uri
+ * @param localname name of the attribute
+ * @param env pointer to the environment
+ */ 
 GUTHTHILA_EXPORT int GUTHTHILA_CALL
 guththila_write_start_element_with_namespace(
     guththila_xml_writer_t * wr,
@@ -237,6 +378,14 @@
     char *local_name,
     const axutil_env_t * env);
 
+/*
+ * Write a start element with the prefix. If the prefix is not 
+ * defined previously method will fail. 
+ * @param wr pointer to the writer
+ * @param namespace_uri uri
+ * @param localname name of the attribute
+ * @param env pointer to the environment
+ */ 
 GUTHTHILA_EXPORT int GUTHTHILA_CALL
 guththila_write_start_element_with_prefix(
     guththila_xml_writer_t * wr,
@@ -244,6 +393,15 @@
     char *local_name,
     const axutil_env_t * env);
 
+/*
+ * Write a empty element with prefix and namespace. If the namespace is not 
+ * defined previoully new namespace will be written. 
+ * @param wr pointer to the writer
+ * @param prefix prefix of the attribute
+ * @param namespace_uri uri
+ * @param localname name of the attribute
+ * @param env pointer to the environment
+ */ 
 GUTHTHILA_EXPORT int GUTHTHILA_CALL
 guththila_write_empty_element_with_prefix_and_namespace(
     guththila_xml_writer_t * wr,
@@ -252,6 +410,14 @@
     char *local_name,
     const axutil_env_t * env);
 
+/*
+ * Write a empty element with the namespace. If the namespace is not 
+ * defined previously method will fail. 
+ * @param wr pointer to the writer
+ * @param namespace_uri uri
+ * @param localname name of the attribute
+ * @param env pointer to the environment
+ */ 
 GUTHTHILA_EXPORT int GUTHTHILA_CALL
 guththila_write_empty_element_with_namespace(
     guththila_xml_writer_t * wr,
@@ -259,6 +425,14 @@
     char *local_name,
     const axutil_env_t * env);
 
+/*
+ * Write a empty element with the prefix. If the prefix is not 
+ * defined previously method will fail. 
+ * @param wr pointer to the writer
+ * @param namespace_uri uri
+ * @param localname name of the attribute
+ * @param env pointer to the environment
+ */ 
 GUTHTHILA_EXPORT int GUTHTHILA_CALL
 guththila_write_empty_element_with_prefix(
     guththila_xml_writer_t * wr,
@@ -266,50 +440,68 @@
     char *local_name,
     const axutil_env_t * env);
 
+/*
+ * Close all the elements that were started by writing the end elements.
+ * @param wr pointer to the writer
+ * @param env pointer to the environment
+ */ 
 GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_write_end_document(
     guththila_xml_writer_t * wr,
     const axutil_env_t * env);
-
+/* 
+ * Write a new element with the name, then write the characters as text, 
+ * then close the element and write a new line.
+ * @param wr pointer to the writer
+ * @element_name name of the element
+ * @characters text of the new element
+ * @param env pointer to the environment
+ */
 GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_write_line(
     guththila_xml_writer_t * wr,
     char *element_name,
     char *characters,
     const axutil_env_t * env);
 
+/*
+ * Get the memory buffer that is written.  
+ * @param wr pointer to the writer
+ * @param env pointer to the environment
+ * @return memory buffer
+ */
 GUTHTHILA_EXPORT char *GUTHTHILA_CALL guththila_get_memory_buffer(
     guththila_xml_writer_t * wr,
     const axutil_env_t * env);
 
+/*
+ * Get the size of the memory buffer. 
+ * @param wr pointer to the writer
+ * @param env pointer to the environment
+ * @return size of the buffer
+ */
 GUTHTHILA_EXPORT unsigned int GUTHTHILA_CALL
 guththila_get_memory_buffer_size(
     guththila_xml_writer_t * wr,
     const axutil_env_t * env);
 
+/*
+ * Free the writer. 
+ * @param wr pointer to the writer
+ * @param env pointer to the environment
+ */
 GUTHTHILA_EXPORT void GUTHTHILA_CALL guththila_xml_writer_free(
     guththila_xml_writer_t * wr,
     const axutil_env_t * env);
-
+/*
+ * Get the prefix for the namespace.
+ * @param wr pointer to the writer
+ * @namespace namespace uri
+ * @param env pointer to the environment
+ * @return prefix for the namspace uri
+ */
 GUTHTHILA_EXPORT char *GUTHTHILA_CALL guththila_get_prefix_for_namespace(
     guththila_xml_writer_t * wr,
     char *namespace,
     const axutil_env_t * env);
 
-int GUTHTHILA_CALL guththila_write(
-    guththila_xml_writer_t * wr,
-    char *buff,
-    size_t buff_size,
-    const axutil_env_t * env);
-
-int GUTHTHILA_CALL guththila_write_token(
-    guththila_xml_writer_t * wr,
-    guththila_token_t * tok,
-    const axutil_env_t * env);
-
-int GUTHTHILA_CALL guththila_write_xtoken(
-    guththila_xml_writer_t * wr,
-    char *buff,
-    size_t buff_len,
-    const axutil_env_t * env);
-
 EXTERN_C_END()
 #endif

Modified: webservices/axis2/trunk/c/guththila/src/guththila_xml_parser.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/guththila/src/guththila_xml_parser.c?rev=656508&r1=656507&r2=656508&view=diff
==============================================================================
--- webservices/axis2/trunk/c/guththila/src/guththila_xml_parser.c (original)
+++ webservices/axis2/trunk/c/guththila/src/guththila_xml_parser.c Wed May 14 22:04:02 2008
@@ -25,9 +25,15 @@
     
 #define GUTHTHILA_VALIDATION_PARSER
 
+/*
+ * Read the next char from the reader and return it.
+ */
 static int  
 guththila_next_char(guththila_t * m,int eof,const axutil_env_t * env);
 
+/*
+ * Read the specified number of characters at once.
+ */
 static int  
 guththila_next_no_char( 
     guththila_t * m,
@@ -36,6 +42,9 @@
     size_t no,
     const axutil_env_t * env);
 
+/*
+ * Close a token that is opened previously. 
+ */
 static void 
 guththila_token_close(
     guththila_t * m,
@@ -44,16 +53,24 @@
     int referer,
     const axutil_env_t * env);
 
+/* 
+ * Process the XMl declaration part of a XML document.
+ */
 static int 
 guththila_process_xml_dec(
     guththila_t * m,
     const axutil_env_t * env);
 
+/* 
+ * Read characters until all the white spaces are read.
+ */
 #ifndef GUTHTHILA_SKIP_SPACES
 #define GUTHTHILA_SKIP_SPACES(m, c, _env)while(0x20 == c || 0x9 == c || 0xD == c || 0xA == c){c = guththila_next_char(m, 0, _env);}
-
 #endif  
     
+/*
+ * Read character including new line until a non white space character is met.
+ */
 #ifndef GUTHTHILA_SKIP_SPACES_WITH_NEW_LINE
 #define GUTHTHILA_SKIP_SPACES_WITH_NEW_LINE(m, c, _env) while (0x20 == c || 0x9 == c || 0xD == c || 0xA == c || '\n' == c){c = guththila_next_char(m, 0, _env);}
 #endif  
@@ -66,10 +83,17 @@
 #define GUTHTHILA_XML_URI "http://www.w3.org/XML/1998/namespace"
 #endif    
 
+/* 
+ * Return the last character that was read
+ */
 #ifndef GUTHTHILA_LAST_CHAR
 #define GUTHTHILA_LAST_CHAR(m) (m->buffer.buff + m->buffer.next - 1)
 #endif  
-    
+
+/*
+ * Open a token. When we open a token we don't know it's type. We only 
+ * set the starting values.
+ */
 #ifndef GUTHTHILA_TOKEN_OPEN
 #define GUTHTHILA_TOKEN_OPEN(m, tok, _env)					\
     m->temp_tok = guththila_tok_list_get_token(&m->tokens, _env); \
@@ -79,6 +103,9 @@
 /* We are sure that the difference lies within the int range */
 #endif  
     
+/*
+ * Read until we met a = character.
+ */
 #ifndef GUTHTHILA_PROCESS_EQU
 #define GUTHTHILA_PROCESS_EQU(m, c, ic, _env)							\
     GUTHTHILA_SKIP_SPACES(m, c, _env); \
@@ -88,6 +115,9 @@
     }
 #endif  
     
+/*
+ * Initialize a attribute to the values given.
+ */
 #ifndef GUTHTHILA_ATTRIBUTE_INITIALIZE
 #define GUTHTHILA_ATTRIBUTE_INITIALIZE(_attr, _pref, _name, _val)	\
     (_attr->pref = (_pref)); \
@@ -95,24 +125,39 @@
     (_attr->val = (_val));
 #endif  
     
+/*
+ * Initialize namespace to the values given.
+ */
 #ifndef GUTHTHILA_NAMESPACE_INITIALIZE
 #define GUTHTHILA_NAMESPACE_INITIALIZE(_namesp, _name, _uri)	\
     (_namesp->name = _name); \
     (_namesp->uri = _uri);
 #endif  
     
+/*
+ * Return non zero value if the given argument is a space.
+ */
 #ifndef GUTHTHILA_IS_SPACE
 #define GUTHTHILA_IS_SPACE(c) (0x20 == c || 0xD == c || 0xA == c || 0x9 == c)     
 #endif  
     
+/*
+ * Deterine weather a given character is a valid xml string char.
+ */
 #ifndef GUTHTHILA_IS_VALID_STRING_CHAR
 #define GUTHTHILA_IS_VALID_STRING_CHAR(c) (isalpha(c) || '_' == c || ':' == c)
 #endif 
-    
+
+/*
+ * Determine weahter a given character is a valid starting char for a xml name.
+ */    
 #ifndef GUTHTHILA_IS_VALID_STARTING_CHAR
 #define GUTHTHILA_IS_VALID_STARTING_CHAR(c) (isalpha(c) || '_' == c || ':' == c)
 #endif 
 
+/*
+ * Initialize the variables in the guththila_t structure.
+ */
 #ifndef GUTHTHILA_VARIABLE_INITIALZE
 #define GUTHTHILA_VARIABLE_INITIALZE(m) \
     m->temp_prefix = NULL; \
@@ -124,6 +169,10 @@
     m->value = NULL;
 #endif 
 
+/*
+ * Initialize the guththila_t structure with the reader. 
+ * All the values will be set to default values. 
+ */
 GUTHTHILA_EXPORT int GUTHTHILA_CALL
 guththila_init(guththila_t * m, void *reader, const axutil_env_t * env) 
 {
@@ -161,9 +210,8 @@
                                       1,0,0,env);
 
     }
-
   
-  e_namesp = (guththila_elem_namesp_t *) AXIS2_MALLOC(env->allocator,
+    e_namesp = (guththila_elem_namesp_t *) AXIS2_MALLOC(env->allocator,
                                                         sizeof(guththila_elem_namesp_t));
     if (e_namesp && temp_tok && temp_name)
     {
@@ -211,153 +259,11 @@
     return GUTHTHILA_SUCCESS;
 }
 
-GUTHTHILA_EXPORT guththila_t * GUTHTHILA_CALL
-guththila_create(void *reader,const axutil_env_t *env) 
-{
-    guththila_t * m =
-        (guththila_t *) AXIS2_MALLOC(env->allocator, sizeof(guththila_t *));
-    if (!m)
-        return NULL;
-    m->reader = (guththila_reader_t *) reader;
-    if (!guththila_tok_list_init(&m->tokens, env))
-    {
-        AXIS2_FREE(env->allocator, m);
-        return NULL;
-    }
-    if (m->reader->type == GUTHTHILA_MEMORY_READER)
-    {
-        guththila_buffer_init_for_buffer(&m->buffer, m->reader->buff,
-                                          m->reader->buff_size, env);
-    }
-    else if (m->reader->type == GUTHTHILA_FILE_READER || m->reader->type == GUTHTHILA_IO_READER)
-    {
-        guththila_buffer_init(&m->buffer, 0, env);
-    }
-    guththila_stack_init(&m->elem, env);
-    guththila_stack_init(&m->attrib, env);
-    guththila_stack_init(&m->namesp, env);
-    m->name = NULL;
-    m->prefix = NULL;
-    m->value = NULL;
-    m->status = S_1;
-    m->guththila_event = -1;
-    m->next = 0;
-    m->last_start = -1;
-    m->temp_name = NULL;
-    m->temp_prefix = NULL;
-    m->temp_tok = NULL;
-    return m;
-}
-
-GUTHTHILA_EXPORT void GUTHTHILA_CALL
-guththila_free(guththila_t * m, const axutil_env_t * env) 
-{
-  int size = 0, i = 0, j = 0;
-    guththila_attr_t * attr = NULL;
-    guththila_element_t* elem = NULL;
-    guththila_elem_namesp_t * e_namesp = NULL;
-
-    if (m->prefix)
-    {
-        guththila_tok_list_release_token(&m->tokens, m->prefix, env);
-    }
-    if (m->name)
-    {
-        guththila_tok_list_release_token(&m->tokens, m->name, env);
-    }
-    if (m->value)
-    {
-        guththila_tok_list_release_token(&m->tokens, m->value, env);
-    }
-    if (m->temp_tok)
-    {
-        guththila_tok_list_release_token(&m->tokens, m->temp_tok, env);
-    }
-    if (m->temp_name)
-    {
-        guththila_tok_list_release_token(&m->tokens, m->temp_name, env);
-    }
-    if (m->temp_prefix)
-    {
-        guththila_tok_list_release_token(&m->tokens, m->temp_prefix, env);
-    }
-
-    size = GUTHTHILA_STACK_SIZE(m->attrib);
-
-    for (i = 0; i < size; i++)
-    {
-        attr = (guththila_attr_t *) guththila_stack_pop(&m->attrib, env);
-        if (attr)
-        {
-            if (attr->name)
-                guththila_tok_list_release_token(&m->tokens, attr->name, env);
-            if (attr->pref)
-                guththila_tok_list_release_token(&m->tokens, attr->pref, env);
-                AXIS2_FREE(env->allocator, attr);
-        }
-    }
-    guththila_stack_un_init(&m->attrib, env);
-    size = GUTHTHILA_STACK_SIZE(m->elem);
-    for (i = 0; i < size; i++)
-    {
-        elem =
-            (guththila_element_t *) guththila_stack_pop(&m->elem, env);
-        if (elem)
-        {
-            if (elem->name)
-                guththila_tok_list_release_token(&m->tokens, elem->name, env);
-            if (elem->prefix)
-                guththila_tok_list_release_token(&m->tokens, elem->prefix, env);
-            AXIS2_FREE(env->allocator, elem);
-        }
-    }
-    guththila_stack_un_init(&m->elem,env);
-#ifndef GUTHTHILA_VALIDATION_PARSER
-    guththila_namespace_t * namesp = NULL;
-
-    size = GUTHTHILA_STACK_SIZE(m->namesp);
-    for (i = 0; i < size; i++)
-    {
-        namesp =
-            (guththila_namespace_t *) guththila_stack_pop(&m->namesp, env);
-        if (namesp)
-        {
-            if (namesp->name)
-                guththila_tok_list_release_token(&m->tokens, namesp->name, env);
-            if (namesp->uri)
-                guththila_tok_list_release_token(&m->tokens, namesp->uri, env);
-            AXIS2_FREE(env->allocator, namesp);
-        }
-    }
-#else  /*   */
-    
-    size = GUTHTHILA_STACK_SIZE(m->namesp);
-    for (i = 0; i < size; i++)
-    {
-        e_namesp =
-            (guththila_elem_namesp_t *) guththila_stack_pop(&m->namesp, env);
-        for (j = 0; j < e_namesp->no; j++)
-        {
-            if(e_namesp->namesp[j].name)
-            {
-                guththila_tok_list_release_token(&m->tokens,e_namesp->namesp[j].name,env);
-            }
-			if(e_namesp->namesp[j].uri)
-            {
-                guththila_tok_list_release_token(&m->tokens,e_namesp->namesp[j].uri, env);
-            }
-        }
-        AXIS2_FREE(env->allocator, e_namesp->namesp);
-        AXIS2_FREE(env->allocator, e_namesp);
-    }
-#endif  
-    guththila_stack_un_init(&m->namesp, env);
-    guththila_tok_list_free_data(&m->tokens, env);
-    guththila_buffer_un_init(&m->buffer, env);
-    AXIS2_FREE(env->allocator, m);
-    return;
-}
 
+/*
+ * Uninitialize a guththila_t structure. This method deallocates all the 
+ * resources that are held in the guththila_t structure.
+ */
 GUTHTHILA_EXPORT int GUTHTHILA_CALL
 guththila_un_init(guththila_t * m,const axutil_env_t * env) 
 {
@@ -471,6 +377,9 @@
     return GUTHTHILA_SUCCESS;
 }
 
+/* 
+ * Replace the references with the corresponding actual values.
+ */ 
 static void
 guththila_token_evaluate_references(guththila_token_t * tok)
 {
@@ -555,6 +464,9 @@
     }
 }
 
+/*
+ * Close a token. This method accepts the type of the token as a parameter.
+ */
 static void 
 guththila_token_close(guththila_t * m, guththila_token_t * tok, 
 					  int tok_type, int referer, 
@@ -588,6 +500,7 @@
         break;
     case _attribute_value:
         guththila_token_evaluate_references(m->temp_tok);
+        /* Chech weather we are at a xml namespace declaration */
         if ((m->temp_prefix && (guththila_tok_str_cmp(m->temp_prefix, "xmlns", 5u, env) == 0)) ||
             (guththila_tok_str_cmp(m->temp_name, "xmlns", 5u, env) == 0))
             /*checks inside the m->temp_name to parse the default namespace*/
@@ -601,6 +514,7 @@
             guththila_stack_push(&m->namesp, namesp);            
 #else   
             elem = (guththila_element_t *)guththila_stack_peek(&m->elem, env);
+            /* This is the first namespace */
             if (elem && !elem->is_namesp)
             {
                 e_namesp = (guththila_elem_namesp_t *) AXIS2_MALLOC(env->allocator,
@@ -625,10 +539,12 @@
                         e_namesp = NULL;
                     }
                 }
-            }            
+            }     
+            /* Already there is a namespace */       
             else if (elem && elem->is_namesp)
             {
                 e_namesp = (guththila_elem_namesp_t *)guththila_stack_peek(&m->namesp, env);
+                /* if we have enough space allocated */
 				if (e_namesp->no < e_namesp->size)
 				{
 					e_namesp->namesp[e_namesp->no].name = m->temp_name;
@@ -658,10 +574,10 @@
                 }
             }            
 #endif  
-        }
-        
+        }        
         else
         {
+            /* It is just a attribute */
             attr = (guththila_attr_t *) AXIS2_MALLOC(env->allocator,
                                                   sizeof(guththila_attr_t));           
 
@@ -696,6 +612,7 @@
     guththila_elem_namesp_t *e_namesp = NULL;
 
     size = GUTHTHILA_STACK_SIZE(m->attrib);
+    /* Loop through all the attributes */
     for (i = 0; i < size; i++)
     {
         guththila_attr_t *attr =
@@ -703,6 +620,7 @@
                         guththila_stack_get_by_index(&m->attrib, i, env);
         if (attr && attr->pref)
         {
+            /* We have a attribute prefix. Need to validate the prefix */
             nmsp_no = GUTHTHILA_STACK_SIZE(m->namesp);
             for (j = nmsp_no - 1; j >= 0; j--)
             {
@@ -722,9 +640,10 @@
             }                                            
             if (!namesp_found) return GUTHTHILA_FAILURE;
         }
-    }    
+    }
+    /* If the element has a prefix. Need to validate the prefix*/    
     if (m->prefix)
-    {
+    {        
         namesp_found = AXIS2_FALSE;
         nmsp_no = GUTHTHILA_STACK_SIZE(m->namesp);
         for (j = nmsp_no - 1; j >= 0; j--)
@@ -755,16 +674,12 @@
     guththila_element_t * elem = NULL;
     guththila_elem_namesp_t * nmsp = NULL;
     guththila_token_t * tok = NULL;
-    int quote = 0,
-        ref = 0;
+    int quote = 0, ref = 0;
     guththila_char_t c_arra[16] = { 0 };
     int c = -1;
     guththila_attr_t * attr = NULL;
-    int size = 0,
-        i = 0,
-        nmsp_counter,
-        loop = 0,
-        white_space = 0;
+    int size = 0, i = 0, nmsp_counter, loop = 0, white_space = 0;
+    /* Need to release the resources for attributes */
     size = GUTHTHILA_STACK_SIZE(m->attrib);
     for (i = 0; i < size; i++)
     {
@@ -781,7 +696,8 @@
     GUTHTHILA_VARIABLE_INITIALZE(m);
     
 #ifdef GUTHTHILA_VALIDATION_PARSER
-        if (m->guththila_event == GUTHTHILA_EMPTY_ELEMENT)
+    /* If the previous event was a empty element we need to do some clean up */
+    if (m->guththila_event == GUTHTHILA_EMPTY_ELEMENT)
     {
         elem = (guththila_element_t *) guththila_stack_pop(&m->elem, env);
         if (elem->is_namesp)
@@ -807,10 +723,11 @@
             guththila_tok_list_release_token(&m->tokens, elem->name, env);
         if (elem->prefix)
             guththila_tok_list_release_token(&m->tokens, elem->prefix, env);
-            AXIS2_FREE(env->allocator, elem);
+        AXIS2_FREE(env->allocator, elem);
     }
     
 #endif  
+    /* Actual XML parsing logic */
     do
     {
         loop = 0;
@@ -837,6 +754,7 @@
             c = guththila_next_char(m, 0, env);
             if (c != '?' && c != '!' && c != '/')
             {
+                /* We are at the beginig of a xml element */
                 if (GUTHTHILA_IS_VALID_STARTING_CHAR(c))
                 {
                     GUTHTHILA_TOKEN_OPEN(m, tok, env);
@@ -851,14 +769,14 @@
                         }                       
                         else
                         {
+                            /* We know for sure that this is a prefix */
                             guththila_token_close(m, tok, _prefix, 0, env);
                             c = guththila_next_char(m, 0, env);
                             GUTHTHILA_TOKEN_OPEN(m, tok, env);
                         }
-                    }
-                    
-                    guththila_token_close(m, tok, _name, 0, env);
-                    
+                    }        
+                    /* XML element name */            
+                    guththila_token_close(m, tok, _name, 0, env);                    
 #ifdef GUTHTHILA_VALIDATION_PARSER		
                     elem =
                        (guththila_element_t *) AXIS2_MALLOC(env->allocator,
@@ -866,13 +784,14 @@
                     elem->name = m->name;
                     elem->prefix = m->prefix;
                     elem->is_namesp = 0;
-                    guththila_stack_push(&m->elem, elem, env);
-                    
+                    guththila_stack_push(&m->elem, elem, env);                    
 #endif  
                 }
                 GUTHTHILA_SKIP_SPACES(m, c, env);
+                /* Process the attributes */
                 for (;;)
                 {
+                    /* Empty element */
                     if (c == '/')
                     {
                         c = guththila_next_char(m, 0, env);
@@ -887,14 +806,17 @@
                             return -1;
                         }
                     }
+                    /* Normal element */
                     else if (c == '>')
                     {
                         m->guththila_event = GUTHTHILA_START_ELEMENT;
                         if (!guththila_validate_namespaces(m, env)) return -1;
                         else return GUTHTHILA_START_ELEMENT;
                     }
+                    /* We are in the middle of a element */
                     else if (c != -1)
                     {
+                        /* Process the attributes */
                         if (GUTHTHILA_IS_VALID_STARTING_CHAR(c))
                         {
                             GUTHTHILA_TOKEN_OPEN(m, tok, env);
@@ -910,18 +832,21 @@
                                 }
                                 else if (c == ':')
                                 {
+                                    /* Prefix */
                                     guththila_token_close(m, tok, _prefix, 0,
                                                            env);
                                     c = guththila_next_char(m, 0, env);
                                     GUTHTHILA_TOKEN_OPEN(m, tok, env);
                                 }
                             }
+                            /* Attribute name*/
                             guththila_token_close(m, tok, _attribute_name, 0,env);
                         }
                         else
                         {
                             return -1;
                         }
+                        /* Attribute Value */
                         GUTHTHILA_PROCESS_EQU(m, c, quote, env);
                         if ('\'' == quote || '\"' == quote)
                         {
@@ -951,6 +876,7 @@
             }
             else if (c == '/')
             {
+                /* End Element */
                 m->guththila_event = GUTHTHILA_END_ELEMENT;
                 c = guththila_next_char(m, -1, env);
                 if (GUTHTHILA_IS_VALID_STARTING_CHAR(c))
@@ -967,15 +893,17 @@
                         }
                         else
                         {
+                            /* Prefix */
                             guththila_token_close(m, tok, _prefix, 0, env);
                             c = guththila_next_char(m, 0, env);
                             GUTHTHILA_TOKEN_OPEN(m, tok, env);
                         }
                     }
+                    /* name */
                     guththila_token_close(m, tok, _name, 0, env);
                     
 #ifdef GUTHTHILA_VALIDATION_PARSER	
-                        elem =
+                    elem =
                         (guththila_element_t *) guththila_stack_pop(&m->elem,env);
                     if (!elem || (!elem->prefix && m->prefix) ||
                          (elem->prefix && !m->prefix))
@@ -989,6 +917,7 @@
                     {
                         return -1;
                     }
+                    /* Releasing the namespace related resources */
                     if (elem->is_namesp)
                     {
                         nmsp =
@@ -1012,14 +941,14 @@
                         AXIS2_FREE(env->allocator, nmsp->namesp);
                         AXIS2_FREE(env->allocator, nmsp);
                     }
+                    /* Release the tokens */
                     if (elem->name)
                         guththila_tok_list_release_token(&m->tokens, elem->name,env);
                     if (elem->prefix)
                         guththila_tok_list_release_token(&m->tokens,elem->prefix, env);
-                        AXIS2_FREE(env->allocator, elem);
-                    
+                    AXIS2_FREE(env->allocator, elem);                    
 #endif  
-                        GUTHTHILA_SKIP_SPACES(m, c, env);
+                    GUTHTHILA_SKIP_SPACES(m, c, env);
                     if (c != '>')
                         return -1;
                     return GUTHTHILA_END_ELEMENT;
@@ -1028,6 +957,7 @@
             }
             else if (c == '!')
             {
+                /* Comment */
                 if (2 == guththila_next_no_char(m, 0, c_arra, 2, env) &&
                      '-' == c_arra[0] && '-' == c_arra[1])
                 {
@@ -1050,8 +980,7 @@
                                     guththila_token_close(m, tok, _char_data,0, env);
                                     m->next = m->next + 2;
                                     return GUTHTHILA_COMMENT;
-                                }
-                                
+                                }                                
                                 else
                                 {
                                     return -1;
@@ -1072,6 +1001,7 @@
             }
             else if (c == '?')
             {
+                /* XML declaration */
                 c = guththila_process_xml_dec(m, env);
                 if (c != -1)
                     return GUTHTHILA_START_DOCUMENT;               
@@ -1081,10 +1011,10 @@
         }
         else if (c != '<' && m->status == S_2 && c != -1)
         {
+            /* Text */
             m->guththila_event = GUTHTHILA_CHARACTER;
             if (!GUTHTHILA_IS_SPACE(c))
-                white_space = 0;
-            
+                white_space = 0;            
             else
                 white_space = 1;
             GUTHTHILA_TOKEN_OPEN(m, tok, env);
@@ -1128,6 +1058,7 @@
     return c;
 }
 
+/* Process the XML declaration */
 static int 
 guththila_process_xml_dec(
     guththila_t * m,
@@ -1229,6 +1160,7 @@
     }
     return c;
 }
+
 GUTHTHILA_EXPORT int GUTHTHILA_CALL
 guththila_get_attribute_count(
     guththila_t * m,
@@ -1466,7 +1398,7 @@
         }
     }
     
-#else   /*  */
+#else   
     guththila_elem_namesp_t * nmsp = NULL;
     if (((guththila_element_t *) guththila_stack_peek(&m->elem, env))->is_namesp)
     {
@@ -1486,8 +1418,7 @@
     guththila_t * m, int i,
     const axutil_env_t *env) 
 {
-    guththila_char_t *str = NULL;    
-    /*TODO check the given index, this can begn from 1, here I assume begin from 0 */ 
+    guththila_char_t *str = NULL;         
 #ifndef GUTHTHILA_VALIDATION_PARSER
     if (GUTHTHILA_STACK_SIZE(m->namesp) >= i)
     {
@@ -1565,6 +1496,7 @@
     return "UTF-8";
 }
 
+/* Return the next character */
 static int 
 guththila_next_char(guththila_t * m, int eof, const axutil_env_t * env) 
 {
@@ -1572,6 +1504,9 @@
     size_t temp, data_move, i;
     guththila_char_t **temp1;
     size_t * temp2, *temp3;
+    /* we have a buffered reader. Easiest case just fetch the character from 
+     * the buffer. Here we have a single buffer. 
+     * */
     if (m->reader->type == GUTHTHILA_MEMORY_READER &&
          m->next < GUTHTHILA_BUFFER_CURRENT_DATA_SIZE(m->buffer))
     {
@@ -1581,11 +1516,12 @@
     else if (m->reader->type == GUTHTHILA_IO_READER ||
              m->reader->type == GUTHTHILA_FILE_READER)
     {
-        
+        /* comlex stuff. We have a array of buffers */  
         if ( m->buffer.cur_buff != -1 && 
              m->next < GUTHTHILA_BUFFER_PRE_DATA_SIZE(m->buffer) +
              GUTHTHILA_BUFFER_CURRENT_DATA_SIZE(m->buffer))
         {
+            /* What we are looking for is already in the buffer */
             c = m->buffer.buff[m->buffer.cur_buff][m->next++ -
                                                     GUTHTHILA_BUFFER_PRE_DATA_SIZE
                                                     (m->buffer)];
@@ -1598,6 +1534,7 @@
             /* We are sure that the difference lies within the int range */
             if (m->buffer.cur_buff == (int)m->buffer.no_buffers - 1)
             {
+                /* we are out of allocated buffers. Need to allocate more buffers */
                 temp = m->buffer.no_buffers * 2;
                 temp1 =
                     (guththila_char_t **) AXIS2_MALLOC(env->allocator,
@@ -1634,6 +1571,9 @@
             m->buffer.buffs_size[m->buffer.cur_buff] =
                 m->buffer.buffs_size[m->buffer.cur_buff - 1] * 2;
             m->buffer.data_size[m->buffer.cur_buff] = 0;
+            /* We need to have the content for one token in a single buffer. 
+             * So if the space is not sufficient we have to move first part 
+             * of the token to the next buffer */
             if (m->last_start != -1)
             {
                 data_move =
@@ -1665,6 +1605,7 @@
                                                     (m->buffer)];
             return c >= 0 ? c : -1;
         }
+        /* Initial stage. We dont' have the array of buffers allocated*/
         else if (m->buffer.cur_buff == -1)
         {
             m->buffer.buff[0] =
@@ -1683,6 +1624,9 @@
     return -1;
 }
 
+/* Same functionality as the guththila_next_char. But insted of reading 
+ * one character this function reads several characters at once 
+ * */ 
 static int 
 guththila_next_no_char(guththila_t * m, int eof, 
 					   guththila_char_t *bytes, 

Modified: webservices/axis2/trunk/c/guththila/src/guththila_xml_writer.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/guththila/src/guththila_xml_writer.c?rev=656508&r1=656507&r2=656508&view=diff
==============================================================================
--- webservices/axis2/trunk/c/guththila/src/guththila_xml_writer.c (original)
+++ webservices/axis2/trunk/c/guththila/src/guththila_xml_writer.c Wed May 14 22:04:02 2008
@@ -110,6 +110,31 @@
 	} 
 #endif*/ 
 
+/* 
+ * Write the contents of the buff in to the guththila_xml_writer buffer. 
+ * len indicates the number of items in the buff.
+ */
+int GUTHTHILA_CALL guththila_write(
+    guththila_xml_writer_t * wr,
+    char *buff,
+    size_t buff_size,
+    const axutil_env_t * env);
+
+/* 
+ * Same functionality as the guththila_write only difference is here we are given 
+ * a token to write, not a buffer.
+ */
+int GUTHTHILA_CALL guththila_write_token(
+    guththila_xml_writer_t * wr,
+    guththila_token_t * tok,
+    const axutil_env_t * env);
+
+int GUTHTHILA_CALL guththila_write_xtoken(
+    guththila_xml_writer_t * wr,
+    char *buff,
+    size_t buff_len,
+    const axutil_env_t * env);
+
 GUTHTHILA_EXPORT guththila_xml_writer_t * GUTHTHILA_CALL 
 guththila_create_xml_stream_writer(guththila_char_t *file_name,
                                    const axutil_env_t * env) 
@@ -220,6 +245,7 @@
     {
         remain_len = wr->buffer.buffs_size[wr->buffer.cur_buff] -
                      wr->buffer.data_size[wr->buffer.cur_buff];
+        /* We have space */
         if (buff_len < remain_len)
         {
             memcpy(wr->buffer.buff[wr->buffer.cur_buff] +
@@ -240,6 +266,7 @@
             /* We are sure that the difference lies within the int range */
             if (((int)wr->buffer.no_buffers - 1) == wr->buffer.cur_buff)
             {
+                /* Out of allocated array buffers. Need to allocate*/
                 wr->buffer.no_buffers = wr->buffer.no_buffers * 2;
                 temp3 = (guththila_char_t **) AXIS2_MALLOC(env->allocator,
                          sizeof(guththila_char_t *) * wr->buffer.no_buffers);
@@ -266,6 +293,7 @@
             {
                 temp = temp * 2;
             }
+            /* Create a be buffer */
             wr->buffer.buff[wr->buffer.cur_buff] =
                 (guththila_char_t *) AXIS2_MALLOC(env->allocator, sizeof(guththila_char_t) * temp);
             wr->buffer.buffs_size[wr->buffer.cur_buff] = temp;
@@ -285,6 +313,7 @@
     return GUTHTHILA_FAILURE;
 }
 
+
 int GUTHTHILA_CALL
 guththila_write_token(guththila_xml_writer_t * wr, guththila_token_t * tok,
                         const axutil_env_t * env) 
@@ -500,19 +529,22 @@
                                    sizeof(guththila_xml_writer_element_t));
     len = strlen(start_element);
     if (wr->status == START)
-    {
+    {   
+        /* If we are in a start we need to close and start */
         guththila_write(wr, "><", 2u, env);
         cur_pos = wr->next;
         guththila_write_xtoken(wr, start_element, len, env);
     }
     else if (wr->status == START_EMPTY)
     {
+        /* We need to close and start */
         guththila_write(wr, "/><", 3u, env);
         cur_pos = wr->next;
         guththila_write_xtoken(wr, start_element, len, env);
     }
     else if (wr->status == BEGINING)
     {
+        /* We can start rightaway*/
         guththila_write(wr, "<", 1u, env);
         cur_pos = wr->next;
         guththila_write_xtoken(wr, start_element, len, env);
@@ -546,6 +578,7 @@
     if (wr->status == START)
     {
         guththila_write(wr, "></", 3u, env);
+        /* Write the contents of the element at the top */
         elem =
             (guththila_xml_writer_element_t *) guththila_stack_pop(&wr->element, env);
         if (elem)
@@ -847,6 +880,7 @@
     guththila_token_t ** tok_name = NULL, **tok_uri = NULL;
     size_t pref_len = strlen(prefix), uri_len = strlen(uri);
     stack_size = GUTHTHILA_STACK_SIZE(wr->namesp);
+    /* Check weather we have met the namespace before */
     for (i = stack_size - 1; i >= 0; i--)
     {
         writer_namesp =
@@ -869,6 +903,7 @@
             }
         }
     }
+    /* Proceed if we didn't find the namespace */    
     if (!nmsp_found && (wr->status == START || wr->status == START_EMPTY))
     {
         guththila_write(wr, " xmlns:", 7u, env);
@@ -1066,7 +1101,9 @@
     size_t pref_len = strlen(prefix);
     guththila_xml_writer_namesp_t * writer_namesp = NULL;
     if (wr->status == START || wr->status == START_EMPTY)
-    {
+    {   
+        /* We need to make sure that there is a namespace defined with the 
+         * given prefix as the name */
         for (i = stack_size - 1; i >= 0; i--)
         {
             writer_namesp =
@@ -1115,6 +1152,7 @@
     guththila_xml_writer_namesp_t * writer_namesp = NULL;
     if (wr->status == START || wr->status == START_EMPTY)
     {
+        /* We need to make sure that the namespace is previously declared */
         for (i = stack_size - 1; i >= 0; i--)
         {
             writer_namesp = (guththila_xml_writer_namesp_t *)
@@ -1173,6 +1211,7 @@
     pref_len = strlen(prefix);
     elem_len = strlen(local_name);
     stack_size = GUTHTHILA_STACK_SIZE(wr->namesp);
+    /* We have to determine weather we have seen the namespace before */
     for (i = stack_size - 1; i >= 0; i--)
     {
         writer_namesp =
@@ -1267,8 +1306,9 @@
         }
         if (!nmsp_found)
         {
-	    namesp =
-        	(guththila_xml_writer_namesp_t *) AXIS2_MALLOC(env->allocator,
+            /* If this namespace not defined previously we need to add it */
+	        namesp =
+        	    (guththila_xml_writer_namesp_t *) AXIS2_MALLOC(env->allocator,
                                                    sizeof
                                                    (guththila_xml_writer_namesp_t));	
             
@@ -1464,7 +1504,7 @@
         temp = writer_namesp->no;
         for (j = 0; j < temp; j++)
         {
-            
+            /* if we found a namespace with the given prefix we can proceed */
 #ifndef GUTHTHILA_XML_WRITER_TOKEN
             if (!strcmp(prefix, writer_namesp->name[j]))
             {                
@@ -1562,6 +1602,7 @@
     pref_len = strlen(prefix);
     elem_len = strlen(local_name);
     stack_size = GUTHTHILA_STACK_SIZE(wr->namesp);
+    /* Chech weather we have defined this namespace before */
     for (i = stack_size - 1; i >= 0; i--)
     {
         writer_namesp =
@@ -1656,7 +1697,7 @@
         }
         if (!nmsp_found)
         {
-            
+            /* If the namespace is not defined we need to remember it for later*/
 #ifndef GUTHTHILA_XML_WRITER_TOKEN
             namesp->name =
                 (guththila_char_t **) AXIS2_MALLOC(env->allocator,
@@ -1845,7 +1886,7 @@
         temp = writer_namesp->no;
         for (j = 0; j < temp; j++)
         {
-            
+            /* Proceed if we found the namespace */
 #ifndef GUTHTHILA_XML_WRITER_TOKEN
             if (!strcmp(prefix, writer_namesp->name[j]))
             {                
@@ -1907,6 +1948,7 @@
 #endif  
                 wr->status = START_EMPTY;
                 element->name_sp_stack_no = -1;
+                /* remember the element */
                 return guththila_stack_push(&wr->element, element, env);
             }
         }
@@ -1923,6 +1965,7 @@
     int size = GUTHTHILA_STACK_SIZE(wr->element);
     if (wr->status == START_EMPTY)
         guththila_write_end_element(wr, env);
+    /* For all the open elements in the element stack close them */
     for (i = 0; i < size; i++)
     {
         if (!guththila_write_end_element(wr, env))
@@ -2011,6 +2054,7 @@
     int size,
     const axutil_env_t * env) 
 {
+    /* Just write what ever given. But need to close things before */
     if(wr->status == START)
     {
         guththila_write(wr,">", 1u, env);



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org