Author: miguel
Date: 2006-10-18 22:47:43 -0400 (Wed, 18 Oct 2006)
New Revision: 66808

Modified:
   trunk/mono/eglib/src/gmarkup.c
   trunk/mono/eglib/test/markup.c
Log:
Small improvements, but it still fails with the machine.config



Modified: trunk/mono/eglib/src/gmarkup.c
===================================================================
--- trunk/mono/eglib/src/gmarkup.c      2006-10-18 22:11:45 UTC (rev 66807)
+++ trunk/mono/eglib/src/gmarkup.c      2006-10-19 02:47:43 UTC (rev 66808)
@@ -50,7 +50,8 @@
        TEXT,
        FLUSH_TEXT,
        CLOSING_ELEMENT,
-       COMMENT
+       COMMENT,
+       SKIP_XML_DECLARATION
 } ParseState;
 
 struct _GMarkupParseContext {
@@ -117,7 +118,8 @@
                return end;
        }
        start = ++p;
-       for (++p; p < end && *p != '"'; p++)
+       for (; p < end && *p != '"'; p++)
+               ;
        if (p == end)
                return end;
        l = p - start;
@@ -151,7 +153,7 @@
 }
 
 static const char *
-parse_attributes (const char *p, const char *end, char ***names, char 
***values, GError **error, int *full_stop)
+parse_attributes (const char *p, const char *end, char ***names, char 
***values, GError **error, int *full_stop, int state)
 {
        int nnames = 0;
 
@@ -164,6 +166,11 @@
                        *full_stop = 0;
                        return p; 
                }
+               if (state == SKIP_XML_DECLARATION && *p == '?' && ((p+1) < end) 
&& *(p+1) == '>'){
+                       *full_stop = 0;
+                       return p+1;
+               }
+               
                if (*p == '/' && ((p+1) < end && *(p+1) == '>')){
                        *full_stop = 1;
                        return p+1;
@@ -244,13 +251,17 @@
                        if (c == ' ' || c == '\t' || c == '\f' || c == '\n')
                                continue;
                        if (c == '<'){
-                               context->state = START_ELEMENT;
+                               if (p+1 < end && p [1] == '?'){
+                                       context->state = SKIP_XML_DECLARATION;
+                                       p++;
+                               } else
+                                       context->state = START_ELEMENT;
                                continue;
                        }
                        set_error ("Expected < to start the document");
                        goto fail;
 
-
+               case SKIP_XML_DECLARATION:
                case START_ELEMENT: {
                        const char *element_start = p, *element_end;
                        char *ename = NULL;
@@ -289,7 +300,7 @@
                                set_error ("Unfinished element");
                                goto fail;
                        }
-                       p = parse_attributes (p, end, &names, &values, error, 
&full_stop);
+                       p = parse_attributes (p, end, &names, &values, error, 
&full_stop, context->state);
                        if (p == end){
                                if (names != NULL) {
                                        g_strfreev (names);
@@ -306,13 +317,14 @@
                                goto fail;
                        strncpy (ename, element_start, l);
                        ename [l] = 0;
-                       
-                       if (context->parser.start_element != NULL)
-                               context->parser.start_element (context, ename,
-                                                              (const gchar **) 
names,
-                                                              (const gchar **) 
values,
-                                                              
context->user_data, error);
 
+                       if (context->state == START_ELEMENT)
+                               if (context->parser.start_element != NULL)
+                                       context->parser.start_element (context, 
ename,
+                                                                      (const 
gchar **) names,
+                                                                      (const 
gchar **) values,
+                                                                      
context->user_data, error);
+
                        if (names != NULL){
                                g_strfreev (names);
                                g_strfreev (values);
@@ -324,7 +336,7 @@
                        }
                        
                        if (full_stop){
-                               if (context->parser.end_element != NULL){
+                               if (context->parser.end_element != NULL &&  
context->state == START_ELEMENT){
                                        context->parser.end_element (context, 
ename, context->user_data, error);
                                        if (error != NULL && *error != NULL){
                                                free (ename);
@@ -361,7 +373,7 @@
                                p += 2;
                                break;
                        }
-
+                       break;
                        
                case FLUSH_TEXT:
                        if (context->parser.text != NULL){
@@ -387,6 +399,7 @@
                                set_error ("Too many closing tags, not enough 
open tags");
                                goto fail;
                        }
+                       
                        text = current->data;
                        if (context->parser.end_element != NULL){
                                context->parser.end_element (context, text, 
context->user_data, error);

Modified: trunk/mono/eglib/test/markup.c
===================================================================
--- trunk/mono/eglib/test/markup.c      2006-10-18 22:11:45 UTC (rev 66807)
+++ trunk/mono/eglib/test/markup.c      2006-10-19 02:47:43 UTC (rev 66808)
@@ -201,11 +201,32 @@
 
 }
 
+RESULT
+xml_parse (void)
+{
+       return markup_test ("<?xml version=\"1.0\" 
encoding=\"utf-8\"?><a></a>");
+}
+
+RESULT
+machine_config (void)
+{
+       char *data;
+       gsize size;
+       
+       if (g_file_get_contents ("../../data/net_1_1/machine.config", &data, 
&size, NULL)){
+               return markup_test (data);
+       }
+       printf ("Ignoring this test\n");
+       return NULL;
+}
+
 static Test markup_tests [] = {
        {"invalid_documents", invalid_documents},
        {"good_documents", valid_documents},
        {"mono_domain", mono_domain},
        {"mcs_config", mcs_config},
+       {"xml_parse", xml_parse},
+       {"machine_config", machine_config},
        {NULL, NULL}
 };
 

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to