1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: bmp.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
34 #ifndef INCLUDED_RTL_MATH_HXX
35 #include <rtl/math.hxx>
44 #include <vcl/svapp.hxx>
46 #include "svtools/solar.hrc"
47 #include "filedlg.hxx"
48 #include "bmpcore.hxx"
55 class BmpApp
: public BmpCreator
59 String aOutputFileName
;
62 BOOL
GetCommandOption( const ::std::vector
< String
>& rArgs
, const String
& rSwitch
, String
& rSwitchParam
);
63 BOOL
GetCommandOptions( const ::std::vector
< String
>& rArgs
, const String
& rSwitch
, ::std::vector
< String
>& rSwitchParams
);
65 void SetExitCode( BYTE cExit
)
67 if( ( EXIT_NOERROR
== cExitCode
) || ( cExit
!= EXIT_NOERROR
) )
72 virtual void Message( const String
& rText
, BYTE cExitCode
);
79 int Start( const ::std::vector
< String
>& rArgs
);
82 // -----------------------------------------------------------------------------
88 // -----------------------------------------------------------------------------
94 // -----------------------------------------------------------------------
96 BOOL
BmpApp::GetCommandOption( const ::std::vector
< String
>& rArgs
, const String
& rSwitch
, String
& rParam
)
100 for( int i
= 0, nCount
= rArgs
.size(); ( i
< nCount
) && !bRet
; i
++ )
102 String
aTestStr( '-' );
104 for( int n
= 0; ( n
< 2 ) && !bRet
; n
++ )
108 if( aTestStr
.CompareIgnoreCaseToAscii( rArgs
[ i
] ) == COMPARE_EQUAL
)
112 if( i
< ( nCount
- 1 ) )
113 rParam
= rArgs
[ i
+ 1 ];
126 // -----------------------------------------------------------------------
128 BOOL
BmpApp::GetCommandOptions( const ::std::vector
< String
>& rArgs
, const String
& rSwitch
, ::std::vector
< String
>& rParams
)
132 for( int i
= 0, nCount
= rArgs
.size(); ( i
< nCount
); i
++ )
134 String
aTestStr( '-' );
136 for( int n
= 0; ( n
< 2 ) && !bRet
; n
++ )
140 if( aTestStr
.CompareIgnoreCaseToAscii( rArgs
[ i
] ) == COMPARE_EQUAL
)
142 if( i
< ( nCount
- 1 ) )
143 rParams
.push_back( rArgs
[ i
+ 1 ] );
145 rParams
.push_back( String() );
155 return( rParams
.size() > 0 );
158 // -----------------------------------------------------------------------
160 void BmpApp::Message( const String
& rText
, BYTE cExit
)
162 if( EXIT_NOERROR
!= cExit
)
163 SetExitCode( cExit
);
165 ByteString
aText( rText
, RTL_TEXTENCODING_UTF8
);
166 aText
.Append( "\r\n" );
167 fprintf( stderr
, "%s", aText
.GetBuffer() );
170 // -----------------------------------------------------------------------------
172 void BmpApp::ShowUsage()
174 Message( String( RTL_CONSTASCII_USTRINGPARAM( "Usage:" ) ), EXIT_NOERROR
);
175 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
);
176 Message( String( RTL_CONSTASCII_USTRINGPARAM( "Options:" ) ), EXIT_NOERROR
);
177 Message( String( RTL_CONSTASCII_USTRINGPARAM( " -i ... name of directory to be searched for input files [multiple occurence is possible]" ) ), EXIT_NOERROR
);
178 Message( String( RTL_CONSTASCII_USTRINGPARAM( " -f name of file, output should be written to" ) ), EXIT_NOERROR
);
179 Message( String( RTL_CONSTASCII_USTRINGPARAM( "Examples:" ) ), EXIT_NOERROR
);
180 Message( String( RTL_CONSTASCII_USTRINGPARAM( " bmp /home/test.srs /home/out enus 01 -i /home/res -f /home/out/bmp.err" ) ), EXIT_NOERROR
);
183 // -----------------------------------------------------------------------------
185 int BmpApp::Start( const ::std::vector
< String
>& rArgs
)
189 cExitCode
= EXIT_NOERROR
;
191 if( rArgs
.size() >= 6 )
195 const String
aSrsName( rArgs
[ nCurCmd
++ ] );
196 ::std::vector
< String
> aInDirVector
;
199 aOutName
= rArgs
[ nCurCmd
++ ];
201 aLangDir
= ByteString( rArgs
[ nCurCmd
++ ], RTL_TEXTENCODING_ASCII_US
);
202 aLangInfo
.mnLangNum
= static_cast< sal_uInt16
>( rArgs
[ nCurCmd
++ ].ToInt32() );
204 memcpy( aLangInfo
.maLangDir
, aLangDir
.GetBuffer(), aLangDir
.Len() + 1 );
206 GetCommandOption( rArgs
, 'f', aOutputFileName
);
207 GetCommandOptions( rArgs
, 'i', aInDirVector
);
209 Create( aSrsName
, aInDirVector
, aOutName
, aLangInfo
);
214 cExitCode
= EXIT_COMMONERROR
;
217 if( ( EXIT_NOERROR
== cExitCode
) && aOutputFileName
.Len() && aOutName
.Len() )
219 SvFileStream
aOStm( aOutputFileName
, STREAM_WRITE
| STREAM_TRUNC
);
220 ByteString
aStr( "Successfully generated ImageList(s) in: " );
222 aOStm
.WriteLine( aStr
.Append( ByteString( aOutName
, RTL_TEXTENCODING_UTF8
) ) );
233 int main( int nArgCount
, char* ppArgs
[] )
236 static char aDisplayVar
[ 1024 ];
238 strcpy( aDisplayVar
, "DISPLAY=" );
239 putenv( aDisplayVar
);
242 ::std::vector
< String
> aArgs
;
245 InitVCL( com::sun::star::uno::Reference
< com::sun::star::lang::XMultiServiceFactory
>() );
247 for( int i
= 1; i
< nArgCount
; i
++ )
248 aArgs
.push_back( String( ppArgs
[ i
], RTL_TEXTENCODING_ASCII_US
) );
250 return aBmpApp
.Start( aArgs
);