libports: Expat

This patch adds the "Expat" XML parser library to libports.

Fixes #245.
This commit is contained in:
Christian Prochaska 2012-06-12 19:26:17 +02:00 committed by Norman Feske
parent 7d419893f9
commit 4fc9383c31
6 changed files with 186 additions and 0 deletions

View File

@ -0,0 +1,4 @@
EXPAT_VER = 2.1.0
EXPAT = expat-$(EXPAT_VER)
REP_INC_DIR += contrib/$(EXPAT)/lib

12
libports/lib/mk/expat.mk Normal file
View File

@ -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

25
libports/ports/expat.mk Normal file
View File

@ -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)

79
libports/run/expat.run Normal file
View File

@ -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 {
<config>
<parent-provides>
<service name="ROM"/>
<service name="RAM"/>
<service name="CAP"/>
<service name="PD"/>
<service name="RM"/>
<service name="CPU"/>
<service name="LOG"/>
<service name="IO_PORT"/>
<service name="IRQ"/>
<service name="SIGNAL"/>
</parent-provides>
<default-route>
<any-service> <parent/> <any-child/> </any-service>
</default-route>
<start name="timer">
<resource name="RAM" quantum="1M"/>
<provides> <service name="Timer"/> </provides>
</start>
<start name="test-expat">
<resource name="RAM" quantum="2M"/>
<config>
<test_tag test_attribute="test_value" />
</config>
</start>
</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 :

View File

@ -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 <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#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;
}

View File

@ -0,0 +1,3 @@
TARGET = test-expat
SRC_CC = main.cc
LIBS = expat libc libc_log libc_rom