LCOV - code coverage report
Current view: top level - libreoffice/l10ntools/source - export2.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 156 0.0 %
Date: 2012-12-17 Functions: 0 14 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             : #include "sal/config.h"
      21             : 
      22             : #include "export.hxx"
      23             : #include <stdio.h>
      24             : #include <osl/time.h>
      25             : #include <osl/process.h>
      26             : #include <rtl/strbuf.hxx>
      27             : #include <rtl/ustring.hxx>
      28             : #include <sal/macros.h>
      29             : #include <iostream>
      30             : #include <iomanip>
      31             : #include <time.h>
      32             : #include <stdlib.h>
      33             : 
      34             : //flags for handleArguments()
      35             : #define STATE_NON       0x0001
      36             : #define STATE_INPUT     0x0002
      37             : #define STATE_OUTPUT    0x0003
      38             : #define STATE_PRJ       0x0004
      39             : #define STATE_ROOT      0x0005
      40             : #define STATE_MERGESRC  0x0006
      41             : #define STATE_LANGUAGES 0x0007
      42             : 
      43             : //
      44             : // class ResData();
      45             : //
      46             : 
      47             : /*****************************************************************************/
      48           0 : ResData::~ResData()
      49             : /*****************************************************************************/
      50             : {
      51           0 :     if ( pStringList ) {
      52             :         // delete existing res. of type StringList
      53           0 :         for ( size_t i = 0; i < pStringList->size(); i++ ) {
      54           0 :             ExportListEntry* test = (*pStringList)[ i ];
      55           0 :             if( test != NULL ) delete test;
      56             :         }
      57           0 :         delete pStringList;
      58             :     }
      59           0 :     if ( pFilterList ) {
      60             :         // delete existing res. of type FilterList
      61           0 :         for ( size_t i = 0; i < pFilterList->size(); i++ ) {
      62           0 :             ExportListEntry* test = (*pFilterList)[ i ];
      63           0 :             delete test;
      64             :         }
      65           0 :         delete pFilterList;
      66             :     }
      67           0 :     if ( pItemList ) {
      68             :         // delete existing res. of type ItemList
      69           0 :         for ( size_t i = 0; i < pItemList->size(); i++ ) {
      70           0 :             ExportListEntry* test = (*pItemList)[ i ];
      71           0 :             delete test;
      72             :         }
      73           0 :         delete pItemList;
      74             :     }
      75           0 :     if ( pUIEntries ) {
      76             :         // delete existing res. of type UIEntries
      77           0 :         for ( size_t i = 0; i < pUIEntries->size(); i++ ) {
      78           0 :             ExportListEntry* test = (*pUIEntries)[ i ];
      79           0 :             delete test;
      80             :         }
      81           0 :         delete pUIEntries;
      82             :     }
      83           0 : }
      84             : 
      85             : //
      86             : // class Export
      87             : //
      88             : 
      89             : /*****************************************************************************/
      90           0 : rtl::OString Export::sLanguages;
      91             : /*****************************************************************************/
      92             : 
      93           0 : bool Export::handleArguments(
      94             :     int argc, char * argv[], HandledArgs& o_aHandledArgs)
      95             : {
      96           0 :     o_aHandledArgs = HandledArgs();
      97           0 :     sLanguages = "";
      98           0 :     sal_uInt16 nState = STATE_NON;
      99             : 
     100           0 :     for( int i = 1; i < argc; i++ )
     101             :     {
     102           0 :         if ( OString( argv[ i ] ).toAsciiUpperCase() == "-I" )
     103             :         {
     104           0 :             nState = STATE_INPUT; // next token specifies source file
     105             :         }
     106           0 :         else if ( OString( argv[ i ] ).toAsciiUpperCase() == "-O" )
     107             :         {
     108           0 :             nState = STATE_OUTPUT; // next token specifies the dest file
     109             :         }
     110           0 :         else if ( OString( argv[ i ] ).toAsciiUpperCase() == "-P" )
     111             :         {
     112           0 :             nState = STATE_PRJ; // next token specifies the cur. project
     113             :         }
     114           0 :         else if ( OString( argv[ i ] ).toAsciiUpperCase() == "-R" )
     115             :         {
     116           0 :             nState = STATE_ROOT; // next token specifies path to project root
     117             :         }
     118           0 :         else if ( OString( argv[ i ] ).toAsciiUpperCase() == "-M" )
     119             :         {
     120           0 :             nState = STATE_MERGESRC; // next token specifies the merge database
     121             :         }
     122           0 :         else if ( OString( argv[ i ] ).toAsciiUpperCase() == "-L" )
     123             :         {
     124           0 :             nState = STATE_LANGUAGES;
     125             :         }
     126             :         else
     127             :         {
     128           0 :             switch ( nState )
     129             :             {
     130             :                 case STATE_NON:
     131             :                 {
     132           0 :                     return false;    // no valid command line
     133             :                 }
     134             :                 case STATE_INPUT:
     135             :                 {
     136           0 :                     o_aHandledArgs.m_sInputFile = OString( argv[i] );
     137             :                 }
     138           0 :                 break;
     139             :                 case STATE_OUTPUT:
     140             :                 {
     141           0 :                     o_aHandledArgs.m_sOutputFile = OString( argv[i] );
     142             :                 }
     143           0 :                 break;
     144             :                 case STATE_PRJ:
     145             :                 {
     146           0 :                     o_aHandledArgs.m_sPrj = OString( argv[i] );
     147             :                 }
     148           0 :                 break;
     149             :                 case STATE_ROOT:
     150             :                 {
     151           0 :                     o_aHandledArgs.m_sPrjRoot = OString( argv[i] );
     152             :                 }
     153           0 :                 break;
     154             :                 case STATE_MERGESRC:
     155             :                 {
     156           0 :                     o_aHandledArgs.m_sMergeSrc = OString( argv[i] );
     157           0 :                     o_aHandledArgs.m_bMergeMode = true;
     158             :                 }
     159           0 :                 break;
     160             :                 case STATE_LANGUAGES:
     161             :                 {
     162           0 :                     sLanguages = OString( argv[i] );
     163             :                 }
     164           0 :                 break;
     165             :             }
     166             :         }
     167             :     }
     168           0 :     if( !o_aHandledArgs.m_sInputFile.isEmpty() &&
     169           0 :         !o_aHandledArgs.m_sOutputFile.isEmpty() )
     170             :     {
     171           0 :         return true;
     172             :     }
     173             :     else
     174             :     {
     175           0 :         o_aHandledArgs = HandledArgs();
     176           0 :         return false;
     177             :     }
     178             : }
     179             : 
     180           0 : void Export::writeUsage(const OString& rName, const OString& rFileType)
     181             : {
     182             :     std::cout
     183           0 :         << "Syntax: " << rName.getStr()
     184           0 :         << " [-p Prj] [-r PrjRoot] -i FileIn -o FileOut"
     185           0 :         << " [-m DataBase] [-l l1,l2,...]\n"
     186           0 :         << " Prj:      Project\n"
     187           0 :         << " PrjRoot:  Path to project root (../.. etc.)\n"
     188           0 :         << " FileIn:   Source files (*." << rFileType.getStr() << ")\n"
     189           0 :         << " FileOut:  Destination file (*.*)\n"
     190           0 :         << " DataBase: Mergedata (*.po)\n"
     191           0 :         << " -l: Restrict the handled languages; l1, l2, ... are elements of"
     192           0 :         << " (de, en-US, ...)\n";
     193           0 : }
     194             : 
     195             : /*****************************************************************************/
     196           0 : void Export::SetLanguages( std::vector<rtl::OString> val ){
     197             : /*****************************************************************************/
     198           0 :     aLanguages = val;
     199           0 :     isInitialized = true;
     200           0 : }
     201             : /*****************************************************************************/
     202           0 : std::vector<rtl::OString> Export::GetLanguages(){
     203             : /*****************************************************************************/
     204           0 :     return aLanguages;
     205             : }
     206           0 : std::vector<rtl::OString> Export::aLanguages       = std::vector<rtl::OString>();
     207           0 : std::vector<rtl::OString> Export::aForcedLanguages = std::vector<rtl::OString>();
     208             : 
     209             : /*****************************************************************************/
     210           0 : rtl::OString Export::QuoteHTML( rtl::OString const &rString )
     211             : /*****************************************************************************/
     212             : {
     213           0 :     rtl::OStringBuffer sReturn;
     214           0 :     for ( sal_Int32 i = 0; i < rString.getLength(); i++ ) {
     215           0 :         rtl::OString sTemp = rString.copy( i );
     216           0 :         if ( sTemp.match( "<Arg n=" ) ) {
     217           0 :             while ( i < rString.getLength() && rString[i] != '>' ) {
     218           0 :                  sReturn.append(rString[i]);
     219           0 :                 i++;
     220             :             }
     221           0 :             if ( rString[i] == '>' ) {
     222           0 :                 sReturn.append('>');
     223           0 :                 i++;
     224             :             }
     225             :         }
     226           0 :         if ( i < rString.getLength()) {
     227           0 :             switch ( rString[i]) {
     228             :                 case '<':
     229           0 :                     sReturn.append("&lt;");
     230           0 :                 break;
     231             : 
     232             :                 case '>':
     233           0 :                     sReturn.append("&gt;");
     234           0 :                 break;
     235             : 
     236             :                 case '\"':
     237           0 :                     sReturn.append("&quot;");
     238           0 :                 break;
     239             : 
     240             :                 case '\'':
     241           0 :                     sReturn.append("&apos;");
     242           0 :                 break;
     243             : 
     244             :                 case '&':
     245           0 :                     if ((( i + 4 ) < rString.getLength()) &&
     246           0 :                         ( rString.copy( i, 5 ) == "&amp;" ))
     247           0 :                             sReturn.append(rString[i]);
     248             :                     else
     249           0 :                         sReturn.append("&amp;");
     250           0 :                 break;
     251             : 
     252             :                 default:
     253           0 :                     sReturn.append(rString[i]);
     254           0 :                 break;
     255             :             }
     256             :         }
     257           0 :     }
     258           0 :     return sReturn.makeStringAndClear();
     259             : }
     260             : 
     261           0 : void Export::RemoveUTF8ByteOrderMarker( rtl::OString &rString )
     262             : {
     263           0 :     if( hasUTF8ByteOrderMarker( rString ) )
     264           0 :         rString = rString.copy(3);
     265           0 : }
     266             : 
     267           0 : bool Export::hasUTF8ByteOrderMarker( const rtl::OString &rString )
     268             : {
     269           0 :     return rString.getLength() >= 3 && rString[0] == '\xEF' &&
     270           0 :            rString[1] == '\xBB' && rString[2] == '\xBF' ;
     271             : }
     272             : 
     273             : /*****************************************************************************/
     274           0 : rtl::OString Export::UnquoteHTML( rtl::OString const &rString )
     275             : /*****************************************************************************/
     276             : {
     277           0 :     rtl::OStringBuffer sReturn;
     278           0 :     for (sal_Int32 i = 0; i != rString.getLength();) {
     279           0 :         if (rString.match("&amp;", i)) {
     280           0 :             sReturn.append('&');
     281           0 :             i += RTL_CONSTASCII_LENGTH("&amp;");
     282           0 :         } else if (rString.match("&lt;", i)) {
     283           0 :             sReturn.append('<');
     284           0 :             i += RTL_CONSTASCII_LENGTH("&lt;");
     285           0 :         } else if (rString.match("&gt;", i)) {
     286           0 :             sReturn.append('>');
     287           0 :             i += RTL_CONSTASCII_LENGTH("&gt;");
     288           0 :         } else if (rString.match("&quot;", i)) {
     289           0 :             sReturn.append('"');
     290           0 :             i += RTL_CONSTASCII_LENGTH("&quot;");
     291           0 :         } else if (rString.match("&apos;", i)) {
     292           0 :             sReturn.append('\'');
     293           0 :             i += RTL_CONSTASCII_LENGTH("&apos;");
     294             :         } else {
     295           0 :             sReturn.append(rString[i]);
     296           0 :             ++i;
     297             :         }
     298             :     }
     299           0 :     return sReturn.makeStringAndClear();
     300             : }
     301             : 
     302           0 : bool Export::isSourceLanguage(const rtl::OString &rLanguage)
     303             : {
     304           0 :     return !isAllowed(rLanguage);
     305             : }
     306             : 
     307           0 : bool Export::isAllowed(const rtl::OString &rLanguage)
     308             : {
     309           0 :     return !rLanguage.equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("en-US"));
     310             : }
     311             : 
     312             : bool Export::isInitialized = false;
     313             : 
     314             : /*****************************************************************************/
     315           0 : void Export::InitLanguages( bool bMergeMode ){
     316             : /*****************************************************************************/
     317           0 :     if( !isInitialized )
     318             :     {
     319           0 :         rtl::OString sTmp;
     320           0 :         OStringBoolHashMap aEnvLangs;
     321             : 
     322           0 :         sal_Int32 nIndex = 0;
     323           0 :         do
     324             :         {
     325           0 :             rtl::OString aToken = sLanguages.getToken(0, ',', nIndex);
     326           0 :             sTmp = aToken.getToken(0, '=').trim();
     327           0 :             if( bMergeMode && !isAllowed( sTmp ) ){}
     328           0 :             else if( !( (sTmp[0]=='x' || sTmp[0]=='X') && sTmp[1]=='-' ) ){
     329           0 :                 aLanguages.push_back( sTmp );
     330           0 :             }
     331             :         }
     332             :         while ( nIndex >= 0 );
     333             : 
     334           0 :         isInitialized = true;
     335             :     }
     336           0 : }
     337             : 
     338             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10