From 37390318599be0f468c3536ce3a66a168103dc0e Mon Sep 17 00:00:00 2001 From: Silvan Jegen Date: Mon, 12 Sep 2016 20:22:08 +0200 Subject: Start parsing files And also deal with memory while doing it. --- Makefile | 1 + sxmlc.c | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e621e95..a33f93a 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,7 @@ debug: $(CC) $(CFLAGS) -g -lmxml -pthread -o mxml mxml.c $(CC) $(CFLAGS) -g -o ezxml ezxml.c ezxmllib.o $(CC) $(CFLAGS) -g -o yxml yxml.c yxmllib.o + $(CC) $(CFLAGS) -g -o sxmlc sxmlc.c sxmlclib.o .c.o: $(CC) $(CFLAGS) -c -o $@ $< diff --git a/sxmlc.c b/sxmlc.c index 1bbf13c..6272a22 100644 --- a/sxmlc.c +++ b/sxmlc.c @@ -4,11 +4,45 @@ #include "sxmlclib.h" int process(char *fn) { + XMLDoc *doc = malloc(sizeof(XMLDoc)); + if (!doc) { + fprintf(stderr, "Could not allocate memory for the XMLDoc when trying to parse %s.\n", fn); + exit(1); + } + + XMLDoc_init(doc); + + int ret = XMLDoc_parse_file_DOM(fn, doc); + if (!ret) { + fprintf(stderr, "Error when parsing file '%s'.\n", fn); + return 1; + } + + if (doc->i_root < 0) { + fprintf(stderr, "i_root was negative. Skipping file '%s'.\n", fn); + return 1; + } + + XMLNode *root = doc->nodes[doc->i_root]; + if (!root) { + fprintf(stderr, "Root was NULL. Exiting.\n"); + return 1; + } + //get_article_title(root); + + fprintf(stderr, "root is '%s'.\n", root->tag); + + - printf("\n"); + XMLDoc_free(doc); return 0; } +XMLNode* get_article_title(XMLNode *root) { + + return root; +} + int main(int argc, char *argv[]) { for (int i = 1; i < argc; i++) { -- cgit v1.2.3