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

pull/9/head
kelson42 12 years ago
commit 85620ed05e

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

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

@ -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 <stdlib.h>
#include <unistd.h> #include <unistd.h>
@ -6,86 +26,86 @@
using namespace std; using namespace std;
int main(int argc, char *argv[]) int main(int argc, char *argv[]) {
{
// find current binary path /* Initialisation of a few paths */
string progpath = getExecutablePath(); string executablePath = getExecutablePath();
string cwd = removeLastPathElement(progpath); string executableDirectory = removeLastPathElement(executablePath);
string ld_path = computeAbsolutePath(cwd, "xulrunner"); string applicationIniPath = computeAbsolutePath(executableDirectory, "application.ini");
// retrieve existing env if exist. /* Find xulrunner directory */
string previous_env; string xulrunnerDirectory = computeAbsolutePath(executableDirectory, "xulrunner");
char *previous_env_buf = getenv("LD_LIBRARY_PATH"); if (!fileExists(xulrunnerDirectory)) {
if (previous_env_buf == NULL) xulrunnerDirectory = computeAbsolutePath(executableDirectory, "kiwix");
previous_env = ""; xulrunnerDirectory = computeAbsolutePath(executableDirectory, "xulrunner");
else if (!fileExists(xulrunnerDirectory)) {
previous_env = string(previous_env_buf); 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 #ifdef _WIN32
string sep = ";"; string sep = ";";
#else #else
string sep = ":"; string sep = ":";
#endif #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 /* Launch xulrunner */
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
if (argc == 0) { 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); "", NULL);
} else if (argc == 1) { } 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); argv[1], NULL);
} else if (argc == 2) { } 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); argv[1], argv[2], NULL);
} else if (argc == 3) { } 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); argv[1], argv[2], argv[3], NULL);
} else if (argc == 4) { } 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); argv[1], argv[2], argv[3], argv[4], NULL);
} else if (argc == 5) { } 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); argv[1], argv[2], argv[3], argv[4], argv[5], NULL);
} else if (argc == 6) { } 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); argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], NULL);
} else if (argc == 7) { } 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); argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], NULL);
} else if (argc == 8) { } 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); argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], NULL);
} else if (argc >= 9) { } 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."); 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); argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], NULL);
} }
} }

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

Loading…
Cancel
Save