1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
14 //flags for handleArguments()
16 NONE
, Input
, Output
, MergeSrc
, Languages
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;
58 return false; // no valid command line
62 o_aHandledArgs
.m_sInputFile
= OString( argv
[i
] );
67 o_aHandledArgs
.m_sOutputFile
= OString( argv
[i
] );
72 o_aHandledArgs
.m_sMergeSrc
= OString( argv
[i
] );
75 case State::Languages
:
77 o_aHandledArgs
.m_sLanguage
= OString( argv
[i
] );
83 if( !o_aHandledArgs
.m_sInputFile
.isEmpty() &&
84 !o_aHandledArgs
.m_sOutputFile
.isEmpty() )
90 o_aHandledArgs
= HandledArgs();
95 void writeUsage(const OString
& rName
, const OString
& rFileType
)
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";
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";
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";
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: */