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