diff --git a/src/indexer/kiwix-index.cpp b/src/indexer/kiwix-index.cpp index c106b29..e797346 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 @@ -26,8 +26,6 @@ #include #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; diff --git a/src/installer/kiwix-install.cpp b/src/installer/kiwix-install.cpp index 61a14c4..06f5a1e 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,18 +20,9 @@ #include #include #include - -#ifndef _WIN32 -#include -#else -#include -#include -#endif - #include #include -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 { 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); } } diff --git a/src/server/kiwix-serve.cpp b/src/server/kiwix-serve.cpp index ee4cc5b..627633e 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 @@ -69,6 +69,7 @@ extern "C" { #include #include #include +#include #include using namespace std; @@ -503,12 +504,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 (...) { } @@ -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 */