LibreOffice Module l10ntools (master) 1
helpex.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 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <sal/config.h>
21
22#include <iostream>
23#include <string>
24#include <cstring>
25
26#include <sal/main.h>
27
28#include <helpmerge.hxx>
29#include <common.hxx>
30#include <memory>
31
32#ifndef TESTDRIVER
33
34static void WriteUsage()
35{
36 std::cout
37 << (" Syntax: Helpex -[m]i FileIn -o FileOut [-m DataBase] [-l Lang]\n"
38 " FileIn + i: Source file (*.xhp)\n"
39 " FileIn + -mi: File including paths of source files"
40 " (only for merge)\n"
41 " FileOut: Destination file (*.*) or files (in case of -mi)\n"
42 " DataBase: Mergedata (*.po)\n"
43 " Lang: Restrict the handled languages; one element of\n"
44 " (de, en-US, ...) or all\n");
45}
46
48{
49 bool hasNoError = true;
50 try
51 {
52 bool bMultiMerge = false;
53 for (int nIndex = 1; nIndex != argc; ++nIndex)
54 {
55 if (std::strcmp(argv[nIndex], "-mi") == 0)
56 {
57 argv[nIndex][1] = 'i';
58 argv[nIndex][2] = '\0';
59 bMultiMerge = true;
60 break;
61 }
62 }
63
65 if ( !common::handleArguments( argc, argv, aArgs) )
66 {
67 WriteUsage();
68 return 1;
69 }
70
71 if ( aArgs.m_bMergeMode )
72 {
73 if( bMultiMerge )
74 {
75 std::ifstream aInput( aArgs.m_sInputFile.getStr() );
76 if( !aInput.is_open() )
77 {
78 std::cerr << "Helpex error: cannot open input file\n";
79 return 1;
80 }
81 std::unique_ptr<MergeDataFile> pMergeDataFile;
82 if( aArgs.m_sLanguage != "qtz")
83 {
84 pMergeDataFile.reset(new MergeDataFile(aArgs.m_sMergeSrc, "", false, false ));
85 }
86 std::string sTemp;
87 aInput >> sTemp;
88 while( !aInput.eof() )
89 {
90 // coverity[tainted_data] - this is a build time tool
91 const OString sXhpFile( sTemp.data(), static_cast<sal_Int32>(sTemp.length()) );
92 HelpParser aParser( sXhpFile );
93 const OString sOutput(
94 aArgs.m_sOutputFile +
95 sXhpFile.subView( sXhpFile.lastIndexOf('/') ));
96 if( !aParser.Merge( sOutput,
97 aArgs.m_sLanguage, pMergeDataFile.get() ))
98 {
99 hasNoError = false;
100 }
101 aInput >> sTemp;
102 }
103 aInput.close();
104 }
105 else
106 {
107 HelpParser aParser( aArgs.m_sInputFile );
108 std::unique_ptr<MergeDataFile> pMergeDataFile;
109 if( aArgs.m_sLanguage != "qtz")
110 {
111 pMergeDataFile.reset(new MergeDataFile(aArgs.m_sMergeSrc, aArgs.m_sInputFile, false, false ));
112 }
113 hasNoError =
114 aParser.Merge(
115 aArgs.m_sOutputFile,
116 aArgs.m_sLanguage, pMergeDataFile.get() );
117 }
118 }
119 else
120 {
121 HelpParser aParser( aArgs.m_sInputFile );
122 XMLFile xmlfile( OString('0') );
123 hasNoError =
125 aArgs.m_sOutputFile, aArgs.m_sInputFile,
126 &xmlfile, "help" );
127 }
128 }
129 catch (std::exception& e)
130 {
131 std::cerr << "Helpex exception: " << e.what() << std::endl;
132 hasNoError = true;
133 }
134
135 if( hasNoError )
136 return 0;
137 else
138 return 1;
139}
140#endif
141
142/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This Class is responsible for extracting/merging OpenOffice XML Helpfiles.
Definition: helpmerge.hxx:34
bool Merge(const OString &rDestinationFile_in, const OString &sLanguage, MergeDataFile *pMergeDataFile)
Method merges the String into XMLfile, which must point to an existing file.
Definition: helpmerge.cxx:138
static bool CreatePO(const OString &rPOFile_in, const OString &sHelpFile, XMLFile *pXmlFile, std::string_view rGsi1)
Method append a PO file with the content of a parsed XML file @PRECOND rHelpFile is valid.
Definition: helpmerge.cxx:75
Purpose: holds information of data to merge, read from PO file.
Definition: export.hxx:114
Holds information of a XML file, is root node of tree.
Definition: xmlparse.hxx:148
static void WriteUsage()
Definition: helpex.cxx:34
SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
Definition: helpex.cxx:47
sal_Int32 nIndex
bool handleArguments(int argc, char *argv[], HandledArgs &o_aHandledArgs)
Handle command line parameters.
Definition: common.cxx:25
Result type of handleArguments()
Definition: common.hxx:26
OString m_sMergeSrc
Definition: common.hxx:29
OString m_sOutputFile
Definition: common.hxx:28
OString m_sLanguage
Definition: common.hxx:30
OString m_sInputFile
Definition: common.hxx:27