summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Tardon <dtardon@redhat.com>2015-03-04 15:46:07 +0100
committerDavid Tardon <dtardon@redhat.com>2015-03-04 15:56:14 +0100
commit7f34f7ad051c09cab67618c9d05583a7880725ec (patch)
tree028da4e9adf7e9f68394f32713ed4e114ea0a15b /src
create new project
Diffstat (limited to 'src')
-rw-r--r--src/.gitignore2
-rw-r--r--src/Makefile.am13
-rw-r--r--src/conv/.gitignore3
-rw-r--r--src/conv/Makefile.am5
-rw-r--r--src/conv/raw/.gitignore9
-rw-r--r--src/conv/raw/Makefile.am40
-rw-r--r--src/conv/raw/xar2raw.cpp89
-rw-r--r--src/conv/raw/xar2raw.rc.in31
-rw-r--r--src/conv/svg/.gitignore9
-rw-r--r--src/conv/svg/Makefile.am40
-rw-r--r--src/conv/svg/xar2svg.cpp81
-rw-r--r--src/conv/svg/xar2svg.rc.in31
-rw-r--r--src/lib/.gitignore9
-rw-r--r--src/lib/Makefile.am49
-rw-r--r--src/lib/XaraDocument.cpp45
-rw-r--r--src/lib/libxara.rc.in31
-rw-r--r--src/lib/libxara_utils.cpp244
-rw-r--r--src/lib/libxara_utils.h161
-rw-r--r--src/test/.gitignore10
-rw-r--r--src/test/Makefile.am27
-rw-r--r--src/test/test.cpp46
21 files changed, 975 insertions, 0 deletions
diff --git a/src/.gitignore b/src/.gitignore
new file mode 100644
index 0000000..c038ed7
--- /dev/null
+++ b/src/.gitignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in \ No newline at end of file
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000..12e3fc8
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,13 @@
+## -*- Mode: make; tab-width: 4; indent-tabs-mode: tabs -*-
+
+SUBDIRS = lib
+
+if WITH_TOOLS
+SUBDIRS += conv
+endif
+
+if WITH_TESTS
+SUBDIRS += test
+endif
+
+## vim:set shiftwidth=4 tabstop=4 noexpandtab:
diff --git a/src/conv/.gitignore b/src/conv/.gitignore
new file mode 100644
index 0000000..8f1b0d9
--- /dev/null
+++ b/src/conv/.gitignore
@@ -0,0 +1,3 @@
+Makefile
+Makefile.in
+*.o
diff --git a/src/conv/Makefile.am b/src/conv/Makefile.am
new file mode 100644
index 0000000..a34f5a1
--- /dev/null
+++ b/src/conv/Makefile.am
@@ -0,0 +1,5 @@
+## -*- Mode: make; tab-width: 4; indent-tabs-mode: tabs -*-
+
+SUBDIRS = raw svg
+
+## vim:set shiftwidth=4 tabstop=4 noexpandtab:
diff --git a/src/conv/raw/.gitignore b/src/conv/raw/.gitignore
new file mode 100644
index 0000000..75e5a18
--- /dev/null
+++ b/src/conv/raw/.gitignore
@@ -0,0 +1,9 @@
+.deps
+.libs
+*.lo
+*.la
+Makefile
+Makefile.in
+xar2raw
+xar2raw.exe
+xar2raw.rc
diff --git a/src/conv/raw/Makefile.am b/src/conv/raw/Makefile.am
new file mode 100644
index 0000000..9bc61fc
--- /dev/null
+++ b/src/conv/raw/Makefile.am
@@ -0,0 +1,40 @@
+## -*- Mode: make; tab-width: 4; indent-tabs-mode: tabs -*-
+
+bin_PROGRAMS = xar2raw
+
+AM_CXXFLAGS = \
+ -I$(top_srcdir)/inc \
+ $(REVENGE_CFLAGS) \
+ $(REVENGE_GENERATORS_CFLAGS) \
+ $(REVENGE_STREAM_CFLAGS) \
+ $(BOOST_CFLAGS) \
+ $(DEBUG_CXXFLAGS)
+
+xar2raw_DEPENDENCIES = @XAR2RAW_WIN32_RESOURCE@
+xar2raw_LDADD = \
+ ../../lib/libxara-@XARA_MAJOR_VERSION@.@XARA_MINOR_VERSION@.la \
+ $(REVENGE_LIBS) \
+ $(REVENGE_GENERATORS_LIBS) \
+ $(REVENGE_STREAM_LIBS) \
+ @XAR2RAW_WIN32_RESOURCE@
+
+xar2raw_SOURCES = xar2raw.cpp
+
+if OS_WIN32
+
+@XAR2RAW_WIN32_RESOURCE@ : xar2raw.rc $(xar2raw_OBJECTS)
+ chmod +x $(top_srcdir)/build/win32/*compile-resource && \
+ WINDRES=@WINDRES@ $(top_srcdir)/build/win32/lt-compile-resource xar2raw.rc @XAR2RAW_WIN32_RESOURCE@
+
+endif
+
+# Include the xar2raw_SOURCES in case we build a tarball without stream
+EXTRA_DIST = \
+ $(xar2raw_SOURCES) \
+ xar2raw.rc.in
+
+# These may be in the builddir too
+BUILD_EXTRA_DIST = \
+ xar2raw.rc
+
+## vim:set shiftwidth=4 tabstop=4 noexpandtab:
diff --git a/src/conv/raw/xar2raw.cpp b/src/conv/raw/xar2raw.cpp
new file mode 100644
index 0000000..6627d30
--- /dev/null
+++ b/src/conv/raw/xar2raw.cpp
@@ -0,0 +1,89 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the libxara project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include <boost/shared_ptr.hpp>
+
+#include <librevenge/librevenge.h>
+#include <librevenge-generators/librevenge-generators.h>
+#include <librevenge-stream/librevenge-stream.h>
+
+#include <libxara/libxara.h>
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifndef VERSION
+#define VERSION "UNKNOWN VERSION"
+#endif
+
+namespace
+{
+
+int printUsage()
+{
+ printf("Usage: xar2raw [OPTION] <Document>\n");
+ printf("\n");
+ printf("Options:\n");
+ printf("--callgraph Display the call graph nesting level\n");
+ printf("--help Shows this help message\n");
+ printf("--version Output xar2raw version \n");
+ return -1;
+}
+
+int printVersion()
+{
+ printf("xar2raw %s\n", VERSION);
+ return 0;
+}
+
+} // anonymous namespace
+
+using libxara::XaraDocument;
+
+int main(int argc, char *argv[])
+{
+ bool printIndentLevel = false;
+ char *file = 0;
+
+ if (argc < 2)
+ return printUsage();
+
+ for (int i = 1; i < argc; i++)
+ {
+ if (!strcmp(argv[i], "--callgraph"))
+ printIndentLevel = true;
+ else if (!strcmp(argv[i], "--version"))
+ return printVersion();
+ else if (!file && strncmp(argv[i], "--", 2))
+ file = argv[i];
+ else
+ return printUsage();
+ }
+
+ if (!file)
+ return printUsage();
+
+ boost::shared_ptr<librevenge::RVNGInputStream> input(new librevenge::RVNGFileStream(file));
+
+ if (!XaraDocument::isSupported(input.get()))
+ {
+ std::cerr << "ERROR: Unsupported file format (unsupported version) or file is encrypted!" << std::endl;
+ return 1;
+ }
+
+ librevenge::RVNGRawDrawingGenerator documentGenerator(printIndentLevel);
+
+ return (XaraDocument::parse(input.get(), &documentGenerator)) ? 0 : 1;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
diff --git a/src/conv/raw/xar2raw.rc.in b/src/conv/raw/xar2raw.rc.in
new file mode 100644
index 0000000..5200996
--- /dev/null
+++ b/src/conv/raw/xar2raw.rc.in
@@ -0,0 +1,31 @@
+#include <winver.h>
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION @XARA_MAJOR_VERSION@,@XARA_MINOR_VERSION@,@XARA_MICRO_VERSION@,BUILDNUMBER
+ PRODUCTVERSION @XARA_MAJOR_VERSION@,@XARA_MINOR_VERSION@,@XARA_MICRO_VERSION@,0
+ FILEFLAGSMASK 0
+ FILEFLAGS 0
+ FILEOS VOS__WINDOWS32
+ FILETYPE VFT_APP
+ FILESUBTYPE VFT2_UNKNOWN
+ BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904B0"
+ BEGIN
+ VALUE "CompanyName", "The libxara developer community"
+ VALUE "FileDescription", "xar2text"
+ VALUE "FileVersion", "@XARA_MAJOR_VERSION@.@XARA_MINOR_VERSION@.@XARA_MICRO_VERSION@.BUILDNUMBER"
+ VALUE "InternalName", "xar2raw"
+ VALUE "LegalCopyright", "Copyright (C) 2015 David Tardon"
+ VALUE "OriginalFilename", "xar2raw.exe"
+ VALUE "ProductName", "libxara"
+ VALUE "ProductVersion", "@XARA_MAJOR_VERSION@.@XARA_MINOR_VERSION@.@XARA_MICRO_VERSION@"
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1200
+ END
+ END
+
diff --git a/src/conv/svg/.gitignore b/src/conv/svg/.gitignore
new file mode 100644
index 0000000..4268697
--- /dev/null
+++ b/src/conv/svg/.gitignore
@@ -0,0 +1,9 @@
+.deps
+.libs
+*.lo
+*.la
+Makefile
+Makefile.in
+xar2svg
+xar2svg.exe
+xar2svg.rc
diff --git a/src/conv/svg/Makefile.am b/src/conv/svg/Makefile.am
new file mode 100644
index 0000000..c1b3cc5
--- /dev/null
+++ b/src/conv/svg/Makefile.am
@@ -0,0 +1,40 @@
+## -*- Mode: make; tab-width: 4; indent-tabs-mode: tabs -*-
+
+bin_PROGRAMS = xar2svg
+
+AM_CXXFLAGS = \
+ -I$(top_srcdir)/inc \
+ $(REVENGE_CFLAGS) \
+ $(REVENGE_GENERATORS_CFLAGS) \
+ $(REVENGE_STREAM_CFLAGS) \
+ $(BOOST_CFLAGS) \
+ $(DEBUG_CXXFLAGS)
+
+xar2svg_DEPENDENCIES = @XAR2SVG_WIN32_RESOURCE@
+xar2svg_LDADD = \
+ ../../lib/libxara-@XARA_MAJOR_VERSION@.@XARA_MINOR_VERSION@.la \
+ $(REVENGE_LIBS) \
+ $(REVENGE_GENERATORS_LIBS) \
+ $(REVENGE_STREAM_LIBS) \
+ @XAR2SVG_WIN32_RESOURCE@
+
+xar2svg_SOURCES = xar2svg.cpp
+
+if OS_WIN32
+
+@XAR2SVG_WIN32_RESOURCE@ : xar2svg.rc $(xar2svg_OBJECTS)
+ chmod +x $(top_srcdir)/build/win32/*compile-resource && \
+ WINDRES=@WINDRES@ $(top_srcdir)/build/win32/lt-compile-resource xar2svg.rc @XAR2SVG_WIN32_RESOURCE@
+
+endif
+
+# Include the xar2svg_SOURCES in case we build a tarball without stream
+EXTRA_DIST = \
+ $(xar2svg_SOURCES) \
+ xar2svg.rc.in
+
+# These may be in the builddir too
+BUILD_EXTRA_DIST = \
+ xar2svg.rc
+
+## vim:set shiftwidth=4 tabstop=4 noexpandtab:
diff --git a/src/conv/svg/xar2svg.cpp b/src/conv/svg/xar2svg.cpp
new file mode 100644
index 0000000..4d03414
--- /dev/null
+++ b/src/conv/svg/xar2svg.cpp
@@ -0,0 +1,81 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * This file is part of the libxara project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <iostream>
+#include <sstream>
+#include <stdio.h>
+#include <string.h>
+
+#include <librevenge/librevenge.h>
+#include <librevenge-generators/librevenge-generators.h>
+#include <librevenge-stream/librevenge-stream.h>
+
+#include <libxara/libxara.h>
+
+namespace
+{
+
+int printUsage()
+{
+ printf("Usage: xar2svg [OPTION] <Document>\n");
+ printf("\n");
+ printf("Options:\n");
+ printf("--help Shows this help message\n");
+ return -1;
+}
+
+} // anonymous namespace
+
+using libxara::XaraDocument;
+
+int main(int argc, char *argv[])
+{
+ if (argc < 2)
+ return printUsage();
+
+ char *file = 0;
+
+ for (int i = 1; i < argc; i++)
+ {
+ if (!file && strncmp(argv[i], "--", 2))
+ file = argv[i];
+ else
+ return printUsage();
+ }
+
+ if (!file)
+ return printUsage();
+
+ librevenge::RVNGFileStream input(file);
+
+ if (!XaraDocument::isSupported(&input))
+ {
+ std::cerr << "ERROR: Unsupported file format (unsupported version) or file is encrypted!" << std::endl;
+ return 1;
+ }
+
+ librevenge::RVNGStringVector vec;
+ librevenge::RVNGSVGDrawingGenerator generator(vec, "");
+ bool result = XaraDocument::parse(&input, &generator);
+ if (!result || vec.empty() || vec[0].empty())
+ {
+ std::cerr << "ERROR: SVG Generation failed!" << std::endl;
+ return 1;
+ }
+
+#if 1
+ std::cout << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n";
+ std::cout << "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"";
+ std::cout << " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n";
+#endif
+ std::cout << vec[0].cstr() << std::endl;
+ return 0;
+}
+
+/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
diff --git a/src/conv/svg/xar2svg.rc.in b/src/conv/svg/xar2svg.rc.in
new file mode 100644
index 0000000..f4aebe2
--- /dev/null
+++ b/src/conv/svg/xar2svg.rc.in
@@ -0,0 +1,31 @@
+#include <winver.h>
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION @XARA_MAJOR_VERSION@,@XARA_MINOR_VERSION@,@XARA_MICRO_VERSION@,BUILDNUMBER
+ PRODUCTVERSION @XARA_MAJOR_VERSION@,@XARA_MINOR_VERSION@,@XARA_MICRO_VERSION@,0
+ FILEFLAGSMASK 0
+ FILEFLAGS 0
+ FILEOS VOS__WINDOWS32
+ FILETYPE VFT_APP
+ FILESUBTYPE VFT2_UNKNOWN
+ BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904B0"
+ BEGIN
+ VALUE "CompanyName", "The libxara developer community"
+ VALUE "FileDescription", "xar2text"
+ VALUE "FileVersion", "@XARA_MAJOR_VERSION@.@XARA_MINOR_VERSION@.@XARA_MICRO_VERSION@.BUILDNUMBER"
+ VALUE "InternalName", "xar2svg"
+ VALUE "LegalCopyright", "Copyright (C) 2015 David Tardon"
+ VALUE "OriginalFilename", "xar2svg.exe"
+ VALUE "ProductName", "libxara"
+ VALUE "ProductVersion", "@XARA_MAJOR_VERSION@.@XARA_MINOR_VERSION@.@XARA_MICRO_VERSION@"
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1200
+ END
+ END
+
diff --git a/src/lib/.gitignore b/src/lib/.gitignore
new file mode 100644
index 0000000..8f379bf
--- /dev/null
+++ b/src/lib/.gitignore
@@ -0,0 +1,9 @@
+.deps
+.libs
+*.lo
+*.la
+*.o
+*.rc
+*.inc
+Makefile
+Makefile.in
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
new file mode 100644
index 0000000..94aed7e
--- /dev/null
+++ b/src/lib/Makefile.am
@@ -0,0 +1,49 @@
+## -*- Mode: make; tab-width: 4; indent-tabs-mode: tabs -*-
+
+if PLATFORM_WIN32
+version_info = -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) -avoid-version
+else
+version_info = -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
+endif
+
+lib_LTLIBRARIES = libxara-@XARA_MAJOR_VERSION@.@XARA_MINOR_VERSION@.la
+libxara_@XARA_MAJOR_VERSION@_@XARA_MINOR_VERSION@_includedir = $(includedir)/libxara-@XARA_MAJOR_VERSION@.@XARA_MINOR_VERSION@/libxara
+libxara_@XARA_MAJOR_VERSION@_@XARA_MINOR_VERSION@_include_HEADERS = \
+ $(top_srcdir)/inc/libxara/XaraDocument.h \
+ $(top_srcdir)/inc/libxara/libxara.h
+
+AM_CXXFLAGS = \
+ -DLIBXARA_BUILD=1 \
+ -I$(top_srcdir)/inc \
+ $(REVENGE_CFLAGS) \
+ $(REVENGE_STREAM_CFLAGS) \
+ $(BOOST_CFLAGS) \
+ $(DEBUG_CXXFLAGS)
+
+libxara_@XARA_MAJOR_VERSION@_@XARA_MINOR_VERSION@_la_LIBADD = \
+ $(REVENGE_LIBS) \
+ @LIBXARA_WIN32_RESOURCE@
+
+libxara_@XARA_MAJOR_VERSION@_@XARA_MINOR_VERSION@_la_DEPENDENCIES = @LIBXARA_WIN32_RESOURCE@
+libxara_@XARA_MAJOR_VERSION@_@XARA_MINOR_VERSION@_la_LDFLAGS = $(version_info) -export-dynamic -no-undefined
+libxara_@XARA_MAJOR_VERSION@_@XARA_MINOR_VERSION@_la_SOURCES = \
+ XaraDocument.cpp \
+ libxara_utils.cpp \
+ libxara_utils.h
+
+if OS_WIN32
+
+@LIBXARA_WIN32_RESOURCE@ : libxara.rc $(libxara_@XARA_MAJOR_VERSION@_@XARA_MINOR_VERSION@_la_OBJECTS)
+ chmod +x $(top_srcdir)/build/win32/*compile-resource
+ WINDRES=@WINDRES@ $(top_srcdir)/build/win32/lt-compile-resource libxara.rc @LIBXARA_WIN32_RESOURCE@
+
+endif
+
+EXTRA_DIST = \
+ libxara.rc.in
+
+# These may be in the builddir too
+BUILD_EXTRA_DIST = \
+ libxara.rc
+
+## vim:set shiftwidth=4 tabstop=4 noexpandtab:
diff --git a/src/lib/XaraDocument.cpp b/src/lib/XaraDocument.cpp
new file mode 100644
index 0000000..34c2f16
--- /dev/null
+++ b/src/lib/XaraDocument.cpp
@@ -0,0 +1,45 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * This file is part of the libxara project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <libxara/libxara.h>
+
+#include "libxara_utils.h"
+
+using librevenge::RVNGInputStream;
+
+namespace libxara
+{
+
+XARAAPI bool XaraDocument::isSupported(librevenge::RVNGInputStream *const input) try
+{
+ (void) input;
+ return false;
+}
+catch (...)
+{
+ return false;
+}
+
+XARAAPI bool XaraDocument::parse(librevenge::RVNGInputStream *const input, librevenge::RVNGDrawingInterface *const document) try
+{
+ (void) document;
+ const RVNGInputStreamPtr_t input_(input, XARADummyDeleter());
+
+ input_->seek(0, librevenge::RVNG_SEEK_SET);
+
+ return false;
+}
+catch (...)
+{
+ return false;
+}
+
+} // namespace libxara
+
+/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
diff --git a/src/lib/libxara.rc.in b/src/lib/libxara.rc.in
new file mode 100644
index 0000000..5521561
--- /dev/null
+++ b/src/lib/libxara.rc.in
@@ -0,0 +1,31 @@
+#include <winver.h>
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION @XARA_MAJOR_VERSION@,@XARA_MINOR_VERSION@,@XARA_MICRO_VERSION@,BUILDNUMBER
+ PRODUCTVERSION @XARA_MAJOR_VERSION@,@XARA_MINOR_VERSION@,@XARA_MICRO_VERSION@,0
+ FILEFLAGSMASK 0
+ FILEFLAGS 0
+ FILEOS VOS__WINDOWS32
+ FILETYPE VFT_DLL
+ FILESUBTYPE VFT2_UNKNOWN
+ BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904B0"
+ BEGIN
+ VALUE "CompanyName", "The libxara developer community"
+ VALUE "FileDescription", "libxara"
+ VALUE "FileVersion", "@XARA_MAJOR_VERSION@.@XARA_MINOR_VERSION@.@XARA_MICRO_VERSION@.BUILDNUMBER"
+ VALUE "InternalName", "libxara-0.0"
+ VALUE "LegalCopyright", "Copyright (C) 2015 David Tardon, other contributors"
+ VALUE "OriginalFilename", "libxara-0.0.dll"
+ VALUE "ProductName", "libxara"
+ VALUE "ProductVersion", "@XARA_MAJOR_VERSION@.@XARA_MINOR_VERSION@.@XARA_MICRO_VERSION@"
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1200
+ END
+ END
+
diff --git a/src/lib/libxara_utils.cpp b/src/lib/libxara_utils.cpp
new file mode 100644
index 0000000..7308875
--- /dev/null
+++ b/src/lib/libxara_utils.cpp
@@ -0,0 +1,244 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * This file is part of the libxara project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <cstdio>
+
+#include "libxara_utils.h"
+
+using std::string;
+
+namespace libxara
+{
+
+namespace
+{
+
+void checkStream(librevenge::RVNGInputStream *const input)
+{
+ if (!input || input->isEnd())
+ throw EndOfStreamException();
+}
+
+struct SeekFailedException {};
+
+}
+
+uint8_t readU8(librevenge::RVNGInputStream *input, bool /* bigEndian */)
+{
+ checkStream(input);
+
+ unsigned long numBytesRead;
+ uint8_t const *p = input->read(sizeof(uint8_t), numBytesRead);
+
+ if (p && numBytesRead == sizeof(uint8_t))
+ return *(uint8_t const *)(p);
+ throw EndOfStreamException();
+}
+
+uint16_t readU16(librevenge::RVNGInputStream *input, bool bigEndian)
+{
+ checkStream(input);
+
+ unsigned long numBytesRead;
+ uint8_t const *p = input->read(sizeof(uint16_t), numBytesRead);
+
+ if (p && numBytesRead == sizeof(uint16_t))
+ {
+ if (bigEndian)
+ return static_cast<uint16_t>((uint16_t)p[1]|((uint16_t)p[0]<<8));
+ return static_cast<uint16_t>((uint16_t)p[0]|((uint16_t)p[1]<<8));
+ }
+ throw EndOfStreamException();
+}
+
+uint32_t readU32(librevenge::RVNGInputStream *input, bool bigEndian)
+{
+ checkStream(input);
+
+ unsigned long numBytesRead;
+ uint8_t const *p = input->read(sizeof(uint32_t), numBytesRead);
+
+ if (p && numBytesRead == sizeof(uint32_t))
+ {
+ if (bigEndian)
+ return (uint32_t)p[3]|((uint32_t)p[2]<<8)|((uint32_t)p[1]<<16)|((uint32_t)p[0]<<24);
+ return (uint32_t)p[0]|((uint32_t)p[1]<<8)|((uint32_t)p[2]<<16)|((uint32_t)p[3]<<24);
+ }
+ throw EndOfStreamException();
+}
+
+uint64_t readU64(librevenge::RVNGInputStream *input, bool bigEndian)
+{
+ checkStream(input);
+
+ unsigned long numBytesRead;
+ uint8_t const *p = input->read(sizeof(uint64_t), numBytesRead);
+
+ if (p && numBytesRead == sizeof(uint64_t))
+ {
+ if (bigEndian)
+ return (uint64_t)p[7]|((uint64_t)p[6]<<8)|((uint64_t)p[5]<<16)|((uint64_t)p[4]<<24)|((uint64_t)p[3]<<32)|((uint64_t)p[2]<<40)|((uint64_t)p[1]<<48)|((uint64_t)p[0]<<56);
+ return (uint64_t)p[0]|((uint64_t)p[1]<<8)|((uint64_t)p[2]<<16)|((uint64_t)p[3]<<24)|((uint64_t)p[4]<<32)|((uint64_t)p[5]<<40)|((uint64_t)p[6]<<48)|((uint64_t)p[7]<<56);
+ }
+ throw EndOfStreamException();
+}
+
+const unsigned char *readNBytes(librevenge::RVNGInputStream *const input, const unsigned long numBytes)
+{
+ checkStream(input);
+
+ unsigned long readBytes = 0;
+ const unsigned char *const s = input->read(numBytes, readBytes);
+
+ if (numBytes != readBytes)
+ throw EndOfStreamException();
+
+ return s;
+}
+
+string readCString(librevenge::RVNGInputStream *input)
+{
+ checkStream(input);
+
+ string str;
+ unsigned char c = readU8(input);
+ while (0 != c)
+ {
+ str.push_back(c);
+ c = readU8(input);
+ }
+
+ return str;
+}
+
+string readPascalString(librevenge::RVNGInputStream *input)
+{
+ checkStream(input);
+
+ const unsigned length = readU8(input);
+ string str;
+ for (unsigned i = 0; length != i; ++i)
+ str.push_back(readU8(input));
+
+ return str;
+}
+
+void skip(librevenge::RVNGInputStream *input, unsigned long numBytes)
+{
+ checkStream(input);
+
+ seekRelative(input, static_cast<long>(numBytes));
+}
+
+void seek(librevenge::RVNGInputStream *const input, const unsigned long pos)
+{
+ if (!input)
+ throw EndOfStreamException();
+
+ if (0 != input->seek(static_cast<long>(pos), librevenge::RVNG_SEEK_SET))
+ throw SeekFailedException();
+}
+
+void seekRelative(librevenge::RVNGInputStream *const input, const long pos)
+{
+ if (!input)
+ throw EndOfStreamException();
+
+ if (0 != input->seek(pos, librevenge::RVNG_SEEK_CUR))
+ throw SeekFailedException();
+}
+
+unsigned long getLength(librevenge::RVNGInputStream *const input)
+{
+ if (!input)
+ throw SeekFailedException();
+
+ const unsigned long begin = input->tell();
+ unsigned long end = begin;
+
+ if (0 == input->seek(0, librevenge::RVNG_SEEK_END))
+ end = input->tell();
+ else
+ {
+ // librevenge::RVNG_SEEK_END does not work. Use the harder way.
+ while (!input->isEnd())
+ {
+ readU8(input);
+ ++end;
+ }
+ }
+
+ seek(input, begin);
+
+ return end - begin;
+}
+
+uint8_t readU8(const boost::shared_ptr<librevenge::RVNGInputStream> input, bool)
+{
+ return readU8(input.get());
+}
+
+uint16_t readU16(const boost::shared_ptr<librevenge::RVNGInputStream> input, const bool bigEndian)
+{
+ return readU16(input.get(), bigEndian);
+}
+
+uint32_t readU32(const boost::shared_ptr<librevenge::RVNGInputStream> input, const bool bigEndian)
+{
+ return readU32(input.get(), bigEndian);
+}
+
+uint64_t readU64(const boost::shared_ptr<librevenge::RVNGInputStream> input, const bool bigEndian)
+{
+ return readU64(input.get(), bigEndian);
+}
+
+const unsigned char *readNBytes(const boost::shared_ptr<librevenge::RVNGInputStream> input, const unsigned long numBytes)
+{
+ return readNBytes(input.get(), numBytes);
+}
+
+std::string readCString(const boost::shared_ptr<librevenge::RVNGInputStream> input)
+{
+ return readCString(input.get());
+}
+
+std::string readPascalString(const boost::shared_ptr<librevenge::RVNGInputStream> input)
+{
+ return readPascalString(input.get());
+}
+
+void skip(const boost::shared_ptr<librevenge::RVNGInputStream> input, const unsigned long numBytes)
+{
+ return skip(input.get(), numBytes);
+}
+
+void seek(const boost::shared_ptr<librevenge::RVNGInputStream> input, const unsigned long pos)
+{
+ seek(input.get(), pos);
+}
+
+void seekRelative(const boost::shared_ptr<librevenge::RVNGInputStream> input, const long pos)
+{
+ seekRelative(input.get(), pos);
+}
+
+unsigned long getLength(const boost::shared_ptr<librevenge::RVNGInputStream> input)
+{
+ return getLength(input.get());
+}
+
+EndOfStreamException::EndOfStreamException()
+{
+ XARA_DEBUG_MSG(("Throwing EndOfStreamException\n"));
+}
+
+}
+
+/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
diff --git a/src/lib/libxara_utils.h b/src/lib/libxara_utils.h
new file mode 100644
index 0000000..39b1a1c
--- /dev/null
+++ b/src/lib/libxara_utils.h
@@ -0,0 +1,161 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * This file is part of the libxara project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_LIBXARA_UTILS_H
+#define INCLUDED_LIBXARA_UTILS_H
+
+#ifdef DEBUG
+#include <cstdio>
+#endif
+
+#include <string>
+
+#include <boost/shared_ptr.hpp>
+
+#include <librevenge-stream/librevenge-stream.h>
+#include <librevenge/librevenge.h>
+
+#ifdef _MSC_VER
+
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef short int16_t;
+typedef unsigned uint32_t;
+typedef int int32_t;
+typedef unsigned __int64 uint64_t;
+typedef __int64 int64_t;
+
+#else
+
+#ifdef HAVE_CONFIG_H
+
+#include "config.h"
+
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
+
+#ifdef HAVE_INTTYPES_H
+#include <inttypes.h>
+#endif
+
+#else
+
+// assume that the headers are there inside LibreOffice build when no HAVE_CONFIG_H is defined
+#include <stdint.h>
+#include <inttypes.h>
+
+#endif
+
+#endif
+
+// debug message includes source file and line number
+//#define VERBOSE_DEBUG 1
+
+// do nothing with debug messages in a release compile
+#ifdef DEBUG
+#ifdef VERBOSE_DEBUG
+#define XARA_DEBUG_MSG(M) std::printf("%15s:%5d: ", __FILE__, __LINE__); std::printf M
+#define XARA_DEBUG(M) M
+#else
+#define XARA_DEBUG_MSG(M) std::printf M
+#define XARA_DEBUG(M) M
+#endif
+#else
+#define XARA_DEBUG_MSG(M)
+#define XARA_DEBUG(M)
+#endif
+
+#define XARA_NUM_ELEMENTS(array) (sizeof(array) / sizeof(array[0]))
+
+namespace libxara
+{
+
+typedef boost::shared_ptr<librevenge::RVNGInputStream> RVNGInputStreamPtr_t;
+
+struct XARADummyDeleter
+{
+ void operator()(void *) {}
+};
+
+uint8_t readU8(librevenge::RVNGInputStream *input, bool = false);
+uint16_t readU16(librevenge::RVNGInputStream *input, bool bigEndian=false);
+uint32_t readU32(librevenge::RVNGInputStream *input, bool bigEndian=false);
+uint64_t readU64(librevenge::RVNGInputStream *input, bool bigEndian=false);
+
+const unsigned char *readNBytes(librevenge::RVNGInputStream *input, unsigned long numBytes);
+
+std::string readCString(librevenge::RVNGInputStream *input);
+std::string readPascalString(librevenge::RVNGInputStream *input);
+
+void skip(librevenge::RVNGInputStream *input, unsigned long numBytes);
+
+void seek(librevenge::RVNGInputStream *input, unsigned long pos);
+void seekRelative(librevenge::RVNGInputStream *input, long pos);
+
+unsigned long getLength(librevenge::RVNGInputStream *input);
+
+uint8_t readU8(boost::shared_ptr<librevenge::RVNGInputStream> input, bool = false);
+uint16_t readU16(boost::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
+uint32_t readU32(boost::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
+uint64_t readU64(boost::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
+
+const unsigned char *readNBytes(boost::shared_ptr<librevenge::RVNGInputStream> input, unsigned long numBytes);
+
+std::string readCString(boost::shared_ptr<librevenge::RVNGInputStream> input);
+std::string readPascalString(boost::shared_ptr<librevenge::RVNGInputStream> input);
+
+void skip(boost::shared_ptr<librevenge::RVNGInputStream> input, unsigned long numBytes);
+
+void seek(boost::shared_ptr<librevenge::RVNGInputStream> input, unsigned long pos);
+void seekRelative(boost::shared_ptr<librevenge::RVNGInputStream> input, long pos);
+
+unsigned long getLength(boost::shared_ptr<librevenge::RVNGInputStream> input);
+
+class EndOfStreamException
+{
+public:
+ EndOfStreamException();
+};
+
+class GenericException
+{
+};
+
+// parser exceptions
+
+class FileAccessError
+{
+};
+
+class PackageError
+{
+};
+
+class ParseError
+{
+};
+
+class PasswordMismatch
+{
+};
+
+class UnsupportedEncryption
+{
+};
+
+class UnsupportedFormat
+{
+};
+
+} // namespace libxara
+
+#endif // INCLUDED_LIBXARA_UTILS_H
+
+/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
diff --git a/src/test/.gitignore b/src/test/.gitignore
new file mode 100644
index 0000000..7742c8b
--- /dev/null
+++ b/src/test/.gitignore
@@ -0,0 +1,10 @@
+Makefile
+Makefile.in
+test
+.libs
+.deps
+*.lo
+*.log
+*.o
+*.trs
+*~
diff --git a/src/test/Makefile.am b/src/test/Makefile.am
new file mode 100644
index 0000000..d259d53
--- /dev/null
+++ b/src/test/Makefile.am
@@ -0,0 +1,27 @@
+## -*- Mode: make; tab-width: 4; indent-tabs-mode: tabs -*-
+
+target_test = test
+
+check_PROGRAMS = $(target_test)
+
+AM_CXXFLAGS = \
+ -I$(top_srcdir)/inc \
+ -I$(top_srcdir)/src/lib \
+ $(CPPUNIT_CFLAGS) \
+ $(REVENGE_CFLAGS) \
+ $(REVENGE_STREAM_CFLAGS) \
+ $(DEBUG_CXXFLAGS)
+
+test_LDFLAGS = -L$(top_srcdir)/src/lib
+test_LDADD = \
+ $(top_builddir)/src/lib/libxara-@XARA_MAJOR_VERSION@.@XARA_MINOR_VERSION@.la \
+ $(CPPUNIT_LIBS) \
+ $(REVENGE_LIBS) \
+ $(REVENGE_STREAM_LIBS)
+
+test_SOURCES = \
+ test.cpp
+
+TESTS = $(target_test)
+
+## vim:set shiftwidth=4 tabstop=4 noexpandtab:
diff --git a/src/test/test.cpp b/src/test/test.cpp
new file mode 100644
index 0000000..5bb1571
--- /dev/null
+++ b/src/test/test.cpp
@@ -0,0 +1,46 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * This file is part of the libxara project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <iostream>
+
+#include <cppunit/BriefTestProgressListener.h>
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/TestResult.h>
+#include <cppunit/TestResultCollector.h>
+#include <cppunit/TestRunner.h>
+
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+int main()
+{
+ // Create the event manager and test controller
+ CPPUNIT_NS::TestResult controller;
+
+ // Add a listener that colllects test result
+ CPPUNIT_NS::TestResultCollector result;
+ controller.addListener(&result);
+
+ // Add a listener that print dots as test run.
+ CPPUNIT_NS::BriefTestProgressListener progress;
+ controller.addListener(&progress);
+
+ // Add the top suite to the test runner
+ CPPUNIT_NS::TestRunner runner;
+ runner.addTest(CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest());
+ runner.run(controller);
+
+ // output
+ CPPUNIT_NS::CompilerOutputter outputter(&result, std::cerr);
+ outputter.write();
+
+ // return status code
+ return result.wasSuccessful() ? 0 : 1;
+}
+
+/* vim:set shiftwidth=2 softtabstop=2 expandtab: */