From 4fc9383c317b61d3f8de9c7c56fbd710de23c43f Mon Sep 17 00:00:00 2001 From: Christian Prochaska Date: Tue, 12 Jun 2012 19:26:17 +0200 Subject: [PATCH] libports: Expat This patch adds the "Expat" XML parser library to libports. Fixes #245. --- libports/lib/import/import-expat.mk | 4 ++ libports/lib/mk/expat.mk | 12 +++++ libports/ports/expat.mk | 25 +++++++++ libports/run/expat.run | 79 +++++++++++++++++++++++++++++ libports/src/test/expat/main.cc | 63 +++++++++++++++++++++++ libports/src/test/expat/target.mk | 3 ++ 6 files changed, 186 insertions(+) create mode 100644 libports/lib/import/import-expat.mk create mode 100644 libports/lib/mk/expat.mk create mode 100644 libports/ports/expat.mk create mode 100644 libports/run/expat.run create mode 100644 libports/src/test/expat/main.cc create mode 100644 libports/src/test/expat/target.mk diff --git a/libports/lib/import/import-expat.mk b/libports/lib/import/import-expat.mk new file mode 100644 index 000000000..199a14e66 --- /dev/null +++ b/libports/lib/import/import-expat.mk @@ -0,0 +1,4 @@ +EXPAT_VER = 2.1.0 +EXPAT = expat-$(EXPAT_VER) + +REP_INC_DIR += contrib/$(EXPAT)/lib diff --git a/libports/lib/mk/expat.mk b/libports/lib/mk/expat.mk new file mode 100644 index 000000000..7a68d7427 --- /dev/null +++ b/libports/lib/mk/expat.mk @@ -0,0 +1,12 @@ +include $(REP_DIR)/lib/import/import-expat.mk + +EXPAT_DIR = $(REP_DIR)/contrib/$(EXPAT) +LIBS += libc + +SRC_C = xmlparse.c xmlrole.c xmltok.c + +CC_OPT += -DHAVE_MEMMOVE -DXML_NS=1 -DXML_DTD=1 -DXML_CONTEXT_BYTES=1024 + +vpath %.c $(EXPAT_DIR)/lib + +SHARED_LIB = yes diff --git a/libports/ports/expat.mk b/libports/ports/expat.mk new file mode 100644 index 000000000..badd12361 --- /dev/null +++ b/libports/ports/expat.mk @@ -0,0 +1,25 @@ +include lib/import/import-expat.mk + +EXPAT_TGZ = $(EXPAT).tar.gz +EXPAT_URL = http://sourceforge.net/projects/expat/files/expat/$(EXPAT_VER)/$(EXPAT_TGZ) + +# +# Interface to top-level prepare Makefile +# +PORTS += $(EXPAT) + +prepare-expat: $(CONTRIB_DIR)/$(EXPAT) + +$(CONTRIB_DIR)/$(EXPAT):clean-expat + +# +# Port-specific local rules +# +$(DOWNLOAD_DIR)/$(EXPAT_TGZ): + $(VERBOSE)wget -c -P $(DOWNLOAD_DIR) $(EXPAT_URL) && touch $@ + +$(CONTRIB_DIR)/$(EXPAT): $(DOWNLOAD_DIR)/$(EXPAT_TGZ) + $(VERBOSE)tar xfz $< -C $(CONTRIB_DIR) && touch $@ + +clean-expat: + $(VERBOSE)rm -rf $(CONTRIB_DIR)/$(EXPAT) diff --git a/libports/run/expat.run b/libports/run/expat.run new file mode 100644 index 000000000..6b11a2bb6 --- /dev/null +++ b/libports/run/expat.run @@ -0,0 +1,79 @@ +# +# \brief Test for using the expat library +# \author Christian Prochaska +# \date 2012-06-12 +# + +# +# Build +# + +build { core init drivers/timer test/expat } + +create_boot_directory + +# +# Generate config +# + +install_config { + + + + + + + + + + + + + + + + + + + + + + + + + + + +} + +# +# Boot modules +# + +build_boot_image { + core init timer + ld.lib.so libc.lib.so libc_log.lib.so libc_rom.lib.so expat.lib.so + test-expat +} + +# +# Execute test case +# + +append qemu_args " -nographic -m 64" + +run_genode_until {.*child exited with exit value 0.*} 5 + +grep_output {\[init -> test-expat\] } + +compare_output_to { + [init -> test-expat] start of element: config + [init -> test-expat] start of element: test_tag + [init -> test-expat] attribute: name='test_attribute', value='test_value' + [init -> test-expat] end of element: test_tag + [init -> test-expat] end of element: config +} + +puts "\nTest succeeded\n" + +# vi: set ft=tcl : diff --git a/libports/src/test/expat/main.cc b/libports/src/test/expat/main.cc new file mode 100644 index 000000000..d6da98d2a --- /dev/null +++ b/libports/src/test/expat/main.cc @@ -0,0 +1,63 @@ +/* + * \brief Expat test + * \author Christian Prochaska + * \date 2012-06-12 + */ + +/* + * Copyright (C) 2012 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#include +#include +#include +#include + +#include "expat.h" + + +static void start_element(void *userdata, const char *name, const char **attr) +{ + printf(" start of element: %s\n", name); + + for (int i = 0; attr[i]; i += 2) + printf(" attribute: name='%s', value='%s'\n", attr[i], attr[i + 1]); +} + + +static void end_element(void *userdata, const char *name) +{ + printf(" end of element: %s\n", name); +} + + +int main(int argc, char *argv[]) +{ + char buf[128]; + + XML_Parser parser = XML_ParserCreate(NULL); + XML_SetElementHandler(parser, start_element, end_element); + + int config_fd = open("config", O_RDONLY); + + if (config_fd < 0) { + printf(" Error: could not open config file\n"); + return -1; + } + + read(config_fd, buf, sizeof(buf)); + + if (XML_Parse(parser, buf, strlen(buf), 1) == XML_STATUS_ERROR) { + printf(" Error: %s at line %lu\n", + XML_ErrorString(XML_GetErrorCode(parser)), + XML_GetCurrentLineNumber(parser)); + return -1; + } + + XML_ParserFree(parser); + + return 0; +} diff --git a/libports/src/test/expat/target.mk b/libports/src/test/expat/target.mk new file mode 100644 index 000000000..a7f3bd92c --- /dev/null +++ b/libports/src/test/expat/target.mk @@ -0,0 +1,3 @@ +TARGET = test-expat +SRC_CC = main.cc +LIBS = expat libc libc_log libc_rom