Merge branch 'master' of ssh://git.code.sf.net/p/kiwix/kiwix

This commit is contained in:
kelson42 2014-04-04 18:43:14 +02:00
commit 85620ed05e
4 changed files with 82 additions and 104 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2011 Emmanuel Engelhart <kelson@kiwix.org>
* Copyright 2009-2013 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
@ -26,8 +26,6 @@
#include <unistd.h>
#endif
enum supportedBackend { XAPIAN };
void usage() {
cout << "Usage: kiwix-index [--verbose] ZIM_PATH INDEX_PATH" << endl;
exit(1);
@ -41,33 +39,24 @@ int main(int argc, char **argv) {
bool verboseFlag = false;
int option_index = 0;
int c = 0;
supportedBackend backend = XAPIAN;
kiwix::Indexer *indexer = NULL;
kiwix::XapianIndexer *indexer = NULL;
/* Argument parsing */
while (42) {
static struct option long_options[] = {
{"verbose", no_argument, 0, 'v'},
{"backend", required_argument, 0, 'b'},
{0, 0, 0, 0}
};
if (c != -1) {
c = getopt_long(argc, argv, "vb:", long_options, &option_index);
c = getopt_long(argc, argv, "v", long_options, &option_index);
switch (c) {
case 'v':
verboseFlag = true;
break;
case 'b':
if (!strcmp(optarg, "xapian")) {
backend = XAPIAN;
} else {
usage();
}
break;
}
} else {
if (optind < argc) {
@ -104,11 +93,7 @@ int main(int argc, char **argv) {
while (indexer->isRunning()) {
if (verboseFlag)
cout << indexer->getProgression() << "% of all the articles indexed..." << endl;
#ifdef _WIN32
Sleep(1000);
#else
sleep(1);
#endif
kiwix::sleep(1000);
}
if (verboseFlag)
cout << "100% of the articles were successfuly indexed..." << endl;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2011 Emmanuel Engelhart <kelson@kiwix.org>
* Copyright 2011-2014 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
@ -20,18 +20,9 @@
#include <getopt.h>
#include <pathTools.h>
#include <kiwix/xapianIndexer.h>
#ifndef _WIN32
#include <unistd.h>
#else
#include <Windows.h>
#include <io.h>
#endif
#include <kiwix/reader.h>
#include <kiwix/manager.h>
enum supportedBackend { XAPIAN };
enum supportedAction { NONE, ADDCONTENT };
void usage() {
@ -49,7 +40,6 @@ int main(int argc, char **argv) {
bool buildIndexFlag = false;
int option_index = 0;
int c = 0;
supportedBackend backend = XAPIAN;
/* Argument parsing */
while (42) {
@ -57,12 +47,11 @@ int main(int argc, char **argv) {
static struct option long_options[] = {
{"verbose", no_argument, 0, 'v'},
{"buildIndex", no_argument, 0, 'i'},
{"backend", required_argument, 0, 'b'},
{0, 0, 0, 0}
};
if (c != -1) {
c = getopt_long(argc, argv, "vib:", long_options, &option_index);
c = getopt_long(argc, argv, "vi", long_options, &option_index);
switch (c) {
case 'v':
@ -71,13 +60,6 @@ int main(int argc, char **argv) {
case 'i':
buildIndexFlag = true;
break;
case 'b':
if (!strcmp(optarg, "xapian")) {
backend = XAPIAN;
} else {
usage();
}
break;
}
} else {
if (optind < argc) {
@ -174,7 +156,7 @@ int main(int argc, char **argv) {
string indexPath = computeAbsolutePath(dataIndexPath, indexFilename);
if (buildIndexFlag && !fileExists(indexPath)) {
if (verboseFlag) { std::cout << "Start indexing the ZIM file..." << std::endl; }
kiwix::Indexer *indexer = NULL;
kiwix::XapianIndexer *indexer = NULL;
try {
indexer = new kiwix::XapianIndexer();
} catch (...) {
@ -186,11 +168,7 @@ int main(int argc, char **argv) {
indexer->setVerboseFlag(verboseFlag);
indexer->start(contentPath, indexPath);
while (indexer->isRunning()) {
#ifdef _WIN32
Sleep(1000);
#else
sleep(1);
#endif
kiwix::sleep(1000);
}
delete indexer;
} else {

View File

@ -1,3 +1,23 @@
/*
* 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.
*/
#include <stdlib.h>
#include <unistd.h>
@ -6,86 +26,86 @@
using namespace std;
int main(int argc, char *argv[])
{
int main(int argc, char *argv[]) {
// find current binary path
string progpath = getExecutablePath();
string cwd = removeLastPathElement(progpath);
string ld_path = computeAbsolutePath(cwd, "xulrunner");
// retrieve existing env if exist.
string previous_env;
char *previous_env_buf = getenv("LD_LIBRARY_PATH");
if (previous_env_buf == NULL)
previous_env = "";
else
previous_env = string(previous_env_buf);
/* Initialisation of a few paths */
string executablePath = getExecutablePath();
string executableDirectory = removeLastPathElement(executablePath);
string applicationIniPath = computeAbsolutePath(executableDirectory, "application.ini");
/* Find xulrunner directory */
string xulrunnerDirectory = computeAbsolutePath(executableDirectory, "xulrunner");
if (!fileExists(xulrunnerDirectory)) {
xulrunnerDirectory = computeAbsolutePath(executableDirectory, "kiwix");
xulrunnerDirectory = computeAbsolutePath(executableDirectory, "xulrunner");
if (!fileExists(xulrunnerDirectory)) {
perror("Unable to find the xulrunner directory");
return EXIT_FAILURE;
}
}
/* Find xulrunner binary path */
string xulrunnerPath = computeAbsolutePath(xulrunnerDirectory, "xulrunner-bin");
if (!fileExists(xulrunnerPath)) {
xulrunnerPath = computeAbsolutePath(executableDirectory, "xulrunner");
if (!fileExists(xulrunnerPath)) {
perror("Unable to find neither the 'xulrunner-bin' nor the 'xulrunner' binary");
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 = ";";
#else
string sep = ":";
#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());
// generate putenv string
string env_str = "LD_LIBRARY_PATH=" + ld_path + sep + previous_env;
putenv((char *)env_str.c_str());
string xulrunner_path = computeAbsolutePath(cwd, "xulrunner/xulrunner-bin");
string application_ini = computeAbsolutePath(cwd, "application.ini");
//debug prints
/*
cout << "CurProg: " << progpath << endl;
cout << "cwd: " << cwd << endl;
cout << "LD path: " << ld_path << endl;
cout << "xulrunner_path: " << xulrunner_path << endl;
cout << "application_ini: " << application_ini << endl;
*/
// exist if xulrunner can't be found
if (!fileExists(xulrunner_path)) {
xulrunner_path = computeAbsolutePath(cwd, "xulrunner/xulrunner");
if (!fileExists(xulrunner_path)) {
perror("Unable to find neither the 'xulrunner-bin' nor the 'xulrunner' binary");
return EXIT_FAILURE;
}
}
// execute xulrunner
/* Launch xulrunner */
if (argc == 0) {
return execl(xulrunner_path.c_str(), xulrunner_path.c_str(), application_ini.c_str(),
return execl(xulrunnerPath.c_str(), xulrunnerPath.c_str(), applicationIniPath.c_str(),
"", NULL);
} else if (argc == 1) {
return execl(xulrunner_path.c_str(), xulrunner_path.c_str(), application_ini.c_str(),
return execl(xulrunnerPath.c_str(), xulrunnerPath.c_str(), applicationIniPath.c_str(),
argv[1], NULL);
} else if (argc == 2) {
return execl(xulrunner_path.c_str(), xulrunner_path.c_str(), application_ini.c_str(),
return execl(xulrunnerPath.c_str(), xulrunnerPath.c_str(), applicationIniPath.c_str(),
argv[1], argv[2], NULL);
} else if (argc == 3) {
return execl(xulrunner_path.c_str(), xulrunner_path.c_str(), application_ini.c_str(),
return execl(xulrunnerPath.c_str(), xulrunnerPath.c_str(), applicationIniPath.c_str(),
argv[1], argv[2], argv[3], NULL);
} else if (argc == 4) {
return execl(xulrunner_path.c_str(), xulrunner_path.c_str(), application_ini.c_str(),
return execl(xulrunnerPath.c_str(), xulrunnerPath.c_str(), applicationIniPath.c_str(),
argv[1], argv[2], argv[3], argv[4], NULL);
} else if (argc == 5) {
return execl(xulrunner_path.c_str(), xulrunner_path.c_str(), application_ini.c_str(),
return execl(xulrunnerPath.c_str(), xulrunnerPath.c_str(), applicationIniPath.c_str(),
argv[1], argv[2], argv[3], argv[4], argv[5], NULL);
} else if (argc == 6) {
return execl(xulrunner_path.c_str(), xulrunner_path.c_str(), application_ini.c_str(),
return execl(xulrunnerPath.c_str(), xulrunnerPath.c_str(), applicationIniPath.c_str(),
argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], NULL);
} else if (argc == 7) {
return execl(xulrunner_path.c_str(), xulrunner_path.c_str(), application_ini.c_str(),
return execl(xulrunnerPath.c_str(), xulrunnerPath.c_str(), applicationIniPath.c_str(),
argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], NULL);
} else if (argc == 8) {
return execl(xulrunner_path.c_str(), xulrunner_path.c_str(), application_ini.c_str(),
return execl(xulrunnerPath.c_str(), xulrunnerPath.c_str(), applicationIniPath.c_str(),
argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], NULL);
} else if (argc >= 9) {
if (argc>9) {
if (argc > 9) {
fprintf(stderr, "Kiwix was not able to forward all your arguments to the xulrunner binary.");
}
return execl(xulrunner_path.c_str(), xulrunner_path.c_str(), application_ini.c_str(),
return execl(xulrunnerPath.c_str(), xulrunnerPath.c_str(), applicationIniPath.c_str(),
argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], NULL);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2011-2012 Emmanuel Engelhart <kelson@kiwix.org>
* Copyright 2009-2014 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
@ -69,6 +69,7 @@ extern "C" {
#include <pathTools.h>
#include <regexTools.h>
#include <stringTools.h>
#include <otherTools.h>
#include <resourceTools.h>
using namespace std;
@ -503,12 +504,10 @@ int main(int argc, char **argv) {
} else if (!indexPath.empty()) {
vector<string> booksIds = libraryManager.getBooksIds();
kiwix::supportedIndexType indexType = kiwix::UNKNOWN;
bool hasSearchIndex = false;
/* Try with the XapianSearcher */
try {
new kiwix::XapianSearcher(indexPath);
hasSearchIndex = true;
indexType = kiwix::XAPIAN;
} catch (...) {
}
@ -664,11 +663,7 @@ int main(int argc, char **argv) {
}
}
#ifdef _WIN32
Sleep(1000);
#else
sleep(1);
#endif
kiwix::sleep(1000);
} while (waiting);
/* Stop the daemon */