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

Generated by: LCOV version 1.10