summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--l10ntools/inc/cfgmerge.hxx14
-rw-r--r--l10ntools/inc/export.hxx9
-rw-r--r--l10ntools/inc/gsicheck.hxx8
-rw-r--r--l10ntools/inc/lngmerge.hxx12
-rw-r--r--l10ntools/inc/xmlparse.hxx7
-rw-r--r--l10ntools/inc/xrmmerge.hxx6
-rw-r--r--l10ntools/source/cfgmerge.cxx45
-rw-r--r--l10ntools/source/export.cxx49
-rw-r--r--l10ntools/source/export2.cxx97
-rw-r--r--l10ntools/source/gsicheck.cxx112
-rw-r--r--l10ntools/source/helpmerge.cxx89
-rw-r--r--l10ntools/source/lngmerge.cxx43
-rw-r--r--l10ntools/source/localize.cxx31
-rw-r--r--l10ntools/source/merge.cxx22
-rw-r--r--l10ntools/source/xmlparse.cxx48
-rw-r--r--l10ntools/source/xrmlex.l2
-rw-r--r--l10ntools/source/xrmmerge.cxx54
17 files changed, 224 insertions, 424 deletions
diff --git a/l10ntools/inc/cfgmerge.hxx b/l10ntools/inc/cfgmerge.hxx
index bd0627e876f0..6c82cc3a1ccb 100644
--- a/l10ntools/inc/cfgmerge.hxx
+++ b/l10ntools/inc/cfgmerge.hxx
@@ -29,9 +29,13 @@
#ifndef _CFG_MERGE_HXX
#define _CFG_MERGE_HXX
-#include <boost/unordered_map.hpp>
+#include "sal/config.h"
+
+#include <fstream>
#include <vector>
+#include "boost/unordered_map.hpp"
+
typedef boost::unordered_map<rtl::OString, rtl::OString, rtl::OStringHash> OStringHashMap;
@@ -68,7 +72,7 @@ public:
// class CfgStack
//
-typedef ::std::vector< CfgStackData* > CfgStackList;
+typedef std::vector< CfgStackData* > CfgStackList;
class CfgStack
{
@@ -89,9 +93,9 @@ public:
return temp;
}
- CfgStackData *GetStackData( size_t nPos = LIST_APPEND );
+ CfgStackData *GetStackData();
- rtl::OString GetAccessPath( size_t nPos = LIST_APPEND );
+ rtl::OString GetAccessPath( size_t nPos );
size_t size() const { return maList.size(); }
};
@@ -148,7 +152,7 @@ public:
class CfgOutputParser : public CfgParser
{
protected:
- SvFileStream *pOutputStream;
+ std::ofstream pOutputStream;
public:
CfgOutputParser(const rtl::OString &rOutputFile);
virtual ~CfgOutputParser();
diff --git a/l10ntools/inc/export.hxx b/l10ntools/inc/export.hxx
index ba086b56de42..52efd998376e 100644
--- a/l10ntools/inc/export.hxx
+++ b/l10ntools/inc/export.hxx
@@ -31,6 +31,8 @@
#include "sal/config.h"
+#include <fstream>
+
#include <comphelper/string.hxx>
#ifndef L10NTOOLS_DIRECTORY_HXX
@@ -38,7 +40,6 @@
#include <l10ntools/directory.hxx>
#endif
-#include <tools/stream.hxx>
#include <tools/fsys.hxx>
#include <osl/file.hxx>
#include <osl/file.h>
@@ -263,7 +264,7 @@ class Export
private:
WordTransformer *pWordTransformer;
- SvFileStream aOutput;
+ std::ofstream aOutput;
ResStack aResStack; // stack for parsing recursive
@@ -304,8 +305,6 @@ public:
static void SetLanguages( std::vector<rtl::OString> val );
static void RemoveUTF8ByteOrderMarker( rtl::OString &rString );
static bool hasUTF8ByteOrderMarker( const rtl::OString &rString );
- static void RemoveUTF8ByteOrderMarkerFromFile(const rtl::OString &rFilename);
- static bool fileHasUTF8ByteOrderMarker(const rtl::OString &rString);
static rtl::OString QuoteHTML( rtl::OString const &rString );
static bool CopyFile(const rtl::OString& rSource , const rtl::OString& rDest);
@@ -321,7 +320,6 @@ public:
static void getCurrentDir( std::string& dir );
static rtl::OString GetTimeStamp();
- static sal_Bool ConvertLineEnds( rtl::OString const & sSource, rtl::OString const & sDestination );
static rtl::OString GetNativeFile( rtl::OString const & sSource );
static DirEntry GetTempFile();
@@ -461,7 +459,6 @@ class MergeDataFile
private:
sal_Bool bErrorLog;
rtl::OString sErrorLog;
- SvFileStream aErrLog;
MergeDataHashMap aMap;
std::set<rtl::OString> aLanguageSet;
diff --git a/l10ntools/inc/gsicheck.hxx b/l10ntools/inc/gsicheck.hxx
index eaab60042d8d..46b3709032f8 100644
--- a/l10ntools/inc/gsicheck.hxx
+++ b/l10ntools/inc/gsicheck.hxx
@@ -92,7 +92,7 @@ public:
typedef ::std::vector< GSILine* > GSIBlock_Impl;
-class LazySvFileStream;
+class LazyStream;
class GSIBlock
{
@@ -122,9 +122,9 @@ public:
void SetReferenceLine( GSILine* pLine );
sal_Bool CheckSyntax( sal_uLong nLine, sal_Bool bRequireSourceLine, sal_Bool bFixTags );
- void WriteError( LazySvFileStream &aErrOut, sal_Bool bRequireSourceLine );
- void WriteCorrect( LazySvFileStream &aOkOut, sal_Bool bRequireSourceLine );
- void WriteFixed( LazySvFileStream &aFixOut );
+ void WriteError( LazyStream &aErrOut, sal_Bool bRequireSourceLine );
+ void WriteCorrect( LazyStream &aOkOut, sal_Bool bRequireSourceLine );
+ void WriteFixed( LazyStream &aFixOut );
};
#endif
diff --git a/l10ntools/inc/lngmerge.hxx b/l10ntools/inc/lngmerge.hxx
index d6a0ebd4e2cf..99c852d9bac5 100644
--- a/l10ntools/inc/lngmerge.hxx
+++ b/l10ntools/inc/lngmerge.hxx
@@ -25,11 +25,15 @@
* for a copy of the LGPLv3 License.
*
************************************************************************/
-// local includes
-#include "export.hxx"
+
+#include "sal/config.h"
+
+#include <iosfwd>
#include <vector>
-typedef ::std::vector< rtl::OString* > LngLineList;
+#include "export.hxx"
+
+typedef std::vector< rtl::OString* > LngLineList;
#define LNG_OK 0x0000
#define LNG_FILE_NOTFOUND 0x0001
@@ -56,7 +60,7 @@ private:
bool isNextGroup(rtl::OString &sGroup_out, rtl::OString &sLine_in);
void ReadLine(const rtl::OString &rLine_in,
OStringHashMap &rText_inout);
- void WriteSDF(SvFileStream &aSDFStream, OStringHashMap &rText_inout,
+ void WriteSDF(std::ofstream &aSDFStream, OStringHashMap &rText_inout,
const rtl::OString &rPrj, const rtl::OString &rRoot,
const rtl::OString &rActFileName, const rtl::OString &rID);
public:
diff --git a/l10ntools/inc/xmlparse.hxx b/l10ntools/inc/xmlparse.hxx
index e24f8e6df790..94b5e918f863 100644
--- a/l10ntools/inc/xmlparse.hxx
+++ b/l10ntools/inc/xmlparse.hxx
@@ -33,7 +33,6 @@
#include <expat.h>
#include <rtl/ustring.hxx>
#include <rtl/ustrbuf.hxx>
-#include <tools/stream.hxx>
#include "export.hxx"
#include "xmlutil.hxx"
@@ -483,7 +482,6 @@ private:
void Comment( const XML_Char *data );
void Default( const XML_Char *s, int len );
-
public:
/// creates a new parser
SimpleXMLParser();
@@ -496,11 +494,6 @@ public:
XMLFile *pXMLFileIn // the XMLFile
);
- /// parse a memory stream, returns NULL on criticall errors
- XMLFile *Execute(
- SvMemoryStream *pStream // the stream
- );
-
/// returns an error struct
const XMLError &GetError() { return aErrorInformation; }
};
diff --git a/l10ntools/inc/xrmmerge.hxx b/l10ntools/inc/xrmmerge.hxx
index bcf82e405cb1..d4232c544cf9 100644
--- a/l10ntools/inc/xrmmerge.hxx
+++ b/l10ntools/inc/xrmmerge.hxx
@@ -26,6 +26,10 @@
*
************************************************************************/
+#include "sal/config.h"
+
+#include <fstream>
+
//
// XRMResParser
//
@@ -89,7 +93,7 @@ class XRMResOutputParser : public XRMResParser
private:
std::vector<rtl::OString> aLanguages;
protected:
- SvFileStream *pOutputStream;
+ std::ofstream pOutputStream;
public:
XRMResOutputParser ( const rtl::OString &rOutputFile );
virtual ~XRMResOutputParser();
diff --git a/l10ntools/source/cfgmerge.cxx b/l10ntools/source/cfgmerge.cxx
index 773bc6191881..9503a3fc30d4 100644
--- a/l10ntools/source/cfgmerge.cxx
+++ b/l10ntools/source/cfgmerge.cxx
@@ -261,33 +261,25 @@ CfgStack::~CfgStack()
rtl::OString CfgStack::GetAccessPath( size_t nPos )
{
- if ( nPos == LIST_APPEND )
- nPos = maList.size() - 1;
-
rtl::OStringBuffer sReturn;
for (size_t i = 0; i <= nPos; ++i)
{
if (i)
sReturn.append('.');
- sReturn.append(GetStackData( i )->GetIdentifier());
+ sReturn.append(maList[i]->GetIdentifier());
}
return sReturn.makeStringAndClear();
}
/*****************************************************************************/
-CfgStackData *CfgStack::GetStackData( size_t nPos )
+CfgStackData *CfgStack::GetStackData()
/*****************************************************************************/
{
- if ( nPos == LIST_APPEND )
- {
- if (!maList.empty())
- nPos = maList.size() - 1;
- else
- return 0;
- }
-
- return maList[ nPos ];
+ if (!maList.empty())
+ return maList[maList.size() - 1];
+ else
+ return 0;
}
//
@@ -519,20 +511,13 @@ void CfgParser::Error(const rtl::OString& rError)
CfgOutputParser::CfgOutputParser(const rtl::OString &rOutputFile)
{
- pOutputStream =
- new SvFileStream(
- rtl::OStringToOUString(rOutputFile, RTL_TEXTENCODING_ASCII_US),
- STREAM_STD_WRITE | STREAM_TRUNC
- );
- pOutputStream->SetStreamCharSet( RTL_TEXTENCODING_UTF8 );
-
- if ( !pOutputStream->IsOpen())
+ pOutputStream.open(
+ rOutputFile.getStr(), std::ios_base::out | std::ios_base::trunc);
+ if (!pOutputStream.is_open())
{
rtl::OStringBuffer sError(RTL_CONSTASCII_STRINGPARAM("ERROR: Unable to open output file: "));
sError.append(rOutputFile);
Error(sError.makeStringAndClear());
- delete pOutputStream;
- pOutputStream = NULL;
std::exit(EXIT_FAILURE);
}
}
@@ -541,10 +526,7 @@ CfgOutputParser::CfgOutputParser(const rtl::OString &rOutputFile)
CfgOutputParser::~CfgOutputParser()
/*****************************************************************************/
{
- if ( pOutputStream ) {
- pOutputStream->Close();
- delete pOutputStream;
- }
+ pOutputStream.close();
}
//
@@ -576,7 +558,7 @@ CfgExport::~CfgExport()
void CfgExport::WorkOnRessourceEnd()
/*****************************************************************************/
{
- if ( pOutputStream && bLocalize ) {
+ if ( bLocalize ) {
if ( pStackData->sText[rtl::OString(RTL_CONSTASCII_STRINGPARAM("en-US"))].getLength() )
{
rtl::OString sFallback = pStackData->sText[rtl::OString(RTL_CONSTASCII_STRINGPARAM("en-US"))];
@@ -614,7 +596,7 @@ void CfgExport::WorkOnRessourceEnd()
sOutput += sText; sOutput += "\t\t\t\t";
sOutput += sTimeStamp;
- pOutputStream->WriteLine( sOutput );
+ pOutputStream << sOutput.getStr() << '\n';
}
}
}
@@ -706,8 +688,7 @@ void CfgMerge::WorkOnText(rtl::OString &rText, const rtl::OString& rLangIndex)
void CfgMerge::Output(const rtl::OString& rOutput)
{
- if (pOutputStream)
- pOutputStream->Write(rOutput.getStr(), rOutput.getLength());
+ pOutputStream << rOutput.getStr();
}
/*****************************************************************************/
diff --git a/l10ntools/source/export.cxx b/l10ntools/source/export.cxx
index b41ff8a9ee80..238184aefcfa 100644
--- a/l10ntools/source/export.cxx
+++ b/l10ntools/source/export.cxx
@@ -26,6 +26,10 @@
*
************************************************************************/
+#include "sal/config.h"
+
+#include <cstring>
+
#include <stdio.h>
#include <stdlib.h>
#include <tools/fsys.hxx>
@@ -71,10 +75,8 @@ rtl::OString sPrjRoot;
rtl::OString sActFileName;
rtl::OString sOutputFile;
rtl::OString sMergeSrc;
-rtl::OString sTempFile;
rtl::OString sFile;
MergeDataFile *pMergeDataFile;
-FILE *pTempFile;
extern "C" {
// the whole interface to lexer is in this extern "C" section
@@ -95,8 +97,6 @@ extern char *GetOutputFile( int argc, char* argv[])
sActFileName = "";
Export::sLanguages = "";
Export::sForcedLanguages = "";
- sTempFile = "";
- pTempFile = NULL;
sal_uInt16 nState = STATE_NON;
sal_Bool bInput = sal_False;
@@ -176,7 +176,7 @@ extern char *GetOutputFile( int argc, char* argv[])
// command line is valid
bEnableExport = sal_True;
char *pReturn = new char[ sOutputFile.getLength() + 1 ];
- strcpy( pReturn, sOutputFile.getStr()); // #100211# - checked
+ std::strcpy( pReturn, sOutputFile.getStr()); // #100211# - checked
return pReturn;
}
@@ -223,15 +223,6 @@ extern FILE *GetNextFile()
/*****************************************************************************/
{
// look for next valid filename in input file list
- if ( !sTempFile.isEmpty())
- {
- fclose( pTempFile );
- rtl::OUString sTemp(rtl::OStringToOUString(sTempFile,
- RTL_TEXTENCODING_ASCII_US));
- DirEntry aTemp( sTemp );
- aTemp.Kill();
- }
-
while ( !aInputFileList.empty() )
{
rtl::OString sFileName(aInputFileList[0]);
@@ -247,8 +238,7 @@ extern FILE *GetNextFile()
return GetNextFile();
}
- sTempFile = sFileName;
- Export::RemoveUTF8ByteOrderMarkerFromFile( sFileName );
+ //TODO: explict BOM handling?
// able to open file?
FILE *pFile = fopen( sFileName.getStr(), "r" );
@@ -256,8 +246,6 @@ extern FILE *GetNextFile()
fprintf( stderr, "Error: Could not open File %s\n",
sFileName.getStr());
else {
- pTempFile = pFile;
-
// this is a valid file which can be opened, so
// create path to project root
DirEntry aEntry(rtl::OStringToOUString(sOrigFile,
@@ -422,14 +410,12 @@ Export::Export(const rtl::OString &rOutput, sal_Bool bWrite,
// open output stream
if ( bEnableExport ) {
- aOutput.Open( rtl::OStringToOUString( rOutput, RTL_TEXTENCODING_ASCII_US ), STREAM_STD_WRITE | STREAM_TRUNC );
- if( !aOutput.IsOpen() ) {
+ aOutput.open(
+ rOutput.getStr(), std::ios_base::out | std::ios_base::trunc);
+ if (!aOutput.is_open()) {
fprintf(stderr, "ERROR : Can't open file %s\n", rOutput.getStr());
exit ( -1 );
}
- aOutput.SetStreamCharSet( RTL_TEXTENCODING_UTF8 );
-
- aOutput.SetLineDelimiter( LINEEND_CRLF );
}
}
@@ -464,9 +450,8 @@ Export::Export(const rtl::OString &rOutput, sal_Bool bWrite,
// open output stream
if ( bEnableExport ) {
- aOutput.Open( rtl::OStringToOUString( rOutput, RTL_TEXTENCODING_ASCII_US ), STREAM_STD_WRITE | STREAM_TRUNC );
- aOutput.SetStreamCharSet( RTL_TEXTENCODING_UTF8 );
- aOutput.SetLineDelimiter( LINEEND_CRLF );
+ aOutput.open(
+ rOutput.getStr(), std::ios_base::out | std::ios_base::trunc);
}
}
@@ -496,7 +481,7 @@ Export::~Export()
delete pParseQueue;
// close output stream
if ( bEnableExport )
- aOutput.Close();
+ aOutput.close();
for ( size_t i = 0, n = aResStack.size(); i < n; ++i )
delete aResStack[ i ];
aResStack.clear();
@@ -1233,7 +1218,7 @@ sal_Bool Export::WriteData( ResData *pResData, sal_Bool bCreateNew )
sOutput += sXTitle; sOutput += "\t";
sOutput += sTimeStamp;
- aOutput.WriteLine( sOutput );
+ aOutput << sOutput.getStr() << '\n';
}
if ( bCreateNew ) {
@@ -1362,7 +1347,7 @@ sal_Bool Export::WriteExportList(ResData *pResData, ExportList *pExportList,
sOutput.append(sText).append("\t\t\t\t");
sOutput.append(sTimeStamp);
- aOutput.WriteLine(sOutput.makeStringAndClear());
+ aOutput << sOutput.makeStringAndClear().getStr() << '\n';
}
}
@@ -1522,7 +1507,7 @@ rtl::OString Export::GetText(const rtl::OString &rSource, int nToken)
helper::searchAndReplaceAll(&sTmp, "\\0x7F", "-=<[0x7F]>=-");
sal_uInt16 nState = TXT_STATE_TEXT;
- for (sal_Int32 i = 0; i < getTokenCount(sTmp, '\"'); ++i)
+ for (sal_Int32 i = 1; i < getTokenCount(sTmp, '"'); ++i)
{
rtl::OString sToken(getToken(sTmp, i, '"'));
if (!sToken.isEmpty()) {
@@ -1598,10 +1583,10 @@ void Export::WriteToMerged(const rtl::OString &rText , bool bSDFContent)
}
} for (sal_Int32 i = 0; i < sText.getLength(); ++i) {
if (sText[i] == '\n') {
- aOutput.WriteLine(rtl::OString());
+ aOutput << '\n';
} else {
char cChar = sText[i];
- aOutput.Write(&cChar, 1);
+ aOutput << cChar;
}
}
}
diff --git a/l10ntools/source/export2.cxx b/l10ntools/source/export2.cxx
index eb4fee826090..cd61d92385bf 100644
--- a/l10ntools/source/export2.cxx
+++ b/l10ntools/source/export2.cxx
@@ -26,6 +26,8 @@
*
************************************************************************/
+#include "sal/config.h"
+
#include "export.hxx"
#include <stdio.h>
#include <osl/time.h>
@@ -206,54 +208,6 @@ bool Export::hasUTF8ByteOrderMarker( const rtl::OString &rString )
rString[1] == '\xBB' && rString[2] == '\xBF' ;
}
-bool Export::fileHasUTF8ByteOrderMarker(const rtl::OString &rString)
-{
- SvFileStream aFileIn(rtl::OStringToOUString(rString, RTL_TEXTENCODING_ASCII_US), STREAM_READ);
- rtl::OString sLine;
- if( !aFileIn.IsEof() )
- {
- aFileIn.ReadLine( sLine );
- if( aFileIn.IsOpen() )
- aFileIn.Close();
- return hasUTF8ByteOrderMarker( sLine );
- }
- if( aFileIn.IsOpen() ) aFileIn.Close();
- return false;
-}
-
-void Export::RemoveUTF8ByteOrderMarkerFromFile(const rtl::OString &rFilename)
-{
- SvFileStream aFileIn(rtl::OStringToOUString(rFilename , RTL_TEXTENCODING_ASCII_US) , STREAM_READ );
- rtl::OString sLine;
- if( !aFileIn.IsEof() )
- {
- aFileIn.ReadLine( sLine );
- // Test header
- if( hasUTF8ByteOrderMarker( sLine ) )
- {
- DirEntry aTempFile = Export::GetTempFile();
- rtl::OString sTempFile = rtl::OUStringToOString(aTempFile.GetFull() , RTL_TEXTENCODING_ASCII_US);
- SvFileStream aNewFile(rtl::OStringToOUString(sTempFile , RTL_TEXTENCODING_ASCII_US) , STREAM_WRITE);
- // Remove header
- RemoveUTF8ByteOrderMarker( sLine );
- aNewFile.WriteLine( sLine );
- // Copy the rest
- while( !aFileIn.IsEof() )
- {
- aFileIn.ReadLine( sLine );
- aNewFile.WriteLine( sLine );
- }
- if( aFileIn.IsOpen() ) aFileIn.Close();
- if( aNewFile.IsOpen() ) aNewFile.Close();
- DirEntry aEntry( rFilename.getStr() );
- aEntry.Kill();
- DirEntry( sTempFile ).MoveTo( DirEntry( rFilename.getStr() ) );
- }
- }
- if( aFileIn.IsOpen() )
- aFileIn.Close();
-}
-
bool Export::CopyFile(const rtl::OString& rSource, const rtl::OString& rDest)
{
const int BUFFERSIZE = 8192;
@@ -395,54 +349,11 @@ rtl::OString Export::GetTimeStamp()
}
/*****************************************************************************/
-sal_Bool Export::ConvertLineEnds(
- rtl::OString const & sSource, rtl::OString const & sDestination )
-/*****************************************************************************/
-{
- rtl::OUString sSourceFile(rtl::OStringToOUString(sSource, RTL_TEXTENCODING_ASCII_US));
- rtl::OUString sDestinationFile(rtl::OStringToOUString(sDestination, RTL_TEXTENCODING_ASCII_US));
-
- SvFileStream aSource( sSourceFile, STREAM_READ );
- if ( !aSource.IsOpen())
- return sal_False;
- SvFileStream aDestination( sDestinationFile, STREAM_STD_WRITE | STREAM_TRUNC );
- if ( !aDestination.IsOpen()) {
- aSource.Close();
- return sal_False;
- }
-
- rtl::OString sLine;
-
- while ( !aSource.IsEof())
- {
- aSource.ReadLine( sLine );
- if ( !aSource.IsEof()) //a complete line
- {
- sLine = comphelper::string::remove(sLine, '\r');
- aDestination.WriteLine( sLine );
- }
- else //a final incomplete line, just copy it as-is
- aDestination.Write( sLine.getStr(), sLine.getLength() );
- }
-
- aSource.Close();
- aDestination.Close();
-
- return sal_True;
-}
-
-/*****************************************************************************/
rtl::OString Export::GetNativeFile( rtl::OString const & sSource )
/*****************************************************************************/
{
- DirEntry aTemp( GetTempFile());
- rtl::OString sReturn(rtl::OUStringToOString(aTemp.GetFull(), RTL_TEXTENCODING_ASCII_US));
-
- for ( sal_uInt16 i = 0; i < 10; i++ )
- if ( ConvertLineEnds( sSource, sReturn ))
- return sReturn;
-
- return rtl::OString();
+ //TODO: Drop this completely unless line end conversion *is* an issue
+ return sSource;
}
const char* Export::GetEnv( const char *pVar )
diff --git a/l10ntools/source/gsicheck.cxx b/l10ntools/source/gsicheck.cxx
index 2f860ace213d..aa6f0de125dd 100644
--- a/l10ntools/source/gsicheck.cxx
+++ b/l10ntools/source/gsicheck.cxx
@@ -26,9 +26,13 @@
*
************************************************************************/
+#include "sal/config.h"
+
+#include <fstream>
+#include <string>
+
#include <stdio.h>
#include <tools/fsys.hxx>
-#include <tools/stream.hxx>
#include <rtl/strbuf.hxx>
#include <comphelper/string.hxx>
@@ -90,47 +94,39 @@ sal_Bool LanguageOK( rtl::OString const & aLang )
return sal_False;
}
-//
-// class LazySvFileStream
-//
-
-
-class LazySvFileStream : public SvFileStream
+class LazyStream: public std::ofstream
{
private:
- rtl::OUString aFileName;
- sal_Bool bOpened;
- StreamMode eOpenMode;
+ rtl::OString aFileName;
+ bool bOpened;
public:
- LazySvFileStream()
+ LazyStream()
: aFileName()
- , bOpened( sal_False )
- , eOpenMode( 0 )
+ , bOpened(false)
{};
- void SetOpenParams( const rtl::OUString& rFileName, StreamMode eOpenModeP )
+ void SetFileName( const rtl::OString& rFileName )
{
aFileName = rFileName;
- eOpenMode = eOpenModeP;
};
void LazyOpen();
};
-void LazySvFileStream::LazyOpen()
+void LazyStream::LazyOpen()
{
if ( !bOpened )
{
- Open( aFileName, eOpenMode );
- if ( !IsOpen())
+ open(aFileName.getStr(), std::ios_base::out | std::ios_base::trunc);
+ if (!is_open())
{
fprintf( stderr, "\nERROR: Could not open Output-File %s!\n\n",
- rtl::OUStringToOString(aFileName, RTL_TEXTENCODING_ASCII_US).getStr() );
+ aFileName.getStr() );
exit ( 4 );
}
- bOpened = sal_True;
+ bOpened = true;
}
}
@@ -535,7 +531,7 @@ sal_Bool GSIBlock::CheckSyntax( sal_uLong nLine, sal_Bool bRequireSourceLine, sa
return bHasError || bHasBlockError;
}
-void GSIBlock::WriteError( LazySvFileStream &aErrOut, sal_Bool bRequireSourceLine )
+void GSIBlock::WriteError( LazyStream &aErrOut, sal_Bool bRequireSourceLine )
{
if ( pSourceLine && pSourceLine->IsOK() && bCheckSourceLang && !bHasBlockError )
return;
@@ -549,18 +545,18 @@ void GSIBlock::WriteError( LazySvFileStream &aErrOut, sal_Bool bRequireSourceLin
{
bHasError = sal_True;
aErrOut.LazyOpen();
- aErrOut.WriteLine( pItem->data_ );
+ aErrOut << pItem->data_.getStr() << '\n';
}
}
if ( pSourceLine && ( bHasError || !pSourceLine->IsOK() ) && !( !bHasError && bCheckTranslationLang ) )
{
aErrOut.LazyOpen();
- aErrOut.WriteLine( pSourceLine->data_ );
+ aErrOut << pSourceLine->data_.getStr() << '\n';
}
}
-void GSIBlock::WriteCorrect( LazySvFileStream &aOkOut, sal_Bool bRequireSourceLine )
+void GSIBlock::WriteCorrect( LazyStream &aOkOut, sal_Bool bRequireSourceLine )
{
if ( ( !pSourceLine && bRequireSourceLine ) || ( pSourceLine && !pSourceLine->IsOK() && !bCheckTranslationLang ) )
return;
@@ -573,18 +569,18 @@ void GSIBlock::WriteCorrect( LazySvFileStream &aOkOut, sal_Bool bRequireSourceLi
{
bHasOK = sal_True;
aOkOut.LazyOpen();
- aOkOut.WriteLine( pItem->data_ );
+ aOkOut << pItem->data_.getStr() << '\n';
}
}
if ( ( pSourceLine && pSourceLine->IsOK() && ( !maList.empty() || !bCheckTranslationLang ) ) || ( bHasOK && bCheckTranslationLang ) )
{
aOkOut.LazyOpen();
- aOkOut.WriteLine( pSourceLine->data_ );
+ aOkOut << pSourceLine->data_.getStr() << '\n';
}
}
-void GSIBlock::WriteFixed( LazySvFileStream &aFixOut )
+void GSIBlock::WriteFixed( LazyStream &aFixOut )
{
if ( pSourceLine && !pSourceLine->IsFixed() && bCheckSourceLang )
return;
@@ -597,14 +593,14 @@ void GSIBlock::WriteFixed( LazySvFileStream &aFixOut )
{
bHasFixes = sal_True;
aFixOut.LazyOpen();
- aFixOut.WriteLine( pItem->data_ );
+ aFixOut << pItem->data_.getStr() << '\n';
}
}
if ( pSourceLine && ( bHasFixes || pSourceLine->IsFixed() ) )
{
aFixOut.LazyOpen();
- aFixOut.WriteLine( pSourceLine->data_ );
+ aFixOut << pSourceLine->data_.getStr() << '\n';
}
}
@@ -846,13 +842,13 @@ int _cdecl main( int argc, char *argv[] )
exit ( 2 );
}
- SvFileStream aGSI( rtl::OStringToOUString( aFilename, RTL_TEXTENCODING_ASCII_US ), STREAM_STD_READ );
- if ( !aGSI.IsOpen()) {
+ std::ifstream aGSI(aFilename.getStr());
+ if (!aGSI.is_open()) {
fprintf( stderr, "\nERROR: Could not open GSI-File %s!\n\n", aFilename.getStr() );
exit ( 3 );
}
- SvFileStream aReferenceGSI;
+ std::ifstream aReferenceGSI;
if ( bReferenceFile )
{
DirEntry aReferenceSource = DirEntry( rtl::OStringToOUString( aReferenceFilename, RTL_TEXTENCODING_ASCII_US ));
@@ -861,14 +857,14 @@ int _cdecl main( int argc, char *argv[] )
exit ( 2 );
}
- aReferenceGSI.Open( rtl::OStringToOUString( aReferenceFilename, RTL_TEXTENCODING_ASCII_US ), STREAM_STD_READ );
- if ( !aReferenceGSI.IsOpen()) {
+ aReferenceGSI.open(aReferenceFilename.getStr());
+ if (!aReferenceGSI.is_open()) {
fprintf( stderr, "\nERROR: Could not open Input-File %s!\n\n", aFilename.getStr() );
exit ( 3 );
}
}
- LazySvFileStream aOkOut;
+ LazyStream aOkOut;
rtl::OUString aBaseName(aSource.GetBase());
if ( bWriteCorrect )
{
@@ -879,10 +875,12 @@ int _cdecl main( int argc, char *argv[] )
aSource.SetBase( sTmpBase );
aCorrectFilename = aSource.GetFull();
}
- aOkOut.SetOpenParams( aCorrectFilename , STREAM_STD_WRITE | STREAM_TRUNC );
+ aOkOut.SetFileName(
+ rtl::OUStringToOString(
+ aCorrectFilename, osl_getThreadTextEncoding()));
}
- LazySvFileStream aErrOut;
+ LazyStream aErrOut;
if ( bWriteError )
{
if (aErrorFilename.isEmpty())
@@ -892,10 +890,12 @@ int _cdecl main( int argc, char *argv[] )
aSource.SetBase( sTmpBase );
aErrorFilename = aSource.GetFull();
}
- aErrOut.SetOpenParams( aErrorFilename , STREAM_STD_WRITE | STREAM_TRUNC );
+ aErrOut.SetFileName(
+ rtl::OUStringToOString(
+ aErrorFilename, osl_getThreadTextEncoding()));
}
- LazySvFileStream aFixOut;
+ LazyStream aFixOut;
if ( bWriteFixed )
{
if (aFixedFilename.isEmpty())
@@ -905,25 +905,26 @@ int _cdecl main( int argc, char *argv[] )
aSource.SetBase( sTmpBase );
aFixedFilename = aSource.GetFull();
}
- aFixOut.SetOpenParams( aFixedFilename , STREAM_STD_WRITE | STREAM_TRUNC );
+ aFixOut.SetFileName(
+ rtl::OUStringToOString(
+ aFixedFilename, osl_getThreadTextEncoding()));
}
- rtl::OString sReferenceLine;
GSILine* pReferenceLine = NULL;
sal_uLong nReferenceLine = 0;
- rtl::OString sGSILine;
GSILine* pGSILine = NULL;
rtl::OString aOldId("No Valid ID"); // just set to something which can never be an ID
GSIBlock *pBlock = NULL;
sal_uLong nLine = 0;
- while ( !aGSI.IsEof() )
+ while (!aGSI.eof())
{
- aGSI.ReadLine( sGSILine );
+ std::string s;
+ std::getline(aGSI, s);
nLine++;
- pGSILine = new GSILine( sGSILine, nLine );
+ pGSILine = new GSILine(rtl::OString(s.data(), s.length()), nLine );
sal_Bool bDelete = sal_True;
@@ -937,7 +938,7 @@ int _cdecl main( int argc, char *argv[] )
{
bFileHasError = sal_True;
aErrOut.LazyOpen();
- aErrOut.WriteLine( pGSILine->data_ );
+ aErrOut << pGSILine->data_.getStr();
}
}
else if ( pGSILine->GetLineType().equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("res-comment")) )
@@ -945,7 +946,7 @@ int _cdecl main( int argc, char *argv[] )
if ( bWriteCorrect )
{
aOkOut.LazyOpen();
- aOkOut.WriteLine( pGSILine->data_ );
+ aOkOut << pGSILine->data_.getStr() << '\n';
}
}
else
@@ -975,13 +976,16 @@ int _cdecl main( int argc, char *argv[] )
if ( bReferenceFile )
{
sal_Bool bContinueSearching = sal_True;
- while ( ( !aReferenceGSI.IsEof() || pReferenceLine ) && bContinueSearching )
+ while ( ( !aReferenceGSI.eof() || pReferenceLine ) && bContinueSearching )
{
if ( !pReferenceLine )
{
- aReferenceGSI.ReadLine( sReferenceLine );
+ std::string s2;
+ std::getline(aReferenceGSI, s2);
nReferenceLine++;
- pReferenceLine = new GSILine( sReferenceLine, nReferenceLine );
+ pReferenceLine = new GSILine(
+ rtl::OString(s2.data(), s2.length()),
+ nReferenceLine);
}
if ( pReferenceLine->GetLineFormat() != FORMAT_UNKNOWN )
{
@@ -1034,14 +1038,14 @@ int _cdecl main( int argc, char *argv[] )
delete pBlock;
}
- aGSI.Close();
+ aGSI.close();
if ( bWriteError )
- aErrOut.Close();
+ aErrOut.close();
if ( bWriteCorrect )
- aOkOut.Close();
+ aOkOut.close();
if ( bWriteFixed )
- aFixOut.Close();
+ aFixOut.close();
if ( bFileHasError )
return 55;
diff --git a/l10ntools/source/helpmerge.cxx b/l10ntools/source/helpmerge.cxx
index 431c60b0f29c..a66ae391853c 100644
--- a/l10ntools/source/helpmerge.cxx
+++ b/l10ntools/source/helpmerge.cxx
@@ -28,6 +28,7 @@
#include "sal/config.h"
+#include <fstream>
#include <functional>
#include <tools/fsys.hxx>
@@ -88,25 +89,9 @@ bool HelpParser::CreateSDF(
const rtl::OString &rSDFFile_in, const rtl::OString &rPrj_in,const rtl::OString &rRoot_in,
const rtl::OString &sHelpFile, XMLFile *pXmlFile, const rtl::OString &rGsi1){
SimpleXMLParser aParser;
- rtl::OUString sUsedTempFile;
- rtl::OUString sXmlFile;
-
- if( Export::fileHasUTF8ByteOrderMarker( sHelpFile ) )
- {
- DirEntry aTempFile = Export::GetTempFile();
- DirEntry aSourceFile(
- rtl::OStringToOUString(sHelpFile, RTL_TEXTENCODING_ASCII_US));
- aSourceFile.CopyTo( aTempFile , FSYS_ACTION_COPYFILE );
- rtl::OUString sTempFile(aTempFile.GetFull());
- Export::RemoveUTF8ByteOrderMarkerFromFile(
- rtl::OUStringToOString(sTempFile, RTL_TEXTENCODING_ASCII_US));
- sUsedTempFile = sTempFile;
- sXmlFile = sTempFile;
- }
- else
- {
- sXmlFile = rtl::OStringToOUString(sHelpFile, RTL_TEXTENCODING_ASCII_US);
- }
+ rtl::OUString sXmlFile(
+ rtl::OStringToOUString(sHelpFile, RTL_TEXTENCODING_ASCII_US));
+ //TODO: explicit BOM handling?
rtl::OString fullFilePath = rPrj_in;
fullFilePath += "\\";
@@ -128,11 +113,10 @@ bool HelpParser::CreateSDF(
if( !file->CheckExportStatus() ){
return true;
}
- SvFileStream aSDFStream(
- rtl::OStringToOUString(rSDFFile_in, RTL_TEXTENCODING_ASCII_US),
- STREAM_STD_WRITE | STREAM_TRUNC);
+ std::ofstream aSDFStream(
+ rSDFFile_in.getStr(), std::ios_base::out | std::ios_base::trunc);
- if ( !aSDFStream.IsOpen()) {
+ if (!aSDFStream.is_open()) {
fprintf(stdout,"Can't open file %s\n",rSDFFile_in.getStr());
return false;
}
@@ -199,18 +183,14 @@ bool HelpParser::CreateSDF(
sBuffer.append( sOUTimeStamp );
rtl::OString sOut(rtl::OUStringToOString(sBuffer.makeStringAndClear().getStr() , RTL_TEXTENCODING_UTF8));
if( !data.isEmpty() )
- aSDFStream.WriteLine( sOut );
+ aSDFStream << sOut.getStr() << '\n';
pXMLElement=NULL;
}else fprintf(stdout,"\nDBG: NullPointer in HelpParser::CreateSDF , Language %s\n",sCur.getStr() );
}
}
- aSDFStream.Close();
+ aSDFStream.close();
- if( !sUsedTempFile.isEmpty() ){
- DirEntry aTempFile( sUsedTempFile );
- aTempFile.Kill();
- }
return sal_True;
}
@@ -238,22 +218,9 @@ bool HelpParser::Merge( const rtl::OString &rSDFFile, const rtl::OString &rDesti
SimpleXMLParser aParser;
- rtl::OUString sUsedTempFile;
- rtl::OUString sXmlFile;
-
- if( Export::fileHasUTF8ByteOrderMarker( sHelpFile ) ){
- DirEntry aTempFile = Export::GetTempFile();
- DirEntry aSourceFile(
- rtl::OStringToOUString(sHelpFile, RTL_TEXTENCODING_ASCII_US));
- aSourceFile.CopyTo( aTempFile , FSYS_ACTION_COPYFILE );
- rtl::OUString sTempFile(aTempFile.GetFull());
- Export::RemoveUTF8ByteOrderMarkerFromFile(
- rtl::OUStringToOString(sTempFile, RTL_TEXTENCODING_ASCII_US));
- sUsedTempFile = sTempFile;
- sXmlFile = sTempFile;
- }else{
- sXmlFile = rtl::OStringToOUString(sHelpFile, RTL_TEXTENCODING_ASCII_US);
- }
+ rtl::OUString sXmlFile(
+ rtl::OStringToOUString(sHelpFile, RTL_TEXTENCODING_ASCII_US));
+ //TODO: explicit BOM handling?
OUString sOUHelpFile( sXmlFile );
DirEntry aFile( sXmlFile );
@@ -261,10 +228,6 @@ bool HelpParser::Merge( const rtl::OString &rSDFFile, const rtl::OString &rDesti
XMLFile* xmlfile = ( aParser.Execute( aFile.GetFull() , sOUHelpFile, new XMLFile( rtl::OUString('0') ) ) );
hasNoError = MergeSingleFile( xmlfile , aMergeDataFile , rLanguage , rDestinationFile );
delete xmlfile;
- if( !sUsedTempFile.isEmpty() ){
- DirEntry aTempFile( sUsedTempFile );
- aTempFile.Kill();
- }
return hasNoError;
}
@@ -306,26 +269,9 @@ bool HelpParser::Merge(
(void) rSDFFile ;
bool hasNoError = true;
SimpleXMLParser aParser;
- rtl::OUString sUsedTempFile;
- rtl::OUString sXmlFile;
-
- if( Export::fileHasUTF8ByteOrderMarker( sHelpFile ) )
- {
- DirEntry aTempFile = Export::GetTempFile();
- DirEntry aSourceFile(
- rtl::OStringToOUString(sHelpFile, RTL_TEXTENCODING_ASCII_US));
- aSourceFile.CopyTo( aTempFile , FSYS_ACTION_COPYFILE );
- rtl::OUString sTempFile(aTempFile.GetFull());
- Export::RemoveUTF8ByteOrderMarkerFromFile(
- rtl::OUStringToOString(sTempFile , RTL_TEXTENCODING_ASCII_US));
- sUsedTempFile = sTempFile;
- sXmlFile = sTempFile;
- }
- else
- {
- sXmlFile = rtl::OStringToOUString(sHelpFile, RTL_TEXTENCODING_ASCII_US);
- }
-
+ rtl::OUString sXmlFile(
+ rtl::OStringToOUString(sHelpFile, RTL_TEXTENCODING_ASCII_US));
+ //TODO: explicit BOM handling?
OUString sOUHelpFile( sXmlFile );
DirEntry aFile( sXmlFile );
@@ -358,11 +304,6 @@ bool HelpParser::Merge(
if( !hasNoError ) return false; // Stop on error
}
- if( !sUsedTempFile.isEmpty() )
- {
- DirEntry aTempFile( sUsedTempFile );
- aTempFile.Kill();
- }
delete xmlfile;
return hasNoError;
}
diff --git a/l10ntools/source/lngmerge.cxx b/l10ntools/source/lngmerge.cxx
index fee478f48c3f..4619bf3aff7b 100644
--- a/l10ntools/source/lngmerge.cxx
+++ b/l10ntools/source/lngmerge.cxx
@@ -26,6 +26,11 @@
*
************************************************************************/
+#include "sal/config.h"
+
+#include <fstream>
+#include <string>
+
#include <tools/fsys.hxx>
#include <comphelper/string.hxx>
@@ -51,16 +56,15 @@ LngParser::LngParser(const rtl::OString &rLngFile, sal_Bool bUTF8,
DirEntry aEntry(rtl::OStringToOUString(sSource, RTL_TEXTENCODING_ASCII_US));
if ( aEntry.Exists())
{
- SvFileStream aStream(
- rtl::OStringToOUString(sSource, RTL_TEXTENCODING_ASCII_US),
- STREAM_STD_READ);
- if ( aStream.IsOpen())
+ std::ifstream aStream(sSource.getStr());
+ if (aStream.is_open())
{
- rtl::OString sLine;
bool bFirstLine = true;
- while ( !aStream.IsEof())
+ while (!aStream.eof())
{
- aStream.ReadLine( sLine );
+ std::string s;
+ std::getline(aStream, s);
+ rtl::OString sLine(s.data(), s.length());
if( bFirstLine )
{
@@ -93,13 +97,11 @@ sal_Bool LngParser::CreateSDF(const rtl::OString &rSDFFile,
Export::InitLanguages( false );
aLanguages = Export::GetLanguages();
- SvFileStream aSDFStream(
- rtl::OStringToOUString(rSDFFile, RTL_TEXTENCODING_ASCII_US),
- STREAM_STD_WRITE | STREAM_TRUNC);
- if ( !aSDFStream.IsOpen()) {
+ std::ofstream aSDFStream(
+ rSDFFile.getStr(), std::ios_base::out | std::ios_base::trunc);
+ if (!aSDFStream.is_open()) {
nError = SDF_COULD_NOT_OPEN;
}
- aSDFStream.SetStreamCharSet( RTL_TEXTENCODING_UTF8 );
nError = SDF_OK;
DirEntry aEntry(rtl::OStringToOUString(sSource, RTL_TEXTENCODING_ASCII_US));
aEntry.ToAbs();
@@ -134,11 +136,11 @@ sal_Bool LngParser::CreateSDF(const rtl::OString &rSDFFile,
WriteSDF( aSDFStream , Text , rPrj , rRoot , sActFileName , sID );
}
}
- aSDFStream.Close();
+ aSDFStream.close();
return true;
}
-void LngParser::WriteSDF(SvFileStream &aSDFStream,
+void LngParser::WriteSDF(std::ofstream &aSDFStream,
OStringHashMap &rText_inout, const rtl::OString &rPrj,
const rtl::OString &rRoot, const rtl::OString &rActFileName,
const rtl::OString &rID)
@@ -163,7 +165,7 @@ void LngParser::WriteSDF(SvFileStream &aSDFStream,
sOutput += sCur; sOutput += "\t";
sOutput += sAct; sOutput += "\t\t\t\t";
sOutput += sTimeStamp;
- aSDFStream.WriteLine( sOutput );
+ aSDFStream << sOutput.getStr() << '\n';
}
}
}
@@ -198,10 +200,9 @@ sal_Bool LngParser::Merge(
const rtl::OString &rDestinationFile)
{
Export::InitLanguages( true );
- SvFileStream aDestination(
- rtl::OStringToOUString(rDestinationFile, RTL_TEXTENCODING_ASCII_US),
- STREAM_STD_WRITE | STREAM_TRUNC);
- if ( !aDestination.IsOpen()) {
+ std::ofstream aDestination(
+ rDestinationFile.getStr(), std::ios_base::out | std::ios_base::trunc);
+ if (!aDestination.is_open()) {
nError = LNG_COULD_NOT_OPEN;
}
nError = LNG_OK;
@@ -346,9 +347,9 @@ sal_Bool LngParser::Merge(
}
for ( size_t i = 0; i < pLines->size(); ++i )
- aDestination.WriteLine( *(*pLines)[ i ] );
+ aDestination << (*pLines)[i]->getStr() << '\n';
- aDestination.Close();
+ aDestination.close();
return sal_True;
}
diff --git a/l10ntools/source/localize.cxx b/l10ntools/source/localize.cxx
index 8ae73c969c53..725e683ea33a 100644
--- a/l10ntools/source/localize.cxx
+++ b/l10ntools/source/localize.cxx
@@ -28,6 +28,8 @@
#include "sal/config.h"
+#include <fstream>
+
#include "srciter.hxx"
#include "export.hxx"
#include <string>
@@ -173,7 +175,7 @@ const char DLIST_NAME[] = "d.lst";
class SourceTreeLocalizer : public SourceTreeIterator
{
private:
- SvFileStream aSDF;
+ std::ofstream aSDF;
sal_uInt16 nMode;
rtl::OString sLanguageRestriction;
@@ -369,15 +371,18 @@ void SourceTreeLocalizer::WorkOnFile(
fprintf(stderr, "%s failed\n", sCommand.getStr());
nFileCnt++;
- SvFileStream aSDFIn( aTemp.GetFull(), STREAM_READ );
- rtl::OString sLine;
- while ( aSDFIn.IsOpen() && !aSDFIn.IsEof())
+ ifstream aSDFIn(
+ rtl::OUStringToOString(
+ aTemp.GetFull(), osl_getThreadTextEncoding()).
+ getStr());
+ while (aSDFIn.is_open() && !aSDFIn.eof())
{
- aSDFIn.ReadLine( sLine );
- if (!sLine.isEmpty())
- aSDF.WriteLine( sLine );
+ std::string s;
+ std::getline(aSDFIn, s);
+ if (!s.empty())
+ aSDF << s << '\n';
}
- aSDFIn.Close();
+ aSDFIn.close();
aTemp.Kill();
@@ -521,22 +526,20 @@ sal_Bool SourceTreeLocalizer::Extract(const rtl::OString &rDestinationFile)
{
nMode = LOCALIZE_EXTRACT;
- aSDF.Open(rtl::OStringToOUString(rDestinationFile, RTL_TEXTENCODING_ASCII_US) , STREAM_STD_WRITE);
- aSDF.SetLineDelimiter( LINEEND_CRLF );
+ aSDF.open(
+ rDestinationFile.getStr(), std::ios_base::out | std::ios_base::app);
- sal_Bool bReturn = aSDF.IsOpen();
+ sal_Bool bReturn = aSDF.is_open();
if ( bReturn )
{
- aSDF.Seek( STREAM_SEEK_TO_END );
bReturn = StartExecute();
- aSDF.Close();
}
else
{
printf("ERROR: Can't create file %s\n", rDestinationFile.getStr());
}
nMode = LOCALIZE_NONE;
- aSDF.Close();
+ aSDF.close();
return bReturn;
}
diff --git a/l10ntools/source/merge.cxx b/l10ntools/source/merge.cxx
index 75b0d55ec65d..e078e308907e 100644
--- a/l10ntools/source/merge.cxx
+++ b/l10ntools/source/merge.cxx
@@ -26,6 +26,11 @@
*
************************************************************************/
+#include "sal/config.h"
+
+#include <fstream>
+#include <string>
+
#include <stdio.h>
#include <tools/fsys.hxx>
#include <comphelper/string.hxx>
@@ -175,23 +180,22 @@ MergeDataFile::MergeDataFile(
bool bCaseSensitive)
: bErrorLog( bErrLog )
{
- SvFileStream aInputStream(rtl::OStringToOUString(rFileName, RTL_TEXTENCODING_ASCII_US), STREAM_STD_READ);
- aInputStream.SetStreamCharSet( RTL_TEXTENCODING_MS_1252 );
- rtl::OString sLine;
+ std::ifstream aInputStream(rFileName.getStr());
const ::rtl::OString sHACK(RTL_CONSTASCII_STRINGPARAM("HACK"));
const ::rtl::OString sFileNormalized(lcl_NormalizeFilename(rFile));
const bool isFileEmpty = !sFileNormalized.isEmpty();
- if( !aInputStream.IsOpen() )
+ if (!aInputStream.is_open())
{
printf("Warning : Can't open %s\n", rFileName.getStr());
return;
}
- while ( !aInputStream.IsEof())
+ while (!aInputStream.eof())
{
- xub_StrLen nToks;
- aInputStream.ReadLine( sLine );
- nToks = getTokenCount(sLine, '\t');
+ std::string buf;
+ std::getline(aInputStream, buf);
+ rtl::OString sLine(buf.data(), buf.length());
+ xub_StrLen nToks = getTokenCount(sLine, '\t');
if ( nToks == 15 )
{
// Skip all wrong filenames
@@ -223,7 +227,7 @@ MergeDataFile::MergeDataFile(
printf("ERROR: File format is obsolete and no longer supported!\n");
}
}
- aInputStream.Close();
+ aInputStream.close();
}
MergeDataFile::~MergeDataFile()
diff --git a/l10ntools/source/xmlparse.cxx b/l10ntools/source/xmlparse.cxx
index 50096c77525d..d6010960c2ff 100644
--- a/l10ntools/source/xmlparse.cxx
+++ b/l10ntools/source/xmlparse.cxx
@@ -26,6 +26,8 @@
*
************************************************************************/
+#include "sal/config.h"
+
#include <iterator> /* std::iterator*/
#include <stdio.h>
@@ -1154,37 +1156,30 @@ XMLFile *SimpleXMLParser::Execute( const rtl::OUString &rFullFileName , const rt
RTL_CONSTASCII_USTRINGPARAM("ERROR: Unable to open file "));
aErrorInformation.sMessage += rFileName;
- SvFileStream aStream( rFileName, STREAM_STD_READ );
-
- if ( !aStream.IsOpen())
- return NULL;
-
- SvMemoryStream aMemStream;
- aStream >> aMemStream;
- aMemStream.Seek( 0 );
-
- aStream.Close();
+ oslFileHandle h;
+ if (osl_openFile(rFileName.pData, &h, osl_File_OpenFlag_Read)
+ != osl_File_E_None)
+ {
+ return 0;
+ }
+ sal_uInt64 s;
+ oslFileError e = osl_getFileSize(h, &s);
+ void * p;
+ if (e == osl_File_E_None) {
+ e = osl_mapFile(h, &p, s, 0, 0);
+ }
+ if (e != osl_File_E_None) {
+ osl_closeFile(h);
+ return 0;
+ }
pXMLFile = pXMLFileIn;
pXMLFile->SetName( rFileName );
pXMLFile->SetFullName( rFullFileName );
- return Execute( &aMemStream );
-}
-
-/*****************************************************************************/
-XMLFile *SimpleXMLParser::Execute( SvMemoryStream *pStream )
-/*****************************************************************************/
-{
- if ( !pXMLFile )
- pXMLFile = new XMLFile(rtl::OUString());
-
pCurNode = pXMLFile;
pCurData = NULL;
- sal_uLong nPos = pStream->Tell();
- pStream->Seek( STREAM_SEEK_TO_END );
-
aErrorInformation.eCode = XML_ERROR_NONE;
aErrorInformation.nLine = 0;
aErrorInformation.nColumn = 0;
@@ -1199,8 +1194,7 @@ XMLFile *SimpleXMLParser::Execute( SvMemoryStream *pStream )
aErrorInformation.sMessage = rtl::OUString(
RTL_CONSTASCII_USTRINGPARAM("XML-File parsed successfully"));
- if ( !XML_Parse(
- aParser, ( char * ) pStream->GetData() + nPos, pStream->Tell() - nPos, sal_True ))
+ if (!XML_Parse(aParser, reinterpret_cast< char * >(p), s, true))
{
aErrorInformation.eCode = XML_GetErrorCode( aParser );
aErrorInformation.nLine = XML_GetErrorLineNumber( aParser );
@@ -1319,7 +1313,9 @@ XMLFile *SimpleXMLParser::Execute( SvMemoryStream *pStream )
delete pXMLFile;
pXMLFile = NULL;
}
- pStream->Seek( nPos );
+
+ osl_unmapMappedFile(h, p, s);
+ osl_closeFile(h);
return pXMLFile;
}
diff --git a/l10ntools/source/xrmlex.l b/l10ntools/source/xrmlex.l
index b7dccbd3d8f5..60da7be0654e 100644
--- a/l10ntools/source/xrmlex.l
+++ b/l10ntools/source/xrmlex.l
@@ -40,7 +40,6 @@ extern int SetError();
extern char *GetOutputFile( int argc, char* argv[]);
extern FILE *GetXrmFile();
extern int isQuiet();
-extern void removeTempFile();
extern char* getFilename();
/* forwards */
@@ -238,7 +237,6 @@ main( int argc, char* argv[])
nRetValue = GetError();
EndXrmExport();
- removeTempFile();
/* return error level */
return nRetValue;
}
diff --git a/l10ntools/source/xrmmerge.cxx b/l10ntools/source/xrmmerge.cxx
index b8d40c452cb5..1ad773dea085 100644
--- a/l10ntools/source/xrmmerge.cxx
+++ b/l10ntools/source/xrmmerge.cxx
@@ -28,6 +28,8 @@
#include "sal/config.h"
+#include <cstring>
+
#include <comphelper/string.hxx>
#include <stdio.h>
#include <tools/fsys.hxx>
@@ -71,7 +73,6 @@ rtl::OString sOutputFile;
rtl::OString sMergeSrc;
rtl::OString sLangAttribute;
rtl::OString sResourceType;
-rtl::OUString sUsedTempFile;
XRMResParser *pParser = NULL;
extern "C" {
@@ -158,19 +159,14 @@ extern char *GetOutputFile( int argc, char* argv[])
// command line is valid
bEnableExport = sal_True;
char *pReturn = new char[ sOutputFile.getLength() + 1 ];
- strcpy( pReturn, sOutputFile.getStr()); // #100211# - checked
+ std::strcpy( pReturn, sOutputFile.getStr()); // #100211# - checked
return pReturn;
}
// command line is not valid
return NULL;
}
-void removeTempFile(){
- if (!sUsedTempFile.isEmpty()) {
- DirEntry aTempFile( sUsedTempFile );
- aTempFile.Kill();
- }
-}
+
/*****************************************************************************/
int InitXrmExport( char *pOutput , char* pFilename)
/*****************************************************************************/
@@ -204,22 +200,10 @@ extern const char* getFilename()
extern FILE *GetXrmFile()
/*****************************************************************************/
{
- FILE *pFile = 0;
// look for valid filename
if (!sInputFileName.isEmpty()) {
- if( Export::fileHasUTF8ByteOrderMarker( sInputFileName ) ){
- DirEntry aTempFile = Export::GetTempFile();
- DirEntry aSourceFile( rtl::OStringToOUString( sInputFileName , RTL_TEXTENCODING_ASCII_US ) );
- aSourceFile.CopyTo( aTempFile , FSYS_ACTION_COPYFILE );
- rtl::OUString sTempFile = aTempFile.GetFull();
- Export::RemoveUTF8ByteOrderMarkerFromFile(rtl::OUStringToOString(sTempFile , RTL_TEXTENCODING_ASCII_US) );
- pFile = fopen(rtl::OUStringToOString(sTempFile , RTL_TEXTENCODING_ASCII_US).getStr(), "r");
- sUsedTempFile = sTempFile;
- }else{
- // able to open file?
- pFile = fopen(sInputFileName.getStr(), "r");
- sUsedTempFile = rtl::OUString();
- }
+ //TODO: explicit BOM handling?
+ FILE * pFile = fopen(sInputFileName.getStr(), "r");
if ( !pFile ){
fprintf( stderr, "Error: Could not open file %s\n",
sInputFileName.getStr());
@@ -467,18 +451,12 @@ XRMResOutputParser::XRMResOutputParser ( const rtl::OString &rOutputFile )
/*****************************************************************************/
{
aLanguages = Export::GetLanguages();
- pOutputStream =
- new SvFileStream(
- rtl::OStringToOUString( rOutputFile, RTL_TEXTENCODING_ASCII_US ),
- STREAM_STD_WRITE | STREAM_TRUNC
- );
- pOutputStream->SetStreamCharSet( RTL_TEXTENCODING_UTF8 );
- if ( !pOutputStream->IsOpen()) {
+ pOutputStream.open(
+ rOutputFile.getStr(), std::ios_base::out | std::ios_base::trunc);
+ if (!pOutputStream.is_open()) {
rtl::OString sError( "Unable to open output file: " );
sError += rOutputFile;
Error( sError );
- delete pOutputStream;
- pOutputStream = NULL;
}
}
@@ -486,10 +464,7 @@ XRMResOutputParser::XRMResOutputParser ( const rtl::OString &rOutputFile )
XRMResOutputParser::~XRMResOutputParser()
/*****************************************************************************/
{
- if ( pOutputStream ) {
- pOutputStream->Close();
- delete pOutputStream;
- }
+ pOutputStream.close();
}
//
@@ -576,7 +551,7 @@ void XRMResExport::EndOfText(
)
/*****************************************************************************/
{
- if ( pResData && pOutputStream )
+ if ( pResData )
{
rtl::OString sTimeStamp( Export::GetTimeStamp());
rtl::OString sCur;
@@ -607,7 +582,7 @@ void XRMResExport::EndOfText(
sOutput = sOutput.replace('\0', '_');
if( sAct.getLength() > 1 )
- pOutputStream->WriteLine( sOutput );
+ pOutputStream << sOutput.getStr() << '\n';
}
}
delete pResData;
@@ -751,9 +726,8 @@ void XRMResMerge::WorkOnText(
void XRMResMerge::Output( const rtl::OString& rOutput )
/*****************************************************************************/
{
- //printf("W: %s\n",rOutput.GetBuffer());
- if ( pOutputStream && !rOutput.isEmpty() )
- pOutputStream->Write( rOutput.getStr(), rOutput.getLength());
+ if (!rOutput.isEmpty())
+ pOutputStream << rOutput.getStr();
}
/*****************************************************************************/