Work on parsing the XML heading files.
authorBen Pfaff <blp@cs.stanford.edu>
Thu, 6 Aug 2015 07:43:07 +0000 (00:43 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Thu, 6 Aug 2015 07:43:07 +0000 (00:43 -0700)
.gitignore
Makefile
parse-all-xml [new file with mode: 0755]
parse-xml.c [new file with mode: 0644]

index 790fe2c1ae8dea8faa974af1e0e663b352cb9db6..fba1fc27c19fea18a4f81dad98ff5249e8861add 100644 (file)
@@ -5,6 +5,7 @@ spv/
 unzipped/
 webold/
 dump
+parse-xml
 tdump*
 ndump*
 pspp.jnl
index 3172b3dddcd9076d47de6b8695f20e33acd24da1..284a8e72fa31a77e92c97b7c53b59328d1ea63ee 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,11 @@
-dump.o: CFLAGS = -std=gnu99 -Wall -Werror -g -D_GNU_SOURCE=1
-dump2.o: CFLAGS = -std=gnu99 -Wall -Werror -g -D_GNU_SOURCE=1 -Wno-unused
-all: dump dump2
+CFLAGS := -std=gnu99 -Wall -Werror -g -D_GNU_SOURCE=1
+base_cflags := $(CFLAGS)
+base_ldflags := $(LDFLAGS)
+parse-xml.o: CFLAGS := $(shell pkg-config --cflags libxml-2.0) $(base_cflags)
+parse-xml: LDFLAGS := $(shell pkg-config --libs libxml-2.0) $(LDFLAGS)
+dump2.o: CFLAGS := $(base_cflags) -Wno-unused
+
+all: dump dump2 parse-xml
 dump: dump.o
 dump2: dump2.o
+parse-xml: parse-xml.o
diff --git a/parse-all-xml b/parse-all-xml
new file mode 100755 (executable)
index 0000000..98a4258
--- /dev/null
@@ -0,0 +1,5 @@
+#! /bin/sh
+for d in `ls -1 unzipped/*/*.xml |grep -vE 'notes|table|warning|chart|model'`
+do
+    ./parse-xml $d
+done | sort -u
diff --git a/parse-xml.c b/parse-xml.c
new file mode 100644 (file)
index 0000000..c044505
--- /dev/null
@@ -0,0 +1,47 @@
+#include <stdio.h>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+
+static void
+print_containment (xmlNode * a_node)
+{
+  for (xmlNode *node = a_node; node; node = node->next)
+    {
+      if (node->type == XML_ELEMENT_NODE)
+        {
+          const xmlNode *parent = node->parent;
+          if (parent->type == XML_ELEMENT_NODE)
+            printf ("%s %s\n", parent->name, node->name);
+          else if (parent->type == XML_DOCUMENT_NODE)
+            printf ("<root> %s\n", node->name);
+        }
+
+      print_containment (node->children);
+    }
+}
+
+int
+main (int argc, char **argv)
+{
+  if (argc != 2)
+    {
+      fprintf (stderr, "usage: %s FILE.xml\n", argv[0]);
+      exit (1);
+    }
+
+  LIBXML_TEST_VERSION;
+
+  xmlDoc *doc = xmlReadFile(argv[1], NULL, 0);
+  if (doc == NULL)
+    {
+      fprintf (stderr, "error: could not parse file %s\n", argv[1]);
+      exit (1);
+    }
+
+  xmlNode *root = xmlDocGetRootElement(doc);
+  print_containment(root);
+  xmlFreeDoc(doc);
+  xmlCleanupParser();
+
+  return 0;
+}