Use XSLT file to open JDiveLog logs

Open JDiveLog files by translating them to subsurface format using XSLT.
These files are identified by the name of the first element (JDiveLog)
and transform is applied to only these.

The XSLT feature is compiled in only if libxslt is installed. The
transformation files are installed globally in Linux under
/usr/share/subsurface/xslt. Windows and OSX still need appropriate Makefile
changes and testing.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Miika Turkia 2011-11-05 12:39:17 +02:00 committed by Linus Torvalds
parent 4b735521e2
commit 350462949d
4 changed files with 52 additions and 3 deletions

View file

@ -5,6 +5,7 @@ CFLAGS=-Wall -Wno-pointer-sign -g
INSTALL=install INSTALL=install
PKGCONFIG=pkg-config PKGCONFIG=pkg-config
XML2CONFIG=xml2-config XML2CONFIG=xml2-config
XSLCONFIG=xslt-config
# these locations seem to work for SuSE and Fedora # these locations seem to work for SuSE and Fedora
# prefix = $(HOME) # prefix = $(HOME)
@ -15,12 +16,14 @@ DESKTOPDIR = $(DATADIR)/applications
ICONPATH = $(DATADIR)/icons/hicolor ICONPATH = $(DATADIR)/icons/hicolor
ICONDIR = $(ICONPATH)/scalable/apps ICONDIR = $(ICONPATH)/scalable/apps
MANDIR = $(DATADIR)/man/man1 MANDIR = $(DATADIR)/man/man1
XSLTDIR = $(DATADIR)/subsurface/xslt
gtk_update_icon_cache = gtk-update-icon-cache -f -t $(ICONPATH) gtk_update_icon_cache = gtk-update-icon-cache -f -t $(ICONPATH)
NAME = subsurface NAME = subsurface
ICONFILE = $(NAME).svg ICONFILE = $(NAME).svg
DESKTOPFILE = $(NAME).desktop DESKTOPFILE = $(NAME).desktop
MANFILES = $(NAME).1 MANFILES = $(NAME).1
XSLTFILES = xslt/*.xslt
MACOSXINSTALL = /Applications/Subsurface.app MACOSXINSTALL = /Applications/Subsurface.app
MACOSXFILES = packaging/macosx MACOSXFILES = packaging/macosx
@ -77,7 +80,7 @@ LIBGTK = $(shell $(PKGCONFIG) --libs gtk+-2.0 glib-2.0 gconf-2.0)
LIBDIVECOMPUTERCFLAGS = $(LIBDIVECOMPUTERINCLUDES) LIBDIVECOMPUTERCFLAGS = $(LIBDIVECOMPUTERINCLUDES)
LIBDIVECOMPUTER = $(LIBDIVECOMPUTERARCHIVE) $(LIBUSB) LIBDIVECOMPUTER = $(LIBDIVECOMPUTERARCHIVE) $(LIBUSB)
LIBS = $(LIBXML2) $(LIBGTK) $(LIBDIVECOMPUTER) -lpthread LIBS = $(LIBXML2) $(LIBXSLT) $(LIBGTK) $(LIBDIVECOMPUTER) -lpthread
OBJS = main.o dive.o profile.o info.o equipment.o divelist.o \ OBJS = main.o dive.o profile.o info.o equipment.o divelist.o \
parse-xml.o save-xml.o libdivecomputer.o print.o uemis.o \ parse-xml.o save-xml.o libdivecomputer.o print.o uemis.o \
@ -98,12 +101,26 @@ install: $(NAME)
fi fi
$(INSTALL) -d -m 755 $(MANDIR) $(INSTALL) -d -m 755 $(MANDIR)
$(INSTALL) -m 644 $(MANFILES) $(MANDIR) $(INSTALL) -m 644 $(MANFILES) $(MANDIR)
@-if test ! -z "$(XSLT)"; then \
$(INSTALL) -d -m 755 $(DATADIR)/subsurface; \
$(INSTALL) -d -m 755 $(XSLTDIR); \
$(INSTALL) -m 644 $(XSLTFILES) $(XSLTDIR); \
fi
LIBXML2 = $(shell $(XML2CONFIG) --libs) LIBXML2 = $(shell $(XML2CONFIG) --libs)
LIBXSLT = $(shell $(XSLCONFIG) --libs)
XML2CFLAGS = $(shell $(XML2CONFIG) --cflags) XML2CFLAGS = $(shell $(XML2CONFIG) --cflags)
GLIB2CFLAGS = $(shell $(PKGCONFIG) --cflags glib-2.0) GLIB2CFLAGS = $(shell $(PKGCONFIG) --cflags glib-2.0)
GCONF2CFLAGS = $(shell $(PKGCONFIG) --cflags gconf-2.0) GCONF2CFLAGS = $(shell $(PKGCONFIG) --cflags gconf-2.0)
GTK2CFLAGS = $(shell $(PKGCONFIG) --cflags gtk+-2.0) GTK2CFLAGS = $(shell $(PKGCONFIG) --cflags gtk+-2.0)
CFLAGS += $(shell $(XSLCONFIG) --cflags)
ifneq ($(strip $(LIBXSLT)),)
# We still need proper paths and install options for OSX and Windows
ifeq ($(shell sh -c 'uname -s 2>/dev/null || echo not'),Linux)
XSLT=-DXSLT='"$(XSLTDIR)"'
endif
endif
install-macosx: $(NAME) install-macosx: $(NAME)
$(INSTALL) -d -m 755 $(MACOSXINSTALL)/Contents/Resources $(INSTALL) -d -m 755 $(MACOSXINSTALL)/Contents/Resources
@ -116,7 +133,7 @@ install-macosx: $(NAME)
$(INSTALL) $(MACOSXFILES)/Subsurface.icns $(MACOSXINSTALL)/Contents/Resources/ $(INSTALL) $(MACOSXFILES)/Subsurface.icns $(MACOSXINSTALL)/Contents/Resources/
parse-xml.o: parse-xml.c dive.h parse-xml.o: parse-xml.c dive.h
$(CC) $(CFLAGS) $(GLIB2CFLAGS) -c $(XML2CFLAGS) parse-xml.c $(CC) $(CFLAGS) $(GLIB2CFLAGS) -c $(XML2CFLAGS) $(XSLT) parse-xml.c
save-xml.o: save-xml.c dive.h save-xml.o: save-xml.c dive.h
$(CC) $(CFLAGS) $(GLIB2CFLAGS) -c save-xml.c $(CC) $(CFLAGS) $(GLIB2CFLAGS) -c save-xml.c

5
dive.h
View file

@ -5,6 +5,7 @@
#include <time.h> #include <time.h>
#include <glib.h> #include <glib.h>
#include <libxml/tree.h>
/* /*
* Some silly typedefs to make our units very explicit. * Some silly typedefs to make our units very explicit.
@ -253,6 +254,10 @@ extern void parse_xml_init(void);
extern void parse_xml_file(const char *filename, GError **error); extern void parse_xml_file(const char *filename, GError **error);
extern void set_filename(const char *filename); extern void set_filename(const char *filename);
#ifdef XSLT
extern xmlDoc *test_xslt_transforms(xmlDoc *doc);
#endif
extern void show_dive_info(struct dive *); extern void show_dive_info(struct dive *);
extern void flush_dive_info_changes(struct dive *); extern void flush_dive_info_changes(struct dive *);

View file

@ -2,7 +2,8 @@ Source: subsurface
Priority: optional Priority: optional
Maintainer: Roland Dreier <roland@digitalvampire.org> Maintainer: Roland Dreier <roland@digitalvampire.org>
Build-Depends: autoconf, automake, libtool, debhelper (>= 8), dh-autoreconf, Build-Depends: autoconf, automake, libtool, debhelper (>= 8), dh-autoreconf,
pkg-config, libgtk2.0-dev, libgconf2-dev, libxml2-dev, libdivecomputer-dev pkg-config, libgtk2.0-dev, libgconf2-dev, libxml2-dev, libdivecomputer-dev,
libxslt-dev
Standards-Version: 3.9.2 Standards-Version: 3.9.2
Section: utils Section: utils
Homepage: http://subsurface.hohndel.org Homepage: http://subsurface.hohndel.org

View file

@ -7,6 +7,9 @@
#include <time.h> #include <time.h>
#include <libxml/parser.h> #include <libxml/parser.h>
#include <libxml/tree.h> #include <libxml/tree.h>
#ifdef XSLT
#include <libxslt/transform.h>
#endif
#include "dive.h" #include "dive.h"
#include "uemis.h" #include "uemis.h"
@ -1466,6 +1469,9 @@ void parse_xml_file(const char *filename, GError **error)
set_filename(filename); set_filename(filename);
reset_all(); reset_all();
dive_start(); dive_start();
#ifdef XSLT
doc = test_xslt_transforms(doc);
#endif
traverse(xmlDocGetRootElement(doc)); traverse(xmlDocGetRootElement(doc));
dive_end(); dive_end();
xmlFreeDoc(doc); xmlFreeDoc(doc);
@ -1476,3 +1482,23 @@ void parse_xml_init(void)
{ {
LIBXML_TEST_VERSION LIBXML_TEST_VERSION
} }
#ifdef XSLT
xmlDoc *test_xslt_transforms(xmlDoc *doc)
{
xmlDoc *transformed;
xsltStylesheetPtr xslt = NULL;
xmlNode *root_element = xmlDocGetRootElement(doc);
if (strcasecmp(root_element->name, "JDiveLog") == 0) {
xmlSubstituteEntitiesDefault(1);
xslt = xsltParseStylesheetFile(XSLT G_DIR_SEPARATOR_S "jdivelog2subsurface.xslt");
if (xslt == NULL)
return doc;
transformed = xsltApplyStylesheet(xslt, doc, NULL);
xmlFreeDoc(doc);
xsltFreeStylesheet(xslt);
return transformed;
}
return doc;
}
#endif