diff options
author | Ivo Hinkelmann <ihi@openoffice.org> | 2008-02-05 14:55:49 +0000 |
---|---|---|
committer | Ivo Hinkelmann <ihi@openoffice.org> | 2008-02-05 14:55:49 +0000 |
commit | e7551bce3a5232f3726fc3050ca3dcaf9260deac (patch) | |
tree | af47c8fc90fdd6d3f6ec3edf7a844f12de6a1045 /transex3 | |
parent | fdb20ac81d5c06bf6e824bf1a963b8f6a437766e (diff) |
INTEGRATION: CWS l10ntooling09 (1.26.20); FILE MERGED
2007/12/27 15:12:20 gh 1.26.20.1: create output file only if needed to avoid 0 byte length files
Diffstat (limited to 'transex3')
-rw-r--r-- | transex3/source/gsicheck.cxx | 100 |
1 files changed, 73 insertions, 27 deletions
diff --git a/transex3/source/gsicheck.cxx b/transex3/source/gsicheck.cxx index 0b9a3884973e..404122693376 100644 --- a/transex3/source/gsicheck.cxx +++ b/transex3/source/gsicheck.cxx @@ -4,9 +4,9 @@ * * $RCSfile: gsicheck.cxx,v $ * - * $Revision: 1.26 $ + * $Revision: 1.27 $ * - * last change: $Author: hr $ $Date: 2007-06-27 17:53:17 $ + * last change: $Author: ihi $ $Date: 2008-02-05 15:55:49 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -92,6 +92,50 @@ BOOL LanguageOK( ByteString aLang ) // +// class LazySvFileStream +// + + +class LazySvFileStream : public SvFileStream +{ + +private: + String aFileName; + BOOL bOpened; + StreamMode eOpenMode; + +public: + LazySvFileStream() + : aFileName() + , bOpened( FALSE ) + , eOpenMode( 0 ) + {}; + + void SetOpenParams( const String& rFileName, StreamMode eOpenModeP ) + { + aFileName = rFileName; + eOpenMode = eOpenModeP; + }; + + void LazyOpen(); +}; + +void LazySvFileStream::LazyOpen() +{ + if ( !bOpened ) + { + Open( aFileName, eOpenMode ); + if ( !IsOpen()) + { + fprintf( stderr, "\nERROR: Could not open Output-File %s!\n\n", ByteString( aFileName, RTL_TEXTENCODING_ASCII_US ).GetBuffer() ); + exit ( 4 ); + } + bOpened = TRUE; + } +} + + +// // class GSILine // @@ -566,7 +610,7 @@ BOOL GSIBlock::CheckSyntax( ULONG nLine, BOOL bRequireSourceLine, BOOL bFixTags return bHasError || bHasBlockError; } -void GSIBlock::WriteError( SvStream &aErrOut, BOOL bRequireSourceLine ) +void GSIBlock::WriteError( LazySvFileStream &aErrOut, BOOL bRequireSourceLine ) { if ( pSourceLine && pSourceLine->IsOK() && bCheckSourceLang && !bHasBlockError ) return; @@ -579,15 +623,19 @@ void GSIBlock::WriteError( SvStream &aErrOut, BOOL bRequireSourceLine ) if ( !GetObject( i )->IsOK() || bCopyAll ) { bHasError = TRUE; + aErrOut.LazyOpen(); aErrOut.WriteLine( *GetObject( i ) ); } } if ( pSourceLine && ( bHasError || !pSourceLine->IsOK() ) && !( !bHasError && bCheckTranslationLang ) ) + { + aErrOut.LazyOpen(); aErrOut.WriteLine( *pSourceLine ); + } } -void GSIBlock::WriteCorrect( SvStream &aOkOut, BOOL bRequireSourceLine ) +void GSIBlock::WriteCorrect( LazySvFileStream &aOkOut, BOOL bRequireSourceLine ) { if ( ( !pSourceLine && bRequireSourceLine ) || ( pSourceLine && !pSourceLine->IsOK() && !bCheckTranslationLang ) ) return; @@ -599,15 +647,19 @@ void GSIBlock::WriteCorrect( SvStream &aOkOut, BOOL bRequireSourceLine ) if ( ( GetObject( i )->IsOK() || bCheckSourceLang ) && !bHasBlockError ) { bHasOK = TRUE; + aOkOut.LazyOpen(); aOkOut.WriteLine( *GetObject( i ) ); } } if ( ( pSourceLine && pSourceLine->IsOK() && ( Count() || !bCheckTranslationLang ) ) || ( bHasOK && bCheckTranslationLang ) ) + { + aOkOut.LazyOpen(); aOkOut.WriteLine( *pSourceLine ); + } } -void GSIBlock::WriteFixed( SvStream &aFixOut, BOOL /*bRequireSourceLine*/ ) +void GSIBlock::WriteFixed( LazySvFileStream &aFixOut, BOOL /*bRequireSourceLine*/ ) { if ( pSourceLine && !pSourceLine->IsFixed() && bCheckSourceLang ) return; @@ -619,14 +671,19 @@ void GSIBlock::WriteFixed( SvStream &aFixOut, BOOL /*bRequireSourceLine*/ ) if ( GetObject( i )->IsFixed() ) { bHasFixes = TRUE; + aFixOut.LazyOpen(); aFixOut.WriteLine( *GetObject( i ) ); } } if ( pSourceLine && bHasFixes ) + { + aFixOut.LazyOpen(); aFixOut.WriteLine( *pSourceLine ); + } } + /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ @@ -640,7 +697,7 @@ void Help() /*****************************************************************************/ { fprintf( stdout, "\n" ); - fprintf( stdout, "gsicheck Version 1.8.7 (c)1999 - 2006 by SUN Microsystems\n" ); + fprintf( stdout, "gsicheck Version 1.8.7a (c)1999 - 2006 by SUN Microsystems\n" ); fprintf( stdout, "=========================================================\n" ); fprintf( stdout, "\n" ); fprintf( stdout, "gsicheck checks the syntax of tags in GSI-Files and SDF-Files\n" ); @@ -885,7 +942,7 @@ int _cdecl main( int argc, char *argv[] ) } } - SvFileStream aOkOut; + LazySvFileStream aOkOut; String aBaseName = aSource.GetBase(); if ( bWriteCorrect ) { @@ -896,15 +953,10 @@ int _cdecl main( int argc, char *argv[] ) aSource.SetBase( sTmpBase ); aCorrectFilename = aSource.GetFull(); } - aOkOut.Open( aCorrectFilename , STREAM_STD_WRITE | STREAM_TRUNC ); - if ( !aOkOut.IsOpen()) - { - fprintf( stderr, "\nERROR: Could not open Output-File %s!\n\n", ByteString( aCorrectFilename, RTL_TEXTENCODING_ASCII_US ).GetBuffer() ); - exit ( 4 ); - } + aOkOut.SetOpenParams( aCorrectFilename , STREAM_STD_WRITE | STREAM_TRUNC ); } - SvFileStream aErrOut; + LazySvFileStream aErrOut; if ( bWriteError ) { if ( !aErrorFilename.Len() ) @@ -914,15 +966,10 @@ int _cdecl main( int argc, char *argv[] ) aSource.SetBase( sTmpBase ); aErrorFilename = aSource.GetFull(); } - aErrOut.Open( aErrorFilename , STREAM_STD_WRITE | STREAM_TRUNC ); - if ( !aErrOut.IsOpen()) - { - fprintf( stderr, "\nERROR: Could not open Output-File %s!\n\n", ByteString( aErrorFilename, RTL_TEXTENCODING_ASCII_US ).GetBuffer() ); - exit ( 4 ); - } + aErrOut.SetOpenParams( aErrorFilename , STREAM_STD_WRITE | STREAM_TRUNC ); } - SvFileStream aFixOut; + LazySvFileStream aFixOut; if ( bWriteFixed ) { if ( !aFixedFilename.Len() ) @@ -932,12 +979,7 @@ int _cdecl main( int argc, char *argv[] ) aSource.SetBase( sTmpBase ); aFixedFilename = aSource.GetFull(); } - aFixOut.Open( aFixedFilename , STREAM_STD_WRITE | STREAM_TRUNC ); - if ( !aFixOut.IsOpen()) - { - fprintf( stderr, "\nERROR: Could not open Output-File %s!\n\n", ByteString( aFixedFilename, RTL_TEXTENCODING_ASCII_US ).GetBuffer() ); - exit ( 4 ); - } + aFixOut.SetOpenParams( aFixedFilename , STREAM_STD_WRITE | STREAM_TRUNC ); } @@ -969,13 +1011,17 @@ int _cdecl main( int argc, char *argv[] ) if ( bWriteError ) { bFileHasError = TRUE; + aErrOut.LazyOpen(); aErrOut.WriteLine( *pGSILine ); } } else if ( pGSILine->GetLineType().EqualsIgnoreCaseAscii("res-comment") ) { // ignore comment lines, but write them to Correct Items File if ( bWriteCorrect ) + { + aOkOut.LazyOpen(); aOkOut.WriteLine( *pGSILine ); + } } else { |