From 946efde18162392b30967af66b61fb1e93eed09d Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Mon, 31 Jan 2000 04:53:47 +0000 Subject: [PATCH] config.h.in: Rebuilt. * include/config.h.in: Rebuilt. * acconfig.h (HAVE_ICONV): Define. * configure: Rebuilt. * configure.in: Check for `iconv' function. * gnu/gcj/convert/BytesToUnicode.java (getDecoder): Try iconv if no specific encoder exists. * gnu/gcj/convert/UnicodeToBytes.java (getEncoder): Try iconv if no specific encoder exists. * Makefile.in: Rebuilt. * Makefile.am (convert_source_files): Mention Input_iconv.java and Output_iconv.java. (nat_source_files): Added natIconv.cc. * gnu/gcj/convert/natIconv.cc: New file. * gnu/gcj/convert/Input_iconv.java: New file. * gnu/gcj/convert/Output_iconv.java: New file. From-SVN: r31708 --- libjava/ChangeLog | 18 +++ libjava/Makefile.am | 3 + libjava/Makefile.in | 65 +++------ libjava/acconfig.h | 3 + libjava/configure | 2 +- libjava/configure.in | 2 +- libjava/gnu/gcj/convert/BytesToUnicode.java | 13 +- libjava/gnu/gcj/convert/Input_iconv.java | 42 ++++++ libjava/gnu/gcj/convert/Output_iconv.java | 42 ++++++ libjava/gnu/gcj/convert/UnicodeToBytes.java | 15 ++- libjava/gnu/gcj/convert/natIconv.cc | 142 ++++++++++++++++++++ libjava/include/config.h.in | 3 + 12 files changed, 295 insertions(+), 55 deletions(-) create mode 100644 libjava/gnu/gcj/convert/Input_iconv.java create mode 100644 libjava/gnu/gcj/convert/Output_iconv.java create mode 100644 libjava/gnu/gcj/convert/natIconv.cc diff --git a/libjava/ChangeLog b/libjava/ChangeLog index f6883b266bca..1484947d8672 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,21 @@ +2000-01-30 Tom Tromey + + * include/config.h.in: Rebuilt. + * acconfig.h (HAVE_ICONV): Define. + * configure: Rebuilt. + * configure.in: Check for `iconv' function. + * gnu/gcj/convert/BytesToUnicode.java (getDecoder): Try iconv if + no specific encoder exists. + * gnu/gcj/convert/UnicodeToBytes.java (getEncoder): Try iconv if + no specific encoder exists. + * Makefile.in: Rebuilt. + * Makefile.am (convert_source_files): Mention Input_iconv.java and + Output_iconv.java. + (nat_source_files): Added natIconv.cc. + * gnu/gcj/convert/natIconv.cc: New file. + * gnu/gcj/convert/Input_iconv.java: New file. + * gnu/gcj/convert/Output_iconv.java: New file. + 2000-01-28 Tom Tromey * Makefile.in: Rebuilt. diff --git a/libjava/Makefile.am b/libjava/Makefile.am index 8b1143babab3..0c02d9e32b71 100644 --- a/libjava/Makefile.am +++ b/libjava/Makefile.am @@ -447,11 +447,13 @@ gnu/gcj/convert/Input_EUCJIS.java \ gnu/gcj/convert/Input_JavaSrc.java \ gnu/gcj/convert/Input_SJIS.java \ gnu/gcj/convert/Input_UTF8.java \ +gnu/gcj/convert/Input_iconv.java \ gnu/gcj/convert/Output_8859_1.java \ gnu/gcj/convert/Output_EUCJIS.java \ gnu/gcj/convert/Output_JavaSrc.java \ gnu/gcj/convert/Output_SJIS.java \ gnu/gcj/convert/Output_UTF8.java \ +gnu/gcj/convert/Output_iconv.java \ gnu/gcj/convert/UnicodeToBytes.java ## List of all .java files for which the .h file is maintained by @@ -787,6 +789,7 @@ nat_source_files = \ gnu/gcj/convert/JIS0208_to_Unicode.cc \ gnu/gcj/convert/JIS0212_to_Unicode.cc \ gnu/gcj/convert/Unicode_to_JIS.cc \ +gnu/gcj/convert/natIconv.cc \ gnu/gcj/convert/natInput_EUCJIS.cc \ gnu/gcj/convert/natInput_SJIS.cc \ gnu/gcj/convert/natOutput_EUCJIS.cc \ diff --git a/libjava/Makefile.in b/libjava/Makefile.in index 2943f2036379..c53bb53d4268 100644 --- a/libjava/Makefile.in +++ b/libjava/Makefile.in @@ -267,11 +267,13 @@ gnu/gcj/convert/Input_EUCJIS.java \ gnu/gcj/convert/Input_JavaSrc.java \ gnu/gcj/convert/Input_SJIS.java \ gnu/gcj/convert/Input_UTF8.java \ +gnu/gcj/convert/Input_iconv.java \ gnu/gcj/convert/Output_8859_1.java \ gnu/gcj/convert/Output_EUCJIS.java \ gnu/gcj/convert/Output_JavaSrc.java \ gnu/gcj/convert/Output_SJIS.java \ gnu/gcj/convert/Output_UTF8.java \ +gnu/gcj/convert/Output_iconv.java \ gnu/gcj/convert/UnicodeToBytes.java @@ -601,6 +603,7 @@ nat_source_files = \ gnu/gcj/convert/JIS0208_to_Unicode.cc \ gnu/gcj/convert/JIS0212_to_Unicode.cc \ gnu/gcj/convert/Unicode_to_JIS.cc \ +gnu/gcj/convert/natIconv.cc \ gnu/gcj/convert/natInput_EUCJIS.cc \ gnu/gcj/convert/natInput_SJIS.cc \ gnu/gcj/convert/natOutput_EUCJIS.cc \ @@ -725,8 +728,7 @@ LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ DATA = $(data_DATA) $(toolexeclib_DATA) DIST_COMMON = README COPYING.LIB ChangeLog Makefile.am Makefile.in NEWS \ -THANKS acconfig.h acinclude.m4 aclocal.m4 configure configure.in \ -include/config.h.in include/stamp-h.in libgcj.spec.in +THANKS acinclude.m4 aclocal.m4 configure configure.in libgcj.spec.in DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) @@ -742,10 +744,12 @@ DEP_FILES = .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \ .deps/gnu/gcj/convert/Input_EUCJIS.P \ .deps/gnu/gcj/convert/Input_JavaSrc.P \ .deps/gnu/gcj/convert/Input_SJIS.P .deps/gnu/gcj/convert/Input_UTF8.P \ +.deps/gnu/gcj/convert/Input_iconv.P \ .deps/gnu/gcj/convert/Output_8859_1.P \ .deps/gnu/gcj/convert/Output_EUCJIS.P \ .deps/gnu/gcj/convert/Output_JavaSrc.P \ .deps/gnu/gcj/convert/Output_SJIS.P .deps/gnu/gcj/convert/Output_UTF8.P \ +.deps/gnu/gcj/convert/Output_iconv.P \ .deps/gnu/gcj/convert/UnicodeToBytes.P \ .deps/gnu/gcj/protocol/file/Connection.P \ .deps/gnu/gcj/protocol/file/Handler.P \ @@ -949,34 +953,6 @@ config.status: $(srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) $(SHELL) ./config.status --recheck $(srcdir)/configure: @MAINTAINER_MODE_TRUE@$(srcdir)/configure.in $(ACLOCAL_M4) $(CONFIGURE_DEPENDENCIES) cd $(srcdir) && $(AUTOCONF) - -include/config.h: include/stamp-h - @if test ! -f $@; then \ - rm -f include/stamp-h; \ - $(MAKE) include/stamp-h; \ - else :; fi -include/stamp-h: $(srcdir)/include/config.h.in $(top_builddir)/config.status - cd $(top_builddir) \ - && CONFIG_FILES= CONFIG_HEADERS=include/config.h \ - $(SHELL) ./config.status - @echo timestamp > include/stamp-h 2> /dev/null -$(srcdir)/include/config.h.in: @MAINTAINER_MODE_TRUE@$(srcdir)/include/stamp-h.in - @if test ! -f $@; then \ - rm -f $(srcdir)/include/stamp-h.in; \ - $(MAKE) $(srcdir)/include/stamp-h.in; \ - else :; fi -$(srcdir)/include/stamp-h.in: $(top_srcdir)/configure.in $(ACLOCAL_M4) acconfig.h - cd $(top_srcdir) && $(AUTOHEADER) - @echo timestamp > $(srcdir)/include/stamp-h.in 2> /dev/null - -mostlyclean-hdr: - -clean-hdr: - -distclean-hdr: - -rm -f include/config.h - -maintainer-clean-hdr: libgcj.spec: $(top_builddir)/config.status libgcj.spec.in cd $(top_builddir) && CONFIG_FILES=$@ CONFIG_HEADERS= $(SHELL) ./config.status @@ -1415,33 +1391,31 @@ distclean-generic: -rm -f config.cache config.log stamp-h stamp-h[0-9]* maintainer-clean-generic: -mostlyclean-am: mostlyclean-hdr mostlyclean-toolexeclibLIBRARIES \ - mostlyclean-compile mostlyclean-libtool \ - mostlyclean-toolexeclibLTLIBRARIES \ +mostlyclean-am: mostlyclean-toolexeclibLIBRARIES mostlyclean-compile \ + mostlyclean-libtool mostlyclean-toolexeclibLTLIBRARIES \ mostlyclean-binPROGRAMS mostlyclean-noinstPROGRAMS \ mostlyclean-tags mostlyclean-depend mostlyclean-generic mostlyclean: mostlyclean-recursive -clean-am: clean-hdr clean-toolexeclibLIBRARIES clean-compile \ - clean-libtool clean-toolexeclibLTLIBRARIES \ - clean-binPROGRAMS clean-noinstPROGRAMS clean-tags \ - clean-depend clean-generic mostlyclean-am clean-local +clean-am: clean-toolexeclibLIBRARIES clean-compile clean-libtool \ + clean-toolexeclibLTLIBRARIES clean-binPROGRAMS \ + clean-noinstPROGRAMS clean-tags clean-depend \ + clean-generic mostlyclean-am clean-local clean: clean-recursive -distclean-am: distclean-hdr distclean-toolexeclibLIBRARIES \ - distclean-compile distclean-libtool \ - distclean-toolexeclibLTLIBRARIES distclean-binPROGRAMS \ - distclean-noinstPROGRAMS distclean-tags \ - distclean-depend distclean-generic clean-am +distclean-am: distclean-toolexeclibLIBRARIES distclean-compile \ + distclean-libtool distclean-toolexeclibLTLIBRARIES \ + distclean-binPROGRAMS distclean-noinstPROGRAMS \ + distclean-tags distclean-depend distclean-generic \ + clean-am -rm -f libtool distclean: distclean-recursive -rm -f config.status -maintainer-clean-am: maintainer-clean-hdr \ - maintainer-clean-toolexeclibLIBRARIES \ +maintainer-clean-am: maintainer-clean-toolexeclibLIBRARIES \ maintainer-clean-compile maintainer-clean-libtool \ maintainer-clean-toolexeclibLTLIBRARIES \ maintainer-clean-binPROGRAMS \ @@ -1454,8 +1428,7 @@ maintainer-clean-am: maintainer-clean-hdr \ maintainer-clean: maintainer-clean-recursive -rm -f config.status -.PHONY: mostlyclean-hdr distclean-hdr clean-hdr maintainer-clean-hdr \ -mostlyclean-toolexeclibLIBRARIES distclean-toolexeclibLIBRARIES \ +.PHONY: mostlyclean-toolexeclibLIBRARIES distclean-toolexeclibLIBRARIES \ clean-toolexeclibLIBRARIES maintainer-clean-toolexeclibLIBRARIES \ uninstall-toolexeclibLIBRARIES install-toolexeclibLIBRARIES \ mostlyclean-compile distclean-compile clean-compile \ diff --git a/libjava/acconfig.h b/libjava/acconfig.h index 8a739831eb3d..a3a2ea22a2a5 100644 --- a/libjava/acconfig.h +++ b/libjava/acconfig.h @@ -134,3 +134,6 @@ /* Define if g++ has a bug preventing us from inlining math routines. */ #undef __NO_MATH_INLINES + +/* Define if you have working iconv() function. */ +#undef HAVE_ICONV diff --git a/libjava/configure b/libjava/configure index b015a69ca07c..86d0c123c602 100755 --- a/libjava/configure +++ b/libjava/configure @@ -2741,7 +2741,7 @@ else fi done - for ac_func in access stat mkdir rename rmdir unlink realpath + for ac_func in access stat mkdir rename rmdir unlink realpath iconv do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 echo "configure:2748: checking for $ac_func" >&5 diff --git a/libjava/configure.in b/libjava/configure.in index e8f17e87b81c..fb52c43a2a61 100644 --- a/libjava/configure.in +++ b/libjava/configure.in @@ -372,7 +372,7 @@ if test -n "${with_cross_host}"; then else AC_CHECK_FUNCS(strerror ioctl select fstat open fsync sleep) AC_CHECK_FUNCS(gmtime_r localtime_r readdir_r getpwuid_r getcwd) - AC_CHECK_FUNCS(access stat mkdir rename rmdir unlink realpath) + AC_CHECK_FUNCS(access stat mkdir rename rmdir unlink realpath iconv) AC_CHECK_FUNCS(inet_aton inet_addr, break) AC_CHECK_FUNCS(inet_pton uname inet_ntoa) AC_CHECK_FUNCS(backtrace fork execvp pipe) diff --git a/libjava/gnu/gcj/convert/BytesToUnicode.java b/libjava/gnu/gcj/convert/BytesToUnicode.java index e5302b73f215..1d96409f372b 100644 --- a/libjava/gnu/gcj/convert/BytesToUnicode.java +++ b/libjava/gnu/gcj/convert/BytesToUnicode.java @@ -1,4 +1,4 @@ -/* Copyright (C) 1999 Red Hat, Inc. +/* Copyright (C) 1999, 2000 Red Hat, Inc. This file is part of libgcj. @@ -69,8 +69,15 @@ public abstract class BytesToUnicode } catch (Throwable ex) { - throw new java.io.UnsupportedEncodingException(encoding - + " (" + ex + ')'); + try + { + return new Input_iconv (encoding); + } + catch (Throwable _) + { + throw new java.io.UnsupportedEncodingException(encoding + + " (" + ex + ')'); + } } } diff --git a/libjava/gnu/gcj/convert/Input_iconv.java b/libjava/gnu/gcj/convert/Input_iconv.java new file mode 100644 index 000000000000..7b5fb03a54bf --- /dev/null +++ b/libjava/gnu/gcj/convert/Input_iconv.java @@ -0,0 +1,42 @@ +// Input_iconv.java -- Java side of iconv() reader. + +/* Copyright (C) 2000 Red Hat, Inc. + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.gcj.convert; +import gnu.gcj.RawData; +import java.io.UnsupportedEncodingException; + +/** + * Convert bytes in some iconv-supported encoding to Unicode. + * @author Tom Tromey + * @date January 30, 2000 + */ + +public class Input_iconv extends BytesToUnicode +{ + public Input_iconv (String encoding) throws UnsupportedEncodingException + { + this.encoding = encoding; + this.handle = null; + init (encoding); + } + + public String getName() { return encoding; } + + public native void finalize (); + private native void init (String encoding) + throws UnsupportedEncodingException; + public native int read (char[] outbuffer, int outpos, int count); + + // The encoding we're using. + private String encoding; + + // The iconv handle. + private RawData handle; +} diff --git a/libjava/gnu/gcj/convert/Output_iconv.java b/libjava/gnu/gcj/convert/Output_iconv.java new file mode 100644 index 000000000000..386028aee111 --- /dev/null +++ b/libjava/gnu/gcj/convert/Output_iconv.java @@ -0,0 +1,42 @@ +// Output_iconv.java -- Java side of iconv() writer. + +/* Copyright (C) 2000 Red Hat, Inc. + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.gcj.convert; +import gnu.gcj.RawData; +import java.io.UnsupportedEncodingException; + +/** + * Convert Unicode to bytes in some iconv-supported encoding. + * @author Tom Tromey + * @date January 30, 2000 + */ + +public class Output_iconv extends UnicodeToBytes +{ + public Output_iconv (String encoding) throws UnsupportedEncodingException + { + this.encoding = encoding; + this.handle = null; + init (encoding); + } + + public String getName() { return encoding; } + + public native void finalize (); + private native void init (String encoding) + throws UnsupportedEncodingException; + public native int write (char[] inbuffer, int inpos, int count); + + // The encoding we're using. + private String encoding; + + // The iconv handle. + private RawData handle; +} diff --git a/libjava/gnu/gcj/convert/UnicodeToBytes.java b/libjava/gnu/gcj/convert/UnicodeToBytes.java index 5a33003d6bc6..b91a8cc8489d 100644 --- a/libjava/gnu/gcj/convert/UnicodeToBytes.java +++ b/libjava/gnu/gcj/convert/UnicodeToBytes.java @@ -1,4 +1,4 @@ -/* Copyright (C) 1999 Red Hat, Inc. +/* Copyright (C) 1999, 2000 Red Hat, Inc. This file is part of libgcj. @@ -67,8 +67,16 @@ public abstract class UnicodeToBytes } catch (Throwable ex) { - throw new java.io.UnsupportedEncodingException(encoding + " (" - + ex + ')'); + try + { + return new Output_iconv (encoding); + } + catch (Throwable _) + { + // Put the original exception in the throwable. + throw new java.io.UnsupportedEncodingException(encoding + " (" + + ex + ')'); + } } } @@ -105,5 +113,4 @@ public abstract class UnicodeToBytes str.getChars(inpos, srcEnd, work, 0); return write(work, inpos, inlength); } - } diff --git a/libjava/gnu/gcj/convert/natIconv.cc b/libjava/gnu/gcj/convert/natIconv.cc new file mode 100644 index 000000000000..129db7ecf053 --- /dev/null +++ b/libjava/gnu/gcj/convert/natIconv.cc @@ -0,0 +1,142 @@ +// Input_iconv.java -- Java side of iconv() reader. + +/* Copyright (C) 2000 Red Hat, Inc. + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +/* Author: Tom Tromey . */ + +#include + +#include +#include + +#include +#include +#include + +#ifdef HAVE_ICONV +#include +#endif + +void +gnu::gcj::convert::Input_iconv::init (jstring encoding) +{ +#ifdef HAVE_ICONV + jsize len = _Jv_GetStringUTFLength (encoding); + char buffer[len]; + _Jv_GetStringUTFRegion (encoding, 0, len, buffer); + + iconv_t h = iconv_open ("UCS-2", buffer); + if (h == (iconv_t) -1) + JvThrow (new java::io::UnsupportedEncodingException); + + JvAssert (h != NULL); + handle = reinterpret_cast (h); +#else /* HAVE_ICONV */ + // If no iconv, just throw an exception. + JvThrow (new java::io::UnsupportedEncodingException); +#endif /* HAVE_ICONV */ +} + +void +gnu::gcj::convert::Input_iconv::finalize (void) +{ +#ifdef HAVE_ICONV + if (handle == NULL) + { + iconv_close ((iconv_t) handle); + handle = NULL; + } +#endif /* HAVE_ICONV */ +} + +jint +gnu::gcj::convert::Input_iconv::read (jcharArray outbuffer, + jint outpos, jint count) +{ +#ifdef HAVE_ICONV + jint origpos = outpos; + + jbyte *bytes = elements (inbuffer); + jchar *out = elements (outbuffer); + size_t inavail = inlength - inpos; + size_t old_in = inavail; + size_t outavail = count; + size_t old_out = outavail; + + size_t r = iconv ((iconv_t) handle, + &bytes[inpos], &inavail, + &out[outpos], &outavail); + // FIXME: what if R==-1? + + inpos += old_in - inavail; + return old_out - outavail; +#else /* HAVE_ICONV */ + return -1; +#endif /* HAVE_ICONV */ +} + +void +gnu::gcj::convert::Output_iconv::init (jstring encoding) +{ +#ifdef HAVE_ICONV + jsize len = _Jv_GetStringUTFLength (encoding); + char buffer[len]; + _Jv_GetStringUTFRegion (encoding, 0, len, buffer); + + iconv_t h = iconv_open (buffer, "UCS-2"); + if (h == (iconv_t) -1) + JvThrow (new java::io::UnsupportedEncodingException); + + JvAssert (h != NULL); + handle = reinterpret_cast (h); +#else /* HAVE_ICONV */ + // If no iconv, just throw an exception. + JvThrow (new java::io::UnsupportedEncodingException); +#endif /* HAVE_ICONV */ +} + +void +gnu::gcj::convert::Output_iconv::finalize (void) +{ +#ifdef HAVE_ICONV + if (handle == NULL) + { + iconv_close ((iconv_t) handle); + handle = NULL; + } +#endif /* HAVE_ICONV */ +} + +jint +gnu::gcj::convert::Output_iconv::write (jcharArray inbuffer, + jint inpos, jint count) +{ +#ifdef HAVE_ICONV + jint origpos = outpos; + + jchar *chars = elements (inbuffer); + jbyte *out = elements (buf); + + size_t inavail = count; + size_t old_in = count; + + size_t outavail = buf->length - count; + size_t old_out = outavail; + + size_t r = iconv ((iconv_t) handle, + &chars[inpos], &inavail, + &out[count], &outavail); + // FIXME: what if R==-1? + + count += old_out - outavail; + return old_in - inavail; +#else /* HAVE_ICONV */ + return -1; +#endif /* HAVE_ICONV */ +} diff --git a/libjava/include/config.h.in b/libjava/include/config.h.in index de926858e4ae..42740c4a17e6 100644 --- a/libjava/include/config.h.in +++ b/libjava/include/config.h.in @@ -194,6 +194,9 @@ /* Define if you have the gmtime_r function. */ #undef HAVE_GMTIME_R +/* Define if you have the iconv function. */ +#undef HAVE_ICONV + /* Define if you have the inet_addr function. */ #undef HAVE_INET_ADDR