Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / helpcompiler / source / HelpIndexer_main.cxx
blob82822d897445a98626a5ccd692900796d030ad20
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <helpcompiler/HelpIndexer.hxx>
11 #include <osl/file.hxx>
12 #include <osl/process.h>
13 #include <osl/thread.h>
14 #include <string>
15 #include <iostream>
17 #include "LuceneHelper.hxx"
19 int main(int argc, char **argv)
21 try
23 const std::string aLang("-lang");
24 const std::string aModule("-mod");
25 const std::string aDir("-dir");
27 std::string lang;
28 std::string module;
29 std::string dir;
31 bool error = false;
32 for (int i = 1; i < argc; ++i) {
33 if (aLang.compare(argv[i]) == 0) {
34 if (i + 1 < argc) {
35 lang = argv[++i];
36 } else {
37 error = true;
39 } else if (aModule.compare(argv[i]) == 0) {
40 if (i + 1 < argc) {
41 module = argv[++i];
42 } else {
43 error = true;
45 } else if (aDir.compare(argv[i]) == 0) {
46 if (i + 1 < argc) {
47 dir = argv[++i];
48 } else {
49 error = true;
51 } else {
52 error = true;
56 if (error) {
57 std::cerr << "Error parsing command-line arguments" << std::endl;
60 if (error || lang.empty() || module.empty() || dir.empty()) {
61 std::cerr << "Usage: HelpIndexer -lang ISOLangCode -mod HelpModule -dir Dir" << std::endl;
62 return 1;
65 OUString sDir;
67 osl::File::getFileURLFromSystemPath(
68 OUString(dir.c_str(), dir.size(), osl_getThreadTextEncoding()),
69 sDir);
71 OUString cwd;
72 osl_getProcessWorkingDir(&cwd.pData);
74 osl::File::getAbsoluteFileURL(cwd, sDir, sDir);
76 HelpIndexer indexer(
77 OUString(lang.c_str(), lang.size(), osl_getThreadTextEncoding()),
78 OUString(module.c_str(), module.size(), osl_getThreadTextEncoding()),
79 sDir, sDir);
81 if (!indexer.indexDocuments()) {
82 std::cerr << OUStringToOString(indexer.getErrorMessage(), osl_getThreadTextEncoding()).getStr() << std::endl;
83 return 2;
85 return 0;
87 catch (std::exception& e)
89 std::cerr << "failure: " << e.what() << std::endl;
90 return 2;
94 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */