diff options
author | Nils Fuhrmann <nf@openoffice.org> | 2001-05-09 08:02:36 +0000 |
---|---|---|
committer | Nils Fuhrmann <nf@openoffice.org> | 2001-05-09 08:02:36 +0000 |
commit | 8e05abab151d5711d6f1bde0cb2c5d628da4e24f (patch) | |
tree | ee3bfcd01f28262b64b57cc410fb67f7c89db616 /transex3 | |
parent | 102e4b81fafc9ad8fb83e4bdcb28dbb704b47091 (diff) |
Added converter for all text files from or to UTF-8
Diffstat (limited to 'transex3')
-rw-r--r-- | transex3/source/makefile.mk | 12 | ||||
-rw-r--r-- | transex3/source/txtconv.cxx | 167 |
2 files changed, 176 insertions, 3 deletions
diff --git a/transex3/source/makefile.mk b/transex3/source/makefile.mk index 30b7dee17e6b..f7b7d80825a0 100644 --- a/transex3/source/makefile.mk +++ b/transex3/source/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.6 $ +# $Revision: 1.7 $ # -# last change: $Author: nf $ $Date: 2001-04-25 10:17:04 $ +# last change: $Author: nf $ $Date: 2001-05-09 09:02:36 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -134,7 +134,13 @@ APP8STACK= 16000 APP8OBJS= $(OBJ)$/utf8conv.obj $(OBJ)$/xgfconv.obj $(OBJ)$/export2.obj APP8STDLIBS=$(STATIC_LIBS) -DEPOBJFILES=$(APP1OBJS) $(APP2OBJS) $(APP3OBJS) $(APP4OBJS) $(APP5OBJS) $(APP6OBJS) $(APP7OBJS) $(APP8OBJS) +# encoding converter for text files +APP9TARGET= txtconv +APP9STACK= 16000 +APP9OBJS= $(OBJ)$/utf8conv.obj $(OBJ)$/txtconv.obj +APP9STDLIBS=$(STATIC_LIBS) + +DEPOBJFILES=$(APP1OBJS) $(APP2OBJS) $(APP3OBJS) $(APP4OBJS) $(APP5OBJS) $(APP6OBJS) $(APP7OBJS) $(APP8OBJS) $(APP9OBJS) .IF "$(depend)" == "" ALL : $(MISC)$/src_yy.c \ diff --git a/transex3/source/txtconv.cxx b/transex3/source/txtconv.cxx new file mode 100644 index 000000000000..69eaea1faa76 --- /dev/null +++ b/transex3/source/txtconv.cxx @@ -0,0 +1,167 @@ +/************************************************************************* + * + * $RCSfile: txtconv.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: nf $ $Date: 2001-05-09 09:02:36 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#include <stdio.h> +#include <tools/fsys.hxx> +#include <tools/stream.hxx> + +// local includes +#include "utf8conv.hxx" + +/*****************************************************************************/ +void Help() +/*****************************************************************************/ +{ + fprintf( stdout, "\n" ); + fprintf( stdout, "txtconv (c)2001 by StarOffice Entwicklungs GmbH\n" ); + fprintf( stdout, "===============================================\n" ); + fprintf( stdout, "\n" ); + fprintf( stdout, "txtconv converts textfiles from or to UTF-8\n" ); + fprintf( stdout, "\n" ); + fprintf( stdout, "Syntax: txtconv (-t|-f charset) filename\n" ); + fprintf( stdout, "Switches: -t => conversion from charset to UTF-8\n" ); + fprintf( stdout, " -f => conversion from UTF-8 to charset\n" ); + fprintf( stdout, "\n" ); + fprintf( stdout, "Allowed charsets:\n" ); + fprintf( stdout, " MS_932 => Japanese\n" ); + fprintf( stdout, " MS_936 => Chinese Simplified\n" ); + fprintf( stdout, " MS_949 => Korean\n" ); + fprintf( stdout, " MS_950 => Chinese Traditional\n" ); + fprintf( stdout, " MS_1250 => East Europe\n" ); + fprintf( stdout, " MS_1251 => Cyrillic\n" ); + fprintf( stdout, " MS_1252 => West Europe\n" ); + fprintf( stdout, " MS_1253 => Greek\n" ); + fprintf( stdout, " MS_1254 => Turkish\n" ); + fprintf( stdout, " MS_1255 => Hebrew\n" ); + fprintf( stdout, " MS_1256 => Arabic\n" ); + fprintf( stdout, "\n" ); +} + +/*****************************************************************************/ +#if defined( UNX ) || defined( MAC ) +int main( int argc, char *argv[] ) +#else +int _cdecl main( int argc, char *argv[] ) +#endif +/*****************************************************************************/ +{ + if ( argc != 4 ) { + Help(); + exit ( 0 ); + } + + if ( ByteString( argv[ 1 ] ) == "-t" || ByteString( argv[ 1 ] ) == "-f" ) { + rtl_TextEncoding nEncoding; + + ByteString sCharset( argv[ 2 ] ); + sCharset.ToUpperAscii(); + + if ( sCharset == "MS_932" ) nEncoding = RTL_TEXTENCODING_MS_932; + else if ( sCharset == "MS_936" ) nEncoding = RTL_TEXTENCODING_MS_936; + else if ( sCharset == "MS_949" ) nEncoding = RTL_TEXTENCODING_MS_949; + else if ( sCharset == "MS_950" ) nEncoding = RTL_TEXTENCODING_MS_950; + else if ( sCharset == "MS_1250" ) nEncoding = RTL_TEXTENCODING_MS_1250; + else if ( sCharset == "MS_1251" ) nEncoding = RTL_TEXTENCODING_MS_1251; + else if ( sCharset == "MS_1252" ) nEncoding = RTL_TEXTENCODING_MS_1252; + else if ( sCharset == "MS_1253" ) nEncoding = RTL_TEXTENCODING_MS_1253; + else if ( sCharset == "MS_1254" ) nEncoding = RTL_TEXTENCODING_MS_1254; + else if ( sCharset == "MS_1255" ) nEncoding = RTL_TEXTENCODING_MS_1255; + else if ( sCharset == "MS_1256" ) nEncoding = RTL_TEXTENCODING_MS_1256; + else if ( sCharset == "MS_1257" ) nEncoding = RTL_TEXTENCODING_MS_1257; + + else { + Help(); + exit ( 1 ); + } + + DirEntry aSource = DirEntry( String( argv[ 3 ], RTL_TEXTENCODING_ASCII_US )); + if ( !aSource.Exists()) { + fprintf( stderr, "\nERROR: File %s not found!\n\n", ByteString( argv[ 3 ] ).GetBuffer()); + exit ( 2 ); + } + + String sGSI( argv[ 3 ], RTL_TEXTENCODING_ASCII_US ); + SvFileStream aGSI( sGSI, STREAM_STD_READ ); + if ( !aGSI.IsOpen()) { + fprintf( stderr, "\nERROR: Could not open file %s!\n\n", ByteString( argv[ 3 ] ).GetBuffer()); + exit ( 3 ); + } + + ByteString sGSILine; + while ( !aGSI.IsEof()) { + + aGSI.ReadLine( sGSILine ); + if ( ByteString( argv[ 1 ] ) == "-t" ) + sGSILine = UTF8Converter::ConvertToUTF8( sGSILine, nEncoding ); + else + sGSILine = UTF8Converter::ConvertFromUTF8( sGSILine, nEncoding ); + + fprintf( stdout, "%s\n", sGSILine.GetBuffer()); + } + + aGSI.Close(); + } + else { + Help(); + exit( 1 ); + } + + return 0; +} |