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/.
16 //flags for handleArguments()
18 NONE
, Input
, Output
, MergeSrc
, Languages
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;
60 return false; // no valid command line
64 o_aHandledArgs
.m_sInputFile
= OString( argv
[i
] );
69 o_aHandledArgs
.m_sOutputFile
= OString( argv
[i
] );
74 o_aHandledArgs
.m_sMergeSrc
= OString( argv
[i
] );
77 case State::Languages
:
79 o_aHandledArgs
.m_sLanguage
= OString( argv
[i
] );
85 if( !o_aHandledArgs
.m_sInputFile
.isEmpty() &&
86 !o_aHandledArgs
.m_sOutputFile
.isEmpty() )
92 o_aHandledArgs
= HandledArgs();
97 void writeUsage(const OString
& rName
, const OString
& rFileType
)
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";
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";
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";
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: */