Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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 : */
9 :
10 : #include "common.hxx"
11 :
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
18 :
19 : namespace common {
20 :
21 0 : bool handleArguments(
22 : int argc, char * argv[], HandledArgs& o_aHandledArgs)
23 : {
24 0 : o_aHandledArgs = HandledArgs();
25 0 : sal_uInt16 nState = STATE_NON;
26 :
27 0 : for( int i = 1; i < argc; i++ )
28 : {
29 0 : if ( OString( argv[ i ] ).toAsciiUpperCase() == "-I" )
30 : {
31 0 : nState = STATE_INPUT; // next token specifies source file
32 : }
33 0 : else if ( OString( argv[ i ] ).toAsciiUpperCase() == "-O" )
34 : {
35 0 : nState = STATE_OUTPUT; // next token specifies the dest file
36 : }
37 0 : else if ( OString( argv[ i ] ).toAsciiUpperCase() == "-M" )
38 : {
39 0 : nState = STATE_MERGESRC; // next token specifies the merge database
40 0 : o_aHandledArgs.m_bMergeMode = true;
41 : }
42 0 : else if ( OString( argv[ i ] ).toAsciiUpperCase() == "-L" )
43 : {
44 0 : nState = STATE_LANGUAGES;
45 : }
46 0 : else if ( OString( argv[ i ] ).toAsciiUpperCase() == "-B" )
47 : {
48 0 : o_aHandledArgs.m_bUTF8BOM = true;
49 : }
50 : else
51 : {
52 0 : switch ( nState )
53 : {
54 : case STATE_NON:
55 : {
56 0 : return false; // no valid command line
57 : }
58 : case STATE_INPUT:
59 : {
60 0 : o_aHandledArgs.m_sInputFile = OString( argv[i] );
61 : }
62 0 : break;
63 : case STATE_OUTPUT:
64 : {
65 0 : o_aHandledArgs.m_sOutputFile = OString( argv[i] );
66 : }
67 0 : break;
68 : case STATE_MERGESRC:
69 : {
70 0 : o_aHandledArgs.m_sMergeSrc = OString( argv[i] );
71 : }
72 0 : break;
73 : case STATE_LANGUAGES:
74 : {
75 0 : o_aHandledArgs.m_sLanguage = OString( argv[i] );
76 : }
77 0 : break;
78 : }
79 : }
80 : }
81 0 : if( !o_aHandledArgs.m_sInputFile.isEmpty() &&
82 0 : !o_aHandledArgs.m_sOutputFile.isEmpty() )
83 : {
84 0 : return true;
85 : }
86 : else
87 : {
88 0 : o_aHandledArgs = HandledArgs();
89 0 : return false;
90 : }
91 : }
92 :
93 0 : void writeUsage(const OString& rName, const OString& rFileType)
94 : {
95 : std::cout
96 0 : << " Syntax: " << rName.getStr()
97 0 : << " -i FileIn -o FileOut [-m DataBase] [-l Lang] [-b]\n"
98 0 : << " FileIn: Source files (" << rFileType.getStr() << ")\n"
99 0 : << " FileOut: Destination file (*.*)\n"
100 0 : << " DataBase: Mergedata (*.po)\n"
101 0 : << " Lang: Restrict the handled language; one element of\n"
102 0 : << " (de, en-US, ...) or all\n"
103 0 : << " -b: Add UTF-8 Byte Order Mark to FileOut(use with -m option)\n";
104 0 : }
105 :
106 0 : void writePoEntry(
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 )
110 : {
111 : try
112 : {
113 0 : PoEntry aPO(rSourceFile, rResType, rGroupId, rLocalId, rHelpText, rText, eType);
114 0 : rPoStream.writeEntry( aPO );
115 : }
116 0 : catch( PoEntry::Exception& aException )
117 : {
118 0 : if(aException == PoEntry::NOSOURCFILE)
119 : {
120 0 : std::cerr << rExecutable << " warning: no sourcefile specified for po entry\n";
121 : }
122 : else
123 : {
124 0 : std::cerr << rExecutable << " warning: invalid po attributes extracted from " << rSourceFile << "\n";
125 0 : if(aException == PoEntry::NOGROUPID)
126 : {
127 0 : std::cerr << "No groupID specified!\n";
128 0 : std::cerr << "String: " << rText << "\n";
129 : }
130 0 : else if (aException == PoEntry::NOSTRING)
131 : {
132 0 : std::cerr << "No string specified!\n";
133 0 : std::cerr << "GroupID: " << rGroupId << "\n";
134 0 : if( !rLocalId.isEmpty() ) std::cerr << "LocalID: " << rLocalId << "\n";
135 : }
136 : else
137 : {
138 0 : if (aException == PoEntry::NORESTYPE)
139 : {
140 0 : std::cerr << "No resource type specified!\n";
141 : }
142 0 : else if (aException == PoEntry::WRONGHELPTEXT)
143 : {
144 0 : std::cerr << "x-comment length is 5 characters:" << rHelpText << "\n";
145 : }
146 :
147 0 : std::cerr << "GroupID: " << rGroupId << "\n";
148 0 : if( !rLocalId.isEmpty() ) std::cerr << "LocalID: " << rLocalId << "\n";
149 0 : std::cerr << "String: " << rText << "\n";
150 : }
151 : }
152 : }
153 0 : }
154 :
155 0 : }
156 :
157 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|