summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvan Jegen <s.jegen@gmail.com>2016-09-12 20:22:08 +0200
committerSilvan Jegen <s.jegen@gmail.com>2016-09-12 20:22:08 +0200
commit37390318599be0f468c3536ce3a66a168103dc0e (patch)
tree85dc64582075cc10a56fa52e1c29523fd0478c11
parent3f3d13b724e685e39f4c843719c45cabe54d7c05 (diff)
Start parsing files
And also deal with memory while doing it.
-rw-r--r--Makefile1
-rw-r--r--sxmlc.c36
2 files changed, 36 insertions, 1 deletions
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++) {