aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2011-08-28 16:58:26 -0700
committerGravatar Linus Torvalds <torvalds@linux-foundation.org>2011-08-28 16:58:26 -0700
commited45f7cb140a508b6f661f75b2c4803686b0e379 (patch)
treef4e3111113844e2a9ec44f027ae80f147dc41dd9
parent857e153070aee4383a82342a41caf0c5a0f8d700 (diff)
downloadsubsurface-ed45f7cb140a508b6f661f75b2c4803686b0e379.tar.gz
Add crazy (bad) xml parser thing
It only works for the Suunto "one xml file per dive" format, not for the libdivecomputer one that just puts many dives in one file. Maybe there is some way for libxml2 to handle concatenated xml files (start again on errors), but I don't know it yet. I need to get stinking drunk before I look at more xml mess. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--Makefile2
-rw-r--r--parse.c48
2 files changed, 50 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 000000000..fea7d03d8
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,2 @@
+parse: parse.c
+ gcc -g -o parse `xml2-config --cflags` parse.c `xml2-config --libs`
diff --git a/parse.c b/parse.c
new file mode 100644
index 000000000..6277a9021
--- /dev/null
+++ b/parse.c
@@ -0,0 +1,48 @@
+#include <stdio.h>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+
+static void show_one_node(int i, xmlNode *node)
+{
+ static const char indent[] = " ..";
+
+ if (i >= sizeof(indent))
+ i = sizeof(indent)-1;
+ printf("%.*snode '%s': %s\n", i, indent, node->name, node->content);
+}
+
+static void show(int indent, xmlNode *node)
+{
+ xmlNode *n;
+
+ for (n = node; n; n = n->next) {
+ show_one_node(indent, n);
+ show(indent+2, n->children);
+ }
+}
+
+static void parse(const char *filename)
+{
+ xmlDoc *doc;
+
+ doc = xmlReadFile(filename, NULL, 0);
+ if (!doc) {
+ fprintf(stderr, "Failed to parse '%s'.\n", filename);
+ return;
+ }
+
+ show(0, xmlDocGetRootElement(doc));
+ xmlFreeDoc(doc);
+ xmlCleanupParser();
+}
+
+int main(int argc, char **argv)
+{
+ int i;
+
+ LIBXML_TEST_VERSION
+
+ for (i = 1; i < argc; i++)
+ parse(argv[i]);
+ return 0;
+}