From 5b3448c4414be6f66e66b776e94542e02f7aea2a Mon Sep 17 00:00:00 2001 From: kelson42 Date: Wed, 2 Apr 2014 11:35:28 +0200 Subject: [PATCH 01/12] + Beautification of the code --- src/launcher/kiwix-launcher.cpp | 122 +++++++++++++++++++------------- 1 file changed, 71 insertions(+), 51 deletions(-) diff --git a/src/launcher/kiwix-launcher.cpp b/src/launcher/kiwix-launcher.cpp index f43a59d..572c51d 100644 --- a/src/launcher/kiwix-launcher.cpp +++ b/src/launcher/kiwix-launcher.cpp @@ -1,3 +1,23 @@ +/* + * Copyright 2012-2014 + * Renaud Gaudin + * 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 #include @@ -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); } } From c2f02bf14990560afc5b848e885a092341b3f1a3 Mon Sep 17 00:00:00 2001 From: kelson42 Date: Wed, 2 Apr 2014 11:55:34 +0200 Subject: [PATCH 02/12] + Change license header --- src/indexer/kiwix-index.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/indexer/kiwix-index.cpp b/src/indexer/kiwix-index.cpp index c106b29..85c1ce5 100644 --- a/src/indexer/kiwix-index.cpp +++ b/src/indexer/kiwix-index.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2011 Emmanuel Engelhart + * Copyright 2009-2013 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 From ef6d5bc0552f6c71a814e9dd181cb44398434213 Mon Sep 17 00:00:00 2001 From: kelson42 Date: Wed, 2 Apr 2014 15:36:37 +0200 Subject: [PATCH 03/12] + update coypright header --- src/server/kiwix-serve.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/kiwix-serve.cpp b/src/server/kiwix-serve.cpp index ee4cc5b..963157a 100644 --- a/src/server/kiwix-serve.cpp +++ b/src/server/kiwix-serve.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2011-2012 Emmanuel Engelhart + * Copyright 2009-2014 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 From 9a00b7c1d403dd2bdd8571f1d989ade22aa0af07 Mon Sep 17 00:00:00 2001 From: kelson42 Date: Wed, 2 Apr 2014 16:18:06 +0200 Subject: [PATCH 04/12] + remove unused variable --- src/server/kiwix-serve.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/server/kiwix-serve.cpp b/src/server/kiwix-serve.cpp index 963157a..ebb70a7 100644 --- a/src/server/kiwix-serve.cpp +++ b/src/server/kiwix-serve.cpp @@ -503,12 +503,10 @@ int main(int argc, char **argv) { } else if (!indexPath.empty()) { vector 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 (...) { } From 334985505994a3fa664be9623f4afc9f2854a9bf Mon Sep 17 00:00:00 2001 From: kelson42 Date: Wed, 2 Apr 2014 16:26:09 +0200 Subject: [PATCH 05/12] + Remove last traces of CLUCENE backend support --- src/indexer/kiwix-index.cpp | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/indexer/kiwix-index.cpp b/src/indexer/kiwix-index.cpp index 85c1ce5..4f2035e 100644 --- a/src/indexer/kiwix-index.cpp +++ b/src/indexer/kiwix-index.cpp @@ -26,8 +26,6 @@ #include #endif -enum supportedBackend { XAPIAN }; - void usage() { cout << "Usage: kiwix-index [--verbose] ZIM_PATH INDEX_PATH" << endl; exit(1); @@ -41,7 +39,6 @@ int main(int argc, char **argv) { bool verboseFlag = false; int option_index = 0; int c = 0; - supportedBackend backend = XAPIAN; kiwix::Indexer *indexer = NULL; @@ -50,24 +47,16 @@ int main(int argc, char **argv) { 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) { From 50020339879f0f2f78a1953afc6b88ba52b36cba Mon Sep 17 00:00:00 2001 From: kelson42 Date: Wed, 2 Apr 2014 16:38:59 +0200 Subject: [PATCH 06/12] + Use directly "KiwixIndexer" instead of "Indexer" --- src/indexer/kiwix-index.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/indexer/kiwix-index.cpp b/src/indexer/kiwix-index.cpp index 4f2035e..8b9950f 100644 --- a/src/indexer/kiwix-index.cpp +++ b/src/indexer/kiwix-index.cpp @@ -40,7 +40,7 @@ int main(int argc, char **argv) { int option_index = 0; int c = 0; - kiwix::Indexer *indexer = NULL; + kiwix::XapianIndexer *indexer = NULL; /* Argument parsing */ while (42) { From a768ecbf2998bfb12d608c6de8ec8dc28b72b7e6 Mon Sep 17 00:00:00 2001 From: kelson42 Date: Wed, 2 Apr 2014 16:55:17 +0200 Subject: [PATCH 07/12] + use kiwix:sleep() --- src/indexer/kiwix-index.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/indexer/kiwix-index.cpp b/src/indexer/kiwix-index.cpp index 8b9950f..08a4873 100644 --- a/src/indexer/kiwix-index.cpp +++ b/src/indexer/kiwix-index.cpp @@ -18,6 +18,7 @@ */ #include +#include #include #ifdef _WIN32 @@ -93,11 +94,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; From fe36cd5822770614831d3e9fb521c9570d63e90b Mon Sep 17 00:00:00 2001 From: kelson42 Date: Wed, 2 Apr 2014 17:03:15 +0200 Subject: [PATCH 08/12] + remove useless #include --- src/indexer/kiwix-index.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/indexer/kiwix-index.cpp b/src/indexer/kiwix-index.cpp index 08a4873..e797346 100644 --- a/src/indexer/kiwix-index.cpp +++ b/src/indexer/kiwix-index.cpp @@ -18,7 +18,6 @@ */ #include -#include #include #ifdef _WIN32 From cd20c8c027714ac45231bc633c7087d3ee6dcae5 Mon Sep 17 00:00:00 2001 From: kelson42 Date: Wed, 2 Apr 2014 17:08:33 +0200 Subject: [PATCH 09/12] + use now kiwix::sleep() --- src/installer/kiwix-install.cpp | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/installer/kiwix-install.cpp b/src/installer/kiwix-install.cpp index 61a14c4..4372233 100644 --- a/src/installer/kiwix-install.cpp +++ b/src/installer/kiwix-install.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2011 Emmanuel Engelhart + * Copyright 2011-2014 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 @@ -20,14 +20,6 @@ #include #include #include - -#ifndef _WIN32 -#include -#else -#include -#include -#endif - #include #include @@ -186,11 +178,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 { From ce4a4ee6d39e540cdfad3a089e69238343932e45 Mon Sep 17 00:00:00 2001 From: kelson42 Date: Wed, 2 Apr 2014 17:10:35 +0200 Subject: [PATCH 10/12] + remove old backend stuff --- src/installer/kiwix-install.cpp | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/installer/kiwix-install.cpp b/src/installer/kiwix-install.cpp index 4372233..2f5a6ff 100644 --- a/src/installer/kiwix-install.cpp +++ b/src/installer/kiwix-install.cpp @@ -23,7 +23,6 @@ #include #include -enum supportedBackend { XAPIAN }; enum supportedAction { NONE, ADDCONTENT }; void usage() { @@ -41,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) { @@ -49,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': @@ -63,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) { From 2c03199e1b47b3464e8abc08ae81357abf1f48b4 Mon Sep 17 00:00:00 2001 From: kelson42 Date: Wed, 2 Apr 2014 17:11:40 +0200 Subject: [PATCH 11/12] + Fix compilation warning --- src/installer/kiwix-install.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/installer/kiwix-install.cpp b/src/installer/kiwix-install.cpp index 2f5a6ff..06f5a1e 100644 --- a/src/installer/kiwix-install.cpp +++ b/src/installer/kiwix-install.cpp @@ -156,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 (...) { From 9cc083aaa92b2157bf82560116a52157f3e1f89f Mon Sep 17 00:00:00 2001 From: kelson42 Date: Wed, 2 Apr 2014 17:15:45 +0200 Subject: [PATCH 12/12] + use kiwix::sleep() --- src/server/kiwix-serve.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/server/kiwix-serve.cpp b/src/server/kiwix-serve.cpp index ebb70a7..627633e 100644 --- a/src/server/kiwix-serve.cpp +++ b/src/server/kiwix-serve.cpp @@ -69,6 +69,7 @@ extern "C" { #include #include #include +#include #include using namespace std; @@ -662,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 */