From: Ben Pfaff Date: Thu, 6 Aug 2015 07:43:07 +0000 (-0700) Subject: Work on parsing the XML heading files. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;ds=sidebyside;h=0f833bb108ef5a1d78be8ee31b2fe2855f6bd03b;p=pspp Work on parsing the XML heading files. --- diff --git a/.gitignore b/.gitignore index 790fe2c1ae..fba1fc27c1 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ spv/ unzipped/ webold/ dump +parse-xml tdump* ndump* pspp.jnl diff --git a/Makefile b/Makefile index 3172b3dddc..284a8e72fa 100644 --- 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 index 0000000000..98a4258ddb --- /dev/null +++ b/parse-all-xml @@ -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 index 0000000000..c0445052ed --- /dev/null +++ b/parse-xml.c @@ -0,0 +1,47 @@ +#include +#include +#include + +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 (" %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; +}