xref: /aoo42x/main/l10ntools/source/xgfconv.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir #include <stdio.h>
2*cdf0e10cSrcweir 
3*cdf0e10cSrcweir #include "export.hxx"
4*cdf0e10cSrcweir #include "utf8conv.hxx"
5*cdf0e10cSrcweir 
6*cdf0e10cSrcweir /*****************************************************************************/
7*cdf0e10cSrcweir 
8*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
9*cdf0e10cSrcweir #include "precompiled_l10ntools.hxx"
10*cdf0e10cSrcweir #if defined(UNX) || defined(OS2)
11*cdf0e10cSrcweir int main( int argc, char *argv[] )
12*cdf0e10cSrcweir #else
13*cdf0e10cSrcweir int _cdecl main( int argc, char *argv[] )
14*cdf0e10cSrcweir #endif
15*cdf0e10cSrcweir /*****************************************************************************/
16*cdf0e10cSrcweir {
17*cdf0e10cSrcweir 	if ( argc != 3 ) {
18*cdf0e10cSrcweir 		fprintf( stderr, "xgfconv InputFile OutputFile\n" );
19*cdf0e10cSrcweir 		return ( 5 );
20*cdf0e10cSrcweir 	}
21*cdf0e10cSrcweir 
22*cdf0e10cSrcweir 	ByteString sInput( argv[ 1 ] );
23*cdf0e10cSrcweir 	ByteString sOutput( argv[ 2 ] );
24*cdf0e10cSrcweir 
25*cdf0e10cSrcweir 	SvFileStream aInput( String( sInput, RTL_TEXTENCODING_ASCII_US ), STREAM_STD_READ );
26*cdf0e10cSrcweir 	if ( !aInput.IsOpen()) {
27*cdf0e10cSrcweir 		fprintf( stderr, "ERROR: Unable to open input file!\n" );
28*cdf0e10cSrcweir 		return ( 5 );
29*cdf0e10cSrcweir 	}
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 	SvFileStream aOutput( String( sOutput, RTL_TEXTENCODING_ASCII_US ), STREAM_STD_WRITE | STREAM_TRUNC );
32*cdf0e10cSrcweir 	if ( !aOutput.IsOpen()) {
33*cdf0e10cSrcweir 		fprintf( stderr, "ERROR: Unable to open output file!\n" );
34*cdf0e10cSrcweir 		aInput.Close();
35*cdf0e10cSrcweir 		return ( 5 );
36*cdf0e10cSrcweir 	}
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir 	ByteString sLine;
39*cdf0e10cSrcweir 	sal_Bool bFirst = sal_True;
40*cdf0e10cSrcweir 	while ( !aInput.IsEof()) {
41*cdf0e10cSrcweir 		aInput.ReadLine( sLine );
42*cdf0e10cSrcweir 		ByteString sLangId = sLine.GetToken( 0, '\t' );
43*cdf0e10cSrcweir 		ByteString sFile = sLine.GetToken( 1, '\t' );
44*cdf0e10cSrcweir 		ByteString sText = sLine.Copy( sLangId.Len() + sFile.Len() + 2 );
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir 		sal_uInt16 nLangId = sLangId.ToInt32();
47*cdf0e10cSrcweir 		CharSet aCharSet = Export::GetCharSet( nLangId );
48*cdf0e10cSrcweir 		if ( aCharSet != 0xFFFF && sText.Len()) {
49*cdf0e10cSrcweir 			sText = UTF8Converter::ConvertToUTF8( sText, aCharSet );
50*cdf0e10cSrcweir 			ByteString sOutput = sFile;
51*cdf0e10cSrcweir 			sOutput += "\t";
52*cdf0e10cSrcweir 			sOutput += sText;
53*cdf0e10cSrcweir 			if ( !bFirst ) {
54*cdf0e10cSrcweir 				ByteString sEmpty;
55*cdf0e10cSrcweir 				aOutput.WriteLine( sEmpty );
56*cdf0e10cSrcweir 			}
57*cdf0e10cSrcweir 			else
58*cdf0e10cSrcweir 				bFirst = sal_False;
59*cdf0e10cSrcweir 			aOutput.Write( sOutput.GetBuffer(), sOutput.Len());
60*cdf0e10cSrcweir 		}
61*cdf0e10cSrcweir 	}
62*cdf0e10cSrcweir 	aInput.Close();
63*cdf0e10cSrcweir 	aOutput.Close();
64*cdf0e10cSrcweir 	return ( 0 );
65*cdf0e10cSrcweir }
66*cdf0e10cSrcweir 
67