Fix typo
[LibreOffice.git] / l10ntools / source / common.cxx
blob4cc9ba6405a9b6d412ad57ce6984dc21829e0ec9
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 <iostream>
12 #include <common.hxx>
14 namespace {
16 //flags for handleArguments()
17 enum class State {
18 NONE, Input, Output, MergeSrc, Languages
23 namespace common {
25 bool handleArguments(
26 int argc, char * argv[], HandledArgs& o_aHandledArgs)
28 o_aHandledArgs = HandledArgs();
29 State nState = State::NONE;
31 for( int i = 1; i < argc; i++ )
33 if ( OString( argv[ i ] ).toAsciiUpperCase() == "-I" )
35 nState = State::Input; // next token specifies source file
37 else if ( OString( argv[ i ] ).toAsciiUpperCase() == "-O" )
39 nState = State::Output; // next token specifies the dest file
41 else if ( OString( argv[ i ] ).toAsciiUpperCase() == "-M" )
43 nState = State::MergeSrc; // next token specifies the merge database
44 o_aHandledArgs.m_bMergeMode = true;
46 else if ( OString( argv[ i ] ).toAsciiUpperCase() == "-L" )
48 nState = State::Languages;
50 else if ( OString( argv[ i ] ).toAsciiUpperCase() == "-B" )
52 o_aHandledArgs.m_bUTF8BOM = true;
54 else
56 switch ( nState )
58 case State::NONE:
60 return false; // no valid command line
62 case State::Input:
64 o_aHandledArgs.m_sInputFile = OString( argv[i] );
66 break;
67 case State::Output:
69 o_aHandledArgs.m_sOutputFile = OString( argv[i] );
71 break;
72 case State::MergeSrc:
74 o_aHandledArgs.m_sMergeSrc = OString( argv[i] );
76 break;
77 case State::Languages:
79 o_aHandledArgs.m_sLanguage = OString( argv[i] );
81 break;
85 if( !o_aHandledArgs.m_sInputFile.isEmpty() &&
86 !o_aHandledArgs.m_sOutputFile.isEmpty() )
88 return true;
90 else
92 o_aHandledArgs = HandledArgs();
93 return false;
97 void writeUsage(const OString& rName, const OString& rFileType)
99 std::cout
100 << " Syntax: " << rName
101 << " -i FileIn -o FileOut [-m DataBase] [-l Lang] [-b]\n"
102 " FileIn: Source files (" << rFileType << ")\n"
103 " FileOut: Destination file (*.*)\n"
104 " DataBase: Mergedata (*.po)\n"
105 " Lang: Restrict the handled language; one element of\n"
106 " (de, en-US, ...) or all\n"
107 " -b: Add UTF-8 Byte Order Mark to FileOut(use with -m option)\n";
110 void writePoEntry(
111 const OString& rExecutable, PoOfstream& rPoStream, const OString& rSourceFile,
112 std::string_view rResType, const OString& rGroupId, const OString& rLocalId,
113 const OString& rHelpText, const OString& rText, const PoEntry::TYPE eType )
117 PoEntry aPO(rSourceFile, rResType, rGroupId, rLocalId, rHelpText, rText, eType);
118 rPoStream.writeEntry( aPO );
120 catch( PoEntry::Exception& aException )
122 if(aException == PoEntry::NOSOURCFILE)
124 std::cerr << rExecutable << " warning: no sourcefile specified for po entry\n";
126 else
128 std::cerr << rExecutable << " warning: invalid po attributes extracted from " << rSourceFile << "\n";
129 if(aException == PoEntry::NOGROUPID)
131 std::cerr << "No groupID specified!\n";
132 std::cerr << "String: " << rText << "\n";
134 else if (aException == PoEntry::NOSTRING)
136 std::cerr << "No string specified!\n";
137 std::cerr << "GroupID: " << rGroupId << "\n";
138 if( !rLocalId.isEmpty() ) std::cerr << "LocalID: " << rLocalId << "\n";
140 else
142 if (aException == PoEntry::NORESTYPE)
144 std::cerr << "No resource type specified!\n";
146 else if (aException == PoEntry::WRONGHELPTEXT)
148 std::cerr << "x-comment length is 5 characters:" << rHelpText << "\n";
151 std::cerr << "GroupID: " << rGroupId << "\n";
152 if( !rLocalId.isEmpty() ) std::cerr << "LocalID: " << rLocalId << "\n";
153 std::cerr << "String: " << rText << "\n";
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */