LCOV - code coverage report
Current view: top level - libreoffice/svtools/bmpmaker - bmp.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 86 0.0 %
Date: 2012-12-27 Functions: 0 10 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : 
      21             : #include <rtl/math.hxx>
      22             : #include <rtl/strbuf.hxx>
      23             : 
      24             : #include <math.h>
      25             : #include <stdio.h>
      26             : #include <signal.h>
      27             : #include <vector>
      28             : using namespace std;
      29             : 
      30             : #include <vcl/svapp.hxx>
      31             : 
      32             : #include "svl/solar.hrc"
      33             : #include "bmpcore.hxx"
      34             : #include "bmp.hrc"
      35             : 
      36             : // ----------
      37             : // - BmpApp -
      38             : // ----------
      39             : 
      40             : class BmpApp : public BmpCreator
      41             : {
      42             : private:
      43             : 
      44             :     String          aOutputFileName;
      45             :     sal_uInt8           cExitCode;
      46             : 
      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 );
      49             : 
      50           0 :     void            SetExitCode( sal_uInt8 cExit )
      51             :                     {
      52           0 :                         if( ( EXIT_NOERROR == cExitCode ) || ( cExit != EXIT_NOERROR ) )
      53           0 :                             cExitCode = cExit;
      54           0 :                     }
      55             :     void            ShowUsage();
      56             : 
      57             :     virtual void    Message( const String& rText, sal_uInt8 cExitCode );
      58             : 
      59             : public:
      60             : 
      61             :                     BmpApp();
      62             :                     ~BmpApp();
      63             : 
      64             :     int             Start( const ::std::vector< String >& rArgs );
      65             : };
      66             : 
      67             : // -----------------------------------------------------------------------------
      68             : 
      69           0 : BmpApp::BmpApp()
      70             : {
      71           0 : }
      72             : 
      73             : // -----------------------------------------------------------------------------
      74             : 
      75           0 : BmpApp::~BmpApp()
      76             : {
      77           0 : }
      78             : 
      79             : // -----------------------------------------------------------------------
      80             : 
      81           0 : sal_Bool BmpApp::GetCommandOption( const ::std::vector< String >& rArgs, const String& rSwitch, String& rParam )
      82             : {
      83           0 :     sal_Bool bRet = sal_False;
      84             : 
      85           0 :     for( int i = 0, nCount = rArgs.size(); ( i < nCount ) && !bRet; i++ )
      86             :     {
      87           0 :         rtl::OUString  aTestStr( '-' );
      88             : 
      89           0 :         for( int n = 0; ( n < 2 ) && !bRet; n++ )
      90             :         {
      91           0 :             aTestStr += rSwitch;
      92             : 
      93           0 :             if( aTestStr.equalsIgnoreAsciiCase( rArgs[ i ] ) )
      94             :             {
      95           0 :                 bRet = sal_True;
      96             : 
      97           0 :                 if( i < ( nCount - 1 ) )
      98           0 :                     rParam = rArgs[ i + 1 ];
      99             :                 else
     100           0 :                     rParam = String();
     101             :             }
     102             : 
     103           0 :             if( 0 == n )
     104           0 :                 aTestStr = rtl::OUString('/');
     105             :         }
     106           0 :     }
     107             : 
     108           0 :     return bRet;
     109             : }
     110             : 
     111             : // -----------------------------------------------------------------------
     112             : 
     113           0 : sal_Bool BmpApp::GetCommandOptions( const ::std::vector< String >& rArgs, const String& rSwitch, ::std::vector< String >& rParams )
     114             : {
     115           0 :     sal_Bool bRet = sal_False;
     116             : 
     117           0 :     for( int i = 0, nCount = rArgs.size(); ( i < nCount ); i++ )
     118             :     {
     119           0 :         rtl::OUString  aTestStr( '-' );
     120             : 
     121           0 :         for( int n = 0; ( n < 2 ) && !bRet; n++ )
     122             :         {
     123           0 :             aTestStr += rSwitch;
     124             : 
     125           0 :             if( aTestStr.equalsIgnoreAsciiCase( rArgs[ i ] ) )
     126             :             {
     127           0 :                 if( i < ( nCount - 1 ) )
     128           0 :                     rParams.push_back( rArgs[ i + 1 ] );
     129             :                 else
     130           0 :                     rParams.push_back( String() );
     131             : 
     132           0 :                 break;
     133             :             }
     134             : 
     135           0 :             if( 0 == n )
     136           0 :                 aTestStr = rtl::OUString('/');
     137             :         }
     138           0 :     }
     139             : 
     140           0 :     return( rParams.size() > 0 );
     141             : }
     142             : 
     143             : // -----------------------------------------------------------------------
     144             : 
     145           0 : void BmpApp::Message( const String& rText, sal_uInt8 cExit )
     146             : {
     147           0 :     if( EXIT_NOERROR != cExit )
     148           0 :         SetExitCode( cExit );
     149             : 
     150           0 :     rtl::OStringBuffer aText(rtl::OUStringToOString(rText, RTL_TEXTENCODING_UTF8));
     151           0 :     aText.append(RTL_CONSTASCII_STRINGPARAM("\r\n"));
     152           0 :     fprintf(stderr, "%s", aText.getStr());
     153           0 : }
     154             : 
     155             : // -----------------------------------------------------------------------------
     156             : 
     157           0 : void BmpApp::ShowUsage()
     158             : {
     159           0 :     Message( String( RTL_CONSTASCII_USTRINGPARAM( "Usage:" ) ), EXIT_NOERROR );
     160           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 );
     161           0 :     Message( String( RTL_CONSTASCII_USTRINGPARAM( "Options:" ) ), EXIT_NOERROR );
     162           0 :     Message( String( RTL_CONSTASCII_USTRINGPARAM( "   -i ...        name of directory to be searched for input files [multiple occurrence is possible]" ) ), EXIT_NOERROR );
     163           0 :     Message( String( RTL_CONSTASCII_USTRINGPARAM( "   -f            name of file, output should be written to" ) ), EXIT_NOERROR );
     164           0 :     Message( String( RTL_CONSTASCII_USTRINGPARAM( "Examples:" ) ), EXIT_NOERROR );
     165           0 :     Message( String( RTL_CONSTASCII_USTRINGPARAM( "    bmp /home/test.srs /home/out enus 01 -i /home/res -f /home/out/bmp.err" ) ), EXIT_NOERROR );
     166           0 : }
     167             : 
     168             : // -----------------------------------------------------------------------------
     169             : 
     170           0 : int BmpApp::Start( const ::std::vector< String >& rArgs )
     171             : {
     172           0 :     String aOutName;
     173             : 
     174           0 :     cExitCode = EXIT_NOERROR;
     175             : 
     176           0 :     if( rArgs.size() >= 6 )
     177             :     {
     178             :         LangInfo                aLangInfo;
     179           0 :         sal_uInt16                  nCurCmd = 0;
     180           0 :         const String            aSrsName( rArgs[ nCurCmd++ ] );
     181           0 :         ::std::vector< String > aInDirVector;
     182             : 
     183           0 :         aOutName = rArgs[ nCurCmd++ ];
     184             : 
     185           0 :         rtl::OString aLangDir(rtl::OUStringToOString(rArgs[nCurCmd++], RTL_TEXTENCODING_ASCII_US));
     186           0 :         aLangInfo.mnLangNum = static_cast< sal_uInt16 >( rArgs[ nCurCmd++ ].ToInt32() );
     187             : 
     188           0 :         memcpy( aLangInfo.maLangDir, aLangDir.getStr(), aLangDir.getLength() + 1 );
     189             : 
     190           0 :         GetCommandOption( rArgs, rtl::OUString('f'), aOutputFileName );
     191           0 :         GetCommandOptions( rArgs, rtl::OUString('i'), aInDirVector );
     192             : 
     193           0 :         Create( aSrsName, aInDirVector, aOutName, aLangInfo );
     194             :     }
     195             :     else
     196             :     {
     197           0 :         ShowUsage();
     198           0 :         cExitCode = EXIT_COMMONERROR;
     199             :     }
     200             : 
     201           0 :     if( ( EXIT_NOERROR == cExitCode ) && aOutputFileName.Len() && aOutName.Len() )
     202             :     {
     203           0 :         SvFileStream    aOStm( aOutputFileName, STREAM_WRITE | STREAM_TRUNC );
     204           0 :         rtl::OStringBuffer aStr(RTL_CONSTASCII_STRINGPARAM("Successfully generated ImageList(s) in: "));
     205           0 :         aStr.append(rtl::OUStringToOString(aOutName, RTL_TEXTENCODING_UTF8));
     206           0 :         aOStm.WriteLine(aStr.makeStringAndClear());
     207           0 :         aOStm.Close();
     208             :     }
     209             : 
     210           0 :     return cExitCode;
     211             : }
     212             : 
     213             : // --------
     214             : // - Main -
     215             : // --------
     216             : 
     217           0 : int main( int nArgCount, char* ppArgs[] )
     218             : {
     219             : #ifdef UNX
     220             :     static char aDisplayVar[ 1024 ];
     221             : 
     222           0 :     strcpy( aDisplayVar, "DISPLAY=" );
     223           0 :     putenv( aDisplayVar );
     224             : #endif
     225             : 
     226           0 :     ::std::vector< String > aArgs;
     227           0 :     BmpApp                  aBmpApp;
     228             : 
     229           0 :     InitVCL();
     230             : 
     231           0 :     for( int i = 1; i < nArgCount; i++ )
     232           0 :         aArgs.push_back( String( ppArgs[ i ], RTL_TEXTENCODING_ASCII_US ) );
     233             : 
     234           0 :     return aBmpApp.Start( aArgs );
     235             : }
     236             : 
     237             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10