xref: /aoo42x/main/l10ntools/source/xgfconv.cxx (revision 3cd96b95)
1*3cd96b95SAndrew Rist /**************************************************************
2*3cd96b95SAndrew Rist  *
3*3cd96b95SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*3cd96b95SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*3cd96b95SAndrew Rist  * distributed with this work for additional information
6*3cd96b95SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*3cd96b95SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*3cd96b95SAndrew Rist  * "License"); you may not use this file except in compliance
9*3cd96b95SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*3cd96b95SAndrew Rist  *
11*3cd96b95SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*3cd96b95SAndrew Rist  *
13*3cd96b95SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*3cd96b95SAndrew Rist  * software distributed under the License is distributed on an
15*3cd96b95SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*3cd96b95SAndrew Rist  * KIND, either express or implied.  See the License for the
17*3cd96b95SAndrew Rist  * specific language governing permissions and limitations
18*3cd96b95SAndrew Rist  * under the License.
19*3cd96b95SAndrew Rist  *
20*3cd96b95SAndrew Rist  *************************************************************/
21*3cd96b95SAndrew Rist 
22cdf0e10cSrcweir #include <stdio.h>
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "export.hxx"
25cdf0e10cSrcweir #include "utf8conv.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir /*****************************************************************************/
28cdf0e10cSrcweir 
29cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
30cdf0e10cSrcweir #include "precompiled_l10ntools.hxx"
31cdf0e10cSrcweir #if defined(UNX) || defined(OS2)
main(int argc,char * argv[])32cdf0e10cSrcweir int main( int argc, char *argv[] )
33cdf0e10cSrcweir #else
34cdf0e10cSrcweir int _cdecl main( int argc, char *argv[] )
35cdf0e10cSrcweir #endif
36cdf0e10cSrcweir /*****************************************************************************/
37cdf0e10cSrcweir {
38cdf0e10cSrcweir 	if ( argc != 3 ) {
39cdf0e10cSrcweir 		fprintf( stderr, "xgfconv InputFile OutputFile\n" );
40cdf0e10cSrcweir 		return ( 5 );
41cdf0e10cSrcweir 	}
42cdf0e10cSrcweir 
43cdf0e10cSrcweir 	ByteString sInput( argv[ 1 ] );
44cdf0e10cSrcweir 	ByteString sOutput( argv[ 2 ] );
45cdf0e10cSrcweir 
46cdf0e10cSrcweir 	SvFileStream aInput( String( sInput, RTL_TEXTENCODING_ASCII_US ), STREAM_STD_READ );
47cdf0e10cSrcweir 	if ( !aInput.IsOpen()) {
48cdf0e10cSrcweir 		fprintf( stderr, "ERROR: Unable to open input file!\n" );
49cdf0e10cSrcweir 		return ( 5 );
50cdf0e10cSrcweir 	}
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 	SvFileStream aOutput( String( sOutput, RTL_TEXTENCODING_ASCII_US ), STREAM_STD_WRITE | STREAM_TRUNC );
53cdf0e10cSrcweir 	if ( !aOutput.IsOpen()) {
54cdf0e10cSrcweir 		fprintf( stderr, "ERROR: Unable to open output file!\n" );
55cdf0e10cSrcweir 		aInput.Close();
56cdf0e10cSrcweir 		return ( 5 );
57cdf0e10cSrcweir 	}
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 	ByteString sLine;
60cdf0e10cSrcweir 	sal_Bool bFirst = sal_True;
61cdf0e10cSrcweir 	while ( !aInput.IsEof()) {
62cdf0e10cSrcweir 		aInput.ReadLine( sLine );
63cdf0e10cSrcweir 		ByteString sLangId = sLine.GetToken( 0, '\t' );
64cdf0e10cSrcweir 		ByteString sFile = sLine.GetToken( 1, '\t' );
65cdf0e10cSrcweir 		ByteString sText = sLine.Copy( sLangId.Len() + sFile.Len() + 2 );
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 		sal_uInt16 nLangId = sLangId.ToInt32();
68cdf0e10cSrcweir 		CharSet aCharSet = Export::GetCharSet( nLangId );
69cdf0e10cSrcweir 		if ( aCharSet != 0xFFFF && sText.Len()) {
70cdf0e10cSrcweir 			sText = UTF8Converter::ConvertToUTF8( sText, aCharSet );
71cdf0e10cSrcweir 			ByteString sOutput = sFile;
72cdf0e10cSrcweir 			sOutput += "\t";
73cdf0e10cSrcweir 			sOutput += sText;
74cdf0e10cSrcweir 			if ( !bFirst ) {
75cdf0e10cSrcweir 				ByteString sEmpty;
76cdf0e10cSrcweir 				aOutput.WriteLine( sEmpty );
77cdf0e10cSrcweir 			}
78cdf0e10cSrcweir 			else
79cdf0e10cSrcweir 				bFirst = sal_False;
80cdf0e10cSrcweir 			aOutput.Write( sOutput.GetBuffer(), sOutput.Len());
81cdf0e10cSrcweir 		}
82cdf0e10cSrcweir 	}
83cdf0e10cSrcweir 	aInput.Close();
84cdf0e10cSrcweir 	aOutput.Close();
85cdf0e10cSrcweir 	return ( 0 );
86cdf0e10cSrcweir }
87cdf0e10cSrcweir 
88