1. mst
  2. ooo340

Commits

Simon Wilper  committed a730fee

toolsfixes: #115441# replaced SvStreams and Co

  • Participants
  • Parent commits 91e0afc
  • Branches default

Comments (0)

Files changed (4)

File l10ntools/inc/export.hxx

View file
  • Ignore whitespace
 
 #ifndef L10NTOOLS_DIRECTORY_HXX
 #define L10NTOOLS_DIRECTORY_HXX
+
 #include <l10ntools/directory.hxx>
+
 #endif
 
-
-// #define MERGE_SOURCE_LANGUAGES <- To merge en-US and de resource 
+/*
+#define MERGE_SOURCE_LANGUAGES <- To merge en-US and de resource 
 
 #include <tools/string.hxx>
-#include <tools/list.hxx>
-#include <tools/stream.hxx>
 #include <tools/fsys.hxx>
 #include <osl/file.hxx>
 #include <osl/file.h>
+#include <tools/stream.hxx>
+*/
 
-#include <hash_map> /* std::hashmap*/
-#include <iterator> /* std::iterator*/
-#include <set>      /* std::set*/
-#include <vector>   /* std::vector*/
+#include <tools/list.hxx>
+
+#include <cstring>
+
+#include <hash_map> /* std::hashmap */
+#include <iterator> /* std::iterator */
+#include <set>      /* std::set */
+#include <vector>   /* std::vector */
 #include <queue>    
-#include <string>       /* std::string */
-#include <sstream> /* std::stringstream */
-#include <cctype> /* toupper() */
+#include <string>   /* std::string */
+#include <sstream>  /* std::stringstream */
+#include <iostream>
+#include <fstream>
+#include <cctype>   /* toupper() */
 
 #include <unistd.h>
+
 #ifdef WNT
 #include <direct.h>
 #endif
 
-#define NO_TRANSLATE_ISO		"x-no-translate"
-
+#define NO_TRANSLATE_ISO "x-no-translate"
 #define JAPANESE_ISO "ja"
 
 /** Iterates over a std::string and removes all characters c returning
  * @param c the character that shall be removed
  * @returns the string with the specified character removed
  */
-std::string EraseAllChars( std::string str, char c ) {
-    std::string::iterator i = str.begin();
-    std::stringstream buffer;
+std::string eraseAllChars( std::string str, char c )
+{
+	std::string::iterator i = str.begin();
+	std::stringstream buffer;
 	while ( i != str.end() ) {
 		if ( *i != c ) buffer << *i;
 		i++;
 	}
-
 	return buffer.str();
 }
 
  * @param str the source string to process
  * @returns the uppercase string
  */
-std::string ToUpperAscii( std::string str ) {
-    std::string::iterator i = str.begin();
-    std::stringstream buffer;
+std::string toUpperAscii( std::string str )
+{
+	std::string::iterator i = str.begin();
+	std::stringstream buffer;
 	while ( i != str.end() ) {
-        char c = *i;
+		char c = *i;
 		if ( isascii( c ) && isalpha( c ) && islower( c ) )
-            buffer << (char)toupper(c);
-        else
-            buffer << c;
+			buffer << (char)toupper(c);
+		else
+			buffer << c;
 		i++;
 	}
-
 	return buffer.str();
 }
 
-struct eqstr{
-  BOOL operator()(const char* s1, const char* s2) const{
-    return strcmp(s1,s2)==0;
-  }
+/** Converts a std::string to lowercase
+ *
+ * @param str the source string to process
+ * @returns the lowercase string
+ */
+std::string toLowerAscii( std::string str )
+{
+	std::string::iterator i = str.begin();
+	std::stringstream buffer;
+	while ( i != str.end() ) {
+		char c = *i;
+		if ( isascii( c ) && isalpha( c ) && isupper( c ) )
+			buffer << (char)tolower(c);
+		else
+			buffer << c;
+		i++;
+	}
+	return buffer.str();
+}
+
+struct eqstr
+{
+	bool operator()( const char* s1, const char* s2 ) const
+	{
+		return strcmp( s1, s2 ) == 0;
+	}
 };
 
-struct equalstring{
-        bool operator()( const std::string& rKey1, const std::string& rKey2 ) const {
-            return rKey1 == rKey2; //rKey1.CompareTo( rKey2 )==COMPARE_EQUAL;
-    }
-};
-struct lessstring{
-        bool operator()( const std::string& rKey1, const std::string& rKey2 ) const {
-            return rKey1 < rKey2; //rKey1.CompareTo( rKey2 )==COMPARE_LESS;
-    }
+struct equalstring
+{
+	bool operator()( const std::string& rKey1, const std::string& rKey2 ) const
+	{
+		return rKey1 == rKey2; //rKey1.CompareTo( rKey2 )==COMPARE_EQUAL;
+	}
 };
 
-struct hashstring{
-    size_t operator()( const std::string& rName ) const{
-                std::hash< const char* > myHash;
-                return myHash( rName.c_str() );
-    }
+struct lessstring
+{
+	bool operator()( const std::string& rKey1, const std::string& rKey2 ) const
+	{
+		return rKey1 < rKey2; //rKey1.CompareTo( rKey2 )==COMPARE_LESS;
+	}
+};
+
+struct hashstring
+{
+	size_t operator()( const std::string& rName ) const
+	{
+		std::hash< const char* > myHash;
+		return myHash( rName.c_str() );
+	}
 };
 
 class PFormEntrys;
 	MergeDataHashMap;
 
 #define SOURCE_LANGUAGE std::string("en-US")
-#define LIST_REFID  "LIST_REFID"
+#define LIST_REFID "LIST_REFID"
 
 typedef stringHashMap ExportListEntry;
 
-DECLARE_LIST( ExportListBase, ExportListEntry * )
+//DECLARE_LIST( ExportListBase, ExportListEntry * )
 
 //
 // class ExportList
 //
 
-class ExportList : public ExportListBase
+//class ExportList : public ExportListBase
+class ExportList : public std::vector<ExportListEntry*>
 {
 private:
 	ULONG nSourceLanguageListEntryCount;
 
 public:
-	ExportList() : ExportListBase() { nSourceLanguageListEntryCount = 0; }
+	ExportList() { nSourceLanguageListEntryCount = 0; }
 	ULONG GetSourceLanguageListEntryCount() { return nSourceLanguageListEntryCount; }
 	void NewSourceLanguageListEntry() { nSourceLanguageListEntryCount++; }
 };
 {
 public:
 	~ResData();
-	BOOL SetId( const std::string &rId, USHORT nLevel );
+	bool SetId( const std::string &rId, USHORT nLevel );
     
-    USHORT nWidth;
-	USHORT nChildIndex;
-	USHORT nIdLevel;
-	BOOL bChild;
-	BOOL bChildWithText;
+    unsigned int nWidth;
+	unsigned int nChildIndex;
+	unsigned int nIdLevel;
+	bool bChild;
+	bool bChildWithText;
 
-	BOOL bText;
-	BOOL bHelpText;
-	BOOL bQuickHelpText;
-	BOOL bTitle;
-	BOOL bList;
+	bool bText;
+	bool bHelpText;
+	bool bQuickHelpText;
+	bool bTitle;
+	bool bList;
 
-	BOOL bRestMerged;
+	bool bRestMerged;
 
     std::string sResTyp;
     std::string sId;
     std::string sFilename;
 
 	stringHashMap sText;
-	USHORT nTextRefId;
+	unsigned int nTextRefId;
 
 	stringHashMap sHelpText;
-    USHORT nHelpTextRefId;
+    unsigned int nHelpTextRefId;
 
 	stringHashMap sQuickHelpText;
-    USHORT nQuickHelpTextRefId;
+    unsigned int nQuickHelpTextRefId;
 
 	stringHashMap sTitle;
-    USHORT nTitleRefId;
+    unsigned int nTitleRefId;
 
 	std::string sTextTyp;
 	stringHashMap aFallbackData;
 	
 	void addMergedLanguage( std::string& sLang );
 	bool isMerged( std::string& sLang );
-	ResData( const std::string &rPF, const std::string &rGId )
-			: 
+	ResData( const std::string &rPF, const std::string &rGId ) : 
             nWidth( 0 ),
             nChildIndex( 0 ),
             nIdLevel( ID_LEVEL_NULL ),
-            bChild( FALSE ),
-            bChildWithText( FALSE ),
-            bText( FALSE ),
-            bHelpText( FALSE ),
-            bQuickHelpText( FALSE ),
-            bTitle( FALSE ),
-            bList( FALSE ),
-            bRestMerged( FALSE ),
+            bChild( false ),
+            bChildWithText( false ),
+            bText( false ),
+            bHelpText( false ),
+            bQuickHelpText( false ),
+            bTitle( false ),
+            bList( false ),
+            bRestMerged( false ),
             sGId( rGId ),
             nTextRefId( REFID_NONE ),
             nHelpTextRefId( REFID_NONE ),
             pPairedList( NULL ),
             sPForm( rPF )
 	{
-		sGId = EraseAllChars( sGId, '\r' );
-		sPForm = EraseAllChars( sPForm, '\r' );
+		sGId = eraseAllChars( sGId, '\r' );
+		sPForm = eraseAllChars( sPForm, '\r' );
 	};
 	ResData( const std::string &rPF, const std::string &rGId , const std::string &rFilename )
 			: 			
             sPForm( rPF )
 
 	{
-		sGId = EraseAllChars( sGId, '\r' );
-		sPForm = EraseAllChars( sPForm, '\r' );
+		sGId = eraseAllChars( sGId, '\r' );
+		sPForm = eraseAllChars( sPForm, '\r' );
 	};
 
 
 #define MERGE_MODE_NORMAL			0x0000
 #define MERGE_MODE_LIST				0x0001
 
-DECLARE_LIST( ResStack, ResData * )
+//DECLARE_LIST( ResStack, ResData * )
 // forwards
-class WordTransformer;
+//class WordTransformer;
 class ParserQueue;
 
 class Export
 {
 private:
-	WordTransformer	*pWordTransformer;
+	//WordTransformer	*pWordTransformer;
 
 	CharSet	aCharSet;					// used charset in src
 
-	SvFileStream aOutput;
+	//SvFileStream aOutput;
+	std::ofstream aOutput;
     
-	ResStack aResStack;					// stack for parsing recursive
+	//ResStack aResStack;					// stack for parsing recursive
+	std::vector<ResData*> aResStack;
 
 	std::string sActPForm;				// hold cur. system
 
-	BOOL bDefine;						// cur. res. in a define?
-	BOOL bNextMustBeDefineEOL;			// define but no \ at lineend
+	bool bDefine;						// cur. res. in a define?
+	bool bNextMustBeDefineEOL;			// define but no \ at lineend
 	ULONG nLevel;						// res. recursiv? how deep?
 	USHORT nList;						// cur. res. is String- or FilterList
     std::string nListLang;
     bool bSkipFile;
 	std::string sProject;
 	std::string sRoot;
-	BOOL bEnableExport;
-	BOOL bMergeMode;
+	bool bEnableExport;
+	bool bMergeMode;
 	std::string sMergeSrc;
 	std::string sLastListLine;
-	BOOL bError;						// any errors while export?
-	BOOL bReadOver;
-	BOOL bDontWriteOutput;
+	bool bError;						// any errors while export?
+	bool bReadOver;
+	bool bDontWriteOutput;
 	std::string sLastTextTyp;
     static bool isInitialized;
 	std::string sFilename;
     static void UnquotHTML( std::string &rString );
 	
     static const char* GetEnv( const char *pVar );
-	static int getCurrentDirectory( rtl::OUString& base_fqurl , rtl::OUString& base );
+	static int getCurrentDirectory( const std::string& base_fqurl , const std::string& base );
 
     static bool isSourceLanguage( const std::string &sLanguage );
 	static bool isAllowed( const std::string &sLanguage );	
     static bool LanguageAllowed( const std::string &nLanguage );
     static void Languages( std::vector<std::string>::const_iterator& begin , std::vector<std::string>::const_iterator& end );
 	static void getRandomName( const std::string& sPrefix , std::string& sRandStr , const std::string& sPostfix  );
-    static void getRandomName( std::string& sRandStr );
-    static void getCurrentDir( std::string& dir );
+    static void getRandomName( const std::string& sRandStr );
+    static void getCurrentDir( const std::string& dir );
 
-    static void replaceEncoding( std::string& rString );
+    static void replaceEncoding( const std::string& rString );
     
 	static std::string GetFallbackLanguage( const std::string nLanguage );
 	static void FillInFallbacks( ResData *pResData );
     static void FillInListFallbacks( ExportList *pList, const std::string &nSource, const std::string &nFallback );
     static std::string GetTimeStamp();
-	static BOOL ConvertLineEnds( std::string sSource, std::string sDestination );
+	static bool ConvertLineEnds( std::string sSource, std::string sDestination );
 	static std::string GetNativeFile( std::string sSource );
 	static DirEntry GetTempFile();
 	
     static std::vector<std::string> aLanguages;
     static std::vector<std::string> aForcedLanguages;
 
-	BOOL ListExists( ResData *pResData, USHORT nLst );
+	bool ListExists( ResData *pResData, USHORT nLst );
 
-	BOOL WriteData( ResData *pResData, BOOL bCreateNew = FALSE );// called befor dest. cur ResData
-	BOOL WriteExportList( ResData *pResData, ExportList *pExportList,
-						const std::string &rTyp, BOOL bCreateNew = FALSE );
+	bool WriteData( ResData *pResData, bool bCreateNew = FALSE );// called befor dest. cur ResData
+	bool WriteExportList( ResData *pResData, ExportList *pExportList,
+						const std::string &rTyp, bool bCreateNew = FALSE );
 	
 	std::string MergePairedList( std::string& sLine , std::string& sText );
 
 	void CleanValue( std::string &rValue );
 	std::string GetText( const std::string &rSource, int nToken );
 
-	BOOL PrepareTextToMerge( std::string &rText, USHORT nTyp,
+	bool PrepareTextToMerge( std::string &rText, USHORT nTyp,
 		std::string &nLangIndex, ResData *pResData );		
 
 	void MergeRest( ResData *pResData, USHORT nMode = MERGE_MODE_NORMAL );
 	void CutComment( std::string &rText );
 
 public:
-	Export( const std::string &rOutput, BOOL bWrite,
+	Export( const std::string &rOutput, bool bWrite,
 			const std::string &rPrj, const std::string &rPrjRoot , const std::string& rFile );
-	Export( const std::string &rOutput, BOOL bWrite,
+	Export( const std::string &rOutput, bool bWrite,
 			const std::string &rPrj, const std::string &rPrjRoot,
 			const std::string &rMergeSource , const std::string& rFile );
 	~Export();
 	void Init();
 	int Execute( int nToken, const char * pToken );	// called from lexer
 	void SetError() { bError = TRUE; }
-	BOOL GetError() { return bError; }
+	bool GetError() { return bError; }
 };
 
 
 			sTitle[ nId ] = rTitle;
 			bTitleFirst[ nId ] = true;
 		}
-     BOOL GetText( std::string &rReturn, USHORT nTyp, const std::string &nLangIndex, BOOL bDel = FALSE );
-     BOOL GetTransex3Text( std::string &rReturn, USHORT nTyp, const std::string &nLangIndex, BOOL bDel = FALSE );
+     bool GetText( std::string &rReturn, USHORT nTyp, const std::string &nLangIndex, bool bDel = FALSE );
+     bool GetTransex3Text( std::string &rReturn, USHORT nTyp, const std::string &nLangIndex, bool bDel = FALSE );
 
 };
 
     PFormEntrys* GetPFObject( const std::string& rPFO );
 
 	std::string Dump();
-	BOOL operator==( ResData *pData );
+	bool operator==( ResData *pData );
 };
 
 //
 class MergeDataFile
 {
 private:
-	BOOL bErrorLog;
+	bool bErrorLog;
 	std::string sErrorLog;
-	SvFileStream aErrLog;
+	
+	//SvFileStream aErrLog;
+	std::ofstream aErrLog;
+
     stringSet aLanguageSet;
     MergeDataHashMap aMap;  
     stringHashMap aLanguageMap;
     
 
 public:
-    MergeDataFile( const std::string &rFileName, const std::string& rFile , BOOL bErrLog, CharSet aCharSet, bool bCaseSensitive = false );
+    MergeDataFile( const std::string &rFileName, const std::string& rFile , bool bErrLog, CharSet aCharSet, bool bCaseSensitive = false );
 	~MergeDataFile();
     
     

File l10ntools/inc/l10ntools/directory.hxx

View file
  • Ignore whitespace
+#ifndef __directory_hxx
+#define __directory_hxx
+
 #include <string>
 #include <vector>
 #include <algorithm>
         std::string getFullName()       { return sFullName; }
         void setSkipLinks( bool is_skipped );
 
+		void appendToPath( const std::string& sPath );
+
         void dump();
         Directory() {};
 
 };
 
 }
+#endif

File l10ntools/source/directory.cxx

View file
  • Ignore whitespace
     bSkipLinks = is_skipped;
 }
 
+void Directory::appendToPath( const string& sPath )
+{
+	sFullName += sPath;
+}
+
 void Directory::readDirectory()
 {
     readDirectory( sFullName );

File l10ntools/source/export.cxx

View file
  • Ignore whitespace
 #include <stdio.h>
 #include <stdlib.h>
 #include <tools/fsys.hxx>
+#include "l10ntools/directory.hxx"
 #include "export.hxx"
 #include "tokens.h"
 #include "utf8conv.hxx"
 			bUnmerge = TRUE;
 			bMergeMode = TRUE;
 		}
-		else if ( ToUpperAscii(sSwitch) == "-UTF8" ) {
+		else if ( toUpperAscii(sSwitch) == "-UTF8" ) {
 			nState = STATE_UTF8;
 			bUTF8 = TRUE;
 		}
-		else if ( ToUpperAscii(sSwitch) == "-NOUTF8" ) {
+		else if ( toUpperAscii(sSwitch) == "-NOUTF8" ) {
 			nState = STATE_UTF8;
 			bUTF8 = FALSE;
 		}
 
 			// this is a valid file which can be opened, so
 			// create path to project root
-			DirEntry aEntry( String( sOrigFile, RTL_TEXTENCODING_ASCII_US ));
-			aEntry.ToAbs();
-			string sFullEntry( aEntry.GetFull(), RTL_TEXTENCODING_ASCII_US );
-			aEntry += DirEntry( String( "..", RTL_TEXTENCODING_ASCII_US ));
-			aEntry += DirEntry( sPrjRoot );
-			string sPrjEntry( aEntry.GetFull(), RTL_TEXTENCODING_ASCII_US );
+			//transex::Directory aEntry( sOrigFile );
+			//DirEntry aEntry( String( sOrigFile, RTL_TEXTENCODING_ASCII_US ));
+			//aEntry.ToAbs();
+			/*
+			string sFullEntry = aEntry.getFullName(); //( aEntry.GetFull(), RTL_TEXTENCODING_ASCII_US );
+			aEntry.appendToPath( ".." + sPrjRoot );
+			
+			//aEntry += DirEntry( String( "..", RTL_TEXTENCODING_ASCII_US ));
+			//aEntry += DirEntry( sPrjRoot );
+			string sPrjEntry = aEntry.getFullName(); //( aEntry.GetFull(), RTL_TEXTENCODING_ASCII_US );
 
 			// create file name, beginnig with project root
 			// (e.g.: source\ui\src\menue.src)
 				pExport->Init();
 			}
 			// return the valid file handle
+			*/
             return pFile;
 		}
 	}
 // class ResData
 //
 
-void ResData::Dump(){
+void ResData::Dump() {
 	printf("**************\nResData\n");
-	printf("sPForm = %s , sResTyp = %s , sId = %s , sGId = %s , sHelpId = %s\n",sPForm.GetBuffer()
-		,sResTyp.GetBuffer(),sId.GetBuffer(),sGId.GetBuffer(),sHelpId.GetBuffer());
+	printf("sPForm = %s , sResTyp = %s , sId = %s , sGId = %s , sHelpId = %s\n",sPForm.c_str()
+		,sResTyp.c_str(),sId.c_str(),sGId.c_str(),sHelpId.c_str());
 
 	string a("*pStringList");
 	string b("*pUIEntries");
 	printf("\n");
 }
 
-void ResData::addFallbackData( string& sId_in , const string& sText_in ){
+void ResData::addFallbackData( string& sId_in , const string& sText_in ) {
 	//printf(" ResData::addFallbackData ( sId = %s , sText = %s )\n", sId_in.GetBuffer() , sText_in.GetBuffer() );
     aFallbackData[ sId_in ] = sText_in;
 }
-bool ResData::getFallbackData( string& sId_in , string& sText_inout ){
+
+bool ResData::getFallbackData( string& sId_in , string& sText_inout ) {
 	sText_inout = aFallbackData[ sId_in ];
 	//printf("ResData::getFallbackData( sId = %s , return sText = %s \n" , sId_in.GetBuffer(), sText_inout.GetBuffer());
-    return sText_inout.Len() > 0;
+    return sText_inout.length() > 0;
 }
 
-void ResData::addMergedLanguage( string& sLang ){
-	aMergedLanguages[ sLang ]=string("1");
+void ResData::addMergedLanguage( string& sLang ) {
+	aMergedLanguages[ sLang ] = string("1");
 }
-bool ResData::isMerged( string& sLang ){
-	return aMergedLanguages[ sLang ].Equals("1");
+
+bool ResData::isMerged( string& sLang ) {
+	return aMergedLanguages[ sLang ] == "1"; //Equals("1");
 }
 
 /*****************************************************************************/
-BOOL ResData::SetId( const string &rId, USHORT nLevel )
+bool ResData::SetId( const string &rId, USHORT nLevel )
 /*****************************************************************************/
 {
 	if ( nLevel > nIdLevel )
 
 		if ( bChild && bChildWithText ) {
 			string sError( "ResId after child definition" );
-			yyerror( sError.GetBufferAccess());
-			sError.ReleaseBufferAccess();
+			yyerror( sError.c_str());
+			//sError.ReleaseBufferAccess();
 			SetError();
 		}
 
 				const string &rPrj, const string &rPrjRoot , const string& rFile )
 /*****************************************************************************/
 				:
-				pWordTransformer( NULL ),
+				//pWordTransformer( NULL ),
 				aCharSet( RTL_TEXTENCODING_MS_1252 ),
 				bDefine( FALSE ),
 				bNextMustBeDefineEOL( FALSE ),
 				const string &rMergeSource , const string& rFile )
 /*****************************************************************************/
 				:
-				pWordTransformer( NULL ),
+				//pWordTransformer( NULL ),
 				aCharSet( RTL_TEXTENCODING_MS_1252 ),
 				bDefine( FALSE ),
 				bNextMustBeDefineEOL( FALSE ),
     if ( sFull.Len() > 255 ) {
 		string sError( "GroupId > 255 chars" );
 	    printf("GroupID = %s\n",sFull.GetBuffer());
-        yyerror( sError.GetBufferAccess());
-		sError.ReleaseBufferAccess();
+        yyerror( sError.c_str());
+		//sError.ReleaseBufferAccess();
 	}
 
 	return sFull;