xref: /AOO42X/main/l10ntools/source/gsiconv.cxx (revision b1c5455db1639c48e26c568e4fa7ee78ca5d60ee)
1*3cd96b95SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
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
10cdf0e10cSrcweir  *
11*3cd96b95SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
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.
19cdf0e10cSrcweir  *
20*3cd96b95SAndrew Rist  *************************************************************/
21*3cd96b95SAndrew Rist 
22*3cd96b95SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_l10ntools.hxx"
26cdf0e10cSrcweir #include <stdio.h>
27cdf0e10cSrcweir #include <tools/fsys.hxx>
28cdf0e10cSrcweir #include <tools/stream.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir // local includes
31cdf0e10cSrcweir #include "utf8conv.hxx"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #define GSI_FILE_UNKNOWN        0x0000
34cdf0e10cSrcweir #define GSI_FILE_OLDSTYLE       0x0001
35cdf0e10cSrcweir #define GSI_FILE_L10NFRAMEWORK  0x0002
36cdf0e10cSrcweir 
37cdf0e10cSrcweir /*****************************************************************************/
GetGSIFileType(SvStream & rStream)38cdf0e10cSrcweir sal_uInt16 GetGSIFileType( SvStream &rStream )
39cdf0e10cSrcweir /*****************************************************************************/
40cdf0e10cSrcweir {
41cdf0e10cSrcweir     sal_uInt16 nFileType = GSI_FILE_UNKNOWN;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir     sal_uLong nPos( rStream.Tell());
44cdf0e10cSrcweir     rStream.Seek( STREAM_SEEK_TO_BEGIN );
45cdf0e10cSrcweir 
46cdf0e10cSrcweir     ByteString sLine;
47cdf0e10cSrcweir     while( !rStream.IsEof() && !sLine.Len())
48cdf0e10cSrcweir         rStream.ReadLine( sLine );
49cdf0e10cSrcweir 
50cdf0e10cSrcweir     if( sLine.Len()) {
51cdf0e10cSrcweir         if( sLine.Search( "($$)" ) != STRING_NOTFOUND )
52cdf0e10cSrcweir             nFileType = GSI_FILE_OLDSTYLE;
53cdf0e10cSrcweir         else
54cdf0e10cSrcweir             nFileType = GSI_FILE_L10NFRAMEWORK;
55cdf0e10cSrcweir     }
56cdf0e10cSrcweir 
57cdf0e10cSrcweir     rStream.Seek( nPos );
58cdf0e10cSrcweir 
59cdf0e10cSrcweir     return nFileType;
60cdf0e10cSrcweir }
61cdf0e10cSrcweir 
62cdf0e10cSrcweir /*****************************************************************************/
GetGSILineId(const ByteString & rLine,sal_uInt16 nFileType)63cdf0e10cSrcweir ByteString GetGSILineId( const ByteString &rLine, sal_uInt16 nFileType )
64cdf0e10cSrcweir /*****************************************************************************/
65cdf0e10cSrcweir {
66cdf0e10cSrcweir     ByteString sId;
67cdf0e10cSrcweir     switch ( nFileType ) {
68cdf0e10cSrcweir         case GSI_FILE_OLDSTYLE:
69cdf0e10cSrcweir             sId = rLine;
70cdf0e10cSrcweir             sId.SearchAndReplaceAll( "($$)", "\t" );
71cdf0e10cSrcweir             sId = sId.GetToken( 0, '\t' );
72cdf0e10cSrcweir         break;
73cdf0e10cSrcweir 
74cdf0e10cSrcweir         case GSI_FILE_L10NFRAMEWORK:
75cdf0e10cSrcweir             sId = rLine.GetToken( 0, '\t' );
76cdf0e10cSrcweir             sId += "\t";
77cdf0e10cSrcweir             sId += rLine.GetToken( 1, '\t' );
78cdf0e10cSrcweir             sId += "\t";
79cdf0e10cSrcweir             sId += rLine.GetToken( 4, '\t' );
80cdf0e10cSrcweir             sId += "\t";
81cdf0e10cSrcweir             sId += rLine.GetToken( 5, '\t' );
82cdf0e10cSrcweir         break;
83cdf0e10cSrcweir     }
84cdf0e10cSrcweir     return sId;
85cdf0e10cSrcweir }
86cdf0e10cSrcweir 
87cdf0e10cSrcweir /*****************************************************************************/
GetGSILineLangId(const ByteString & rLine,sal_uInt16 nFileType)88cdf0e10cSrcweir ByteString GetGSILineLangId( const ByteString &rLine, sal_uInt16 nFileType )
89cdf0e10cSrcweir /*****************************************************************************/
90cdf0e10cSrcweir {
91cdf0e10cSrcweir     ByteString sLangId;
92cdf0e10cSrcweir     switch ( nFileType ) {
93cdf0e10cSrcweir         case GSI_FILE_OLDSTYLE:
94cdf0e10cSrcweir             sLangId = rLine;
95cdf0e10cSrcweir             sLangId.SearchAndReplaceAll( "($$)", "\t" );
96cdf0e10cSrcweir             sLangId = sLangId.GetToken( 2, '\t' );
97cdf0e10cSrcweir         break;
98cdf0e10cSrcweir 
99cdf0e10cSrcweir         case GSI_FILE_L10NFRAMEWORK:
100cdf0e10cSrcweir             sLangId = rLine.GetToken( 9, '\t' );
101cdf0e10cSrcweir         break;
102cdf0e10cSrcweir     }
103cdf0e10cSrcweir     return sLangId;
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir /*****************************************************************************/
ConvertGSILine(sal_Bool bToUTF8,ByteString & rLine,rtl_TextEncoding nEncoding,sal_uInt16 nFileType)107cdf0e10cSrcweir void ConvertGSILine( sal_Bool bToUTF8, ByteString &rLine,
108cdf0e10cSrcweir         rtl_TextEncoding nEncoding, sal_uInt16 nFileType )
109cdf0e10cSrcweir /*****************************************************************************/
110cdf0e10cSrcweir {
111cdf0e10cSrcweir     switch ( nFileType ) {
112cdf0e10cSrcweir         case GSI_FILE_OLDSTYLE:
113cdf0e10cSrcweir             if ( bToUTF8 )
114cdf0e10cSrcweir                 rLine = UTF8Converter::ConvertToUTF8( rLine, nEncoding );
115cdf0e10cSrcweir             else
116cdf0e10cSrcweir                 rLine = UTF8Converter::ConvertFromUTF8( rLine, nEncoding );
117cdf0e10cSrcweir         break;
118cdf0e10cSrcweir 
119cdf0e10cSrcweir         case GSI_FILE_L10NFRAMEWORK: {
120cdf0e10cSrcweir             ByteString sConverted;
121cdf0e10cSrcweir             for ( sal_uInt16 i = 0; i < rLine.GetTokenCount( '\t' ); i++ ) {
122cdf0e10cSrcweir                 ByteString sToken = rLine.GetToken( i, '\t' );
123cdf0e10cSrcweir                 if (( i > 9 ) && ( i < 14 )) {
124cdf0e10cSrcweir                     if( bToUTF8 )
125cdf0e10cSrcweir                         sToken = UTF8Converter::ConvertToUTF8( sToken, nEncoding );
126cdf0e10cSrcweir                     else
127cdf0e10cSrcweir                         sToken = UTF8Converter::ConvertFromUTF8( sToken, nEncoding );
128cdf0e10cSrcweir                 }
129cdf0e10cSrcweir                 if ( i )
130cdf0e10cSrcweir                     sConverted += "\t";
131cdf0e10cSrcweir                 sConverted += sToken;
132cdf0e10cSrcweir             }
133cdf0e10cSrcweir             rLine = sConverted;
134cdf0e10cSrcweir         }
135cdf0e10cSrcweir         break;
136cdf0e10cSrcweir     }
137cdf0e10cSrcweir }
138cdf0e10cSrcweir 
139cdf0e10cSrcweir /*****************************************************************************/
Help()140cdf0e10cSrcweir void Help()
141cdf0e10cSrcweir /*****************************************************************************/
142cdf0e10cSrcweir {
143cdf0e10cSrcweir     fprintf( stdout, "\n" );
144cdf0e10cSrcweir     fprintf( stdout, "gsiconv (c)1999 by StarOffice Entwicklungs GmbH\n" );
145cdf0e10cSrcweir     fprintf( stdout, "===============================================\n" );
146cdf0e10cSrcweir     fprintf( stdout, "\n" );
147cdf0e10cSrcweir     fprintf( stdout, "gsiconv converts strings in GSI-Files (Gutschmitt Interface) from or to UTF-8\n" );
148cdf0e10cSrcweir     fprintf( stdout, "\n" );
149cdf0e10cSrcweir     fprintf( stdout, "Syntax: gsiconv (-t|-f langid charset)|(-p n) filename\n" );
150cdf0e10cSrcweir     fprintf( stdout, "Switches: -t   => conversion from charset to UTF-8\n" );
151cdf0e10cSrcweir     fprintf( stdout, "          -f   => conversion from UTF-8 to charset\n" );
152cdf0e10cSrcweir     fprintf( stdout, "          -p n => creates several files with ca. n lines\n" );
153cdf0e10cSrcweir     fprintf( stdout, "\n" );
154cdf0e10cSrcweir     fprintf( stdout, "Allowed charsets:\n" );
155cdf0e10cSrcweir     fprintf( stdout, "          MS_932  => Japanese\n" );
156cdf0e10cSrcweir     fprintf( stdout, "          MS_936  => Chinese Simplified\n" );
157cdf0e10cSrcweir     fprintf( stdout, "          MS_949  => Korean\n" );
158cdf0e10cSrcweir     fprintf( stdout, "          MS_950  => Chinese Traditional\n" );
159cdf0e10cSrcweir     fprintf( stdout, "          MS_1250 => East Europe\n" );
160cdf0e10cSrcweir     fprintf( stdout, "          MS_1251 => Cyrillic\n" );
161cdf0e10cSrcweir     fprintf( stdout, "          MS_1252 => West Europe\n" );
162cdf0e10cSrcweir     fprintf( stdout, "          MS_1253 => Greek\n" );
163cdf0e10cSrcweir     fprintf( stdout, "          MS_1254 => Turkish\n" );
164cdf0e10cSrcweir     fprintf( stdout, "          MS_1255 => Hebrew\n" );
165cdf0e10cSrcweir     fprintf( stdout, "          MS_1256 => Arabic\n" );
166cdf0e10cSrcweir     fprintf( stdout, "\n" );
167cdf0e10cSrcweir     fprintf( stdout, "Allowed langids:\n" );
168cdf0e10cSrcweir     fprintf( stdout, "          1  => ENGLISH_US\n" );
169cdf0e10cSrcweir     fprintf( stdout, "          3  => PORTUGUESE \n" );
170cdf0e10cSrcweir     fprintf( stdout, "          4  => GERMAN_DE (new german style)\n" );
171cdf0e10cSrcweir     fprintf( stdout, "          7  => RUSSIAN\n" );
172cdf0e10cSrcweir     fprintf( stdout, "          30 => GREEK\n" );
173cdf0e10cSrcweir     fprintf( stdout, "          31 => DUTCH\n" );
174cdf0e10cSrcweir     fprintf( stdout, "          33 => FRENCH\n" );
175cdf0e10cSrcweir     fprintf( stdout, "          34 => SPANISH\n" );
176cdf0e10cSrcweir     fprintf( stdout, "          35 => FINNISH\n" );
177cdf0e10cSrcweir     fprintf( stdout, "          36 => HUNGARIAN\n" );
178cdf0e10cSrcweir     fprintf( stdout, "          39 => ITALIAN\n" );
179cdf0e10cSrcweir     fprintf( stdout, "          42 => CZECH\n" );
180cdf0e10cSrcweir     fprintf( stdout, "          44 => ENGLISH (UK)\n" );
181cdf0e10cSrcweir     fprintf( stdout, "          45 => DANISH\n" );
182cdf0e10cSrcweir     fprintf( stdout, "          46 => SWEDISH\n" );
183cdf0e10cSrcweir     fprintf( stdout, "          47 => NORWEGIAN\n" );
184cdf0e10cSrcweir     fprintf( stdout, "          49 => GERMAN (old german style)\n" );
185cdf0e10cSrcweir     fprintf( stdout, "          55 => PORTUGUESE_BRAZILIAN\n" );
186cdf0e10cSrcweir     fprintf( stdout, "          81 => JAPANESE\n" );
187cdf0e10cSrcweir     fprintf( stdout, "          82 => KOREAN\n" );
188cdf0e10cSrcweir     fprintf( stdout, "          86 => CHINESE_SIMPLIFIED\n" );
189cdf0e10cSrcweir     fprintf( stdout, "          88 => CHINESE_TRADITIONAL\n" );
190cdf0e10cSrcweir     fprintf( stdout, "          90 => TURKISH\n" );
191cdf0e10cSrcweir     fprintf( stdout, "          96 => ARABIC\n" );
192cdf0e10cSrcweir     fprintf( stdout, "          97 => HEBREW\n" );
193cdf0e10cSrcweir     fprintf( stdout, "\n" );
194cdf0e10cSrcweir }
195cdf0e10cSrcweir 
196cdf0e10cSrcweir /*****************************************************************************/
197cdf0e10cSrcweir #if defined(UNX) || defined(OS2)
main(int argc,char * argv[])198cdf0e10cSrcweir int main( int argc, char *argv[] )
199cdf0e10cSrcweir #else
200cdf0e10cSrcweir int _cdecl main( int argc, char *argv[] )
201cdf0e10cSrcweir #endif
202cdf0e10cSrcweir /*****************************************************************************/
203cdf0e10cSrcweir {
204cdf0e10cSrcweir     if (( argc != 5 ) && ( argc != 4 )) {
205cdf0e10cSrcweir         Help();
206cdf0e10cSrcweir         exit ( 0 );
207cdf0e10cSrcweir     }
208cdf0e10cSrcweir 
209cdf0e10cSrcweir     if ( argc == 4 ) {
210cdf0e10cSrcweir         if ( ByteString( argv[ 1 ] ) == "-p" ) {
211cdf0e10cSrcweir 
212cdf0e10cSrcweir             DirEntry aSource = DirEntry( String( argv[ 3 ], RTL_TEXTENCODING_ASCII_US ));
213cdf0e10cSrcweir             if ( !aSource.Exists()) {
214cdf0e10cSrcweir                 fprintf( stderr, "\nERROR: GSI-File %s not found!\n\n", ByteString( argv[ 3 ] ).GetBuffer());
215cdf0e10cSrcweir                 exit ( 2 );
216cdf0e10cSrcweir             }
217cdf0e10cSrcweir 
218cdf0e10cSrcweir             DirEntry aOutput( aSource );
219cdf0e10cSrcweir 
220cdf0e10cSrcweir             String sBase = aOutput.GetBase();
221cdf0e10cSrcweir             String sExt = aOutput.GetExtension();
222cdf0e10cSrcweir 
223cdf0e10cSrcweir             String sGSI( argv[ 3 ], RTL_TEXTENCODING_ASCII_US );
224cdf0e10cSrcweir             SvFileStream aGSI( sGSI, STREAM_STD_READ  );
225cdf0e10cSrcweir             if ( !aGSI.IsOpen()) {
226cdf0e10cSrcweir                 fprintf( stderr, "\nERROR: Could not open GSI-File %s!\n\n", ByteString( argv[ 3 ] ).GetBuffer());
227cdf0e10cSrcweir                 exit ( 3 );
228cdf0e10cSrcweir             }
229cdf0e10cSrcweir 
230cdf0e10cSrcweir             sal_uInt16 nFileType( GetGSIFileType( aGSI ));
231cdf0e10cSrcweir 
232cdf0e10cSrcweir             sal_uLong nMaxLines = (sal_uLong) ByteString( argv[ 2 ] ).ToInt64();
233cdf0e10cSrcweir             if ( !nMaxLines ) {
234cdf0e10cSrcweir                 fprintf( stderr, "\nERROR: Linecount must be at least 1!\n\n" );
235cdf0e10cSrcweir                 exit ( 3 );
236cdf0e10cSrcweir             }
237cdf0e10cSrcweir 
238cdf0e10cSrcweir             ByteString sGSILine;
239cdf0e10cSrcweir             ByteString sOldId;
240cdf0e10cSrcweir             sal_uLong nLine = 0;
241cdf0e10cSrcweir             sal_uLong nOutputFile = 1;
242cdf0e10cSrcweir 
243cdf0e10cSrcweir             String sOutput( sBase );
244cdf0e10cSrcweir             sOutput += String( "_", RTL_TEXTENCODING_ASCII_US );
245cdf0e10cSrcweir             sOutput += String::CreateFromInt64( nOutputFile );
246cdf0e10cSrcweir             if ( sExt.Len()) {
247cdf0e10cSrcweir                 sOutput += String( ".", RTL_TEXTENCODING_ASCII_US );
248cdf0e10cSrcweir                 sOutput += sExt;
249cdf0e10cSrcweir             }
250cdf0e10cSrcweir             nOutputFile ++;
251cdf0e10cSrcweir 
252cdf0e10cSrcweir             aOutput.SetName( sOutput );
253cdf0e10cSrcweir             SvFileStream aOutputStream( aOutput.GetFull(), STREAM_STD_WRITE | STREAM_TRUNC );
254cdf0e10cSrcweir 
255cdf0e10cSrcweir             while ( !aGSI.IsEof()) {
256cdf0e10cSrcweir 
257cdf0e10cSrcweir                 aGSI.ReadLine( sGSILine );
258cdf0e10cSrcweir                 ByteString sId( GetGSILineId( sGSILine, nFileType ));
259cdf0e10cSrcweir 
260cdf0e10cSrcweir                 nLine++;
261cdf0e10cSrcweir 
262cdf0e10cSrcweir                 if (( nLine >= nMaxLines ) && ( sId != sOldId )) {
263cdf0e10cSrcweir                     aOutputStream.Close();
264cdf0e10cSrcweir 
265cdf0e10cSrcweir                     ByteString sText( aOutput.GetFull(), gsl_getSystemTextEncoding());
266cdf0e10cSrcweir                     sText += " with ";
267cdf0e10cSrcweir                     sText += ByteString::CreateFromInt64( nLine );
268cdf0e10cSrcweir                     sText += " lines written.";
269cdf0e10cSrcweir 
270cdf0e10cSrcweir                     fprintf( stdout, "%s\n", sText.GetBuffer());
271cdf0e10cSrcweir                     String sOutput1( sBase );
272cdf0e10cSrcweir                     sOutput1 += String( "_", RTL_TEXTENCODING_ASCII_US );
273cdf0e10cSrcweir                     sOutput1 += String::CreateFromInt64( nOutputFile );
274cdf0e10cSrcweir                     if ( sExt.Len()) {
275cdf0e10cSrcweir                         sOutput1 += String( ".", RTL_TEXTENCODING_ASCII_US );
276cdf0e10cSrcweir                         sOutput1 += sExt;
277cdf0e10cSrcweir                     }
278cdf0e10cSrcweir                     nOutputFile ++;
279cdf0e10cSrcweir 
280cdf0e10cSrcweir                     aOutput.SetName( sOutput1 );
281cdf0e10cSrcweir 
282cdf0e10cSrcweir                     aOutputStream.Open( aOutput.GetFull(), STREAM_STD_WRITE | STREAM_TRUNC );
283cdf0e10cSrcweir                     nLine = 0;
284cdf0e10cSrcweir                 }
285cdf0e10cSrcweir 
286cdf0e10cSrcweir                 aOutputStream.WriteLine( sGSILine );
287cdf0e10cSrcweir 
288cdf0e10cSrcweir                 sOldId = sId;
289cdf0e10cSrcweir             }
290cdf0e10cSrcweir 
291cdf0e10cSrcweir             aGSI.Close();
292cdf0e10cSrcweir             aOutputStream.Close();
293cdf0e10cSrcweir 
294cdf0e10cSrcweir             ByteString sText( aOutput.GetFull(), RTL_TEXTENCODING_ASCII_US );
295cdf0e10cSrcweir             sText += " with ";
296cdf0e10cSrcweir             sText += ByteString::CreateFromInt64( nLine );
297cdf0e10cSrcweir             sText += " lines written.";
298cdf0e10cSrcweir         }
299cdf0e10cSrcweir         else {
300cdf0e10cSrcweir             Help();
301cdf0e10cSrcweir             exit( 1 );
302cdf0e10cSrcweir         }
303cdf0e10cSrcweir     }
304cdf0e10cSrcweir     else {
305cdf0e10cSrcweir         if ( ByteString( argv[ 1 ] ) == "-t" || ByteString( argv[ 1 ] ) == "-f" ) {
306cdf0e10cSrcweir             rtl_TextEncoding nEncoding;
307cdf0e10cSrcweir 
308cdf0e10cSrcweir             ByteString sCurLangId( argv[ 2 ] );
309cdf0e10cSrcweir 
310cdf0e10cSrcweir             ByteString sCharset( argv[ 3 ] );
311cdf0e10cSrcweir             sCharset.ToUpperAscii();
312cdf0e10cSrcweir 
313cdf0e10cSrcweir             if      ( sCharset == "MS_932" )    nEncoding = RTL_TEXTENCODING_MS_932;
314cdf0e10cSrcweir             else if ( sCharset == "MS_936" )    nEncoding = RTL_TEXTENCODING_MS_936;
315cdf0e10cSrcweir             else if ( sCharset == "MS_949" )    nEncoding = RTL_TEXTENCODING_MS_949;
316cdf0e10cSrcweir             else if ( sCharset == "MS_950" )    nEncoding = RTL_TEXTENCODING_MS_950;
317cdf0e10cSrcweir             else if ( sCharset == "MS_1250" )   nEncoding = RTL_TEXTENCODING_MS_1250;
318cdf0e10cSrcweir             else if ( sCharset == "MS_1251" )   nEncoding = RTL_TEXTENCODING_MS_1251;
319cdf0e10cSrcweir             else if ( sCharset == "MS_1252" )   nEncoding = RTL_TEXTENCODING_MS_1252;
320cdf0e10cSrcweir             else if ( sCharset == "MS_1253" )   nEncoding = RTL_TEXTENCODING_MS_1253;
321cdf0e10cSrcweir             else if ( sCharset == "MS_1254" )   nEncoding = RTL_TEXTENCODING_MS_1254;
322cdf0e10cSrcweir             else if ( sCharset == "MS_1255" )   nEncoding = RTL_TEXTENCODING_MS_1255;
323cdf0e10cSrcweir             else if ( sCharset == "MS_1256" )   nEncoding = RTL_TEXTENCODING_MS_1256;
324cdf0e10cSrcweir             else if ( sCharset == "MS_1257" )   nEncoding = RTL_TEXTENCODING_MS_1257;
325cdf0e10cSrcweir             else if ( sCharset == "UTF8" )      nEncoding = RTL_TEXTENCODING_UTF8;
326cdf0e10cSrcweir 
327cdf0e10cSrcweir             else {
328cdf0e10cSrcweir                 Help();
329cdf0e10cSrcweir                 exit ( 1 );
330cdf0e10cSrcweir             }
331cdf0e10cSrcweir 
332cdf0e10cSrcweir             DirEntry aSource = DirEntry( String( argv[ 4 ], RTL_TEXTENCODING_ASCII_US ));
333cdf0e10cSrcweir             if ( !aSource.Exists()) {
334cdf0e10cSrcweir                 fprintf( stderr, "\nERROR: GSI-File %s not found!\n\n", ByteString( argv[ 3 ] ).GetBuffer());
335cdf0e10cSrcweir                 exit ( 2 );
336cdf0e10cSrcweir             }
337cdf0e10cSrcweir 
338cdf0e10cSrcweir             String sGSI( argv[ 4 ], RTL_TEXTENCODING_ASCII_US );
339cdf0e10cSrcweir             SvFileStream aGSI( sGSI, STREAM_STD_READ );
340cdf0e10cSrcweir             if ( !aGSI.IsOpen()) {
341cdf0e10cSrcweir                 fprintf( stderr, "\nERROR: Could not open GSI-File %s!\n\n", ByteString( argv[ 3 ] ).GetBuffer());
342cdf0e10cSrcweir                 exit ( 3 );
343cdf0e10cSrcweir             }
344cdf0e10cSrcweir             sal_uInt16 nFileType( GetGSIFileType( aGSI ));
345cdf0e10cSrcweir 
346cdf0e10cSrcweir             ByteString sGSILine;
347cdf0e10cSrcweir             while ( !aGSI.IsEof()) {
348cdf0e10cSrcweir 
349cdf0e10cSrcweir                 aGSI.ReadLine( sGSILine );
350cdf0e10cSrcweir                 ByteString sLangId( GetGSILineLangId( sGSILine, nFileType ));
351cdf0e10cSrcweir                 if ( sLangId == sCurLangId )
352cdf0e10cSrcweir                     ConvertGSILine(( ByteString( argv[ 1 ] ) == "-t" ), sGSILine, nEncoding, nFileType );
353cdf0e10cSrcweir 
354cdf0e10cSrcweir                 fprintf( stdout, "%s\n", sGSILine.GetBuffer());
355cdf0e10cSrcweir             }
356cdf0e10cSrcweir 
357cdf0e10cSrcweir             aGSI.Close();
358cdf0e10cSrcweir         }
359cdf0e10cSrcweir         else {
360cdf0e10cSrcweir             Help();
361cdf0e10cSrcweir             exit( 1 );
362cdf0e10cSrcweir         }
363cdf0e10cSrcweir     }
364cdf0e10cSrcweir     return 0;
365cdf0e10cSrcweir }
366