[Libreoffice-commits] .: l10ntools/inc l10ntools/source

Tor Lillqvist tml at kemper.freedesktop.org
Wed Mar 30 07:28:53 PDT 2011


 l10ntools/inc/inireader.hxx     |   55 ----------------
 l10ntools/inc/treeconfig.hxx    |   31 ---------
 l10ntools/source/inireader.cxx  |  135 ----------------------------------------
 l10ntools/source/localize.cxx   |   57 +++-------------
 l10ntools/source/makefile.mk    |    2 
 l10ntools/source/treeconfig.cxx |  131 --------------------------------------
 6 files changed, 14 insertions(+), 397 deletions(-)

New commits:
commit d5370052d2b27901fb268d7d487d187fc4d85045
Author: Tor Lillqvist <tlillqvist at novell.com>
Date:   Wed Mar 30 17:26:25 2011 +0300

    Bin some Hamburg crack
    
    We don't need the possibility to use a "source_config" file that would
    list "repositories".

diff --git a/l10ntools/inc/inireader.hxx b/l10ntools/inc/inireader.hxx
deleted file mode 100644
index 0112c79..0000000
--- a/l10ntools/inc/inireader.hxx
+++ /dev/null
@@ -1,55 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-#include <string>
-#include <boost/unordered_map.hpp>
-#include <unicode/regex.h>
-
-using namespace std;
-
-namespace transex3
-{
-
-struct eqstr
-{
-    bool operator()( const string s1 , const string s2) const
-    {
-        return s1.compare( s2 ) == 0;
-    }
-};
-
-typedef boost::unordered_map< string , string > stringmap;
-typedef boost::unordered_map< string, stringmap* > INImap;
-
-class INIreader
-{
-    private:
-        UErrorCode section_status;  
-        UErrorCode parameter_status; 
-        RegexMatcher* section_match;
-        RegexMatcher* parameter_match;
-
-    public: 
-        INIreader(): section_status   ( U_ZERO_ERROR ) ,
-                     parameter_status ( U_ZERO_ERROR ) 
-        {
-                     section_match   = new RegexMatcher   ( "^\\s*\\[([a-zA-Z0-9]*)\\].*" , 0 , section_status );
-                     parameter_match = new RegexMatcher   ( "^\\s*([a-zA-Z0-9]*)\\s*=\\s*([a-zA-Z0-9 ]*).*" , 0 , parameter_status ) ;
-        }
-        ~INIreader()
-        {
-            delete section_match;
-            delete parameter_match;
-        }
-        // open "filename", fill boost::unordered_map with sections / paramaters 
-        bool read( INImap& myMap , string& filename );
-       
-    private:
-        bool is_section( string& line , string& section_str );
-        bool is_parameter( string& line , string& parameter_key , string& parameter_value );
-        inline void check_status( UErrorCode status );
-        inline void toStlString ( const UnicodeString& str, string& stl_str );
-        inline void trim( string& str );
-};
-
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/l10ntools/inc/treeconfig.hxx b/l10ntools/inc/treeconfig.hxx
deleted file mode 100644
index f5c3794..0000000
--- a/l10ntools/inc/treeconfig.hxx
+++ /dev/null
@@ -1,31 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-#include <vector>
-#include <string>
-
-#include "inireader.hxx"
-
-namespace transex3{
-
-class Treeconfig
-{
-
-    private:
-        INIreader   inireader;    
-        INImap      map;
-        bool        has_config_file;
-        void getCurrentDir( string& dir );
-        bool isConfigFilePresent();
-
-    public:
-    
-        Treeconfig() : has_config_file( false ) { parseConfig(); }
-        // read the config file, returns true in case a config file had been found
-        bool parseConfig();
-        // returns a string vector containing all active  repositories, returns true in case we are deep inside
-        // of a source tree. This could affect the behavour of the tool
-        bool getActiveRepositories( vector<string>& active_repos);
-};
-
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/l10ntools/source/inireader.cxx b/l10ntools/source/inireader.cxx
deleted file mode 100644
index 0510595..0000000
--- a/l10ntools/source/inireader.cxx
+++ /dev/null
@@ -1,135 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-#include <unicode/regex.h>
-#include <unicode/unistr.h>
-#include <string>
-#include <fstream>
-#include <iostream>
-#include "inireader.hxx"
-
-using namespace std;
-namespace transex3
-{
-
-bool INIreader::read( INImap& myMap , string& filename )
-{
-    ifstream aFStream( filename.c_str() ); 
-    if( aFStream && aFStream.is_open())		
-    {
-        string line;
-        string section;
-        string param_key;
-        string param_value;
-        stringmap* myvalues = 0;
-
-        while( std::getline( aFStream , line ) )
-        {
-            trim( line );
-            if( line.empty() ){
-            }
-            else if( is_section( line , section ) )
-            {
-                //cerr << "[" << section << "]\n"; 
-                myvalues = new stringmap();
-                myMap[ section ] = myvalues ;
-            }
-            else if ( is_parameter( line , param_key , param_value ) )
-            {
-                //cerr << "" << param_key << " = " << param_value << "\n";
-                if( myvalues )
-                {
-                    (*myvalues)[ param_key ] = param_value ;
-                }
-                else
-                {
-                    cerr << "ERROR: The INI file " << filename << " appears to be broken ... parameters without a section?!?\n";
-                    if( aFStream.is_open() ) aFStream.close();
-                    return false;
-                }
-            }
-        }
-
-        if( aFStream.is_open() ) 
-            aFStream.close();
-        
-        return true;
-    }
-    else
-    {
-        cerr << "ERROR: Can't open file '" << filename << "'\n";
-    }
-    return false;
-}
-
-bool INIreader::is_section( string& line , string& section_str )
-{
-    // Error in regex ?
-    check_status( section_status );
-    UnicodeString target( line.c_str() , line.length() );
-    
-    section_match->reset( target );
-    check_status( section_status );
-
-    if( section_match->find() )
-    {
-        check_status( section_status );
-        UnicodeString result(  section_match->group( 1 , section_status) );
-        check_status( section_status );
-        toStlString( result , section_str );
-        
-        return true;
-    }
-    return false;
-}
-
-bool INIreader::is_parameter( string& line , string& parameter_key , string& parameter_value )
-{
-    // Error in regex ?
-    check_status( parameter_status );
-    UnicodeString target( line.c_str() , line.length() );
-    
-    parameter_match->reset( target );
-    check_status( parameter_status );
-
-    if( parameter_match->find() )
-    {
-        check_status( parameter_status );
-        
-        UnicodeString result1(  parameter_match->group( 1 , parameter_status) );
-        check_status( parameter_status );
-        toStlString( result1 , parameter_key );
-        UnicodeString result2(  parameter_match->group( 2 , parameter_status) );
-        check_status( parameter_status );
-        toStlString( result2 , parameter_value );
-        
-        return true;
-    }
-    return false;
-}
-
-void INIreader::check_status( UErrorCode status )
-{
-    if( U_FAILURE( status) )
-    {   
-        cerr << "Error in or while using regex: " << u_errorName( status ) << "\n";
-        exit(-1);
-    }
-}
-
-void INIreader::toStlString( const UnicodeString& str , string& stl_str)
-{
-         // convert to string 
-        char* buffer = new char[ str.length()*3 ];
-        str.extract( 0 , str.length() , buffer );
-        stl_str = string( buffer );
-        delete [] buffer;
-}
-
-void INIreader::trim( string& str )
-{
-    string str1 = str.substr( 0 , str.find_last_not_of(' ') + 1 );
-    str = str1.empty() ? str1 : str1.substr( str1.find_first_not_of(' ') );
-}
-
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/l10ntools/source/localize.cxx b/l10ntools/source/localize.cxx
index 588a3e7..5aaaf19 100644
--- a/l10ntools/source/localize.cxx
+++ b/l10ntools/source/localize.cxx
@@ -31,7 +31,6 @@
 
 #include "srciter.hxx"
 #include "export.hxx"
-#include "treeconfig.hxx"
 #include <string>
 #include <vector>
 #include <stdio.h>
@@ -44,6 +43,8 @@
 #include <l10ntools/file.hxx>
 #endif
 
+using namespace std;
+
 namespace transex3
 {
 
@@ -310,11 +311,11 @@ const ByteString SourceTreeLocalizer::GetProjectRootRel()
 bool skipProject( ByteString sPrj )
 {
     int nIndex = 0;
-    bool bReturn = TRUE;
+    bool bReturn = true;
     ByteString sModule( ModuleList[ nIndex ] );
     while( !sModule.Equals( "NULL" ) && bReturn ) {
         if( sPrj.Equals ( sModule ) )
-            bReturn = FALSE;
+            bReturn = false;
         nIndex++;
         sModule = ModuleList[ nIndex ];
     }
@@ -969,48 +970,16 @@ int _cdecl main( int argc, char *argv[] )
     //printf("B %s\nA %s\n",rDestinationFile.GetBuffer(), sFile.GetBuffer()); 
     sFileName = sFileABS;
 
-    Treeconfig treeconfig;
-    vector<string> repos;
-    bool hasPwd = treeconfig.getActiveRepositories( repos );
-    if( hasPwd ) cout << "Found special path!\n";
-
-    // localize through all repositories
-    for( vector<string>::iterator iter = repos.begin(); iter != repos.end() ; ++iter )
-    {
-        string curRepository;
-        curRepository = string( Export::GetEnv("SRC_ROOT") ) + "/" + *iter;
-        cout << "Localizing repository " << curRepository << "\n";
-        SourceTreeLocalizer aIter( ByteString( curRepository.c_str() ) , sVersion , (sOutput.Len() > 0) , bSkipLinks );
-        aIter.SetLanguageRestriction( sLanguages );	 
-        if ( bExport ){
-            fflush( stdout );
-            if( *iter == "ooo" )
-                aIter.Extract( sFileName );
-            else
-            {
-                ByteString sFileNameWithExt( sFileName );
-                sFileNameWithExt += ByteString( "." );
-                sFileNameWithExt += ByteString( (*iter).c_str() );
-                aIter.Extract( sFileNameWithExt );
-            }
-            printf("\n%d files found!\n",aIter.GetFileCnt());
-        }
+    string pwd;
+    Export::getCurrentDir( pwd );
+    cout << "Localizing directory " << pwd << "\n";
+    SourceTreeLocalizer aIter( ByteString( pwd.c_str() ) , sVersion , (sOutput.Len() > 0) , bSkipLinks );
+    aIter.SetLanguageRestriction( sLanguages );
+    if ( bExport ){
+        fflush( stdout );
+        aIter.Extract( sFileName );
+        printf("\n%d files found!\n",aIter.GetFileCnt());
     }
-    if( hasPwd )
-    {
-        string pwd;
-        Export::getCurrentDir( pwd );
-        cout << "Localizing repository " << pwd << "\n";
-        SourceTreeLocalizer aIter( ByteString( pwd.c_str() ) , sVersion , (sOutput.Len() > 0) , bSkipLinks );
-        aIter.SetLanguageRestriction( sLanguages );	 
-        if ( bExport ){
-            fflush( stdout );
-            aIter.Extract( sFileName );
-            printf("\n%d files found!\n",aIter.GetFileCnt());
-        }
- 
-    }
-
     return 0;
 }
 
diff --git a/l10ntools/source/makefile.mk b/l10ntools/source/makefile.mk
index ab28ca0..a08794f 100644
--- a/l10ntools/source/makefile.mk
+++ b/l10ntools/source/makefile.mk
@@ -130,7 +130,7 @@ APP7STDLIBS+= \
 APP9TARGET= localize_sl
 EXCEPTIONSFILES=                            \
                     $(OBJ)$/localize.obj
-APP9OBJS=   $(OBJ)$/localize.obj $(OBJ)$/utf8conv.obj $(OBJ)$/srciter.obj $(OBJ)$/export2.obj $(OBJ)$/file.obj $(OBJ)$/directory.obj $(OBJ)$/treeconfig.obj $(OBJ)$/inireader.obj
+APP9OBJS=   $(OBJ)$/localize.obj $(OBJ)$/utf8conv.obj $(OBJ)$/srciter.obj $(OBJ)$/export2.obj $(OBJ)$/file.obj $(OBJ)$/directory.obj
 
 APP9STDLIBS+= \
             $(TOOLSLIB) \
diff --git a/l10ntools/source/treeconfig.cxx b/l10ntools/source/treeconfig.cxx
deleted file mode 100644
index e6cdb49..0000000
--- a/l10ntools/source/treeconfig.cxx
+++ /dev/null
@@ -1,131 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-#include <vector>
-#include <string>
-#include <iostream>
-#include "treeconfig.hxx"
-#include "export.hxx"
-#ifdef WNT
-#include <direct.h>
-#include <io.h>
-#else
-#include <dirent.h>
-#endif
-#include <sys/stat.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-using namespace std;
-
-namespace transex3
-{
-
-bool Treeconfig::parseConfig(){
-    
-    string source_config_file = string( static_cast<ByteString>( Export::GetEnv("SRC_ROOT") ).GetBuffer() );
-    if( source_config_file.empty() )
-    {
-        cerr << "Error: no suitable environment set?!?";
-        exit( -1 );
-    }
-    source_config_file += string("/source_config");
-    if( isConfigFilePresent() )
-    {
-        inireader.read( map , source_config_file );
-        return true;
-    }
-    else return false;
-}
-
-// ALWAYS add all repositories from source_config file to the container active_repos
-// if a config_file is present ALWAYS return false
-// if you are in the root of a repository also add it to the container active_repos
-// if you are far inside a repository /my/path/ooo/sw/source then don't add it to the container but return true
-// if you are in some misc place like /tmp then return true
-// => the application can decide what to do in case the function returns true thus how to handle pwd() path
-bool Treeconfig::getActiveRepositories( vector<string>& active_repos ){
-    
-    bool isPresent = isConfigFilePresent();
-    bool hasPath   = false;
-    string pwd;
-    string guessedRepo;
-    Export::getCurrentDir( pwd );
-    string source_root = Export::GetEnv( "SRC_ROOT" );
-    string solarsrc    = Export::GetEnv( "SOLARSRC" );
-    string partial;
-
-    // if we are inside of a repository root then active it otherwise let the app handle the return!
-    string::size_type pos = pwd.find_first_of( source_root );
-    if( pos != string::npos && ( pos + source_root.length() +1 ) < pwd.length()){  // I am within SRC_ROOT
-        partial = pwd.substr( pos + source_root.length() +1  , pwd.length());
-        string::size_type nextPart = partial.find_first_of( "/" );
-        if( nextPart != string::npos )
-            hasPath = true;
-        else
-            guessedRepo = partial;
-    }
-    else                              // I am NOT within SRC_ROOT
-        hasPath = true;
-    
-    if( isPresent )
-    {
-        hasPath = false;                // if config_file is present don't care about pwd
-        stringmap* repos = static_cast<stringmap*>( map[ string("repositories") ] );
-        if( repos != 0 )
-        {
-            for( stringmap::iterator iter = repos->begin() ; iter != repos->end() ; ++iter )
-            {
-                if( static_cast<string>( iter->second ) == string( "active" ) )
-                {
-                    active_repos.push_back( iter->first );
-                    if( static_cast<string>( iter->first ) == guessedRepo )
-                    {
-                        guessedRepo.clear();            // don't add double in case it is present in config_file
-                    }
-                }
-            }
-        }
-        else
-        {
-            cerr << "Error: source_config files doesn't contain a 'repositories' section ?!?";
-            exit( -1 );
-        }
-    }
-    if( !guessedRepo.empty() ){
-        active_repos.push_back( guessedRepo );          // add myrepo
-    }
-    return hasPath;                                     // are we deep inside of a source tree or outside of SRC_ROOT?
-}
-
-void Treeconfig::getCurrentDir( string& dir )
-{
-    char buffer[64000];
-    if( getcwd( buffer , sizeof( buffer ) ) == 0 ){
-        cerr << "Error: getcwd failed!\n";
-        exit( -1 );
-    }
-    dir = string( buffer );
-}
-
-bool Treeconfig::isConfigFilePresent()
-{
-    string config_file = Export::GetEnv( "SRC_ROOT" );
-    config_file += "/source_config";
-    
-    struct stat status;
-    if( stat( config_file.c_str() , &status ) < 0 )
-    {
-        return false; 
-    }
-#ifdef WNT
-    return ( status.st_mode & _S_IFREG ) && ( _access( config_file.c_str() , 4 ) >= 0 ) ;
-#else
-    return ( status.st_mode & S_IFREG ) && ( access( config_file.c_str() , R_OK ) >= 0 ) ;
-#endif
-}
-
-
-
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list