Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : : *
5 : : * The contents of this file are subject to the Mozilla Public License Version
6 : : * 1.1 (the "License"); you may not use this file except in compliance with
7 : : * the License or as specified alternatively below. You may obtain a copy of
8 : : * the License at http://www.mozilla.org/MPL/
9 : : *
10 : : * Software distributed under the License is distributed on an "AS IS" basis,
11 : : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : : * for the specific language governing rights and limitations under the
13 : : * License.
14 : : *
15 : : * Major Contributor(s):
16 : : * Copyright (C) 2012 Gert van Valkenhoef <g.h.m.van.valkenhoef@rug.nl>
17 : : * (initial developer)
18 : : *
19 : : * All Rights Reserved.
20 : : *
21 : : * For minor contributions see the git repository.
22 : : *
23 : : * Alternatively, the contents of this file may be used under the terms of
24 : : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
25 : : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
26 : : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
27 : : * instead of those above.
28 : : */
29 : :
30 : : #include <l10ntools/HelpIndexer.hxx>
31 : : #include <osl/file.hxx>
32 : : #include <osl/process.h>
33 : : #include <osl/thread.h>
34 : : #include <string>
35 : : #include <iostream>
36 : :
37 : : #include "LuceneHelper.hxx"
38 : :
39 : 9 : int main(int argc, char **argv) {
40 [ + - ]: 9 : const std::string pLang("-lang");
41 [ + - ]: 9 : const std::string pModule("-mod");
42 [ + - ]: 9 : const std::string pDir("-dir");
43 : :
44 [ + - ]: 9 : std::string lang;
45 [ + - ]: 9 : std::string module;
46 [ + - ]: 9 : std::string dir;
47 : :
48 : 9 : bool error = false;
49 [ + + ]: 36 : for (int i = 1; i < argc; ++i) {
50 [ + - ][ + + ]: 27 : if (pLang.compare(argv[i]) == 0) {
51 [ + - ]: 9 : if (i + 1 < argc) {
52 [ + - ]: 9 : lang = argv[++i];
53 : : } else {
54 : 0 : error = true;
55 : : }
56 [ + - ][ + + ]: 18 : } else if (pModule.compare(argv[i]) == 0) {
57 [ + - ]: 9 : if (i + 1 < argc) {
58 [ + - ]: 9 : module = argv[++i];
59 : : } else {
60 : 0 : error = true;
61 : : }
62 [ + - ][ + - ]: 9 : } else if (pDir.compare(argv[i]) == 0) {
63 [ + - ]: 9 : if (i + 1 < argc) {
64 [ + - ]: 9 : dir = argv[++i];
65 : : } else {
66 : 0 : error = true;
67 : : }
68 : : } else {
69 : 0 : error = true;
70 : : }
71 : : }
72 : :
73 [ - + ]: 9 : if (error) {
74 [ # # ][ # # ]: 0 : std::cerr << "Error parsing command-line arguments" << std::endl;
75 : : }
76 : :
77 [ + - ][ + - ]: 9 : if (error || lang.empty() || module.empty() || dir.empty()) {
[ + - ][ - + ]
[ - + ]
78 [ # # ][ # # ]: 0 : std::cerr << "Usage: HelpIndexer -lang ISOLangCode -mod HelpModule -dir Dir" << std::endl;
79 : 0 : return 1;
80 : : }
81 : :
82 [ + - ][ + - ]: 9 : std::string captionDir(dir + SAL_PATHDELIMITER + "caption");
83 [ + - ][ + - ]: 9 : std::string contentDir(dir + SAL_PATHDELIMITER + "content");
84 [ + - ][ + - ]: 9 : std::string indexDir(dir + SAL_PATHDELIMITER + module + ".idxl");
[ + - ]
85 : :
86 : 9 : rtl::OUString sDir;
87 : :
88 : : osl::File::getFileURLFromSystemPath(
89 [ + - ]: 9 : rtl::OUString(dir.c_str(), dir.size(), osl_getThreadTextEncoding()),
90 [ + - ][ + - ]: 9 : sDir);
91 : :
92 : 9 : rtl::OUString cwd;
93 [ + - ]: 9 : osl_getProcessWorkingDir(&cwd.pData);
94 : :
95 [ + - ]: 9 : osl::File::getAbsoluteFileURL(cwd, sDir, sDir);
96 : :
97 : : HelpIndexer indexer(
98 [ + - ]: 9 : rtl::OUString(lang.c_str(), lang.size(), osl_getThreadTextEncoding()),
99 [ + - ]: 9 : rtl::OUString(module.c_str(), module.size(), osl_getThreadTextEncoding()),
100 [ + - ]: 18 : sDir, sDir);
[ + - + - ]
101 : :
102 [ - + ][ + - ]: 9 : if (!indexer.indexDocuments()) {
103 [ # # ][ # # ]: 0 : std::cerr << rtl::OUStringToOString(indexer.getErrorMessage(), osl_getThreadTextEncoding()).getStr() << std::endl;
[ # # ][ # # ]
[ # # ]
104 : 0 : return 2;
105 : : }
106 [ + - ]: 9 : return 0;
107 [ + - ][ + - ]: 27 : }
108 : :
109 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|