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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <rtl/math.hxx>
22 #include <rtl/strbuf.hxx>
30 #include <vcl/svapp.hxx>
32 #include "svl/solar.hrc"
33 #include "bmpcore.hxx"
40 class BmpApp
: public BmpCreator
44 String aOutputFileName
;
47 sal_Bool
GetCommandOption( const ::std::vector
< String
>& rArgs
, const String
& rSwitch
, String
& rSwitchParam
);
48 sal_Bool
GetCommandOptions( const ::std::vector
< String
>& rArgs
, const String
& rSwitch
, ::std::vector
< String
>& rSwitchParams
);
50 void SetExitCode( sal_uInt8 cExit
)
52 if( ( EXIT_NOERROR
== cExitCode
) || ( cExit
!= EXIT_NOERROR
) )
57 virtual void Message( const String
& rText
, sal_uInt8 cExitCode
);
64 int Start( const ::std::vector
< String
>& rArgs
);
67 // -----------------------------------------------------------------------------
73 // -----------------------------------------------------------------------------
79 // -----------------------------------------------------------------------
81 sal_Bool
BmpApp::GetCommandOption( const ::std::vector
< String
>& rArgs
, const String
& rSwitch
, String
& rParam
)
83 sal_Bool bRet
= sal_False
;
85 for( int i
= 0, nCount
= rArgs
.size(); ( i
< nCount
) && !bRet
; i
++ )
87 rtl::OUString
aTestStr( '-' );
89 for( int n
= 0; ( n
< 2 ) && !bRet
; n
++ )
93 if( aTestStr
.equalsIgnoreAsciiCase( rArgs
[ i
] ) )
97 if( i
< ( nCount
- 1 ) )
98 rParam
= rArgs
[ i
+ 1 ];
104 aTestStr
= rtl::OUString('/');
111 // -----------------------------------------------------------------------
113 sal_Bool
BmpApp::GetCommandOptions( const ::std::vector
< String
>& rArgs
, const String
& rSwitch
, ::std::vector
< String
>& rParams
)
115 sal_Bool bRet
= sal_False
;
117 for( int i
= 0, nCount
= rArgs
.size(); ( i
< nCount
); i
++ )
119 rtl::OUString
aTestStr( '-' );
121 for( int n
= 0; ( n
< 2 ) && !bRet
; n
++ )
125 if( aTestStr
.equalsIgnoreAsciiCase( rArgs
[ i
] ) )
127 if( i
< ( nCount
- 1 ) )
128 rParams
.push_back( rArgs
[ i
+ 1 ] );
130 rParams
.push_back( String() );
136 aTestStr
= rtl::OUString('/');
140 return( rParams
.size() > 0 );
143 // -----------------------------------------------------------------------
145 void BmpApp::Message( const String
& rText
, sal_uInt8 cExit
)
147 if( EXIT_NOERROR
!= cExit
)
148 SetExitCode( cExit
);
150 rtl::OStringBuffer
aText(rtl::OUStringToOString(rText
, RTL_TEXTENCODING_UTF8
));
151 aText
.append(RTL_CONSTASCII_STRINGPARAM("\r\n"));
152 fprintf(stderr
, "%s", aText
.getStr());
155 // -----------------------------------------------------------------------------
157 void BmpApp::ShowUsage()
159 Message( String( RTL_CONSTASCII_USTRINGPARAM( "Usage:" ) ), EXIT_NOERROR
);
160 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
);
161 Message( String( RTL_CONSTASCII_USTRINGPARAM( "Options:" ) ), EXIT_NOERROR
);
162 Message( String( RTL_CONSTASCII_USTRINGPARAM( " -i ... name of directory to be searched for input files [multiple occurrence is possible]" ) ), EXIT_NOERROR
);
163 Message( String( RTL_CONSTASCII_USTRINGPARAM( " -f name of file, output should be written to" ) ), EXIT_NOERROR
);
164 Message( String( RTL_CONSTASCII_USTRINGPARAM( "Examples:" ) ), EXIT_NOERROR
);
165 Message( String( RTL_CONSTASCII_USTRINGPARAM( " bmp /home/test.srs /home/out enus 01 -i /home/res -f /home/out/bmp.err" ) ), EXIT_NOERROR
);
168 // -----------------------------------------------------------------------------
170 int BmpApp::Start( const ::std::vector
< String
>& rArgs
)
174 cExitCode
= EXIT_NOERROR
;
176 if( rArgs
.size() >= 6 )
179 sal_uInt16 nCurCmd
= 0;
180 const String
aSrsName( rArgs
[ nCurCmd
++ ] );
181 ::std::vector
< String
> aInDirVector
;
183 aOutName
= rArgs
[ nCurCmd
++ ];
185 rtl::OString
aLangDir(rtl::OUStringToOString(rArgs
[nCurCmd
++], RTL_TEXTENCODING_ASCII_US
));
186 aLangInfo
.mnLangNum
= static_cast< sal_uInt16
>( rArgs
[ nCurCmd
++ ].ToInt32() );
188 memcpy( aLangInfo
.maLangDir
, aLangDir
.getStr(), aLangDir
.getLength() + 1 );
190 GetCommandOption( rArgs
, rtl::OUString('f'), aOutputFileName
);
191 GetCommandOptions( rArgs
, rtl::OUString('i'), aInDirVector
);
193 Create( aSrsName
, aInDirVector
, aOutName
, aLangInfo
);
198 cExitCode
= EXIT_COMMONERROR
;
201 if( ( EXIT_NOERROR
== cExitCode
) && aOutputFileName
.Len() && aOutName
.Len() )
203 SvFileStream
aOStm( aOutputFileName
, STREAM_WRITE
| STREAM_TRUNC
);
204 rtl::OStringBuffer
aStr(RTL_CONSTASCII_STRINGPARAM("Successfully generated ImageList(s) in: "));
205 aStr
.append(rtl::OUStringToOString(aOutName
, RTL_TEXTENCODING_UTF8
));
206 aOStm
.WriteLine(aStr
.makeStringAndClear());
217 int main( int nArgCount
, char* ppArgs
[] )
220 static char aDisplayVar
[ 1024 ];
222 strcpy( aDisplayVar
, "DISPLAY=" );
223 putenv( aDisplayVar
);
226 ::std::vector
< String
> aArgs
;
231 for( int i
= 1; i
< nArgCount
; i
++ )
232 aArgs
.push_back( String( ppArgs
[ i
], RTL_TEXTENCODING_ASCII_US
) );
234 return aBmpApp
.Start( aArgs
);
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */