tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / l10ntools / source / helpex.cxx
bloba5406d9b9c71f0e8fa2e3eb258c926dc934c095a
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
22 #include <iostream>
23 #include <string>
24 #include <cstring>
26 #include <sal/main.h>
28 #include <helpmerge.hxx>
29 #include <common.hxx>
30 #include <memory>
32 #ifndef TESTDRIVER
34 static void WriteUsage()
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");
47 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
49 bool hasNoError = true;
50 try
52 bool bMultiMerge = false;
53 for (int nIndex = 1; nIndex != argc; ++nIndex)
55 if (std::strcmp(argv[nIndex], "-mi") == 0)
57 argv[nIndex][1] = 'i';
58 argv[nIndex][2] = '\0';
59 bMultiMerge = true;
60 break;
64 common::HandledArgs aArgs;
65 if ( !common::handleArguments( argc, argv, aArgs) )
67 WriteUsage();
68 return 1;
71 if ( aArgs.m_bMergeMode )
73 if( bMultiMerge )
75 std::ifstream aInput( aArgs.m_sInputFile.getStr() );
76 if( !aInput.is_open() )
78 std::cerr << "Helpex error: cannot open input file\n";
79 return 1;
81 std::unique_ptr<MergeDataFile> pMergeDataFile;
82 if( aArgs.m_sLanguage != "qtz")
84 pMergeDataFile.reset(new MergeDataFile(aArgs.m_sMergeSrc, "", false, false ));
86 std::string sTemp;
87 while ( aInput >> sTemp )
89 // coverity[tainted_data] - this is a build time tool
90 const OString sXhpFile( sTemp.data(), static_cast<sal_Int32>(sTemp.length()) );
91 HelpParser aParser( sXhpFile );
92 const OString sOutput(
93 aArgs.m_sOutputFile +
94 sXhpFile.subView( sXhpFile.lastIndexOf('/') ));
95 if( !aParser.Merge( sOutput,
96 aArgs.m_sLanguage, pMergeDataFile.get() ))
98 hasNoError = false;
101 aInput.close();
103 else
105 HelpParser aParser( aArgs.m_sInputFile );
106 std::unique_ptr<MergeDataFile> pMergeDataFile;
107 if( aArgs.m_sLanguage != "qtz")
109 pMergeDataFile.reset(new MergeDataFile(aArgs.m_sMergeSrc, aArgs.m_sInputFile, false, false ));
111 hasNoError =
112 aParser.Merge(
113 aArgs.m_sOutputFile,
114 aArgs.m_sLanguage, pMergeDataFile.get() );
117 else
119 HelpParser aParser( aArgs.m_sInputFile );
120 XMLFile xmlfile( OString('0') );
121 hasNoError =
122 HelpParser::CreatePO(
123 aArgs.m_sOutputFile, aArgs.m_sInputFile,
124 &xmlfile, "help" );
127 catch (std::exception& e)
129 std::cerr << "Helpex exception: " << e.what() << std::endl;
130 hasNoError = true;
133 if( hasNoError )
134 return 0;
135 else
136 return 1;
138 #endif
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */