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