LibreOffice Module helpcompiler (master) 1
HelpIndexer_main.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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 */
9
11#include <osl/file.hxx>
12#include <osl/process.h>
13#include <osl/thread.h>
14#include <string>
15#include <iostream>
16
17int main(int argc, char **argv)
18{
19 try
20 {
21 const std::string aLang("-lang");
22 const std::string aModule("-mod");
23 const std::string aDir("-dir");
24
25 std::string lang;
26 std::string module;
27 std::string dir;
28
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;
36 }
37 } else if (aModule.compare(argv[i]) == 0) {
38 if (i + 1 < argc) {
39 module = argv[++i];
40 } else {
41 error = true;
42 }
43 } else if (aDir.compare(argv[i]) == 0) {
44 if (i + 1 < argc) {
45 dir = argv[++i];
46 } else {
47 error = true;
48 }
49 } else {
50 error = true;
51 }
52 }
53
54 if (error) {
55 std::cerr << "Error parsing command-line arguments" << std::endl;
56 }
57
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;
61 }
62
63 OUString sDir;
64
65 osl::File::getFileURLFromSystemPath(
66 OUString(dir.c_str(), dir.size(), osl_getThreadTextEncoding()),
67 sDir);
68
69 OUString cwd;
70 osl_getProcessWorkingDir(&cwd.pData);
71
72 (void)osl::File::getAbsoluteFileURL(cwd, sDir, sDir);
73
74 HelpIndexer indexer(
75 OUString(lang.c_str(), lang.size(), osl_getThreadTextEncoding()),
76 OUString(module.c_str(), module.size(), osl_getThreadTextEncoding()),
77 sDir, sDir);
78
79 if (!indexer.indexDocuments()) {
80 std::cerr << indexer.getErrorMessage() << std::endl;
81 return 2;
82 }
83 return 0;
84 }
85 catch (std::exception& e)
86 {
87 std::cerr << "failure: " << e.what() << std::endl;
88 return 2;
89 }
90}
91
92/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
int main(int argc, char **argv)
bool indexDocuments()
Run the indexer.
Definition: HelpIndexer.cxx:74
OUString const & getErrorMessage() const
Get the error string (empty if no error occurred).
Definition: HelpIndexer.hxx:63
int i
module