merge the formfield patch from ooo-build
[ooovba.git] / svtools / bmpmaker / bmp.cxx
blobbe522f9d7bf8249a794f51b94667f2edf3881538
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: bmp.cxx,v $
10 * $Revision: 1.19 $
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>
36 #endif
38 #include <math.h>
39 #include <stdio.h>
40 #include <signal.h>
41 #include <vector>
42 using namespace std;
44 #include <vcl/svapp.hxx>
46 #include "svtools/solar.hrc"
47 #include "filedlg.hxx"
48 #include "bmpcore.hxx"
49 #include "bmp.hrc"
51 // ----------
52 // - BmpApp -
53 // ----------
55 class BmpApp : public BmpCreator
57 private:
59 String aOutputFileName;
60 BYTE cExitCode;
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 ) )
68 cExitCode = cExit;
70 void ShowUsage();
72 virtual void Message( const String& rText, BYTE cExitCode );
74 public:
76 BmpApp();
77 ~BmpApp();
79 int Start( const ::std::vector< String >& rArgs );
82 // -----------------------------------------------------------------------------
84 BmpApp::BmpApp()
88 // -----------------------------------------------------------------------------
90 BmpApp::~BmpApp()
94 // -----------------------------------------------------------------------
96 BOOL BmpApp::GetCommandOption( const ::std::vector< String >& rArgs, const String& rSwitch, String& rParam )
98 BOOL bRet = FALSE;
100 for( int i = 0, nCount = rArgs.size(); ( i < nCount ) && !bRet; i++ )
102 String aTestStr( '-' );
104 for( int n = 0; ( n < 2 ) && !bRet; n++ )
106 aTestStr += rSwitch;
108 if( aTestStr.CompareIgnoreCaseToAscii( rArgs[ i ] ) == COMPARE_EQUAL )
110 bRet = TRUE;
112 if( i < ( nCount - 1 ) )
113 rParam = rArgs[ i + 1 ];
114 else
115 rParam = String();
118 if( 0 == n )
119 aTestStr = '/';
123 return bRet;
126 // -----------------------------------------------------------------------
128 BOOL BmpApp::GetCommandOptions( const ::std::vector< String >& rArgs, const String& rSwitch, ::std::vector< String >& rParams )
130 BOOL bRet = FALSE;
132 for( int i = 0, nCount = rArgs.size(); ( i < nCount ); i++ )
134 String aTestStr( '-' );
136 for( int n = 0; ( n < 2 ) && !bRet; n++ )
138 aTestStr += rSwitch;
140 if( aTestStr.CompareIgnoreCaseToAscii( rArgs[ i ] ) == COMPARE_EQUAL )
142 if( i < ( nCount - 1 ) )
143 rParams.push_back( rArgs[ i + 1 ] );
144 else
145 rParams.push_back( String() );
147 break;
150 if( 0 == n )
151 aTestStr = '/';
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 )
187 String aOutName;
189 cExitCode = EXIT_NOERROR;
191 if( rArgs.size() >= 6 )
193 LangInfo aLangInfo;
194 USHORT nCurCmd = 0;
195 const String aSrsName( rArgs[ nCurCmd++ ] );
196 ::std::vector< String > aInDirVector;
197 ByteString aLangDir;
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 );
211 else
213 ShowUsage();
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 ) ) );
223 aOStm.Close();
226 return cExitCode;
229 // --------
230 // - Main -
231 // --------
233 int main( int nArgCount, char* ppArgs[] )
235 #ifdef UNX
236 static char aDisplayVar[ 1024 ];
238 strcpy( aDisplayVar, "DISPLAY=" );
239 putenv( aDisplayVar );
240 #endif
242 ::std::vector< String > aArgs;
243 BmpApp aBmpApp;
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 );