diff --git a/src/common/base64.h b/include/common/base64.h similarity index 100% rename from src/common/base64.h rename to include/common/base64.h diff --git a/src/common/networkTools.h b/include/common/networkTools.h similarity index 100% rename from src/common/networkTools.h rename to include/common/networkTools.h diff --git a/src/common/otherTools.h b/include/common/otherTools.h similarity index 100% rename from src/common/otherTools.h rename to include/common/otherTools.h diff --git a/src/common/pathTools.h b/include/common/pathTools.h similarity index 98% rename from src/common/pathTools.h rename to include/common/pathTools.h index 7dc5f8cdc..6e87e5af4 100644 --- a/src/common/pathTools.h +++ b/include/common/pathTools.h @@ -37,7 +37,7 @@ #include #endif -#include +#include "stringTools.h" using namespace std; diff --git a/src/common/regexTools.h b/include/common/regexTools.h similarity index 100% rename from src/common/regexTools.h rename to include/common/regexTools.h diff --git a/src/common/resourceTools.h b/include/common/resourceTools.h similarity index 100% rename from src/common/resourceTools.h rename to include/common/resourceTools.h diff --git a/src/common/stringTools.h b/include/common/stringTools.h similarity index 99% rename from src/common/stringTools.h rename to include/common/stringTools.h index 75b3de7cd..788b26857 100644 --- a/src/common/stringTools.h +++ b/include/common/stringTools.h @@ -34,7 +34,7 @@ #include #include -#include +#include "pathTools.h" namespace kiwix { diff --git a/src/common/tree.h b/include/common/tree.h similarity index 100% rename from src/common/tree.h rename to include/common/tree.h diff --git a/src/common/kiwix/ctpp2/CTPP2VMStringLoader.hpp b/include/ctpp2/CTPP2VMStringLoader.hpp similarity index 87% rename from src/common/kiwix/ctpp2/CTPP2VMStringLoader.hpp rename to include/ctpp2/CTPP2VMStringLoader.hpp index 7220133ae..84f8eeb1e 100644 --- a/src/common/kiwix/ctpp2/CTPP2VMStringLoader.hpp +++ b/include/ctpp2/CTPP2VMStringLoader.hpp @@ -20,12 +20,12 @@ #ifndef _CTPP2_VM_STRING_LOADER_HPP__ #define _CTPP2_VM_STRING_LOADER_HPP__ 1 -#include "ctpp2/CTPP2VMLoader.hpp" -#include "ctpp2/CTPP2Util.hpp" -#include "ctpp2/CTPP2Exception.hpp" -#include "ctpp2/CTPP2VMExecutable.hpp" -#include "ctpp2/CTPP2VMInstruction.hpp" -#include "ctpp2/CTPP2VMMemoryCore.hpp" +#include +#include +#include +#include +#include +#include #include #include @@ -34,7 +34,7 @@ #include #include -#include +// #include #include #include diff --git a/src/common/kiwix/indexer.h b/include/indexer.h similarity index 98% rename from src/common/kiwix/indexer.h rename to include/indexer.h index 8ba671c14..e9f45b630 100755 --- a/src/common/kiwix/indexer.h +++ b/include/indexer.h @@ -29,9 +29,9 @@ #include #include -#include -#include -#include +#include "common/stringTools.h" +#include "common/otherTools.h" +#include "common/resourceTools.h" #include #include #include diff --git a/src/common/componentTools.h b/include/kiwix.h similarity index 63% rename from src/common/componentTools.h rename to include/kiwix.h index 2923003a2..a83c3a9c5 100644 --- a/src/common/componentTools.h +++ b/include/kiwix.h @@ -17,28 +17,10 @@ * MA 02110-1301, USA. */ -#ifndef KIWIX_COMPONENTTOOLS_H -#define KIWIX_COMPONENTTOOLS_H +#ifndef KIWIX_H +#define KIWIX_H -#ifdef _WIN32 - #include -#endif +#include "library.h" -#include -#ifdef __APPLE__ - #include -#endif - -#ifdef _WIN32 - #include -#endif - -#include "nsStringAPI.h" -#include "nsEmbedString.h" - -const char *nsStringToCString(const nsAString &str); -std::string nsStringToString(const nsEmbedString &str); -const char *nsStringToUTF8(const nsAString &str); - -#endif +#endif \ No newline at end of file diff --git a/src/common/kiwix/library.h b/include/library.h similarity index 97% rename from src/common/kiwix/library.h rename to include/library.h index 2bc16c8ba..1479fb690 100644 --- a/src/common/kiwix/library.h +++ b/include/library.h @@ -27,8 +27,8 @@ #include #include -#include -#include +#include "common/stringTools.h" +#include "common/regexTools.h" #define KIWIX_LIBRARY_VERSION "20110515" diff --git a/src/common/kiwix/manager.h b/include/manager.h similarity index 96% rename from src/common/kiwix/manager.h rename to include/manager.h index 453ba9054..5c2a87ba4 100644 --- a/src/common/kiwix/manager.h +++ b/include/manager.h @@ -26,11 +26,11 @@ #include -#include "../base64.h" -#include "../regexTools.h" -#include "../pathTools.h" -#include -#include +#include "common/base64.h" +#include "common/regexTools.h" +#include "common/pathTools.h" +#include "library.h" +#include "reader.h" using namespace std; diff --git a/include/meson.build b/include/meson.build new file mode 100644 index 000000000..78e0a876e --- /dev/null +++ b/include/meson.build @@ -0,0 +1,31 @@ +headers = [ + 'indexer.h', + 'library.h', + 'manager.h', + 'reader.h', + 'searcher.h' +] + +if xapian_dep.found() + headers += ['xapianIndexer.h', 'xapianSearcher.h'] +endif + +install_headers(headers, subdir:'kiwix') + +install_headers( + 'common/base64.h', + 'common/networkTools.h', + 'common/otherTools.h', + 'common/pathTools.h', + 'common/regexTools.h', + 'common/resourceTools.h', + 'common/stringTools.h', + 'common/tree.h', + subdir:'kiwix/common' +) + + +install_headers( + 'ctpp2/CTPP2VMStringLoader.hpp', + subdir:'kiwix/ctpp2' +) diff --git a/src/common/kiwix/reader.h b/include/reader.h similarity index 98% rename from src/common/kiwix/reader.h rename to include/reader.h index 7d0325069..f9bf9db0a 100644 --- a/src/common/kiwix/reader.h +++ b/include/reader.h @@ -29,9 +29,8 @@ #include #include #include -#include "time.h" -#include -#include +#include "common/pathTools.h" +#include "common/stringTools.h" using namespace std; diff --git a/src/common/kiwix/searcher.h b/include/searcher.h similarity index 93% rename from src/common/kiwix/searcher.h rename to include/searcher.h index f8a2551e2..9fb118891 100644 --- a/src/common/kiwix/searcher.h +++ b/include/searcher.h @@ -28,16 +28,16 @@ #include #include #include -#include -#include -#include -#include "unicode/putil.h" +#include "common/resourceTools.h" +#include "common/pathTools.h" +#include "common/stringTools.h" +#include #ifndef __ANDROID__ #include #include #include -#include "kiwix/ctpp2/CTPP2VMStringLoader.hpp" +#include "ctpp2/CTPP2VMStringLoader.hpp" using namespace CTPP; #endif diff --git a/src/common/kiwix/xapianIndexer.h b/include/xapianIndexer.h similarity index 100% rename from src/common/kiwix/xapianIndexer.h rename to include/xapianIndexer.h diff --git a/src/common/kiwix/xapianSearcher.h b/include/xapianSearcher.h similarity index 100% rename from src/common/kiwix/xapianSearcher.h rename to include/xapianSearcher.h diff --git a/meson.build b/meson.build new file mode 100644 index 000000000..573e01a16 --- /dev/null +++ b/meson.build @@ -0,0 +1,61 @@ +project('kiwixlib', 'cpp', + version : '1.0.0', + license : 'GPL') + +compiler = meson.get_compiler('cpp') + +thread_dep = dependency('threads') +zlib_dep = dependency('zlib') +bzip_dep = dependency('bzip2') +libicu_dep = dependency('icu-i18n') +lzma_dep = dependency('liblzma') +libzim_dep = dependency('zimlib') +pugixml_dep = dependency('pugixml') +aria2_dep = find_program('aria2c') + +ctpp2_prefix_install = get_option('ctpp2-install-prefix') +if get_option('default_library') == 'static' + libname = 'ctpp2-st' +else + libname = 'ctpp2' +endif +if ctpp2_prefix_install == '' + if not compiler.has_header('ctpp2/CTPP2Logger.hpp') + error('ctpp2/CTPP2Logger.hppnot found') + endif + ctpp2_lib = compiler.find_library(libname) + ctpp2_dep = declare_dependency(dependencies:[ctpp2_lib]) +else + ctpp2_include_path = ctpp2_prefix_install + '/include' + ctpp2_include_args = ['-I'+ctpp2_include_path] + if not compiler.has_header('ctpp2/CTPP2Logger.hpp', args:ctpp2_include_args) + error('ctpp2/CTPP2Logger.hppnot found') + endif + ctpp2_include_path = include_directories(ctpp2_include_path, is_system:true) + ctpp2_lib_path = ctpp2_prefix_install+'/lib' + ctpp2_lib = compiler.find_library(libname, dirs:ctpp2_lib_path) + ctpp2_dep = declare_dependency(include_directories:ctpp2_include_path, dependencies:[ctpp2_lib]) +endif + +xapian_dep = dependency('xapian-core', required:false) +if xapian_dep.found() + message('xapian_dep found') +else + message('xapian_dep not found') +endif + +all_deps = [thread_dep, zlib_dep, libicu_dep, lzma_dep, libzim_dep, ctpp2_dep, xapian_dep, pugixml_dep, bzip_dep] + +inc = include_directories('include') + +subdir('include') +subdir('src') + +pkg_mod = import('pkgconfig') +pkg_mod.generate(libraries : kiwixlib, + version : '1.0', + name : 'libkiwix', + filebase : 'kiwix', + description : 'A library that contains a lot of things used by used by other kiwix programs', + requires: ['zimlib', 'zlib', 'xapian-core', 'icu-i18n', 'liblzma', 'bzip2', 'pugixml']) + diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 000000000..23c06234d --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,2 @@ +option('ctpp2-install-prefix', type : 'string', value : '', + description : 'Prefix where ctpp libs has been installed') \ No newline at end of file diff --git a/src/common/base64.cpp b/src/common/base64.cpp index 522d0b028..e8889a6b0 100644 --- a/src/common/base64.cpp +++ b/src/common/base64.cpp @@ -24,7 +24,7 @@ René Nyffenegger rene.nyffenegger@adp-gmbh.ch */ -#include "base64.h" +#include #include static const std::string base64_chars = diff --git a/src/common/componentTools.cpp b/src/common/componentTools.cpp deleted file mode 100644 index 3bf3d5815..000000000 --- a/src/common/componentTools.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2011 Emmanuel Engelhart - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ - -#include "componentTools.h" - -const char *nsStringToCString(const nsAString &str) { - const char *cStr; - nsCString tmpStr; - -#ifdef _WIN32 - LossyCopyUTF16toASCII(str, tmpStr); -#else - CopyUTF16toUTF8(str, tmpStr); -#endif - - NS_CStringGetData(tmpStr, &cStr); - -#ifdef _WIN32 - return _strdup(cStr); -#else - return strdup(cStr); -#endif -} - -std::string nsStringToString(const nsEmbedString &str) { -#ifdef _WIN32 - PRUnichar *start = (PRUnichar *)str.get(); - PRUnichar *end = start + str.Length(); - wchar_t wca[4096]; - wchar_t *wstart = wca; - wchar_t *wpr = wstart; - - for(; start < end; ++start) - { - *wstart = (wchar_t) *start; - ++wstart; - } - *wstart = 0; - - std::string ptr; - ptr.resize(4096); - size_t size = wcstombs((char*)ptr.data(), wpr, 4096); - ptr.resize(size); - - return ptr; -#else - const char *cStr; - nsCString tmpStr; - - CopyUTF16toUTF8(str, tmpStr); - NS_CStringGetData(tmpStr, &cStr); - return std::string(cStr); -#endif - -} - -const char *nsStringToUTF8(const nsAString &str) { - const char *cStr; - nsCString tmpStr; - CopyUTF16toUTF8(str, tmpStr); - NS_CStringGetData(tmpStr, &cStr); - -#ifdef _WIN32 - return _strdup(cStr); -#else - return strdup(cStr); -#endif -} diff --git a/src/common/networkTools.cpp b/src/common/networkTools.cpp index bee034ce1..268a49bed 100644 --- a/src/common/networkTools.cpp +++ b/src/common/networkTools.cpp @@ -17,7 +17,7 @@ * MA 02110-1301, USA. */ -#include "networkTools.h" +#include std::map kiwix::getNetworkInterfaces() { std::map interfaces; diff --git a/src/common/otherTools.cpp b/src/common/otherTools.cpp index 4603254f6..4ec60b48c 100644 --- a/src/common/otherTools.cpp +++ b/src/common/otherTools.cpp @@ -17,7 +17,7 @@ * MA 02110-1301, USA. */ -#include "otherTools.h" +#include void kiwix::sleep(unsigned int milliseconds) { #ifdef _WIN32 diff --git a/src/common/pathTools.cpp b/src/common/pathTools.cpp index a01934ca3..a0899d87c 100644 --- a/src/common/pathTools.cpp +++ b/src/common/pathTools.cpp @@ -17,7 +17,7 @@ * MA 02110-1301, USA. */ -#include "pathTools.h" +#include #ifdef __APPLE__ #include @@ -41,6 +41,8 @@ #include #endif +#include + #ifndef PATH_MAX #define PATH_MAX 1024 #endif diff --git a/src/common/regexTools.cpp b/src/common/regexTools.cpp index b62e30088..32f38dbea 100644 --- a/src/common/regexTools.cpp +++ b/src/common/regexTools.cpp @@ -17,7 +17,7 @@ * MA 02110-1301, USA. */ -#include "regexTools.h" +#include std::map regexCache; diff --git a/src/common/resourceTools.cpp b/src/common/resourceTools.cpp index 6a3f67cdb..1c84224a1 100644 --- a/src/common/resourceTools.cpp +++ b/src/common/resourceTools.cpp @@ -1,4 +1,4 @@ -#include +#include #include std::string getResourceAsString(const std::string &name) { diff --git a/src/common/stringTools.cpp b/src/common/stringTools.cpp index 308765036..c5b768ce1 100644 --- a/src/common/stringTools.cpp +++ b/src/common/stringTools.cpp @@ -17,7 +17,7 @@ * MA 02110-1301, USA. */ -#include "stringTools.h" +#include /* tell ICU where to find its dat file (tables) */ void kiwix::loadICUExternalTables() { diff --git a/src/common/kiwix/ctpp2/CTPP2VMStringLoader.cpp b/src/ctpp2/CTPP2VMStringLoader.cpp similarity index 99% rename from src/common/kiwix/ctpp2/CTPP2VMStringLoader.cpp rename to src/ctpp2/CTPP2VMStringLoader.cpp index e52387d50..02da6f238 100644 --- a/src/common/kiwix/ctpp2/CTPP2VMStringLoader.cpp +++ b/src/ctpp2/CTPP2VMStringLoader.cpp @@ -17,7 +17,7 @@ * MA 02110-1301, USA. */ -#include "CTPP2VMStringLoader.hpp" +#include namespace CTPP // C++ Template Engine { diff --git a/src/common/kiwix/indexer.cpp b/src/indexer.cpp similarity index 100% rename from src/common/kiwix/indexer.cpp rename to src/indexer.cpp diff --git a/src/common/kiwix/library.cpp b/src/library.cpp similarity index 100% rename from src/common/kiwix/library.cpp rename to src/library.cpp diff --git a/src/common/kiwix/manager.cpp b/src/manager.cpp similarity index 100% rename from src/common/kiwix/manager.cpp rename to src/manager.cpp diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 000000000..1148a662a --- /dev/null +++ b/src/meson.build @@ -0,0 +1,27 @@ +kiwix_sources = [ + 'library.cpp', + 'manager.cpp', + 'reader.cpp', + 'searcher.cpp', + 'indexer.cpp', + 'common/base64.cpp', + 'common/pathTools.cpp', + 'common/regexTools.cpp', + 'common/stringTools.cpp', + 'common/resourceTools.cpp', + 'common/networkTools.cpp', + 'common/otherTools.cpp', + 'ctpp2/CTPP2VMStringLoader.cpp', + 'xapian/htmlparse.cc', + 'xapian/myhtmlparse.cc' +] + +if xapian_dep.found() + kiwix_sources += ['xapianIndexer.cpp', 'xapianSearcher.cpp'] +endif + +kiwixlib = library('kiwix', + kiwix_sources, + include_directories : inc, + dependencies : all_deps, + install : true) diff --git a/src/common/kiwix/reader.cpp b/src/reader.cpp similarity index 100% rename from src/common/kiwix/reader.cpp rename to src/reader.cpp diff --git a/src/common/kiwix/searcher.cpp b/src/searcher.cpp similarity index 100% rename from src/common/kiwix/searcher.cpp rename to src/searcher.cpp diff --git a/src/common/kiwix/xapian/htmlparse.cc b/src/xapian/htmlparse.cc similarity index 100% rename from src/common/kiwix/xapian/htmlparse.cc rename to src/xapian/htmlparse.cc diff --git a/src/common/kiwix/xapian/htmlparse.h b/src/xapian/htmlparse.h similarity index 100% rename from src/common/kiwix/xapian/htmlparse.h rename to src/xapian/htmlparse.h diff --git a/src/common/kiwix/xapian/myhtmlparse.cc b/src/xapian/myhtmlparse.cc similarity index 100% rename from src/common/kiwix/xapian/myhtmlparse.cc rename to src/xapian/myhtmlparse.cc diff --git a/src/common/kiwix/xapian/myhtmlparse.h b/src/xapian/myhtmlparse.h similarity index 100% rename from src/common/kiwix/xapian/myhtmlparse.h rename to src/xapian/myhtmlparse.h diff --git a/src/common/kiwix/xapian/namedentities.h b/src/xapian/namedentities.h similarity index 100% rename from src/common/kiwix/xapian/namedentities.h rename to src/xapian/namedentities.h diff --git a/src/common/kiwix/xapianIndexer.cpp b/src/xapianIndexer.cpp similarity index 100% rename from src/common/kiwix/xapianIndexer.cpp rename to src/xapianIndexer.cpp diff --git a/src/common/kiwix/xapianSearcher.cpp b/src/xapianSearcher.cpp similarity index 100% rename from src/common/kiwix/xapianSearcher.cpp rename to src/xapianSearcher.cpp