Bump version to 21.06.18.1
[LibreOffice.git] / helpcompiler / source / HelpIndexer_main.cxx
blob3ad47bbf7a289f509cd809408e978b6b3ea1c40e
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 int main(int argc, char **argv)
19 try
21 const std::string aLang("-lang");
22 const std::string aModule("-mod");
23 const std::string aDir("-dir");
25 std::string lang;
26 std::string module;
27 std::string dir;
29 bool error = false;
30 for (int i = 1; i < argc; ++i) {
31 if (aLang.compare(argv[i]) == 0) {
32 if (i + 1 < argc) {
33 lang = argv[++i];
34 } else {
35 error = true;
37 } else if (aModule.compare(argv[i]) == 0) {
38 if (i + 1 < argc) {
39 module = argv[++i];
40 } else {
41 error = true;
43 } else if (aDir.compare(argv[i]) == 0) {
44 if (i + 1 < argc) {
45 dir = argv[++i];
46 } else {
47 error = true;
49 } else {
50 error = true;
54 if (error) {
55 std::cerr << "Error parsing command-line arguments" << std::endl;
58 if (error || lang.empty() || module.empty() || dir.empty()) {
59 std::cerr << "Usage: HelpIndexer -lang ISOLangCode -mod HelpModule -dir Dir" << std::endl;
60 return 1;
63 OUString sDir;
65 osl::File::getFileURLFromSystemPath(
66 OUString(dir.c_str(), dir.size(), osl_getThreadTextEncoding()),
67 sDir);
69 OUString cwd;
70 osl_getProcessWorkingDir(&cwd.pData);
72 (void)osl::File::getAbsoluteFileURL(cwd, sDir, sDir);
74 HelpIndexer indexer(
75 OUString(lang.c_str(), lang.size(), osl_getThreadTextEncoding()),
76 OUString(module.c_str(), module.size(), osl_getThreadTextEncoding()),
77 sDir, sDir);
79 if (!indexer.indexDocuments()) {
80 std::cerr << indexer.getErrorMessage() << std::endl;
81 return 2;
83 return 0;
85 catch (std::exception& e)
87 std::cerr << "failure: " << e.what() << std::endl;
88 return 2;
92 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */