We now have half a foundation for escaping characters!
authorStefan 'psYchotic' Zwanenburg <[email protected]>
Wed, 29 Oct 2008 01:51:03 +0000 (29 02:51 +0100)
committerStefan 'psYchotic' Zwanenburg <[email protected]>
Wed, 29 Oct 2008 01:51:03 +0000 (29 02:51 +0100)
    modified:   cds.xml
    modified:   xmlparser.c
modified:   Makefile

Makefile
xmlparser.c
xmlparser.h

index 2e7f865..eb0fd40 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,12 +1,16 @@
-GLIB = `pkg-config --cflags --libs glib-2.0`
+GLIBFLAGS = `pkg-config --cflags glib-2.0`
+GLIBLIBS = `pkg-config --libs glib-2.0`
 CFLAGS += -Wall -O3
 
 .PHONY: clean
 
 all: main
 
-main: main.c xmlparser.c xmlparser.h
-       ${CC} -o xmlparser main.c xmlparser.c -Wall ${CFLAGS} ${GLIB}
+main: main.c xmlparser.h xmlparser
+       ${CC} -o xmlparser main.c xmlparser.c ${CFLAGS} ${GLIBFLAGS} ${GLIBLIBS}
+
+xmlparser: xmlparser.c xmlparser.h
+       ${CC} -c xmlparser.c ${CFLAGS} ${GLIBFLAGS}
 
 clean:
-       rm xmlparser
+       rm xmlparser xmlparser.o
index e9e4658..c1bf863 100644 (file)
@@ -12,6 +12,8 @@ XmlTag xml_tag_new(XmlTag parent) {
     tag->children = g_array_new(FALSE, FALSE, sizeof(XmlTag));
     tag->parent = parent;
     tag->value = g_string_new(NULL);
+    tag->attributes = g_malloc(sizeof(GData *));
+    g_datalist_init(tag->attributes);
 
     return tag;
 }
@@ -68,6 +70,9 @@ void xml_error(const char *message, int line, int col) {
     printf("ERROR (%d,%d): %s\n", line, col + g_string_strip(NULL) + 1, message);
 }
 
+void xml_tag_parse_attributes(XmlTag tag) {
+}
+
 XmlTag xml_parse(char *path_to_file) {
     GIOChannel *input = g_io_channel_new_file(path_to_file, "r", NULL);
     if (input == NULL) {
@@ -82,6 +87,8 @@ XmlTag xml_parse(char *path_to_file) {
     XmlTag currenttag = head;
     // Are we parsing a tag definition?
     gboolean opentag = FALSE;
+    // Is the current character escaped?
+    gboolean escape = FALSE;
     
     int i;
     int line = 1;
@@ -91,6 +98,12 @@ XmlTag xml_parse(char *path_to_file) {
         for (i = 0; i < buffer->len; i++) {
             c = buffer->str[i];
             switch (c) {
+                case '\\':
+                    if (escape) escape = FALSE;
+                    else {
+                        escape = TRUE;
+                        break;
+                    }
                 case '<':
                     if (opentag) {
                         XML_STATUS = XML_SYNTAX_ERROR;
@@ -114,10 +127,17 @@ XmlTag xml_parse(char *path_to_file) {
                             xml_error(XML_NOT_CLOSING_CURRENT, line, i-currenttag->name->len - 1);
                             return NULL;
                         }
+                        printf("Closed tag %s, going back to: %s\n", currenttag->parent->name->str, currenttag->parent->parent->name->str);
                         g_array_remove_index(currenttag->parent->children, currenttag->parent->children->len-1);
                         XmlTag temp = currenttag;
                         currenttag = temp->parent->parent;
                         xml_free_tag(temp);
+                    } else if (g_str_has_suffix(currenttag->name->str, " /")) {
+                        g_string_truncate(currenttag->name, currenttag->name->len - 2);
+                        printf("Opened and closed tag %s, going back to: %s\n", currenttag->name->str, currenttag->parent->name->str);
+                        currenttag = currenttag->parent;
+                    } else {
+                        printf("Opened tag %s, coming from: %s\n", currenttag->name->str, currenttag->parent->name->str);
                     }
                     break;
                 default:
index d92d0a6..da46eba 100644 (file)
@@ -7,6 +7,7 @@ typedef struct XmlTag {
     GArray              *children;
     GString             *value;
     struct XmlTag       *parent;
+    GData               **attributes;
 } *XmlTag;
 
 XmlTag xml_tag_new(XmlTag parent);