first version of meson

This commit is contained in:
Matthieu Gautier 2016-12-20 00:19:38 +01:00
parent d326603662
commit 8871e6c2e3
8 changed files with 58 additions and 636 deletions

40
meson.build Normal file
View File

@ -0,0 +1,40 @@
project('kiwix-tools', 'cpp')
compiler = meson.get_compiler('cpp')
thread_dep = dependency('threads')
kiwixlib_dep = dependency('kiwix')
microhttpd_dep = dependency('libmicrohttpd')
# Idealy we should not have more dependency, however :
# We should declare we use ctpp2 in kiwixlib in the pkg-config file.
# But there is no pkg-config file for ctpp2. Once one exists, no need to
# declare the dependency here
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.hpp not 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
all_deps = [thread_dep, kiwixlib_dep, microhttpd_dep, ctpp2_dep]
#subdir('include')
subdir('src')

2
meson_options.txt Normal file
View File

@ -0,0 +1,2 @@
option('ctpp2-install-prefix', type : 'string', value : '',
description : 'Prefix where ctpp libs has been installed')

View File

@ -1,294 +0,0 @@
/*
* Copyright 2011 Emmanuel Engelhart <kelson@kiwix.org>
* Copyright 2011 Renaud Gaudin <reg@kiwix.org>
*
* 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 <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <kiwix/manager.h>
#include <pathTools.h>
#include <regexTools.h>
#include "contentManager.h"
ContentManager::ContentManager(int x) : manager() {}
bool ContentManager::OpenLibraryFromFile(string path, bool readOnly) {
try {
return this->manager.readFile(path, readOnly);
} catch (exception &e) {
cerr << e.what() << endl;
return false;
}
return true;
}
bool ContentManager::OpenLibraryFromText(string &xml, bool readOnly) {
bool returnValue = true;
const char *cXml;
cXml = xml.c_str();
try {
return this->manager.readXml(cXml, readOnly);
} catch (exception &e) {
cerr << e.what() << endl;
return false;
}
return false;
}
bool ContentManager::WriteLibrary() {
try {
return this->manager.writeFile(this->manager.writableLibraryPath);
} catch (exception &e) {
cerr << e.what() << endl;
return false;
}
return false;
}
bool ContentManager::WriteLibraryToFile(string &path) {
try {
return this->manager.writeFile(path.c_str());
} catch (exception &e) {
cerr << e.what() << endl;
return false;
}
return false;
}
bool ContentManager::AddBookFromPath(string &path) {
try {
return this->manager.addBookFromPath(path.c_str(), path);
} catch (exception &e) {
cerr << e.what() << endl;
return false;
}
return false;
}
bool ContentManager::RemoveBookById(string &id) {
try {
return this->manager.removeBookById(id.c_str());
} catch (exception &e) {
cerr << e.what() << endl;
return false;
}
return false;
}
bool ContentManager::SetCurrentBookId(string &id) {
try {
return this->manager.setCurrentBookId(id.c_str());
} catch (exception &e) {
cerr << e.what() << endl;
return false;
}
return false;
}
string ContentManager::GetCurrentBookId() {
string none = "";
try {
return this->manager.getCurrentBookId();
} catch (exception &e) {
cerr << e.what() << endl;
return none;
}
return none;
}
bool ContentManager::GetBookById(string &id,
string &path,
string &title,
string &indexPath,
string &indexType,
string &description,
string &articleCount,
string &mediaCount,
string &size,
string &creator,
string &date,
string &language,
string &favicon,
string &url) {
try {
kiwix::Book book;
if (this->manager.getBookById(id.c_str(), book)) {
path = book.pathAbsolute.data();
title = book.title.data();
indexPath = book.indexPathAbsolute.data();
articleCount = book.articleCount.data();
mediaCount = book.mediaCount.data();
size = book.size.data();
creator = book.creator.data();
date = book.date.data();
language = book.language.data();
url = book.url.data();
string faviconUrl = "";
if (!book.faviconMimeType.empty()) {
faviconUrl = "url(data:" + book.faviconMimeType + ";base64," + book.favicon + ")";
}
favicon = faviconUrl.data();
string indexTypeString = "";
if (book.indexType == kiwix::XAPIAN) {
indexTypeString = "xapian";
}
indexType = indexTypeString.data();
description = book.description.data();
return true;
}
} catch (exception &e) {
cerr << e.what() << endl;
return false;
}
return false;
}
bool ContentManager::UpdateBookLastOpenDateById(string &id) {
try {
return this->manager.updateBookLastOpenDateById(id.c_str());
} catch (exception &e) {
cerr << e.what() << endl;
return false;
}
return false;
}
unsigned int ContentManager::GetBookCount(const bool localBooks, const bool remoteBooks) {
int count = 0;
try {
return this->manager.getBookCount(localBooks, remoteBooks);
} catch (exception &e) {
cerr << e.what() << endl;
return count;
}
return count;
}
bool ContentManager::ListBooks(string &mode, string &sortBy, unsigned int maxSize,
string &language, string &publisher, string &search) {
try {
// Set the mode enum
kiwix::supportedListMode listMode;
if (mode == "lastOpen") {
listMode = kiwix::LASTOPEN;
} else if ( mode == "remote") {
listMode = kiwix::REMOTE;
} else {
listMode = kiwix::LOCAL;
}
// Set the sortBy enum
kiwix::supportedListSortBy listSortBy;
if (sortBy == "publisher") {
listSortBy = kiwix::PUBLISHER;
} else if ( sortBy == "date") {
listSortBy = kiwix::DATE;
} else if ( sortBy == "size") {
listSortBy = kiwix::SIZE;
} else {
listSortBy = kiwix::TITLE;
}
return this->manager.listBooks(listMode, listSortBy, maxSize, language.c_str(), publisher.c_str(), search.c_str());
} catch (exception &e) {
cerr << e.what() << endl;
}
return false;
}
const char* ContentManager::GetListNextBookId() {
string id;
try {
if (!this->manager.bookIdList.empty()) {
id = *(this->manager.bookIdList.begin());
this->manager.bookIdList.erase(this->manager.bookIdList.begin());
}
} catch (exception &e) {
cerr << e.what() << endl;
}
return id.c_str();
}
bool ContentManager::SetBookIndex(string &id, string &path, string &indexType) {
try {
kiwix::supportedIndexType iType;
iType = kiwix::XAPIAN;
return this->manager.setBookIndex(id.c_str(), path.c_str(), iType);
} catch (exception &e) {
cerr << e.what() << endl;
}
return false;
}
bool ContentManager::SetBookPath(string &id, string &path) {
try {
return this->manager.setBookPath(id.c_str(), path.c_str());
} catch (exception &e) {
cerr << e.what() << endl;
}
return false;
}
string ContentManager::GetBooksLanguages() {
string languagesStr = "";
vector<string> booksLanguages = this->manager.getBooksLanguages();
vector<string>::iterator itr;
for ( itr = booksLanguages.begin(); itr != booksLanguages.end(); ++itr ) {
languagesStr += *itr + ";";
}
return languagesStr;
}
string ContentManager::GetBooksPublishers() {
string publishersStr = "";
vector<string> booksPublishers = this->manager.getBooksPublishers();
vector<string>::iterator itr;
for ( itr = booksPublishers.begin(); itr != booksPublishers.end(); ++itr ) {
publishersStr += *itr + ";";
}
return publishersStr;
}

View File

@ -1,285 +0,0 @@
/*
* Copyright 2012-2014
* Renaud Gaudin <reg@kiwix.org>
* Emmanuel Engelhart <kelson@kiwix.org>
*
* 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.
*/
#ifdef _WIN32
#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )
#include <Windows.h>
#include <process.h>
#define EXEXT ".exe"
#define EXECL _execl
#define PUTENV _putenv
#else
#define EXEXT ""
#include <stdlib.h>
#include <unistd.h>
#define EXECL execl
#define PUTENV putenv
#endif
#include <vector>
#include "pathTools.h"
using namespace std;
/* Split string in a token array */
std::vector<std::string> split(const std::string & str,
const std::string & delims=" *-")
{
std::string::size_type lastPos = str.find_first_not_of(delims, 0);
std::string::size_type pos = str.find_first_of(delims, lastPos);
std::vector<std::string> tokens;
while (std::string::npos != pos || std::string::npos != lastPos)
{
tokens.push_back(str.substr(lastPos, pos - lastPos));
lastPos = str.find_first_not_of(delims, pos);
pos = str.find_first_of(delims, lastPos);
}
return tokens;
}
/* Quote string on Windows */
char *prepareArgument(const char *argument) {
if (argument != NULL) {
#ifdef _WIN32
string quotedArgument = "\"" + string(argument) + "\"";
return strdup(quotedArgument.c_str());
#else
return strdup(argument);
#endif
} else {
return NULL;
}
}
int main(int argc, char *argv[]) {
/* Initialisation of a few paths */
string executablePath = getExecutablePath();
string executableDirectory = removeLastPathElement(executablePath);
/* Possible xulrunner paths */
std::vector<std::string> xulrunnerPossibleDirectories;
std::vector<std::string>::iterator directoriesIt;
/* Possible xulrunner paths: local directories */
xulrunnerPossibleDirectories.push_back(computeAbsolutePath(executableDirectory, "xulrunner"));
xulrunnerPossibleDirectories.push_back(computeAbsolutePath(executableDirectory, "kiwix/xulrunner"));
xulrunnerPossibleDirectories.push_back(computeAbsolutePath(executableDirectory, "kiwix-linux/xulrunner"));
xulrunnerPossibleDirectories.push_back(computeAbsolutePath(executableDirectory, "kiwix-win/xulrunner"));
xulrunnerPossibleDirectories.push_back(computeAbsolutePath(executableDirectory, "kiwix-windows/xulrunner"));
/* Possible xulrunner paths: system directories */
string binaryPath = getenv("PATH") == NULL ? "" : string(getenv("PATH"));
std::vector<std::string> xulrunnerPossibleSystemDirectories = ::split(binaryPath, ":");
for (directoriesIt = xulrunnerPossibleSystemDirectories.begin() ;
directoriesIt != xulrunnerPossibleSystemDirectories.end() ;
directoriesIt++) {
xulrunnerPossibleDirectories.push_back(*directoriesIt);
}
/* Possible xulrunner binary names */
std::vector<std::string> xulrunnerPossibleNames;
xulrunnerPossibleNames.push_back(std::string("xulrunner") + std::string(EXEXT));
xulrunnerPossibleNames.push_back(std::string("xulrunner-bin") + std::string(EXEXT));
xulrunnerPossibleNames.push_back(std::string("xulrunner-") + std::string(GECKO_VERSION));
xulrunnerPossibleNames.push_back(std::string("xulrunner-") + std::string(GECKO_VERSION) +
std::string(".0"));
xulrunnerPossibleNames.push_back(std::string("xulrunner-") + std::string(MAJOR_GECKO_VERSION));
xulrunnerPossibleNames.push_back(std::string("xulrunner-") + std::string(MINOR_GECKO_VERSION));
/* Find xulrunner (binary) path */
string xulrunnerPath;
std::vector<std::string>::iterator filesIt;
directoriesIt = xulrunnerPossibleDirectories.begin();
while (xulrunnerPath.empty() && directoriesIt != xulrunnerPossibleDirectories.end()) {
if (fileExists(*directoriesIt)) {
filesIt = xulrunnerPossibleNames.begin();
while (xulrunnerPath.empty() &&
filesIt != xulrunnerPossibleNames.end()) {
xulrunnerPath = computeAbsolutePath(*directoriesIt, *filesIt);
if (!fileExists(xulrunnerPath)) {
xulrunnerPath.clear();
}
filesIt++;
};
}
directoriesIt++;
}
if (!fileExists(xulrunnerPath)) {
perror("Error: unable to find the xulrunner binary.");
return EXIT_FAILURE;
}
/* Compute xulrunner directory */
string xulrunnerDirectory = removeLastPathElement(xulrunnerPath);
/* Compute application.ini path */
std::vector<std::string> applicationIniPossiblePaths;
applicationIniPossiblePaths.push_back(computeAbsolutePath(executableDirectory,
"application.ini"));
applicationIniPossiblePaths.push_back(computeAbsolutePath(executableDirectory,
"kiwix/application.ini"));
applicationIniPossiblePaths.push_back(computeAbsolutePath(executableDirectory,
"kiwix-linux/application.ini"));
applicationIniPossiblePaths.push_back(computeAbsolutePath(executableDirectory,
"kiwix-win/application.ini"));
applicationIniPossiblePaths.push_back(computeAbsolutePath(executableDirectory,
"kiwix-windows/application.ini"));
string applicationIniPath;
filesIt = applicationIniPossiblePaths.begin();
while (applicationIniPath.empty() &&
filesIt != applicationIniPossiblePaths.end()) {
if (fileExists(*filesIt)) {
applicationIniPath = *filesIt;
}
filesIt++;
};
if (!fileExists(xulrunnerPath)) {
perror("Error: unable to find the application.ini file.");
return EXIT_FAILURE;
}
/* Debug prints */
/*
cout << "Executable directory (executableDirectory): " << executableDirectory << endl;
cout << "Executable path (executablePath): " << executablePath << endl;
cout << "Xulrunner directory (xulrunnerDirectory): " << xulrunnerDirectory << endl;
cout << "Xulrunner path (xulrunnerPath): " << xulrunnerPath << endl;
cout << "Application.ini path (applicationIniPath): " << applicationIniPath << endl;
*/
/* Modify environnement variables */
#ifdef _WIN32
string sep = ";";
string execlArg0 = "kiwix-launcher.exe";
#else
string sep = ":";
string execlArg0 = xulrunnerPath.c_str();
#endif
string ldLibraryPath = getenv("LD_LIBRARY_PATH") == NULL ? "" : string(getenv("LD_LIBRARY_PATH"));
string putenvStr = "LD_LIBRARY_PATH=" + xulrunnerDirectory + sep + ldLibraryPath;
PUTENV((char *)putenvStr.c_str());
/* Launch xulrunner */
if (argc == 0) {
return EXECL(xulrunnerPath.c_str(),
execlArg0.c_str(),
prepareArgument(applicationIniPath.c_str()),
NULL);
} else if (argc == 1) {
return EXECL(xulrunnerPath.c_str(),
execlArg0.c_str(),
prepareArgument(applicationIniPath.c_str()),
prepareArgument(argv[1]),
NULL);
} else if (argc == 2) {
return EXECL(xulrunnerPath.c_str(),
execlArg0.c_str(),
prepareArgument(applicationIniPath.c_str()),
prepareArgument(argv[1]),
prepareArgument(argv[2]),
NULL);
} else if (argc == 3) {
return EXECL(xulrunnerPath.c_str(),
execlArg0.c_str(),
prepareArgument(applicationIniPath.c_str()),
prepareArgument(argv[1]),
prepareArgument(argv[2]),
prepareArgument(argv[3]),
NULL);
} else if (argc == 4) {
return EXECL(xulrunnerPath.c_str(),
execlArg0.c_str(),
prepareArgument(applicationIniPath.c_str()),
prepareArgument(argv[1]),
prepareArgument(argv[2]),
prepareArgument(argv[3]),
prepareArgument(argv[4]),
NULL);
} else if (argc == 5) {
return EXECL(xulrunnerPath.c_str(),
execlArg0.c_str(),
prepareArgument(applicationIniPath.c_str()),
prepareArgument(argv[1]),
prepareArgument(argv[2]),
prepareArgument(argv[3]),
prepareArgument(argv[4]),
prepareArgument(argv[5]),
NULL);
} else if (argc == 6) {
return EXECL(xulrunnerPath.c_str(),
execlArg0.c_str(),
prepareArgument(applicationIniPath.c_str()),
prepareArgument(argv[1]),
prepareArgument(argv[2]),
prepareArgument(argv[3]),
prepareArgument(argv[4]),
prepareArgument(argv[5]),
prepareArgument(argv[6]),
NULL);
} else if (argc == 7) {
return EXECL(xulrunnerPath.c_str(),
execlArg0.c_str(),
prepareArgument(applicationIniPath.c_str()),
prepareArgument(argv[1]),
prepareArgument(argv[2]),
prepareArgument(argv[3]),
prepareArgument(argv[4]),
prepareArgument(argv[5]),
prepareArgument(argv[6]),
prepareArgument(argv[7]),
NULL);
} else if (argc == 8) {
return EXECL(xulrunnerPath.c_str(),
execlArg0.c_str(),
prepareArgument(applicationIniPath.c_str()),
prepareArgument(argv[1]),
prepareArgument(argv[2]),
prepareArgument(argv[3]),
prepareArgument(argv[4]),
prepareArgument(argv[5]),
prepareArgument(argv[6]),
prepareArgument(argv[7]),
prepareArgument(argv[8]),
NULL);
} else if (argc >= 9) {
if (argc > 9) {
cerr << "Kiwix was not able to forward all your arguments to the xulrunner binary." << endl;
}
return EXECL(xulrunnerPath.c_str(),
execlArg0.c_str(),
prepareArgument(applicationIniPath.c_str()),
prepareArgument(argv[1]),
prepareArgument(argv[2]),
prepareArgument(argv[3]),
prepareArgument(argv[4]),
prepareArgument(argv[5]),
prepareArgument(argv[6]),
prepareArgument(argv[7]),
prepareArgument(argv[8]),
prepareArgument(argv[9]),
NULL);
}
}

View File

@ -1,52 +0,0 @@
.TH KIWIX 1 "12 June 2012"
.SH NAME
Kiwix \- Offline ZIM file reader
.SH SYNOPSIS
.B kiwix [-jsconsole] [-articleByUrl] [-articleByTitle] [FILE]
.SH DESCRIPTION
.PP
Kiwix is an offline content reader for the ZIM format.
.br
ZIM files are compressed content (usually HTML) archives.
.br
Most popular ZIM includes Wikipedia and Wikileaks.
.TP
\fB\-jsconsole\fR
Enable the Javascript Debug console (Xulrunner)
.TP
\fB\-articleByUrl url\fR
Open a specific article by url. FILE must be given.
.TP
\fB\-articleByTitle title\fR
Open a specific article by title. FILE must be given.
.PP
Features:
* Pure ZIM file reader
* Full text search engine
* Bookmarks & Notes
* ZIM base HTTP server
* PDF/HTML export
* Localized in 80+ languages
* Search suggestions
* ZIM file indexing capacity
* Tabs navigation
* Content manager
.SH SEE ALSO
kiwix-index(1) kiwix-install(1) kiwix-serve(1)
.br
kiwix-compact(1) kiwix-manage(1)
.SH TROUBLESHOOTING
See http://reportabug.kiwix.org for more details on how to report bugs in Kiwix.
.SH AUTHORS
Emmanuel Engelhart <kelson@kiwix.org>
Guillaume Duhamel <gduhamel@linterweb.com>
Fabien Coullon <fcoulon@linterweb.com>
Renaud Gaudin <rgaudin@gmail.com>
Wilfredo Rodriguez <wilfredor@kiwix.org>
.br
Vasudev Kamath <kamathvasudev@gmail.com> (Manual)

8
src/meson.build Normal file
View File

@ -0,0 +1,8 @@
#subdir('indexer')
#subdir('installer')
#subdir('manager')
#subdir('reader')
#subdir('searcher')
subdir('server')

View File

@ -62,11 +62,11 @@ extern "C" {
#include <kiwix/reader.h>
#include <kiwix/manager.h>
#include <kiwix/xapianSearcher.h>
#include <pathTools.h>
#include <regexTools.h>
#include <stringTools.h>
#include <otherTools.h>
#include <resourceTools.h>
#include <kiwix/common/pathTools.h>
#include <kiwix/common/regexTools.h>
#include <kiwix/common/stringTools.h>
#include <kiwix/common/otherTools.h>
#include <kiwix/common/resourceTools.h>
#ifndef _WIN32
#include <stdint.h>

3
src/server/meson.build Normal file
View File

@ -0,0 +1,3 @@
executable('kiwix-serve', ['kiwix-serve.cpp'],
dependencies:all_deps,
install:true)