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/.
12 //flags for handleArguments()
13 #define STATE_NON 0x0001
14 #define STATE_INPUT 0x0002
15 #define STATE_OUTPUT 0x0003
16 #define STATE_MERGESRC 0x0005
17 #define STATE_LANGUAGES 0x0006
22 int argc
, char * argv
[], HandledArgs
& o_aHandledArgs
)
24 o_aHandledArgs
= HandledArgs();
25 sal_uInt16 nState
= STATE_NON
;
27 for( int i
= 1; i
< argc
; i
++ )
29 if ( OString( argv
[ i
] ).toAsciiUpperCase() == "-I" )
31 nState
= STATE_INPUT
; // next token specifies source file
33 else if ( OString( argv
[ i
] ).toAsciiUpperCase() == "-O" )
35 nState
= STATE_OUTPUT
; // next token specifies the dest file
37 else if ( OString( argv
[ i
] ).toAsciiUpperCase() == "-M" )
39 nState
= STATE_MERGESRC
; // next token specifies the merge database
40 o_aHandledArgs
.m_bMergeMode
= true;
42 else if ( OString( argv
[ i
] ).toAsciiUpperCase() == "-L" )
44 nState
= STATE_LANGUAGES
;
46 else if ( OString( argv
[ i
] ).toAsciiUpperCase() == "-B" )
48 o_aHandledArgs
.m_bUTF8BOM
= true;
56 return false; // no valid command line
60 o_aHandledArgs
.m_sInputFile
= OString( argv
[i
] );
65 o_aHandledArgs
.m_sOutputFile
= OString( argv
[i
] );
70 o_aHandledArgs
.m_sMergeSrc
= OString( argv
[i
] );
75 o_aHandledArgs
.m_sLanguage
= OString( argv
[i
] );
81 if( !o_aHandledArgs
.m_sInputFile
.isEmpty() &&
82 !o_aHandledArgs
.m_sOutputFile
.isEmpty() )
88 o_aHandledArgs
= HandledArgs();
93 void writeUsage(const OString
& rName
, const OString
& rFileType
)
96 << " Syntax: " << rName
.getStr()
97 << " -i FileIn -o FileOut [-m DataBase] [-l Lang] [-b]\n"
98 " FileIn: Source files (" << rFileType
.getStr() << ")\n"
99 " FileOut: Destination file (*.*)\n"
100 " DataBase: Mergedata (*.po)\n"
101 " Lang: Restrict the handled language; one element of\n"
102 " (de, en-US, ...) or all\n"
103 " -b: Add UTF-8 Byte Order Mark to FileOut(use with -m option)\n";
107 const OString
& rExecutable
, PoOfstream
& rPoStream
, const OString
& rSourceFile
,
108 const OString
& rResType
, const OString
& rGroupId
, const OString
& rLocalId
,
109 const OString
& rHelpText
, const OString
& rText
, const PoEntry::TYPE eType
)
113 PoEntry
aPO(rSourceFile
, rResType
, rGroupId
, rLocalId
, rHelpText
, rText
, eType
);
114 rPoStream
.writeEntry( aPO
);
116 catch( PoEntry::Exception
& aException
)
118 if(aException
== PoEntry::NOSOURCFILE
)
120 std::cerr
<< rExecutable
<< " warning: no sourcefile specified for po entry\n";
124 std::cerr
<< rExecutable
<< " warning: invalid po attributes extracted from " << rSourceFile
<< "\n";
125 if(aException
== PoEntry::NOGROUPID
)
127 std::cerr
<< "No groupID specified!\n";
128 std::cerr
<< "String: " << rText
<< "\n";
130 else if (aException
== PoEntry::NOSTRING
)
132 std::cerr
<< "No string specified!\n";
133 std::cerr
<< "GroupID: " << rGroupId
<< "\n";
134 if( !rLocalId
.isEmpty() ) std::cerr
<< "LocalID: " << rLocalId
<< "\n";
138 if (aException
== PoEntry::NORESTYPE
)
140 std::cerr
<< "No resource type specified!\n";
142 else if (aException
== PoEntry::WRONGHELPTEXT
)
144 std::cerr
<< "x-comment length is 5 characters:" << rHelpText
<< "\n";
147 std::cerr
<< "GroupID: " << rGroupId
<< "\n";
148 if( !rLocalId
.isEmpty() ) std::cerr
<< "LocalID: " << rLocalId
<< "\n";
149 std::cerr
<< "String: " << rText
<< "\n";
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */