Update ooo320-m1
[ooovba.git] / transex3 / source / xgfconv.cxx
bloba02920fff874ab44842052cc527010c7cf1146d4
1 #include <stdio.h>
3 #include "export.hxx"
4 #include "utf8conv.hxx"
6 /*****************************************************************************/
8 // MARKER(update_precomp.py): autogen include statement, do not remove
9 #include "precompiled_transex3.hxx"
10 #if defined(UNX) || defined(OS2)
11 int main( int argc, char *argv[] )
12 #else
13 int _cdecl main( int argc, char *argv[] )
14 #endif
15 /*****************************************************************************/
17 if ( argc != 3 ) {
18 fprintf( stderr, "xgfconv InputFile OutputFile\n" );
19 return ( 5 );
22 ByteString sInput( argv[ 1 ] );
23 ByteString sOutput( argv[ 2 ] );
25 SvFileStream aInput( String( sInput, RTL_TEXTENCODING_ASCII_US ), STREAM_STD_READ );
26 if ( !aInput.IsOpen()) {
27 fprintf( stderr, "ERROR: Unable to open input file!\n" );
28 return ( 5 );
31 SvFileStream aOutput( String( sOutput, RTL_TEXTENCODING_ASCII_US ), STREAM_STD_WRITE | STREAM_TRUNC );
32 if ( !aOutput.IsOpen()) {
33 fprintf( stderr, "ERROR: Unable to open output file!\n" );
34 aInput.Close();
35 return ( 5 );
38 ByteString sLine;
39 BOOL bFirst = TRUE;
40 while ( !aInput.IsEof()) {
41 aInput.ReadLine( sLine );
42 ByteString sLangId = sLine.GetToken( 0, '\t' );
43 ByteString sFile = sLine.GetToken( 1, '\t' );
44 ByteString sText = sLine.Copy( sLangId.Len() + sFile.Len() + 2 );
46 USHORT nLangId = sLangId.ToInt32();
47 CharSet aCharSet = Export::GetCharSet( nLangId );
48 if ( aCharSet != 0xFFFF && sText.Len()) {
49 sText = UTF8Converter::ConvertToUTF8( sText, aCharSet );
50 ByteString sOutput = sFile;
51 sOutput += "\t";
52 sOutput += sText;
53 if ( !bFirst ) {
54 ByteString sEmpty;
55 aOutput.WriteLine( sEmpty );
57 else
58 bFirst = FALSE;
59 aOutput.Write( sOutput.GetBuffer(), sOutput.Len());
62 aInput.Close();
63 aOutput.Close();
64 return ( 0 );