LCOV - code coverage report
Current view: top level - svtools/bmpmaker - bmp.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 86 0.0 %
Date: 2012-08-25 Functions: 0 10 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <rtl/math.hxx>
      31                 :            : #include <rtl/strbuf.hxx>
      32                 :            : 
      33                 :            : #include <math.h>
      34                 :            : #include <stdio.h>
      35                 :            : #include <signal.h>
      36                 :            : #include <vector>
      37                 :            : using namespace std;
      38                 :            : 
      39                 :            : #include <vcl/svapp.hxx>
      40                 :            : 
      41                 :            : #include "svl/solar.hrc"
      42                 :            : #include "bmpcore.hxx"
      43                 :            : #include "bmp.hrc"
      44                 :            : 
      45                 :            : // ----------
      46                 :            : // - BmpApp -
      47                 :            : // ----------
      48                 :            : 
      49                 :            : class BmpApp : public BmpCreator
      50                 :            : {
      51                 :            : private:
      52                 :            : 
      53                 :            :     String          aOutputFileName;
      54                 :            :     sal_uInt8           cExitCode;
      55                 :            : 
      56                 :            :     sal_Bool            GetCommandOption( const ::std::vector< String >& rArgs, const String& rSwitch, String& rSwitchParam );
      57                 :            :     sal_Bool            GetCommandOptions( const ::std::vector< String >& rArgs, const String& rSwitch, ::std::vector< String >& rSwitchParams );
      58                 :            : 
      59                 :          0 :     void            SetExitCode( sal_uInt8 cExit )
      60                 :            :                     {
      61                 :          0 :                         if( ( EXIT_NOERROR == cExitCode ) || ( cExit != EXIT_NOERROR ) )
      62                 :          0 :                             cExitCode = cExit;
      63                 :          0 :                     }
      64                 :            :     void            ShowUsage();
      65                 :            : 
      66                 :            :     virtual void    Message( const String& rText, sal_uInt8 cExitCode );
      67                 :            : 
      68                 :            : public:
      69                 :            : 
      70                 :            :                     BmpApp();
      71                 :            :                     ~BmpApp();
      72                 :            : 
      73                 :            :     int             Start( const ::std::vector< String >& rArgs );
      74                 :            : };
      75                 :            : 
      76                 :            : // -----------------------------------------------------------------------------
      77                 :            : 
      78                 :          0 : BmpApp::BmpApp()
      79                 :            : {
      80                 :          0 : }
      81                 :            : 
      82                 :            : // -----------------------------------------------------------------------------
      83                 :            : 
      84                 :          0 : BmpApp::~BmpApp()
      85                 :            : {
      86                 :          0 : }
      87                 :            : 
      88                 :            : // -----------------------------------------------------------------------
      89                 :            : 
      90                 :          0 : sal_Bool BmpApp::GetCommandOption( const ::std::vector< String >& rArgs, const String& rSwitch, String& rParam )
      91                 :            : {
      92                 :          0 :     sal_Bool bRet = sal_False;
      93                 :            : 
      94                 :          0 :     for( int i = 0, nCount = rArgs.size(); ( i < nCount ) && !bRet; i++ )
      95                 :            :     {
      96                 :          0 :         rtl::OUString  aTestStr( '-' );
      97                 :            : 
      98                 :          0 :         for( int n = 0; ( n < 2 ) && !bRet; n++ )
      99                 :            :         {
     100                 :          0 :             aTestStr += rSwitch;
     101                 :            : 
     102                 :          0 :             if( aTestStr.equalsIgnoreAsciiCase( rArgs[ i ] ) )
     103                 :            :             {
     104                 :          0 :                 bRet = sal_True;
     105                 :            : 
     106                 :          0 :                 if( i < ( nCount - 1 ) )
     107                 :          0 :                     rParam = rArgs[ i + 1 ];
     108                 :            :                 else
     109                 :          0 :                     rParam = String();
     110                 :            :             }
     111                 :            : 
     112                 :          0 :             if( 0 == n )
     113                 :          0 :                 aTestStr = rtl::OUString('/');
     114                 :            :         }
     115                 :          0 :     }
     116                 :            : 
     117                 :          0 :     return bRet;
     118                 :            : }
     119                 :            : 
     120                 :            : // -----------------------------------------------------------------------
     121                 :            : 
     122                 :          0 : sal_Bool BmpApp::GetCommandOptions( const ::std::vector< String >& rArgs, const String& rSwitch, ::std::vector< String >& rParams )
     123                 :            : {
     124                 :          0 :     sal_Bool bRet = sal_False;
     125                 :            : 
     126                 :          0 :     for( int i = 0, nCount = rArgs.size(); ( i < nCount ); i++ )
     127                 :            :     {
     128                 :          0 :         rtl::OUString  aTestStr( '-' );
     129                 :            : 
     130                 :          0 :         for( int n = 0; ( n < 2 ) && !bRet; n++ )
     131                 :            :         {
     132                 :          0 :             aTestStr += rSwitch;
     133                 :            : 
     134                 :          0 :             if( aTestStr.equalsIgnoreAsciiCase( rArgs[ i ] ) )
     135                 :            :             {
     136                 :          0 :                 if( i < ( nCount - 1 ) )
     137                 :          0 :                     rParams.push_back( rArgs[ i + 1 ] );
     138                 :            :                 else
     139                 :          0 :                     rParams.push_back( String() );
     140                 :            : 
     141                 :          0 :                 break;
     142                 :            :             }
     143                 :            : 
     144                 :          0 :             if( 0 == n )
     145                 :          0 :                 aTestStr = rtl::OUString('/');
     146                 :            :         }
     147                 :          0 :     }
     148                 :            : 
     149                 :          0 :     return( rParams.size() > 0 );
     150                 :            : }
     151                 :            : 
     152                 :            : // -----------------------------------------------------------------------
     153                 :            : 
     154                 :          0 : void BmpApp::Message( const String& rText, sal_uInt8 cExit )
     155                 :            : {
     156                 :          0 :     if( EXIT_NOERROR != cExit )
     157                 :          0 :         SetExitCode( cExit );
     158                 :            : 
     159                 :          0 :     rtl::OStringBuffer aText(rtl::OUStringToOString(rText, RTL_TEXTENCODING_UTF8));
     160                 :          0 :     aText.append(RTL_CONSTASCII_STRINGPARAM("\r\n"));
     161                 :          0 :     fprintf(stderr, "%s", aText.getStr());
     162                 :          0 : }
     163                 :            : 
     164                 :            : // -----------------------------------------------------------------------------
     165                 :            : 
     166                 :          0 : void BmpApp::ShowUsage()
     167                 :            : {
     168                 :          0 :     Message( String( RTL_CONSTASCII_USTRINGPARAM( "Usage:" ) ), EXIT_NOERROR );
     169                 :          0 :     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 );
     170                 :          0 :     Message( String( RTL_CONSTASCII_USTRINGPARAM( "Options:" ) ), EXIT_NOERROR );
     171                 :          0 :     Message( String( RTL_CONSTASCII_USTRINGPARAM( "   -i ...        name of directory to be searched for input files [multiple occurrence is possible]" ) ), EXIT_NOERROR );
     172                 :          0 :     Message( String( RTL_CONSTASCII_USTRINGPARAM( "   -f            name of file, output should be written to" ) ), EXIT_NOERROR );
     173                 :          0 :     Message( String( RTL_CONSTASCII_USTRINGPARAM( "Examples:" ) ), EXIT_NOERROR );
     174                 :          0 :     Message( String( RTL_CONSTASCII_USTRINGPARAM( "    bmp /home/test.srs /home/out enus 01 -i /home/res -f /home/out/bmp.err" ) ), EXIT_NOERROR );
     175                 :          0 : }
     176                 :            : 
     177                 :            : // -----------------------------------------------------------------------------
     178                 :            : 
     179                 :          0 : int BmpApp::Start( const ::std::vector< String >& rArgs )
     180                 :            : {
     181                 :          0 :     String aOutName;
     182                 :            : 
     183                 :          0 :     cExitCode = EXIT_NOERROR;
     184                 :            : 
     185                 :          0 :     if( rArgs.size() >= 6 )
     186                 :            :     {
     187                 :            :         LangInfo                aLangInfo;
     188                 :          0 :         sal_uInt16                  nCurCmd = 0;
     189                 :          0 :         const String            aSrsName( rArgs[ nCurCmd++ ] );
     190                 :          0 :         ::std::vector< String > aInDirVector;
     191                 :            : 
     192                 :          0 :         aOutName = rArgs[ nCurCmd++ ];
     193                 :            : 
     194                 :          0 :         rtl::OString aLangDir(rtl::OUStringToOString(rArgs[nCurCmd++], RTL_TEXTENCODING_ASCII_US));
     195                 :          0 :         aLangInfo.mnLangNum = static_cast< sal_uInt16 >( rArgs[ nCurCmd++ ].ToInt32() );
     196                 :            : 
     197                 :          0 :         memcpy( aLangInfo.maLangDir, aLangDir.getStr(), aLangDir.getLength() + 1 );
     198                 :            : 
     199                 :          0 :         GetCommandOption( rArgs, rtl::OUString('f'), aOutputFileName );
     200                 :          0 :         GetCommandOptions( rArgs, rtl::OUString('i'), aInDirVector );
     201                 :            : 
     202                 :          0 :         Create( aSrsName, aInDirVector, aOutName, aLangInfo );
     203                 :            :     }
     204                 :            :     else
     205                 :            :     {
     206                 :          0 :         ShowUsage();
     207                 :          0 :         cExitCode = EXIT_COMMONERROR;
     208                 :            :     }
     209                 :            : 
     210                 :          0 :     if( ( EXIT_NOERROR == cExitCode ) && aOutputFileName.Len() && aOutName.Len() )
     211                 :            :     {
     212                 :          0 :         SvFileStream    aOStm( aOutputFileName, STREAM_WRITE | STREAM_TRUNC );
     213                 :          0 :         rtl::OStringBuffer aStr(RTL_CONSTASCII_STRINGPARAM("Successfully generated ImageList(s) in: "));
     214                 :          0 :         aStr.append(rtl::OUStringToOString(aOutName, RTL_TEXTENCODING_UTF8));
     215                 :          0 :         aOStm.WriteLine(aStr.makeStringAndClear());
     216                 :          0 :         aOStm.Close();
     217                 :            :     }
     218                 :            : 
     219                 :          0 :     return cExitCode;
     220                 :            : }
     221                 :            : 
     222                 :            : // --------
     223                 :            : // - Main -
     224                 :            : // --------
     225                 :            : 
     226                 :          0 : int main( int nArgCount, char* ppArgs[] )
     227                 :            : {
     228                 :            : #ifdef UNX
     229                 :            :     static char aDisplayVar[ 1024 ];
     230                 :            : 
     231                 :          0 :     strcpy( aDisplayVar, "DISPLAY=" );
     232                 :          0 :     putenv( aDisplayVar );
     233                 :            : #endif
     234                 :            : 
     235                 :          0 :     ::std::vector< String > aArgs;
     236                 :          0 :     BmpApp                  aBmpApp;
     237                 :            : 
     238                 :          0 :     InitVCL( com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >() );
     239                 :            : 
     240                 :          0 :     for( int i = 1; i < nArgCount; i++ )
     241                 :          0 :         aArgs.push_back( String( ppArgs[ i ], RTL_TEXTENCODING_ASCII_US ) );
     242                 :            : 
     243                 :          0 :     return aBmpApp.Start( aArgs );
     244                 :            : }
     245                 :            : 
     246                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10