1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svtools.hxx"
26
27 #ifndef INCLUDED_RTL_MATH_HXX
28 #include <rtl/math.hxx>
29 #endif
30
31 #include <math.h>
32 #include <stdio.h>
33 #include <signal.h>
34 #include <vector>
35 using namespace std;
36
37 #include <vcl/svapp.hxx>
38
39 #include "svl/solar.hrc"
40 #include <svtools/filedlg.hxx>
41 #include "bmpcore.hxx"
42 #include "bmp.hrc"
43
44 // ----------
45 // - BmpApp -
46 // ----------
47
48 class BmpApp : public BmpCreator
49 {
50 private:
51
52 String aOutputFileName;
53 sal_uInt8 cExitCode;
54
55 sal_Bool GetCommandOption( const ::std::vector< String >& rArgs, const String& rSwitch, String& rSwitchParam );
56 sal_Bool GetCommandOptions( const ::std::vector< String >& rArgs, const String& rSwitch, ::std::vector< String >& rSwitchParams );
57
SetExitCode(sal_uInt8 cExit)58 void SetExitCode( sal_uInt8 cExit )
59 {
60 if( ( EXIT_NOERROR == cExitCode ) || ( cExit != EXIT_NOERROR ) )
61 cExitCode = cExit;
62 }
63 void ShowUsage();
64
65 virtual void Message( const String& rText, sal_uInt8 cExitCode );
66
67 public:
68
69 BmpApp();
70 ~BmpApp();
71
72 int Start( const ::std::vector< String >& rArgs );
73 };
74
75 // -----------------------------------------------------------------------------
76
BmpApp()77 BmpApp::BmpApp()
78 {
79 }
80
81 // -----------------------------------------------------------------------------
82
~BmpApp()83 BmpApp::~BmpApp()
84 {
85 }
86
87 // -----------------------------------------------------------------------
88
GetCommandOption(const::std::vector<String> & rArgs,const String & rSwitch,String & rParam)89 sal_Bool BmpApp::GetCommandOption( const ::std::vector< String >& rArgs, const String& rSwitch, String& rParam )
90 {
91 sal_Bool bRet = sal_False;
92
93 for( int i = 0, nCount = rArgs.size(); ( i < nCount ) && !bRet; i++ )
94 {
95 String aTestStr( '-' );
96
97 for( int n = 0; ( n < 2 ) && !bRet; n++ )
98 {
99 aTestStr += rSwitch;
100
101 if( aTestStr.CompareIgnoreCaseToAscii( rArgs[ i ] ) == COMPARE_EQUAL )
102 {
103 bRet = sal_True;
104
105 if( i < ( nCount - 1 ) )
106 rParam = rArgs[ i + 1 ];
107 else
108 rParam = String();
109 }
110
111 if( 0 == n )
112 aTestStr = '/';
113 }
114 }
115
116 return bRet;
117 }
118
119 // -----------------------------------------------------------------------
120
GetCommandOptions(const::std::vector<String> & rArgs,const String & rSwitch,::std::vector<String> & rParams)121 sal_Bool BmpApp::GetCommandOptions( const ::std::vector< String >& rArgs, const String& rSwitch, ::std::vector< String >& rParams )
122 {
123 sal_Bool bRet = sal_False;
124
125 for( int i = 0, nCount = rArgs.size(); ( i < nCount ); i++ )
126 {
127 String aTestStr( '-' );
128
129 for( int n = 0; ( n < 2 ) && !bRet; n++ )
130 {
131 aTestStr += rSwitch;
132
133 if( aTestStr.CompareIgnoreCaseToAscii( rArgs[ i ] ) == COMPARE_EQUAL )
134 {
135 if( i < ( nCount - 1 ) )
136 rParams.push_back( rArgs[ i + 1 ] );
137 else
138 rParams.push_back( String() );
139
140 break;
141 }
142
143 if( 0 == n )
144 aTestStr = '/';
145 }
146 }
147
148 return( rParams.size() > 0 );
149 }
150
151 // -----------------------------------------------------------------------
152
Message(const String & rText,sal_uInt8 cExit)153 void BmpApp::Message( const String& rText, sal_uInt8 cExit )
154 {
155 if( EXIT_NOERROR != cExit )
156 SetExitCode( cExit );
157
158 ByteString aText( rText, RTL_TEXTENCODING_UTF8 );
159 aText.Append( "\r\n" );
160 fprintf( stderr, aText.GetBuffer() );
161 }
162
163 // -----------------------------------------------------------------------------
164
ShowUsage()165 void BmpApp::ShowUsage()
166 {
167 Message( String( RTL_CONSTASCII_USTRINGPARAM( "Usage:" ) ), EXIT_NOERROR );
168 Message( String( RTL_CONSTASCII_USTRINGPARAM( " bmp srs_inputfile output_dir lang_dir lang_num -i input_dir [-i input_dir ][-f err_file]" ) ), EXIT_NOERROR );
169 Message( String( RTL_CONSTASCII_USTRINGPARAM( "Options:" ) ), EXIT_NOERROR );
170 Message( String( RTL_CONSTASCII_USTRINGPARAM( " -i ... name of directory to be searched for input files [multiple occurence is possible]" ) ), EXIT_NOERROR );
171 Message( String( RTL_CONSTASCII_USTRINGPARAM( " -f name of file, output should be written to" ) ), EXIT_NOERROR );
172 Message( String( RTL_CONSTASCII_USTRINGPARAM( "Examples:" ) ), EXIT_NOERROR );
173 Message( String( RTL_CONSTASCII_USTRINGPARAM( " bmp /home/test.srs /home/out enus 01 -i /home/res -f /home/out/bmp.err" ) ), EXIT_NOERROR );
174 }
175
176 // -----------------------------------------------------------------------------
177
Start(const::std::vector<String> & rArgs)178 int BmpApp::Start( const ::std::vector< String >& rArgs )
179 {
180 String aOutName;
181
182 cExitCode = EXIT_NOERROR;
183
184 if( rArgs.size() >= 6 )
185 {
186 LangInfo aLangInfo;
187 sal_uInt16 nCurCmd = 0;
188 const String aSrsName( rArgs[ nCurCmd++ ] );
189 ::std::vector< String > aInDirVector;
190 ByteString aLangDir;
191
192 aOutName = rArgs[ nCurCmd++ ];
193
194 aLangDir = ByteString( rArgs[ nCurCmd++ ], RTL_TEXTENCODING_ASCII_US );
195 aLangInfo.mnLangNum = static_cast< sal_uInt16 >( rArgs[ nCurCmd++ ].ToInt32() );
196
197 memcpy( aLangInfo.maLangDir, aLangDir.GetBuffer(), aLangDir.Len() + 1 );
198
199 GetCommandOption( rArgs, 'f', aOutputFileName );
200 GetCommandOptions( rArgs, 'i', aInDirVector );
201
202 Create( aSrsName, aInDirVector, aOutName, aLangInfo );
203 }
204 else
205 {
206 ShowUsage();
207 cExitCode = EXIT_COMMONERROR;
208 }
209
210 if( ( EXIT_NOERROR == cExitCode ) && aOutputFileName.Len() && aOutName.Len() )
211 {
212 SvFileStream aOStm( aOutputFileName, STREAM_WRITE | STREAM_TRUNC );
213 ByteString aStr( "Successfully generated ImageList(s) in: " );
214
215 aOStm.WriteLine( aStr.Append( ByteString( aOutName, RTL_TEXTENCODING_UTF8 ) ) );
216 aOStm.Close();
217 }
218
219 return cExitCode;
220 }
221
222 // --------
223 // - Main -
224 // --------
225
main(int nArgCount,char * ppArgs[])226 int main( int nArgCount, char* ppArgs[] )
227 {
228 #ifdef UNX
229 static char aDisplayVar[ 1024 ];
230
231 strcpy( aDisplayVar, "DISPLAY=" );
232 putenv( aDisplayVar );
233 #endif
234
235 ::std::vector< String > aArgs;
236 BmpApp aBmpApp;
237
238 InitVCL( com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >() );
239
240 for( int i = 1; i < nArgCount; i++ )
241 aArgs.push_back( String( ppArgs[ i ], RTL_TEXTENCODING_ASCII_US ) );
242
243 return aBmpApp.Start( aArgs );
244 }
245