LCOV - code coverage report
Current view: top level - l10ntools/source - common.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 27 58 46.6 %
Date: 2014-11-03 Functions: 3 5 60.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             : 
      10             : #include "common.hxx"
      11             : 
      12             : //flags for handleArguments()
      13             : #define STATE_NON       0x0001
      14             : #define STATE_INPUT     0x0002
      15             : #define STATE_OUTPUT    0x0003
      16             : #define STATE_MERGESRC  0x0005
      17             : #define STATE_LANGUAGES 0x0006
      18             : 
      19             : namespace common {
      20             : 
      21           8 : bool handleArguments(
      22             :     int argc, char * argv[], HandledArgs& o_aHandledArgs)
      23             : {
      24           8 :     o_aHandledArgs = HandledArgs();
      25           8 :     sal_uInt16 nState = STATE_NON;
      26             : 
      27          72 :     for( int i = 1; i < argc; i++ )
      28             :     {
      29          64 :         if ( OString( argv[ i ] ).toAsciiUpperCase() == "-I" )
      30             :         {
      31           8 :             nState = STATE_INPUT; // next token specifies source file
      32             :         }
      33          56 :         else if ( OString( argv[ i ] ).toAsciiUpperCase() == "-O" )
      34             :         {
      35           8 :             nState = STATE_OUTPUT; // next token specifies the dest file
      36             :         }
      37          48 :         else if ( OString( argv[ i ] ).toAsciiUpperCase() == "-M" )
      38             :         {
      39           8 :             nState = STATE_MERGESRC; // next token specifies the merge database
      40           8 :             o_aHandledArgs.m_bMergeMode = true;
      41             :         }
      42          40 :         else if ( OString( argv[ i ] ).toAsciiUpperCase() == "-L" )
      43             :         {
      44           8 :             nState = STATE_LANGUAGES;
      45             :         }
      46          32 :         else if ( OString( argv[ i ] ).toAsciiUpperCase() == "-B" )
      47             :         {
      48           0 :             o_aHandledArgs.m_bUTF8BOM = true;
      49             :         }
      50             :         else
      51             :         {
      52          32 :             switch ( nState )
      53             :             {
      54             :                 case STATE_NON:
      55             :                 {
      56           0 :                     return false;    // no valid command line
      57             :                 }
      58             :                 case STATE_INPUT:
      59             :                 {
      60           8 :                     o_aHandledArgs.m_sInputFile = OString( argv[i] );
      61             :                 }
      62           8 :                 break;
      63             :                 case STATE_OUTPUT:
      64             :                 {
      65           8 :                     o_aHandledArgs.m_sOutputFile = OString( argv[i] );
      66             :                 }
      67           8 :                 break;
      68             :                 case STATE_MERGESRC:
      69             :                 {
      70           8 :                     o_aHandledArgs.m_sMergeSrc = OString( argv[i] );
      71             :                 }
      72           8 :                 break;
      73             :                 case STATE_LANGUAGES:
      74             :                 {
      75           8 :                     o_aHandledArgs.m_sLanguage = OString( argv[i] );
      76             :                 }
      77           8 :                 break;
      78             :             }
      79             :         }
      80             :     }
      81          16 :     if( !o_aHandledArgs.m_sInputFile.isEmpty() &&
      82           8 :         !o_aHandledArgs.m_sOutputFile.isEmpty() )
      83             :     {
      84           8 :         return true;
      85             :     }
      86             :     else
      87             :     {
      88           0 :         o_aHandledArgs = HandledArgs();
      89           0 :         return false;
      90             :     }
      91             : }
      92             : 
      93           0 : void writeUsage(const OString& rName, const OString& rFileType)
      94             : {
      95             :     std::cout
      96           0 :         << " Syntax: " << rName.getStr()
      97             :         << " -i FileIn -o FileOut [-m DataBase] [-l Lang] [-b]\n"
      98           0 :            " FileIn:   Source files (" << rFileType.getStr() << ")\n"
      99             :            " FileOut:  Destination file (*.*)\n"
     100             :            " DataBase: Mergedata (*.po)\n"
     101             :            " Lang: Restrict the handled language; one element of\n"
     102             :            " (de, en-US, ...) or all\n"
     103           0 :            " -b:   Add UTF-8 Byte Order Mark to FileOut(use with -m option)\n";
     104           0 : }
     105             : 
     106           0 : void writePoEntry(
     107             :     const OString& rExecutable, PoOfstream& rPoStream, const OString& rSourceFile,
     108             :     const OString& rResType, const OString& rGroupId, const OString& rLocalId,
     109             :     const OString& rHelpText, const OString& rText, const PoEntry::TYPE eType )
     110             : {
     111             :     try
     112             :     {
     113           0 :         PoEntry aPO(rSourceFile, rResType, rGroupId, rLocalId, rHelpText, rText, eType);
     114           0 :         rPoStream.writeEntry( aPO );
     115             :     }
     116           0 :     catch( PoEntry::Exception& aException )
     117             :     {
     118           0 :         if(aException == PoEntry::NOSOURCFILE)
     119             :         {
     120           0 :             std::cerr << rExecutable << " warning: no sourcefile specified for po entry\n";
     121             :         }
     122             :         else
     123             :         {
     124           0 :             std::cerr << rExecutable << " warning: invalid po attributes extracted from " <<  rSourceFile << "\n";
     125           0 :             if(aException == PoEntry::NOGROUPID)
     126             :             {
     127           0 :                 std::cerr << "No groupID specified!\n";
     128           0 :                 std::cerr << "String: " << rText << "\n";
     129             :             }
     130           0 :             else if (aException == PoEntry::NOSTRING)
     131             :             {
     132           0 :                 std::cerr << "No string specified!\n";
     133           0 :                 std::cerr << "GroupID: " << rGroupId << "\n";
     134           0 :                 if( !rLocalId.isEmpty() ) std::cerr << "LocalID: " << rLocalId << "\n";
     135             :             }
     136             :             else
     137             :             {
     138           0 :                 if (aException == PoEntry::NORESTYPE)
     139             :                 {
     140           0 :                     std::cerr << "No resource type specified!\n";
     141             :                 }
     142           0 :                 else if (aException == PoEntry::WRONGHELPTEXT)
     143             :                 {
     144           0 :                     std::cerr << "x-comment length is 5 characters:" << rHelpText << "\n";
     145             :                 }
     146             : 
     147           0 :                 std::cerr << "GroupID: " << rGroupId << "\n";
     148           0 :                 if( !rLocalId.isEmpty() ) std::cerr << "LocalID: " << rLocalId << "\n";
     149           0 :                 std::cerr << "String: " << rText << "\n";
     150             :             }
     151             :         }
     152             :     }
     153           0 : }
     154             : 
     155          24 : }
     156             : 
     157             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10