From 554fd8c5195424bdbcabf5de30fdc183aba391bd Mon Sep 17 00:00:00 2001 From: upstream source tree Date: Sun, 15 Mar 2015 20:14:05 -0400 Subject: obtained gcc-4.6.4.tar.bz2 from upstream website; verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository. --- libjava/classpath/native/.cvsignore | 8 + libjava/classpath/native/Makefile.am | 17 + libjava/classpath/native/Makefile.in | 589 +++++ libjava/classpath/native/fdlibm/.cvsignore | 8 + libjava/classpath/native/fdlibm/Makefile.am | 65 + libjava/classpath/native/fdlibm/Makefile.in | 674 +++++ libjava/classpath/native/fdlibm/dtoa.c | 921 +++++++ libjava/classpath/native/fdlibm/e_acos.c | 110 + libjava/classpath/native/fdlibm/e_asin.c | 119 + libjava/classpath/native/fdlibm/e_atan2.c | 131 + libjava/classpath/native/fdlibm/e_cosh.c | 92 + libjava/classpath/native/fdlibm/e_exp.c | 165 ++ libjava/classpath/native/fdlibm/e_fmod.c | 139 ++ libjava/classpath/native/fdlibm/e_hypot.c | 129 + libjava/classpath/native/fdlibm/e_log.c | 151 ++ libjava/classpath/native/fdlibm/e_log10.c | 93 + libjava/classpath/native/fdlibm/e_pow.c | 312 +++ libjava/classpath/native/fdlibm/e_rem_pio2.c | 185 ++ libjava/classpath/native/fdlibm/e_remainder.c | 79 + libjava/classpath/native/fdlibm/e_scalb.c | 51 + libjava/classpath/native/fdlibm/e_sinh.c | 85 + libjava/classpath/native/fdlibm/e_sqrt.c | 451 ++++ libjava/classpath/native/fdlibm/fdlibm.h | 408 +++ libjava/classpath/native/fdlibm/ieeefp.h | 170 ++ libjava/classpath/native/fdlibm/k_cos.c | 95 + libjava/classpath/native/fdlibm/k_rem_pio2.c | 316 +++ libjava/classpath/native/fdlibm/k_sin.c | 78 + libjava/classpath/native/fdlibm/k_tan.c | 153 ++ libjava/classpath/native/fdlibm/mprec.c | 1021 ++++++++ libjava/classpath/native/fdlibm/mprec.h | 387 +++ libjava/classpath/native/fdlibm/namespace.h | 3 + libjava/classpath/native/fdlibm/s_atan.c | 140 ++ libjava/classpath/native/fdlibm/s_cbrt.c | 96 + libjava/classpath/native/fdlibm/s_ceil.c | 80 + libjava/classpath/native/fdlibm/s_copysign.c | 37 + libjava/classpath/native/fdlibm/s_cos.c | 81 + libjava/classpath/native/fdlibm/s_expm1.c | 229 ++ libjava/classpath/native/fdlibm/s_fabs.c | 36 + libjava/classpath/native/fdlibm/s_finite.c | 31 + libjava/classpath/native/fdlibm/s_floor.c | 80 + libjava/classpath/native/fdlibm/s_log1p.c | 168 ++ libjava/classpath/native/fdlibm/s_rint.c | 86 + libjava/classpath/native/fdlibm/s_scalbn.c | 65 + libjava/classpath/native/fdlibm/s_sin.c | 81 + libjava/classpath/native/fdlibm/s_tan.c | 75 + libjava/classpath/native/fdlibm/s_tanh.c | 85 + libjava/classpath/native/fdlibm/sf_fabs.c | 47 + libjava/classpath/native/fdlibm/sf_rint.c | 80 + libjava/classpath/native/fdlibm/strtod.c | 719 ++++++ libjava/classpath/native/fdlibm/w_acos.c | 39 + libjava/classpath/native/fdlibm/w_asin.c | 41 + libjava/classpath/native/fdlibm/w_atan2.c | 40 + libjava/classpath/native/fdlibm/w_cosh.c | 38 + libjava/classpath/native/fdlibm/w_exp.c | 48 + libjava/classpath/native/fdlibm/w_fmod.c | 39 + libjava/classpath/native/fdlibm/w_hypot.c | 39 + libjava/classpath/native/fdlibm/w_log.c | 39 + libjava/classpath/native/fdlibm/w_log10.c | 42 + libjava/classpath/native/fdlibm/w_pow.c | 60 + libjava/classpath/native/fdlibm/w_remainder.c | 38 + libjava/classpath/native/fdlibm/w_sinh.c | 38 + libjava/classpath/native/fdlibm/w_sqrt.c | 38 + libjava/classpath/native/jawt/.cvsignore | 8 + libjava/classpath/native/jawt/Makefile.am | 13 + libjava/classpath/native/jawt/Makefile.in | 615 +++++ libjava/classpath/native/jawt/jawt.c | 188 ++ libjava/classpath/native/jni/.cvsignore | 8 + libjava/classpath/native/jni/Makefile.am | 47 + libjava/classpath/native/jni/Makefile.in | 604 +++++ libjava/classpath/native/jni/classpath/.cvsignore | 8 + libjava/classpath/native/jni/classpath/Makefile.am | 12 + libjava/classpath/native/jni/classpath/Makefile.in | 564 +++++ .../native/jni/classpath/classpath_jawt.h | 61 + libjava/classpath/native/jni/classpath/jcl.c | 274 ++ libjava/classpath/native/jni/classpath/jcl.h | 94 + libjava/classpath/native/jni/classpath/jnilink.c | 125 + libjava/classpath/native/jni/classpath/jnilink.h | 82 + libjava/classpath/native/jni/gconf-peer/.cvsignore | 6 + .../native/jni/gconf-peer/GConfNativePeer.c | 617 +++++ .../classpath/native/jni/gconf-peer/Makefile.am | 14 + .../classpath/native/jni/gconf-peer/Makefile.in | 612 +++++ .../native/jni/gstreamer-peer/Makefile.am | 29 + .../native/jni/gstreamer-peer/Makefile.in | 637 +++++ .../native/jni/gstreamer-peer/gst_classpath_src.c | 408 +++ .../native/jni/gstreamer-peer/gst_classpath_src.h | 88 + .../native/jni/gstreamer-peer/gst_input_stream.c | 290 +++ .../native/jni/gstreamer-peer/gst_input_stream.h | 71 + .../jni/gstreamer-peer/gst_native_data_line.c | 251 ++ .../jni/gstreamer-peer/gst_native_pipeline.c | 611 +++++ .../jni/gstreamer-peer/gst_native_pipeline.h | 63 + .../classpath/native/jni/gstreamer-peer/gst_peer.c | 83 + .../classpath/native/jni/gstreamer-peer/gst_peer.h | 59 + .../native/jni/gstreamer-peer/gstreamer_io_peer.c | 739 ++++++ libjava/classpath/native/jni/gtk-peer/.cvsignore | 8 + .../native/jni/gtk-peer/GtkDragSourceContextPeer.c | 330 +++ libjava/classpath/native/jni/gtk-peer/Makefile.am | 61 + libjava/classpath/native/jni/gtk-peer/Makefile.in | 743 ++++++ .../native/jni/gtk-peer/cairographics2d.h | 116 + libjava/classpath/native/jni/gtk-peer/gdkdisplay.h | 43 + libjava/classpath/native/jni/gtk-peer/gdkfont.h | 105 + .../gnu_java_awt_peer_gtk_CairoGraphics2D.c | 749 ++++++ .../gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c | 333 +++ .../gnu_java_awt_peer_gtk_ComponentGraphics.c | 295 +++ .../gnu_java_awt_peer_gtk_ComponentGraphicsCopy.c | 129 + .../gnu_java_awt_peer_gtk_FreetypeGlyphVector.c | 449 ++++ .../gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c | 370 +++ .../gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.c | 299 +++ .../gnu_java_awt_peer_gtk_GdkPixbufDecoder.c | 470 ++++ .../gtk-peer/gnu_java_awt_peer_gtk_GdkRobotPeer.c | 430 ++++ ...gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice.c | 351 +++ .../gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c | 376 +++ .../gtk-peer/gnu_java_awt_peer_gtk_GtkCanvasPeer.c | 58 + ...gnu_java_awt_peer_gtk_GtkCheckboxMenuItemPeer.c | 78 + .../gnu_java_awt_peer_gtk_GtkCheckboxPeer.c | 407 +++ .../gtk-peer/gnu_java_awt_peer_gtk_GtkChoicePeer.c | 237 ++ .../gtk-peer/gnu_java_awt_peer_gtk_GtkClipboard.c | 422 ++++ .../gnu_java_awt_peer_gtk_GtkComponentPeer.c | 1260 ++++++++++ .../gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer.c | 84 + .../gnu_java_awt_peer_gtk_GtkFileDialogPeer.c | 302 +++ .../gtk-peer/gnu_java_awt_peer_gtk_GtkFramePeer.c | 234 ++ .../gnu_java_awt_peer_gtk_GtkGenericPeer.c | 100 + .../jni/gtk-peer/gnu_java_awt_peer_gtk_GtkImage.c | 434 ++++ .../gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c | 221 ++ .../gtk-peer/gnu_java_awt_peer_gtk_GtkListPeer.c | 549 ++++ .../gnu_java_awt_peer_gtk_GtkMenuBarPeer.c | 92 + .../gnu_java_awt_peer_gtk_GtkMenuComponentPeer.c | 55 + .../gnu_java_awt_peer_gtk_GtkMenuItemPeer.c | 191 ++ .../gtk-peer/gnu_java_awt_peer_gtk_GtkMenuPeer.c | 176 ++ .../gtk-peer/gnu_java_awt_peer_gtk_GtkPanelPeer.c | 112 + .../gnu_java_awt_peer_gtk_GtkPopupMenuPeer.c | 105 + .../gnu_java_awt_peer_gtk_GtkScrollPanePeer.c | 222 ++ .../gnu_java_awt_peer_gtk_GtkScrollbarPeer.c | 296 +++ .../gtk-peer/gnu_java_awt_peer_gtk_GtkSelection.c | 489 ++++ .../gnu_java_awt_peer_gtk_GtkTextAreaPeer.c | 547 ++++ .../gnu_java_awt_peer_gtk_GtkTextFieldPeer.c | 388 +++ .../gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c | 626 +++++ .../gnu_java_awt_peer_gtk_GtkVolatileImage.c | 204 ++ .../gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c | 2164 ++++++++++++++++ libjava/classpath/native/jni/gtk-peer/gtk_jawt.c | 203 ++ libjava/classpath/native/jni/gtk-peer/gtkpeer.c | 586 +++++ libjava/classpath/native/jni/gtk-peer/gtkpeer.h | 360 +++ libjava/classpath/native/jni/java-io/.cvsignore | 8 + libjava/classpath/native/jni/java-io/Makefile.am | 13 + libjava/classpath/native/jni/java-io/Makefile.in | 617 +++++ .../classpath/native/jni/java-io/java_io_VMFile.c | 1214 +++++++++ .../jni/java-io/java_io_VMObjectInputStream.c | 69 + .../jni/java-io/java_io_VMObjectStreamClass.c | 381 +++ libjava/classpath/native/jni/java-lang/.cvsignore | 8 + libjava/classpath/native/jni/java-lang/Makefile.am | 20 + libjava/classpath/native/jni/java-lang/Makefile.in | 642 +++++ ...a_lang_management_VMOperatingSystemMXBeanImpl.c | 65 + .../native/jni/java-lang/java_lang_VMDouble.c | 455 ++++ .../native/jni/java-lang/java_lang_VMFloat.c | 71 + .../native/jni/java-lang/java_lang_VMMath.c | 225 ++ .../native/jni/java-lang/java_lang_VMProcess.c | 409 +++ .../native/jni/java-lang/java_lang_VMSystem.c | 189 ++ .../jni/java-lang/java_lang_reflect_VMArray.c | 62 + libjava/classpath/native/jni/java-math/Makefile.am | 11 + libjava/classpath/native/jni/java-math/Makefile.in | 610 +++++ .../native/jni/java-math/gnu_java_math_GMP.c | 1396 +++++++++++ libjava/classpath/native/jni/java-net/.cvsignore | 8 + libjava/classpath/native/jni/java-net/Makefile.am | 26 + libjava/classpath/native/jni/java-net/Makefile.in | 637 +++++ .../jni/java-net/gnu_java_net_VMPlainSocketImpl.c | 965 ++++++++ .../java-net/gnu_java_net_local_LocalSocketImpl.c | 517 ++++ .../native/jni/java-net/java_net_VMInetAddress.c | 395 +++ .../jni/java-net/java_net_VMNetworkInterface.c | 399 +++ .../native/jni/java-net/java_net_VMURLConnection.c | 102 + libjava/classpath/native/jni/java-net/javanet.c | 1500 +++++++++++ libjava/classpath/native/jni/java-net/javanet.h | 101 + libjava/classpath/native/jni/java-net/local.c | 189 ++ libjava/classpath/native/jni/java-net/local.h | 28 + libjava/classpath/native/jni/java-nio/.cvsignore | 8 + libjava/classpath/native/jni/java-nio/Makefile.am | 24 + libjava/classpath/native/jni/java-nio/Makefile.in | 642 +++++ .../jni/java-nio/gnu_java_nio_EpollSelectorImpl.c | 416 ++++ .../jni/java-nio/gnu_java_nio_KqueueSelectorImpl.c | 387 +++ .../native/jni/java-nio/gnu_java_nio_VMChannel.c | 2035 +++++++++++++++ .../native/jni/java-nio/gnu_java_nio_VMPipe.c | 83 + .../native/jni/java-nio/gnu_java_nio_VMSelector.c | 303 +++ .../gnu_java_nio_charset_iconv_IconvDecoder.c | 208 ++ .../gnu_java_nio_charset_iconv_IconvEncoder.c | 208 ++ .../jni/java-nio/java_nio_MappedByteBufferImpl.c | 241 ++ .../jni/java-nio/java_nio_VMDirectByteBuffer.c | 130 + libjava/classpath/native/jni/java-nio/javanio.c | 144 ++ libjava/classpath/native/jni/java-nio/javanio.h | 334 +++ libjava/classpath/native/jni/java-util/.cvsignore | 8 + libjava/classpath/native/jni/java-util/Makefile.am | 9 + libjava/classpath/native/jni/java-util/Makefile.in | 606 +++++ .../native/jni/java-util/java_util_VMTimeZone.c | 223 ++ libjava/classpath/native/jni/midi-alsa/.cvsignore | 9 + libjava/classpath/native/jni/midi-alsa/Makefile.am | 13 + libjava/classpath/native/jni/midi-alsa/Makefile.in | 619 +++++ ..._javax_sound_midi_alsa_AlsaMidiDeviceProvider.c | 148 ++ ...javax_sound_midi_alsa_AlsaMidiSequencerDevice.c | 59 + .../gnu_javax_sound_midi_alsa_AlsaPortDevice.c | 149 ++ libjava/classpath/native/jni/midi-dssi/.cvsignore | 9 + libjava/classpath/native/jni/midi-dssi/Makefile.am | 15 + libjava/classpath/native/jni/midi-dssi/Makefile.in | 619 +++++ libjava/classpath/native/jni/midi-dssi/README | 134 + libjava/classpath/native/jni/midi-dssi/dssi_data.h | 114 + ..._javax_sound_midi_dssi_DSSIMidiDeviceProvider.c | 139 ++ .../gnu_javax_sound_midi_dssi_DSSISynthesizer.c | 584 +++++ libjava/classpath/native/jni/native-lib/.cvsignore | 8 + .../classpath/native/jni/native-lib/Makefile.am | 13 + .../classpath/native/jni/native-lib/Makefile.in | 567 +++++ libjava/classpath/native/jni/native-lib/cpio.c | 592 +++++ libjava/classpath/native/jni/native-lib/cpio.h | 99 + libjava/classpath/native/jni/native-lib/cpnative.h | 49 + libjava/classpath/native/jni/native-lib/cpnet.c | 818 ++++++ libjava/classpath/native/jni/native-lib/cpnet.h | 221 ++ libjava/classpath/native/jni/native-lib/cpproc.c | 141 ++ libjava/classpath/native/jni/native-lib/cpproc.h | 52 + libjava/classpath/native/jni/qt-peer/.cvsignore | 9 + libjava/classpath/native/jni/qt-peer/Makefile.am | 85 + libjava/classpath/native/jni/qt-peer/Makefile.in | 703 ++++++ libjava/classpath/native/jni/qt-peer/buttonevent.h | 27 + .../native/jni/qt-peer/componentevent.cpp | 223 ++ .../classpath/native/jni/qt-peer/componentevent.h | 203 ++ libjava/classpath/native/jni/qt-peer/containers.h | 10 + .../classpath/native/jni/qt-peer/eventmethods.h | 245 ++ .../classpath/native/jni/qt-peer/keybindings.cpp | 600 +++++ libjava/classpath/native/jni/qt-peer/keybindings.h | 20 + .../classpath/native/jni/qt-peer/mainqtthread.cpp | 104 + .../native/jni/qt-peer/mainthreadinterface.cpp | 69 + .../native/jni/qt-peer/mainthreadinterface.h | 36 + .../classpath/native/jni/qt-peer/nativewrapper.cpp | 64 + .../classpath/native/jni/qt-peer/nativewrapper.h | 10 + libjava/classpath/native/jni/qt-peer/qmatrix.cpp | 96 + .../classpath/native/jni/qt-peer/qpainterpath.cpp | 239 ++ libjava/classpath/native/jni/qt-peer/qpen.cpp | 108 + .../classpath/native/jni/qt-peer/qtaudioclip.cpp | 114 + .../classpath/native/jni/qt-peer/qtbuttonpeer.cpp | 94 + .../classpath/native/jni/qt-peer/qtcanvaspeer.cpp | 75 + .../native/jni/qt-peer/qtcheckboxpeer.cpp | 164 ++ .../classpath/native/jni/qt-peer/qtchoicepeer.cpp | 142 ++ .../classpath/native/jni/qt-peer/qtcomponent.cpp | 122 + libjava/classpath/native/jni/qt-peer/qtcomponent.h | 16 + .../native/jni/qt-peer/qtcomponentpeer.cpp | 384 +++ .../classpath/native/jni/qt-peer/qtdialogpeer.cpp | 164 ++ .../native/jni/qt-peer/qtembeddedwindowpeer.cpp | 113 + .../native/jni/qt-peer/qtfiledialogpeer.cpp | 101 + libjava/classpath/native/jni/qt-peer/qtfont.h | 8 + .../classpath/native/jni/qt-peer/qtfontmetrics.cpp | 233 ++ .../classpath/native/jni/qt-peer/qtfontpeer.cpp | 92 + .../classpath/native/jni/qt-peer/qtframepeer.cpp | 205 ++ .../classpath/native/jni/qt-peer/qtgraphics.cpp | 475 ++++ libjava/classpath/native/jni/qt-peer/qtgraphics.h | 26 + libjava/classpath/native/jni/qt-peer/qtimage.cpp | 401 +++ libjava/classpath/native/jni/qt-peer/qtimage.h | 10 + .../classpath/native/jni/qt-peer/qtlabelpeer.cpp | 151 ++ .../classpath/native/jni/qt-peer/qtlistpeer.cpp | 210 ++ .../classpath/native/jni/qt-peer/qtmenubarpeer.cpp | 150 ++ .../native/jni/qt-peer/qtmenucomponentpeer.cpp | 66 + .../native/jni/qt-peer/qtmenuitempeer.cpp | 182 ++ .../classpath/native/jni/qt-peer/qtmenupeer.cpp | 254 ++ .../classpath/native/jni/qt-peer/qtpanelpeer.cpp | 77 + .../native/jni/qt-peer/qtpopupmenupeer.cpp | 76 + .../native/jni/qt-peer/qtscreendevice.cpp | 123 + .../native/jni/qt-peer/qtscrollbarpeer.cpp | 142 ++ .../native/jni/qt-peer/qtscrollpanepeer.cpp | 214 ++ libjava/classpath/native/jni/qt-peer/qtstrings.cpp | 54 + libjava/classpath/native/jni/qt-peer/qtstrings.h | 10 + .../native/jni/qt-peer/qttextareapeer.cpp | 197 ++ .../native/jni/qt-peer/qttextfieldpeer.cpp | 290 +++ libjava/classpath/native/jni/qt-peer/qttoolkit.cpp | 156 ++ .../native/jni/qt-peer/qtvolatileimage.cpp | 347 +++ .../classpath/native/jni/qt-peer/qtwindowpeer.cpp | 157 ++ .../classpath/native/jni/qt-peer/slotcallbacks.cpp | 256 ++ .../classpath/native/jni/qt-peer/slotcallbacks.h | 24 + libjava/classpath/native/jni/xmlj/.cvsignore | 8 + libjava/classpath/native/jni/xmlj/BUGS | 35 + libjava/classpath/native/jni/xmlj/Makefile.am | 28 + libjava/classpath/native/jni/xmlj/Makefile.in | 634 +++++ libjava/classpath/native/jni/xmlj/xmlj_dom.c | 2617 ++++++++++++++++++++ libjava/classpath/native/jni/xmlj/xmlj_dom.h | 70 + libjava/classpath/native/jni/xmlj/xmlj_error.c | 169 ++ libjava/classpath/native/jni/xmlj/xmlj_error.h | 85 + libjava/classpath/native/jni/xmlj/xmlj_io.c | 799 ++++++ libjava/classpath/native/jni/xmlj/xmlj_io.h | 170 ++ libjava/classpath/native/jni/xmlj/xmlj_node.c | 203 ++ libjava/classpath/native/jni/xmlj/xmlj_node.h | 72 + libjava/classpath/native/jni/xmlj/xmlj_sax.c | 1445 +++++++++++ libjava/classpath/native/jni/xmlj/xmlj_sax.h | 160 ++ libjava/classpath/native/jni/xmlj/xmlj_transform.c | 868 +++++++ libjava/classpath/native/jni/xmlj/xmlj_util.c | 280 +++ libjava/classpath/native/jni/xmlj/xmlj_util.h | 65 + libjava/classpath/native/jni/xmlj/xmlj_xpath.c | 624 +++++ libjava/classpath/native/plugin/.cvsignore | 6 + libjava/classpath/native/plugin/Makefile.am | 18 + libjava/classpath/native/plugin/Makefile.in | 627 +++++ libjava/classpath/native/plugin/gcjwebplugin.cc | 1803 ++++++++++++++ 292 files changed, 76324 insertions(+) create mode 100644 libjava/classpath/native/.cvsignore create mode 100644 libjava/classpath/native/Makefile.am create mode 100644 libjava/classpath/native/Makefile.in create mode 100644 libjava/classpath/native/fdlibm/.cvsignore create mode 100644 libjava/classpath/native/fdlibm/Makefile.am create mode 100644 libjava/classpath/native/fdlibm/Makefile.in create mode 100644 libjava/classpath/native/fdlibm/dtoa.c create mode 100644 libjava/classpath/native/fdlibm/e_acos.c create mode 100644 libjava/classpath/native/fdlibm/e_asin.c create mode 100644 libjava/classpath/native/fdlibm/e_atan2.c create mode 100644 libjava/classpath/native/fdlibm/e_cosh.c create mode 100644 libjava/classpath/native/fdlibm/e_exp.c create mode 100644 libjava/classpath/native/fdlibm/e_fmod.c create mode 100644 libjava/classpath/native/fdlibm/e_hypot.c create mode 100644 libjava/classpath/native/fdlibm/e_log.c create mode 100644 libjava/classpath/native/fdlibm/e_log10.c create mode 100644 libjava/classpath/native/fdlibm/e_pow.c create mode 100644 libjava/classpath/native/fdlibm/e_rem_pio2.c create mode 100644 libjava/classpath/native/fdlibm/e_remainder.c create mode 100644 libjava/classpath/native/fdlibm/e_scalb.c create mode 100644 libjava/classpath/native/fdlibm/e_sinh.c create mode 100644 libjava/classpath/native/fdlibm/e_sqrt.c create mode 100644 libjava/classpath/native/fdlibm/fdlibm.h create mode 100644 libjava/classpath/native/fdlibm/ieeefp.h create mode 100644 libjava/classpath/native/fdlibm/k_cos.c create mode 100644 libjava/classpath/native/fdlibm/k_rem_pio2.c create mode 100644 libjava/classpath/native/fdlibm/k_sin.c create mode 100644 libjava/classpath/native/fdlibm/k_tan.c create mode 100644 libjava/classpath/native/fdlibm/mprec.c create mode 100644 libjava/classpath/native/fdlibm/mprec.h create mode 100644 libjava/classpath/native/fdlibm/namespace.h create mode 100644 libjava/classpath/native/fdlibm/s_atan.c create mode 100644 libjava/classpath/native/fdlibm/s_cbrt.c create mode 100644 libjava/classpath/native/fdlibm/s_ceil.c create mode 100644 libjava/classpath/native/fdlibm/s_copysign.c create mode 100644 libjava/classpath/native/fdlibm/s_cos.c create mode 100644 libjava/classpath/native/fdlibm/s_expm1.c create mode 100644 libjava/classpath/native/fdlibm/s_fabs.c create mode 100644 libjava/classpath/native/fdlibm/s_finite.c create mode 100644 libjava/classpath/native/fdlibm/s_floor.c create mode 100644 libjava/classpath/native/fdlibm/s_log1p.c create mode 100644 libjava/classpath/native/fdlibm/s_rint.c create mode 100644 libjava/classpath/native/fdlibm/s_scalbn.c create mode 100644 libjava/classpath/native/fdlibm/s_sin.c create mode 100644 libjava/classpath/native/fdlibm/s_tan.c create mode 100644 libjava/classpath/native/fdlibm/s_tanh.c create mode 100644 libjava/classpath/native/fdlibm/sf_fabs.c create mode 100644 libjava/classpath/native/fdlibm/sf_rint.c create mode 100644 libjava/classpath/native/fdlibm/strtod.c create mode 100644 libjava/classpath/native/fdlibm/w_acos.c create mode 100644 libjava/classpath/native/fdlibm/w_asin.c create mode 100644 libjava/classpath/native/fdlibm/w_atan2.c create mode 100644 libjava/classpath/native/fdlibm/w_cosh.c create mode 100644 libjava/classpath/native/fdlibm/w_exp.c create mode 100644 libjava/classpath/native/fdlibm/w_fmod.c create mode 100644 libjava/classpath/native/fdlibm/w_hypot.c create mode 100644 libjava/classpath/native/fdlibm/w_log.c create mode 100644 libjava/classpath/native/fdlibm/w_log10.c create mode 100644 libjava/classpath/native/fdlibm/w_pow.c create mode 100644 libjava/classpath/native/fdlibm/w_remainder.c create mode 100644 libjava/classpath/native/fdlibm/w_sinh.c create mode 100644 libjava/classpath/native/fdlibm/w_sqrt.c create mode 100644 libjava/classpath/native/jawt/.cvsignore create mode 100644 libjava/classpath/native/jawt/Makefile.am create mode 100644 libjava/classpath/native/jawt/Makefile.in create mode 100644 libjava/classpath/native/jawt/jawt.c create mode 100644 libjava/classpath/native/jni/.cvsignore create mode 100644 libjava/classpath/native/jni/Makefile.am create mode 100644 libjava/classpath/native/jni/Makefile.in create mode 100644 libjava/classpath/native/jni/classpath/.cvsignore create mode 100644 libjava/classpath/native/jni/classpath/Makefile.am create mode 100644 libjava/classpath/native/jni/classpath/Makefile.in create mode 100644 libjava/classpath/native/jni/classpath/classpath_jawt.h create mode 100644 libjava/classpath/native/jni/classpath/jcl.c create mode 100644 libjava/classpath/native/jni/classpath/jcl.h create mode 100644 libjava/classpath/native/jni/classpath/jnilink.c create mode 100644 libjava/classpath/native/jni/classpath/jnilink.h create mode 100644 libjava/classpath/native/jni/gconf-peer/.cvsignore create mode 100644 libjava/classpath/native/jni/gconf-peer/GConfNativePeer.c create mode 100644 libjava/classpath/native/jni/gconf-peer/Makefile.am create mode 100644 libjava/classpath/native/jni/gconf-peer/Makefile.in create mode 100644 libjava/classpath/native/jni/gstreamer-peer/Makefile.am create mode 100644 libjava/classpath/native/jni/gstreamer-peer/Makefile.in create mode 100644 libjava/classpath/native/jni/gstreamer-peer/gst_classpath_src.c create mode 100644 libjava/classpath/native/jni/gstreamer-peer/gst_classpath_src.h create mode 100644 libjava/classpath/native/jni/gstreamer-peer/gst_input_stream.c create mode 100644 libjava/classpath/native/jni/gstreamer-peer/gst_input_stream.h create mode 100644 libjava/classpath/native/jni/gstreamer-peer/gst_native_data_line.c create mode 100644 libjava/classpath/native/jni/gstreamer-peer/gst_native_pipeline.c create mode 100644 libjava/classpath/native/jni/gstreamer-peer/gst_native_pipeline.h create mode 100644 libjava/classpath/native/jni/gstreamer-peer/gst_peer.c create mode 100644 libjava/classpath/native/jni/gstreamer-peer/gst_peer.h create mode 100644 libjava/classpath/native/jni/gstreamer-peer/gstreamer_io_peer.c create mode 100644 libjava/classpath/native/jni/gtk-peer/.cvsignore create mode 100644 libjava/classpath/native/jni/gtk-peer/GtkDragSourceContextPeer.c create mode 100644 libjava/classpath/native/jni/gtk-peer/Makefile.am create mode 100644 libjava/classpath/native/jni/gtk-peer/Makefile.in create mode 100644 libjava/classpath/native/jni/gtk-peer/cairographics2d.h create mode 100644 libjava/classpath/native/jni/gtk-peer/gdkdisplay.h create mode 100644 libjava/classpath/native/jni/gtk-peer/gdkfont.h create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphicsCopy.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_FreetypeGlyphVector.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkPixbufDecoder.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkRobotPeer.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCanvasPeer.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxMenuItemPeer.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxPeer.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkChoicePeer.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkClipboard.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFileDialogPeer.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFramePeer.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkGenericPeer.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkImage.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkListPeer.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuBarPeer.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuComponentPeer.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuItemPeer.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuPeer.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPanelPeer.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPopupMenuPeer.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkScrollPanePeer.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkScrollbarPeer.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkSelection.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextAreaPeer.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextFieldPeer.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkVolatileImage.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gtk_jawt.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gtkpeer.c create mode 100644 libjava/classpath/native/jni/gtk-peer/gtkpeer.h create mode 100644 libjava/classpath/native/jni/java-io/.cvsignore create mode 100644 libjava/classpath/native/jni/java-io/Makefile.am create mode 100644 libjava/classpath/native/jni/java-io/Makefile.in create mode 100644 libjava/classpath/native/jni/java-io/java_io_VMFile.c create mode 100644 libjava/classpath/native/jni/java-io/java_io_VMObjectInputStream.c create mode 100644 libjava/classpath/native/jni/java-io/java_io_VMObjectStreamClass.c create mode 100644 libjava/classpath/native/jni/java-lang/.cvsignore create mode 100644 libjava/classpath/native/jni/java-lang/Makefile.am create mode 100644 libjava/classpath/native/jni/java-lang/Makefile.in create mode 100644 libjava/classpath/native/jni/java-lang/gnu_java_lang_management_VMOperatingSystemMXBeanImpl.c create mode 100644 libjava/classpath/native/jni/java-lang/java_lang_VMDouble.c create mode 100644 libjava/classpath/native/jni/java-lang/java_lang_VMFloat.c create mode 100644 libjava/classpath/native/jni/java-lang/java_lang_VMMath.c create mode 100644 libjava/classpath/native/jni/java-lang/java_lang_VMProcess.c create mode 100644 libjava/classpath/native/jni/java-lang/java_lang_VMSystem.c create mode 100644 libjava/classpath/native/jni/java-lang/java_lang_reflect_VMArray.c create mode 100644 libjava/classpath/native/jni/java-math/Makefile.am create mode 100644 libjava/classpath/native/jni/java-math/Makefile.in create mode 100644 libjava/classpath/native/jni/java-math/gnu_java_math_GMP.c create mode 100644 libjava/classpath/native/jni/java-net/.cvsignore create mode 100644 libjava/classpath/native/jni/java-net/Makefile.am create mode 100644 libjava/classpath/native/jni/java-net/Makefile.in create mode 100644 libjava/classpath/native/jni/java-net/gnu_java_net_VMPlainSocketImpl.c create mode 100644 libjava/classpath/native/jni/java-net/gnu_java_net_local_LocalSocketImpl.c create mode 100644 libjava/classpath/native/jni/java-net/java_net_VMInetAddress.c create mode 100644 libjava/classpath/native/jni/java-net/java_net_VMNetworkInterface.c create mode 100644 libjava/classpath/native/jni/java-net/java_net_VMURLConnection.c create mode 100644 libjava/classpath/native/jni/java-net/javanet.c create mode 100644 libjava/classpath/native/jni/java-net/javanet.h create mode 100644 libjava/classpath/native/jni/java-net/local.c create mode 100644 libjava/classpath/native/jni/java-net/local.h create mode 100644 libjava/classpath/native/jni/java-nio/.cvsignore create mode 100644 libjava/classpath/native/jni/java-nio/Makefile.am create mode 100644 libjava/classpath/native/jni/java-nio/Makefile.in create mode 100644 libjava/classpath/native/jni/java-nio/gnu_java_nio_EpollSelectorImpl.c create mode 100644 libjava/classpath/native/jni/java-nio/gnu_java_nio_KqueueSelectorImpl.c create mode 100644 libjava/classpath/native/jni/java-nio/gnu_java_nio_VMChannel.c create mode 100644 libjava/classpath/native/jni/java-nio/gnu_java_nio_VMPipe.c create mode 100644 libjava/classpath/native/jni/java-nio/gnu_java_nio_VMSelector.c create mode 100644 libjava/classpath/native/jni/java-nio/gnu_java_nio_charset_iconv_IconvDecoder.c create mode 100644 libjava/classpath/native/jni/java-nio/gnu_java_nio_charset_iconv_IconvEncoder.c create mode 100644 libjava/classpath/native/jni/java-nio/java_nio_MappedByteBufferImpl.c create mode 100644 libjava/classpath/native/jni/java-nio/java_nio_VMDirectByteBuffer.c create mode 100644 libjava/classpath/native/jni/java-nio/javanio.c create mode 100644 libjava/classpath/native/jni/java-nio/javanio.h create mode 100644 libjava/classpath/native/jni/java-util/.cvsignore create mode 100644 libjava/classpath/native/jni/java-util/Makefile.am create mode 100644 libjava/classpath/native/jni/java-util/Makefile.in create mode 100644 libjava/classpath/native/jni/java-util/java_util_VMTimeZone.c create mode 100644 libjava/classpath/native/jni/midi-alsa/.cvsignore create mode 100644 libjava/classpath/native/jni/midi-alsa/Makefile.am create mode 100644 libjava/classpath/native/jni/midi-alsa/Makefile.in create mode 100644 libjava/classpath/native/jni/midi-alsa/gnu_javax_sound_midi_alsa_AlsaMidiDeviceProvider.c create mode 100644 libjava/classpath/native/jni/midi-alsa/gnu_javax_sound_midi_alsa_AlsaMidiSequencerDevice.c create mode 100644 libjava/classpath/native/jni/midi-alsa/gnu_javax_sound_midi_alsa_AlsaPortDevice.c create mode 100644 libjava/classpath/native/jni/midi-dssi/.cvsignore create mode 100644 libjava/classpath/native/jni/midi-dssi/Makefile.am create mode 100644 libjava/classpath/native/jni/midi-dssi/Makefile.in create mode 100644 libjava/classpath/native/jni/midi-dssi/README create mode 100644 libjava/classpath/native/jni/midi-dssi/dssi_data.h create mode 100644 libjava/classpath/native/jni/midi-dssi/gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider.c create mode 100644 libjava/classpath/native/jni/midi-dssi/gnu_javax_sound_midi_dssi_DSSISynthesizer.c create mode 100644 libjava/classpath/native/jni/native-lib/.cvsignore create mode 100644 libjava/classpath/native/jni/native-lib/Makefile.am create mode 100644 libjava/classpath/native/jni/native-lib/Makefile.in create mode 100644 libjava/classpath/native/jni/native-lib/cpio.c create mode 100644 libjava/classpath/native/jni/native-lib/cpio.h create mode 100644 libjava/classpath/native/jni/native-lib/cpnative.h create mode 100644 libjava/classpath/native/jni/native-lib/cpnet.c create mode 100644 libjava/classpath/native/jni/native-lib/cpnet.h create mode 100644 libjava/classpath/native/jni/native-lib/cpproc.c create mode 100644 libjava/classpath/native/jni/native-lib/cpproc.h create mode 100644 libjava/classpath/native/jni/qt-peer/.cvsignore create mode 100644 libjava/classpath/native/jni/qt-peer/Makefile.am create mode 100644 libjava/classpath/native/jni/qt-peer/Makefile.in create mode 100644 libjava/classpath/native/jni/qt-peer/buttonevent.h create mode 100644 libjava/classpath/native/jni/qt-peer/componentevent.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/componentevent.h create mode 100644 libjava/classpath/native/jni/qt-peer/containers.h create mode 100644 libjava/classpath/native/jni/qt-peer/eventmethods.h create mode 100644 libjava/classpath/native/jni/qt-peer/keybindings.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/keybindings.h create mode 100644 libjava/classpath/native/jni/qt-peer/mainqtthread.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/mainthreadinterface.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/mainthreadinterface.h create mode 100644 libjava/classpath/native/jni/qt-peer/nativewrapper.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/nativewrapper.h create mode 100644 libjava/classpath/native/jni/qt-peer/qmatrix.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/qpainterpath.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/qpen.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/qtaudioclip.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/qtbuttonpeer.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/qtcanvaspeer.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/qtcheckboxpeer.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/qtchoicepeer.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/qtcomponent.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/qtcomponent.h create mode 100644 libjava/classpath/native/jni/qt-peer/qtcomponentpeer.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/qtdialogpeer.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/qtembeddedwindowpeer.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/qtfiledialogpeer.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/qtfont.h create mode 100644 libjava/classpath/native/jni/qt-peer/qtfontmetrics.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/qtfontpeer.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/qtframepeer.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/qtgraphics.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/qtgraphics.h create mode 100644 libjava/classpath/native/jni/qt-peer/qtimage.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/qtimage.h create mode 100644 libjava/classpath/native/jni/qt-peer/qtlabelpeer.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/qtlistpeer.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/qtmenubarpeer.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/qtmenucomponentpeer.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/qtmenuitempeer.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/qtmenupeer.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/qtpanelpeer.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/qtpopupmenupeer.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/qtscreendevice.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/qtscrollbarpeer.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/qtscrollpanepeer.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/qtstrings.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/qtstrings.h create mode 100644 libjava/classpath/native/jni/qt-peer/qttextareapeer.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/qttextfieldpeer.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/qttoolkit.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/qtvolatileimage.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/qtwindowpeer.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/slotcallbacks.cpp create mode 100644 libjava/classpath/native/jni/qt-peer/slotcallbacks.h create mode 100644 libjava/classpath/native/jni/xmlj/.cvsignore create mode 100644 libjava/classpath/native/jni/xmlj/BUGS create mode 100644 libjava/classpath/native/jni/xmlj/Makefile.am create mode 100644 libjava/classpath/native/jni/xmlj/Makefile.in create mode 100644 libjava/classpath/native/jni/xmlj/xmlj_dom.c create mode 100644 libjava/classpath/native/jni/xmlj/xmlj_dom.h create mode 100644 libjava/classpath/native/jni/xmlj/xmlj_error.c create mode 100644 libjava/classpath/native/jni/xmlj/xmlj_error.h create mode 100644 libjava/classpath/native/jni/xmlj/xmlj_io.c create mode 100644 libjava/classpath/native/jni/xmlj/xmlj_io.h create mode 100644 libjava/classpath/native/jni/xmlj/xmlj_node.c create mode 100644 libjava/classpath/native/jni/xmlj/xmlj_node.h create mode 100644 libjava/classpath/native/jni/xmlj/xmlj_sax.c create mode 100644 libjava/classpath/native/jni/xmlj/xmlj_sax.h create mode 100644 libjava/classpath/native/jni/xmlj/xmlj_transform.c create mode 100644 libjava/classpath/native/jni/xmlj/xmlj_util.c create mode 100644 libjava/classpath/native/jni/xmlj/xmlj_util.h create mode 100644 libjava/classpath/native/jni/xmlj/xmlj_xpath.c create mode 100644 libjava/classpath/native/plugin/.cvsignore create mode 100644 libjava/classpath/native/plugin/Makefile.am create mode 100644 libjava/classpath/native/plugin/Makefile.in create mode 100644 libjava/classpath/native/plugin/gcjwebplugin.cc (limited to 'libjava/classpath/native') diff --git a/libjava/classpath/native/.cvsignore b/libjava/classpath/native/.cvsignore new file mode 100644 index 000000000..e9f2658a6 --- /dev/null +++ b/libjava/classpath/native/.cvsignore @@ -0,0 +1,8 @@ +*.o +*.a +*.lo +*.la +.libs +.deps +Makefile +Makefile.in diff --git a/libjava/classpath/native/Makefile.am b/libjava/classpath/native/Makefile.am new file mode 100644 index 000000000..89b859eb7 --- /dev/null +++ b/libjava/classpath/native/Makefile.am @@ -0,0 +1,17 @@ +## Input file for automake to generate the Makefile.in used by configure + +if CREATE_JNI_LIBRARIES + JNIDIR = jni +endif + +if CREATE_GTK_PEER_LIBRARIES + JAWTDIR = jawt +endif + +if CREATE_PLUGIN + PLUGINDIR = plugin +endif + +SUBDIRS = fdlibm $(JNIDIR) $(JAWTDIR) $(PLUGINDIR) +DIST_SUBDIRS = fdlibm jni jawt plugin + diff --git a/libjava/classpath/native/Makefile.in b/libjava/classpath/native/Makefile.in new file mode 100644 index 000000000..4d6e58120 --- /dev/null +++ b/libjava/classpath/native/Makefile.in @@ -0,0 +1,589 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +subdir = native +DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/../../config/depstand.m4 \ + $(top_srcdir)/../../config/lead-dot.m4 \ + $(top_srcdir)/../../config/lib-ld.m4 \ + $(top_srcdir)/../../config/lib-link.m4 \ + $(top_srcdir)/../../config/lib-prefix.m4 \ + $(top_srcdir)/../../config/multi.m4 \ + $(top_srcdir)/../../config/no-executables.m4 \ + $(top_srcdir)/../../config/override.m4 \ + $(top_srcdir)/../../libtool.m4 \ + $(top_srcdir)/../../ltoptions.m4 \ + $(top_srcdir)/../../ltsugar.m4 \ + $(top_srcdir)/../../ltversion.m4 \ + $(top_srcdir)/../../lt~obsolete.m4 \ + $(top_srcdir)/m4/ac_prog_antlr.m4 \ + $(top_srcdir)/m4/ac_prog_java.m4 \ + $(top_srcdir)/m4/ac_prog_java_works.m4 \ + $(top_srcdir)/m4/ac_prog_javac.m4 \ + $(top_srcdir)/m4/ac_prog_javac_works.m4 \ + $(top_srcdir)/m4/acattribute.m4 $(top_srcdir)/m4/accross.m4 \ + $(top_srcdir)/m4/acinclude.m4 \ + $(top_srcdir)/m4/ax_create_stdint_h.m4 \ + $(top_srcdir)/m4/ax_func_which_gethostbyname_r.m4 \ + $(top_srcdir)/m4/gcc_attribute.m4 $(top_srcdir)/m4/iconv.m4 \ + $(top_srcdir)/m4/pkg.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/../../mkinstalldirs +CONFIG_HEADER = $(top_builddir)/include/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +SOURCES = +RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \ + html-recursive info-recursive install-data-recursive \ + install-dvi-recursive install-exec-recursive \ + install-html-recursive install-info-recursive \ + install-pdf-recursive install-ps-recursive install-recursive \ + installcheck-recursive installdirs-recursive pdf-recursive \ + ps-recursive uninstall-recursive +RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ + distclean-recursive maintainer-clean-recursive +AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \ + $(RECURSIVE_CLEAN_TARGETS:-recursive=) tags TAGS ctags CTAGS +ETAGS = etags +CTAGS = ctags +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +ANTLR = @ANTLR@ +ANTLR_JAR = @ANTLR_JAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CAIRO_CFLAGS = @CAIRO_CFLAGS@ +CAIRO_LIBS = @CAIRO_LIBS@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CLASSPATH_CONVENIENCE = @CLASSPATH_CONVENIENCE@ +CLASSPATH_INCLUDES = @CLASSPATH_INCLUDES@ +CLASSPATH_MODULE = @CLASSPATH_MODULE@ +COLLECTIONS_PREFIX = @COLLECTIONS_PREFIX@ +CP = @CP@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DATE = @DATE@ +DEFAULT_PREFS_PEER = @DEFAULT_PREFS_PEER@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +ECJ_JAR = @ECJ_JAR@ +EGREP = @EGREP@ +ERROR_CFLAGS = @ERROR_CFLAGS@ +EXAMPLESDIR = @EXAMPLESDIR@ +EXEEXT = @EXEEXT@ +EXTRA_CFLAGS = @EXTRA_CFLAGS@ +FGREP = @FGREP@ +FIND = @FIND@ +FREETYPE2_CFLAGS = @FREETYPE2_CFLAGS@ +FREETYPE2_LIBS = @FREETYPE2_LIBS@ +GCONF_CFLAGS = @GCONF_CFLAGS@ +GCONF_LIBS = @GCONF_LIBS@ +GDK_CFLAGS = @GDK_CFLAGS@ +GDK_LIBS = @GDK_LIBS@ +GJDOC = @GJDOC@ +GLIB_CFLAGS = @GLIB_CFLAGS@ +GLIB_LIBS = @GLIB_LIBS@ +GMP_CFLAGS = @GMP_CFLAGS@ +GMP_LIBS = @GMP_LIBS@ +GREP = @GREP@ +GSTREAMER_BASE_CFLAGS = @GSTREAMER_BASE_CFLAGS@ +GSTREAMER_BASE_LIBS = @GSTREAMER_BASE_LIBS@ +GSTREAMER_CFLAGS = @GSTREAMER_CFLAGS@ +GSTREAMER_FILE_READER = @GSTREAMER_FILE_READER@ +GSTREAMER_LIBS = @GSTREAMER_LIBS@ +GSTREAMER_MIXER_PROVIDER = @GSTREAMER_MIXER_PROVIDER@ +GSTREAMER_PLUGINS_BASE_CFLAGS = @GSTREAMER_PLUGINS_BASE_CFLAGS@ +GSTREAMER_PLUGINS_BASE_LIBS = @GSTREAMER_PLUGINS_BASE_LIBS@ +GST_PLUGIN_LDFLAGS = @GST_PLUGIN_LDFLAGS@ +GTK_CFLAGS = @GTK_CFLAGS@ +GTK_LIBS = @GTK_LIBS@ +INIT_LOAD_LIBRARY = @INIT_LOAD_LIBRARY@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAR = @JAR@ +JAVA = @JAVA@ +JAVAC = @JAVAC@ +JAVAC_IS_GCJ = @JAVAC_IS_GCJ@ +JAVAC_MEM_OPT = @JAVAC_MEM_OPT@ +JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION = @JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION@ +JAY = @JAY@ +JAY_SKELETON = @JAY_SKELETON@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBDEBUG = @LIBDEBUG@ +LIBICONV = @LIBICONV@ +LIBMAGIC = @LIBMAGIC@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBVERSION = @LIBVERSION@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBICONV = @LTLIBICONV@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MKDIR = @MKDIR@ +MKDIR_P = @MKDIR_P@ +MOC = @MOC@ +MOZILLA_CFLAGS = @MOZILLA_CFLAGS@ +MOZILLA_LIBS = @MOZILLA_LIBS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PANGOFT2_CFLAGS = @PANGOFT2_CFLAGS@ +PANGOFT2_LIBS = @PANGOFT2_LIBS@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PATH_TO_ESCHER = @PATH_TO_ESCHER@ +PATH_TO_GLIBJ_ZIP = @PATH_TO_GLIBJ_ZIP@ +PERL = @PERL@ +PKG_CONFIG = @PKG_CONFIG@ +PLUGIN_DIR = @PLUGIN_DIR@ +QT_CFLAGS = @QT_CFLAGS@ +QT_LIBS = @QT_LIBS@ +RANLIB = @RANLIB@ +REMOVE = @REMOVE@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRICT_WARNING_CFLAGS = @STRICT_WARNING_CFLAGS@ +STRIP = @STRIP@ +TOOLSDIR = @TOOLSDIR@ +USER_JAVAH = @USER_JAVAH@ +VERSION = @VERSION@ +WANT_NATIVE_BIG_INTEGER = @WANT_NATIVE_BIG_INTEGER@ +WARNING_CFLAGS = @WARNING_CFLAGS@ +XMKMF = @XMKMF@ +XML_CFLAGS = @XML_CFLAGS@ +XML_LIBS = @XML_LIBS@ +XSLT_CFLAGS = @XSLT_CFLAGS@ +XSLT_LIBS = @XSLT_LIBS@ +XTEST_LIBS = @XTEST_LIBS@ +X_CFLAGS = @X_CFLAGS@ +X_EXTRA_LIBS = @X_EXTRA_LIBS@ +X_LIBS = @X_LIBS@ +X_PRE_LIBS = @X_PRE_LIBS@ +ZIP = @ZIP@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_ANTLR = @ac_ct_ANTLR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +default_toolkit = @default_toolkit@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +glibjdir = @glibjdir@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +multi_basedir = @multi_basedir@ +nativeexeclibdir = @nativeexeclibdir@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +toolexeclibdir = @toolexeclibdir@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +uudecode = @uudecode@ +vm_classes = @vm_classes@ +@CREATE_JNI_LIBRARIES_TRUE@JNIDIR = jni +@CREATE_GTK_PEER_LIBRARIES_TRUE@JAWTDIR = jawt +@CREATE_PLUGIN_TRUE@PLUGINDIR = plugin +SUBDIRS = fdlibm $(JNIDIR) $(JAWTDIR) $(PLUGINDIR) +DIST_SUBDIRS = fdlibm jni jawt plugin +all: all-recursive + +.SUFFIXES: +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu native/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu native/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +# This directory's subdirectories are mostly independent; you can cd +# into them and run `make' without going through this Makefile. +# To change the values of `make' variables: instead of editing Makefiles, +# (1) if the variable is set in `config.status', edit `config.status' +# (which will cause the Makefiles to be regenerated when you run `make'); +# (2) otherwise, pass the desired values on the `make' command line. +$(RECURSIVE_TARGETS): + @fail= failcom='exit 1'; \ + for f in x $$MAKEFLAGS; do \ + case $$f in \ + *=* | --[!k]*);; \ + *k*) failcom='fail=yes';; \ + esac; \ + done; \ + dot_seen=no; \ + target=`echo $@ | sed s/-recursive//`; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + dot_seen=yes; \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || eval $$failcom; \ + done; \ + if test "$$dot_seen" = "no"; then \ + $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ + fi; test -z "$$fail" + +$(RECURSIVE_CLEAN_TARGETS): + @fail= failcom='exit 1'; \ + for f in x $$MAKEFLAGS; do \ + case $$f in \ + *=* | --[!k]*);; \ + *k*) failcom='fail=yes';; \ + esac; \ + done; \ + dot_seen=no; \ + case "$@" in \ + distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ + *) list='$(SUBDIRS)' ;; \ + esac; \ + rev=''; for subdir in $$list; do \ + if test "$$subdir" = "."; then :; else \ + rev="$$subdir $$rev"; \ + fi; \ + done; \ + rev="$$rev ."; \ + target=`echo $@ | sed s/-recursive//`; \ + for subdir in $$rev; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || eval $$failcom; \ + done && test -z "$$fail" +tags-recursive: + list='$(SUBDIRS)'; for subdir in $$list; do \ + test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \ + done +ctags-recursive: + list='$(SUBDIRS)'; for subdir in $$list; do \ + test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \ + done + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: tags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \ + include_option=--etags-include; \ + empty_fix=.; \ + else \ + include_option=--include; \ + empty_fix=; \ + fi; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + test ! -f $$subdir/TAGS || \ + set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \ + fi; \ + done; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: ctags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags +check-am: all-am +check: check-recursive +all-am: Makefile +installdirs: installdirs-recursive +installdirs-am: +install: install-recursive +install-exec: install-exec-recursive +install-data: install-data-recursive +uninstall: uninstall-recursive + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-recursive +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-recursive + +clean-am: clean-generic clean-libtool mostlyclean-am + +distclean: distclean-recursive + -rm -f Makefile +distclean-am: clean-am distclean-generic distclean-tags + +dvi: dvi-recursive + +dvi-am: + +html: html-recursive + +html-am: + +info: info-recursive + +info-am: + +install-data-am: + +install-dvi: install-dvi-recursive + +install-dvi-am: + +install-exec-am: + +install-html: install-html-recursive + +install-html-am: + +install-info: install-info-recursive + +install-info-am: + +install-man: + +install-pdf: install-pdf-recursive + +install-pdf-am: + +install-ps: install-ps-recursive + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-recursive + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-recursive + +mostlyclean-am: mostlyclean-generic mostlyclean-libtool + +pdf: pdf-recursive + +pdf-am: + +ps: ps-recursive + +ps-am: + +uninstall-am: + +.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) ctags-recursive \ + install-am install-strip tags-recursive + +.PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \ + all all-am check check-am clean clean-generic clean-libtool \ + ctags ctags-recursive distclean distclean-generic \ + distclean-libtool distclean-tags dvi dvi-am html html-am info \ + info-am install install-am install-data install-data-am \ + install-dvi install-dvi-am install-exec install-exec-am \ + install-html install-html-am install-info install-info-am \ + install-man install-pdf install-pdf-am install-ps \ + install-ps-am install-strip installcheck installcheck-am \ + installdirs installdirs-am maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-generic \ + mostlyclean-libtool pdf pdf-am ps ps-am tags tags-recursive \ + uninstall uninstall-am + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/libjava/classpath/native/fdlibm/.cvsignore b/libjava/classpath/native/fdlibm/.cvsignore new file mode 100644 index 000000000..e9f2658a6 --- /dev/null +++ b/libjava/classpath/native/fdlibm/.cvsignore @@ -0,0 +1,8 @@ +*.o +*.a +*.lo +*.la +.libs +.deps +Makefile +Makefile.in diff --git a/libjava/classpath/native/fdlibm/Makefile.am b/libjava/classpath/native/fdlibm/Makefile.am new file mode 100644 index 000000000..29bf83746 --- /dev/null +++ b/libjava/classpath/native/fdlibm/Makefile.am @@ -0,0 +1,65 @@ +noinst_LTLIBRARIES = libfdlibm.la + +libfdlibm_la_SOURCES = \ + dtoa.c \ + e_acos.c \ + e_asin.c \ + e_atan2.c \ + e_cosh.c \ + e_exp.c \ + e_fmod.c \ + e_hypot.c \ + e_log.c \ + e_log10.c \ + e_pow.c \ + e_remainder.c \ + e_rem_pio2.c \ + e_scalb.c \ + e_sinh.c \ + e_sqrt.c \ + fdlibm.h \ + ieeefp.h \ + k_cos.c \ + k_rem_pio2.c \ + k_sin.c \ + k_tan.c \ + mprec.c \ + mprec.h \ + s_atan.c \ + s_cbrt.c \ + s_ceil.c \ + s_copysign.c \ + s_cos.c \ + s_expm1.c \ + s_fabs.c \ + sf_fabs.c \ + s_finite.c \ + s_floor.c \ + s_log1p.c \ + sf_rint.c \ + s_rint.c \ + s_scalbn.c \ + s_sin.c \ + s_tan.c \ + s_tanh.c \ + strtod.c \ + w_acos.c \ + w_asin.c \ + w_atan2.c \ + w_cosh.c \ + w_exp.c \ + w_fmod.c \ + w_hypot.c \ + w_log.c \ + w_log10.c \ + w_pow.c \ + w_remainder.c \ + w_sinh.c \ + w_sqrt.c \ + namespace.h + +AM_LDFLAGS = @CLASSPATH_CONVENIENCE@ + +AM_CFLAGS = @EXTRA_CFLAGS@ + +# We don't need extra includes, so no AM_CPPFLAGS. diff --git a/libjava/classpath/native/fdlibm/Makefile.in b/libjava/classpath/native/fdlibm/Makefile.in new file mode 100644 index 000000000..ff3445121 --- /dev/null +++ b/libjava/classpath/native/fdlibm/Makefile.in @@ -0,0 +1,674 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +subdir = native/fdlibm +DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/../../config/depstand.m4 \ + $(top_srcdir)/../../config/lead-dot.m4 \ + $(top_srcdir)/../../config/lib-ld.m4 \ + $(top_srcdir)/../../config/lib-link.m4 \ + $(top_srcdir)/../../config/lib-prefix.m4 \ + $(top_srcdir)/../../config/multi.m4 \ + $(top_srcdir)/../../config/no-executables.m4 \ + $(top_srcdir)/../../config/override.m4 \ + $(top_srcdir)/../../libtool.m4 \ + $(top_srcdir)/../../ltoptions.m4 \ + $(top_srcdir)/../../ltsugar.m4 \ + $(top_srcdir)/../../ltversion.m4 \ + $(top_srcdir)/../../lt~obsolete.m4 \ + $(top_srcdir)/m4/ac_prog_antlr.m4 \ + $(top_srcdir)/m4/ac_prog_java.m4 \ + $(top_srcdir)/m4/ac_prog_java_works.m4 \ + $(top_srcdir)/m4/ac_prog_javac.m4 \ + $(top_srcdir)/m4/ac_prog_javac_works.m4 \ + $(top_srcdir)/m4/acattribute.m4 $(top_srcdir)/m4/accross.m4 \ + $(top_srcdir)/m4/acinclude.m4 \ + $(top_srcdir)/m4/ax_create_stdint_h.m4 \ + $(top_srcdir)/m4/ax_func_which_gethostbyname_r.m4 \ + $(top_srcdir)/m4/gcc_attribute.m4 $(top_srcdir)/m4/iconv.m4 \ + $(top_srcdir)/m4/pkg.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/../../mkinstalldirs +CONFIG_HEADER = $(top_builddir)/include/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +LTLIBRARIES = $(noinst_LTLIBRARIES) +libfdlibm_la_LIBADD = +am_libfdlibm_la_OBJECTS = dtoa.lo e_acos.lo e_asin.lo e_atan2.lo \ + e_cosh.lo e_exp.lo e_fmod.lo e_hypot.lo e_log.lo e_log10.lo \ + e_pow.lo e_remainder.lo e_rem_pio2.lo e_scalb.lo e_sinh.lo \ + e_sqrt.lo k_cos.lo k_rem_pio2.lo k_sin.lo k_tan.lo mprec.lo \ + s_atan.lo s_cbrt.lo s_ceil.lo s_copysign.lo s_cos.lo \ + s_expm1.lo s_fabs.lo sf_fabs.lo s_finite.lo s_floor.lo \ + s_log1p.lo sf_rint.lo s_rint.lo s_scalbn.lo s_sin.lo s_tan.lo \ + s_tanh.lo strtod.lo w_acos.lo w_asin.lo w_atan2.lo w_cosh.lo \ + w_exp.lo w_fmod.lo w_hypot.lo w_log.lo w_log10.lo w_pow.lo \ + w_remainder.lo w_sinh.lo w_sqrt.lo +libfdlibm_la_OBJECTS = $(am_libfdlibm_la_OBJECTS) +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/include +depcomp = $(SHELL) $(top_srcdir)/../../depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(libfdlibm_la_SOURCES) +ETAGS = etags +CTAGS = ctags +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +ANTLR = @ANTLR@ +ANTLR_JAR = @ANTLR_JAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CAIRO_CFLAGS = @CAIRO_CFLAGS@ +CAIRO_LIBS = @CAIRO_LIBS@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CLASSPATH_CONVENIENCE = @CLASSPATH_CONVENIENCE@ +CLASSPATH_INCLUDES = @CLASSPATH_INCLUDES@ +CLASSPATH_MODULE = @CLASSPATH_MODULE@ +COLLECTIONS_PREFIX = @COLLECTIONS_PREFIX@ +CP = @CP@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DATE = @DATE@ +DEFAULT_PREFS_PEER = @DEFAULT_PREFS_PEER@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +ECJ_JAR = @ECJ_JAR@ +EGREP = @EGREP@ +ERROR_CFLAGS = @ERROR_CFLAGS@ +EXAMPLESDIR = @EXAMPLESDIR@ +EXEEXT = @EXEEXT@ +EXTRA_CFLAGS = @EXTRA_CFLAGS@ +FGREP = @FGREP@ +FIND = @FIND@ +FREETYPE2_CFLAGS = @FREETYPE2_CFLAGS@ +FREETYPE2_LIBS = @FREETYPE2_LIBS@ +GCONF_CFLAGS = @GCONF_CFLAGS@ +GCONF_LIBS = @GCONF_LIBS@ +GDK_CFLAGS = @GDK_CFLAGS@ +GDK_LIBS = @GDK_LIBS@ +GJDOC = @GJDOC@ +GLIB_CFLAGS = @GLIB_CFLAGS@ +GLIB_LIBS = @GLIB_LIBS@ +GMP_CFLAGS = @GMP_CFLAGS@ +GMP_LIBS = @GMP_LIBS@ +GREP = @GREP@ +GSTREAMER_BASE_CFLAGS = @GSTREAMER_BASE_CFLAGS@ +GSTREAMER_BASE_LIBS = @GSTREAMER_BASE_LIBS@ +GSTREAMER_CFLAGS = @GSTREAMER_CFLAGS@ +GSTREAMER_FILE_READER = @GSTREAMER_FILE_READER@ +GSTREAMER_LIBS = @GSTREAMER_LIBS@ +GSTREAMER_MIXER_PROVIDER = @GSTREAMER_MIXER_PROVIDER@ +GSTREAMER_PLUGINS_BASE_CFLAGS = @GSTREAMER_PLUGINS_BASE_CFLAGS@ +GSTREAMER_PLUGINS_BASE_LIBS = @GSTREAMER_PLUGINS_BASE_LIBS@ +GST_PLUGIN_LDFLAGS = @GST_PLUGIN_LDFLAGS@ +GTK_CFLAGS = @GTK_CFLAGS@ +GTK_LIBS = @GTK_LIBS@ +INIT_LOAD_LIBRARY = @INIT_LOAD_LIBRARY@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAR = @JAR@ +JAVA = @JAVA@ +JAVAC = @JAVAC@ +JAVAC_IS_GCJ = @JAVAC_IS_GCJ@ +JAVAC_MEM_OPT = @JAVAC_MEM_OPT@ +JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION = @JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION@ +JAY = @JAY@ +JAY_SKELETON = @JAY_SKELETON@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBDEBUG = @LIBDEBUG@ +LIBICONV = @LIBICONV@ +LIBMAGIC = @LIBMAGIC@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBVERSION = @LIBVERSION@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBICONV = @LTLIBICONV@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MKDIR = @MKDIR@ +MKDIR_P = @MKDIR_P@ +MOC = @MOC@ +MOZILLA_CFLAGS = @MOZILLA_CFLAGS@ +MOZILLA_LIBS = @MOZILLA_LIBS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PANGOFT2_CFLAGS = @PANGOFT2_CFLAGS@ +PANGOFT2_LIBS = @PANGOFT2_LIBS@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PATH_TO_ESCHER = @PATH_TO_ESCHER@ +PATH_TO_GLIBJ_ZIP = @PATH_TO_GLIBJ_ZIP@ +PERL = @PERL@ +PKG_CONFIG = @PKG_CONFIG@ +PLUGIN_DIR = @PLUGIN_DIR@ +QT_CFLAGS = @QT_CFLAGS@ +QT_LIBS = @QT_LIBS@ +RANLIB = @RANLIB@ +REMOVE = @REMOVE@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRICT_WARNING_CFLAGS = @STRICT_WARNING_CFLAGS@ +STRIP = @STRIP@ +TOOLSDIR = @TOOLSDIR@ +USER_JAVAH = @USER_JAVAH@ +VERSION = @VERSION@ +WANT_NATIVE_BIG_INTEGER = @WANT_NATIVE_BIG_INTEGER@ +WARNING_CFLAGS = @WARNING_CFLAGS@ +XMKMF = @XMKMF@ +XML_CFLAGS = @XML_CFLAGS@ +XML_LIBS = @XML_LIBS@ +XSLT_CFLAGS = @XSLT_CFLAGS@ +XSLT_LIBS = @XSLT_LIBS@ +XTEST_LIBS = @XTEST_LIBS@ +X_CFLAGS = @X_CFLAGS@ +X_EXTRA_LIBS = @X_EXTRA_LIBS@ +X_LIBS = @X_LIBS@ +X_PRE_LIBS = @X_PRE_LIBS@ +ZIP = @ZIP@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_ANTLR = @ac_ct_ANTLR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +default_toolkit = @default_toolkit@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +glibjdir = @glibjdir@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +multi_basedir = @multi_basedir@ +nativeexeclibdir = @nativeexeclibdir@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +toolexeclibdir = @toolexeclibdir@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +uudecode = @uudecode@ +vm_classes = @vm_classes@ +noinst_LTLIBRARIES = libfdlibm.la +libfdlibm_la_SOURCES = \ + dtoa.c \ + e_acos.c \ + e_asin.c \ + e_atan2.c \ + e_cosh.c \ + e_exp.c \ + e_fmod.c \ + e_hypot.c \ + e_log.c \ + e_log10.c \ + e_pow.c \ + e_remainder.c \ + e_rem_pio2.c \ + e_scalb.c \ + e_sinh.c \ + e_sqrt.c \ + fdlibm.h \ + ieeefp.h \ + k_cos.c \ + k_rem_pio2.c \ + k_sin.c \ + k_tan.c \ + mprec.c \ + mprec.h \ + s_atan.c \ + s_cbrt.c \ + s_ceil.c \ + s_copysign.c \ + s_cos.c \ + s_expm1.c \ + s_fabs.c \ + sf_fabs.c \ + s_finite.c \ + s_floor.c \ + s_log1p.c \ + sf_rint.c \ + s_rint.c \ + s_scalbn.c \ + s_sin.c \ + s_tan.c \ + s_tanh.c \ + strtod.c \ + w_acos.c \ + w_asin.c \ + w_atan2.c \ + w_cosh.c \ + w_exp.c \ + w_fmod.c \ + w_hypot.c \ + w_log.c \ + w_log10.c \ + w_pow.c \ + w_remainder.c \ + w_sinh.c \ + w_sqrt.c \ + namespace.h + +AM_LDFLAGS = @CLASSPATH_CONVENIENCE@ +AM_CFLAGS = @EXTRA_CFLAGS@ +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu native/fdlibm/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu native/fdlibm/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +clean-noinstLTLIBRARIES: + -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES) + @list='$(noinst_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libfdlibm.la: $(libfdlibm_la_OBJECTS) $(libfdlibm_la_DEPENDENCIES) + $(LINK) $(libfdlibm_la_OBJECTS) $(libfdlibm_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dtoa.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/e_acos.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/e_asin.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/e_atan2.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/e_cosh.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/e_exp.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/e_fmod.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/e_hypot.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/e_log.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/e_log10.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/e_pow.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/e_rem_pio2.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/e_remainder.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/e_scalb.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/e_sinh.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/e_sqrt.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/k_cos.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/k_rem_pio2.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/k_sin.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/k_tan.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mprec.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/s_atan.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/s_cbrt.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/s_ceil.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/s_copysign.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/s_cos.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/s_expm1.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/s_fabs.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/s_finite.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/s_floor.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/s_log1p.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/s_rint.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/s_scalbn.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/s_sin.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/s_tan.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/s_tanh.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sf_fabs.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sf_rint.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strtod.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/w_acos.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/w_asin.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/w_atan2.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/w_cosh.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/w_exp.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/w_fmod.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/w_hypot.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/w_log.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/w_log10.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/w_pow.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/w_remainder.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/w_sinh.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/w_sqrt.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-noinstLTLIBRARIES ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags dvi dvi-am html html-am info info-am install \ + install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-pdf install-pdf-am install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ + pdf pdf-am ps ps-am tags uninstall uninstall-am + + +# We don't need extra includes, so no AM_CPPFLAGS. + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/libjava/classpath/native/fdlibm/dtoa.c b/libjava/classpath/native/fdlibm/dtoa.c new file mode 100644 index 000000000..458e629d3 --- /dev/null +++ b/libjava/classpath/native/fdlibm/dtoa.c @@ -0,0 +1,921 @@ +/**************************************************************** + * + * The author of this software is David M. Gay. + * + * Copyright (c) 1991, 2006 by AT&T. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose without fee is hereby granted, provided that this entire notice + * is included in all copies of any software which is or includes a copy + * or modification of this software and in all copies of the supporting + * documentation for such software. + * + * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY + * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY + * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. + * + ***************************************************************/ + +/* Please send bug reports to + David M. Gay + AT&T Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-2070 + U.S.A. + dmg@research.att.com or research!dmg + */ + +#include +#include +#include "mprec.h" +#include + +static int +_DEFUN (quorem, + (b, S), + _Jv_Bigint * b _AND _Jv_Bigint * S) +{ + int n; + long borrow, y; + unsigned long carry, q, ys; + unsigned long *bx, *bxe, *sx, *sxe; +#ifdef Pack_32 + long z; + unsigned long si, zs; +#endif + + n = S->_wds; +#ifdef DEBUG + /*debug*/ if (b->_wds > n) + /*debug*/ Bug ("oversize b in quorem"); +#endif + if (b->_wds < n) + return 0; + sx = S->_x; + sxe = sx + --n; + bx = b->_x; + bxe = bx + n; + q = *bxe / (*sxe + 1); /* ensure q <= true quotient */ +#ifdef DEBUG + /*debug*/ if (q > 9) + /*debug*/ Bug ("oversized quotient in quorem"); +#endif + if (q) + { + borrow = 0; + carry = 0; + do + { +#ifdef Pack_32 + si = *sx++; + ys = (si & 0xffff) * q + carry; + zs = (si >> 16) * q + (ys >> 16); + carry = zs >> 16; + y = (*bx & 0xffff) - (ys & 0xffff) + borrow; + borrow = y >> 16; + Sign_Extend (borrow, y); + z = (*bx >> 16) - (zs & 0xffff) + borrow; + borrow = z >> 16; + Sign_Extend (borrow, z); + Storeinc (bx, z, y); +#else + ys = *sx++ * q + carry; + carry = ys >> 16; + y = *bx - (ys & 0xffff) + borrow; + borrow = y >> 16; + Sign_Extend (borrow, y); + *bx++ = y & 0xffff; +#endif + } + while (sx <= sxe); + if (!*bxe) + { + bx = b->_x; + while (--bxe > bx && !*bxe) + --n; + b->_wds = n; + } + } + if (cmp (b, S) >= 0) + { + q++; + borrow = 0; + carry = 0; + bx = b->_x; + sx = S->_x; + do + { +#ifdef Pack_32 + si = *sx++; + ys = (si & 0xffff) + carry; + zs = (si >> 16) + (ys >> 16); + carry = zs >> 16; + y = (*bx & 0xffff) - (ys & 0xffff) + borrow; + borrow = y >> 16; + Sign_Extend (borrow, y); + z = (*bx >> 16) - (zs & 0xffff) + borrow; + borrow = z >> 16; + Sign_Extend (borrow, z); + Storeinc (bx, z, y); +#else + ys = *sx++ + carry; + carry = ys >> 16; + y = *bx - (ys & 0xffff) + borrow; + borrow = y >> 16; + Sign_Extend (borrow, y); + *bx++ = y & 0xffff; +#endif + } + while (sx <= sxe); + bx = b->_x; + bxe = bx + n; + if (!*bxe) + { + while (--bxe > bx && !*bxe) + --n; + b->_wds = n; + } + } + return q; +} + +#ifdef DEBUG +#include + +void +print (_Jv_Bigint * b) +{ + int i, wds; + unsigned long *x, y; + wds = b->_wds; + x = b->_x+wds; + i = 0; + do + { + x--; + fprintf (stderr, "%08x", *x); + } + while (++i < wds); + fprintf (stderr, "\n"); +} +#endif + +/* dtoa for IEEE arithmetic (dmg): convert double to ASCII string. + * + * Inspired by "How to Print Floating-Point Numbers Accurately" by + * Guy L. Steele, Jr. and Jon L. White [Proc. ACM SIGPLAN '90, pp. 92-101]. + * + * Modifications: + * 1. Rather than iterating, we use a simple numeric overestimate + * to determine k = floor(log10(d)). We scale relevant + * quantities using O(log2(k)) rather than O(k) multiplications. + * 2. For some modes > 2 (corresponding to ecvt and fcvt), we don't + * try to generate digits strictly left to right. Instead, we + * compute with fewer bits and propagate the carry if necessary + * when rounding the final digit up. This is often faster. + * 3. Under the assumption that input will be rounded nearest, + * mode 0 renders 1e23 as 1e23 rather than 9.999999999999999e22. + * That is, we allow equality in stopping tests when the + * round-nearest rule will give the same floating-point value + * as would satisfaction of the stopping test with strict + * inequality. + * 4. We remove common factors of powers of 2 from relevant + * quantities. + * 5. When converting floating-point integers less than 1e16, + * we use floating-point arithmetic rather than resorting + * to multiple-precision integers. + * 6. When asked to produce fewer than 15 digits, we first try + * to get by with floating-point arithmetic; we resort to + * multiple-precision integer arithmetic only if we cannot + * guarantee that the floating-point calculation has given + * the correctly rounded result. For k requested digits and + * "uniformly" distributed input, the probability is + * something like 10^(k-15) that we must resort to the long + * calculation. + */ + + +char * +_DEFUN (_dtoa_r, + (ptr, _d, mode, ndigits, decpt, sign, rve, float_type), + struct _Jv_reent *ptr _AND + double _d _AND + int mode _AND + int ndigits _AND + int *decpt _AND + int *sign _AND + char **rve _AND + int float_type) +{ + /* + float_type == 0 for double precision, 1 for float. + + Arguments ndigits, decpt, sign are similar to those + of ecvt and fcvt; trailing zeros are suppressed from + the returned string. If not null, *rve is set to point + to the end of the return value. If d is +-Infinity or NaN, + then *decpt is set to 9999. + + mode: + 0 ==> shortest string that yields d when read in + and rounded to nearest. + 1 ==> like 0, but with Steele & White stopping rule; + e.g. with IEEE P754 arithmetic , mode 0 gives + 1e23 whereas mode 1 gives 9.999999999999999e22. + 2 ==> max(1,ndigits) significant digits. This gives a + return value similar to that of ecvt, except + that trailing zeros are suppressed. + 3 ==> through ndigits past the decimal point. This + gives a return value similar to that from fcvt, + except that trailing zeros are suppressed, and + ndigits can be negative. + 4-9 should give the same return values as 2-3, i.e., + 4 <= mode <= 9 ==> same return as mode + 2 + (mode & 1). These modes are mainly for + debugging; often they run slower but sometimes + faster than modes 2-3. + 4,5,8,9 ==> left-to-right digit generation. + 6-9 ==> don't try fast floating-point estimate + (if applicable). + + > 16 ==> Floating-point arg is treated as single precision. + + Values of mode other than 0-9 are treated as mode 0. + + Sufficient space is allocated to the return value + to hold the suppressed trailing zeros. + */ + + int bbits, b2, b5, be, dig, i, ieps, ilim0, j, j1, k, k0, + k_check, leftright, m2, m5, s2, s5, try_quick; + int ilim = 0, ilim1 = 0, spec_case = 0; + union double_union d, d2, eps; + long L; +#ifndef Sudden_Underflow + int denorm; + unsigned long x; +#endif + _Jv_Bigint *b, *b1, *delta, *mlo = NULL, *mhi, *S; + double ds; + char *s, *s0; + + d.d = _d; + + if (ptr->_result) + { + ptr->_result->_k = ptr->_result_k; + ptr->_result->_maxwds = 1 << ptr->_result_k; + Bfree (ptr, ptr->_result); + ptr->_result = 0; + } + + if (word0 (d) & Sign_bit) + { + /* set sign for everything, including 0's and NaNs */ + *sign = 1; + word0 (d) &= ~Sign_bit; /* clear sign bit */ + } + else + *sign = 0; + +#if defined(IEEE_Arith) + defined(VAX) +#ifdef IEEE_Arith + if ((word0 (d) & Exp_mask) == Exp_mask) +#else + if (word0 (d) == 0x8000) +#endif + { + /* Infinity or NaN */ + *decpt = 9999; + s = +#ifdef IEEE_Arith + !word1 (d) && !(word0 (d) & 0xfffff) ? "Infinity" : +#endif + "NaN"; + if (rve) + *rve = +#ifdef IEEE_Arith + s[3] ? s + 8 : +#endif + s + 3; + return s; + } +#endif +#ifdef IBM + d.d += 0; /* normalize */ +#endif + if (!d.d) + { + *decpt = 1; + s = "0"; + if (rve) + *rve = s + 1; + return s; + } + + b = d2b (ptr, d.d, &be, &bbits); +#ifdef Sudden_Underflow + i = (int) (word0 (d) >> Exp_shift1 & (Exp_mask >> Exp_shift1)); +#else + if ((i = (int) (word0 (d) >> Exp_shift1 & (Exp_mask >> Exp_shift1)))) + { +#endif + d2.d = d.d; + word0 (d2) &= Frac_mask1; + word0 (d2) |= Exp_11; +#ifdef IBM + if (j = 11 - hi0bits (word0 (d2) & Frac_mask)) + d2.d /= 1 << j; +#endif + + /* log(x) ~=~ log(1.5) + (x-1.5)/1.5 + * log10(x) = log(x) / log(10) + * ~=~ log(1.5)/log(10) + (x-1.5)/(1.5*log(10)) + * log10(d) = (i-Bias)*log(2)/log(10) + log10(d2) + * + * This suggests computing an approximation k to log10(d) by + * + * k = (i - Bias)*0.301029995663981 + * + ( (d2-1.5)*0.289529654602168 + 0.176091259055681 ); + * + * We want k to be too large rather than too small. + * The error in the first-order Taylor series approximation + * is in our favor, so we just round up the constant enough + * to compensate for any error in the multiplication of + * (i - Bias) by 0.301029995663981; since |i - Bias| <= 1077, + * and 1077 * 0.30103 * 2^-52 ~=~ 7.2e-14, + * adding 1e-13 to the constant term more than suffices. + * Hence we adjust the constant term to 0.1760912590558. + * (We could get a more accurate k by invoking log10, + * but this is probably not worthwhile.) + */ + + i -= Bias; +#ifdef IBM + i <<= 2; + i += j; +#endif +#ifndef Sudden_Underflow + denorm = 0; + } + else + { + /* d is denormalized */ + + i = bbits + be + (Bias + (P - 1) - 1); + x = i > 32 ? word0 (d) << (64 - i) | word1 (d) >> (i - 32) + : word1 (d) << (32 - i); + d2.d = x; + word0 (d2) -= 31 * Exp_msk1; /* adjust exponent */ + i -= (Bias + (P - 1) - 1) + 1; + denorm = 1; + } +#endif + ds = (d2.d - 1.5) * 0.289529654602168 + 0.1760912590558 + i * 0.301029995663981; + k = (int) ds; + if (ds < 0. && ds != k) + k--; /* want k = floor(ds) */ + k_check = 1; + if (k >= 0 && k <= Ten_pmax) + { + if (d.d < tens[k]) + k--; + k_check = 0; + } + j = bbits - i - 1; + if (j >= 0) + { + b2 = 0; + s2 = j; + } + else + { + b2 = -j; + s2 = 0; + } + if (k >= 0) + { + b5 = 0; + s5 = k; + s2 += k; + } + else + { + b2 -= k; + b5 = -k; + s5 = 0; + } + if (mode < 0 || mode > 9) + mode = 0; + try_quick = 1; + if (mode > 5) + { + mode -= 4; + try_quick = 0; + } + leftright = 1; + switch (mode) + { + case 0: + case 1: + ilim = ilim1 = -1; + i = 18; + ndigits = 0; + break; + case 2: + leftright = 0; + /* no break */ + case 4: + if (ndigits <= 0) + ndigits = 1; + ilim = ilim1 = i = ndigits; + break; + case 3: + leftright = 0; + /* no break */ + case 5: + i = ndigits + k + 1; + ilim = i; + ilim1 = i - 1; + if (i <= 0) + i = 1; + } + j = sizeof (unsigned long); + for (ptr->_result_k = 0; (int) (sizeof (_Jv_Bigint) - sizeof (unsigned long)) + j <= i; + j <<= 1) + ptr->_result_k++; + ptr->_result = Balloc (ptr, ptr->_result_k); + s = s0 = (char *) ptr->_result; + + if (ilim >= 0 && ilim <= Quick_max && try_quick) + { + /* Try to get by with floating-point arithmetic. */ + + i = 0; + d2.d = d.d; + k0 = k; + ilim0 = ilim; + ieps = 2; /* conservative */ + if (k > 0) + { + ds = tens[k & 0xf]; + j = k >> 4; + if (j & Bletch) + { + /* prevent overflows */ + j &= Bletch - 1; + d.d /= bigtens[n_bigtens - 1]; + ieps++; + } + for (; j; j >>= 1, i++) + if (j & 1) + { + ieps++; + ds *= bigtens[i]; + } + d.d /= ds; + } + else if ((j1 = -k)) + { + d.d *= tens[j1 & 0xf]; + for (j = j1 >> 4; j; j >>= 1, i++) + if (j & 1) + { + ieps++; + d.d *= bigtens[i]; + } + } + if (k_check && d.d < 1. && ilim > 0) + { + if (ilim1 <= 0) + goto fast_failed; + ilim = ilim1; + k--; + d.d *= 10.; + ieps++; + } + eps.d = ieps * d.d + 7.; + word0 (eps) -= (P - 1) * Exp_msk1; + if (ilim == 0) + { + S = mhi = 0; + d.d -= 5.; + if (d.d > eps.d) + goto one_digit; + if (d.d < -eps.d) + goto no_digits; + goto fast_failed; + } +#ifndef No_leftright + if (leftright) + { + /* Use Steele & White method of only + * generating digits needed. + */ + eps.d = 0.5 / tens[ilim - 1] - eps.d; + for (i = 0;;) + { + L = d.d; + d.d -= L; + *s++ = '0' + (int) L; + if (d.d < eps.d) + goto ret1; + if (1. - d.d < eps.d) + goto bump_up; + if (++i >= ilim) + break; + eps.d *= 10.; + d.d *= 10.; + } + } + else + { +#endif + /* Generate ilim digits, then fix them up. */ + eps.d *= tens[ilim - 1]; + for (i = 1;; i++, d.d *= 10.) + { + L = d.d; + d.d -= L; + *s++ = '0' + (int) L; + if (i == ilim) + { + if (d.d > 0.5 + eps.d) + goto bump_up; + else if (d.d < 0.5 - eps.d) + { + while (*--s == '0'); + s++; + goto ret1; + } + break; + } + } +#ifndef No_leftright + } +#endif + fast_failed: + s = s0; + d.d = d2.d; + k = k0; + ilim = ilim0; + } + + /* Do we have a "small" integer? */ + + if (be >= 0 && k <= Int_max) + { + /* Yes. */ + ds = tens[k]; + if (ndigits < 0 && ilim <= 0) + { + S = mhi = 0; + if (ilim < 0 || d.d <= 5 * ds) + goto no_digits; + goto one_digit; + } + for (i = 1;; i++) + { + L = d.d / ds; + d.d -= L * ds; +#ifdef Check_FLT_ROUNDS + /* If FLT_ROUNDS == 2, L will usually be high by 1 */ + if (d.d < 0) + { + L--; + d.d += ds; + } +#endif + *s++ = '0' + (int) L; + if (i == ilim) + { + d.d += d.d; + if (d.d > ds || (d.d == ds && L & 1)) + { + bump_up: + while (*--s == '9') + if (s == s0) + { + k++; + *s = '0'; + break; + } + ++*s++; + } + break; + } + if (!(d.d *= 10.)) + break; + } + goto ret1; + } + + m2 = b2; + m5 = b5; + mhi = mlo = 0; + if (leftright) + { + if (mode < 2) + { + i = +#ifndef Sudden_Underflow + denorm ? be + (Bias + (P - 1) - 1 + 1) : +#endif +#ifdef IBM + 1 + 4 * P - 3 - bbits + ((bbits + be - 1) & 3); +#else + 1 + P - bbits; +#endif + } + else + { + j = ilim - 1; + if (m5 >= j) + m5 -= j; + else + { + s5 += j -= m5; + b5 += j; + m5 = 0; + } + if ((i = ilim) < 0) + { + m2 -= i; + i = 0; + } + } + b2 += i; + s2 += i; + mhi = i2b (ptr, 1); + } + if (m2 > 0 && s2 > 0) + { + i = m2 < s2 ? m2 : s2; + b2 -= i; + m2 -= i; + s2 -= i; + } + if (b5 > 0) + { + if (leftright) + { + if (m5 > 0) + { + mhi = pow5mult (ptr, mhi, m5); + b1 = mult (ptr, mhi, b); + Bfree (ptr, b); + b = b1; + } + if ((j = b5 - m5)) + b = pow5mult (ptr, b, j); + } + else + b = pow5mult (ptr, b, b5); + } + S = i2b (ptr, 1); + if (s5 > 0) + S = pow5mult (ptr, S, s5); + + /* Check for special case that d is a normalized power of 2. */ + + if (mode < 2) + { + if (!word1 (d) && !(word0 (d) & Bndry_mask) +#ifndef Sudden_Underflow + && word0(d) & Exp_mask +#endif + ) + { + /* The special case */ + b2 += Log2P; + s2 += Log2P; + spec_case = 1; + } + else + spec_case = 0; + } + + /* Arrange for convenient computation of quotients: + * shift left if necessary so divisor has 4 leading 0 bits. + * + * Perhaps we should just compute leading 28 bits of S once + * and for all and pass them and a shift to quorem, so it + * can do shifts and ors to compute the numerator for q. + */ + +#ifdef Pack_32 + if ((i = ((s5 ? 32 - hi0bits (S->_x[S->_wds - 1]) : 1) + s2) & 0x1f)) + i = 32 - i; +#else + if ((i = ((s5 ? 32 - hi0bits (S->_x[S->_wds - 1]) : 1) + s2) & 0xf)) + i = 16 - i; +#endif + if (i > 4) + { + i -= 4; + b2 += i; + m2 += i; + s2 += i; + } + else if (i < 4) + { + i += 28; + b2 += i; + m2 += i; + s2 += i; + } + if (b2 > 0) + b = lshift (ptr, b, b2); + if (s2 > 0) + S = lshift (ptr, S, s2); + if (k_check) + { + if (cmp (b, S) < 0) + { + k--; + b = multadd (ptr, b, 10, 0); /* we botched the k estimate */ + if (leftright) + mhi = multadd (ptr, mhi, 10, 0); + ilim = ilim1; + } + } + if (ilim <= 0 && mode > 2) + { + if (ilim < 0 || cmp (b, S = multadd (ptr, S, 5, 0)) <= 0) + { + /* no digits, fcvt style */ + no_digits: + k = -1 - ndigits; + goto ret; + } + one_digit: + *s++ = '1'; + k++; + goto ret; + } + if (leftright) + { + if (m2 > 0) + mhi = lshift (ptr, mhi, m2); + + /* Single precision case, */ + if (float_type) + mhi = lshift (ptr, mhi, 29); + + /* Compute mlo -- check for special case + * that d is a normalized power of 2. + */ + + mlo = mhi; + if (spec_case) + { + mhi = Balloc (ptr, mhi->_k); + Bcopy (mhi, mlo); + mhi = lshift (ptr, mhi, Log2P); + } + + for (i = 1;; i++) + { + dig = quorem (b, S) + '0'; + /* Do we yet have the shortest decimal string + * that will round to d? + */ + j = cmp (b, mlo); + delta = diff (ptr, S, mhi); + j1 = delta->_sign ? 1 : cmp (b, delta); + Bfree (ptr, delta); +#ifndef ROUND_BIASED + if (j1 == 0 && !mode && !(word1 (d) & 1)) + { + if (dig == '9') + goto round_9_up; + if (j > 0) + dig++; + *s++ = dig; + goto ret; + } +#endif + if (j < 0 || (j == 0 && !mode +#ifndef ROUND_BIASED + && !(word1 (d) & 1) +#endif + )) + { + if (j1 > 0) + { + b = lshift (ptr, b, 1); + j1 = cmp (b, S); + if ((j1 > 0 || (j1 == 0 && dig & 1)) + && dig++ == '9') + goto round_9_up; + } + *s++ = dig; + goto ret; + } + if (j1 > 0) + { + if (dig == '9') + { /* possible if i == 1 */ + round_9_up: + *s++ = '9'; + goto roundoff; + } + *s++ = dig + 1; + goto ret; + } + *s++ = dig; + if (i == ilim) + break; + b = multadd (ptr, b, 10, 0); + if (mlo == mhi) + mlo = mhi = multadd (ptr, mhi, 10, 0); + else + { + mlo = multadd (ptr, mlo, 10, 0); + mhi = multadd (ptr, mhi, 10, 0); + } + } + } + else + for (i = 1;; i++) + { + *s++ = dig = quorem (b, S) + '0'; + if (i >= ilim) + break; + b = multadd (ptr, b, 10, 0); + } + + /* Round off last digit */ + + b = lshift (ptr, b, 1); + j = cmp (b, S); + if (j > 0 || (j == 0 && dig & 1)) + { + roundoff: + while (*--s == '9') + if (s == s0) + { + k++; + *s++ = '1'; + goto ret; + } + ++*s++; + } + else + { + while (*--s == '0'); + s++; + } +ret: + Bfree (ptr, S); + if (mhi) + { + if (mlo && mlo != mhi) + Bfree (ptr, mlo); + Bfree (ptr, mhi); + } +ret1: + Bfree (ptr, b); + *s = 0; + *decpt = k + 1; + if (rve) + *rve = s; + return s0; +} + + +_VOID +_DEFUN (_dtoa, + (_d, mode, ndigits, decpt, sign, rve, buf, float_type), + double _d _AND + int mode _AND + int ndigits _AND + int *decpt _AND + int *sign _AND + char **rve _AND + char *buf _AND + int float_type) +{ + struct _Jv_reent reent; + char *p; + int i; + + memset (&reent, 0, sizeof reent); + + p = _dtoa_r (&reent, _d, mode, ndigits, decpt, sign, rve, float_type); + strcpy (buf, p); + + for (i = 0; i < reent._result_k; ++i) + { + struct _Jv_Bigint *l = reent._freelist[i]; + while (l) + { + struct _Jv_Bigint *next = l->_next; + free (l); + l = next; + } + } + if (reent._freelist) + free (reent._freelist); +} diff --git a/libjava/classpath/native/fdlibm/e_acos.c b/libjava/classpath/native/fdlibm/e_acos.c new file mode 100644 index 000000000..0350ee3ce --- /dev/null +++ b/libjava/classpath/native/fdlibm/e_acos.c @@ -0,0 +1,110 @@ + +/* @(#)e_acos.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* __ieee754_acos(x) + * Method : + * acos(x) = pi/2 - asin(x) + * acos(-x) = pi/2 + asin(x) + * For |x|<=0.5 + * acos(x) = pi/2 - (x + x*x^2*R(x^2)) (see asin.c) + * For x>0.5 + * acos(x) = pi/2 - (pi/2 - 2asin(sqrt((1-x)/2))) + * = 2asin(sqrt((1-x)/2)) + * = 2s + 2s*z*R(z) ...z=(1-x)/2, s=sqrt(z) + * = 2f + (2c + 2s*z*R(z)) + * where f=hi part of s, and c = (z-f*f)/(s+f) is the correction term + * for f so that f+c ~ sqrt(z). + * For x<-0.5 + * acos(x) = pi - 2asin(sqrt((1-|x|)/2)) + * = pi - 0.5*(s+s*z*R(z)), where z=(1-|x|)/2,s=sqrt(z) + * + * Special cases: + * if x is NaN, return x itself; + * if |x|>1, return NaN with invalid signal. + * + * Function needed: sqrt + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ +static const double +#else +static double +#endif +one= 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */ +pi = 3.14159265358979311600e+00, /* 0x400921FB, 0x54442D18 */ +pio2_hi = 1.57079632679489655800e+00, /* 0x3FF921FB, 0x54442D18 */ +pio2_lo = 6.12323399573676603587e-17, /* 0x3C91A626, 0x33145C07 */ +pS0 = 1.66666666666666657415e-01, /* 0x3FC55555, 0x55555555 */ +pS1 = -3.25565818622400915405e-01, /* 0xBFD4D612, 0x03EB6F7D */ +pS2 = 2.01212532134862925881e-01, /* 0x3FC9C155, 0x0E884455 */ +pS3 = -4.00555345006794114027e-02, /* 0xBFA48228, 0xB5688F3B */ +pS4 = 7.91534994289814532176e-04, /* 0x3F49EFE0, 0x7501B288 */ +pS5 = 3.47933107596021167570e-05, /* 0x3F023DE1, 0x0DFDF709 */ +qS1 = -2.40339491173441421878e+00, /* 0xC0033A27, 0x1C8A2D4B */ +qS2 = 2.02094576023350569471e+00, /* 0x40002AE5, 0x9C598AC8 */ +qS3 = -6.88283971605453293030e-01, /* 0xBFE6066C, 0x1B8D0159 */ +qS4 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */ + +#ifdef __STDC__ + double __ieee754_acos(double x) +#else + double __ieee754_acos(x) + double x; +#endif +{ + double z,p,q,r,w,s,c,df; + int32_t hx,ix; + GET_HIGH_WORD(hx,x); + ix = hx&0x7fffffff; + if(ix>=0x3ff00000) { /* |x| >= 1 */ + int32_t lx; + GET_LOW_WORD(lx,x); + if(((ix-0x3ff00000)|lx)==0) { /* |x|==1 */ + if(hx>0) return 0.0; /* acos(1) = 0 */ + else return pi+2.0*pio2_lo; /* acos(-1)= pi */ + } + return (x-x)/(x-x); /* acos(|x|>1) is NaN */ + } + if(ix<0x3fe00000) { /* |x| < 0.5 */ + if(ix<=0x3c600000) return pio2_hi+pio2_lo;/*if|x|<2**-57*/ + z = x*x; + p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5))))); + q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4))); + r = p/q; + return pio2_hi - (x - (pio2_lo-x*r)); + } else if (hx<0) { /* x < -0.5 */ + z = (one+x)*0.5; + p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5))))); + q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4))); + s = __ieee754_sqrt(z); + r = p/q; + w = r*s-pio2_lo; + return pi - 2.0*(s+w); + } else { /* x > 0.5 */ + z = (one-x)*0.5; + s = __ieee754_sqrt(z); + df = s; + SET_LOW_WORD(df,0); + c = (z-df*df)/(s+df); + p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5))))); + q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4))); + r = p/q; + w = r*s+c; + return 2.0*(df+w); + } +} +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/classpath/native/fdlibm/e_asin.c b/libjava/classpath/native/fdlibm/e_asin.c new file mode 100644 index 000000000..6c1efd31c --- /dev/null +++ b/libjava/classpath/native/fdlibm/e_asin.c @@ -0,0 +1,119 @@ + +/* @(#)e_asin.c 1.4 96/03/07 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* __ieee754_asin(x) + * Method : + * Since asin(x) = x + x^3/6 + x^5*3/40 + x^7*15/336 + ... + * we approximate asin(x) on [0,0.5] by + * asin(x) = x + x*x^2*R(x^2) + * where + * R(x^2) is a rational approximation of (asin(x)-x)/x^3 + * and its Remes error is bounded by + * |(asin(x)-x)/x^3 - R(x^2)| < 2^(-58.75) + * + * For x in [0.5,1] + * asin(x) = pi/2-2*asin(sqrt((1-x)/2)) + * Let y = (1-x), z = y/2, s := sqrt(z), and pio2_hi+pio2_lo=pi/2; + * then for x>0.98 + * asin(x) = pi/2 - 2*(s+s*z*R(z)) + * = pio2_hi - (2*(s+s*z*R(z)) - pio2_lo) + * For x<=0.98, let pio4_hi = pio2_hi/2, then + * f = hi part of s; + * c = sqrt(z) - f = (z-f*f)/(s+f) ...f+c=sqrt(z) + * and + * asin(x) = pi/2 - 2*(s+s*z*R(z)) + * = pio4_hi+(pio4-2s)-(2s*z*R(z)-pio2_lo) + * = pio4_hi+(pio4-2f)-(2s*z*R(z)-(pio2_lo+2c)) + * + * Special cases: + * if x is NaN, return x itself; + * if |x|>1, return NaN with invalid signal. + * + */ + + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ +static const double +#else +static double +#endif +one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */ +huge = 1.000e+300, +pio2_hi = 1.57079632679489655800e+00, /* 0x3FF921FB, 0x54442D18 */ +pio2_lo = 6.12323399573676603587e-17, /* 0x3C91A626, 0x33145C07 */ +pio4_hi = 7.85398163397448278999e-01, /* 0x3FE921FB, 0x54442D18 */ + /* coefficient for R(x^2) */ +pS0 = 1.66666666666666657415e-01, /* 0x3FC55555, 0x55555555 */ +pS1 = -3.25565818622400915405e-01, /* 0xBFD4D612, 0x03EB6F7D */ +pS2 = 2.01212532134862925881e-01, /* 0x3FC9C155, 0x0E884455 */ +pS3 = -4.00555345006794114027e-02, /* 0xBFA48228, 0xB5688F3B */ +pS4 = 7.91534994289814532176e-04, /* 0x3F49EFE0, 0x7501B288 */ +pS5 = 3.47933107596021167570e-05, /* 0x3F023DE1, 0x0DFDF709 */ +qS1 = -2.40339491173441421878e+00, /* 0xC0033A27, 0x1C8A2D4B */ +qS2 = 2.02094576023350569471e+00, /* 0x40002AE5, 0x9C598AC8 */ +qS3 = -6.88283971605453293030e-01, /* 0xBFE6066C, 0x1B8D0159 */ +qS4 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */ + +#ifdef __STDC__ + double __ieee754_asin(double x) +#else + double __ieee754_asin(x) + double x; +#endif +{ + double t,w,p,q,c,r,s; + int32_t hx,ix; + GET_HIGH_WORD(hx,x); + ix = hx&0x7fffffff; + if(ix>= 0x3ff00000) { /* |x|>= 1 */ + uint32_t lx; + GET_LOW_WORD(lx,x); + if(((ix-0x3ff00000)|lx)==0) + /* asin(1)=+-pi/2 with inexact */ + return x*pio2_hi+x*pio2_lo; + return (x-x)/(x-x); /* asin(|x|>1) is NaN */ + } else if (ix<0x3fe00000) { /* |x|<0.5 */ + if(ix<0x3e400000) { /* if |x| < 2**-27 */ + if(huge+x>one) return x;/* return x with inexact if x!=0*/ + } else + t = x*x; + p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5))))); + q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4))); + w = p/q; + return x+x*w; + } + /* 1> |x|>= 0.5 */ + w = one-fabs(x); + t = w*0.5; + p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5))))); + q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4))); + s = __ieee754_sqrt(t); + if(ix>=0x3FEF3333) { /* if |x| > 0.975 */ + w = p/q; + t = pio2_hi-(2.0*(s+s*w)-pio2_lo); + } else { + w = s; + SET_LOW_WORD(w,0); + c = (t-w*w)/(s+w); + r = p/q; + p = 2.0*s*r-(pio2_lo-2.0*c); + q = pio4_hi-2.0*w; + t = pio4_hi-(p-q); + } + if(hx>0) return t; else return -t; +} +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/classpath/native/fdlibm/e_atan2.c b/libjava/classpath/native/fdlibm/e_atan2.c new file mode 100644 index 000000000..94491eecb --- /dev/null +++ b/libjava/classpath/native/fdlibm/e_atan2.c @@ -0,0 +1,131 @@ + +/* @(#)e_atan2.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + * + */ + +/* __ieee754_atan2(y,x) + * Method : + * 1. Reduce y to positive by atan2(y,x)=-atan2(-y,x). + * 2. Reduce x to positive by (if x and y are unexceptional): + * ARG (x+iy) = arctan(y/x) ... if x > 0, + * ARG (x+iy) = pi - arctan[y/(-x)] ... if x < 0, + * + * Special cases: + * + * ATAN2((anything), NaN ) is NaN; + * ATAN2(NAN , (anything) ) is NaN; + * ATAN2(+-0, +(anything but NaN)) is +-0 ; + * ATAN2(+-0, -(anything but NaN)) is +-pi ; + * ATAN2(+-(anything but 0 and NaN), 0) is +-pi/2; + * ATAN2(+-(anything but INF and NaN), +INF) is +-0 ; + * ATAN2(+-(anything but INF and NaN), -INF) is +-pi; + * ATAN2(+-INF,+INF ) is +-pi/4 ; + * ATAN2(+-INF,-INF ) is +-3pi/4; + * ATAN2(+-INF, (anything but,0,NaN, and INF)) is +-pi/2; + * + * Constants: + * The hexadecimal values are the intended ones for the following + * constants. The decimal values may be used, provided that the + * compiler will convert from decimal to binary accurately enough + * to produce the hexadecimal values shown. + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ +static const double +#else +static double +#endif +tiny = 1.0e-300, +zero = 0.0, +pi_o_4 = 7.8539816339744827900E-01, /* 0x3FE921FB, 0x54442D18 */ +pi_o_2 = 1.5707963267948965580E+00, /* 0x3FF921FB, 0x54442D18 */ +pi = 3.1415926535897931160E+00, /* 0x400921FB, 0x54442D18 */ +pi_lo = 1.2246467991473531772E-16; /* 0x3CA1A626, 0x33145C07 */ + +#ifdef __STDC__ + double __ieee754_atan2(double y, double x) +#else + double __ieee754_atan2(y,x) + double y,x; +#endif +{ + double z; + int32_t k,m,hx,hy,ix,iy; + uint32_t lx,ly; + + EXTRACT_WORDS(hx,lx,x); + ix = hx&0x7fffffff; + EXTRACT_WORDS(hy,ly,y); + iy = hy&0x7fffffff; + if(((ix|((lx|-lx)>>31))>0x7ff00000)|| + ((iy|((ly|-ly)>>31))>0x7ff00000)) /* x or y is NaN */ + return x+y; + if(((hx-0x3ff00000)|lx)==0) return atan(y); /* x=1.0 */ + m = ((hy>>31)&1)|((hx>>30)&2); /* 2*sign(x)+sign(y) */ + + /* when y = 0 */ + if((iy|ly)==0) { + switch(m) { + case 0: + case 1: return y; /* atan(+-0,+anything)=+-0 */ + case 2: return pi+tiny;/* atan(+0,-anything) = pi */ + case 3: return -pi-tiny;/* atan(-0,-anything) =-pi */ + } + } + /* when x = 0 */ + if((ix|lx)==0) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny; + + /* when x is INF */ + if(ix==0x7ff00000) { + if(iy==0x7ff00000) { + switch(m) { + case 0: return pi_o_4+tiny;/* atan(+INF,+INF) */ + case 1: return -pi_o_4-tiny;/* atan(-INF,+INF) */ + case 2: return 3.0*pi_o_4+tiny;/*atan(+INF,-INF)*/ + case 3: return -3.0*pi_o_4-tiny;/*atan(-INF,-INF)*/ + } + } else { + switch(m) { + case 0: return zero ; /* atan(+...,+INF) */ + case 1: return -zero ; /* atan(-...,+INF) */ + case 2: return pi+tiny ; /* atan(+...,-INF) */ + case 3: return -pi-tiny ; /* atan(-...,-INF) */ + } + } + } + /* when y is INF */ + if(iy==0x7ff00000) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny; + + /* compute y/x */ + k = (iy-ix)>>20; + if(k > 60) z=pi_o_2+0.5*pi_lo; /* |y/x| > 2**60 */ + else if(hx<0&&k<-60) z=0.0; /* |y|/x < -2**60 */ + else z=atan(fabs(y/x)); /* safe to do y/x */ + switch (m) { + case 0: return z ; /* atan(+,+) */ + case 1: { + uint32_t zh; + GET_HIGH_WORD(zh,z); + SET_HIGH_WORD(z, zh ^ 0x80000000); + } + return z ; /* atan(-,+) */ + case 2: return pi-(z-pi_lo);/* atan(+,-) */ + default: /* case 3 */ + return (z-pi_lo)-pi;/* atan(-,-) */ + } +} + +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/classpath/native/fdlibm/e_cosh.c b/libjava/classpath/native/fdlibm/e_cosh.c new file mode 100644 index 000000000..5d731ced0 --- /dev/null +++ b/libjava/classpath/native/fdlibm/e_cosh.c @@ -0,0 +1,92 @@ + +/* @(#)e_cosh.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* __ieee754_cosh(x) + * Method : + * mathematically cosh(x) if defined to be (exp(x)+exp(-x))/2 + * 1. Replace x by |x| (cosh(x) = cosh(-x)). + * 2. + * [ exp(x) - 1 ]^2 + * 0 <= x <= ln2/2 : cosh(x) := 1 + ------------------- + * 2*exp(x) + * + * exp(x) + 1/exp(x) + * ln2/2 <= x <= 22 : cosh(x) := ------------------- + * 2 + * 22 <= x <= lnovft : cosh(x) := exp(x)/2 + * lnovft <= x <= ln2ovft: cosh(x) := exp(x/2)/2 * exp(x/2) + * ln2ovft < x : cosh(x) := huge*huge (overflow) + * + * Special cases: + * cosh(x) is |x| if x is +INF, -INF, or NaN. + * only cosh(0)=1 is exact for finite x. + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ +static const double one = 1.0, half=0.5, huge = 1.0e300; +#else +static double one = 1.0, half=0.5, huge = 1.0e300; +#endif + +#ifdef __STDC__ + double __ieee754_cosh(double x) +#else + double __ieee754_cosh(x) + double x; +#endif +{ + double t,w; + int32_t ix; + uint32_t lx; + + /* High word of |x|. */ + GET_HIGH_WORD(ix,x); + ix &= 0x7fffffff; + + /* x is INF or NaN */ + if(ix>=0x7ff00000) return x*x; + + /* |x| in [0,0.5*ln2], return 1+expm1(|x|)^2/(2*exp(|x|)) */ + if(ix<0x3fd62e43) { + t = expm1(fabs(x)); + w = one+t; + if (ix<0x3c800000) return w; /* cosh(tiny) = 1 */ + return one+(t*t)/(w+w); + } + + /* |x| in [0.5*ln2,22], return (exp(|x|)+1/exp(|x|)/2; */ + if (ix < 0x40360000) { + t = __ieee754_exp(fabs(x)); + return half*t+half/t; + } + + /* |x| in [22, log(maxdouble)] return half*exp(|x|) */ + if (ix < 0x40862E42) return half*__ieee754_exp(fabs(x)); + + /* |x| in [log(maxdouble), overflowthresold] */ + lx = *( (((*(unsigned*)&one)>>29)) + (unsigned*)&x); + if (ix<0x408633CE || + (ix==0x408633ce)&&(lx<=(unsigned)0x8fb9f87d)) { + w = __ieee754_exp(half*fabs(x)); + t = half*w; + return t*w; + } + + /* |x| > overflowthresold, cosh(x) overflow */ + return huge*huge; +} +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/classpath/native/fdlibm/e_exp.c b/libjava/classpath/native/fdlibm/e_exp.c new file mode 100644 index 000000000..985150a3a --- /dev/null +++ b/libjava/classpath/native/fdlibm/e_exp.c @@ -0,0 +1,165 @@ + +/* @(#)e_exp.c 1.6 04/04/22 */ +/* + * ==================================================== + * Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved. + * + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* __ieee754_exp(x) + * Returns the exponential of x. + * + * Method + * 1. Argument reduction: + * Reduce x to an r so that |r| <= 0.5*ln2 ~ 0.34658. + * Given x, find r and integer k such that + * + * x = k*ln2 + r, |r| <= 0.5*ln2. + * + * Here r will be represented as r = hi-lo for better + * accuracy. + * + * 2. Approximation of exp(r) by a special rational function on + * the interval [0,0.34658]: + * Write + * R(r**2) = r*(exp(r)+1)/(exp(r)-1) = 2 + r*r/6 - r**4/360 + ... + * We use a special Remes algorithm on [0,0.34658] to generate + * a polynomial of degree 5 to approximate R. The maximum error + * of this polynomial approximation is bounded by 2**-59. In + * other words, + * R(z) ~ 2.0 + P1*z + P2*z**2 + P3*z**3 + P4*z**4 + P5*z**5 + * (where z=r*r, and the values of P1 to P5 are listed below) + * and + * | 5 | -59 + * | 2.0+P1*z+...+P5*z - R(z) | <= 2 + * | | + * The computation of exp(r) thus becomes + * 2*r + * exp(r) = 1 + ------- + * R - r + * r*R1(r) + * = 1 + r + ----------- (for better accuracy) + * 2 - R1(r) + * where + * 2 4 10 + * R1(r) = r - (P1*r + P2*r + ... + P5*r ). + * + * 3. Scale back to obtain exp(x): + * From step 1, we have + * exp(x) = 2^k * exp(r) + * + * Special cases: + * exp(INF) is INF, exp(NaN) is NaN; + * exp(-INF) is 0, and + * for finite argument, only exp(0)=1 is exact. + * + * Accuracy: + * according to an error analysis, the error is always less than + * 1 ulp (unit in the last place). + * + * Misc. info. + * For IEEE double + * if x > 7.09782712893383973096e+02 then exp(x) overflow + * if x < -7.45133219101941108420e+02 then exp(x) underflow + * + * Constants: + * The hexadecimal values are the intended ones for the following + * constants. The decimal values may be used, provided that the + * compiler will convert from decimal to binary accurately enough + * to produce the hexadecimal values shown. + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ +static const double +#else +static double +#endif +one = 1.0, +halF[2] = {0.5,-0.5,}, +huge = 1.0e+300, +twom1000= 9.33263618503218878990e-302, /* 2**-1000=0x01700000,0*/ +o_threshold= 7.09782712893383973096e+02, /* 0x40862E42, 0xFEFA39EF */ +u_threshold= -7.45133219101941108420e+02, /* 0xc0874910, 0xD52D3051 */ +ln2HI[2] ={ 6.93147180369123816490e-01, /* 0x3fe62e42, 0xfee00000 */ + -6.93147180369123816490e-01,},/* 0xbfe62e42, 0xfee00000 */ +ln2LO[2] ={ 1.90821492927058770002e-10, /* 0x3dea39ef, 0x35793c76 */ + -1.90821492927058770002e-10,},/* 0xbdea39ef, 0x35793c76 */ +invln2 = 1.44269504088896338700e+00, /* 0x3ff71547, 0x652b82fe */ +P1 = 1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */ +P2 = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */ +P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */ +P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */ +P5 = 4.13813679705723846039e-08; /* 0x3E663769, 0x72BEA4D0 */ + + +#ifdef __STDC__ + double __ieee754_exp(double x) /* default IEEE double exp */ +#else + double __ieee754_exp(x) /* default IEEE double exp */ + double x; +#endif +{ + double y,hi,lo,c,t; + int32_t k,xsb; + uint32_t hx; + + GET_HIGH_WORD(hx,x); /* high word of x */ + xsb = (hx>>31)&1; /* sign bit of x */ + hx &= 0x7fffffff; /* high word of |x| */ + + /* filter out non-finite argument */ + if(hx >= 0x40862E42) { /* if |x|>=709.78... */ + if(hx>=0x7ff00000) { + uint32_t lx; + GET_LOW_WORD(lx,x); + if(((hx&0xfffff)|lx)!=0) + return x+x; /* NaN */ + else return (xsb==0)? x:0.0; /* exp(+-inf)={inf,0} */ + } + if(x > o_threshold) return huge*huge; /* overflow */ + if(x < u_threshold) return twom1000*twom1000; /* underflow */ + } + + /* argument reduction */ + if(hx > 0x3fd62e42) { /* if |x| > 0.5 ln2 */ + if(hx < 0x3FF0A2B2) { /* and |x| < 1.5 ln2 */ + hi = x-ln2HI[xsb]; lo=ln2LO[xsb]; k = 1-xsb-xsb; + } else { + k = (int32_t)(invln2*x+halF[xsb]); + t = k; + hi = x - t*ln2HI[0]; /* t*ln2HI is exact here */ + lo = t*ln2LO[0]; + } + x = hi - lo; + } + else if(hx < 0x3e300000) { /* when |x|<2**-28 */ + if(huge+x>one) return one+x;/* trigger inexact */ + } + else k = 0; + + /* x is now in primary range */ + t = x*x; + c = x - t*(P1+t*(P2+t*(P3+t*(P4+t*P5)))); + if(k==0) return one-((x*c)/(c-2.0)-x); + else y = one-((lo-(x*c)/(2.0-c))-hi); + if(k >= -1021) { + uint32_t hy; + GET_HIGH_WORD(hy, y); + SET_HIGH_WORD(y, hy + (k<<20)); /* add k to y's exponent */ + return y; + } else { + uint32_t hy; + GET_HIGH_WORD(hy, y); + SET_HIGH_WORD(y, hy + ((k+1000)<<20));/* add k to y's exponent */ + return y*twom1000; + } +} +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/classpath/native/fdlibm/e_fmod.c b/libjava/classpath/native/fdlibm/e_fmod.c new file mode 100644 index 000000000..e3dd4bf91 --- /dev/null +++ b/libjava/classpath/native/fdlibm/e_fmod.c @@ -0,0 +1,139 @@ + +/* @(#)e_fmod.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* + * __ieee754_fmod(x,y) + * Return x mod y in exact arithmetic + * Method: shift and subtract + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ +static const double one = 1.0, Zero[] = {0.0, -0.0,}; +#else +static double one = 1.0, Zero[] = {0.0, -0.0,}; +#endif + +#ifdef __STDC__ + double __ieee754_fmod(double x, double y) +#else + double __ieee754_fmod(x,y) + double x,y ; +#endif +{ + int32_t n,hx,hy,hz,ix,iy,sx,i; + uint32_t lx,ly,lz; + + EXTRACT_WORDS(hx,lx,x); + EXTRACT_WORDS(hy,ly,y); + sx = hx&0x80000000; /* sign of x */ + hx ^=sx; /* |x| */ + hy &= 0x7fffffff; /* |y| */ + + /* purge off exception values */ + if((hy|ly)==0||(hx>=0x7ff00000)|| /* y=0,or x not finite */ + ((hy|((ly|-ly)>>31))>0x7ff00000)) /* or y is NaN */ + return (x*y)/(x*y); + if(hx<=hy) { + if((hx>31]; /* |x|=|y| return x*0*/ + } + + /* determine ix = ilogb(x) */ + if(hx<0x00100000) { /* subnormal x */ + if(hx==0) { + for (ix = -1043, i=lx; i>0; i<<=1) ix -=1; + } else { + for (ix = -1022,i=(hx<<11); i>0; i<<=1) ix -=1; + } + } else ix = (hx>>20)-1023; + + /* determine iy = ilogb(y) */ + if(hy<0x00100000) { /* subnormal y */ + if(hy==0) { + for (iy = -1043, i=ly; i>0; i<<=1) iy -=1; + } else { + for (iy = -1022,i=(hy<<11); i>0; i<<=1) iy -=1; + } + } else iy = (hy>>20)-1023; + + /* set up {hx,lx}, {hy,ly} and align y to x */ + if(ix >= -1022) + hx = 0x00100000|(0x000fffff&hx); + else { /* subnormal x, shift x to normal */ + n = -1022-ix; + if(n<=31) { + hx = (hx<>(32-n)); + lx <<= n; + } else { + hx = lx<<(n-32); + lx = 0; + } + } + if(iy >= -1022) + hy = 0x00100000|(0x000fffff&hy); + else { /* subnormal y, shift y to normal */ + n = -1022-iy; + if(n<=31) { + hy = (hy<>(32-n)); + ly <<= n; + } else { + hy = ly<<(n-32); + ly = 0; + } + } + + /* fix point fmod */ + n = ix - iy; + while(n--) { + hz=hx-hy;lz=lx-ly; if(lx>31); lx = lx+lx;} + else { + if((hz|lz)==0) /* return sign(x)*0 */ + return Zero[(uint32_t)sx>>31]; + hx = hz+hz+(lz>>31); lx = lz+lz; + } + } + hz=hx-hy;lz=lx-ly; if(lx=0) {hx=hz;lx=lz;} + + /* convert back to floating value and restore the sign */ + if((hx|lx)==0) /* return sign(x)*0 */ + return Zero[(unsigned)sx>>31]; + while(hx<0x00100000) { /* normalize x */ + hx = hx+hx+(lx>>31); lx = lx+lx; + iy -= 1; + } + if(iy>= -1022) { /* normalize output */ + hx = ((hx-0x00100000)|((iy+1023)<<20)); + INSERT_WORDS(x,hx|sx,lx); + } else { /* subnormal output */ + n = -1022 - iy; + if(n<=20) { + lx = (lx>>n)|((uint32_t)hx<<(32-n)); + hx >>= n; + } else if (n<=31) { + lx = (hx<<(32-n))|(lx>>n); hx = sx; + } else { + lx = hx>>(n-32); hx = sx; + } + INSERT_WORDS(x,hx|sx,lx); + x *= one; /* create necessary signal */ + } + return x; /* exact output */ +} +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/classpath/native/fdlibm/e_hypot.c b/libjava/classpath/native/fdlibm/e_hypot.c new file mode 100644 index 000000000..39462879f --- /dev/null +++ b/libjava/classpath/native/fdlibm/e_hypot.c @@ -0,0 +1,129 @@ + +/* @(#)e_hypot.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* __ieee754_hypot(x,y) + * + * Method : + * If (assume round-to-nearest) z=x*x+y*y + * has error less than sqrt(2)/2 ulp, than + * sqrt(z) has error less than 1 ulp (exercise). + * + * So, compute sqrt(x*x+y*y) with some care as + * follows to get the error below 1 ulp: + * + * Assume x>y>0; + * (if possible, set rounding to round-to-nearest) + * 1. if x > 2y use + * x1*x1+(y*y+(x2*(x+x1))) for x*x+y*y + * where x1 = x with lower 32 bits cleared, x2 = x-x1; else + * 2. if x <= 2y use + * t1*y1+((x-y)*(x-y)+(t1*y2+t2*y)) + * where t1 = 2x with lower 32 bits cleared, t2 = 2x-t1, + * y1= y with lower 32 bits chopped, y2 = y-y1. + * + * NOTE: scaling may be necessary if some argument is too + * large or too tiny + * + * Special cases: + * hypot(x,y) is INF if x or y is +INF or -INF; else + * hypot(x,y) is NAN if x or y is NAN. + * + * Accuracy: + * hypot(x,y) returns sqrt(x^2+y^2) with error less + * than 1 ulps (units in the last place) + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double __ieee754_hypot(double x, double y) +#else + double __ieee754_hypot(x,y) + double x, y; +#endif +{ + double a=x,b=y,t1,t2,y1,y2,w; + uint32_t j,k,ha,hb,hx,hy; + + GET_HIGH_WORD(hx,x); + GET_HIGH_WORD(hy,y); + ha = hx&0x7fffffff; /* high word of x */ + hb = hy&0x7fffffff; /* high word of y */ + if(hb > ha) {a=y;b=x;j=ha; ha=hb;hb=j;} else {a=x;b=y;} + SET_HIGH_WORD(a,ha); /* a <- |a| */ + SET_HIGH_WORD(b,hb); /* b <- |b| */ + if((ha-hb)>0x3c00000) {return a+b;} /* x/y > 2**60 */ + k=0; + if(ha > 0x5f300000) { /* a>2**500 */ + if(ha >= 0x7ff00000) { /* Inf or NaN */ + uint32_t la, lb; + w = a+b; /* for sNaN */ + GET_LOW_WORD(la,a); + GET_LOW_WORD(lb,b); + if(((ha&0xfffff)|la)==0) w = a; + if(((hb^0x7ff00000)|lb)==0) w = b; + return w; + } + /* scale a and b by 2**-600 */ + ha -= 0x25800000; hb -= 0x25800000; k += 600; + SET_HIGH_WORD(a,ha); + SET_HIGH_WORD(b,hb); + } + if(hb < 0x20b00000) { /* b < 2**-500 */ + if(hb <= 0x000fffff) { /* subnormal b or 0 */ + uint32_t lb; + GET_LOW_WORD(lb,b); + if((hb|lb)==0) return a; + t1=0; + SET_HIGH_WORD(t1, 0x7fd00000); /* t1=2^1022 */ + b *= t1; + a *= t1; + k -= 1022; + } else { /* scale a and b by 2^600 */ + ha += 0x25800000; /* a *= 2^600 */ + hb += 0x25800000; /* b *= 2^600 */ + k -= 600; + + SET_HIGH_WORD(a,ha); + SET_HIGH_WORD(b,hb); + } + } + /* medium size a and b */ + w = a-b; + if (w>b) { + t1 = 0; + SET_HIGH_WORD(t1, ha); + t2 = a-t1; + w = sqrt(t1*t1-(b*(-b)-t2*(a+t1))); + } else { + a = a+a; + y1 = 0; + SET_HIGH_WORD(y1, hb); + y2 = b - y1; + t1 = 0; + SET_HIGH_WORD(t1, ha+0x00100000); + t2 = a - t1; + w = sqrt(t1*y1-(w*(-w)-(t1*y2+t2*b))); + } + if(k!=0) { + uint32_t ht1; + + t1 = 1.0; + GET_HIGH_WORD(ht1, t1); + SET_HIGH_WORD(t1, ht1 + (k<<20)); + return t1*w; + } else return w; +} +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/classpath/native/fdlibm/e_log.c b/libjava/classpath/native/fdlibm/e_log.c new file mode 100644 index 000000000..dede84d09 --- /dev/null +++ b/libjava/classpath/native/fdlibm/e_log.c @@ -0,0 +1,151 @@ + +/* @(#)e_log.c 1.4 96/03/07 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* __ieee754_log(x) + * Return the logrithm of x + * + * Method : + * 1. Argument Reduction: find k and f such that + * x = 2^k * (1+f), + * where sqrt(2)/2 < 1+f < sqrt(2) . + * + * 2. Approximation of log(1+f). + * Let s = f/(2+f) ; based on log(1+f) = log(1+s) - log(1-s) + * = 2s + 2/3 s**3 + 2/5 s**5 + ....., + * = 2s + s*R + * We use a special Remes algorithm on [0,0.1716] to generate + * a polynomial of degree 14 to approximate R The maximum error + * of this polynomial approximation is bounded by 2**-58.45. In + * other words, + * 2 4 6 8 10 12 14 + * R(z) ~ Lg1*s +Lg2*s +Lg3*s +Lg4*s +Lg5*s +Lg6*s +Lg7*s + * (the values of Lg1 to Lg7 are listed in the program) + * and + * | 2 14 | -58.45 + * | Lg1*s +...+Lg7*s - R(z) | <= 2 + * | | + * Note that 2s = f - s*f = f - hfsq + s*hfsq, where hfsq = f*f/2. + * In order to guarantee error in log below 1ulp, we compute log + * by + * log(1+f) = f - s*(f - R) (if f is not too large) + * log(1+f) = f - (hfsq - s*(hfsq+R)). (better accuracy) + * + * 3. Finally, log(x) = k*ln2 + log(1+f). + * = k*ln2_hi+(f-(hfsq-(s*(hfsq+R)+k*ln2_lo))) + * Here ln2 is split into two floating point number: + * ln2_hi + ln2_lo, + * where n*ln2_hi is always exact for |n| < 2000. + * + * Special cases: + * log(x) is NaN with signal if x < 0 (including -INF) ; + * log(+INF) is +INF; log(0) is -INF with signal; + * log(NaN) is that NaN with no signal. + * + * Accuracy: + * according to an error analysis, the error is always less than + * 1 ulp (unit in the last place). + * + * Constants: + * The hexadecimal values are the intended ones for the following + * constants. The decimal values may be used, provided that the + * compiler will convert from decimal to binary accurately enough + * to produce the hexadecimal values shown. + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ +static const double +#else +static double +#endif +ln2_hi = 6.93147180369123816490e-01, /* 3fe62e42 fee00000 */ +ln2_lo = 1.90821492927058770002e-10, /* 3dea39ef 35793c76 */ +two54 = 1.80143985094819840000e+16, /* 43500000 00000000 */ +Lg1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */ +Lg2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */ +Lg3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */ +Lg4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */ +Lg5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */ +Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */ +Lg7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */ + +#ifdef __STDC__ +static const double zero = 0.0; +#else +static double zero = 0.0; +#endif + +#ifdef __STDC__ + double __ieee754_log(double x) +#else + double __ieee754_log(x) + double x; +#endif +{ + double hfsq,f,s,z,R,w,t1,t2,dk; + int32_t k,hx,i,j; + uint32_t lx; + + EXTRACT_WORDS(hx,lx,x); + + k=0; + if (hx < 0x00100000) { /* x < 2**-1022 */ + if (((hx&0x7fffffff)|lx)==0) + return -two54/zero; /* log(+-0)=-inf */ + if (hx<0) return (x-x)/zero; /* log(-#) = NaN */ + k -= 54; x *= two54; /* subnormal number, scale up x */ + GET_HIGH_WORD(hx,x); /* high word of x */ + } + if (hx >= 0x7ff00000) return x+x; + k += (hx>>20)-1023; + hx &= 0x000fffff; + i = (hx+0x95f64)&0x100000; + SET_HIGH_WORD(x,hx|(i^0x3ff00000)); /* normalize x or x/2 */ + k += (i>>20); + f = x-1.0; + if((0x000fffff&(2+hx))<3) { /* |f| < 2**-20 */ + if(f==zero) { + if(k==0) + return zero; + else { + dk=(double)k; + return dk*ln2_hi+dk*ln2_lo; + } + } + R = f*f*(0.5-0.33333333333333333*f); + if(k==0) return f-R; else {dk=(double)k; + return dk*ln2_hi-((R-dk*ln2_lo)-f);} + } + s = f/(2.0+f); + dk = (double)k; + z = s*s; + i = hx-0x6147a; + w = z*z; + j = 0x6b851-hx; + t1= w*(Lg2+w*(Lg4+w*Lg6)); + t2= z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7))); + i |= j; + R = t2+t1; + if(i>0) { + hfsq=0.5*f*f; + if(k==0) return f-(hfsq-s*(hfsq+R)); else + return dk*ln2_hi-((hfsq-(s*(hfsq+R)+dk*ln2_lo))-f); + } else { + if(k==0) return f-s*(f-R); else + return dk*ln2_hi-((s*(f-R)-dk*ln2_lo)-f); + } +} +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/classpath/native/fdlibm/e_log10.c b/libjava/classpath/native/fdlibm/e_log10.c new file mode 100644 index 000000000..2db17aacc --- /dev/null +++ b/libjava/classpath/native/fdlibm/e_log10.c @@ -0,0 +1,93 @@ + +/* @(#)e_log10.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* __ieee754_log10(x) + * Return the base 10 logarithm of x + * + * Method : + * Let log10_2hi = leading 40 bits of log10(2) and + * log10_2lo = log10(2) - log10_2hi, + * ivln10 = 1/log(10) rounded. + * Then + * n = ilogb(x), + * if(n<0) n = n+1; + * x = scalbn(x,-n); + * log10(x) := n*log10_2hi + (n*log10_2lo + ivln10*log(x)) + * + * Note 1: + * To guarantee log10(10**n)=n, where 10**n is normal, the rounding + * mode must set to Round-to-Nearest. + * Note 2: + * [1/log(10)] rounded to 53 bits has error .198 ulps; + * log10 is monotonic at all binary break points. + * + * Special cases: + * log10(x) is NaN with signal if x < 0; + * log10(+INF) is +INF with no signal; log10(0) is -INF with signal; + * log10(NaN) is that NaN with no signal; + * log10(10**N) = N for N=0,1,...,22. + * + * Constants: + * The hexadecimal values are the intended ones for the following constants. + * The decimal values may be used, provided that the compiler will convert + * from decimal to binary accurately enough to produce the hexadecimal values + * shown. + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ +static const double +#else +static double +#endif +two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */ +ivln10 = 4.34294481903251816668e-01, /* 0x3FDBCB7B, 0x1526E50E */ +log10_2hi = 3.01029995663611771306e-01, /* 0x3FD34413, 0x509F6000 */ +log10_2lo = 3.69423907715893078616e-13; /* 0x3D59FEF3, 0x11F12B36 */ + +static double zero = 0.0; + +#ifdef __STDC__ + double __ieee754_log10(double x) +#else + double __ieee754_log10(x) + double x; +#endif +{ + double y,z; + int32_t i,k,hx; + uint32_t lx; + + EXTRACT_WORDS(hx,lx,x); + + k=0; + if (hx < 0x00100000) { /* x < 2**-1022 */ + if (((hx&0x7fffffff)|lx)==0) + return -two54/zero; /* log(+-0)=-inf */ + if (hx<0) return (x-x)/zero; /* log(-#) = NaN */ + k -= 54; x *= two54; /* subnormal number, scale up x */ + GET_HIGH_WORD(hx, x); /* high word of x */ + } + if (hx >= 0x7ff00000) return x+x; + k += (hx>>20)-1023; + i = ((uint32_t)k&0x80000000)>>31; + hx = (hx&0x000fffff)|((0x3ff-i)<<20); + y = (double)(k+i); + SET_HIGH_WORD(x,hx); + z = y*log10_2lo + ivln10*__ieee754_log(x); + return z+y*log10_2hi; +} +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/classpath/native/fdlibm/e_pow.c b/libjava/classpath/native/fdlibm/e_pow.c new file mode 100644 index 000000000..f846cfab8 --- /dev/null +++ b/libjava/classpath/native/fdlibm/e_pow.c @@ -0,0 +1,312 @@ + +/* + * ==================================================== + * Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved. + * + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* __ieee754_pow(x,y) return x**y + * + * n + * Method: Let x = 2 * (1+f) + * 1. Compute and return log2(x) in two pieces: + * log2(x) = w1 + w2, + * where w1 has 53-24 = 29 bit trailing zeros. + * 2. Perform y*log2(x) = n+y' by simulating muti-precision + * arithmetic, where |y'|<=0.5. + * 3. Return x**y = 2**n*exp(y'*log2) + * + * Special cases: + * 1. (anything) ** 0 is 1 + * 2. (anything) ** 1 is itself + * 3. (anything) ** NAN is NAN + * 4. NAN ** (anything except 0) is NAN + * 5. +-(|x| > 1) ** +INF is +INF + * 6. +-(|x| > 1) ** -INF is +0 + * 7. +-(|x| < 1) ** +INF is +0 + * 8. +-(|x| < 1) ** -INF is +INF + * 9. +-1 ** +-INF is NAN + * 10. +0 ** (+anything except 0, NAN) is +0 + * 11. -0 ** (+anything except 0, NAN, odd integer) is +0 + * 12. +0 ** (-anything except 0, NAN) is +INF + * 13. -0 ** (-anything except 0, NAN, odd integer) is +INF + * 14. -0 ** (odd integer) = -( +0 ** (odd integer) ) + * 15. +INF ** (+anything except 0,NAN) is +INF + * 16. +INF ** (-anything except 0,NAN) is +0 + * 17. -INF ** (anything) = -0 ** (-anything) + * 18. (-anything) ** (integer) is (-1)**(integer)*(+anything**integer) + * 19. (-anything except 0 and inf) ** (non-integer) is NAN + * + * Accuracy: + * pow(x,y) returns x**y nearly rounded. In particular + * pow(integer,integer) + * always returns the correct integer provided it is + * representable. + * + * Constants : + * The hexadecimal values are the intended ones for the following + * constants. The decimal values may be used, provided that the + * compiler will convert from decimal to binary accurately enough + * to produce the hexadecimal values shown. + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ +static const double +#else +static double +#endif +bp[] = {1.0, 1.5,}, +dp_h[] = { 0.0, 5.84962487220764160156e-01,}, /* 0x3FE2B803, 0x40000000 */ +dp_l[] = { 0.0, 1.35003920212974897128e-08,}, /* 0x3E4CFDEB, 0x43CFD006 */ +zero = 0.0, +one = 1.0, +two = 2.0, +two53 = 9007199254740992.0, /* 0x43400000, 0x00000000 */ +huge = 1.0e300, +tiny = 1.0e-300, + /* poly coefs for (3/2)*(log(x)-2s-2/3*s**3 */ +L1 = 5.99999999999994648725e-01, /* 0x3FE33333, 0x33333303 */ +L2 = 4.28571428578550184252e-01, /* 0x3FDB6DB6, 0xDB6FABFF */ +L3 = 3.33333329818377432918e-01, /* 0x3FD55555, 0x518F264D */ +L4 = 2.72728123808534006489e-01, /* 0x3FD17460, 0xA91D4101 */ +L5 = 2.30660745775561754067e-01, /* 0x3FCD864A, 0x93C9DB65 */ +L6 = 2.06975017800338417784e-01, /* 0x3FCA7E28, 0x4A454EEF */ +P1 = 1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */ +P2 = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */ +P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */ +P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */ +P5 = 4.13813679705723846039e-08, /* 0x3E663769, 0x72BEA4D0 */ +lg2 = 6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */ +lg2_h = 6.93147182464599609375e-01, /* 0x3FE62E43, 0x00000000 */ +lg2_l = -1.90465429995776804525e-09, /* 0xBE205C61, 0x0CA86C39 */ +ovt = 8.0085662595372944372e-0017, /* -(1024-log2(ovfl+.5ulp)) */ +cp = 9.61796693925975554329e-01, /* 0x3FEEC709, 0xDC3A03FD =2/(3ln2) */ +cp_h = 9.61796700954437255859e-01, /* 0x3FEEC709, 0xE0000000 =(float)cp */ +cp_l = -7.02846165095275826516e-09, /* 0xBE3E2FE0, 0x145B01F5 =tail of cp_h*/ +ivln2 = 1.44269504088896338700e+00, /* 0x3FF71547, 0x652B82FE =1/ln2 */ +ivln2_h = 1.44269502162933349609e+00, /* 0x3FF71547, 0x60000000 =24b 1/ln2*/ +ivln2_l = 1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/ + +#ifdef __STDC__ + double __ieee754_pow(double x, double y) +#else + double __ieee754_pow(x,y) + double x, y; +#endif +{ + double z,ax,z_h,z_l,p_h,p_l; + double y1,t1,t2,r,s,t,u,v,w; + int32_t i0,i1,i,j,k,yisint,n; + int32_t hx,hy,ix,iy; + uint32_t lx,ly; + + i0 = ((*(int*)&one)>>29)^1; i1=1-i0; + EXTRACT_WORDS(hx,lx,x); + EXTRACT_WORDS(hy,ly,y); + ix = hx&0x7fffffff; iy = hy&0x7fffffff; + + /* y==zero: x**0 = 1 */ + if((iy|ly)==0) return one; + + /* +-NaN return x+y */ + if(ix > 0x7ff00000 || ((ix==0x7ff00000)&&(lx!=0)) || + iy > 0x7ff00000 || ((iy==0x7ff00000)&&(ly!=0))) + return x+y; + + /* determine if y is an odd int when x < 0 + * yisint = 0 ... y is not an integer + * yisint = 1 ... y is an odd int + * yisint = 2 ... y is an even int + */ + yisint = 0; + if(hx<0) { + if(iy>=0x43400000) yisint = 2; /* even integer y */ + else if(iy>=0x3ff00000) { + k = (iy>>20)-0x3ff; /* exponent */ + if(k>20) { + j = ly>>(52-k); + if((uint32_t)(j<<(52-k))==ly) yisint = 2-(j&1); + } else if(ly==0) { + j = iy>>(20-k); + if((j<<(20-k))==iy) yisint = 2-(j&1); + } + } + } + + /* special value of y */ + if(ly==0) { + if (iy==0x7ff00000) { /* y is +-inf */ + if(((ix-0x3ff00000)|lx)==0) + return y - y; /* inf**+-1 is NaN */ + else if (ix >= 0x3ff00000)/* (|x|>1)**+-inf = inf,0 */ + return (hy>=0)? y: zero; + else /* (|x|<1)**-,+inf = inf,0 */ + return (hy<0)?-y: zero; + } + if(iy==0x3ff00000) { /* y is +-1 */ + if(hy<0) return one/x; else return x; + } + if(hy==0x40000000) return x*x; /* y is 2 */ + if(hy==0x3fe00000) { /* y is 0.5 */ + if(hx>=0) /* x >= +0 */ + return __ieee754_sqrt(x); + } + } + + ax = fabs(x); + /* special value of x */ + if(lx==0) { + if(ix==0x7ff00000||ix==0||ix==0x3ff00000){ + z = ax; /*x is +-0,+-inf,+-1*/ + if(hy<0) z = one/z; /* z = (1/|x|) */ + if(hx<0) { + if(((ix-0x3ff00000)|yisint)==0) { + z = (z-z)/(z-z); /* (-1)**non-int is NaN */ + } else if(yisint==1) + z = -z; /* (x<0)**odd = -(|x|**odd) */ + } + return z; + } + } + + n = (hx>>31)+1; + + /* (x<0)**(non-int) is NaN */ + if((n|yisint)==0) return (x-x)/(x-x); + + s = one; /* s (sign of result -ve**odd) = -1 else = 1 */ + if((n|(yisint-1))==0) s = -one;/* (-ve)**(odd int) */ + + /* |y| is huge */ + if(iy>0x41e00000) { /* if |y| > 2**31 */ + if(iy>0x43f00000){ /* if |y| > 2**64, must o/uflow */ + if(ix<=0x3fefffff) return (hy<0)? huge*huge:tiny*tiny; + if(ix>=0x3ff00000) return (hy>0)? huge*huge:tiny*tiny; + } + /* over/underflow if x is not close to one */ + if(ix<0x3fefffff) return (hy<0)? s*huge*huge:s*tiny*tiny; + if(ix>0x3ff00000) return (hy>0)? s*huge*huge:s*tiny*tiny; + /* now |1-x| is tiny <= 2**-20, suffice to compute + log(x) by x-x^2/2+x^3/3-x^4/4 */ + t = ax-one; /* t has 20 trailing zeros */ + w = (t*t)*(0.5-t*(0.3333333333333333333333-t*0.25)); + u = ivln2_h*t; /* ivln2_h has 21 sig. bits */ + v = t*ivln2_l-w*ivln2; + t1 = u+v; + SET_LOW_WORD(t1,0); + t2 = v-(t1-u); + } else { + double ss,s2,s_h,s_l,t_h,t_l; + n = 0; + /* take care subnormal number */ + if(ix<0x00100000) + {ax *= two53; n -= 53; GET_HIGH_WORD(ix,ax); } + n += ((ix)>>20)-0x3ff; + j = ix&0x000fffff; + /* determine interval */ + ix = j|0x3ff00000; /* normalize ix */ + if(j<=0x3988E) k=0; /* |x|>1)|0x20000000)+0x00080000+(k<<18)); + t_l = ax - (t_h-bp[k]); + s_l = v*((u-s_h*t_h)-s_h*t_l); + /* compute log(ax) */ + s2 = ss*ss; + r = s2*s2*(L1+s2*(L2+s2*(L3+s2*(L4+s2*(L5+s2*L6))))); + r += s_l*(s_h+ss); + s2 = s_h*s_h; + t_h = 3.0+s2+r; + SET_LOW_WORD(t_h,0); + t_l = r-((t_h-3.0)-s2); + /* u+v = ss*(1+...) */ + u = s_h*t_h; + v = s_l*t_h+t_l*ss; + /* 2/(3log2)*(ss+...) */ + p_h = u+v; + SET_LOW_WORD(p_h,0); + p_l = v-(p_h-u); + z_h = cp_h*p_h; /* cp_h+cp_l = 2/(3*log2) */ + z_l = cp_l*p_h+p_l*cp+dp_l[k]; + /* log2(ax) = (ss+..)*2/(3*log2) = n + dp_h + z_h + z_l */ + t = (double)n; + t1 = (((z_h+z_l)+dp_h[k])+t); + SET_LOW_WORD(t1,0); + t2 = z_l-(((t1-t)-dp_h[k])-z_h); + } + + /* split up y into y1+y2 and compute (y1+y2)*(t1+t2) */ + y1 = y; + SET_LOW_WORD(y1,0); + p_l = (y-y1)*t1+y*t2; + p_h = y1*t1; + z = p_l+p_h; + EXTRACT_WORDS(j,i,z); + if (j>=0x40900000) { /* z >= 1024 */ + if(((j-0x40900000)|i)!=0) /* if z > 1024 */ + return s*huge*huge; /* overflow */ + else { + if(p_l+ovt>z-p_h) return s*huge*huge; /* overflow */ + } + } else if((j&0x7fffffff)>=0x4090cc00 ) { /* z <= -1075 */ + if(((j-0xc090cc00)|i)!=0) /* z < -1075 */ + return s*tiny*tiny; /* underflow */ + else { + if(p_l<=z-p_h) return s*tiny*tiny; /* underflow */ + } + } + /* + * compute 2**(p_h+p_l) + */ + i = j&0x7fffffff; + k = (i>>20)-0x3ff; + n = 0; + if(i>0x3fe00000) { /* if |z| > 0.5, set n = [z+0.5] */ + n = j+(0x00100000>>(k+1)); + k = ((n&0x7fffffff)>>20)-0x3ff; /* new k for n */ + t = zero; + SET_HIGH_WORD(t,(n&~(0x000fffff>>k))); + n = ((n&0x000fffff)|0x00100000)>>(20-k); + if(j<0) n = -n; + p_h -= t; + } + t = p_l+p_h; + SET_LOW_WORD(t,0); + u = t*lg2_h; + v = (p_l-(t-p_h))*lg2+t*lg2_l; + z = u+v; + w = v-(z-u); + t = z*z; + t1 = z - t*(P1+t*(P2+t*(P3+t*(P4+t*P5)))); + r = (z*t1)/(t1-two)-(w+z*w); + z = one-(r-z); + GET_HIGH_WORD(j,z); + j += (n<<20); + if((j>>20)<=0) z = scalbn(z,n); /* subnormal output */ + else + { + uint32_t hz; + GET_HIGH_WORD(hz,z); + SET_HIGH_WORD(z,hz + (n<<20)); + } + return s*z; +} +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/classpath/native/fdlibm/e_rem_pio2.c b/libjava/classpath/native/fdlibm/e_rem_pio2.c new file mode 100644 index 000000000..6df3de2fb --- /dev/null +++ b/libjava/classpath/native/fdlibm/e_rem_pio2.c @@ -0,0 +1,185 @@ + +/* @(#)e_rem_pio2.c 1.4 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + * + */ + +/* __ieee754_rem_pio2(x,y) + * + * return the remainder of x rem pi/2 in y[0]+y[1] + * use __kernel_rem_pio2() + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +/* + * Table of constants for 2/pi, 396 Hex digits (476 decimal) of 2/pi + */ +#ifdef __STDC__ +static const int32_t two_over_pi[] = { +#else +static int32_t two_over_pi[] = { +#endif +0xA2F983, 0x6E4E44, 0x1529FC, 0x2757D1, 0xF534DD, 0xC0DB62, +0x95993C, 0x439041, 0xFE5163, 0xABDEBB, 0xC561B7, 0x246E3A, +0x424DD2, 0xE00649, 0x2EEA09, 0xD1921C, 0xFE1DEB, 0x1CB129, +0xA73EE8, 0x8235F5, 0x2EBB44, 0x84E99C, 0x7026B4, 0x5F7E41, +0x3991D6, 0x398353, 0x39F49C, 0x845F8B, 0xBDF928, 0x3B1FF8, +0x97FFDE, 0x05980F, 0xEF2F11, 0x8B5A0A, 0x6D1F6D, 0x367ECF, +0x27CB09, 0xB74F46, 0x3F669E, 0x5FEA2D, 0x7527BA, 0xC7EBE5, +0xF17B3D, 0x0739F7, 0x8A5292, 0xEA6BFB, 0x5FB11F, 0x8D5D08, +0x560330, 0x46FC7B, 0x6BABF0, 0xCFBC20, 0x9AF436, 0x1DA9E3, +0x91615E, 0xE61B08, 0x659985, 0x5F14A0, 0x68408D, 0xFFD880, +0x4D7327, 0x310606, 0x1556CA, 0x73A8C9, 0x60E27B, 0xC08C6B, +}; + +#ifdef __STDC__ +static const int32_t npio2_hw[] = { +#else +static int32_t npio2_hw[] = { +#endif +0x3FF921FB, 0x400921FB, 0x4012D97C, 0x401921FB, 0x401F6A7A, 0x4022D97C, +0x4025FDBB, 0x402921FB, 0x402C463A, 0x402F6A7A, 0x4031475C, 0x4032D97C, +0x40346B9C, 0x4035FDBB, 0x40378FDB, 0x403921FB, 0x403AB41B, 0x403C463A, +0x403DD85A, 0x403F6A7A, 0x40407E4C, 0x4041475C, 0x4042106C, 0x4042D97C, +0x4043A28C, 0x40446B9C, 0x404534AC, 0x4045FDBB, 0x4046C6CB, 0x40478FDB, +0x404858EB, 0x404921FB, +}; + +/* + * invpio2: 53 bits of 2/pi + * pio2_1: first 33 bit of pi/2 + * pio2_1t: pi/2 - pio2_1 + * pio2_2: second 33 bit of pi/2 + * pio2_2t: pi/2 - (pio2_1+pio2_2) + * pio2_3: third 33 bit of pi/2 + * pio2_3t: pi/2 - (pio2_1+pio2_2+pio2_3) + */ + +#ifdef __STDC__ +static const double +#else +static double +#endif +zero = 0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */ +half = 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */ +two24 = 1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */ +invpio2 = 6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */ +pio2_1 = 1.57079632673412561417e+00, /* 0x3FF921FB, 0x54400000 */ +pio2_1t = 6.07710050650619224932e-11, /* 0x3DD0B461, 0x1A626331 */ +pio2_2 = 6.07710050630396597660e-11, /* 0x3DD0B461, 0x1A600000 */ +pio2_2t = 2.02226624879595063154e-21, /* 0x3BA3198A, 0x2E037073 */ +pio2_3 = 2.02226624871116645580e-21, /* 0x3BA3198A, 0x2E000000 */ +pio2_3t = 8.47842766036889956997e-32; /* 0x397B839A, 0x252049C1 */ + +#ifdef __STDC__ + int32_t __ieee754_rem_pio2(double x, double *y) +#else + int32_t __ieee754_rem_pio2(x,y) + double x,y[]; +#endif +{ + double z = 0.,w,t,r,fn; + double tx[3]; + int32_t i,j,n,ix,hx; + int e0,nx; + uint32_t low; + + GET_HIGH_WORD(hx,x); /* high word of x */ + ix = hx&0x7fffffff; + if(ix<=0x3fe921fb) /* |x| ~<= pi/4 , no need for reduction */ + {y[0] = x; y[1] = 0; return 0;} + if(ix<0x4002d97c) { /* |x| < 3pi/4, special case with n=+-1 */ + if(hx>0) { + z = x - pio2_1; + if(ix!=0x3ff921fb) { /* 33+53 bit pi is good enough */ + y[0] = z - pio2_1t; + y[1] = (z-y[0])-pio2_1t; + } else { /* near pi/2, use 33+33+53 bit pi */ + z -= pio2_2; + y[0] = z - pio2_2t; + y[1] = (z-y[0])-pio2_2t; + } + return 1; + } else { /* negative x */ + z = x + pio2_1; + if(ix!=0x3ff921fb) { /* 33+53 bit pi is good enough */ + y[0] = z + pio2_1t; + y[1] = (z-y[0])+pio2_1t; + } else { /* near pi/2, use 33+33+53 bit pi */ + z += pio2_2; + y[0] = z + pio2_2t; + y[1] = (z-y[0])+pio2_2t; + } + return -1; + } + } + if(ix<=0x413921fb) { /* |x| ~<= 2^19*(pi/2), medium size */ + t = fabs(x); + n = (int32_t) (t*invpio2+half); + fn = (double)n; + r = t-fn*pio2_1; + w = fn*pio2_1t; /* 1st round good to 85 bit */ + if(n<32&&ix!=npio2_hw[n-1]) { + y[0] = r-w; /* quick check no cancellation */ + } else { + uint32_t high; + + j = ix>>20; + y[0] = r-w; + GET_HIGH_WORD(high, y[0]); + i = j-((high>>20)&0x7ff); + if(i>16) { /* 2nd iteration needed, good to 118 */ + t = r; + w = fn*pio2_2; + r = t-w; + w = fn*pio2_2t-((t-r)-w); + y[0] = r-w; + GET_HIGH_WORD(high,y[0]); + i = j-((high>>20)&0x7ff); + if(i>49) { /* 3rd iteration need, 151 bits acc */ + t = r; /* will cover all possible cases */ + w = fn*pio2_3; + r = t-w; + w = fn*pio2_3t-((t-r)-w); + y[0] = r-w; + } + } + } + y[1] = (r-y[0])-w; + if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;} + else return n; + } + /* + * all other (large) arguments + */ + if(ix>=0x7ff00000) { /* x is inf or NaN */ + y[0]=y[1]=x-x; return 0; + } + /* set z = scalbn(|x|,ilogb(x)-23) */ + GET_LOW_WORD(low,x); + SET_LOW_WORD(z,low); + e0 = (int32_t)(ix>>20)-1046; /* e0 = ilogb(z)-23; */ + SET_HIGH_WORD(z,ix - (e0<<20)); + for(i=0;i<2;i++) { + tx[i] = (double)((int32_t)(z)); + z = (z-tx[i])*two24; + } + tx[2] = z; + nx = 3; + while(tx[nx-1]==zero) nx--; /* skip zero term */ + n = __kernel_rem_pio2(tx,y,e0,nx,2,two_over_pi); + if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;} + return n; +} +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/classpath/native/fdlibm/e_remainder.c b/libjava/classpath/native/fdlibm/e_remainder.c new file mode 100644 index 000000000..6a39820cf --- /dev/null +++ b/libjava/classpath/native/fdlibm/e_remainder.c @@ -0,0 +1,79 @@ + +/* @(#)e_remainder.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* __ieee754_remainder(x,p) + * Return : + * returns x REM p = x - [x/p]*p as if in infinite + * precise arithmetic, where [x/p] is the (infinite bit) + * integer nearest x/p (in half way case choose the even one). + * Method : + * Based on fmod() return x-[x/p]chopped*p exactlp. + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ +static const double zero = 0.0; +#else +static double zero = 0.0; +#endif + + +#ifdef __STDC__ + double __ieee754_remainder(double x, double p) +#else + double __ieee754_remainder(x,p) + double x,p; +#endif +{ + int32_t hx,hp; + uint32_t sx,lx,lp; + double p_half; + + EXTRACT_WORDS(hx,lx,x); + EXTRACT_WORDS(hp,lp,p); + sx = hx&0x80000000; + hp &= 0x7fffffff; + hx &= 0x7fffffff; + + /* purge off exception values */ + if((hp|lp)==0) return (x*p)/(x*p); /* p = 0 */ + if((hx>=0x7ff00000)|| /* x not finite */ + ((hp>=0x7ff00000)&& /* p is NaN */ + (((hp-0x7ff00000)|lp)!=0))) + return (x*p)/(x*p); + + + if (hp<=0x7fdfffff) x = __ieee754_fmod(x,p+p); /* now x < 2p */ + if (((hx-hp)|(lx-lp))==0) return zero*x; + x = fabs(x); + p = fabs(p); + if (hp<0x00200000) { + if(x+x>p) { + x-=p; + if(x+x>=p) x -= p; + } + } else { + p_half = 0.5*p; + if(x>p_half) { + x-=p; + if(x>=p_half) x -= p; + } + } + GET_HIGH_WORD(hx,x); + SET_HIGH_WORD(x,hx ^ sx); + return x; +} +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/classpath/native/fdlibm/e_scalb.c b/libjava/classpath/native/fdlibm/e_scalb.c new file mode 100644 index 000000000..91e9c6ad2 --- /dev/null +++ b/libjava/classpath/native/fdlibm/e_scalb.c @@ -0,0 +1,51 @@ + +/* @(#)e_scalb.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* + * __ieee754_scalb(x, fn) is provide for + * passing various standard test suite. One + * should use scalbn() instead. + */ + +#include "fdlibm.h" + +#ifdef _SCALB_INT +#ifdef __STDC__ + double __ieee754_scalb(double x, int fn) +#else + double __ieee754_scalb(x,fn) + double x; int fn; +#endif +#else +#ifdef __STDC__ + double __ieee754_scalb(double x, double fn) +#else + double __ieee754_scalb(x,fn) + double x, fn; +#endif +#endif +{ +#ifdef _SCALB_INT + return scalbn(x,fn); +#else + if (isnan(x)||isnan(fn)) return x*fn; + if (!finite(fn)) { + if(fn>0.0) return x*fn; + else return x/(-fn); + } + if (rint(fn)!=fn) return (fn-fn)/(fn-fn); + if ( fn > 65000.0) return scalbn(x, 65000); + if (-fn > 65000.0) return scalbn(x,-65000); + return scalbn(x,(int)fn); +#endif +} diff --git a/libjava/classpath/native/fdlibm/e_sinh.c b/libjava/classpath/native/fdlibm/e_sinh.c new file mode 100644 index 000000000..446dea59f --- /dev/null +++ b/libjava/classpath/native/fdlibm/e_sinh.c @@ -0,0 +1,85 @@ + +/* @(#)e_sinh.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* __ieee754_sinh(x) + * Method : + * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2 + * 1. Replace x by |x| (sinh(-x) = -sinh(x)). + * 2. + * E + E/(E+1) + * 0 <= x <= 22 : sinh(x) := --------------, E=expm1(x) + * 2 + * + * 22 <= x <= lnovft : sinh(x) := exp(x)/2 + * lnovft <= x <= ln2ovft: sinh(x) := exp(x/2)/2 * exp(x/2) + * ln2ovft < x : sinh(x) := x*shuge (overflow) + * + * Special cases: + * sinh(x) is |x| if x is +INF, -INF, or NaN. + * only sinh(0)=0 is exact for finite x. + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ +static const double one = 1.0, shuge = 1.0e307; +#else +static double one = 1.0, shuge = 1.0e307; +#endif + +#ifdef __STDC__ + double __ieee754_sinh(double x) +#else + double __ieee754_sinh(x) + double x; +#endif +{ + double t,w,h; + int32_t ix,jx; + uint32_t lx; + + /* High word of |x|. */ + GET_HIGH_WORD(jx,x); + ix = jx&0x7fffffff; + + /* x is INF or NaN */ + if(ix>=0x7ff00000) return x+x; + + h = 0.5; + if (jx<0) h = -h; + /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */ + if (ix < 0x40360000) { /* |x|<22 */ + if (ix<0x3e300000) /* |x|<2**-28 */ + if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */ + t = expm1(fabs(x)); + if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one)); + return h*(t+t/(t+one)); + } + + /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */ + if (ix < 0x40862E42) return h*__ieee754_exp(fabs(x)); + + /* |x| in [log(maxdouble), overflowthresold] */ + lx = *( (((*(uint32_t*)&one)>>29)) + (uint32_t*)&x); + if (ix<0x408633CE || (ix==0x408633ce)&&(lx<=(uint32_t)0x8fb9f87d)) { + w = __ieee754_exp(0.5*fabs(x)); + t = h*w; + return t*w; + } + + /* |x| > overflowthresold, sinh(x) overflow */ + return x*shuge; +} +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/classpath/native/fdlibm/e_sqrt.c b/libjava/classpath/native/fdlibm/e_sqrt.c new file mode 100644 index 000000000..90dd04fca --- /dev/null +++ b/libjava/classpath/native/fdlibm/e_sqrt.c @@ -0,0 +1,451 @@ +/* @(#)e_sqrt.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* __ieee754_sqrt(x) + * Return correctly rounded sqrt. + * ------------------------------------------ + * | Use the hardware sqrt if you have one | + * ------------------------------------------ + * Method: + * Bit by bit method using integer arithmetic. (Slow, but portable) + * 1. Normalization + * Scale x to y in [1,4) with even powers of 2: + * find an integer k such that 1 <= (y=x*2^(2k)) < 4, then + * sqrt(x) = 2^k * sqrt(y) + * 2. Bit by bit computation + * Let q = sqrt(y) truncated to i bit after binary point (q = 1), + * i 0 + * i+1 2 + * s = 2*q , and y = 2 * ( y - q ). (1) + * i i i i + * + * To compute q from q , one checks whether + * i+1 i + * + * -(i+1) 2 + * (q + 2 ) <= y. (2) + * i + * -(i+1) + * If (2) is false, then q = q ; otherwise q = q + 2 . + * i+1 i i+1 i + * + * With some algebric manipulation, it is not difficult to see + * that (2) is equivalent to + * -(i+1) + * s + 2 <= y (3) + * i i + * + * The advantage of (3) is that s and y can be computed by + * i i + * the following recurrence formula: + * if (3) is false + * + * s = s , y = y ; (4) + * i+1 i i+1 i + * + * otherwise, + * -i -(i+1) + * s = s + 2 , y = y - s - 2 (5) + * i+1 i i+1 i i + * + * One may easily use induction to prove (4) and (5). + * Note. Since the left hand side of (3) contain only i+2 bits, + * it does not necessary to do a full (53-bit) comparison + * in (3). + * 3. Final rounding + * After generating the 53 bits result, we compute one more bit. + * Together with the remainder, we can decide whether the + * result is exact, bigger than 1/2ulp, or less than 1/2ulp + * (it will never equal to 1/2ulp). + * The rounding mode can be detected by checking whether + * huge + tiny is equal to huge, and whether huge - tiny is + * equal to huge for some floating point number "huge" and "tiny". + * + * Special cases: + * sqrt(+-0) = +-0 ... exact + * sqrt(inf) = inf + * sqrt(-ve) = NaN ... with invalid signal + * sqrt(NaN) = NaN ... with invalid signal for signaling NaN + * + * Other methods : see the appended file at the end of the program below. + *--------------- + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ +static const double one = 1.0, tiny=1.0e-300; +#else +static double one = 1.0, tiny=1.0e-300; +#endif + +#ifdef __STDC__ + double __ieee754_sqrt(double x) +#else + double __ieee754_sqrt(x) + double x; +#endif +{ + double z; + int32_t sign = (int)0x80000000; + uint32_t r,t1,s1,ix1,q1; + int32_t ix0,s0,q,m,t,i; + + EXTRACT_WORDS(ix0,ix1,x); + + /* take care of Inf and NaN */ + if((ix0&0x7ff00000)==0x7ff00000) { + return x*x+x; /* sqrt(NaN)=NaN, sqrt(+inf)=+inf + sqrt(-inf)=sNaN */ + } + /* take care of zero */ + if(ix0<=0) { + if(((ix0&(~sign))|ix1)==0) return x;/* sqrt(+-0) = +-0 */ + else if(ix0<0) + return (x-x)/(x-x); /* sqrt(-ve) = sNaN */ + } + /* normalize x */ + m = (ix0>>20); + if(m==0) { /* subnormal x */ + while(ix0==0) { + m -= 21; + ix0 |= (ix1>>11); ix1 <<= 21; + } + for(i=0;(ix0&0x00100000)==0;i++) ix0<<=1; + m -= i-1; + ix0 |= (ix1>>(32-i)); + ix1 <<= i; + } + m -= 1023; /* unbias exponent */ + ix0 = (ix0&0x000fffff)|0x00100000; + if(m&1){ /* odd m, double x to make it even */ + ix0 += ix0 + ((ix1&sign)>>31); + ix1 += ix1; + } + m >>= 1; /* m = [m/2] */ + + /* generate sqrt(x) bit by bit */ + ix0 += ix0 + ((ix1&sign)>>31); + ix1 += ix1; + q = q1 = s0 = s1 = 0; /* [q,q1] = sqrt(x) */ + r = 0x00200000; /* r = moving bit from right to left */ + + while(r!=0) { + t = s0+r; + if(t<=ix0) { + s0 = t+r; + ix0 -= t; + q += r; + } + ix0 += ix0 + ((ix1&sign)>>31); + ix1 += ix1; + r>>=1; + } + + r = sign; + while(r!=0) { + t1 = s1+r; + t = s0; + if((t>31); + ix1 += ix1; + r>>=1; + } + + /* use floating add to find out rounding direction */ + if((ix0|ix1)!=0) { + z = one-tiny; /* trigger inexact flag */ + if (z>=one) { + z = one+tiny; + if (q1==(uint32_t)0xffffffff) { q1=0; q += 1;} + else if (z>one) { + if (q1==(uint32_t)0xfffffffe) q+=1; + q1+=2; + } else + q1 += (q1&1); + } + } + ix0 = (q>>1)+0x3fe00000; + ix1 = q1>>1; + if ((q&1)==1) ix1 |= sign; + ix0 += (m <<20); + INSERT_WORDS(z,ix0,ix1); + return z; +} +#endif /* defined(_DOUBLE_IS_32BITS) */ + +/* +Other methods (use floating-point arithmetic) +------------- +(This is a copy of a drafted paper by Prof W. Kahan +and K.C. Ng, written in May, 1986) + + Two algorithms are given here to implement sqrt(x) + (IEEE double precision arithmetic) in software. + Both supply sqrt(x) correctly rounded. The first algorithm (in + Section A) uses newton iterations and involves four divisions. + The second one uses reciproot iterations to avoid division, but + requires more multiplications. Both algorithms need the ability + to chop results of arithmetic operations instead of round them, + and the INEXACT flag to indicate when an arithmetic operation + is executed exactly with no roundoff error, all part of the + standard (IEEE 754-1985). The ability to perform shift, add, + subtract and logical AND operations upon 32-bit words is needed + too, though not part of the standard. + +A. sqrt(x) by Newton Iteration + + (1) Initial approximation + + Let x0 and x1 be the leading and the trailing 32-bit words of + a floating point number x (in IEEE double format) respectively + + 1 11 52 ...widths + ------------------------------------------------------ + x: |s| e | f | + ------------------------------------------------------ + msb lsb msb lsb ...order + + + ------------------------ ------------------------ + x0: |s| e | f1 | x1: | f2 | + ------------------------ ------------------------ + + By performing shifts and subtracts on x0 and x1 (both regarded + as integers), we obtain an 8-bit approximation of sqrt(x) as + follows. + + k := (x0>>1) + 0x1ff80000; + y0 := k - T1[31&(k>>15)]. ... y ~ sqrt(x) to 8 bits + Here k is a 32-bit integer and T1[] is an integer array containing + correction terms. Now magically the floating value of y (y's + leading 32-bit word is y0, the value of its trailing word is 0) + approximates sqrt(x) to almost 8-bit. + + Value of T1: + static int T1[32]= { + 0, 1024, 3062, 5746, 9193, 13348, 18162, 23592, + 29598, 36145, 43202, 50740, 58733, 67158, 75992, 85215, + 83599, 71378, 60428, 50647, 41945, 34246, 27478, 21581, + 16499, 12183, 8588, 5674, 3403, 1742, 661, 130,}; + + (2) Iterative refinement + + Apply Heron's rule three times to y, we have y approximates + sqrt(x) to within 1 ulp (Unit in the Last Place): + + y := (y+x/y)/2 ... almost 17 sig. bits + y := (y+x/y)/2 ... almost 35 sig. bits + y := y-(y-x/y)/2 ... within 1 ulp + + + Remark 1. + Another way to improve y to within 1 ulp is: + + y := (y+x/y) ... almost 17 sig. bits to 2*sqrt(x) + y := y - 0x00100006 ... almost 18 sig. bits to sqrt(x) + + 2 + (x-y )*y + y := y + 2* ---------- ...within 1 ulp + 2 + 3y + x + + + This formula has one division fewer than the one above; however, + it requires more multiplications and additions. Also x must be + scaled in advance to avoid spurious overflow in evaluating the + expression 3y*y+x. Hence it is not recommended uless division + is slow. If division is very slow, then one should use the + reciproot algorithm given in section B. + + (3) Final adjustment + + By twiddling y's last bit it is possible to force y to be + correctly rounded according to the prevailing rounding mode + as follows. Let r and i be copies of the rounding mode and + inexact flag before entering the square root program. Also we + use the expression y+-ulp for the next representable floating + numbers (up and down) of y. Note that y+-ulp = either fixed + point y+-1, or multiply y by nextafter(1,+-inf) in chopped + mode. + + I := FALSE; ... reset INEXACT flag I + R := RZ; ... set rounding mode to round-toward-zero + z := x/y; ... chopped quotient, possibly inexact + If(not I) then { ... if the quotient is exact + if(z=y) { + I := i; ... restore inexact flag + R := r; ... restore rounded mode + return sqrt(x):=y. + } else { + z := z - ulp; ... special rounding + } + } + i := TRUE; ... sqrt(x) is inexact + If (r=RN) then z=z+ulp ... rounded-to-nearest + If (r=RP) then { ... round-toward-+inf + y = y+ulp; z=z+ulp; + } + y := y+z; ... chopped sum + y0:=y0-0x00100000; ... y := y/2 is correctly rounded. + I := i; ... restore inexact flag + R := r; ... restore rounded mode + return sqrt(x):=y. + + (4) Special cases + + Square root of +inf, +-0, or NaN is itself; + Square root of a negative number is NaN with invalid signal. + + +B. sqrt(x) by Reciproot Iteration + + (1) Initial approximation + + Let x0 and x1 be the leading and the trailing 32-bit words of + a floating point number x (in IEEE double format) respectively + (see section A). By performing shifs and subtracts on x0 and y0, + we obtain a 7.8-bit approximation of 1/sqrt(x) as follows. + + k := 0x5fe80000 - (x0>>1); + y0:= k - T2[63&(k>>14)]. ... y ~ 1/sqrt(x) to 7.8 bits + + Here k is a 32-bit integer and T2[] is an integer array + containing correction terms. Now magically the floating + value of y (y's leading 32-bit word is y0, the value of + its trailing word y1 is set to zero) approximates 1/sqrt(x) + to almost 7.8-bit. + + Value of T2: + static int T2[64]= { + 0x1500, 0x2ef8, 0x4d67, 0x6b02, 0x87be, 0xa395, 0xbe7a, 0xd866, + 0xf14a, 0x1091b,0x11fcd,0x13552,0x14999,0x15c98,0x16e34,0x17e5f, + 0x18d03,0x19a01,0x1a545,0x1ae8a,0x1b5c4,0x1bb01,0x1bfde,0x1c28d, + 0x1c2de,0x1c0db,0x1ba73,0x1b11c,0x1a4b5,0x1953d,0x18266,0x16be0, + 0x1683e,0x179d8,0x18a4d,0x19992,0x1a789,0x1b445,0x1bf61,0x1c989, + 0x1d16d,0x1d77b,0x1dddf,0x1e2ad,0x1e5bf,0x1e6e8,0x1e654,0x1e3cd, + 0x1df2a,0x1d635,0x1cb16,0x1be2c,0x1ae4e,0x19bde,0x1868e,0x16e2e, + 0x1527f,0x1334a,0x11051,0xe951, 0xbe01, 0x8e0d, 0x5924, 0x1edd,}; + + (2) Iterative refinement + + Apply Reciproot iteration three times to y and multiply the + result by x to get an approximation z that matches sqrt(x) + to about 1 ulp. To be exact, we will have + -1ulp < sqrt(x)-z<1.0625ulp. + + ... set rounding mode to Round-to-nearest + y := y*(1.5-0.5*x*y*y) ... almost 15 sig. bits to 1/sqrt(x) + y := y*((1.5-2^-30)+0.5*x*y*y)... about 29 sig. bits to 1/sqrt(x) + ... special arrangement for better accuracy + z := x*y ... 29 bits to sqrt(x), with z*y<1 + z := z + 0.5*z*(1-z*y) ... about 1 ulp to sqrt(x) + + Remark 2. The constant 1.5-2^-30 is chosen to bias the error so that + (a) the term z*y in the final iteration is always less than 1; + (b) the error in the final result is biased upward so that + -1 ulp < sqrt(x) - z < 1.0625 ulp + instead of |sqrt(x)-z|<1.03125ulp. + + (3) Final adjustment + + By twiddling y's last bit it is possible to force y to be + correctly rounded according to the prevailing rounding mode + as follows. Let r and i be copies of the rounding mode and + inexact flag before entering the square root program. Also we + use the expression y+-ulp for the next representable floating + numbers (up and down) of y. Note that y+-ulp = either fixed + point y+-1, or multiply y by nextafter(1,+-inf) in chopped + mode. + + R := RZ; ... set rounding mode to round-toward-zero + switch(r) { + case RN: ... round-to-nearest + if(x<= z*(z-ulp)...chopped) z = z - ulp; else + if(x<= z*(z+ulp)...chopped) z = z; else z = z+ulp; + break; + case RZ:case RM: ... round-to-zero or round-to--inf + R:=RP; ... reset rounding mod to round-to-+inf + if(x=(z+ulp)*(z+ulp) ...rounded up) z = z+ulp; + break; + case RP: ... round-to-+inf + if(x>(z+ulp)*(z+ulp)...chopped) z = z+2*ulp; else + if(x>z*z ...chopped) z = z+ulp; + break; + } + + Remark 3. The above comparisons can be done in fixed point. For + example, to compare x and w=z*z chopped, it suffices to compare + x1 and w1 (the trailing parts of x and w), regarding them as + two's complement integers. + + ...Is z an exact square root? + To determine whether z is an exact square root of x, let z1 be the + trailing part of z, and also let x0 and x1 be the leading and + trailing parts of x. + + If ((z1&0x03ffffff)!=0) ... not exact if trailing 26 bits of z!=0 + I := 1; ... Raise Inexact flag: z is not exact + else { + j := 1 - [(x0>>20)&1] ... j = logb(x) mod 2 + k := z1 >> 26; ... get z's 25-th and 26-th + fraction bits + I := i or (k&j) or ((k&(j+j+1))!=(x1&3)); + } + R:= r ... restore rounded mode + return sqrt(x):=z. + + If multiplication is cheaper then the foregoing red tape, the + Inexact flag can be evaluated by + + I := i; + I := (z*z!=x) or I. + + Note that z*z can overwrite I; this value must be sensed if it is + True. + + Remark 4. If z*z = x exactly, then bit 25 to bit 0 of z1 must be + zero. + + -------------------- + z1: | f2 | + -------------------- + bit 31 bit 0 + + Further more, bit 27 and 26 of z1, bit 0 and 1 of x1, and the odd + or even of logb(x) have the following relations: + + ------------------------------------------------- + bit 27,26 of z1 bit 1,0 of x1 logb(x) + ------------------------------------------------- + 00 00 odd and even + 01 01 even + 10 10 odd + 10 00 even + 11 01 even + ------------------------------------------------- + + (4) Special cases (see (4) of Section A). + + */ + diff --git a/libjava/classpath/native/fdlibm/fdlibm.h b/libjava/classpath/native/fdlibm/fdlibm.h new file mode 100644 index 000000000..fc10ecc9c --- /dev/null +++ b/libjava/classpath/native/fdlibm/fdlibm.h @@ -0,0 +1,408 @@ + +/* @(#)fdlibm.h 1.5 04/04/22 */ +/* + * ==================================================== + * Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved. + * + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#ifndef __CLASSPATH_FDLIBM_H__ +#define __CLASSPATH_FDLIBM_H__ + +/* + * On AIX we need _ALL_SOURCE defined to compile/configure native-lib, but can't + * have it defined to compile fdlibm. UGH. + */ +#ifdef _AIX +#undef _ALL_SOURCE +#endif + +#include +#include + +/* + * AIX includes a header that defines hz, + * which conflicts with an fdlibm variable in some functions. + */ +#ifdef _AIX +#undef hz +#endif + +/* GCJ LOCAL: Include files. */ +#include "ieeefp.h" +/* CLASSPATH LOCAL: */ +#include "namespace.h" + +#include "mprec.h" + +/* CYGNUS LOCAL: Default to XOPEN_MODE. */ +#define _XOPEN_MODE + +#ifdef __P +#undef __P +#endif + +/* Sometimes it's necessary to define __LITTLE_ENDIAN explicitly + but these catch some common cases. */ + +#if 0 +#if defined(i386) || defined(i486) || \ + defined(intel) || defined(x86) || defined(i86pc) || \ + defined(__alpha) || defined(__osf__) +#define __LITTLE_ENDIAN +#endif + +#ifdef __LITTLE_ENDIAN +#define __HI(x) *(1+(int*)&x) +#define __LO(x) *(int*)&x +#define __HIp(x) *(1+(int*)x) +#define __LOp(x) *(int*)x +#else +#define __HI(x) *(int*)&x +#define __LO(x) *(1+(int*)&x) +#define __HIp(x) *(int*)x +#define __LOp(x) *(1+(int*)x) +#endif +#endif + +#ifdef __STDC__ +#define __P(p) p +#else +#define __P(p) () +#endif + +/* + * ANSI/POSIX + */ + +extern int signgam; + +#define MAXFLOAT ((float)3.40282346638528860e+38) + +enum fdversion {fdlibm_ieee = -1, fdlibm_svid, fdlibm_xopen, fdlibm_posix}; + +#define _LIB_VERSION_TYPE enum fdversion +#define _LIB_VERSION _fdlib_version + +/* if global variable _LIB_VERSION is not desirable, one may + * change the following to be a constant by: + * #define _LIB_VERSION_TYPE const enum version + * In that case, after one initializes the value _LIB_VERSION (see + * s_lib_version.c) during compile time, it cannot be modified + * in the middle of a program + */ +extern _LIB_VERSION_TYPE _LIB_VERSION; + +#define _IEEE_ fdlibm_ieee +#define _SVID_ fdlibm_svid +#define _XOPEN_ fdlibm_xopen +#define _POSIX_ fdlibm_posix + +struct exception { + int type; + char *name; + double arg1; + double arg2; + double retval; +}; + +#define HUGE MAXFLOAT + +/* + * set X_TLOSS = pi*2**52, which is possibly defined in + * (one may replace the following line by "#include ") + */ + +#define X_TLOSS 1.41484755040568800000e+16 + +#define DOMAIN 1 +#define SING 2 +#define OVERFLOW 3 +#define UNDERFLOW 4 +#define TLOSS 5 +#define PLOSS 6 + +/* These typedefs are true for the targets running Java. */ + +#define _IEEE_LIBM + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * ANSI/POSIX + */ +extern double acos __P((double)); +extern double asin __P((double)); +extern double atan __P((double)); +extern double atan2 __P((double, double)); +extern double cos __P((double)); +extern double sin __P((double)); +extern double tan __P((double)); + +extern double cosh __P((double)); +extern double sinh __P((double)); +extern double tanh __P((double)); + +extern double exp __P((double)); +extern double frexp __P((double, int *)); +extern double ldexp __P((double, int)); +extern double log __P((double)); +extern double log10 __P((double)); +extern double modf __P((double, double *)); + +extern double pow __P((double, double)); +extern double sqrt __P((double)); + +extern double ceil __P((double)); +extern double fabs __P((double)); +extern double floor __P((double)); +extern double fmod __P((double, double)); + +extern double erf __P((double)); +extern double erfc __P((double)); +extern double gamma __P((double)); +extern double hypot __P((double, double)); + +#if !defined(isnan) +#define isnan(x) ((x) != (x)) +#endif + +extern int finite __P((double)); +extern double j0 __P((double)); +extern double j1 __P((double)); +extern double jn __P((int, double)); +extern double lgamma __P((double)); +extern double y0 __P((double)); +extern double y1 __P((double)); +extern double yn __P((int, double)); + +extern double acosh __P((double)); +extern double asinh __P((double)); +extern double atanh __P((double)); +extern double cbrt __P((double)); +extern double logb __P((double)); +extern double nextafter __P((double, double)); +extern double remainder __P((double, double)); +#ifdef _SCALB_INT +extern double scalb __P((double, int)); +#else +extern double scalb __P((double, double)); +#endif + +extern int matherr __P((struct exception *)); + +/* + * IEEE Test Vector + */ +extern double significand __P((double)); + +/* + * Functions callable from C, intended to support IEEE arithmetic. + */ +extern double copysign __P((double, double)); +extern int ilogb __P((double)); +extern double rint __P((double)); +extern double scalbn __P((double, int)); + +/* + * BSD math library entry points + */ +extern double expm1 __P((double)); +extern double log1p __P((double)); + +/* + * Reentrant version of gamma & lgamma; passes signgam back by reference + * as the second argument; user must allocate space for signgam. + */ +#ifdef _REENTRANT +extern double gamma_r __P((double, int *)); +extern double lgamma_r __P((double, int *)); +#endif /* _REENTRANT */ + +/* ieee style elementary functions */ +extern double __ieee754_sqrt __P((double)); +extern double __ieee754_acos __P((double)); +extern double __ieee754_acosh __P((double)); +extern double __ieee754_log __P((double)); +extern double __ieee754_atanh __P((double)); +extern double __ieee754_asin __P((double)); +extern double __ieee754_atan2 __P((double,double)); +extern double __ieee754_exp __P((double)); +extern double __ieee754_cosh __P((double)); +extern double __ieee754_fmod __P((double,double)); +extern double __ieee754_pow __P((double,double)); +extern double __ieee754_lgamma_r __P((double,int *)); +extern double __ieee754_gamma_r __P((double,int *)); +extern double __ieee754_lgamma __P((double)); +extern double __ieee754_gamma __P((double)); +extern double __ieee754_log10 __P((double)); +extern double __ieee754_sinh __P((double)); +extern double __ieee754_hypot __P((double,double)); +extern double __ieee754_j0 __P((double)); +extern double __ieee754_j1 __P((double)); +extern double __ieee754_y0 __P((double)); +extern double __ieee754_y1 __P((double)); +extern double __ieee754_jn __P((int,double)); +extern double __ieee754_yn __P((int,double)); +extern double __ieee754_remainder __P((double,double)); +extern int32_t __ieee754_rem_pio2 __P((double,double*)); +#ifdef _SCALB_INT +extern double __ieee754_scalb __P((double,int)); +#else +extern double __ieee754_scalb __P((double,double)); +#endif + +/* fdlibm kernel function */ +extern double __kernel_standard __P((double,double,int)); +extern double __kernel_sin __P((double,double,int)); +extern double __kernel_cos __P((double,double)); +extern double __kernel_tan __P((double,double,int)); +extern int __kernel_rem_pio2 __P((double*,double*,int,int,int,const int*)); + +/* Classpath extensions */ + +/* The original code used statements like + n0 = ((*(int*)&one)>>29)^1; * index of high word * + ix0 = *(n0+(int*)&x); * high word of x * + ix1 = *((1-n0)+(int*)&x); * low word of x * + to dig two 32 bit words out of the 64 bit IEEE floating point + value. That is non-ANSI, and, moreover, the gcc instruction + scheduler gets it wrong. We instead use the following macros. + Unlike the original code, we determine the endianness at compile + time, not at run time; I don't see much benefit to selecting + endianness at run time. */ + +#ifndef __IEEE_BIG_ENDIAN +#ifndef __IEEE_LITTLE_ENDIAN +#error Must define endianness +#endif +#endif + +/* A union which permits us to convert between a double and two 32 bit + ints. */ + +#ifdef __IEEE_BIG_ENDIAN + + typedef union + { + double value; + struct + { + uint32_t msw; + uint32_t lsw; + } parts; + } ieee_double_shape_type; + +#endif + +#ifdef __IEEE_LITTLE_ENDIAN + + typedef union + { + double value; + struct + { + uint32_t lsw; + uint32_t msw; + } parts; + } ieee_double_shape_type; + +#endif + + /* Get two 32 bit ints from a double. */ + +#define EXTRACT_WORDS(ix0,ix1,d) \ + do { \ + ieee_double_shape_type ew_u; \ + ew_u.value = (d); \ + (ix0) = ew_u.parts.msw; \ + (ix1) = ew_u.parts.lsw; \ + } while (0) + +/* Get the more significant 32 bit int from a double. */ + +#define GET_HIGH_WORD(i,d) \ + do { \ + ieee_double_shape_type gh_u; \ + gh_u.value = (d); \ + (i) = gh_u.parts.msw; \ + } while (0) + +/* Get the less significant 32 bit int from a double. */ + +#define GET_LOW_WORD(i,d) \ + do { \ + ieee_double_shape_type gl_u; \ + gl_u.value = (d); \ + (i) = gl_u.parts.lsw; \ + } while (0) + +/* Set a double from two 32 bit ints. */ + +#define INSERT_WORDS(d,ix0,ix1) \ + do { \ + ieee_double_shape_type iw_u; \ + iw_u.parts.msw = (ix0); \ + iw_u.parts.lsw = (ix1); \ + (d) = iw_u.value; \ + } while (0) + +/* Set the more significant 32 bits of a double from an int. */ + +#define SET_HIGH_WORD(d,v) \ + do { \ + ieee_double_shape_type sh_u; \ + sh_u.value = (d); \ + sh_u.parts.msw = (v); \ + (d) = sh_u.value; \ + } while (0) + +/* Set the less significant 32 bits of a double from an int. */ + +#define SET_LOW_WORD(d,v) \ + do { \ + ieee_double_shape_type sl_u; \ + sl_u.value = (d); \ + sl_u.parts.lsw = (v); \ + (d) = sl_u.value; \ + } while (0) + +/* A union which permits us to convert between a float and a 32 bit + int. */ + +typedef union +{ + float value; + uint32_t word; +} ieee_float_shape_type; + +/* Get a 32 bit int from a float. */ + +#define GET_FLOAT_WORD(i,d) \ +do { \ + ieee_float_shape_type gf_u; \ + gf_u.value = (d); \ + (i) = gf_u.word; \ +} while (0) + +/* Set a float from a 32 bit int. */ + +#define SET_FLOAT_WORD(d,i) \ +do { \ + ieee_float_shape_type sf_u; \ + sf_u.word = (i); \ + (d) = sf_u.value; \ +} while (0) + +#ifdef __cplusplus +} +#endif + +#endif /* __CLASSPATH_FDLIBM_H__ */ + diff --git a/libjava/classpath/native/fdlibm/ieeefp.h b/libjava/classpath/native/fdlibm/ieeefp.h new file mode 100644 index 000000000..c230bbb3c --- /dev/null +++ b/libjava/classpath/native/fdlibm/ieeefp.h @@ -0,0 +1,170 @@ +#ifndef __CLASSPATH_IEEEFP_H__ +#define __CLASSPATH_IEEEFP_H__ + +#ifndef __IEEE_BIG_ENDIAN +#ifndef __IEEE_LITTLE_ENDIAN + +#ifdef __alpha__ +#define __IEEE_LITTLE_ENDIAN +#endif + +#if defined(__arm__) || defined(__thumb__) +/* ARM traditionally used big-endian words; and within those words the + byte ordering was big or little endian depending upon the target. + Modern floating-point formats are naturally ordered; in this case + __VFP_FP__ will be defined, even if soft-float. */ +#ifdef __VFP_FP__ +#ifdef __ARMEL__ +#define __IEEE_LITTLE_ENDIAN +#else +#define __IEEE_BIG_ENDIAN +#endif +#else +#define __IEEE_BIG_ENDIAN +#ifdef __ARMEL__ +#define __IEEE_BYTES_LITTLE_ENDIAN +#endif +#endif +#endif + +#ifdef __hppa__ +#define __IEEE_BIG_ENDIAN +#endif + +#if defined (__sparc) || defined (__sparc__) +#define __IEEE_BIG_ENDIAN +#endif + +#ifdef __m32r__ +#ifdef __LITTLE_ENDIAN__ +#define __IEEE_LITTLE_ENDIAN +#else +#define __IEEE_BIG_ENDIAN +#endif +#endif + +#if defined(__m68k__) || defined(__mc68000__) +#define __IEEE_BIG_ENDIAN +#endif + +#if defined (__H8300__) || defined (__H8300H__) +#define __IEEE_BIG_ENDIAN +#define __SMALL_BITFIELDS +#define _DOUBLE_IS_32BITS +#endif + +#ifdef __H8500__ +#define __IEEE_BIG_ENDIAN +#define __SMALL_BITFIELDS +#define _DOUBLE_IS_32BITS +#endif + +#ifdef __sh__ +#ifdef __LITTLE_ENDIAN__ +#define __IEEE_LITTLE_ENDIAN +#else +#define __IEEE_BIG_ENDIAN +#endif + +#ifdef __SH3E__ +#define _DOUBLE_IS_32BITS +#endif +#endif + +#ifdef _AM29K +#define __IEEE_BIG_ENDIAN +#endif + +#ifdef __i386__ +#define __IEEE_LITTLE_ENDIAN +#endif + +#ifdef __x86_64__ +#define __IEEE_LITTLE_ENDIAN +#endif + +#ifdef __i960__ +#define __IEEE_LITTLE_ENDIAN +#endif + +#ifdef __AVR32__ +#define __IEEE_BIG_ENDIAN +#endif + +#ifdef __MIPSEL__ +#define __IEEE_LITTLE_ENDIAN +#endif + +#ifdef __MIPSEB__ +#define __IEEE_BIG_ENDIAN +#endif + +#ifdef __pj__ +#ifdef __pjl__ +#define __IEEE_LITTLE_ENDIAN +#else +#define __IEEE_BIG_ENDIAN +#endif +#endif + +/* necv70 was __IEEE_LITTLE_ENDIAN. */ + +#ifdef __W65__ +#define __IEEE_LITTLE_ENDIAN +#define __SMALL_BITFIELDS +#define _DOUBLE_IS_32BITS +#endif + +#if defined(__Z8001__) || defined(__Z8002__) +#define __IEEE_BIG_ENDIAN +#endif + +#ifdef __m88k__ +#define __IEEE_BIG_ENDIAN +#endif + +#ifdef __v800 +#define __IEEE_LITTLE_ENDIAN +#endif + +#if defined (__PPC__) || defined (__ppc__) || defined (__powerpc__) || defined (__ppc64__) || defined (_POWER) || defined (_IBMR2) +#if (defined(_BIG_ENDIAN) && _BIG_ENDIAN) || (defined(_AIX) && _AIX) || defined (__BIG_ENDIAN__)|| defined (__APPLE__) +#define __IEEE_BIG_ENDIAN +#else +#if (defined(_LITTLE_ENDIAN) && _LITTLE_ENDIAN) || (defined(__sun__) && __sun__) || (defined(__WIN32__) && __WIN32__) +#define __IEEE_LITTLE_ENDIAN +#endif +#endif +#endif + +#ifdef __fr30__ +#define __IEEE_BIG_ENDIAN +#endif + +#ifdef __mcore__ +#define __IEEE_BIG_ENDIAN +#endif + + +#ifdef __ia64__ +#ifdef __BIG_ENDIAN__ +#define __IEEE_BIG_ENDIAN +#else +#define __IEEE_LITTLE_ENDIAN +#endif +#endif + +#ifdef __s390__ +#define __IEEE_BIG_ENDIAN +#endif + +#ifndef __IEEE_BIG_ENDIAN +#ifndef __IEEE_LITTLE_ENDIAN +#error Endianess not declared!! +#endif /* not __IEEE_LITTLE_ENDIAN */ +#endif /* not __IEEE_BIG_ENDIAN */ + +#endif /* not __IEEE_LITTLE_ENDIAN */ +#endif /* not __IEEE_BIG_ENDIAN */ + +#endif /* __CLASSPATH_IEEEFP_H__ */ diff --git a/libjava/classpath/native/fdlibm/k_cos.c b/libjava/classpath/native/fdlibm/k_cos.c new file mode 100644 index 000000000..3ddc29897 --- /dev/null +++ b/libjava/classpath/native/fdlibm/k_cos.c @@ -0,0 +1,95 @@ + +/* @(#)k_cos.c 1.4 96/03/07 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* + * __kernel_cos( x, y ) + * kernel cos function on [-pi/4, pi/4], pi/4 ~ 0.785398164 + * Input x is assumed to be bounded by ~pi/4 in magnitude. + * Input y is the tail of x. + * + * Algorithm + * 1. Since cos(-x) = cos(x), we need only to consider positive x. + * 2. if x < 2^-27 (hx<0x3e400000 0), return 1 with inexact if x!=0. + * 3. cos(x) is approximated by a polynomial of degree 14 on + * [0,pi/4] + * 4 14 + * cos(x) ~ 1 - x*x/2 + C1*x + ... + C6*x + * where the Remes error is + * + * | 2 4 6 8 10 12 14 | -58 + * |cos(x)-(1-.5*x +C1*x +C2*x +C3*x +C4*x +C5*x +C6*x )| <= 2 + * | | + * + * 4 6 8 10 12 14 + * 4. let r = C1*x +C2*x +C3*x +C4*x +C5*x +C6*x , then + * cos(x) = 1 - x*x/2 + r + * since cos(x+y) ~ cos(x) - sin(x)*y + * ~ cos(x) - x*y, + * a correction term is necessary in cos(x) and hence + * cos(x+y) = 1 - (x*x/2 - (r - x*y)) + * For better accuracy when x > 0.3, let qx = |x|/4 with + * the last 32 bits mask off, and if x > 0.78125, let qx = 0.28125. + * Then + * cos(x+y) = (1-qx) - ((x*x/2-qx) - (r-x*y)). + * Note that 1-qx and (x*x/2-qx) is EXACT here, and the + * magnitude of the latter is at least a quarter of x*x/2, + * thus, reducing the rounding error in the subtraction. + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ +static const double +#else +static double +#endif +one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */ +C1 = 4.16666666666666019037e-02, /* 0x3FA55555, 0x5555554C */ +C2 = -1.38888888888741095749e-03, /* 0xBF56C16C, 0x16C15177 */ +C3 = 2.48015872894767294178e-05, /* 0x3EFA01A0, 0x19CB1590 */ +C4 = -2.75573143513906633035e-07, /* 0xBE927E4F, 0x809C52AD */ +C5 = 2.08757232129817482790e-09, /* 0x3E21EE9E, 0xBDB4B1C4 */ +C6 = -1.13596475577881948265e-11; /* 0xBDA8FAE9, 0xBE8838D4 */ + +#ifdef __STDC__ + double __kernel_cos(double x, double y) +#else + double __kernel_cos(x, y) + double x,y; +#endif +{ + double a,hz,z,r,qx; + int32_t ix; + GET_HIGH_WORD(ix, x); + ix &= 0x7fffffff; /* ix = |x|'s high word*/ + if(ix<0x3e400000) { /* if x < 2**27 */ + if(((int)x)==0) return one; /* generate inexact */ + } + z = x*x; + r = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*C6))))); + if(ix < 0x3FD33333) /* if |x| < 0.3 */ + return one - (0.5*z - (z*r - x*y)); + else { + if(ix > 0x3fe90000) { /* x > 0.78125 */ + qx = 0.28125; + } else { + INSERT_WORDS(qx,ix-0x00200000,0); + } + hz = 0.5*z-qx; + a = one-qx; + return a - (hz - (z*r-x*y)); + } +} +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/classpath/native/fdlibm/k_rem_pio2.c b/libjava/classpath/native/fdlibm/k_rem_pio2.c new file mode 100644 index 000000000..ec473ac0d --- /dev/null +++ b/libjava/classpath/native/fdlibm/k_rem_pio2.c @@ -0,0 +1,316 @@ + +/* @(#)k_rem_pio2.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* + * __kernel_rem_pio2(x,y,e0,nx,prec,ipio2) + * double x[],y[]; int e0,nx,prec; int ipio2[]; + * + * __kernel_rem_pio2 return the last three digits of N with + * y = x - N*pi/2 + * so that |y| < pi/2. + * + * The method is to compute the integer (mod 8) and fraction parts of + * (2/pi)*x without doing the full multiplication. In general we + * skip the part of the product that are known to be a huge integer ( + * more accurately, = 0 mod 8 ). Thus the number of operations are + * independent of the exponent of the input. + * + * (2/pi) is represented by an array of 24-bit integers in ipio2[]. + * + * Input parameters: + * x[] The input value (must be positive) is broken into nx + * pieces of 24-bit integers in double precision format. + * x[i] will be the i-th 24 bit of x. The scaled exponent + * of x[0] is given in input parameter e0 (i.e., x[0]*2^e0 + * match x's up to 24 bits. + * + * Example of breaking a double positive z into x[0]+x[1]+x[2]: + * e0 = ilogb(z)-23 + * z = scalbn(z,-e0) + * for i = 0,1,2 + * x[i] = floor(z) + * z = (z-x[i])*2**24 + * + * + * y[] ouput result in an array of double precision numbers. + * The dimension of y[] is: + * 24-bit precision 1 + * 53-bit precision 2 + * 64-bit precision 2 + * 113-bit precision 3 + * The actual value is the sum of them. Thus for 113-bit + * precison, one may have to do something like: + * + * long double t,w,r_head, r_tail; + * t = (long double)y[2] + (long double)y[1]; + * w = (long double)y[0]; + * r_head = t+w; + * r_tail = w - (r_head - t); + * + * e0 The exponent of x[0] + * + * nx dimension of x[] + * + * prec an integer indicating the precision: + * 0 24 bits (single) + * 1 53 bits (double) + * 2 64 bits (extended) + * 3 113 bits (quad) + * + * ipio2[] + * integer array, contains the (24*i)-th to (24*i+23)-th + * bit of 2/pi after binary point. The corresponding + * floating value is + * + * ipio2[i] * 2^(-24(i+1)). + * + * External function: + * double scalbn(), floor(); + * + * + * Here is the description of some local variables: + * + * jk jk+1 is the initial number of terms of ipio2[] needed + * in the computation. The recommended value is 2,3,4, + * 6 for single, double, extended,and quad. + * + * jz local integer variable indicating the number of + * terms of ipio2[] used. + * + * jx nx - 1 + * + * jv index for pointing to the suitable ipio2[] for the + * computation. In general, we want + * ( 2^e0*x[0] * ipio2[jv-1]*2^(-24jv) )/8 + * is an integer. Thus + * e0-3-24*jv >= 0 or (e0-3)/24 >= jv + * Hence jv = max(0,(e0-3)/24). + * + * jp jp+1 is the number of terms in PIo2[] needed, jp = jk. + * + * q[] double array with integral value, representing the + * 24-bits chunk of the product of x and 2/pi. + * + * q0 the corresponding exponent of q[0]. Note that the + * exponent for q[i] would be q0-24*i. + * + * PIo2[] double precision array, obtained by cutting pi/2 + * into 24 bits chunks. + * + * f[] ipio2[] in floating point + * + * iq[] integer array by breaking up q[] in 24-bits chunk. + * + * fq[] final product of x*(2/pi) in fq[0],..,fq[jk] + * + * ih integer. If >0 it indicates q[] is >= 0.5, hence + * it also indicates the *sign* of the result. + * + */ + + +/* + * Constants: + * The hexadecimal values are the intended ones for the following + * constants. The decimal values may be used, provided that the + * compiler will convert from decimal to binary accurately enough + * to produce the hexadecimal values shown. + */ + +#include "fdlibm.h" + +#ifdef __STDC__ +static const int init_jk[] = {2,3,4,6}; /* initial value for jk */ +#else +static int init_jk[] = {2,3,4,6}; +#endif + +#ifdef __STDC__ +static const double PIo2[] = { +#else +static double PIo2[] = { +#endif + 1.57079625129699707031e+00, /* 0x3FF921FB, 0x40000000 */ + 7.54978941586159635335e-08, /* 0x3E74442D, 0x00000000 */ + 5.39030252995776476554e-15, /* 0x3CF84698, 0x80000000 */ + 3.28200341580791294123e-22, /* 0x3B78CC51, 0x60000000 */ + 1.27065575308067607349e-29, /* 0x39F01B83, 0x80000000 */ + 1.22933308981111328932e-36, /* 0x387A2520, 0x40000000 */ + 2.73370053816464559624e-44, /* 0x36E38222, 0x80000000 */ + 2.16741683877804819444e-51, /* 0x3569F31D, 0x00000000 */ +}; + +#ifdef __STDC__ +static const double +#else +static double +#endif +zero = 0.0, +one = 1.0, +two24 = 1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */ +twon24 = 5.96046447753906250000e-08; /* 0x3E700000, 0x00000000 */ + +#ifdef __STDC__ + int __kernel_rem_pio2(double *x, double *y, int e0, int nx, int prec, const int *ipio2) +#else + int __kernel_rem_pio2(x,y,e0,nx,prec,ipio2) + double x[], y[]; int e0,nx,prec; int ipio2[]; +#endif +{ + int jz,jx,jv,jp,jk,carry,n,iq[20],i,j,k,m,q0,ih; + double z,fw,f[20],fq[20],q[20]; + + /* initialize jk*/ + jk = init_jk[prec]; + jp = jk; + + /* determine jx,jv,q0, note that 3>q0 */ + jx = nx-1; + jv = (e0-3)/24; if(jv<0) jv=0; + q0 = e0-24*(jv+1); + + /* set up f[0] to f[jx+jk] where f[jx+jk] = ipio2[jv+jk] */ + j = jv-jx; m = jx+jk; + for(i=0;i<=m;i++,j++) f[i] = (j<0)? zero : (double) ipio2[j]; + + /* compute q[0],q[1],...q[jk] */ + for (i=0;i<=jk;i++) { + for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j]; q[i] = fw; + } + + jz = jk; +recompute: + /* distill q[] into iq[] reversingly */ + for(i=0,j=jz,z=q[jz];j>0;i++,j--) { + fw = (double)((int)(twon24* z)); + iq[i] = (int)(z-two24*fw); + z = q[j-1]+fw; + } + + /* compute n */ + z = scalbn(z,q0); /* actual value of z */ + z -= 8.0*floor(z*0.125); /* trim off integer >= 8 */ + n = (int) z; + z -= (double)n; + ih = 0; + if(q0>0) { /* need iq[jz-1] to determine n */ + i = (iq[jz-1]>>(24-q0)); n += i; + iq[jz-1] -= i<<(24-q0); + ih = iq[jz-1]>>(23-q0); + } + else if(q0==0) ih = iq[jz-1]>>23; + else if(z>=0.5) ih=2; + + if(ih>0) { /* q > 0.5 */ + n += 1; carry = 0; + for(i=0;i0) { /* rare case: chance is 1 in 12 */ + switch(q0) { + case 1: + iq[jz-1] &= 0x7fffff; break; + case 2: + iq[jz-1] &= 0x3fffff; break; + } + } + if(ih==2) { + z = one - z; + if(carry!=0) z -= scalbn(one,q0); + } + } + + /* check if recomputation is needed */ + if(z==zero) { + j = 0; + for (i=jz-1;i>=jk;i--) j |= iq[i]; + if(j==0) { /* need recomputation */ + for(k=1;iq[jk-k]==0;k++); /* k = no. of terms needed */ + + for(i=jz+1;i<=jz+k;i++) { /* add q[jz+1] to q[jz+k] */ + f[jx+i] = (double) ipio2[jv+i]; + for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j]; + q[i] = fw; + } + jz += k; + goto recompute; + } + } + + /* chop off zero terms */ + if(z==0.0) { + jz -= 1; q0 -= 24; + while(iq[jz]==0) { jz--; q0-=24;} + } else { /* break z into 24-bit if necessary */ + z = scalbn(z,-q0); + if(z>=two24) { + fw = (double)((int)(twon24*z)); + iq[jz] = (int)(z-two24*fw); + jz += 1; q0 += 24; + iq[jz] = (int) fw; + } else iq[jz] = (int) z ; + } + + /* convert integer "bit" chunk to floating-point value */ + fw = scalbn(one,q0); + for(i=jz;i>=0;i--) { + q[i] = fw*(double)iq[i]; fw*=twon24; + } + + /* compute PIo2[0,...,jp]*q[jz,...,0] */ + for(i=jz;i>=0;i--) { + for(fw=0.0,k=0;k<=jp&&k<=jz-i;k++) fw += PIo2[k]*q[i+k]; + fq[jz-i] = fw; + } + + /* compress fq[] into y[] */ + switch(prec) { + case 0: + fw = 0.0; + for (i=jz;i>=0;i--) fw += fq[i]; + y[0] = (ih==0)? fw: -fw; + break; + case 1: + case 2: + fw = 0.0; + for (i=jz;i>=0;i--) fw += fq[i]; + y[0] = (ih==0)? fw: -fw; + fw = fq[0]-fw; + for (i=1;i<=jz;i++) fw += fq[i]; + y[1] = (ih==0)? fw: -fw; + break; + case 3: /* painful */ + for (i=jz;i>0;i--) { + fw = fq[i-1]+fq[i]; + fq[i] += fq[i-1]-fw; + fq[i-1] = fw; + } + for (i=jz;i>1;i--) { + fw = fq[i-1]+fq[i]; + fq[i] += fq[i-1]-fw; + fq[i-1] = fw; + } + for (fw=0.0,i=jz;i>=2;i--) fw += fq[i]; + if(ih==0) { + y[0] = fq[0]; y[1] = fq[1]; y[2] = fw; + } else { + y[0] = -fq[0]; y[1] = -fq[1]; y[2] = -fw; + } + } + return n&7; +} diff --git a/libjava/classpath/native/fdlibm/k_sin.c b/libjava/classpath/native/fdlibm/k_sin.c new file mode 100644 index 000000000..c60dadaf9 --- /dev/null +++ b/libjava/classpath/native/fdlibm/k_sin.c @@ -0,0 +1,78 @@ + +/* @(#)k_sin.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* __kernel_sin( x, y, iy) + * kernel sin function on [-pi/4, pi/4], pi/4 ~ 0.7854 + * Input x is assumed to be bounded by ~pi/4 in magnitude. + * Input y is the tail of x. + * Input iy indicates whether y is 0. (if iy=0, y assume to be 0). + * + * Algorithm + * 1. Since sin(-x) = -sin(x), we need only to consider positive x. + * 2. if x < 2^-27 (hx<0x3e400000 0), return x with inexact if x!=0. + * 3. sin(x) is approximated by a polynomial of degree 13 on + * [0,pi/4] + * 3 13 + * sin(x) ~ x + S1*x + ... + S6*x + * where + * + * |sin(x) 2 4 6 8 10 12 | -58 + * |----- - (1+S1*x +S2*x +S3*x +S4*x +S5*x +S6*x )| <= 2 + * | x | + * + * 4. sin(x+y) = sin(x) + sin'(x')*y + * ~ sin(x) + (1-x*x/2)*y + * For better accuracy, let + * 3 2 2 2 2 + * r = x *(S2+x *(S3+x *(S4+x *(S5+x *S6)))) + * then 3 2 + * sin(x) = x + (S1*x + (x *(r-y/2)+y)) + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ +static const double +#else +static double +#endif +half = 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */ +S1 = -1.66666666666666324348e-01, /* 0xBFC55555, 0x55555549 */ +S2 = 8.33333333332248946124e-03, /* 0x3F811111, 0x1110F8A6 */ +S3 = -1.98412698298579493134e-04, /* 0xBF2A01A0, 0x19C161D5 */ +S4 = 2.75573137070700676789e-06, /* 0x3EC71DE3, 0x57B1FE7D */ +S5 = -2.50507602534068634195e-08, /* 0xBE5AE5E6, 0x8A2B9CEB */ +S6 = 1.58969099521155010221e-10; /* 0x3DE5D93A, 0x5ACFD57C */ + +#ifdef __STDC__ + double __kernel_sin(double x, double y, int iy) +#else + double __kernel_sin(x, y, iy) + double x,y; int iy; /* iy=0 if y is zero */ +#endif +{ + double z,r,v; + int32_t ix; + GET_HIGH_WORD(ix,x); + ix &=0x7fffffff; /* high word of x */ + if(ix<0x3e400000) /* |x| < 2**-27 */ + {if((int)x==0) return x;} /* generate inexact */ + z = x*x; + v = z*x; + r = S2+z*(S3+z*(S4+z*(S5+z*S6))); + if(iy==0) return x+v*(S1+z*r); + else return x-((z*(half*y-v*r)-y)-v*S1); +} +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/classpath/native/fdlibm/k_tan.c b/libjava/classpath/native/fdlibm/k_tan.c new file mode 100644 index 000000000..975d238da --- /dev/null +++ b/libjava/classpath/native/fdlibm/k_tan.c @@ -0,0 +1,153 @@ +#pragma ident "@(#)k_tan.c 1.5 04/04/22 SMI" + +/* + * ==================================================== + * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved. + * + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* INDENT OFF */ +/* __kernel_tan( x, y, k ) + * kernel tan function on [-pi/4, pi/4], pi/4 ~ 0.7854 + * Input x is assumed to be bounded by ~pi/4 in magnitude. + * Input y is the tail of x. + * Input k indicates whether tan (if k = 1) or -1/tan (if k = -1) is returned. + * + * Algorithm + * 1. Since tan(-x) = -tan(x), we need only to consider positive x. + * 2. if x < 2^-28 (hx<0x3e300000 0), return x with inexact if x!=0. + * 3. tan(x) is approximated by a odd polynomial of degree 27 on + * [0,0.67434] + * 3 27 + * tan(x) ~ x + T1*x + ... + T13*x + * where + * + * |tan(x) 2 4 26 | -59.2 + * |----- - (1+T1*x +T2*x +.... +T13*x )| <= 2 + * | x | + * + * Note: tan(x+y) = tan(x) + tan'(x)*y + * ~ tan(x) + (1+x*x)*y + * Therefore, for better accuracy in computing tan(x+y), let + * 3 2 2 2 2 + * r = x *(T2+x *(T3+x *(...+x *(T12+x *T13)))) + * then + * 3 2 + * tan(x+y) = x + (T1*x + (x *(r+y)+y)) + * + * 4. For x in [0.67434,pi/4], let y = pi/4 - x, then + * tan(x) = tan(pi/4-y) = (1-tan(y))/(1+tan(y)) + * = 1 - 2*(tan(y) - (tan(y)^2)/(1+tan(y))) + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +static const double xxx[] = { + 3.33333333333334091986e-01, /* 3FD55555, 55555563 */ + 1.33333333333201242699e-01, /* 3FC11111, 1110FE7A */ + 5.39682539762260521377e-02, /* 3FABA1BA, 1BB341FE */ + 2.18694882948595424599e-02, /* 3F9664F4, 8406D637 */ + 8.86323982359930005737e-03, /* 3F8226E3, E96E8493 */ + 3.59207910759131235356e-03, /* 3F6D6D22, C9560328 */ + 1.45620945432529025516e-03, /* 3F57DBC8, FEE08315 */ + 5.88041240820264096874e-04, /* 3F4344D8, F2F26501 */ + 2.46463134818469906812e-04, /* 3F3026F7, 1A8D1068 */ + 7.81794442939557092300e-05, /* 3F147E88, A03792A6 */ + 7.14072491382608190305e-05, /* 3F12B80F, 32F0A7E9 */ + -1.85586374855275456654e-05, /* BEF375CB, DB605373 */ + 2.59073051863633712884e-05, /* 3EFB2A70, 74BF7AD4 */ +/* one */ 1.00000000000000000000e+00, /* 3FF00000, 00000000 */ +/* pio4 */ 7.85398163397448278999e-01, /* 3FE921FB, 54442D18 */ +/* pio4lo */ 3.06161699786838301793e-17 /* 3C81A626, 33145C07 */ +}; +#define one xxx[13] +#define pio4 xxx[14] +#define pio4lo xxx[15] +#define T xxx +/* INDENT ON */ + +double +__kernel_tan(double x, double y, int iy) { + double z, r, v, w, s; + int32_t ix, hx; + + GET_HIGH_WORD(hx,x); /* high word of x */ + ix = hx & 0x7fffffff; /* high word of |x| */ + if (ix < 0x3e300000) { /* x < 2**-28 */ + if ((int) x == 0) { /* generate inexact */ + uint32_t low; + GET_LOW_WORD(low,x); + if (((ix | low) | (iy + 1)) == 0) + return one / fabs(x); + else { + if (iy == 1) + return x; + else { /* compute -1 / (x+y) carefully */ + double a, t; + + z = w = x + y; + SET_LOW_WORD(z,0); + v = y - (z - x); + t = a = -one / w; + SET_LOW_WORD(t,0); + s = one + t * z; + return t + a * (s + t * v); + } + } + } + } + if (ix >= 0x3FE59428) { /* |x| >= 0.6744 */ + if (hx < 0) { + x = -x; + y = -y; + } + z = pio4 - x; + w = pio4lo - y; + x = z + w; + y = 0.0; + } + z = x * x; + w = z * z; + /* + * Break x^5*(T[1]+x^2*T[2]+...) into + * x^5(T[1]+x^4*T[3]+...+x^20*T[11]) + + * x^5(x^2*(T[2]+x^4*T[4]+...+x^22*[T12])) + */ + r = T[1] + w * (T[3] + w * (T[5] + w * (T[7] + w * (T[9] + + w * T[11])))); + v = z * (T[2] + w * (T[4] + w * (T[6] + w * (T[8] + w * (T[10] + + w * T[12]))))); + s = z * x; + r = y + z * (s * (r + v) + y); + r += T[0] * s; + w = x + r; + if (ix >= 0x3FE59428) { + v = (double) iy; + return (double) (1 - ((hx >> 30) & 2)) * + (v - 2.0 * (x - (w * w / (w + v) - r))); + } + if (iy == 1) + return w; + else { + /* + * if allow error up to 2 ulp, simply return + * -1.0 / (x+r) here + */ + /* compute -1.0 / (x+r) accurately */ + double a, t; + z = w; + SET_LOW_WORD(z,0); + v = r - (z - x); /* z+v = r+x */ + t = a = -1.0 / w; /* a = -1.0/w */ + SET_LOW_WORD(t,0); + s = 1.0 + t * z; + return t + a * (s + t * v); + } +} +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/classpath/native/fdlibm/mprec.c b/libjava/classpath/native/fdlibm/mprec.c new file mode 100644 index 000000000..8a7cdc039 --- /dev/null +++ b/libjava/classpath/native/fdlibm/mprec.c @@ -0,0 +1,1021 @@ +/**************************************************************** + * + * The author of this software is David M. Gay. + * + * Copyright (c) 1991 by AT&T. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose without fee is hereby granted, provided that this entire notice + * is included in all copies of any software which is or includes a copy + * or modification of this software and in all copies of the supporting + * documentation for such software. + * + * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY + * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY + * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. + * + ***************************************************************/ + +/* Please send bug reports to + David M. Gay + AT&T Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-2070 + U.S.A. + dmg@research.att.com or research!dmg + */ + +/* strtod for IEEE-, VAX-, and IBM-arithmetic machines. + * + * This strtod returns a nearest machine number to the input decimal + * string (or sets errno to ERANGE). With IEEE arithmetic, ties are + * broken by the IEEE round-even rule. Otherwise ties are broken by + * biased rounding (add half and chop). + * + * Inspired loosely by William D. Clinger's paper "How to Read Floating + * Point Numbers Accurately" [Proc. ACM SIGPLAN '90, pp. 92-101]. + * + * Modifications: + * + * 1. We only require IEEE, IBM, or VAX double-precision + * arithmetic (not IEEE double-extended). + * 2. We get by with floating-point arithmetic in a case that + * Clinger missed -- when we're computing d * 10^n + * for a small integer d and the integer n is not too + * much larger than 22 (the maximum integer k for which + * we can represent 10^k exactly), we may be able to + * compute (d*10^k) * 10^(e-k) with just one roundoff. + * 3. Rather than a bit-at-a-time adjustment of the binary + * result in the hard case, we use floating-point + * arithmetic to determine the adjustment to within + * one bit; only in really hard cases do we need to + * compute a second residual. + * 4. Because of 3., we don't need a large table of powers of 10 + * for ten-to-e (just some small tables, e.g. of 10^k + * for 0 <= k <= 22). + */ + +/* + * #define IEEE_8087 for IEEE-arithmetic machines where the least + * significant byte has the lowest address. + * #define IEEE_MC68k for IEEE-arithmetic machines where the most + * significant byte has the lowest address. + * #define Sudden_Underflow for IEEE-format machines without gradual + * underflow (i.e., that flush to zero on underflow). + * #define IBM for IBM mainframe-style floating-point arithmetic. + * #define VAX for VAX-style floating-point arithmetic. + * #define Unsigned_Shifts if >> does treats its left operand as unsigned. + * #define No_leftright to omit left-right logic in fast floating-point + * computation of dtoa. + * #define Check_FLT_ROUNDS if FLT_ROUNDS can assume the values 2 or 3. + * #define RND_PRODQUOT to use rnd_prod and rnd_quot (assembly routines + * that use extended-precision instructions to compute rounded + * products and quotients) with IBM. + * #define ROUND_BIASED for IEEE-format with biased rounding. + * #define Inaccurate_Divide for IEEE-format with correctly rounded + * products but inaccurate quotients, e.g., for Intel i860. + * #define Just_16 to store 16 bits per 32-bit long when doing high-precision + * integer arithmetic. Whether this speeds things up or slows things + * down depends on the machine and the number being converted. + */ + +/*#include <_ansi.h>*/ +#include +#include +#include +/* #include */ +#include "mprec.h" + +/* reent.c knows this value */ +/* #define _Kmax 15 */ + +#define _reent _Jv_reent +#define _Bigint _Jv_Bigint + +#define _REENT_CHECK_MP(x) +#define _REENT_MP_FREELIST(x) ((x)->_freelist) +#define _REENT_MP_P5S(x) ((x)->_p5s) + +typedef unsigned long __ULong; +typedef long __Long; + +static void * +mprec_calloc (void *ignore, size_t x1, size_t x2) +{ + char *result = (char *) malloc (x1 * x2); + memset (result, 0, x1 * x2); + return result; +} + +_Bigint * +_DEFUN (Balloc, (ptr, k), struct _reent *ptr _AND int k) +{ + int x; + _Bigint *rv ; + int new_k = k + 1; + + _REENT_CHECK_MP(ptr); + if (_REENT_MP_FREELIST(ptr) == NULL) + { + /* Allocate a list of pointers to the mprec objects */ + _REENT_MP_FREELIST(ptr) = (struct _Bigint **) mprec_calloc (ptr, + sizeof (struct _Bigint *), + new_k); + if (_REENT_MP_FREELIST(ptr) == NULL) + { + return NULL; + } + ptr->_max_k = new_k; + } + else if (new_k > ptr->_max_k) + { + struct _Bigint **new_list + = (struct _Bigint **) realloc (ptr->_freelist, + new_k * sizeof (struct _Bigint *)); + memset (&new_list[ptr->_max_k], 0, + (new_k - ptr->_max_k) * sizeof (struct _Bigint *)); + ptr->_freelist = new_list; + ptr->_max_k = new_k; + + } + + assert (k <= ptr->_max_k); + + if ((rv = _REENT_MP_FREELIST(ptr)[k]) != 0) + { + _REENT_MP_FREELIST(ptr)[k] = rv->_next; + } + else + { + x = 1 << k; + /* Allocate an mprec Bigint and stick in in the freelist */ + rv = (_Bigint *) mprec_calloc (ptr, + 1, + sizeof (_Bigint) + + (x-1) * sizeof(rv->_x)); + if (rv == NULL) return NULL; + rv->_k = k; + rv->_maxwds = x; + } + rv->_sign = rv->_wds = 0; + return rv; +} + +void +_DEFUN (Bfree, (ptr, v), struct _reent *ptr _AND _Bigint * v) +{ + _REENT_CHECK_MP(ptr); + if (v) + { + v->_next = _REENT_MP_FREELIST(ptr)[v->_k]; + _REENT_MP_FREELIST(ptr)[v->_k] = v; + } +} + +_Bigint * +_DEFUN (multadd, (ptr, b, m, a), + struct _reent *ptr _AND + _Bigint * b _AND + int m _AND + int a) +{ + int i, wds; + __ULong *x, y; +#ifdef Pack_32 + __ULong xi, z; +#endif + _Bigint *b1; + + wds = b->_wds; + x = b->_x; + i = 0; + do + { +#ifdef Pack_32 + xi = *x; + y = (xi & 0xffff) * m + a; + z = (xi >> 16) * m + (y >> 16); + a = (int) (z >> 16); + *x++ = (z << 16) + (y & 0xffff); +#else + y = *x * m + a; + a = (int) (y >> 16); + *x++ = y & 0xffff; +#endif + } + while (++i < wds); + if (a) + { + if (wds >= b->_maxwds) + { + b1 = Balloc (ptr, b->_k + 1); + Bcopy (b1, b); + Bfree (ptr, b); + b = b1; + } + b->_x[wds++] = a; + b->_wds = wds; + } + return b; +} + +_Bigint * +_DEFUN (s2b, (ptr, s, nd0, nd, y9), + struct _reent * ptr _AND + _CONST char *s _AND + int nd0 _AND + int nd _AND + __ULong y9) +{ + _Bigint *b; + int i, k; + __Long x, y; + + x = (nd + 8) / 9; + for (k = 0, y = 1; x > y; y <<= 1, k++); +#ifdef Pack_32 + b = Balloc (ptr, k); + b->_x[0] = y9; + b->_wds = 1; +#else + b = Balloc (ptr, k + 1); + b->_x[0] = y9 & 0xffff; + b->_wds = (b->_x[1] = y9 >> 16) ? 2 : 1; +#endif + + i = 9; + if (9 < nd0) + { + s += 9; + do + b = multadd (ptr, b, 10, *s++ - '0'); + while (++i < nd0); + s++; + } + else + s += 10; + for (; i < nd; i++) + b = multadd (ptr, b, 10, *s++ - '0'); + return b; +} + +int +_DEFUN (hi0bits, + (x), register __ULong x) +{ + register int k = 0; + + if (!(x & 0xffff0000)) + { + k = 16; + x <<= 16; + } + if (!(x & 0xff000000)) + { + k += 8; + x <<= 8; + } + if (!(x & 0xf0000000)) + { + k += 4; + x <<= 4; + } + if (!(x & 0xc0000000)) + { + k += 2; + x <<= 2; + } + if (!(x & 0x80000000)) + { + k++; + if (!(x & 0x40000000)) + return 32; + } + return k; +} + +int +_DEFUN (lo0bits, (y), __ULong *y) +{ + register int k; + register __ULong x = *y; + + if (x & 7) + { + if (x & 1) + return 0; + if (x & 2) + { + *y = x >> 1; + return 1; + } + *y = x >> 2; + return 2; + } + k = 0; + if (!(x & 0xffff)) + { + k = 16; + x >>= 16; + } + if (!(x & 0xff)) + { + k += 8; + x >>= 8; + } + if (!(x & 0xf)) + { + k += 4; + x >>= 4; + } + if (!(x & 0x3)) + { + k += 2; + x >>= 2; + } + if (!(x & 1)) + { + k++; + x >>= 1; + if (!x & 1) + return 32; + } + *y = x; + return k; +} + +_Bigint * +_DEFUN (i2b, (ptr, i), struct _reent * ptr _AND int i) +{ + _Bigint *b; + + b = Balloc (ptr, 1); + b->_x[0] = i; + b->_wds = 1; + return b; +} + +_Bigint * +_DEFUN (mult, (ptr, a, b), struct _reent * ptr _AND _Bigint * a _AND _Bigint * b) +{ + _Bigint *c; + int k, wa, wb, wc; + __ULong carry, y, z; + __ULong *x, *xa, *xae, *xb, *xbe, *xc, *xc0; +#ifdef Pack_32 + __ULong z2; +#endif + + if (a->_wds < b->_wds) + { + c = a; + a = b; + b = c; + } + k = a->_k; + wa = a->_wds; + wb = b->_wds; + wc = wa + wb; + if (wc > a->_maxwds) + k++; + c = Balloc (ptr, k); + for (x = c->_x, xa = x + wc; x < xa; x++) + *x = 0; + xa = a->_x; + xae = xa + wa; + xb = b->_x; + xbe = xb + wb; + xc0 = c->_x; +#ifdef Pack_32 + for (; xb < xbe; xb++, xc0++) + { + if ((y = *xb & 0xffff) != 0) + { + x = xa; + xc = xc0; + carry = 0; + do + { + z = (*x & 0xffff) * y + (*xc & 0xffff) + carry; + carry = z >> 16; + z2 = (*x++ >> 16) * y + (*xc >> 16) + carry; + carry = z2 >> 16; + Storeinc (xc, z2, z); + } + while (x < xae); + *xc = carry; + } + if ((y = *xb >> 16) != 0) + { + x = xa; + xc = xc0; + carry = 0; + z2 = *xc; + do + { + z = (*x & 0xffff) * y + (*xc >> 16) + carry; + carry = z >> 16; + Storeinc (xc, z, z2); + z2 = (*x++ >> 16) * y + (*xc & 0xffff) + carry; + carry = z2 >> 16; + } + while (x < xae); + *xc = z2; + } + } +#else + for (; xb < xbe; xc0++) + { + if (y = *xb++) + { + x = xa; + xc = xc0; + carry = 0; + do + { + z = *x++ * y + *xc + carry; + carry = z >> 16; + *xc++ = z & 0xffff; + } + while (x < xae); + *xc = carry; + } + } +#endif + for (xc0 = c->_x, xc = xc0 + wc; wc > 0 && !*--xc; --wc); + c->_wds = wc; + return c; +} + +_Bigint * +_DEFUN (pow5mult, + (ptr, b, k), struct _reent * ptr _AND _Bigint * b _AND int k) +{ + _Bigint *b1, *p5, *p51; + int i; + static _CONST int p05[3] = {5, 25, 125}; + + if ((i = k & 3) != 0) + b = multadd (ptr, b, p05[i - 1], 0); + + if (!(k >>= 2)) + return b; + _REENT_CHECK_MP(ptr); + if (!(p5 = _REENT_MP_P5S(ptr))) + { + /* first time */ + p5 = _REENT_MP_P5S(ptr) = i2b (ptr, 625); + p5->_next = 0; + } + for (;;) + { + if (k & 1) + { + b1 = mult (ptr, b, p5); + Bfree (ptr, b); + b = b1; + } + if (!(k >>= 1)) + break; + if (!(p51 = p5->_next)) + { + p51 = p5->_next = mult (ptr, p5, p5); + p51->_next = 0; + } + p5 = p51; + } + return b; +} + +_Bigint * +_DEFUN (lshift, (ptr, b, k), struct _reent * ptr _AND _Bigint * b _AND int k) +{ + int i, k1, n, n1; + _Bigint *b1; + __ULong *x, *x1, *xe, z; + +#ifdef Pack_32 + n = k >> 5; +#else + n = k >> 4; +#endif + k1 = b->_k; + n1 = n + b->_wds + 1; + for (i = b->_maxwds; n1 > i; i <<= 1) + k1++; + b1 = Balloc (ptr, k1); + x1 = b1->_x; + for (i = 0; i < n; i++) + *x1++ = 0; + x = b->_x; + xe = x + b->_wds; +#ifdef Pack_32 + if (k &= 0x1f) + { + k1 = 32 - k; + z = 0; + do + { + *x1++ = *x << k | z; + z = *x++ >> k1; + } + while (x < xe); + if ((*x1 = z) != 0) + ++n1; + } +#else + if (k &= 0xf) + { + k1 = 16 - k; + z = 0; + do + { + *x1++ = *x << k & 0xffff | z; + z = *x++ >> k1; + } + while (x < xe); + if (*x1 = z) + ++n1; + } +#endif + else + do + *x1++ = *x++; + while (x < xe); + b1->_wds = n1 - 1; + Bfree (ptr, b); + return b1; +} + +int +_DEFUN (cmp, (a, b), _Bigint * a _AND _Bigint * b) +{ + __ULong *xa, *xa0, *xb, *xb0; + int i, j; + + i = a->_wds; + j = b->_wds; +#ifdef DEBUG + if (i > 1 && !a->_x[i - 1]) + Bug ("cmp called with a->_x[a->_wds-1] == 0"); + if (j > 1 && !b->_x[j - 1]) + Bug ("cmp called with b->_x[b->_wds-1] == 0"); +#endif + if (i -= j) + return i; + xa0 = a->_x; + xa = xa0 + j; + xb0 = b->_x; + xb = xb0 + j; + for (;;) + { + if (*--xa != *--xb) + return *xa < *xb ? -1 : 1; + if (xa <= xa0) + break; + } + return 0; +} + +_Bigint * +_DEFUN (diff, (ptr, a, b), struct _reent * ptr _AND + _Bigint * a _AND _Bigint * b) +{ + _Bigint *c; + int i, wa, wb; + __Long borrow, y; /* We need signed shifts here. */ + __ULong *xa, *xae, *xb, *xbe, *xc; +#ifdef Pack_32 + __Long z; +#endif + + i = cmp (a, b); + if (!i) + { + c = Balloc (ptr, 0); + c->_wds = 1; + c->_x[0] = 0; + return c; + } + if (i < 0) + { + c = a; + a = b; + b = c; + i = 1; + } + else + i = 0; + c = Balloc (ptr, a->_k); + c->_sign = i; + wa = a->_wds; + xa = a->_x; + xae = xa + wa; + wb = b->_wds; + xb = b->_x; + xbe = xb + wb; + xc = c->_x; + borrow = 0; +#ifdef Pack_32 + do + { + y = (*xa & 0xffff) - (*xb & 0xffff) + borrow; + borrow = y >> 16; + Sign_Extend (borrow, y); + z = (*xa++ >> 16) - (*xb++ >> 16) + borrow; + borrow = z >> 16; + Sign_Extend (borrow, z); + Storeinc (xc, z, y); + } + while (xb < xbe); + while (xa < xae) + { + y = (*xa & 0xffff) + borrow; + borrow = y >> 16; + Sign_Extend (borrow, y); + z = (*xa++ >> 16) + borrow; + borrow = z >> 16; + Sign_Extend (borrow, z); + Storeinc (xc, z, y); + } +#else + do + { + y = *xa++ - *xb++ + borrow; + borrow = y >> 16; + Sign_Extend (borrow, y); + *xc++ = y & 0xffff; + } + while (xb < xbe); + while (xa < xae) + { + y = *xa++ + borrow; + borrow = y >> 16; + Sign_Extend (borrow, y); + *xc++ = y & 0xffff; + } +#endif + while (!*--xc) + wa--; + c->_wds = wa; + return c; +} + +double +_DEFUN (ulp, (_x), double _x) +{ + union double_union x, a; + register int32_t L; + + x.d = _x; + + L = (word0 (x) & Exp_mask) - (P - 1) * Exp_msk1; +#ifndef Sudden_Underflow + if (L > 0) + { +#endif +#ifdef IBM + L |= Exp_msk1 >> 4; +#endif + word0 (a) = L; +#ifndef _DOUBLE_IS_32BITS + word1 (a) = 0; +#endif + +#ifndef Sudden_Underflow + } + else + { + L = -L >> Exp_shift; + if (L < Exp_shift) + { + word0 (a) = 0x80000 >> L; +#ifndef _DOUBLE_IS_32BITS + word1 (a) = 0; +#endif + } + else + { + word0 (a) = 0; + L -= Exp_shift; +#ifndef _DOUBLE_IS_32BITS + word1 (a) = L >= 31 ? 1 : 1 << (31 - L); +#endif + } + } +#endif + return a.d; +} + +double +_DEFUN (b2d, (a, e), + _Bigint * a _AND int *e) +{ + __ULong *xa, *xa0, w, y, z; + int k; + union double_union d; +#ifdef VAX + __ULong d0, d1; +#else +#define d0 word0(d) +#define d1 word1(d) +#endif + + xa0 = a->_x; + xa = xa0 + a->_wds; + y = *--xa; +#ifdef DEBUG + if (!y) + Bug ("zero y in b2d"); +#endif + k = hi0bits (y); + *e = 32 - k; +#ifdef Pack_32 + if (k < Ebits) + { + d0 = Exp_1 | y >> (Ebits - k); + w = xa > xa0 ? *--xa : 0; +#ifndef _DOUBLE_IS_32BITS + d1 = y << ((32 - Ebits) + k) | w >> (Ebits - k); +#endif + goto ret_d; + } + z = xa > xa0 ? *--xa : 0; + if (k -= Ebits) + { + d0 = Exp_1 | y << k | z >> (32 - k); + y = xa > xa0 ? *--xa : 0; +#ifndef _DOUBLE_IS_32BITS + d1 = z << k | y >> (32 - k); +#endif + } + else + { + d0 = Exp_1 | y; +#ifndef _DOUBLE_IS_32BITS + d1 = z; +#endif + } +#else + if (k < Ebits + 16) + { + z = xa > xa0 ? *--xa : 0; + d0 = Exp_1 | y << k - Ebits | z >> Ebits + 16 - k; + w = xa > xa0 ? *--xa : 0; + y = xa > xa0 ? *--xa : 0; + d1 = z << k + 16 - Ebits | w << k - Ebits | y >> 16 + Ebits - k; + goto ret_d; + } + z = xa > xa0 ? *--xa : 0; + w = xa > xa0 ? *--xa : 0; + k -= Ebits + 16; + d0 = Exp_1 | y << k + 16 | z << k | w >> 16 - k; + y = xa > xa0 ? *--xa : 0; + d1 = w << k + 16 | y << k; +#endif +ret_d: +#ifdef VAX + word0 (d) = d0 >> 16 | d0 << 16; + word1 (d) = d1 >> 16 | d1 << 16; +#else +#undef d0 +#undef d1 +#endif + return d.d; +} + +_Bigint * +_DEFUN (d2b, + (ptr, _d, e, bits), + struct _reent * ptr _AND + double _d _AND + int *e _AND + int *bits) + +{ + union double_union d; + _Bigint *b; + int de, i, k; + __ULong *x, y, z; +#ifdef VAX + __ULong d0, d1; +#endif + d.d = _d; +#ifdef VAX + d0 = word0 (d) >> 16 | word0 (d) << 16; + d1 = word1 (d) >> 16 | word1 (d) << 16; +#else +#define d0 word0(d) +#define d1 word1(d) + d.d = _d; +#endif + +#ifdef Pack_32 + b = Balloc (ptr, 1); +#else + b = Balloc (ptr, 2); +#endif + x = b->_x; + + z = d0 & Frac_mask; + d0 &= 0x7fffffff; /* clear sign bit, which we ignore */ +#ifdef Sudden_Underflow + de = (int) (d0 >> Exp_shift); +#ifndef IBM + z |= Exp_msk11; +#endif +#else + if ((de = (int) (d0 >> Exp_shift)) != 0) + z |= Exp_msk1; +#endif +#ifdef Pack_32 +#ifndef _DOUBLE_IS_32BITS + if (d1) + { + y = d1; + k = lo0bits (&y); + if (k) + { + x[0] = y | z << (32 - k); + z >>= k; + } + else + x[0] = y; + i = b->_wds = (x[1] = z) ? 2 : 1; + } + else +#endif + { +#ifdef DEBUG + if (!z) + Bug ("Zero passed to d2b"); +#endif + k = lo0bits (&z); + x[0] = z; + i = b->_wds = 1; +#ifndef _DOUBLE_IS_32BITS + k += 32; +#endif + } +#else + if (d1) + { + y = d1; + k = lo0bits (&y); + if (k) + if (k >= 16) + { + x[0] = y | z << 32 - k & 0xffff; + x[1] = z >> k - 16 & 0xffff; + x[2] = z >> k; + i = 2; + } + else + { + x[0] = y & 0xffff; + x[1] = y >> 16 | z << 16 - k & 0xffff; + x[2] = z >> k & 0xffff; + x[3] = z >> k + 16; + i = 3; + } + else + { + x[0] = y & 0xffff; + x[1] = y >> 16; + x[2] = z & 0xffff; + x[3] = z >> 16; + i = 3; + } + } + else + { +#ifdef DEBUG + if (!z) + Bug ("Zero passed to d2b"); +#endif + k = lo0bits (&z); + if (k >= 16) + { + x[0] = z; + i = 0; + } + else + { + x[0] = z & 0xffff; + x[1] = z >> 16; + i = 1; + } + k += 32; + } + while (!x[i]) + --i; + b->_wds = i + 1; +#endif +#ifndef Sudden_Underflow + if (de) + { +#endif +#ifdef IBM + *e = (de - Bias - (P - 1) << 2) + k; + *bits = 4 * P + 8 - k - hi0bits (word0 (d) & Frac_mask); +#else + *e = de - Bias - (P - 1) + k; + *bits = P - k; +#endif +#ifndef Sudden_Underflow + } + else + { + *e = de - Bias - (P - 1) + 1 + k; +#ifdef Pack_32 + *bits = 32 * i - hi0bits (x[i - 1]); +#else + *bits = (i + 2) * 16 - hi0bits (x[i]); +#endif + } +#endif + return b; +} +#undef d0 +#undef d1 + +double +_DEFUN (ratio, (a, b), _Bigint * a _AND _Bigint * b) + +{ + union double_union da, db; + int k, ka, kb; + + da.d = b2d (a, &ka); + db.d = b2d (b, &kb); +#ifdef Pack_32 + k = ka - kb + 32 * (a->_wds - b->_wds); +#else + k = ka - kb + 16 * (a->_wds - b->_wds); +#endif +#ifdef IBM + if (k > 0) + { + word0 (da) += (k >> 2) * Exp_msk1; + if (k &= 3) + da.d *= 1 << k; + } + else + { + k = -k; + word0 (db) += (k >> 2) * Exp_msk1; + if (k &= 3) + db.d *= 1 << k; + } +#else + if (k > 0) + word0 (da) += k * Exp_msk1; + else + { + k = -k; + word0 (db) += k * Exp_msk1; + } +#endif + return da.d / db.d; +} + + +_CONST double + tens[] = +{ + 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, + 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, + 1e20, 1e21, 1e22, 1e23, 1e24 + +}; + +#if !defined(_DOUBLE_IS_32BITS) && !defined(__v800) +_CONST double bigtens[] = +{1e16, 1e32, 1e64, 1e128, 1e256}; + +_CONST double tinytens[] = +{1e-16, 1e-32, 1e-64, 1e-128, 1e-256}; +#else +_CONST double bigtens[] = +{1e16, 1e32}; + +_CONST double tinytens[] = +{1e-16, 1e-32}; +#endif + + +double +_DEFUN (_mprec_log10, (dig), + int dig) +{ + double v = 1.0; + if (dig < 24) + return tens[dig]; + while (dig > 0) + { + v *= 10; + dig--; + } + return v; +} diff --git a/libjava/classpath/native/fdlibm/mprec.h b/libjava/classpath/native/fdlibm/mprec.h new file mode 100644 index 000000000..1139b72f1 --- /dev/null +++ b/libjava/classpath/native/fdlibm/mprec.h @@ -0,0 +1,387 @@ +/**************************************************************** + * + * The author of this software is David M. Gay. + * + * Copyright (c) 1991, 2000 by AT&T. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose without fee is hereby granted, provided that this entire notice + * is included in all copies of any software which is or includes a copy + * or modification of this software and in all copies of the supporting + * documentation for such software. + * + * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY + * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY + * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. + * + ***************************************************************/ + +/* Please send bug reports to + David M. Gay + AT&T Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-2070 + U.S.A. + dmg@research.att.com or research!dmg + */ + +#ifndef __CLASSPATH_MPREC_H__ +#define __CLASSPATH_MPREC_H__ + +#include +#include "config-int.h" +#include "ieeefp.h" +/* CLASSPATH LOCAL */ +#include "namespace.h" + +#if defined HAVE_SYS_TYPES_H +#include +#endif + +#if defined HAVE_SYS_CONFIG_H +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + + /* These typedefs are true for the targets running Java. */ + +#ifdef __IEEE_LITTLE_ENDIAN +#define IEEE_8087 +#endif + +#ifdef __IEEE_BIG_ENDIAN +#define IEEE_MC68k +#endif + +#ifdef __Z8000__ +#define Just_16 +#endif + +#ifdef DEBUG +#include "stdio.h" +#include +#define Bug(x) {fprintf(stderr, "%s\n", x); exit(1);} +#endif + + +#ifdef Unsigned_Shifts +#define Sign_Extend(a,b) if (b < 0) a |= (uint32_t)0xffff0000; +#else +#define Sign_Extend(a,b) /*no-op*/ +#endif + +#if defined(IEEE_8087) + defined(IEEE_MC68k) + defined(VAX) + defined(IBM) != 1 +Exactly one of IEEE_8087, IEEE_MC68k, VAX, or IBM should be defined. +#endif + +/* If we are going to examine or modify specific bits in a double using + the word0 and/or word1 macros, then we must wrap the double inside + a union. This is necessary to avoid undefined behavior according to + the ANSI C spec. */ +union double_union +{ + double d; + uint32_t i[2]; +}; + +#ifdef IEEE_8087 +#define word0(x) (x.i[1]) +#define word1(x) (x.i[0]) +#else +#define word0(x) (x.i[0]) +#define word1(x) (x.i[1]) +#endif + +/* The following definition of Storeinc is appropriate for MIPS processors. + * An alternative that might be better on some machines is + * #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff) + */ +#if defined(__IEEE_BYTES_LITTLE_ENDIAN) + defined(IEEE_8087) + defined(VAX) +#define Storeinc(a,b,c) (((unsigned short *)a)[1] = (unsigned short)b, \ +((unsigned short *)a)[0] = (unsigned short)c, a++) +#else +#define Storeinc(a,b,c) (((unsigned short *)a)[0] = (unsigned short)b, \ +((unsigned short *)a)[1] = (unsigned short)c, a++) +#endif + +/* #define P DBL_MANT_DIG */ +/* Ten_pmax = floor(P*log(2)/log(5)) */ +/* Bletch = (highest power of 2 < DBL_MAX_10_EXP) / 16 */ +/* Quick_max = floor((P-1)*log(FLT_RADIX)/log(10) - 1) */ +/* Int_max = floor(P*log(FLT_RADIX)/log(10) - 1) */ + +#if defined(IEEE_8087) + defined(IEEE_MC68k) +#if defined (_DOUBLE_IS_32BITS) +#define Exp_shift 23 +#define Exp_shift1 23 +#define Exp_msk1 ((uint32_t)0x00800000L) +#define Exp_msk11 ((uint32_t)0x00800000L) +#define Exp_mask ((uint32_t)0x7f800000L) +#define P 24 +#define Bias 127 +#if 0 +#define IEEE_Arith /* it is, but the code doesn't handle IEEE singles yet */ +#endif +#define Emin (-126) +#define Exp_1 ((uint32_t)0x3f800000L) +#define Exp_11 ((uint32_t)0x3f800000L) +#define Ebits 8 +#define Frac_mask ((uint32_t)0x007fffffL) +#define Frac_mask1 ((uint32_t)0x007fffffL) +#define Ten_pmax 10 +#define Sign_bit ((uint32_t)0x80000000L) +#define Ten_pmax 10 +#define Bletch 2 +#define Bndry_mask ((uint32_t)0x007fffffL) +#define Bndry_mask1 ((uint32_t)0x007fffffL) +#define LSB 1 +#define Sign_bit ((uint32_t)0x80000000L) +#define Log2P 1 +#define Tiny0 0 +#define Tiny1 1 +#define Quick_max 5 +#define Int_max 6 +#define Infinite(x) (word0(x) == ((uint32_t)0x7f800000L)) +#undef word0 +#undef word1 + +#define word0(x) (x.i[0]) +#define word1(x) 0 +#else + +#define Exp_shift 20 +#define Exp_shift1 20 +#define Exp_msk1 ((uint32_t)0x100000L) +#define Exp_msk11 ((uint32_t)0x100000L) +#define Exp_mask ((uint32_t)0x7ff00000L) +#define P 53 +#define Bias 1023 +#define IEEE_Arith +#define Emin (-1022) +#define Exp_1 ((uint32_t)0x3ff00000L) +#define Exp_11 ((uint32_t)0x3ff00000L) +#define Ebits 11 +#define Frac_mask ((uint32_t)0xfffffL) +#define Frac_mask1 ((uint32_t)0xfffffL) +#define Ten_pmax 22 +#define Bletch 0x10 +#define Bndry_mask ((uint32_t)0xfffffL) +#define Bndry_mask1 ((uint32_t)0xfffffL) +#define LSB 1 +#define Sign_bit ((uint32_t)0x80000000L) +#define Log2P 1 +#define Tiny0 0 +#define Tiny1 1 +#define Quick_max 14 +#define Int_max 14 +#define Infinite(x) (word0(x) == ((uint32_t)0x7ff00000L)) /* sufficient test for here */ +#endif + +#else +#undef Sudden_Underflow +#define Sudden_Underflow +#ifdef IBM +#define Exp_shift 24 +#define Exp_shift1 24 +#define Exp_msk1 ((uint32_t)0x1000000L) +#define Exp_msk11 ((uint32_t)0x1000000L) +#define Exp_mask ((uint32_t)0x7f000000L) +#define P 14 +#define Bias 65 +#define Exp_1 ((uint32_t)0x41000000L) +#define Exp_11 ((uint32_t)0x41000000L) +#define Ebits 8 /* exponent has 7 bits, but 8 is the right value in b2d */ +#define Frac_mask ((uint32_t)0xffffffL) +#define Frac_mask1 ((uint32_t)0xffffffL) +#define Bletch 4 +#define Ten_pmax 22 +#define Bndry_mask ((uint32_t)0xefffffL) +#define Bndry_mask1 ((uint32_t)0xffffffL) +#define LSB 1 +#define Sign_bit ((uint32_t)0x80000000L) +#define Log2P 4 +#define Tiny0 ((uint32_t)0x100000L) +#define Tiny1 0 +#define Quick_max 14 +#define Int_max 15 +#else /* VAX */ +#define Exp_shift 23 +#define Exp_shift1 7 +#define Exp_msk1 0x80 +#define Exp_msk11 ((uint32_t)0x800000L) +#define Exp_mask ((uint32_t)0x7f80L) +#define P 56 +#define Bias 129 +#define Exp_1 ((uint32_t)0x40800000L) +#define Exp_11 ((uint32_t)0x4080L) +#define Ebits 8 +#define Frac_mask ((uint32_t)0x7fffffL) +#define Frac_mask1 ((uint32_t)0xffff007fL) +#define Ten_pmax 24 +#define Bletch 2 +#define Bndry_mask ((uint32_t)0xffff007fL) +#define Bndry_mask1 ((uint32_t)0xffff007fL) +#define LSB ((uint32_t)0x10000L) +#define Sign_bit ((uint32_t)0x8000L) +#define Log2P 1 +#define Tiny0 0x80 +#define Tiny1 0 +#define Quick_max 15 +#define Int_max 15 +#endif +#endif + +#ifndef IEEE_Arith +#define ROUND_BIASED +#endif + +#ifdef RND_PRODQUOT +#define rounded_product(a,b) a = rnd_prod(a, b) +#define rounded_quotient(a,b) a = rnd_quot(a, b) +#ifdef KR_headers +extern double rnd_prod(), rnd_quot(); +#else +extern double rnd_prod(double, double), rnd_quot(double, double); +#endif +#else +#define rounded_product(a,b) a *= b +#define rounded_quotient(a,b) a /= b +#endif + +#define Big0 (Frac_mask1 | Exp_msk1*(DBL_MAX_EXP+Bias-1)) +#define Big1 ((uint32_t)0xffffffffL) + +#ifndef Just_16 +/* When Pack_32 is not defined, we store 16 bits per 32-bit long. + * This makes some inner loops simpler and sometimes saves work + * during multiplications, but it often seems to make things slightly + * slower. Hence the default is now to store 32 bits per long. + */ + +#ifndef Pack_32 +#if SIZEOF_VOID_P != 8 +#define Pack_32 +#endif +#endif +#endif + + +#define MAX_BIGNUMS 16 +#ifdef Pack_32 +#define MAX_BIGNUM_WDS 32 +#else + /* Note that this is a workaround for */ +#define MAX_BIGNUM_WDS 128 +#endif + +struct _Jv_Bigint +{ + struct _Jv_Bigint *_next; + int _k, _maxwds, _sign, _wds; + unsigned long _x[1]; +}; + + +#define _PTR void * +#define _AND , +#define _NOARGS void +#define _CONST const +#define _VOLATILE volatile +#define _SIGNED signed +#define _DOTS , ... +#define _VOID void +#ifndef _EXFUN +#define _EXFUN(name, proto) name proto +#endif /* !EXFUN */ +#define _DEFUN(name, arglist, args) name(args) +#define _DEFUN_VOID(name) name(_NOARGS) +#define _CAST_VOID (void) + + +struct _Jv_reent +{ + /* local copy of errno */ + int _errno; + + /* used by mprec routines */ + struct _Jv_Bigint *_result; + int _result_k; + struct _Jv_Bigint *_p5s; + + struct _Jv_Bigint **_freelist; + int _max_k; +}; + + +typedef struct _Jv_Bigint _Jv_Bigint; + +#define Balloc _Jv_Balloc +#define Bfree _Jv_Bfree +#define multadd _Jv_multadd +#define s2b _Jv_s2b +#define lo0bits _Jv_lo0bits +#define hi0bits _Jv_hi0bits +#define i2b _Jv_i2b +#define mult _Jv_mult +#define pow5mult _Jv_pow5mult +#define lshift _Jv_lshift +#define cmp _Jv__mcmp +#define diff _Jv__mdiff +#define ulp _Jv_ulp +#define b2d _Jv_b2d +#define d2b _Jv_d2b +#define ratio _Jv_ratio + +#define tens _Jv__mprec_tens +#define bigtens _Jv__mprec_bigtens +#define tinytens _Jv__mprec_tinytens + +#define _dtoa _Jv_dtoa +#define _dtoa_r _Jv_dtoa_r +#define _strtod_r _Jv_strtod_r + +extern double _EXFUN(_strtod_r, (struct _Jv_reent *ptr, const char *s00, char **se)); +extern char* _EXFUN(_dtoa_r, (struct _Jv_reent *ptr, double d, + int mode, int ndigits, int *decpt, int *sign, + char **rve, int float_type)); +void _EXFUN(_dtoa, (double d, int mode, int ndigits, int *decpt, int *sign, + char **rve, char *buf, int float_type)); + +double _EXFUN(ulp,(double x)); +double _EXFUN(b2d,(_Jv_Bigint *a , int *e)); +_Jv_Bigint * _EXFUN(Balloc,(struct _Jv_reent *p, int k)); +void _EXFUN(Bfree,(struct _Jv_reent *p, _Jv_Bigint *v)); +_Jv_Bigint * _EXFUN(multadd,(struct _Jv_reent *p, _Jv_Bigint *, int, int)); +_Jv_Bigint * _EXFUN(s2b,(struct _Jv_reent *, const char*, int, int, unsigned long)); +_Jv_Bigint * _EXFUN(i2b,(struct _Jv_reent *,int)); +_Jv_Bigint * _EXFUN(mult, (struct _Jv_reent *, _Jv_Bigint *, _Jv_Bigint *)); +_Jv_Bigint * _EXFUN(pow5mult, (struct _Jv_reent *, _Jv_Bigint *, int k)); +int _EXFUN(hi0bits,(unsigned long)); +int _EXFUN(lo0bits,(unsigned long *)); +_Jv_Bigint * _EXFUN(d2b,(struct _Jv_reent *p, double d, int *e, int *bits)); +_Jv_Bigint * _EXFUN(lshift,(struct _Jv_reent *p, _Jv_Bigint *b, int k)); +_Jv_Bigint * _EXFUN(diff,(struct _Jv_reent *p, _Jv_Bigint *a, _Jv_Bigint *b)); +int _EXFUN(cmp,(_Jv_Bigint *a, _Jv_Bigint *b)); + +double _EXFUN(ratio,(_Jv_Bigint *a, _Jv_Bigint *b)); +#define Bcopy(x,y) memcpy((char *)&x->_sign, (char *)&y->_sign, y->_wds*sizeof(long) + 2*sizeof(int)) + +#if defined(_DOUBLE_IS_32BITS) && defined(__v800) +#define n_bigtens 2 +#else +#define n_bigtens 5 +#endif + +extern _CONST double tinytens[]; +extern _CONST double bigtens[]; +extern _CONST double tens[]; + +#ifdef __cplusplus +} +#endif + +#endif /* __CLASSPATH_MPREC_H__ */ diff --git a/libjava/classpath/native/fdlibm/namespace.h b/libjava/classpath/native/fdlibm/namespace.h new file mode 100644 index 000000000..02da970d0 --- /dev/null +++ b/libjava/classpath/native/fdlibm/namespace.h @@ -0,0 +1,3 @@ +/* GCJ LOCAL We don't use the renaming here, so this file is empty for us. + * Warning ! This is a generated file. Use build_mathnamespace to regenerate it + */ diff --git a/libjava/classpath/native/fdlibm/s_atan.c b/libjava/classpath/native/fdlibm/s_atan.c new file mode 100644 index 000000000..764c72e67 --- /dev/null +++ b/libjava/classpath/native/fdlibm/s_atan.c @@ -0,0 +1,140 @@ + +/* @(#)s_atan.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + * + */ + +/* atan(x) + * Method + * 1. Reduce x to positive by atan(x) = -atan(-x). + * 2. According to the integer k=4t+0.25 chopped, t=x, the argument + * is further reduced to one of the following intervals and the + * arctangent of t is evaluated by the corresponding formula: + * + * [0,7/16] atan(x) = t-t^3*(a1+t^2*(a2+...(a10+t^2*a11)...) + * [7/16,11/16] atan(x) = atan(1/2) + atan( (t-0.5)/(1+t/2) ) + * [11/16.19/16] atan(x) = atan( 1 ) + atan( (t-1)/(1+t) ) + * [19/16,39/16] atan(x) = atan(3/2) + atan( (t-1.5)/(1+1.5t) ) + * [39/16,INF] atan(x) = atan(INF) + atan( -1/t ) + * + * Constants: + * The hexadecimal values are the intended ones for the following + * constants. The decimal values may be used, provided that the + * compiler will convert from decimal to binary accurately enough + * to produce the hexadecimal values shown. + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ +static const double atanhi[] = { +#else +static double atanhi[] = { +#endif + 4.63647609000806093515e-01, /* atan(0.5)hi 0x3FDDAC67, 0x0561BB4F */ + 7.85398163397448278999e-01, /* atan(1.0)hi 0x3FE921FB, 0x54442D18 */ + 9.82793723247329054082e-01, /* atan(1.5)hi 0x3FEF730B, 0xD281F69B */ + 1.57079632679489655800e+00, /* atan(inf)hi 0x3FF921FB, 0x54442D18 */ +}; + +#ifdef __STDC__ +static const double atanlo[] = { +#else +static double atanlo[] = { +#endif + 2.26987774529616870924e-17, /* atan(0.5)lo 0x3C7A2B7F, 0x222F65E2 */ + 3.06161699786838301793e-17, /* atan(1.0)lo 0x3C81A626, 0x33145C07 */ + 1.39033110312309984516e-17, /* atan(1.5)lo 0x3C700788, 0x7AF0CBBD */ + 6.12323399573676603587e-17, /* atan(inf)lo 0x3C91A626, 0x33145C07 */ +}; + +#ifdef __STDC__ +static const double aT[] = { +#else +static double aT[] = { +#endif + 3.33333333333329318027e-01, /* 0x3FD55555, 0x5555550D */ + -1.99999999998764832476e-01, /* 0xBFC99999, 0x9998EBC4 */ + 1.42857142725034663711e-01, /* 0x3FC24924, 0x920083FF */ + -1.11111104054623557880e-01, /* 0xBFBC71C6, 0xFE231671 */ + 9.09088713343650656196e-02, /* 0x3FB745CD, 0xC54C206E */ + -7.69187620504482999495e-02, /* 0xBFB3B0F2, 0xAF749A6D */ + 6.66107313738753120669e-02, /* 0x3FB10D66, 0xA0D03D51 */ + -5.83357013379057348645e-02, /* 0xBFADDE2D, 0x52DEFD9A */ + 4.97687799461593236017e-02, /* 0x3FA97B4B, 0x24760DEB */ + -3.65315727442169155270e-02, /* 0xBFA2B444, 0x2C6A6C2F */ + 1.62858201153657823623e-02, /* 0x3F90AD3A, 0xE322DA11 */ +}; + +#ifdef __STDC__ + static const double +#else + static double +#endif +one = 1.0, +huge = 1.0e300; + +#ifdef __STDC__ + double atan(double x) +#else + double atan(x) + double x; +#endif +{ + double w,s1,s2,z; + int32_t ix,hx,id; + + GET_HIGH_WORD(hx,x); + ix = hx&0x7fffffff; + if(ix>=0x44100000) { /* if |x| >= 2^66 */ + uint32_t low; + + GET_LOW_WORD(low,x); + if(ix>0x7ff00000|| + (ix==0x7ff00000&&(low!=0))) + return x+x; /* NaN */ + if(hx>0) return atanhi[3]+atanlo[3]; + else return -atanhi[3]-atanlo[3]; + } if (ix < 0x3fdc0000) { /* |x| < 0.4375 */ + if (ix < 0x3e200000) { /* |x| < 2^-29 */ + if(huge+x>one) return x; /* raise inexact */ + } + id = -1; + } else { + x = fabs(x); + if (ix < 0x3ff30000) { /* |x| < 1.1875 */ + if (ix < 0x3fe60000) { /* 7/16 <=|x|<11/16 */ + id = 0; x = (2.0*x-one)/(2.0+x); + } else { /* 11/16<=|x|< 19/16 */ + id = 1; x = (x-one)/(x+one); + } + } else { + if (ix < 0x40038000) { /* |x| < 2.4375 */ + id = 2; x = (x-1.5)/(one+1.5*x); + } else { /* 2.4375 <= |x| < 2^66 */ + id = 3; x = -1.0/x; + } + }} + /* end of argument reduction */ + z = x*x; + w = z*z; + /* break sum from i=0 to 10 aT[i]z**(i+1) into odd and even poly */ + s1 = z*(aT[0]+w*(aT[2]+w*(aT[4]+w*(aT[6]+w*(aT[8]+w*aT[10]))))); + s2 = w*(aT[1]+w*(aT[3]+w*(aT[5]+w*(aT[7]+w*aT[9])))); + if (id<0) return x - x*(s1+s2); + else { + z = atanhi[id] - ((x*(s1+s2) - atanlo[id]) - x); + return (hx<0)? -z:z; + } +} +#endif /* _DOUBLE_IS_32BITS */ diff --git a/libjava/classpath/native/fdlibm/s_cbrt.c b/libjava/classpath/native/fdlibm/s_cbrt.c new file mode 100644 index 000000000..344b0a6e3 --- /dev/null +++ b/libjava/classpath/native/fdlibm/s_cbrt.c @@ -0,0 +1,96 @@ + +/* @(#)s_cbrt.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + * + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +/* cbrt(x) + * Return cube root of x + */ +#ifdef __STDC__ +static const uint32_t +#else +static uint32_t +#endif + B1 = 715094163, /* B1 = (682-0.03306235651)*2**20 */ + B2 = 696219795; /* B2 = (664-0.03306235651)*2**20 */ + +#ifdef __STDC__ +static const double +#else +static double +#endif +C = 5.42857142857142815906e-01, /* 19/35 = 0x3FE15F15, 0xF15F15F1 */ +D = -7.05306122448979611050e-01, /* -864/1225 = 0xBFE691DE, 0x2532C834 */ +E = 1.41428571428571436819e+00, /* 99/70 = 0x3FF6A0EA, 0x0EA0EA0F */ +F = 1.60714285714285720630e+00, /* 45/28 = 0x3FF9B6DB, 0x6DB6DB6E */ +G = 3.57142857142857150787e-01; /* 5/14 = 0x3FD6DB6D, 0xB6DB6DB7 */ + +#ifdef __STDC__ + double cbrt(double x) +#else + double cbrt(x) + double x; +#endif +{ + int32_t hx, lx, ht; + double r,s,t=0.0,w; + uint32_t sign; + + + GET_HIGH_WORD(hx,x); /* high word of x */ + sign=hx&0x80000000; /* sign= sign(x) */ + hx ^=sign; + if(hx>=0x7ff00000) return(x+x); /* cbrt(NaN,INF) is itself */ + GET_LOW_WORD(lx, x); + if((hx|lx)==0) + return(x); /* cbrt(0) is itself */ + + SET_HIGH_WORD(x,hx); /* x <- |x| */ + /* rough cbrt to 5 bits */ + if(hx<0x00100000) /* subnormal number */ + { + SET_HIGH_WORD(t,0x43500000); /* set t= 2**54 */ + t*=x; + GET_HIGH_WORD(ht,t); + SET_HIGH_WORD(t,ht/3+B2); + } + else + SET_HIGH_WORD(t,hx/3+B1); + + + /* new cbrt to 23 bits, may be implemented in single precision */ + r=t*t/x; + s=C+r*t; + t*=G+F/(s+E+D/s); + + /* chopped to 20 bits and make it larger than cbrt(x) */ + SET_LOW_WORD(t,0); + GET_HIGH_WORD(ht,t); + SET_HIGH_WORD(t,ht + 0x00000001); + + /* one step newton iteration to 53 bits with error less than 0.667 ulps */ + s=t*t; /* t*t is exact */ + r=x/s; + w=t+t; + r=(r-t)/(w+r); /* r-s is exact */ + t=t+t*r; + + /* retore the sign bit */ + GET_HIGH_WORD(ht,t); + SET_HIGH_WORD(t,ht|sign); + return(t); +} +#endif /* _DOUBLE_IS_32BITS */ diff --git a/libjava/classpath/native/fdlibm/s_ceil.c b/libjava/classpath/native/fdlibm/s_ceil.c new file mode 100644 index 000000000..7415b0da5 --- /dev/null +++ b/libjava/classpath/native/fdlibm/s_ceil.c @@ -0,0 +1,80 @@ + +/* @(#)s_ceil.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* + * ceil(x) + * Return x rounded toward -inf to integral value + * Method: + * Bit twiddling. + * Exception: + * Inexact flag raised if x not equal to ceil(x). + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ +static const double huge = 1.0e300; +#else +static double huge = 1.0e300; +#endif + +#ifdef __STDC__ + double ceil(double x) +#else + double ceil(x) + double x; +#endif +{ + int32_t i0,i1,j0; + uint32_t i,j; + EXTRACT_WORDS(i0,i1,x); + j0 = ((i0>>20)&0x7ff)-0x3ff; + if(j0<20) { + if(j0<0) { /* raise inexact if x != 0 */ + if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */ + if(i0<0) {i0=0x80000000;i1=0;} + else if((i0|i1)!=0) { i0=0x3ff00000;i1=0;} + } + } else { + i = (0x000fffff)>>j0; + if(((i0&i)|i1)==0) return x; /* x is integral */ + if(huge+x>0.0) { /* raise inexact flag */ + if(i0>0) i0 += (0x00100000)>>j0; + i0 &= (~i); i1=0; + } + } + } else if (j0>51) { + if(j0==0x400) return x+x; /* inf or NaN */ + else return x; /* x is integral */ + } else { + i = ((uint32_t)(0xffffffff))>>(j0-20); + if((i1&i)==0) return x; /* x is integral */ + if(huge+x>0.0) { /* raise inexact flag */ + if(i0>0) { + if(j0==20) i0+=1; + else { + j = i1 + (1<<(52-j0)); + if(j=0x7ff00000) return x-x; + + /* argument reduction needed */ + else { + n = __ieee754_rem_pio2(x,y); + switch(n&3) { + case 0: return __kernel_cos(y[0],y[1]); + case 1: return -__kernel_sin(y[0],y[1],1); + case 2: return -__kernel_cos(y[0],y[1]); + default: + return __kernel_sin(y[0],y[1],1); + } + } +} +#endif /* _DOUBLE_IS_32BITS */ diff --git a/libjava/classpath/native/fdlibm/s_expm1.c b/libjava/classpath/native/fdlibm/s_expm1.c new file mode 100644 index 000000000..c84e0b06f --- /dev/null +++ b/libjava/classpath/native/fdlibm/s_expm1.c @@ -0,0 +1,229 @@ + +/* @(#)s_expm1.c 1.5 04/04/22 */ +/* + * ==================================================== + * Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved. + * + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* expm1(x) + * Returns exp(x)-1, the exponential of x minus 1. + * + * Method + * 1. Argument reduction: + * Given x, find r and integer k such that + * + * x = k*ln2 + r, |r| <= 0.5*ln2 ~ 0.34658 + * + * Here a correction term c will be computed to compensate + * the error in r when rounded to a floating-point number. + * + * 2. Approximating expm1(r) by a special rational function on + * the interval [0,0.34658]: + * Since + * r*(exp(r)+1)/(exp(r)-1) = 2+ r^2/6 - r^4/360 + ... + * we define R1(r*r) by + * r*(exp(r)+1)/(exp(r)-1) = 2+ r^2/6 * R1(r*r) + * That is, + * R1(r**2) = 6/r *((exp(r)+1)/(exp(r)-1) - 2/r) + * = 6/r * ( 1 + 2.0*(1/(exp(r)-1) - 1/r)) + * = 1 - r^2/60 + r^4/2520 - r^6/100800 + ... + * We use a special Remes algorithm on [0,0.347] to generate + * a polynomial of degree 5 in r*r to approximate R1. The + * maximum error of this polynomial approximation is bounded + * by 2**-61. In other words, + * R1(z) ~ 1.0 + Q1*z + Q2*z**2 + Q3*z**3 + Q4*z**4 + Q5*z**5 + * where Q1 = -1.6666666666666567384E-2, + * Q2 = 3.9682539681370365873E-4, + * Q3 = -9.9206344733435987357E-6, + * Q4 = 2.5051361420808517002E-7, + * Q5 = -6.2843505682382617102E-9; + * (where z=r*r, and the values of Q1 to Q5 are listed below) + * with error bounded by + * | 5 | -61 + * | 1.0+Q1*z+...+Q5*z - R1(z) | <= 2 + * | | + * + * expm1(r) = exp(r)-1 is then computed by the following + * specific way which minimize the accumulation rounding error: + * 2 3 + * r r [ 3 - (R1 + R1*r/2) ] + * expm1(r) = r + --- + --- * [--------------------] + * 2 2 [ 6 - r*(3 - R1*r/2) ] + * + * To compensate the error in the argument reduction, we use + * expm1(r+c) = expm1(r) + c + expm1(r)*c + * ~ expm1(r) + c + r*c + * Thus c+r*c will be added in as the correction terms for + * expm1(r+c). Now rearrange the term to avoid optimization + * screw up: + * ( 2 2 ) + * ({ ( r [ R1 - (3 - R1*r/2) ] ) } r ) + * expm1(r+c)~r - ({r*(--- * [--------------------]-c)-c} - --- ) + * ({ ( 2 [ 6 - r*(3 - R1*r/2) ] ) } 2 ) + * ( ) + * + * = r - E + * 3. Scale back to obtain expm1(x): + * From step 1, we have + * expm1(x) = either 2^k*[expm1(r)+1] - 1 + * = or 2^k*[expm1(r) + (1-2^-k)] + * 4. Implementation notes: + * (A). To save one multiplication, we scale the coefficient Qi + * to Qi*2^i, and replace z by (x^2)/2. + * (B). To achieve maximum accuracy, we compute expm1(x) by + * (i) if x < -56*ln2, return -1.0, (raise inexact if x!=inf) + * (ii) if k=0, return r-E + * (iii) if k=-1, return 0.5*(r-E)-0.5 + * (iv) if k=1 if r < -0.25, return 2*((r+0.5)- E) + * else return 1.0+2.0*(r-E); + * (v) if (k<-2||k>56) return 2^k(1-(E-r)) - 1 (or exp(x)-1) + * (vi) if k <= 20, return 2^k((1-2^-k)-(E-r)), else + * (vii) return 2^k(1-((E+2^-k)-r)) + * + * Special cases: + * expm1(INF) is INF, expm1(NaN) is NaN; + * expm1(-INF) is -1, and + * for finite argument, only expm1(0)=0 is exact. + * + * Accuracy: + * according to an error analysis, the error is always less than + * 1 ulp (unit in the last place). + * + * Misc. info. + * For IEEE double + * if x > 7.09782712893383973096e+02 then expm1(x) overflow + * + * Constants: + * The hexadecimal values are the intended ones for the following + * constants. The decimal values may be used, provided that the + * compiler will convert from decimal to binary accurately enough + * to produce the hexadecimal values shown. + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ +static const double +#else +static double +#endif +one = 1.0, +huge = 1.0e+300, +tiny = 1.0e-300, +o_threshold = 7.09782712893383973096e+02,/* 0x40862E42, 0xFEFA39EF */ +ln2_hi = 6.93147180369123816490e-01,/* 0x3fe62e42, 0xfee00000 */ +ln2_lo = 1.90821492927058770002e-10,/* 0x3dea39ef, 0x35793c76 */ +invln2 = 1.44269504088896338700e+00,/* 0x3ff71547, 0x652b82fe */ + /* scaled coefficients related to expm1 */ +Q1 = -3.33333333333331316428e-02, /* BFA11111 111110F4 */ +Q2 = 1.58730158725481460165e-03, /* 3F5A01A0 19FE5585 */ +Q3 = -7.93650757867487942473e-05, /* BF14CE19 9EAADBB7 */ +Q4 = 4.00821782732936239552e-06, /* 3ED0CFCA 86E65239 */ +Q5 = -2.01099218183624371326e-07; /* BE8AFDB7 6E09C32D */ + +#ifdef __STDC__ + double expm1(double x) +#else + double expm1(x) + double x; +#endif +{ + double y,hi,lo,c,t,e,hxs,hfx,r1; + int32_t k,xsb; + uint32_t hx; + + GET_HIGH_WORD(hx,x); /* high word of x */ + xsb = hx&0x80000000; /* sign bit of x */ + if(xsb==0) y=x; else y= -x; /* y = |x| */ + hx &= 0x7fffffff; /* high word of |x| */ + + /* filter out huge and non-finite argument */ + if(hx >= 0x4043687A) { /* if |x|>=56*ln2 */ + if(hx >= 0x40862E42) { /* if |x|>=709.78... */ + if(hx>=0x7ff00000) { + uint32_t low; + GET_LOW_WORD(low,x); + if(((hx&0xfffff)|low)!=0) + return x+x; /* NaN */ + else return (xsb==0)? x:-1.0;/* exp(+-inf)={inf,-1} */ + } + if(x > o_threshold) return huge*huge; /* overflow */ + } + if(xsb!=0) { /* x < -56*ln2, return -1.0 with inexact */ + if(x+tiny<0.0) /* raise inexact */ + return tiny-one; /* return -1 */ + } + } + + /* argument reduction */ + if(hx > 0x3fd62e42) { /* if |x| > 0.5 ln2 */ + if(hx < 0x3FF0A2B2) { /* and |x| < 1.5 ln2 */ + if(xsb==0) + {hi = x - ln2_hi; lo = ln2_lo; k = 1;} + else + {hi = x + ln2_hi; lo = -ln2_lo; k = -1;} + } else { + k = invln2*x+((xsb==0)?0.5:-0.5); + t = k; + hi = x - t*ln2_hi; /* t*ln2_hi is exact here */ + lo = t*ln2_lo; + } + x = hi - lo; + c = (hi-x)-lo; + } + else if(hx < 0x3c900000) { /* when |x|<2**-54, return x */ + t = huge+x; /* return x with inexact flags when x!=0 */ + return x - (t-(huge+x)); + } + else k = 0; + + /* x is now in primary range */ + hfx = 0.5*x; + hxs = x*hfx; + r1 = one+hxs*(Q1+hxs*(Q2+hxs*(Q3+hxs*(Q4+hxs*Q5)))); + t = 3.0-r1*hfx; + e = hxs*((r1-t)/(6.0 - x*t)); + if(k==0) return x - (x*e-hxs); /* c is 0 */ + else { + e = (x*(e-c)-c); + e -= hxs; + if(k== -1) return 0.5*(x-e)-0.5; + if(k==1) + if(x < -0.25) return -2.0*(e-(x+0.5)); + else return one+2.0*(x-e); + if (k <= -2 || k>56) { /* suffice to return exp(x)-1 */ + uint32_t hy; + + y = one-(e-x); + GET_HIGH_WORD(hy,y); + SET_HIGH_WORD(y, hy + (k<<20)); /* add k to y's exponent */ + return y-one; + } + t = one; + if(k<20) { + uint32_t hy; + + SET_HIGH_WORD(t, 0x3ff00000 - (0x200000>>k)); /* t=1-2^-k */ + y = t-(e-x); + GET_HIGH_WORD(hy, y); + SET_HIGH_WORD(y, hy + (k<<20)); /* add k to y's exponent */ + } else { + uint32_t hy; + + SET_HIGH_WORD(t, (0x3ff-k)<<20); /* 2^-k */ + y = x-(e+t); + y += one; + GET_HIGH_WORD(hy, y); + SET_HIGH_WORD(y, hy + (k<<20)); /* add k to y's exponent */ + } + } + return y; +} +#endif /* _DOUBLE_IS_32BITS */ diff --git a/libjava/classpath/native/fdlibm/s_fabs.c b/libjava/classpath/native/fdlibm/s_fabs.c new file mode 100644 index 000000000..510c5a884 --- /dev/null +++ b/libjava/classpath/native/fdlibm/s_fabs.c @@ -0,0 +1,36 @@ + +/* @(#)s_fabs.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* + * fabs(x) returns the absolute value of x. + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double fabs(double x) +#else + double fabs(x) + double x; +#endif +{ + uint32_t hx; + + GET_HIGH_WORD(hx,x); + SET_HIGH_WORD(x, hx & 0x7fffffff); + return x; +} + +#endif /* _DOUBLE_IS_32BITS */ diff --git a/libjava/classpath/native/fdlibm/s_finite.c b/libjava/classpath/native/fdlibm/s_finite.c new file mode 100644 index 000000000..e35b776a4 --- /dev/null +++ b/libjava/classpath/native/fdlibm/s_finite.c @@ -0,0 +1,31 @@ + +/* @(#)s_finite.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* + * finite(x) returns 1 is x is finite, else 0; + * no branching! + */ + +#include "fdlibm.h" + +#ifdef __STDC__ + int finite(double x) +#else + int finite(x) + double x; +#endif +{ + uint32_t hx; + GET_HIGH_WORD(hx,x); + return (unsigned)((hx&0x7fffffff)-0x7ff00000)>>31; +} diff --git a/libjava/classpath/native/fdlibm/s_floor.c b/libjava/classpath/native/fdlibm/s_floor.c new file mode 100644 index 000000000..3dd8fff64 --- /dev/null +++ b/libjava/classpath/native/fdlibm/s_floor.c @@ -0,0 +1,80 @@ + +/* @(#)s_floor.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* + * floor(x) + * Return x rounded toward -inf to integral value + * Method: + * Bit twiddling. + * Exception: + * Inexact flag raised if x not equal to floor(x). + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ +static const double huge = 1.0e300; +#else +static double huge = 1.0e300; +#endif + +#ifdef __STDC__ + double floor(double x) +#else + double floor(x) + double x; +#endif +{ + int32_t i0,i1,j0; + uint32_t i,j; + EXTRACT_WORDS(i0,i1,x); + j0 = ((i0>>20)&0x7ff)-0x3ff; + if(j0<20) { + if(j0<0) { /* raise inexact if x != 0 */ + if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */ + if(i0>=0) {i0=i1=0;} + else if(((i0&0x7fffffff)|i1)!=0) + { i0=0xbff00000;i1=0;} + } + } else { + i = (0x000fffff)>>j0; + if(((i0&i)|i1)==0) return x; /* x is integral */ + if(huge+x>0.0) { /* raise inexact flag */ + if(i0<0) i0 += (0x00100000)>>j0; + i0 &= (~i); i1=0; + } + } + } else if (j0>51) { + if(j0==0x400) return x+x; /* inf or NaN */ + else return x; /* x is integral */ + } else { + i = ((uint32_t)(0xffffffff))>>(j0-20); + if((i1&i)==0) return x; /* x is integral */ + if(huge+x>0.0) { /* raise inexact flag */ + if(i0<0) { + if(j0==20) i0+=1; + else { + j = i1+(1<<(52-j0)); + if(j<(uint32_t)i1) i0 +=1 ; /* got a carry */ + i1=j; + } + } + i1 &= (~i); + } + } + INSERT_WORDS(x,i0,i1); + return x; +} +#endif /* _DOUBLE_IS_32BITS */ diff --git a/libjava/classpath/native/fdlibm/s_log1p.c b/libjava/classpath/native/fdlibm/s_log1p.c new file mode 100644 index 000000000..3b42ef523 --- /dev/null +++ b/libjava/classpath/native/fdlibm/s_log1p.c @@ -0,0 +1,168 @@ + +/* @(#)s_log1p.c 1.4 96/03/07 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* double log1p(double x) + * + * Method : + * 1. Argument Reduction: find k and f such that + * 1+x = 2^k * (1+f), + * where sqrt(2)/2 < 1+f < sqrt(2) . + * + * Note. If k=0, then f=x is exact. However, if k!=0, then f + * may not be representable exactly. In that case, a correction + * term is need. Let u=1+x rounded. Let c = (1+x)-u, then + * log(1+x) - log(u) ~ c/u. Thus, we proceed to compute log(u), + * and add back the correction term c/u. + * (Note: when x > 2**53, one can simply return log(x)) + * + * 2. Approximation of log1p(f). + * Let s = f/(2+f) ; based on log(1+f) = log(1+s) - log(1-s) + * = 2s + 2/3 s**3 + 2/5 s**5 + ....., + * = 2s + s*R + * We use a special Remes algorithm on [0,0.1716] to generate + * a polynomial of degree 14 to approximate R The maximum error + * of this polynomial approximation is bounded by 2**-58.45. In + * other words, + * 2 4 6 8 10 12 14 + * R(z) ~ Lp1*s +Lp2*s +Lp3*s +Lp4*s +Lp5*s +Lp6*s +Lp7*s + * (the values of Lp1 to Lp7 are listed in the program) + * and + * | 2 14 | -58.45 + * | Lp1*s +...+Lp7*s - R(z) | <= 2 + * | | + * Note that 2s = f - s*f = f - hfsq + s*hfsq, where hfsq = f*f/2. + * In order to guarantee error in log below 1ulp, we compute log + * by + * log1p(f) = f - (hfsq - s*(hfsq+R)). + * + * 3. Finally, log1p(x) = k*ln2 + log1p(f). + * = k*ln2_hi+(f-(hfsq-(s*(hfsq+R)+k*ln2_lo))) + * Here ln2 is split into two floating point number: + * ln2_hi + ln2_lo, + * where n*ln2_hi is always exact for |n| < 2000. + * + * Special cases: + * log1p(x) is NaN with signal if x < -1 (including -INF) ; + * log1p(+INF) is +INF; log1p(-1) is -INF with signal; + * log1p(NaN) is that NaN with no signal. + * + * Accuracy: + * according to an error analysis, the error is always less than + * 1 ulp (unit in the last place). + * + * Constants: + * The hexadecimal values are the intended ones for the following + * constants. The decimal values may be used, provided that the + * compiler will convert from decimal to binary accurately enough + * to produce the hexadecimal values shown. + * + * Note: Assuming log() return accurate answer, the following + * algorithm can be used to compute log1p(x) to within a few ULP: + * + * u = 1+x; + * if(u==1.0) return x ; else + * return log(u)*(x/(u-1.0)); + * + * See HP-15C Advanced Functions Handbook, p.193. + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ +static const double +#else +static double +#endif +ln2_hi = 6.93147180369123816490e-01, /* 3fe62e42 fee00000 */ +ln2_lo = 1.90821492927058770002e-10, /* 3dea39ef 35793c76 */ +two54 = 1.80143985094819840000e+16, /* 43500000 00000000 */ +Lp1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */ +Lp2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */ +Lp3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */ +Lp4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */ +Lp5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */ +Lp6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */ +Lp7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */ + +static double zero = 0.0; + +#ifdef __STDC__ + double log1p(double x) +#else + double log1p(x) + double x; +#endif +{ + double hfsq,f,c,s,z,R,u; + int32_t k,hx,hu,ax; + + GET_HIGH_WORD(hx,x); /* high word of x */ + ax = hx&0x7fffffff; + + k = 1; + if (hx < 0x3FDA827A) { /* x < 0.41422 */ + if(ax>=0x3ff00000) { /* x <= -1.0 */ + if(x==-1.0) return -two54/zero; /* log1p(-1)=+inf */ + else return (x-x)/(x-x); /* log1p(x<-1)=NaN */ + } + if(ax<0x3e200000) { /* |x| < 2**-29 */ + if(two54+x>zero /* raise inexact */ + &&ax<0x3c900000) /* |x| < 2**-54 */ + return x; + else + return x - x*x*0.5; + } + if(hx>0||hx<=((int)0xbfd2bec3)) { + k=0;f=x;hu=1;} /* -0.2929= 0x7ff00000) return x+x; + if(k!=0) { + if(hx<0x43400000) { + u = 1.0+x; + GET_HIGH_WORD(hu,u); /* high word of u */ + k = (hu>>20)-1023; + c = (k>0)? 1.0-(u-x):x-(u-1.0);/* correction term */ + c /= u; + } else { + u = x; + GET_HIGH_WORD(hu,u); /* high word of u */ + k = (hu>>20)-1023; + c = 0; + } + hu &= 0x000fffff; + if(hu<0x6a09e) { + SET_HIGH_WORD(u, hu|0x3ff00000); /* normalize u */ + } else { + k += 1; + SET_HIGH_WORD(u, hu|0x3fe00000); /* normalize u/2 */ + hu = (0x00100000-hu)>>2; + } + f = u-1.0; + } + hfsq=0.5*f*f; + if(hu==0) { /* |f| < 2**-20 */ + if(f==zero) if(k==0) return zero; + else {c += k*ln2_lo; return k*ln2_hi+c;} + R = hfsq*(1.0-0.66666666666666666*f); + if(k==0) return f-R; else + return k*ln2_hi-((R-(k*ln2_lo+c))-f); + } + s = f/(2.0+f); + z = s*s; + R = z*(Lp1+z*(Lp2+z*(Lp3+z*(Lp4+z*(Lp5+z*(Lp6+z*Lp7)))))); + if(k==0) return f-(hfsq-s*(hfsq+R)); else + return k*ln2_hi-((hfsq-(s*(hfsq+R)+(k*ln2_lo+c)))-f); +} +#endif /* _DOUBLE_IS_32BITS */ diff --git a/libjava/classpath/native/fdlibm/s_rint.c b/libjava/classpath/native/fdlibm/s_rint.c new file mode 100644 index 000000000..fcd3916e8 --- /dev/null +++ b/libjava/classpath/native/fdlibm/s_rint.c @@ -0,0 +1,86 @@ + +/* @(#)s_rint.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* + * rint(x) + * Return x rounded to integral value according to the prevailing + * rounding mode. + * Method: + * Using floating addition. + * Exception: + * Inexact flag raised if x not equal to rint(x). + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ +static const double +#else +static double +#endif +TWO52[2]={ + 4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */ + -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */ +}; + +#ifdef __STDC__ + double rint(double x) +#else + double rint(x) + double x; +#endif +{ + int32_t i0,j0,sx; + uint32_t i,i1; + double t; + volatile double w; + EXTRACT_WORDS(i0,i1,x); + sx = (i0>>31)&1; + j0 = ((i0>>20)&0x7ff)-0x3ff; + if(j0<20) { + if(j0<0) { + if(((i0&0x7fffffff)|i1)==0) return x; + i1 |= (i0&0x0fffff); + i0 &= 0xfffe0000; + i0 |= ((i1|-i1)>>12)&0x80000; + SET_HIGH_WORD(x,i0); + w = TWO52[sx]+x; + t = w-TWO52[sx]; + GET_HIGH_WORD(i0,t); + SET_HIGH_WORD(t,(i0&0x7fffffff)|(sx<<31)); + return t; + } else { + i = (0x000fffff)>>j0; + if(((i0&i)|i1)==0) return x; /* x is integral */ + i>>=1; + if(((i0&i)|i1)!=0) { + if(j0==19) i1 = 0x40000000; else + i0 = (i0&(~i))|((0x20000)>>j0); + } + } + } else if (j0>51) { + if(j0==0x400) return x+x; /* inf or NaN */ + else return x; /* x is integral */ + } else { + i = ((uint32_t)(0xffffffff))>>(j0-20); + if((i1&i)==0) return x; /* x is integral */ + i>>=1; + if((i1&i)!=0) i1 = (i1&(~i))|((0x40000000)>>(j0-20)); + } + INSERT_WORDS(x,i0,i1); + w = TWO52[sx]+x; + return w-TWO52[sx]; +} +#endif /* _DOUBLE_IS_32BITS */ diff --git a/libjava/classpath/native/fdlibm/s_scalbn.c b/libjava/classpath/native/fdlibm/s_scalbn.c new file mode 100644 index 000000000..b1464881e --- /dev/null +++ b/libjava/classpath/native/fdlibm/s_scalbn.c @@ -0,0 +1,65 @@ + +/* @(#)s_scalbn.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* + * scalbn (double x, int n) + * scalbn(x,n) returns x* 2**n computed by exponent + * manipulation rather than by actually performing an + * exponentiation or a multiplication. + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ +static const double +#else +static double +#endif +two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */ +twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */ +huge = 1.0e+300, +tiny = 1.0e-300; + +#ifdef __STDC__ + double scalbn (double x, int n) +#else + double scalbn (x,n) + double x; int n; +#endif +{ + int32_t k,hx,lx; + EXTRACT_WORDS(hx,lx,x); + k = (hx&0x7ff00000)>>20; /* extract exponent */ + if (k==0) { /* 0 or subnormal x */ + if ((lx|(hx&0x7fffffff))==0) return x; /* +-0 */ + x *= two54; + GET_HIGH_WORD(hx,x); + k = ((hx&0x7ff00000)>>20) - 54; + if (n< -50000) return tiny*x; /*underflow*/ + } + if (k==0x7ff) return x+x; /* NaN or Inf */ + k = k+n; + if (k > 0x7fe) return huge*copysign(huge,x); /* overflow */ + if (k > 0) /* normal result */ + {SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20)); return x;} + if (k <= -54) + if (n > 50000) /* in case integer overflow in n+k */ + return huge*copysign(huge,x); /*overflow*/ + else return tiny*copysign(tiny,x); /*underflow*/ + k += 54; /* subnormal result */ + SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20)); + return x*twom54; +} +#endif /* _DOUBLE_IS_32BITS */ diff --git a/libjava/classpath/native/fdlibm/s_sin.c b/libjava/classpath/native/fdlibm/s_sin.c new file mode 100644 index 000000000..b5d264863 --- /dev/null +++ b/libjava/classpath/native/fdlibm/s_sin.c @@ -0,0 +1,81 @@ + +/* @(#)s_sin.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* sin(x) + * Return sine function of x. + * + * kernel function: + * __kernel_sin ... sine function on [-pi/4,pi/4] + * __kernel_cos ... cose function on [-pi/4,pi/4] + * __ieee754_rem_pio2 ... argument reduction routine + * + * Method. + * Let S,C and T denote the sin, cos and tan respectively on + * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2 + * in [-pi/4 , +pi/4], and let n = k mod 4. + * We have + * + * n sin(x) cos(x) tan(x) + * ---------------------------------------------------------- + * 0 S C T + * 1 C -S -1/T + * 2 -S -C T + * 3 -C S -1/T + * ---------------------------------------------------------- + * + * Special cases: + * Let trig be any of sin, cos, or tan. + * trig(+-INF) is NaN, with signals; + * trig(NaN) is that NaN; + * + * Accuracy: + * TRIG(x) returns trig(x) nearly rounded + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double sin(double x) +#else + double sin(x) + double x; +#endif +{ + double y[2],z=0.0; + int32_t n, ix; + + /* High word of x. */ + GET_HIGH_WORD(ix,x); + + /* |x| ~< pi/4 */ + ix &= 0x7fffffff; + if(ix <= 0x3fe921fb) return __kernel_sin(x,z,0); + + /* sin(Inf or NaN) is NaN */ + else if (ix>=0x7ff00000) return x-x; + + /* argument reduction needed */ + else { + n = __ieee754_rem_pio2(x,y); + switch(n&3) { + case 0: return __kernel_sin(y[0],y[1],1); + case 1: return __kernel_cos(y[0],y[1]); + case 2: return -__kernel_sin(y[0],y[1],1); + default: + return -__kernel_cos(y[0],y[1]); + } + } +} +#endif /* _DOUBLE_IS_32BITS */ diff --git a/libjava/classpath/native/fdlibm/s_tan.c b/libjava/classpath/native/fdlibm/s_tan.c new file mode 100644 index 000000000..55cdd3362 --- /dev/null +++ b/libjava/classpath/native/fdlibm/s_tan.c @@ -0,0 +1,75 @@ + +/* @(#)s_tan.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* tan(x) + * Return tangent function of x. + * + * kernel function: + * __kernel_tan ... tangent function on [-pi/4,pi/4] + * __ieee754_rem_pio2 ... argument reduction routine + * + * Method. + * Let S,C and T denote the sin, cos and tan respectively on + * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2 + * in [-pi/4 , +pi/4], and let n = k mod 4. + * We have + * + * n sin(x) cos(x) tan(x) + * ---------------------------------------------------------- + * 0 S C T + * 1 C -S -1/T + * 2 -S -C T + * 3 -C S -1/T + * ---------------------------------------------------------- + * + * Special cases: + * Let trig be any of sin, cos, or tan. + * trig(+-INF) is NaN, with signals; + * trig(NaN) is that NaN; + * + * Accuracy: + * TRIG(x) returns trig(x) nearly rounded + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double tan(double x) +#else + double tan(x) + double x; +#endif +{ + double y[2],z=0.0; + int32_t n, ix; + + /* High word of x. */ + GET_HIGH_WORD(ix,x); + + /* |x| ~< pi/4 */ + ix &= 0x7fffffff; + if(ix <= 0x3fe921fb) return __kernel_tan(x,z,1); + + /* tan(Inf or NaN) is NaN */ + else if (ix>=0x7ff00000) return x-x; /* NaN */ + + /* argument reduction needed */ + else { + n = __ieee754_rem_pio2(x,y); + return __kernel_tan(y[0],y[1],1-((n&1)<<1)); /* 1 -- n even + -1 -- n odd */ + } +} +#endif /* _DOUBLE_IS_32BITS */ diff --git a/libjava/classpath/native/fdlibm/s_tanh.c b/libjava/classpath/native/fdlibm/s_tanh.c new file mode 100644 index 000000000..bf4a7156a --- /dev/null +++ b/libjava/classpath/native/fdlibm/s_tanh.c @@ -0,0 +1,85 @@ + +/* @(#)s_tanh.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* Tanh(x) + * Return the Hyperbolic Tangent of x + * + * Method : + * x -x + * e - e + * 0. tanh(x) is defined to be ----------- + * x -x + * e + e + * 1. reduce x to non-negative by tanh(-x) = -tanh(x). + * 2. 0 <= x <= 2**-55 : tanh(x) := x*(one+x) + * -t + * 2**-55 < x <= 1 : tanh(x) := -----; t = expm1(-2x) + * t + 2 + * 2 + * 1 <= x <= 22.0 : tanh(x) := 1- ----- ; t=expm1(2x) + * t + 2 + * 22.0 < x <= INF : tanh(x) := 1. + * + * Special cases: + * tanh(NaN) is NaN; + * only tanh(0)=0 is exact for finite argument. + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ +static const double one=1.0, two=2.0, tiny = 1.0e-300; +#else +static double one=1.0, two=2.0, tiny = 1.0e-300; +#endif + +#ifdef __STDC__ + double tanh(double x) +#else + double tanh(x) + double x; +#endif +{ + double t,z; + int32_t jx,ix; + + /* High word of |x|. */ + GET_HIGH_WORD(jx,x); + ix = jx&0x7fffffff; + + /* x is INF or NaN */ + if(ix>=0x7ff00000) { + if (jx>=0) return one/x+one; /* tanh(+-inf)=+-1 */ + else return one/x-one; /* tanh(NaN) = NaN */ + } + + /* |x| < 22 */ + if (ix < 0x40360000) { /* |x|<22 */ + if (ix<0x3c800000) /* |x|<2**-55 */ + return x*(one+x); /* tanh(small) = small */ + if (ix>=0x3ff00000) { /* |x|>=1 */ + t = expm1(two*fabs(x)); + z = one - two/(t+two); + } else { + t = expm1(-two*fabs(x)); + z= -t/(t+two); + } + /* |x| > 22, return +-1 */ + } else { + z = one - tiny; /* raised inexact flag */ + } + return (jx>=0)? z: -z; +} +#endif /* _DOUBLE_IS_32BITS */ diff --git a/libjava/classpath/native/fdlibm/sf_fabs.c b/libjava/classpath/native/fdlibm/sf_fabs.c new file mode 100644 index 000000000..34f88afc4 --- /dev/null +++ b/libjava/classpath/native/fdlibm/sf_fabs.c @@ -0,0 +1,47 @@ +/* sf_fabs.c -- float version of s_fabs.c. + * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. + */ + +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* + * fabsf(x) returns the absolute value of x. + */ + +#include "fdlibm.h" + +#ifdef __STDC__ + float fabsf(float x) +#else + float fabsf(x) + float x; +#endif +{ + uint32_t ix; + GET_FLOAT_WORD(ix,x); + SET_FLOAT_WORD(x,ix&0x7fffffff); + return x; +} + +#ifdef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double fabs(double x) +#else + double fabs(x) + double x; +#endif +{ + return (double) fabsf((float) x); +} + +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/classpath/native/fdlibm/sf_rint.c b/libjava/classpath/native/fdlibm/sf_rint.c new file mode 100644 index 000000000..f44207287 --- /dev/null +++ b/libjava/classpath/native/fdlibm/sf_rint.c @@ -0,0 +1,80 @@ +/* sf_rint.c -- float version of s_rint.c. + * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. + */ + +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#include "fdlibm.h" + +#ifdef __STDC__ +static const float +#else +static float +#endif +TWO23[2]={ + 8.3886080000e+06, /* 0x4b000000 */ + -8.3886080000e+06, /* 0xcb000000 */ +}; + +#ifdef __STDC__ + float rintf(float x) +#else + float rintf(x) + float x; +#endif +{ + int32_t i0,j0,sx; + uint32_t i,i1; + float w,t; + GET_FLOAT_WORD(i0,x); + sx = (i0>>31)&1; + j0 = ((i0>>23)&0xff)-0x7f; + if(j0<23) { + if(j0<0) { + if((i0&0x7fffffff)==0) return x; + i1 = (i0&0x07fffff); + i0 &= 0xfff00000; + i0 |= ((i1|-i1)>>9)&0x400000; + SET_FLOAT_WORD(x,i0); + w = TWO23[sx]+x; + t = w-TWO23[sx]; + GET_FLOAT_WORD(i0,t); + SET_FLOAT_WORD(t,(i0&0x7fffffff)|(sx<<31)); + return t; + } else { + i = (0x007fffff)>>j0; + if((i0&i)==0) return x; /* x is integral */ + i>>=1; + if((i0&i)!=0) i0 = (i0&(~i))|((0x100000)>>j0); + } + } else { + if(j0==0x80) return x+x; /* inf or NaN */ + else return x; /* x is integral */ + } + SET_FLOAT_WORD(x,i0); + w = TWO23[sx]+x; + return w-TWO23[sx]; +} + +#ifdef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double rint(double x) +#else + double rint(x) + double x; +#endif +{ + return (double) rintf((float) x); +} + +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/classpath/native/fdlibm/strtod.c b/libjava/classpath/native/fdlibm/strtod.c new file mode 100644 index 000000000..b3e091247 --- /dev/null +++ b/libjava/classpath/native/fdlibm/strtod.c @@ -0,0 +1,719 @@ +/* +FUNCTION + <>, <>---string to double or float + +INDEX + strtod +INDEX + _strtod_r +INDEX + strtodf + +ANSI_SYNOPSIS + #include + double strtod(const char *<[str]>, char **<[tail]>); + float strtodf(const char *<[str]>, char **<[tail]>); + + double _strtod_r(void *<[reent]>, + const char *<[str]>, char **<[tail]>); + +TRAD_SYNOPSIS + #include + double strtod(<[str]>,<[tail]>) + char *<[str]>; + char **<[tail]>; + + float strtodf(<[str]>,<[tail]>) + char *<[str]>; + char **<[tail]>; + + double _strtod_r(<[reent]>,<[str]>,<[tail]>) + char *<[reent]>; + char *<[str]>; + char **<[tail]>; + +DESCRIPTION + The function <> parses the character string <[str]>, + producing a substring which can be converted to a double + value. The substring converted is the longest initial + subsequence of <[str]>, beginning with the first + non-whitespace character, that has the format: + .[+|-]<[digits]>[.][<[digits]>][(e|E)[+|-]<[digits]>] + The substring contains no characters if <[str]> is empty, consists + entirely of whitespace, or if the first non-whitespace + character is something other than <<+>>, <<->>, <<.>>, or a + digit. If the substring is empty, no conversion is done, and + the value of <[str]> is stored in <<*<[tail]>>>. Otherwise, + the substring is converted, and a pointer to the final string + (which will contain at least the terminating null character of + <[str]>) is stored in <<*<[tail]>>>. If you want no + assignment to <<*<[tail]>>>, pass a null pointer as <[tail]>. + <> is identical to <> except for its return type. + + This implementation returns the nearest machine number to the + input decimal string. Ties are broken by using the IEEE + round-even rule. + + The alternate function <<_strtod_r>> is a reentrant version. + The extra argument <[reent]> is a pointer to a reentrancy structure. + +RETURNS + <> returns the converted substring value, if any. If + no conversion could be performed, 0 is returned. If the + correct value is out of the range of representable values, + plus or minus <> is returned, and <> is + stored in errno. If the correct value would cause underflow, 0 + is returned and <> is stored in errno. + +Supporting OS subroutines required: <>, <>, <>, +<>, <>, <>, <>. +*/ + +/**************************************************************** + * + * The author of this software is David M. Gay. + * + * Copyright (c) 1991 by AT&T. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose without fee is hereby granted, provided that this entire notice + * is included in all copies of any software which is or includes a copy + * or modification of this software and in all copies of the supporting + * documentation for such software. + * + * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY + * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY + * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. + * + ***************************************************************/ + +/* Please send bug reports to + David M. Gay + AT&T Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-2070 + U.S.A. + dmg@research.att.com or research!dmg + */ + +#include +#include +#include +#include "mprec.h" + +double +_DEFUN (_strtod_r, (ptr, s00, se), + struct _Jv_reent *ptr _AND + _CONST char *s00 _AND + char **se) +{ + int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, dsign, e1, esign, i, j, + k, nd, nd0, nf, nz, nz0, sign; + int digits = 0; /* Number of digits found in fraction part. */ + long e; + _CONST char *s, *s0, *s1; + double aadj, aadj1, adj; + long L; + unsigned long y, z; + union double_union rv, rv0; + + _Jv_Bigint *bb = NULL, *bb1, *bd = NULL, *bd0, *bs = NULL, *delta = NULL; + sign = nz0 = nz = 0; + rv.d = 0.; + for (s = s00;; s++) + switch (*s) + { + case '-': + sign = 1; + /* no break */ + case '+': + if (*++s) + goto break2; + /* no break */ + case 0: + s = s00; + goto ret; + case '\t': + case '\n': + case '\v': + case '\f': + case '\r': + case ' ': + continue; + default: + goto break2; + } +break2: + if (*s == '0') + { + digits++; + nz0 = 1; + while (*++s == '0') + digits++; + if (!*s) + goto ret; + } + s0 = s; + y = z = 0; + for (nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++) + { + digits++; + if (nd < 9) + y = 10 * y + c - '0'; + else if (nd < 16) + z = 10 * z + c - '0'; + } + nd0 = nd; + if (c == '.') + { + c = *++s; + if (!nd) + { + for (; c == '0'; c = *++s) + { + digits++; + nz++; + } + if (c > '0' && c <= '9') + { + digits++; + s0 = s; + nf += nz; + nz = 0; + goto have_dig; + } + goto dig_done; + } + for (; c >= '0' && c <= '9'; c = *++s) + { + digits++; + have_dig: + nz++; + if (c -= '0') + { + nf += nz; + for (i = 1; i < nz; i++) + if (nd++ < 9) + y *= 10; + else if (nd <= DBL_DIG + 1) + z *= 10; + if (nd++ < 9) + y = 10 * y + c; + else if (nd <= DBL_DIG + 1) + z = 10 * z + c; + nz = 0; + } + } + } +dig_done: + e = 0; + if (c == 'e' || c == 'E') + { + if (!nd && !nz && !nz0) + { + s = s00; + goto ret; + } + s00 = s; + esign = 0; + switch (c = *++s) + { + case '-': + esign = 1; + case '+': + c = *++s; + } + if (c >= '0' && c <= '9') + { + while (c == '0') + c = *++s; + if (c > '0' && c <= '9') + { + e = c - '0'; + s1 = s; + while ((c = *++s) >= '0' && c <= '9') + e = 10 * e + c - '0'; + if (s - s1 > 8) + /* Avoid confusion from exponents + * so large that e might overflow. + */ + e = 9999999L; + if (esign) + e = -e; + } + } + else + { + /* No exponent after an 'E' : that's an error. */ + ptr->_errno = EINVAL; + e = 0; + s = s00; + goto ret; + } + } + if (!nd) + { + if (!nz && !nz0) + s = s00; + goto ret; + } + e1 = e -= nf; + + /* Now we have nd0 digits, starting at s0, followed by a + * decimal point, followed by nd-nd0 digits. The number we're + * after is the integer represented by those digits times + * 10**e */ + + if (!nd0) + nd0 = nd; + k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1; + rv.d = y; + if (k > 9) + rv.d = tens[k - 9] * rv.d + z; + bd0 = 0; + if (nd <= DBL_DIG +#ifndef RND_PRODQUOT + && FLT_ROUNDS == 1 +#endif + ) + { + if (!e) + goto ret; + if (e > 0) + { + if (e <= Ten_pmax) + { +#ifdef VAX + goto vax_ovfl_check; +#else + /* rv.d = */ rounded_product (rv.d, tens[e]); + goto ret; +#endif + } + i = DBL_DIG - nd; + if (e <= Ten_pmax + i) + { + /* A fancier test would sometimes let us do + * this for larger i values. + */ + e -= i; + rv.d *= tens[i]; +#ifdef VAX + /* VAX exponent range is so narrow we must + * worry about overflow here... + */ + vax_ovfl_check: + word0 (rv) -= P * Exp_msk1; + /* rv.d = */ rounded_product (rv.d, tens[e]); + if ((word0 (rv) & Exp_mask) + > Exp_msk1 * (DBL_MAX_EXP + Bias - 1 - P)) + goto ovfl; + word0 (rv) += P * Exp_msk1; +#else + /* rv.d = */ rounded_product (rv.d, tens[e]); +#endif + goto ret; + } + } +#ifndef Inaccurate_Divide + else if (e >= -Ten_pmax) + { + /* rv.d = */ rounded_quotient (rv.d, tens[-e]); + goto ret; + } +#endif + } + e1 += nd - k; + + /* Get starting approximation = rv.d * 10**e1 */ + + if (e1 > 0) + { + if ((i = e1 & 15)) + rv.d *= tens[i]; + + if (e1 &= ~15) + { + if (e1 > DBL_MAX_10_EXP) + { + ovfl: + ptr->_errno = ERANGE; + + /* Force result to IEEE infinity. */ + word0 (rv) = Exp_mask; + word1 (rv) = 0; + + if (bd0) + goto retfree; + goto ret; + } + if (e1 >>= 4) + { + for (j = 0; e1 > 1; j++, e1 >>= 1) + if (e1 & 1) + rv.d *= bigtens[j]; + /* The last multiplication could overflow. */ + word0 (rv) -= P * Exp_msk1; + rv.d *= bigtens[j]; + if ((z = word0 (rv) & Exp_mask) + > Exp_msk1 * (DBL_MAX_EXP + Bias - P)) + goto ovfl; + if (z > Exp_msk1 * (DBL_MAX_EXP + Bias - 1 - P)) + { + /* set to largest number */ + /* (Can't trust DBL_MAX) */ + word0 (rv) = Big0; +#ifndef _DOUBLE_IS_32BITS + word1 (rv) = Big1; +#endif + } + else + word0 (rv) += P * Exp_msk1; + } + + } + } + else if (e1 < 0) + { + e1 = -e1; + if ((i = e1 & 15)) + rv.d /= tens[i]; + if (e1 &= ~15) + { + e1 >>= 4; + if (e1 >= 1 << n_bigtens) + goto undfl; + for (j = 0; e1 > 1; j++, e1 >>= 1) + if (e1 & 1) + rv.d *= tinytens[j]; + /* The last multiplication could underflow. */ + rv0.d = rv.d; + rv.d *= tinytens[j]; + if (!rv.d) + { + rv.d = 2. * rv0.d; + rv.d *= tinytens[j]; + if (!rv.d) + { + undfl: + rv.d = 0.; + ptr->_errno = ERANGE; + if (bd0) + goto retfree; + goto ret; + } +#ifndef _DOUBLE_IS_32BITS + word0 (rv) = Tiny0; + word1 (rv) = Tiny1; +#else + word0 (rv) = Tiny1; +#endif + /* The refinement below will clean + * this approximation up. + */ + } + } + } + + /* Now the hard part -- adjusting rv to the correct value.*/ + + /* Put digits into bd: true value = bd * 10^e */ + + bd0 = s2b (ptr, s0, nd0, nd, y); + + for (;;) + { + bd = Balloc (ptr, bd0->_k); + Bcopy (bd, bd0); + bb = d2b (ptr, rv.d, &bbe, &bbbits); /* rv.d = bb * 2^bbe */ + bs = i2b (ptr, 1); + + if (e >= 0) + { + bb2 = bb5 = 0; + bd2 = bd5 = e; + } + else + { + bb2 = bb5 = -e; + bd2 = bd5 = 0; + } + if (bbe >= 0) + bb2 += bbe; + else + bd2 -= bbe; + bs2 = bb2; +#ifdef Sudden_Underflow +#ifdef IBM + j = 1 + 4 * P - 3 - bbbits + ((bbe + bbbits - 1) & 3); +#else + j = P + 1 - bbbits; +#endif +#else + i = bbe + bbbits - 1; /* logb(rv.d) */ + if (i < Emin) /* denormal */ + j = bbe + (P - Emin); + else + j = P + 1 - bbbits; +#endif + bb2 += j; + bd2 += j; + i = bb2 < bd2 ? bb2 : bd2; + if (i > bs2) + i = bs2; + if (i > 0) + { + bb2 -= i; + bd2 -= i; + bs2 -= i; + } + if (bb5 > 0) + { + bs = pow5mult (ptr, bs, bb5); + bb1 = mult (ptr, bs, bb); + Bfree (ptr, bb); + bb = bb1; + } + if (bb2 > 0) + bb = lshift (ptr, bb, bb2); + if (bd5 > 0) + bd = pow5mult (ptr, bd, bd5); + if (bd2 > 0) + bd = lshift (ptr, bd, bd2); + if (bs2 > 0) + bs = lshift (ptr, bs, bs2); + delta = diff (ptr, bb, bd); + dsign = delta->_sign; + delta->_sign = 0; + i = cmp (delta, bs); + if (i < 0) + { + /* Error is less than half an ulp -- check for + * special case of mantissa a power of two. + */ + if (dsign || word1 (rv) || word0 (rv) & Bndry_mask) + break; + delta = lshift (ptr, delta, Log2P); + if (cmp (delta, bs) > 0) + goto drop_down; + break; + } + if (i == 0) + { + /* exactly half-way between */ + if (dsign) + { + if ((word0 (rv) & Bndry_mask1) == Bndry_mask1 + && word1 (rv) == 0xffffffff) + { + /*boundary case -- increment exponent*/ + word0 (rv) = (word0 (rv) & Exp_mask) + + Exp_msk1 +#ifdef IBM + | Exp_msk1 >> 4 +#endif + ; +#ifndef _DOUBLE_IS_32BITS + word1 (rv) = 0; +#endif + break; + } + } + else if (!(word0 (rv) & Bndry_mask) && !word1 (rv)) + { + drop_down: + /* boundary case -- decrement exponent */ +#ifdef Sudden_Underflow + L = word0 (rv) & Exp_mask; +#ifdef IBM + if (L < Exp_msk1) +#else + if (L <= Exp_msk1) +#endif + goto undfl; + L -= Exp_msk1; +#else + L = (word0 (rv) & Exp_mask) - Exp_msk1; +#endif + word0 (rv) = L | Bndry_mask1; +#ifndef _DOUBLE_IS_32BITS + word1 (rv) = 0xffffffff; +#endif +#ifdef IBM + goto cont; +#else + break; +#endif + } +#ifndef ROUND_BIASED + if (!(word1 (rv) & LSB)) + break; +#endif + if (dsign) + rv.d += ulp (rv.d); +#ifndef ROUND_BIASED + else + { + rv.d -= ulp (rv.d); +#ifndef Sudden_Underflow + if (!rv.d) + goto undfl; +#endif + } +#endif + break; + } + if ((aadj = ratio (delta, bs)) <= 2.) + { + if (dsign) + aadj = aadj1 = 1.; + else if (word1 (rv) || word0 (rv) & Bndry_mask) + { +#ifndef Sudden_Underflow + if (word1 (rv) == Tiny1 && !word0 (rv)) + goto undfl; +#endif + aadj = 1.; + aadj1 = -1.; + } + else + { + /* special case -- power of FLT_RADIX to be */ + /* rounded down... */ + + if (aadj < 2. / FLT_RADIX) + aadj = 1. / FLT_RADIX; + else + aadj *= 0.5; + aadj1 = -aadj; + } + } + else + { + aadj *= 0.5; + aadj1 = dsign ? aadj : -aadj; +#ifdef Check_FLT_ROUNDS + switch (FLT_ROUNDS) + { + case 2: /* towards +infinity */ + aadj1 -= 0.5; + break; + case 0: /* towards 0 */ + case 3: /* towards -infinity */ + aadj1 += 0.5; + } +#else + if (FLT_ROUNDS == 0) + aadj1 += 0.5; +#endif + } + y = word0 (rv) & Exp_mask; + + /* Check for overflow */ + + if (y == Exp_msk1 * (DBL_MAX_EXP + Bias - 1)) + { + rv0.d = rv.d; + word0 (rv) -= P * Exp_msk1; + adj = aadj1 * ulp (rv.d); + rv.d += adj; + if ((word0 (rv) & Exp_mask) >= + Exp_msk1 * (DBL_MAX_EXP + Bias - P)) + { + if (word0 (rv0) == Big0 && word1 (rv0) == Big1) + goto ovfl; +#ifdef _DOUBLE_IS_32BITS + word0 (rv) = Big1; +#else + word0 (rv) = Big0; + word1 (rv) = Big1; +#endif + goto cont; + } + else + word0 (rv) += P * Exp_msk1; + } + else + { +#ifdef Sudden_Underflow + if ((word0 (rv) & Exp_mask) <= P * Exp_msk1) + { + rv0.d = rv.d; + word0 (rv) += P * Exp_msk1; + adj = aadj1 * ulp (rv.d); + rv.d += adj; +#ifdef IBM + if ((word0 (rv) & Exp_mask) < P * Exp_msk1) +#else + if ((word0 (rv) & Exp_mask) <= P * Exp_msk1) +#endif + { + if (word0 (rv0) == Tiny0 + && word1 (rv0) == Tiny1) + goto undfl; + word0 (rv) = Tiny0; + word1 (rv) = Tiny1; + goto cont; + } + else + word0 (rv) -= P * Exp_msk1; + } + else + { + adj = aadj1 * ulp (rv.d); + rv.d += adj; + } +#else + /* Compute adj so that the IEEE rounding rules will + * correctly round rv.d + adj in some half-way cases. + * If rv.d * ulp(rv.d) is denormalized (i.e., + * y <= (P-1)*Exp_msk1), we must adjust aadj to avoid + * trouble from bits lost to denormalization; + * example: 1.2e-307 . + */ + if (y <= (P - 1) * Exp_msk1 && aadj >= 1.) + { + aadj1 = (double) (int) (aadj + 0.5); + if (!dsign) + aadj1 = -aadj1; + } + adj = aadj1 * ulp (rv.d); + rv.d += adj; +#endif + } + z = word0 (rv) & Exp_mask; + if (y == z) + { + /* Can we stop now? */ + L = aadj; + aadj -= L; + /* The tolerances below are conservative. */ + if (dsign || word1 (rv) || word0 (rv) & Bndry_mask) + { + if (aadj < .4999999 || aadj > .5000001) + break; + } + else if (aadj < .4999999 / FLT_RADIX) + break; + } + cont: + Bfree (ptr, bb); + Bfree (ptr, bd); + Bfree (ptr, bs); + Bfree (ptr, delta); + } +retfree: + Bfree (ptr, bb); + Bfree (ptr, bd); + Bfree (ptr, bs); + Bfree (ptr, bd0); + Bfree (ptr, delta); +ret: + if (se) + *se = (char *) s; + if (digits == 0) + ptr->_errno = EINVAL; + return sign ? -rv.d : rv.d; +} + diff --git a/libjava/classpath/native/fdlibm/w_acos.c b/libjava/classpath/native/fdlibm/w_acos.c new file mode 100644 index 000000000..e463eaf9c --- /dev/null +++ b/libjava/classpath/native/fdlibm/w_acos.c @@ -0,0 +1,39 @@ + +/* @(#)w_acos.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* + * wrap_acos(x) + */ + +#include "fdlibm.h" + + +#ifdef __STDC__ + double acos(double x) /* wrapper acos */ +#else + double acos(x) /* wrapper acos */ + double x; +#endif +{ +#ifdef _IEEE_LIBM + return __ieee754_acos(x); +#else + double z; + z = __ieee754_acos(x); + if(_LIB_VERSION == _IEEE_ || isnan(x)) return z; + if(fabs(x)>1.0) { + return __kernel_standard(x,x,1); /* acos(|x|>1) */ + } else + return z; +#endif +} diff --git a/libjava/classpath/native/fdlibm/w_asin.c b/libjava/classpath/native/fdlibm/w_asin.c new file mode 100644 index 000000000..e8182857c --- /dev/null +++ b/libjava/classpath/native/fdlibm/w_asin.c @@ -0,0 +1,41 @@ + +/* @(#)w_asin.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + * + */ + +/* + * wrapper asin(x) + */ + + +#include "fdlibm.h" + + +#ifdef __STDC__ + double asin(double x) /* wrapper asin */ +#else + double asin(x) /* wrapper asin */ + double x; +#endif +{ +#ifdef _IEEE_LIBM + return __ieee754_asin(x); +#else + double z; + z = __ieee754_asin(x); + if(_LIB_VERSION == _IEEE_ || isnan(x)) return z; + if(fabs(x)>1.0) { + return __kernel_standard(x,x,2); /* asin(|x|>1) */ + } else + return z; +#endif +} diff --git a/libjava/classpath/native/fdlibm/w_atan2.c b/libjava/classpath/native/fdlibm/w_atan2.c new file mode 100644 index 000000000..80ad39b35 --- /dev/null +++ b/libjava/classpath/native/fdlibm/w_atan2.c @@ -0,0 +1,40 @@ + +/* @(#)w_atan2.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + * + */ + +/* + * wrapper atan2(y,x) + */ + +#include "fdlibm.h" + + +#ifdef __STDC__ + double atan2(double y, double x) /* wrapper atan2 */ +#else + double atan2(y,x) /* wrapper atan2 */ + double y,x; +#endif +{ +#ifdef _IEEE_LIBM + return __ieee754_atan2(y,x); +#else + double z; + z = __ieee754_atan2(y,x); + if(_LIB_VERSION == _IEEE_||isnan(x)||isnan(y)) return z; + if(x==0.0&&y==0.0) { + return __kernel_standard(y,x,3); /* atan2(+-0,+-0) */ + } else + return z; +#endif +} diff --git a/libjava/classpath/native/fdlibm/w_cosh.c b/libjava/classpath/native/fdlibm/w_cosh.c new file mode 100644 index 000000000..1848726c9 --- /dev/null +++ b/libjava/classpath/native/fdlibm/w_cosh.c @@ -0,0 +1,38 @@ + +/* @(#)w_cosh.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* + * wrapper cosh(x) + */ + +#include "fdlibm.h" + +#ifdef __STDC__ + double cosh(double x) /* wrapper cosh */ +#else + double cosh(x) /* wrapper cosh */ + double x; +#endif +{ +#ifdef _IEEE_LIBM + return __ieee754_cosh(x); +#else + double z; + z = __ieee754_cosh(x); + if(_LIB_VERSION == _IEEE_ || isnan(x)) return z; + if(fabs(x)>7.10475860073943863426e+02) { + return __kernel_standard(x,x,5); /* cosh overflow */ + } else + return z; +#endif +} diff --git a/libjava/classpath/native/fdlibm/w_exp.c b/libjava/classpath/native/fdlibm/w_exp.c new file mode 100644 index 000000000..7819ca133 --- /dev/null +++ b/libjava/classpath/native/fdlibm/w_exp.c @@ -0,0 +1,48 @@ + +/* @(#)w_exp.c 1.4 04/04/22 */ +/* + * ==================================================== + * Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved. + * + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* + * wrapper exp(x) + */ + +#include "fdlibm.h" + +#ifdef __STDC__ +static const double +#else +static double +#endif +o_threshold= 7.09782712893383973096e+02, /* 0x40862E42, 0xFEFA39EF */ +u_threshold= -7.45133219101941108420e+02; /* 0xc0874910, 0xD52D3051 */ + +#ifdef __STDC__ + double exp(double x) /* wrapper exp */ +#else + double exp(x) /* wrapper exp */ + double x; +#endif +{ +#ifdef _IEEE_LIBM + return __ieee754_exp(x); +#else + double z; + z = __ieee754_exp(x); + if(_LIB_VERSION == _IEEE_) return z; + if(finite(x)) { + if(x>o_threshold) + return __kernel_standard(x,x,6); /* exp overflow */ + else if(x 0.0) return z; + if(x==0.0) + return __kernel_standard(x,x,16); /* log(0) */ + else + return __kernel_standard(x,x,17); /* log(x<0) */ +#endif +} diff --git a/libjava/classpath/native/fdlibm/w_log10.c b/libjava/classpath/native/fdlibm/w_log10.c new file mode 100644 index 000000000..2bdebc79a --- /dev/null +++ b/libjava/classpath/native/fdlibm/w_log10.c @@ -0,0 +1,42 @@ + +/* @(#)w_log10.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* + * wrapper log10(X) + */ + +#include "fdlibm.h" + + +#ifdef __STDC__ + double log10(double x) /* wrapper log10 */ +#else + double log10(x) /* wrapper log10 */ + double x; +#endif +{ +#ifdef _IEEE_LIBM + return __ieee754_log10(x); +#else + double z; + z = __ieee754_log10(x); + if(_LIB_VERSION == _IEEE_ || isnan(x)) return z; + if(x<=0.0) { + if(x==0.0) + return __kernel_standard(x,x,18); /* log10(0) */ + else + return __kernel_standard(x,x,19); /* log10(x<0) */ + } else + return z; +#endif +} diff --git a/libjava/classpath/native/fdlibm/w_pow.c b/libjava/classpath/native/fdlibm/w_pow.c new file mode 100644 index 000000000..850c1162b --- /dev/null +++ b/libjava/classpath/native/fdlibm/w_pow.c @@ -0,0 +1,60 @@ + + +/* @(#)w_pow.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* + * wrapper pow(x,y) return x**y + */ + +#include "fdlibm.h" + + +#ifdef __STDC__ + double pow(double x, double y) /* wrapper pow */ +#else + double pow(x,y) /* wrapper pow */ + double x,y; +#endif +{ +#ifdef _IEEE_LIBM + return __ieee754_pow(x,y); +#else + double z; + z=__ieee754_pow(x,y); + if(_LIB_VERSION == _IEEE_|| isnan(y)) return z; + if(isnan(x)) { + if(y==0.0) + return __kernel_standard(x,y,42); /* pow(NaN,0.0) */ + else + return z; + } + if(x==0.0){ + if(y==0.0) + return __kernel_standard(x,y,20); /* pow(0.0,0.0) */ + if(finite(y)&&y<0.0) + return __kernel_standard(x,y,23); /* pow(0.0,negative) */ + return z; + } + if(!finite(z)) { + if(finite(x)&&finite(y)) { + if(isnan(z)) + return __kernel_standard(x,y,24); /* pow neg**non-int */ + else + return __kernel_standard(x,y,21); /* pow overflow */ + } + } + if(z==0.0&&finite(x)&&finite(y)) + return __kernel_standard(x,y,22); /* pow underflow */ + return z; +#endif +} diff --git a/libjava/classpath/native/fdlibm/w_remainder.c b/libjava/classpath/native/fdlibm/w_remainder.c new file mode 100644 index 000000000..8e65c207e --- /dev/null +++ b/libjava/classpath/native/fdlibm/w_remainder.c @@ -0,0 +1,38 @@ + +/* @(#)w_remainder.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* + * wrapper remainder(x,p) + */ + +#include "fdlibm.h" + +#ifdef __STDC__ + double remainder(double x, double y) /* wrapper remainder */ +#else + double remainder(x,y) /* wrapper remainder */ + double x,y; +#endif +{ +#ifdef _IEEE_LIBM + return __ieee754_remainder(x,y); +#else + double z; + z = __ieee754_remainder(x,y); + if(_LIB_VERSION == _IEEE_ || isnan(y)) return z; + if(y==0.0) + return __kernel_standard(x,y,28); /* remainder(x,0) */ + else + return z; +#endif +} diff --git a/libjava/classpath/native/fdlibm/w_sinh.c b/libjava/classpath/native/fdlibm/w_sinh.c new file mode 100644 index 000000000..f328ddec9 --- /dev/null +++ b/libjava/classpath/native/fdlibm/w_sinh.c @@ -0,0 +1,38 @@ + +/* @(#)w_sinh.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* + * wrapper sinh(x) + */ + +#include "fdlibm.h" + +#ifdef __STDC__ + double sinh(double x) /* wrapper sinh */ +#else + double sinh(x) /* wrapper sinh */ + double x; +#endif +{ +#ifdef _IEEE_LIBM + return __ieee754_sinh(x); +#else + double z; + z = __ieee754_sinh(x); + if(_LIB_VERSION == _IEEE_) return z; + if(!finite(z)&&finite(x)) { + return __kernel_standard(x,x,25); /* sinh overflow */ + } else + return z; +#endif +} diff --git a/libjava/classpath/native/fdlibm/w_sqrt.c b/libjava/classpath/native/fdlibm/w_sqrt.c new file mode 100644 index 000000000..4dd589e25 --- /dev/null +++ b/libjava/classpath/native/fdlibm/w_sqrt.c @@ -0,0 +1,38 @@ + +/* @(#)w_sqrt.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* + * wrapper sqrt(x) + */ + +#include "fdlibm.h" + +#ifdef __STDC__ + double sqrt(double x) /* wrapper sqrt */ +#else + double sqrt(x) /* wrapper sqrt */ + double x; +#endif +{ +#ifdef _IEEE_LIBM + return __ieee754_sqrt(x); +#else + double z; + z = __ieee754_sqrt(x); + if(_LIB_VERSION == _IEEE_ || isnan(x)) return z; + if(x<0.0) { + return __kernel_standard(x,x,26); /* sqrt(negative) */ + } else + return z; +#endif +} diff --git a/libjava/classpath/native/jawt/.cvsignore b/libjava/classpath/native/jawt/.cvsignore new file mode 100644 index 000000000..e9f2658a6 --- /dev/null +++ b/libjava/classpath/native/jawt/.cvsignore @@ -0,0 +1,8 @@ +*.o +*.a +*.lo +*.la +.libs +.deps +Makefile +Makefile.in diff --git a/libjava/classpath/native/jawt/Makefile.am b/libjava/classpath/native/jawt/Makefile.am new file mode 100644 index 000000000..5d7ae796c --- /dev/null +++ b/libjava/classpath/native/jawt/Makefile.am @@ -0,0 +1,13 @@ +nativeexeclib_LTLIBRARIES = libjawt.la + +libjawt_la_SOURCES = jawt.c +libjawt_la_LIBADD = $(top_builddir)/native/jni/gtk-peer/libgtkpeer.la +libjawt_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version + +AM_LDFLAGS = @CLASSPATH_MODULE@ @GTK_LIBS@ @PANGOFT2_LIBS@ @X_LIBS@ @XTEST_LIBS@ +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ + +# Just the WARNING_CFLAGS. We cannot use the strict flags since the gtk +# headers contain broken prototypes (by design, see gtkitemfactory.h). +AM_CFLAGS = @WARNING_CFLAGS@ @ERROR_CFLAGS@ \ + @GTK_CFLAGS@ @PANGOFT2_CFLAGS@ @EXTRA_CFLAGS@ diff --git a/libjava/classpath/native/jawt/Makefile.in b/libjava/classpath/native/jawt/Makefile.in new file mode 100644 index 000000000..6ca16394c --- /dev/null +++ b/libjava/classpath/native/jawt/Makefile.in @@ -0,0 +1,615 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +subdir = native/jawt +DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/../../config/depstand.m4 \ + $(top_srcdir)/../../config/lead-dot.m4 \ + $(top_srcdir)/../../config/lib-ld.m4 \ + $(top_srcdir)/../../config/lib-link.m4 \ + $(top_srcdir)/../../config/lib-prefix.m4 \ + $(top_srcdir)/../../config/multi.m4 \ + $(top_srcdir)/../../config/no-executables.m4 \ + $(top_srcdir)/../../config/override.m4 \ + $(top_srcdir)/../../libtool.m4 \ + $(top_srcdir)/../../ltoptions.m4 \ + $(top_srcdir)/../../ltsugar.m4 \ + $(top_srcdir)/../../ltversion.m4 \ + $(top_srcdir)/../../lt~obsolete.m4 \ + $(top_srcdir)/m4/ac_prog_antlr.m4 \ + $(top_srcdir)/m4/ac_prog_java.m4 \ + $(top_srcdir)/m4/ac_prog_java_works.m4 \ + $(top_srcdir)/m4/ac_prog_javac.m4 \ + $(top_srcdir)/m4/ac_prog_javac_works.m4 \ + $(top_srcdir)/m4/acattribute.m4 $(top_srcdir)/m4/accross.m4 \ + $(top_srcdir)/m4/acinclude.m4 \ + $(top_srcdir)/m4/ax_create_stdint_h.m4 \ + $(top_srcdir)/m4/ax_func_which_gethostbyname_r.m4 \ + $(top_srcdir)/m4/gcc_attribute.m4 $(top_srcdir)/m4/iconv.m4 \ + $(top_srcdir)/m4/pkg.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/../../mkinstalldirs +CONFIG_HEADER = $(top_builddir)/include/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__installdirs = "$(DESTDIR)$(nativeexeclibdir)" +LTLIBRARIES = $(nativeexeclib_LTLIBRARIES) +libjawt_la_DEPENDENCIES = \ + $(top_builddir)/native/jni/gtk-peer/libgtkpeer.la +am_libjawt_la_OBJECTS = jawt.lo +libjawt_la_OBJECTS = $(am_libjawt_la_OBJECTS) +libjawt_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(libjawt_la_LDFLAGS) $(LDFLAGS) -o $@ +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/include +depcomp = $(SHELL) $(top_srcdir)/../../depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(libjawt_la_SOURCES) +ETAGS = etags +CTAGS = ctags +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +ANTLR = @ANTLR@ +ANTLR_JAR = @ANTLR_JAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CAIRO_CFLAGS = @CAIRO_CFLAGS@ +CAIRO_LIBS = @CAIRO_LIBS@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CLASSPATH_CONVENIENCE = @CLASSPATH_CONVENIENCE@ +CLASSPATH_INCLUDES = @CLASSPATH_INCLUDES@ +CLASSPATH_MODULE = @CLASSPATH_MODULE@ +COLLECTIONS_PREFIX = @COLLECTIONS_PREFIX@ +CP = @CP@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DATE = @DATE@ +DEFAULT_PREFS_PEER = @DEFAULT_PREFS_PEER@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +ECJ_JAR = @ECJ_JAR@ +EGREP = @EGREP@ +ERROR_CFLAGS = @ERROR_CFLAGS@ +EXAMPLESDIR = @EXAMPLESDIR@ +EXEEXT = @EXEEXT@ +EXTRA_CFLAGS = @EXTRA_CFLAGS@ +FGREP = @FGREP@ +FIND = @FIND@ +FREETYPE2_CFLAGS = @FREETYPE2_CFLAGS@ +FREETYPE2_LIBS = @FREETYPE2_LIBS@ +GCONF_CFLAGS = @GCONF_CFLAGS@ +GCONF_LIBS = @GCONF_LIBS@ +GDK_CFLAGS = @GDK_CFLAGS@ +GDK_LIBS = @GDK_LIBS@ +GJDOC = @GJDOC@ +GLIB_CFLAGS = @GLIB_CFLAGS@ +GLIB_LIBS = @GLIB_LIBS@ +GMP_CFLAGS = @GMP_CFLAGS@ +GMP_LIBS = @GMP_LIBS@ +GREP = @GREP@ +GSTREAMER_BASE_CFLAGS = @GSTREAMER_BASE_CFLAGS@ +GSTREAMER_BASE_LIBS = @GSTREAMER_BASE_LIBS@ +GSTREAMER_CFLAGS = @GSTREAMER_CFLAGS@ +GSTREAMER_FILE_READER = @GSTREAMER_FILE_READER@ +GSTREAMER_LIBS = @GSTREAMER_LIBS@ +GSTREAMER_MIXER_PROVIDER = @GSTREAMER_MIXER_PROVIDER@ +GSTREAMER_PLUGINS_BASE_CFLAGS = @GSTREAMER_PLUGINS_BASE_CFLAGS@ +GSTREAMER_PLUGINS_BASE_LIBS = @GSTREAMER_PLUGINS_BASE_LIBS@ +GST_PLUGIN_LDFLAGS = @GST_PLUGIN_LDFLAGS@ +GTK_CFLAGS = @GTK_CFLAGS@ +GTK_LIBS = @GTK_LIBS@ +INIT_LOAD_LIBRARY = @INIT_LOAD_LIBRARY@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAR = @JAR@ +JAVA = @JAVA@ +JAVAC = @JAVAC@ +JAVAC_IS_GCJ = @JAVAC_IS_GCJ@ +JAVAC_MEM_OPT = @JAVAC_MEM_OPT@ +JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION = @JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION@ +JAY = @JAY@ +JAY_SKELETON = @JAY_SKELETON@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBDEBUG = @LIBDEBUG@ +LIBICONV = @LIBICONV@ +LIBMAGIC = @LIBMAGIC@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBVERSION = @LIBVERSION@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBICONV = @LTLIBICONV@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MKDIR = @MKDIR@ +MKDIR_P = @MKDIR_P@ +MOC = @MOC@ +MOZILLA_CFLAGS = @MOZILLA_CFLAGS@ +MOZILLA_LIBS = @MOZILLA_LIBS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PANGOFT2_CFLAGS = @PANGOFT2_CFLAGS@ +PANGOFT2_LIBS = @PANGOFT2_LIBS@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PATH_TO_ESCHER = @PATH_TO_ESCHER@ +PATH_TO_GLIBJ_ZIP = @PATH_TO_GLIBJ_ZIP@ +PERL = @PERL@ +PKG_CONFIG = @PKG_CONFIG@ +PLUGIN_DIR = @PLUGIN_DIR@ +QT_CFLAGS = @QT_CFLAGS@ +QT_LIBS = @QT_LIBS@ +RANLIB = @RANLIB@ +REMOVE = @REMOVE@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRICT_WARNING_CFLAGS = @STRICT_WARNING_CFLAGS@ +STRIP = @STRIP@ +TOOLSDIR = @TOOLSDIR@ +USER_JAVAH = @USER_JAVAH@ +VERSION = @VERSION@ +WANT_NATIVE_BIG_INTEGER = @WANT_NATIVE_BIG_INTEGER@ +WARNING_CFLAGS = @WARNING_CFLAGS@ +XMKMF = @XMKMF@ +XML_CFLAGS = @XML_CFLAGS@ +XML_LIBS = @XML_LIBS@ +XSLT_CFLAGS = @XSLT_CFLAGS@ +XSLT_LIBS = @XSLT_LIBS@ +XTEST_LIBS = @XTEST_LIBS@ +X_CFLAGS = @X_CFLAGS@ +X_EXTRA_LIBS = @X_EXTRA_LIBS@ +X_LIBS = @X_LIBS@ +X_PRE_LIBS = @X_PRE_LIBS@ +ZIP = @ZIP@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_ANTLR = @ac_ct_ANTLR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +default_toolkit = @default_toolkit@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +glibjdir = @glibjdir@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +multi_basedir = @multi_basedir@ +nativeexeclibdir = @nativeexeclibdir@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +toolexeclibdir = @toolexeclibdir@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +uudecode = @uudecode@ +vm_classes = @vm_classes@ +nativeexeclib_LTLIBRARIES = libjawt.la +libjawt_la_SOURCES = jawt.c +libjawt_la_LIBADD = $(top_builddir)/native/jni/gtk-peer/libgtkpeer.la +libjawt_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version +AM_LDFLAGS = @CLASSPATH_MODULE@ @GTK_LIBS@ @PANGOFT2_LIBS@ @X_LIBS@ @XTEST_LIBS@ +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ + +# Just the WARNING_CFLAGS. We cannot use the strict flags since the gtk +# headers contain broken prototypes (by design, see gtkitemfactory.h). +AM_CFLAGS = @WARNING_CFLAGS@ @ERROR_CFLAGS@ \ + @GTK_CFLAGS@ @PANGOFT2_CFLAGS@ @EXTRA_CFLAGS@ + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu native/jawt/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu native/jawt/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-nativeexeclibLTLIBRARIES: $(nativeexeclib_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(nativeexeclibdir)" || $(MKDIR_P) "$(DESTDIR)$(nativeexeclibdir)" + @list='$(nativeexeclib_LTLIBRARIES)'; test -n "$(nativeexeclibdir)" || list=; \ + list2=; for p in $$list; do \ + if test -f $$p; then \ + list2="$$list2 $$p"; \ + else :; fi; \ + done; \ + test -z "$$list2" || { \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(nativeexeclibdir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(nativeexeclibdir)"; \ + } + +uninstall-nativeexeclibLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(nativeexeclib_LTLIBRARIES)'; test -n "$(nativeexeclibdir)" || list=; \ + for p in $$list; do \ + $(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(nativeexeclibdir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(nativeexeclibdir)/$$f"; \ + done + +clean-nativeexeclibLTLIBRARIES: + -test -z "$(nativeexeclib_LTLIBRARIES)" || rm -f $(nativeexeclib_LTLIBRARIES) + @list='$(nativeexeclib_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libjawt.la: $(libjawt_la_OBJECTS) $(libjawt_la_DEPENDENCIES) + $(libjawt_la_LINK) -rpath $(nativeexeclibdir) $(libjawt_la_OBJECTS) $(libjawt_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/jawt.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) +installdirs: + for dir in "$(DESTDIR)$(nativeexeclibdir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-nativeexeclibLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-nativeexeclibLTLIBRARIES + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-nativeexeclibLTLIBRARIES + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-nativeexeclibLTLIBRARIES ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags dvi dvi-am html html-am info info-am install \ + install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-nativeexeclibLTLIBRARIES install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-nativeexeclibLTLIBRARIES + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/libjava/classpath/native/jawt/jawt.c b/libjava/classpath/native/jawt/jawt.c new file mode 100644 index 000000000..4ebb105d7 --- /dev/null +++ b/libjava/classpath/native/jawt/jawt.c @@ -0,0 +1,188 @@ +/* jawt.c -- X11 implementation of the AWT Native Interface + Copyright (C) 2005 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + +#include +#include +#include +#include +#include "classpath_jawt.h" + +#ifndef __GNUC__ +#define __attribute__(x) /* nothing */ +#endif + +static jint (JNICALL _Jv_Lock) (JAWT_DrawingSurface* surface); +static void (JNICALL _Jv_Unlock) (JAWT_DrawingSurface* surface); +static JAWT_DrawingSurfaceInfo* (JNICALL _Jv_GetDrawingSurfaceInfo) + (JAWT_DrawingSurface* surface); +static void (JNICALL _Jv_FreeDrawingSurfaceInfo) + (JAWT_DrawingSurfaceInfo* surface_info); +static JAWT_DrawingSurface* (JNICALL _Jv_GetDrawingSurface) (JNIEnv* env, + jobject canvas); +static void (JNICALL _Jv_FreeDrawingSurface) (JAWT_DrawingSurface* surface); +static void (JNICALL _Jv_AWTLock) (JNIEnv*); +static void (JNICALL _Jv_AWTUnlock) (JNIEnv*); + +JNIEXPORT jboolean JNICALL +JAWT_GetAWT (JNIEnv* env __attribute__((unused)), JAWT* awt) +{ + jint retrieved_version; + + retrieved_version = classpath_jawt_get_awt_version (); + + if (awt->version > retrieved_version) + return JNI_FALSE; + + awt->GetDrawingSurface = _Jv_GetDrawingSurface; + awt->FreeDrawingSurface = _Jv_FreeDrawingSurface; + awt->Lock = _Jv_AWTLock; + awt->Unlock = _Jv_AWTUnlock; + + return JNI_TRUE; +} + +/* JAWT_DrawingSurface functions */ + +static jint +(JNICALL _Jv_Lock) (JAWT_DrawingSurface* surface __attribute__((unused))) +{ + return classpath_jawt_lock (); +} + +static void +(JNICALL _Jv_Unlock) (JAWT_DrawingSurface* surface __attribute__((unused))) +{ + classpath_jawt_unlock (); +} + +static JAWT_DrawingSurfaceInfo* +(JNICALL _Jv_GetDrawingSurfaceInfo) (JAWT_DrawingSurface* surface) +{ + JAWT_DrawingSurfaceInfo* surface_info; + JAWT_X11DrawingSurfaceInfo* surface_info_x11; + + if (surface == NULL || surface->target == NULL) + return NULL; + + surface_info = (JAWT_DrawingSurfaceInfo*) malloc (sizeof (JAWT_DrawingSurfaceInfo)); + + if (surface_info == NULL) + return NULL; + + surface_info->platformInfo = malloc (sizeof (JAWT_X11DrawingSurfaceInfo)); + + if (surface_info->platformInfo == NULL) + return NULL; + + surface_info_x11 = (JAWT_X11DrawingSurfaceInfo*) surface_info->platformInfo; + + surface_info_x11->display = classpath_jawt_get_default_display (surface->env, + surface->target); + surface_info_x11->drawable = classpath_jawt_get_drawable (surface->env, + surface->target); + surface_info_x11->visualID = classpath_jawt_get_visualID (surface->env, + surface->target); + surface_info_x11->depth = classpath_jawt_get_depth (surface->env, + surface->target); + + /* FIXME: also include bounding rectangle of drawing surface */ + /* FIXME: also include current clipping region */ + + return surface_info; +} + +static void +(JNICALL _Jv_FreeDrawingSurfaceInfo) (JAWT_DrawingSurfaceInfo* surface_info) +{ + JAWT_X11DrawingSurfaceInfo* surface_info_x11; + + if (surface_info == NULL) + return; + + surface_info_x11 = (JAWT_X11DrawingSurfaceInfo*) surface_info->platformInfo; + + surface_info_x11->display = NULL; + surface_info_x11->drawable = 0; + surface_info_x11->visualID = 0; + + free (surface_info->platformInfo); + free (surface_info); + surface_info = NULL; +} + +/* JAWT functions */ + +static JAWT_DrawingSurface* +(JNICALL _Jv_GetDrawingSurface) (JNIEnv* env, jobject canvas) +{ + JAWT_DrawingSurface* surface; + + surface = (JAWT_DrawingSurface*) malloc (sizeof (JAWT_DrawingSurface)); + + if (surface == NULL) + return NULL; + + surface->env = env; + surface->target = canvas; + + /* initialize function pointers */ + surface->GetDrawingSurfaceInfo = _Jv_GetDrawingSurfaceInfo; + surface->FreeDrawingSurfaceInfo = _Jv_FreeDrawingSurfaceInfo; + + surface->Lock = _Jv_Lock; + surface->Unlock = _Jv_Unlock; + + return surface; +} + +static void +(JNICALL _Jv_FreeDrawingSurface) (JAWT_DrawingSurface* surface) +{ + free (surface); +} + +static void +(JNICALL _Jv_AWTLock) (JNIEnv* env __attribute__((unused))) +{ + /* FIXME: what is this supposed to do? */ +} + +static void +(JNICALL _Jv_AWTUnlock) (JNIEnv* env __attribute__((unused))) +{ + /* FIXME: what is this supposed to do? */ +} diff --git a/libjava/classpath/native/jni/.cvsignore b/libjava/classpath/native/jni/.cvsignore new file mode 100644 index 000000000..e9f2658a6 --- /dev/null +++ b/libjava/classpath/native/jni/.cvsignore @@ -0,0 +1,8 @@ +*.o +*.a +*.lo +*.la +.libs +.deps +Makefile +Makefile.in diff --git a/libjava/classpath/native/jni/Makefile.am b/libjava/classpath/native/jni/Makefile.am new file mode 100644 index 000000000..e8db33214 --- /dev/null +++ b/libjava/classpath/native/jni/Makefile.am @@ -0,0 +1,47 @@ +## Input file for automake to generate the Makefile.in used by configure + +if CREATE_CORE_JNI_LIBRARIES + JNIDIRS = native-lib java-io java-lang java-net java-nio java-util +endif + +if CREATE_ALSA_LIBRARIES + ALSADIR = midi-alsa +endif + +if CREATE_DSSI_LIBRARIES + DSSIDIR = midi-dssi +endif + +if CREATE_GTK_PEER_LIBRARIES + GTKDIR = gtk-peer +endif + +if CREATE_QT_PEER_LIBRARIES + CLASSPATH_QT_PEER_DIR = qt-peer +endif + +if CREATE_GCONF_PEER_LIBRARIES + CLASSPATH_GCONF_PEER_DIR = gconf-peer +endif + +if CREATE_GSTREAMER_PEER_LIBRARIES + CLASSPATH_GSTREAMER_PEER_DIR = gstreamer-peer +endif + +if CREATE_XMLJ_LIBRARY + XMLJDIR = xmlj +endif + +if CREATE_GMPBI_LIBRARY + GMPDIR = java-math +endif + +SUBDIRS = classpath $(JNIDIRS) \ + $(ALSADIR) $(DSSIDIR) $(GTKDIR) $(CLASSPATH_QT_PEER_DIR) $(XMLJDIR) \ + $(CLASSPATH_GCONF_PEER_DIR) $(CLASSPATH_GSTREAMER_PEER_DIR) $(GMPDIR) +DIST_SUBDIRS = classpath java-io java-lang java-math java-net java-nio java-util \ + gtk-peer gconf-peer gstreamer-peer qt-peer xmlj midi-alsa \ + midi-dssi native-lib + +all-local: + $(SHELL) $(top_builddir)/scripts/check_jni_methods.sh diff --git a/libjava/classpath/native/jni/Makefile.in b/libjava/classpath/native/jni/Makefile.in new file mode 100644 index 000000000..db801318b --- /dev/null +++ b/libjava/classpath/native/jni/Makefile.in @@ -0,0 +1,604 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +subdir = native/jni +DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/../../config/depstand.m4 \ + $(top_srcdir)/../../config/lead-dot.m4 \ + $(top_srcdir)/../../config/lib-ld.m4 \ + $(top_srcdir)/../../config/lib-link.m4 \ + $(top_srcdir)/../../config/lib-prefix.m4 \ + $(top_srcdir)/../../config/multi.m4 \ + $(top_srcdir)/../../config/no-executables.m4 \ + $(top_srcdir)/../../config/override.m4 \ + $(top_srcdir)/../../libtool.m4 \ + $(top_srcdir)/../../ltoptions.m4 \ + $(top_srcdir)/../../ltsugar.m4 \ + $(top_srcdir)/../../ltversion.m4 \ + $(top_srcdir)/../../lt~obsolete.m4 \ + $(top_srcdir)/m4/ac_prog_antlr.m4 \ + $(top_srcdir)/m4/ac_prog_java.m4 \ + $(top_srcdir)/m4/ac_prog_java_works.m4 \ + $(top_srcdir)/m4/ac_prog_javac.m4 \ + $(top_srcdir)/m4/ac_prog_javac_works.m4 \ + $(top_srcdir)/m4/acattribute.m4 $(top_srcdir)/m4/accross.m4 \ + $(top_srcdir)/m4/acinclude.m4 \ + $(top_srcdir)/m4/ax_create_stdint_h.m4 \ + $(top_srcdir)/m4/ax_func_which_gethostbyname_r.m4 \ + $(top_srcdir)/m4/gcc_attribute.m4 $(top_srcdir)/m4/iconv.m4 \ + $(top_srcdir)/m4/pkg.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/../../mkinstalldirs +CONFIG_HEADER = $(top_builddir)/include/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +SOURCES = +RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \ + html-recursive info-recursive install-data-recursive \ + install-dvi-recursive install-exec-recursive \ + install-html-recursive install-info-recursive \ + install-pdf-recursive install-ps-recursive install-recursive \ + installcheck-recursive installdirs-recursive pdf-recursive \ + ps-recursive uninstall-recursive +RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ + distclean-recursive maintainer-clean-recursive +AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \ + $(RECURSIVE_CLEAN_TARGETS:-recursive=) tags TAGS ctags CTAGS +ETAGS = etags +CTAGS = ctags +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +ANTLR = @ANTLR@ +ANTLR_JAR = @ANTLR_JAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CAIRO_CFLAGS = @CAIRO_CFLAGS@ +CAIRO_LIBS = @CAIRO_LIBS@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CLASSPATH_CONVENIENCE = @CLASSPATH_CONVENIENCE@ +CLASSPATH_INCLUDES = @CLASSPATH_INCLUDES@ +CLASSPATH_MODULE = @CLASSPATH_MODULE@ +COLLECTIONS_PREFIX = @COLLECTIONS_PREFIX@ +CP = @CP@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DATE = @DATE@ +DEFAULT_PREFS_PEER = @DEFAULT_PREFS_PEER@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +ECJ_JAR = @ECJ_JAR@ +EGREP = @EGREP@ +ERROR_CFLAGS = @ERROR_CFLAGS@ +EXAMPLESDIR = @EXAMPLESDIR@ +EXEEXT = @EXEEXT@ +EXTRA_CFLAGS = @EXTRA_CFLAGS@ +FGREP = @FGREP@ +FIND = @FIND@ +FREETYPE2_CFLAGS = @FREETYPE2_CFLAGS@ +FREETYPE2_LIBS = @FREETYPE2_LIBS@ +GCONF_CFLAGS = @GCONF_CFLAGS@ +GCONF_LIBS = @GCONF_LIBS@ +GDK_CFLAGS = @GDK_CFLAGS@ +GDK_LIBS = @GDK_LIBS@ +GJDOC = @GJDOC@ +GLIB_CFLAGS = @GLIB_CFLAGS@ +GLIB_LIBS = @GLIB_LIBS@ +GMP_CFLAGS = @GMP_CFLAGS@ +GMP_LIBS = @GMP_LIBS@ +GREP = @GREP@ +GSTREAMER_BASE_CFLAGS = @GSTREAMER_BASE_CFLAGS@ +GSTREAMER_BASE_LIBS = @GSTREAMER_BASE_LIBS@ +GSTREAMER_CFLAGS = @GSTREAMER_CFLAGS@ +GSTREAMER_FILE_READER = @GSTREAMER_FILE_READER@ +GSTREAMER_LIBS = @GSTREAMER_LIBS@ +GSTREAMER_MIXER_PROVIDER = @GSTREAMER_MIXER_PROVIDER@ +GSTREAMER_PLUGINS_BASE_CFLAGS = @GSTREAMER_PLUGINS_BASE_CFLAGS@ +GSTREAMER_PLUGINS_BASE_LIBS = @GSTREAMER_PLUGINS_BASE_LIBS@ +GST_PLUGIN_LDFLAGS = @GST_PLUGIN_LDFLAGS@ +GTK_CFLAGS = @GTK_CFLAGS@ +GTK_LIBS = @GTK_LIBS@ +INIT_LOAD_LIBRARY = @INIT_LOAD_LIBRARY@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAR = @JAR@ +JAVA = @JAVA@ +JAVAC = @JAVAC@ +JAVAC_IS_GCJ = @JAVAC_IS_GCJ@ +JAVAC_MEM_OPT = @JAVAC_MEM_OPT@ +JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION = @JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION@ +JAY = @JAY@ +JAY_SKELETON = @JAY_SKELETON@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBDEBUG = @LIBDEBUG@ +LIBICONV = @LIBICONV@ +LIBMAGIC = @LIBMAGIC@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBVERSION = @LIBVERSION@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBICONV = @LTLIBICONV@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MKDIR = @MKDIR@ +MKDIR_P = @MKDIR_P@ +MOC = @MOC@ +MOZILLA_CFLAGS = @MOZILLA_CFLAGS@ +MOZILLA_LIBS = @MOZILLA_LIBS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PANGOFT2_CFLAGS = @PANGOFT2_CFLAGS@ +PANGOFT2_LIBS = @PANGOFT2_LIBS@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PATH_TO_ESCHER = @PATH_TO_ESCHER@ +PATH_TO_GLIBJ_ZIP = @PATH_TO_GLIBJ_ZIP@ +PERL = @PERL@ +PKG_CONFIG = @PKG_CONFIG@ +PLUGIN_DIR = @PLUGIN_DIR@ +QT_CFLAGS = @QT_CFLAGS@ +QT_LIBS = @QT_LIBS@ +RANLIB = @RANLIB@ +REMOVE = @REMOVE@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRICT_WARNING_CFLAGS = @STRICT_WARNING_CFLAGS@ +STRIP = @STRIP@ +TOOLSDIR = @TOOLSDIR@ +USER_JAVAH = @USER_JAVAH@ +VERSION = @VERSION@ +WANT_NATIVE_BIG_INTEGER = @WANT_NATIVE_BIG_INTEGER@ +WARNING_CFLAGS = @WARNING_CFLAGS@ +XMKMF = @XMKMF@ +XML_CFLAGS = @XML_CFLAGS@ +XML_LIBS = @XML_LIBS@ +XSLT_CFLAGS = @XSLT_CFLAGS@ +XSLT_LIBS = @XSLT_LIBS@ +XTEST_LIBS = @XTEST_LIBS@ +X_CFLAGS = @X_CFLAGS@ +X_EXTRA_LIBS = @X_EXTRA_LIBS@ +X_LIBS = @X_LIBS@ +X_PRE_LIBS = @X_PRE_LIBS@ +ZIP = @ZIP@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_ANTLR = @ac_ct_ANTLR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +default_toolkit = @default_toolkit@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +glibjdir = @glibjdir@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +multi_basedir = @multi_basedir@ +nativeexeclibdir = @nativeexeclibdir@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +toolexeclibdir = @toolexeclibdir@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +uudecode = @uudecode@ +vm_classes = @vm_classes@ +@CREATE_CORE_JNI_LIBRARIES_TRUE@JNIDIRS = native-lib java-io java-lang java-net java-nio java-util +@CREATE_ALSA_LIBRARIES_TRUE@ALSADIR = midi-alsa +@CREATE_DSSI_LIBRARIES_TRUE@DSSIDIR = midi-dssi +@CREATE_GTK_PEER_LIBRARIES_TRUE@GTKDIR = gtk-peer +@CREATE_QT_PEER_LIBRARIES_TRUE@CLASSPATH_QT_PEER_DIR = qt-peer +@CREATE_GCONF_PEER_LIBRARIES_TRUE@CLASSPATH_GCONF_PEER_DIR = gconf-peer +@CREATE_GSTREAMER_PEER_LIBRARIES_TRUE@CLASSPATH_GSTREAMER_PEER_DIR = gstreamer-peer +@CREATE_XMLJ_LIBRARY_TRUE@XMLJDIR = xmlj +@CREATE_GMPBI_LIBRARY_TRUE@GMPDIR = java-math +SUBDIRS = classpath $(JNIDIRS) \ + $(ALSADIR) $(DSSIDIR) $(GTKDIR) $(CLASSPATH_QT_PEER_DIR) $(XMLJDIR) \ + $(CLASSPATH_GCONF_PEER_DIR) $(CLASSPATH_GSTREAMER_PEER_DIR) $(GMPDIR) + +DIST_SUBDIRS = classpath java-io java-lang java-math java-net java-nio java-util \ + gtk-peer gconf-peer gstreamer-peer qt-peer xmlj midi-alsa \ + midi-dssi native-lib + +all: all-recursive + +.SUFFIXES: +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu native/jni/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu native/jni/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +# This directory's subdirectories are mostly independent; you can cd +# into them and run `make' without going through this Makefile. +# To change the values of `make' variables: instead of editing Makefiles, +# (1) if the variable is set in `config.status', edit `config.status' +# (which will cause the Makefiles to be regenerated when you run `make'); +# (2) otherwise, pass the desired values on the `make' command line. +$(RECURSIVE_TARGETS): + @fail= failcom='exit 1'; \ + for f in x $$MAKEFLAGS; do \ + case $$f in \ + *=* | --[!k]*);; \ + *k*) failcom='fail=yes';; \ + esac; \ + done; \ + dot_seen=no; \ + target=`echo $@ | sed s/-recursive//`; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + dot_seen=yes; \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || eval $$failcom; \ + done; \ + if test "$$dot_seen" = "no"; then \ + $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ + fi; test -z "$$fail" + +$(RECURSIVE_CLEAN_TARGETS): + @fail= failcom='exit 1'; \ + for f in x $$MAKEFLAGS; do \ + case $$f in \ + *=* | --[!k]*);; \ + *k*) failcom='fail=yes';; \ + esac; \ + done; \ + dot_seen=no; \ + case "$@" in \ + distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ + *) list='$(SUBDIRS)' ;; \ + esac; \ + rev=''; for subdir in $$list; do \ + if test "$$subdir" = "."; then :; else \ + rev="$$subdir $$rev"; \ + fi; \ + done; \ + rev="$$rev ."; \ + target=`echo $@ | sed s/-recursive//`; \ + for subdir in $$rev; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || eval $$failcom; \ + done && test -z "$$fail" +tags-recursive: + list='$(SUBDIRS)'; for subdir in $$list; do \ + test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \ + done +ctags-recursive: + list='$(SUBDIRS)'; for subdir in $$list; do \ + test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \ + done + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: tags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \ + include_option=--etags-include; \ + empty_fix=.; \ + else \ + include_option=--include; \ + empty_fix=; \ + fi; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + test ! -f $$subdir/TAGS || \ + set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \ + fi; \ + done; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: ctags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags +check-am: all-am +check: check-recursive +all-am: Makefile all-local +installdirs: installdirs-recursive +installdirs-am: +install: install-recursive +install-exec: install-exec-recursive +install-data: install-data-recursive +uninstall: uninstall-recursive + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-recursive +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-recursive + +clean-am: clean-generic clean-libtool mostlyclean-am + +distclean: distclean-recursive + -rm -f Makefile +distclean-am: clean-am distclean-generic distclean-tags + +dvi: dvi-recursive + +dvi-am: + +html: html-recursive + +html-am: + +info: info-recursive + +info-am: + +install-data-am: + +install-dvi: install-dvi-recursive + +install-dvi-am: + +install-exec-am: + +install-html: install-html-recursive + +install-html-am: + +install-info: install-info-recursive + +install-info-am: + +install-man: + +install-pdf: install-pdf-recursive + +install-pdf-am: + +install-ps: install-ps-recursive + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-recursive + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-recursive + +mostlyclean-am: mostlyclean-generic mostlyclean-libtool + +pdf: pdf-recursive + +pdf-am: + +ps: ps-recursive + +ps-am: + +uninstall-am: + +.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) ctags-recursive \ + install-am install-strip tags-recursive + +.PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \ + all all-am all-local check check-am clean clean-generic \ + clean-libtool ctags ctags-recursive distclean \ + distclean-generic distclean-libtool distclean-tags dvi dvi-am \ + html html-am info info-am install install-am install-data \ + install-data-am install-dvi install-dvi-am install-exec \ + install-exec-am install-html install-html-am install-info \ + install-info-am install-man install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs installdirs-am maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-generic \ + mostlyclean-libtool pdf pdf-am ps ps-am tags tags-recursive \ + uninstall uninstall-am + + +all-local: + $(SHELL) $(top_builddir)/scripts/check_jni_methods.sh + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/libjava/classpath/native/jni/classpath/.cvsignore b/libjava/classpath/native/jni/classpath/.cvsignore new file mode 100644 index 000000000..e9f2658a6 --- /dev/null +++ b/libjava/classpath/native/jni/classpath/.cvsignore @@ -0,0 +1,8 @@ +*.o +*.a +*.lo +*.la +.libs +.deps +Makefile +Makefile.in diff --git a/libjava/classpath/native/jni/classpath/Makefile.am b/libjava/classpath/native/jni/classpath/Makefile.am new file mode 100644 index 000000000..985475527 --- /dev/null +++ b/libjava/classpath/native/jni/classpath/Makefile.am @@ -0,0 +1,12 @@ +# Header needed for jawt implementations such as the one found in ../gtk-peer. +EXTRA_DIST = classpath_jawt.h + +noinst_LTLIBRARIES = libclasspath.la + +libclasspath_la_SOURCES = jcl.c jcl.h \ + jnilink.c jnilink.h + +AM_LDFLAGS = @CLASSPATH_CONVENIENCE@ +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ +AM_CFLAGS = @WARNING_CFLAGS@ @STRICT_WARNING_CFLAGS@ @ERROR_CFLAGS@ \ + @EXTRA_CFLAGS@ diff --git a/libjava/classpath/native/jni/classpath/Makefile.in b/libjava/classpath/native/jni/classpath/Makefile.in new file mode 100644 index 000000000..8067936e6 --- /dev/null +++ b/libjava/classpath/native/jni/classpath/Makefile.in @@ -0,0 +1,564 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +subdir = native/jni/classpath +DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/../../config/depstand.m4 \ + $(top_srcdir)/../../config/lead-dot.m4 \ + $(top_srcdir)/../../config/lib-ld.m4 \ + $(top_srcdir)/../../config/lib-link.m4 \ + $(top_srcdir)/../../config/lib-prefix.m4 \ + $(top_srcdir)/../../config/multi.m4 \ + $(top_srcdir)/../../config/no-executables.m4 \ + $(top_srcdir)/../../config/override.m4 \ + $(top_srcdir)/../../libtool.m4 \ + $(top_srcdir)/../../ltoptions.m4 \ + $(top_srcdir)/../../ltsugar.m4 \ + $(top_srcdir)/../../ltversion.m4 \ + $(top_srcdir)/../../lt~obsolete.m4 \ + $(top_srcdir)/m4/ac_prog_antlr.m4 \ + $(top_srcdir)/m4/ac_prog_java.m4 \ + $(top_srcdir)/m4/ac_prog_java_works.m4 \ + $(top_srcdir)/m4/ac_prog_javac.m4 \ + $(top_srcdir)/m4/ac_prog_javac_works.m4 \ + $(top_srcdir)/m4/acattribute.m4 $(top_srcdir)/m4/accross.m4 \ + $(top_srcdir)/m4/acinclude.m4 \ + $(top_srcdir)/m4/ax_create_stdint_h.m4 \ + $(top_srcdir)/m4/ax_func_which_gethostbyname_r.m4 \ + $(top_srcdir)/m4/gcc_attribute.m4 $(top_srcdir)/m4/iconv.m4 \ + $(top_srcdir)/m4/pkg.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/../../mkinstalldirs +CONFIG_HEADER = $(top_builddir)/include/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +LTLIBRARIES = $(noinst_LTLIBRARIES) +libclasspath_la_LIBADD = +am_libclasspath_la_OBJECTS = jcl.lo jnilink.lo +libclasspath_la_OBJECTS = $(am_libclasspath_la_OBJECTS) +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/include +depcomp = $(SHELL) $(top_srcdir)/../../depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(libclasspath_la_SOURCES) +ETAGS = etags +CTAGS = ctags +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +ANTLR = @ANTLR@ +ANTLR_JAR = @ANTLR_JAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CAIRO_CFLAGS = @CAIRO_CFLAGS@ +CAIRO_LIBS = @CAIRO_LIBS@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CLASSPATH_CONVENIENCE = @CLASSPATH_CONVENIENCE@ +CLASSPATH_INCLUDES = @CLASSPATH_INCLUDES@ +CLASSPATH_MODULE = @CLASSPATH_MODULE@ +COLLECTIONS_PREFIX = @COLLECTIONS_PREFIX@ +CP = @CP@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DATE = @DATE@ +DEFAULT_PREFS_PEER = @DEFAULT_PREFS_PEER@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +ECJ_JAR = @ECJ_JAR@ +EGREP = @EGREP@ +ERROR_CFLAGS = @ERROR_CFLAGS@ +EXAMPLESDIR = @EXAMPLESDIR@ +EXEEXT = @EXEEXT@ +EXTRA_CFLAGS = @EXTRA_CFLAGS@ +FGREP = @FGREP@ +FIND = @FIND@ +FREETYPE2_CFLAGS = @FREETYPE2_CFLAGS@ +FREETYPE2_LIBS = @FREETYPE2_LIBS@ +GCONF_CFLAGS = @GCONF_CFLAGS@ +GCONF_LIBS = @GCONF_LIBS@ +GDK_CFLAGS = @GDK_CFLAGS@ +GDK_LIBS = @GDK_LIBS@ +GJDOC = @GJDOC@ +GLIB_CFLAGS = @GLIB_CFLAGS@ +GLIB_LIBS = @GLIB_LIBS@ +GMP_CFLAGS = @GMP_CFLAGS@ +GMP_LIBS = @GMP_LIBS@ +GREP = @GREP@ +GSTREAMER_BASE_CFLAGS = @GSTREAMER_BASE_CFLAGS@ +GSTREAMER_BASE_LIBS = @GSTREAMER_BASE_LIBS@ +GSTREAMER_CFLAGS = @GSTREAMER_CFLAGS@ +GSTREAMER_FILE_READER = @GSTREAMER_FILE_READER@ +GSTREAMER_LIBS = @GSTREAMER_LIBS@ +GSTREAMER_MIXER_PROVIDER = @GSTREAMER_MIXER_PROVIDER@ +GSTREAMER_PLUGINS_BASE_CFLAGS = @GSTREAMER_PLUGINS_BASE_CFLAGS@ +GSTREAMER_PLUGINS_BASE_LIBS = @GSTREAMER_PLUGINS_BASE_LIBS@ +GST_PLUGIN_LDFLAGS = @GST_PLUGIN_LDFLAGS@ +GTK_CFLAGS = @GTK_CFLAGS@ +GTK_LIBS = @GTK_LIBS@ +INIT_LOAD_LIBRARY = @INIT_LOAD_LIBRARY@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAR = @JAR@ +JAVA = @JAVA@ +JAVAC = @JAVAC@ +JAVAC_IS_GCJ = @JAVAC_IS_GCJ@ +JAVAC_MEM_OPT = @JAVAC_MEM_OPT@ +JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION = @JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION@ +JAY = @JAY@ +JAY_SKELETON = @JAY_SKELETON@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBDEBUG = @LIBDEBUG@ +LIBICONV = @LIBICONV@ +LIBMAGIC = @LIBMAGIC@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBVERSION = @LIBVERSION@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBICONV = @LTLIBICONV@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MKDIR = @MKDIR@ +MKDIR_P = @MKDIR_P@ +MOC = @MOC@ +MOZILLA_CFLAGS = @MOZILLA_CFLAGS@ +MOZILLA_LIBS = @MOZILLA_LIBS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PANGOFT2_CFLAGS = @PANGOFT2_CFLAGS@ +PANGOFT2_LIBS = @PANGOFT2_LIBS@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PATH_TO_ESCHER = @PATH_TO_ESCHER@ +PATH_TO_GLIBJ_ZIP = @PATH_TO_GLIBJ_ZIP@ +PERL = @PERL@ +PKG_CONFIG = @PKG_CONFIG@ +PLUGIN_DIR = @PLUGIN_DIR@ +QT_CFLAGS = @QT_CFLAGS@ +QT_LIBS = @QT_LIBS@ +RANLIB = @RANLIB@ +REMOVE = @REMOVE@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRICT_WARNING_CFLAGS = @STRICT_WARNING_CFLAGS@ +STRIP = @STRIP@ +TOOLSDIR = @TOOLSDIR@ +USER_JAVAH = @USER_JAVAH@ +VERSION = @VERSION@ +WANT_NATIVE_BIG_INTEGER = @WANT_NATIVE_BIG_INTEGER@ +WARNING_CFLAGS = @WARNING_CFLAGS@ +XMKMF = @XMKMF@ +XML_CFLAGS = @XML_CFLAGS@ +XML_LIBS = @XML_LIBS@ +XSLT_CFLAGS = @XSLT_CFLAGS@ +XSLT_LIBS = @XSLT_LIBS@ +XTEST_LIBS = @XTEST_LIBS@ +X_CFLAGS = @X_CFLAGS@ +X_EXTRA_LIBS = @X_EXTRA_LIBS@ +X_LIBS = @X_LIBS@ +X_PRE_LIBS = @X_PRE_LIBS@ +ZIP = @ZIP@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_ANTLR = @ac_ct_ANTLR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +default_toolkit = @default_toolkit@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +glibjdir = @glibjdir@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +multi_basedir = @multi_basedir@ +nativeexeclibdir = @nativeexeclibdir@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +toolexeclibdir = @toolexeclibdir@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +uudecode = @uudecode@ +vm_classes = @vm_classes@ + +# Header needed for jawt implementations such as the one found in ../gtk-peer. +EXTRA_DIST = classpath_jawt.h +noinst_LTLIBRARIES = libclasspath.la +libclasspath_la_SOURCES = jcl.c jcl.h \ + jnilink.c jnilink.h + +AM_LDFLAGS = @CLASSPATH_CONVENIENCE@ +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ +AM_CFLAGS = @WARNING_CFLAGS@ @STRICT_WARNING_CFLAGS@ @ERROR_CFLAGS@ \ + @EXTRA_CFLAGS@ + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu native/jni/classpath/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu native/jni/classpath/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +clean-noinstLTLIBRARIES: + -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES) + @list='$(noinst_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libclasspath.la: $(libclasspath_la_OBJECTS) $(libclasspath_la_DEPENDENCIES) + $(LINK) $(libclasspath_la_OBJECTS) $(libclasspath_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/jcl.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/jnilink.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-noinstLTLIBRARIES ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags dvi dvi-am html html-am info info-am install \ + install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-pdf install-pdf-am install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ + pdf pdf-am ps ps-am tags uninstall uninstall-am + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/libjava/classpath/native/jni/classpath/classpath_jawt.h b/libjava/classpath/native/jni/classpath/classpath_jawt.h new file mode 100644 index 000000000..35c734a57 --- /dev/null +++ b/libjava/classpath/native/jni/classpath/classpath_jawt.h @@ -0,0 +1,61 @@ +/* classpath_awt.h -- libjawt's interface to the peer library + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +/* + * libjawt.so is linked directly to the peer library with -l. This + * header declares all the functions that libjawt.so needs -- X-based + * peer libraries wanting to support libjawt.so must implement these + * functions. + */ + +#ifndef __classpath_jawt_h__ +#define __classpath_jawt_h__ + +#include +#include + +#define CLASSPATH_JAWT_VERSION 0x10004 + +jint classpath_jawt_get_awt_version (void); +Display* classpath_jawt_get_default_display (JNIEnv* env, jobject canvas); +Drawable classpath_jawt_get_drawable (JNIEnv* env, jobject canvas); +VisualID classpath_jawt_get_visualID (JNIEnv* env, jobject canvas); +int classpath_jawt_get_depth (JNIEnv* env, jobject canvas); +jint classpath_jawt_lock (void); +void classpath_jawt_unlock (void); + +#endif /* __classpath_jawt_h__ */ diff --git a/libjava/classpath/native/jni/classpath/jcl.c b/libjava/classpath/native/jni/classpath/jcl.c new file mode 100644 index 000000000..0180ab9f0 --- /dev/null +++ b/libjava/classpath/native/jni/classpath/jcl.c @@ -0,0 +1,274 @@ +/* jcl.c + Copyright (C) 1998, 2005, 2006, 2008 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +/* do not move; needed here because of some macro definitions */ +#include "config.h" + +#include +#include +#include + +#ifndef __GNUC__ + #ifndef __attribute__ + #define __attribute__(x) /* nothing */ + #endif +#endif + +/* + * Cached Pointer class info. + */ +static jclass rawDataClass = NULL; +static jfieldID rawData_fid = NULL; +static jmethodID rawData_mid = NULL; + +/* + * JNI OnLoad constructor. + */ +JNIEXPORT jint JNICALL +JNI_OnLoad (JavaVM *vm, void *reserved __attribute__((unused))) +{ + JNIEnv *env; + void *envp; + + if ((*vm)->GetEnv (vm, &envp, JNI_VERSION_1_4) != JNI_OK) + { + return JNI_VERSION_1_4; + } + env = (JNIEnv *) envp; +#if SIZEOF_VOID_P == 8 + rawDataClass = (*env)->FindClass (env, "gnu/classpath/Pointer64"); + if (rawDataClass != NULL) + rawDataClass = (*env)->NewGlobalRef (env, rawDataClass); + + if (rawDataClass != NULL) + { + rawData_fid = (*env)->GetFieldID (env, rawDataClass, "data", "J"); + rawData_mid = (*env)->GetMethodID (env, rawDataClass, "", "(J)V"); + } +#else +#if SIZEOF_VOID_P == 4 + rawDataClass = (*env)->FindClass (env, "gnu/classpath/Pointer32"); + if (rawDataClass != NULL) + rawDataClass = (*env)->NewGlobalRef (env, rawDataClass); + + if (rawDataClass != NULL) + { + rawData_fid = (*env)->GetFieldID (env, rawDataClass, "data", "I"); + rawData_mid = (*env)->GetMethodID (env, rawDataClass, "", "(I)V"); + } +#else +#error "Pointer size is not supported." +#endif /* SIZEOF_VOID_P == 4 */ +#endif /* SIZEOF_VOID_P == 8 */ + + return JNI_VERSION_1_4; +} + + +JNIEXPORT void JNICALL +JCL_ThrowException (JNIEnv * env, const char *className, const char *errMsg) +{ + jclass excClass; + if ((*env)->ExceptionOccurred (env)) + { + (*env)->ExceptionClear (env); + } + excClass = (*env)->FindClass (env, className); + if (excClass == NULL) + { + jclass errExcClass; + errExcClass = + (*env)->FindClass (env, "java/lang/ClassNotFoundException"); + if (errExcClass == NULL) + { + errExcClass = (*env)->FindClass (env, "java/lang/InternalError"); + if (errExcClass == NULL) + { + fprintf (stderr, "JCL: Utterly failed to throw exeption "); + fprintf (stderr, "%s", className); + fprintf (stderr, " with message "); + fprintf (stderr, "%s", errMsg); + return; + } + } + /* Removed this (more comprehensive) error string to avoid the need for + * a static variable or allocation of a buffer for this message in this + * (unlikely) error case. --Fridi. + * + * sprintf(errstr,"JCL: Failed to throw exception %s with message %s: could not find exception class.", className, errMsg); + */ + (*env)->ThrowNew (env, errExcClass, className); + } + (*env)->ThrowNew (env, excClass, errMsg); +} + +JNIEXPORT void *JNICALL +JCL_malloc (JNIEnv * env, size_t size) +{ + void *mem = malloc (size); + if (mem == NULL) + { + JCL_ThrowException (env, "java/lang/OutOfMemoryError", + "malloc() failed."); + return NULL; + } + return mem; +} + +JNIEXPORT void *JNICALL +JCL_realloc (JNIEnv * env, void *ptr, size_t size) +{ + void *orig_ptr = ptr; + ptr = realloc (ptr, size); + if (ptr == 0) + { + free (orig_ptr); + JCL_ThrowException (env, "java/lang/OutOfMemoryError", + "malloc() failed."); + return NULL; + } + return (ptr); +} + +JNIEXPORT void JNICALL +JCL_free (JNIEnv * env __attribute__ ((unused)), void *p) +{ + if (p != NULL) + { + free (p); + } +} + +JNIEXPORT const char *JNICALL +JCL_jstring_to_cstring (JNIEnv * env, jstring s) +{ + const char *cstr; + if (s == NULL) + { + JCL_ThrowException (env, "java/lang/NullPointerException", + "Null string"); + return NULL; + } + cstr = (const char *) (*env)->GetStringUTFChars (env, s, NULL); + if (cstr == NULL) + { + JCL_ThrowException (env, "java/lang/InternalError", + "GetStringUTFChars() failed."); + return NULL; + } + return cstr; +} + +JNIEXPORT void JNICALL +JCL_free_cstring (JNIEnv * env, jstring s, const char *cstr) +{ + (*env)->ReleaseStringUTFChars (env, s, cstr); +} + +JNIEXPORT jint JNICALL +JCL_MonitorEnter (JNIEnv * env, jobject o) +{ + jint retval = (*env)->MonitorEnter (env, o); + if (retval != 0) + { + JCL_ThrowException (env, "java/lang/InternalError", + "MonitorEnter() failed."); + } + return retval; +} + +JNIEXPORT jint JNICALL +JCL_MonitorExit (JNIEnv * env, jobject o) +{ + jint retval = (*env)->MonitorExit (env, o); + if (retval != 0) + { + JCL_ThrowException (env, "java/lang/InternalError", + "MonitorExit() failed."); + } + return retval; +} + +JNIEXPORT jclass JNICALL +JCL_FindClass (JNIEnv * env, const char *className) +{ + jclass retval = (*env)->FindClass (env, className); + if (retval == NULL) + { + JCL_ThrowException (env, "java/lang/ClassNotFoundException", className); + } + return retval; +} + + +/* + * Build a Pointer object. + */ + +JNIEXPORT jobject JNICALL +JCL_NewRawDataObject (JNIEnv * env, void *data) +{ + if (rawDataClass == NULL || rawData_mid == NULL) + { + JCL_ThrowException (env, "java/lang/InternalError", + "Pointer class was not properly initialized"); + return NULL; + } + +#if SIZEOF_VOID_P == 8 + return (*env)->NewObject (env, rawDataClass, rawData_mid, (jlong) data); +#else + return (*env)->NewObject (env, rawDataClass, rawData_mid, (jint) data); +#endif +} + +JNIEXPORT void * JNICALL +JCL_GetRawData (JNIEnv * env, jobject rawdata) +{ + if (rawData_fid == NULL) + { + JCL_ThrowException (env, "java/lang/InternalError", + "Pointer class was not properly initialized"); + return NULL; + } + +#if SIZEOF_VOID_P == 8 + return (void *) (*env)->GetLongField (env, rawdata, rawData_fid); +#else + return (void *) (*env)->GetIntField (env, rawdata, rawData_fid); +#endif +} diff --git a/libjava/classpath/native/jni/classpath/jcl.h b/libjava/classpath/native/jni/classpath/jcl.h new file mode 100644 index 000000000..d358aeb9c --- /dev/null +++ b/libjava/classpath/native/jni/classpath/jcl.h @@ -0,0 +1,94 @@ +/* jcl.h + Copyright (C) 1998, 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#ifndef __JCL_H__ +#define __JCL_H__ + +#include +#include +#include + +#if SIZEOF_VOID_P == 4 +typedef jint jpointer; +#elif SIZEOF_VOID_P == 8 +typedef jlong jpointer; +#else +#error "Unknown pointer size" +#endif + +/* Helper macros for going between pointers and jlongs. */ +#define JLONG_TO_PTR(T,P) ((T *)(long)P) +#define PTR_TO_JLONG(P) ((jlong)(long)P) + +JNIEXPORT jclass JNICALL JCL_FindClass (JNIEnv * env, const char *className); +JNIEXPORT void JNICALL JCL_ThrowException (JNIEnv * env, + const char *className, + const char *errMsg); +JNIEXPORT void *JNICALL JCL_malloc (JNIEnv * env, size_t size); +JNIEXPORT void *JNICALL JCL_realloc (JNIEnv * env, void *ptr, size_t size); +JNIEXPORT void JNICALL JCL_free (JNIEnv * env, void *p); +JNIEXPORT const char *JNICALL JCL_jstring_to_cstring (JNIEnv * env, + jstring s); +JNIEXPORT void JNICALL JCL_free_cstring (JNIEnv * env, jstring s, + const char *cstr); +JNIEXPORT jint JNICALL JCL_MonitorEnter (JNIEnv * env, jobject o); +JNIEXPORT jint JNICALL JCL_MonitorExit (JNIEnv * env, jobject o); + +JNIEXPORT jobject JNICALL JCL_NewRawDataObject (JNIEnv * env, void *data); +JNIEXPORT void * JNICALL JCL_GetRawData (JNIEnv * env, jobject rawdata); + +#define JCL_RETHROW_EXCEPTION(env) if((*(env))->ExceptionOccurred((env)) != NULL) return NULL; + +/* Simple debug macro */ +#ifdef DEBUG +#define DBG(x) fprintf(stderr, "%s", (x)); +#else +#define DBG(x) +#endif + +/* Some O/S's don't declare 'environ' */ +#if HAVE_CRT_EXTERNS_H +/* Darwin does not have a variable named environ + but has a function which you can get the environ + variable with. */ +#include +#define environ (*_NSGetEnviron()) +#else +extern char **environ; +#endif /* HAVE_CRT_EXTERNS_H */ + +#endif diff --git a/libjava/classpath/native/jni/classpath/jnilink.c b/libjava/classpath/native/jni/classpath/jnilink.c new file mode 100644 index 000000000..15e73a721 --- /dev/null +++ b/libjava/classpath/native/jni/classpath/jnilink.c @@ -0,0 +1,125 @@ +/* JNILINK 1.1: JNI version. + Copyright (C) 1998 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#include +#include +#include + +#include "jnilink.h" + +#define GETCLASS(c) *(jclass*)(c) + +JNIEXPORT jclass JNICALL +LINK_RelinkClass (JNIEnv * env, linkedClass * c, const char *name) +{ + jclass found; + LINK_UnlinkClass (env, *c); + + found = (*env)->FindClass (env, name); + if (found == NULL) + return NULL; + + *c = JCL_malloc (env, sizeof (jclass)); + if (*c == NULL) + return NULL; + + GETCLASS (*c) = (*env)->NewGlobalRef (env, found); + return GETCLASS (*c); +} + +JNIEXPORT jclass JNICALL +LINK_RelinkKnownClass (JNIEnv * env, linkedClass * c, jclass newClass) +{ + LINK_UnlinkClass (env, *c); + + *c = JCL_malloc (env, sizeof (jclass)); + if (*c == NULL) + return NULL; + + GETCLASS (*c) = (*env)->NewGlobalRef (env, newClass); + return newClass; +} + +JNIEXPORT jmethodID JNICALL +LINK_RelinkMethod (JNIEnv * env, jmethodID * m, linkedClass c, + const char *name, const char *sig) +{ + *m = (*env)->GetMethodID (env, GETCLASS (c), name, sig); + return *m; +} + +JNIEXPORT jmethodID JNICALL +LINK_RelinkStaticMethod (JNIEnv * env, jmethodID * m, linkedClass c, + const char *name, const char *sig) +{ + *m = (*env)->GetStaticMethodID (env, GETCLASS (c), name, sig); + return *m; +} + +JNIEXPORT jfieldID JNICALL +LINK_RelinkField (JNIEnv * env, jfieldID * f, linkedClass c, + const char *name, const char *sig) +{ + *f = (*env)->GetFieldID (env, GETCLASS (c), name, sig); + return *f; +} + +JNIEXPORT jfieldID JNICALL +LINK_RelinkStaticField (JNIEnv * env, jfieldID * f, linkedClass c, + const char *name, const char *sig) +{ + *f = (*env)->GetStaticFieldID (env, GETCLASS (c), name, sig); + return *f; +} + + +/* These are for when the class referencing the symbols is unloaded; it +destroys any object references + * the linker might have kept around. + */ +JNIEXPORT void JNICALL +LINK_UnlinkClass (JNIEnv * env, linkedClass * c) +{ + if (*c != NULL) + { + if (GETCLASS (*c) != NULL) + (*env)->DeleteGlobalRef (env, GETCLASS (*c)); + JCL_free (env, *c); + *c = NULL; + } +} diff --git a/libjava/classpath/native/jni/classpath/jnilink.h b/libjava/classpath/native/jni/classpath/jnilink.h new file mode 100644 index 000000000..dd94b3a7a --- /dev/null +++ b/libjava/classpath/native/jni/classpath/jnilink.h @@ -0,0 +1,82 @@ +/* JNILINK 1.1: JNI version. + Copyright (C) 1998 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#ifndef __JNILINK_H__ +#define __JNILINK_H__ + +#include + +typedef void *linkedClass; + +#define LINK_LinkClass(env,c,name) ((c)==NULL ? LINK_ReallyLinkClass((env),&(c),(name)) : (c)) +#define LINK_LinkKnownClass(env,c,newClass) ((c)==NULL ? LINK_ReallyLinkKnownClass((env),&(c),(newClass)) : (c)) +#define LINK_LinkMethod(env,m,c,name,sig) ((m)==NULL ? LINK_RelinkMethod((env),&(m),(c),(name),(sig)) : (m)) +#define LINK_LinkStaticMethod(env,m,c,name,sig) ((m)==NULL ? LINK_RelinkStaticMethod((env),&(m),(c),(name),(sig)) : (m)) +#define LINK_LinkField(env,f,c,name,sig) ((m)==NULL ? LINK_RelinkField((env),&(f),(c),(name),(sig)) : (f)) +#define LINK_LinkStaticField(env,f,c,name,sig) ((m)==NULL ? LINK_RelinkStaticField((env),&(f),(c),(name),(sig)) : (f)) + +#define LINK_LinkConstructor(env,m,c,sig) ((m)==NULL ? LINK_RelinkMethod((env),&(m),(c),"",(sig)) : (m)) + +JNIEXPORT jclass JNICALL +LINK_ReallyLinkClass (JNIEnv * env, linkedClass * c, const char *name); +JNIEXPORT jclass JNICALL +LINK_ReallyLinkKnownClass (JNIEnv * env, linkedClass * c, jclass newClass); +JNIEXPORT jclass JNICALL +LINK_RelinkClass (JNIEnv * env, linkedClass * c, const char *name); +JNIEXPORT jclass JNICALL +LINK_RelinkKnownClass (JNIEnv * env, linkedClass * c, jclass newClass); +JNIEXPORT jmethodID JNICALL +LINK_RelinkMethod (JNIEnv * env, jmethodID * m, linkedClass c, + const char *name, const char *sig); +JNIEXPORT jmethodID JNICALL +LINK_RelinkStaticMethod (JNIEnv * env, jmethodID * m, linkedClass c, + const char *name, const char *sig); +JNIEXPORT jfieldID JNICALL +LINK_RelinkField (JNIEnv * env, jfieldID * f, linkedClass c, + const char *name, const char *sig); +JNIEXPORT jfieldID JNICALL +LINK_RelinkStaticField (JNIEnv * env, jfieldID * f, linkedClass c, + const char *name, const char *sig); + +/* These are for when the class referencing the symbols is unloaded; it +destroys any object references + * the linker might have kept around. + */ +JNIEXPORT void JNICALL LINK_UnlinkClass (JNIEnv * env, linkedClass * c); + +#endif diff --git a/libjava/classpath/native/jni/gconf-peer/.cvsignore b/libjava/classpath/native/jni/gconf-peer/.cvsignore new file mode 100644 index 000000000..799fc9785 --- /dev/null +++ b/libjava/classpath/native/jni/gconf-peer/.cvsignore @@ -0,0 +1,6 @@ +.deps +.libs +*.lo +*.la +Makefile +Makefile.in diff --git a/libjava/classpath/native/jni/gconf-peer/GConfNativePeer.c b/libjava/classpath/native/jni/gconf-peer/GConfNativePeer.c new file mode 100644 index 000000000..3564f9b69 --- /dev/null +++ b/libjava/classpath/native/jni/gconf-peer/GConfNativePeer.c @@ -0,0 +1,617 @@ +/* GConfNativePeer.c -- Implements native methods for class GConfNativePeer + Copyright (C) 2003, 2004 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + +#include +#include + +#include + +#include +#include +#include + +#include "jcl.h" + +#include "gnu_java_util_prefs_gconf_GConfNativePeer.h" + +/* + * Cached id, methods and objects + */ + +/** Reference count */ +static int reference_count = 0; + +/** GConfEngine backend */ +static GConfEngine *engine = NULL; + +/** java.util.ArrayList class */ +static jclass jlist_class = NULL; + +/** java.util.ArrayList constructor id */ +static jmethodID jlist_init_id = NULL; + +/** ava.util.ArrayList add id */ +static jmethodID jlist_add_id = NULL; + +/* ***** PRIVATE FUNCTIONS DELCARATION ***** */ + +/** + * Gets the reference of the default GConfEngine.. + * The client reference should be released with g_object_unref after use. + */ +static void init_gconf (void); + +/** + * Throws a new runtime exception after a failure, with the given message. + */ +static void throw_exception (JNIEnv * env, const char *msg); + +/** + * Throws the given exception after a failure, with the given message. + */ +static void +throw_exception_by_name (JNIEnv * env, const char *name, const char *msg); + +/** + * Return a reference to a java.util.ArrayList class. + */ +static gboolean set_jlist_class (JNIEnv * env); + +/** + * Builds a new reference to a new java.util.ArrayList instace. + * The instance should be freed by the caller after use. + */ +static jclass get_jlist_reference (JNIEnv * env, jclass jlist_class); + +/* ***** END: PRIVATE FUNCTIONS DELCARATION ***** */ + +/* ***** NATIVE FUNCTIONS ***** */ + +/* + * Class: gnu_java_util_prefs_gconf_GConfNativePeer + * Method: init_class + * Signature: ()V + */ +JNIEXPORT void JNICALL +Java_gnu_java_util_prefs_gconf_GConfNativePeer_init_1class + (JNIEnv *env, jclass clazz) +{ + if (reference_count == 0) + { + Java_gnu_java_util_prefs_gconf_GConfNativePeer_init_1id_1cache + (env, clazz); + return; + } + + reference_count++; +} + +/* + * Class: gnu_java_util_prefs_gconf_GConfNativePeer + * Method: init_id_chache + * Signature: ()V + */ +JNIEXPORT void JNICALL +Java_gnu_java_util_prefs_gconf_GConfNativePeer_init_1id_1cache + (JNIEnv *env, jclass clazz __attribute__ ((unused))) +{ + reference_count++; + + init_gconf (); + + /* if engine is null, there is probably an out of memory */ + if (engine == NULL) + { + /* release the string and throw a runtime exception */ + throw_exception (env, + "Unable to initialize GConfEngine in native code\n"); + return; + } + + /* ***** java.util.ArrayList ***** */ + if (set_jlist_class (env) == FALSE) + { + throw_exception (env, + "Unable to get valid reference to java.util.List in native code\n"); + return; + } +} + +/* + * Class: gnu_java_util_prefs_gconf_GConfNativePeer + * Method: gconf_all_keys + * Signature: (Ljava/lang/String;)Ljava/util/List; + */ +JNIEXPORT jobject JNICALL +Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1all_1keys + (JNIEnv *env, jclass clazz __attribute__ ((unused)), jstring node) +{ + /* TODO: check all the calls to gdk_threads_enter/leave */ + + const char *dir = NULL; + const char *_val = NULL; + const char *_val_unescaped = NULL; + + GError *err = NULL; + GSList *entries = NULL; + GSList *tmp; + + /* java.util.ArrayList */ + jobject jlist = NULL; + + dir = JCL_jstring_to_cstring (env, node); + if (dir == NULL) + { + return NULL; + } + + entries = gconf_engine_all_entries (engine, dir, &err); + if (err != NULL) + { + throw_exception_by_name (env, "java/util/prefs/BackingStoreException", + err->message); + g_error_free (err); + err = NULL; + + JCL_free_cstring (env, node, dir); + return NULL; + } + + jlist = get_jlist_reference (env, jlist_class); + if (jlist == NULL) + { + throw_exception_by_name (env, "java/util/prefs/BackingStoreException", + "Unable to get java.util.List reference in native code\n"); + JCL_free_cstring (env, node, dir); + g_slist_foreach (entries, (GFunc) gconf_entry_free, NULL); + g_slist_free (entries); + return NULL; + } + + tmp = entries; + while (tmp != NULL) + { + _val = gconf_entry_get_key (tmp->data); + _val = strrchr (_val, '/'); + ++_val; + + _val_unescaped = gconf_unescape_key (_val, strlen (_val)); + + (*env)->CallBooleanMethod (env, jlist, jlist_add_id, + (*env)->NewStringUTF (env, _val_unescaped)); + + tmp = g_slist_next (tmp); + + g_free ((gpointer) _val_unescaped); + } + + /* clean up things */ + JCL_free_cstring (env, node, dir); + g_slist_foreach (entries, (GFunc) gconf_entry_free, NULL); + g_slist_free (entries); + + return jlist; +} + +/* + * Class: gnu_java_util_prefs_gconf_GConfNativePeer + * Method: gconf_all_nodes + * Signature: (Ljava/lang/String;)Ljava/util/List; + */ +JNIEXPORT jobject JNICALL +Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1all_1nodes + (JNIEnv *env, jclass clazz __attribute__ ((unused)), jstring node) +{ + const char *dir = NULL; + const char *_val = NULL; + const char *_val_unescaped = NULL; + + GError *err = NULL; + GSList *entries = NULL; + GSList *tmp; + + /* java.util.ArrayList */ + jobject jlist = NULL; + + dir = JCL_jstring_to_cstring (env, node); + if (dir == NULL) + { + return NULL; + } + + entries = gconf_engine_all_dirs (engine, dir, &err); + if (err != NULL) + { + throw_exception_by_name (env, "java/util/prefs/BackingStoreException", + err->message); + g_error_free (err); + err = NULL; + JCL_free_cstring (env, node, dir); + return NULL; + } + + jlist = get_jlist_reference (env, jlist_class); + if (jlist == NULL) + { + throw_exception_by_name (env, "java/util/prefs/BackingStoreException", + "Unable to get java.util.List reference in native code\n"); + JCL_free_cstring (env, node, dir); + g_slist_foreach (entries, (GFunc) gconf_entry_free, NULL); + g_slist_free (entries); + return NULL; + } + + tmp = entries; + while (tmp != NULL) + { + _val = tmp->data; + + _val = strrchr (_val, '/'); + ++_val; + + _val_unescaped = gconf_unescape_key (_val, strlen (_val)); + + (*env)->CallBooleanMethod (env, jlist, jlist_add_id, + (*env)->NewStringUTF (env, _val_unescaped)); + + tmp = g_slist_next (tmp); + + g_free ((gpointer) _val_unescaped); + } + + /* clean up things */ + JCL_free_cstring (env, node, dir); + g_slist_foreach (entries, (GFunc) gconf_entry_free, NULL); + g_slist_free (entries); + + return jlist; +} + +/* + * Class: gnu_java_util_prefs_gconf_GConfNativePeer + * Method: gconf_suggest_sync + * Signature: ()V + */ +JNIEXPORT void JNICALL +Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1suggest_1sync + (JNIEnv *env, jclass clazz __attribute__ ((unused))) +{ + GError *err = NULL; + + gconf_engine_suggest_sync (engine, &err); + if (err != NULL) + { + throw_exception_by_name (env, "java/util/prefs/BackingStoreException", + err->message); + g_error_free (err); + err = NULL; + } +} + +/* + * Class: gnu_java_util_prefs_gconf_GConfNativePeer + * Method: gconf_unset + * Signature: (Ljava/lang/String;)Z + */ +JNIEXPORT jboolean JNICALL +Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1unset + (JNIEnv *env, jclass clazz __attribute__ ((unused)), jstring key) +{ + const char *_key = NULL; + gboolean result = JNI_FALSE; + GError *err = NULL; + + _key = JCL_jstring_to_cstring (env, key); + if (_key == NULL) + { + return JNI_FALSE; + } + + result = gconf_engine_unset (engine, _key, &err); + if (err != NULL) + { + result = JNI_FALSE; + g_error_free (err); + err = NULL; + } + + JCL_free_cstring (env, key, _key); + + return result; +} + +/* + * Class: gnu_java_util_prefs_gconf_GConfNativePeer + * Method: gconf_get_string + * Signature: (Ljava/lang/String;)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL +Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1get_1string + (JNIEnv *env, jclass clazz __attribute__ ((unused)), jstring key) +{ + const char *_key = NULL; + const char *_value = NULL; + GError *err = NULL; + jstring result = NULL; + + _key = JCL_jstring_to_cstring (env, key); + if (_key == NULL) + { + return NULL; + } + + _value = gconf_engine_get_string (engine, _key, &err); + JCL_free_cstring (env, key, _key); + if (err != NULL) + { + /* just in case */ + if (_value != NULL) g_free ((gpointer) _value); + g_error_free (err); + err = NULL; + + return NULL; + } + + /* Even if Gconf reported no error it is possible that NULL was returned */ + /* and it should be prevented to create a Java string from that value. */ + if (_value != NULL) + { + result = (*env)->NewStringUTF (env, _value); + g_free ((gpointer) _value); + } + + gconf_engine_suggest_sync (engine, NULL); + + return result; +} + +/* + * Class: gnu_java_util_prefs_gconf_GConfNativePeer + * Method: gconf_set_string + * Signature: (Ljava/lang/String;Ljava/lang/String;)Z + */ +JNIEXPORT jboolean JNICALL +Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1set_1string + (JNIEnv *env, jclass clazz __attribute__ ((unused)), + jstring key, jstring value) +{ + const char *_key = NULL; + const char *_value = NULL; + GError *err = NULL; + + gboolean result = JNI_FALSE; + + /* load an UTF string from the virtual machine. */ + _key = JCL_jstring_to_cstring (env, key); + _value = JCL_jstring_to_cstring (env, value); + if (_key == NULL || _value == NULL) + { + return JNI_FALSE; + } + + result = gconf_engine_set_string (engine, _key, _value, &err); + if (err != NULL) + { + g_error_free (err); + err = NULL; + result = JNI_FALSE; + } + + JCL_free_cstring (env, key, _key); + JCL_free_cstring (env, value, _value); + + return (jboolean) result; +} + +/* + * Class: gnu_java_util_prefs_gconf_GConfNativePeer + * Method: gconf_dir_exists + * Signature: (Ljava/lang/String;)Z + */ +JNIEXPORT jboolean JNICALL +Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1dir_1exists + (JNIEnv *env, jclass clazz __attribute__ ((unused)), jstring node) +{ + const char *dir = NULL; + GError *err = NULL; + jboolean value = JNI_FALSE; + + dir = JCL_jstring_to_cstring (env, node); + if (dir == NULL) + return value; + + /* on error return false */ + value = gconf_engine_dir_exists (engine, dir, &err); + if (err != NULL) + value = JNI_FALSE; + + JCL_free_cstring (env, node, dir); + + return value; +} + +/* + * Class: gnu_java_util_prefs_gconf_GConfNativePeer + * Method: finalize_class + * Signature: ()V + */ +JNIEXPORT void JNICALL +Java_gnu_java_util_prefs_gconf_GConfNativePeer_finalize_1class + (JNIEnv *env, jclass clazz __attribute__ ((unused))) +{ + if (reference_count == 0) + { + /* last reference, free all resources and return */ + g_object_unref (G_OBJECT (engine)); + + (*env)->DeleteGlobalRef (env, jlist_class); + + jlist_class = NULL; + jlist_init_id = NULL; + jlist_add_id = NULL; + + return; + } + + reference_count--; +} + +/* + * Class: gnu_java_util_prefs_gconf_GConfNativePeer + * Method: Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1escape_1key + * Signature: (Ljava/lang/String;)Z + */ +JNIEXPORT jstring JNICALL +Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1escape_1key + (JNIEnv *env, jclass clazz __attribute__ ((unused)), jstring plain) +{ + const char *escaped = NULL; + const char *_plain = NULL; + jstring result = NULL; + + _plain = JCL_jstring_to_cstring (env, plain); + if (_plain == NULL) + { + return NULL; + } + + escaped = gconf_escape_key (_plain, strlen (_plain)); + + JCL_free_cstring (env, plain, _plain); + /* check for NULL, if so prevent string creation */ + if (escaped != NULL) + { + result = (*env)->NewStringUTF (env, escaped); + g_free ((gpointer) escaped); + } + + return result; +} + +/* + * Class: gnu_java_util_prefs_gconf_GConfNativePeer + * Method: Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1unescape_1key + * Signature: (Ljava/lang/String;)Z + */ +JNIEXPORT jstring JNICALL +Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1unescape_1key + (JNIEnv *env, jclass clazz __attribute__ ((unused)), jstring escaped) +{ + const char *plain = NULL; + const char *_escaped = NULL; + jstring result = NULL; + + _escaped = JCL_jstring_to_cstring (env, escaped); + if (_escaped == NULL) + { + return NULL; + } + + plain = gconf_unescape_key (_escaped, strlen (_escaped)); + + JCL_free_cstring (env, escaped, _escaped); + /* check for NULL, if so prevent string creation */ + if (plain != NULL) + { + result = (*env)->NewStringUTF (env, plain); + g_free ((gpointer) plain); + } + + return result; +} + +/* ***** END: NATIVE FUNCTIONS ***** */ + +/* ***** PRIVATE FUNCTIONS IMPLEMENTATION ***** */ + +static void throw_exception (JNIEnv *env, const char *msg) +{ + throw_exception_by_name (env, "java/lang/RuntimeException", msg); +} + +static void +throw_exception_by_name (JNIEnv *env, const char *name, const char *msg) +{ + JCL_ThrowException (env, name, msg); +} + +static void init_gconf (void) +{ + engine = gconf_engine_get_default (); +} + +static gboolean set_jlist_class (JNIEnv *env) +{ + jclass local_jlist_class = NULL; + + /* gets a reference to the ArrayList class */ + local_jlist_class = JCL_FindClass (env, "java/util/ArrayList"); + if (local_jlist_class == NULL) + { + return FALSE; + } + + jlist_class = (*env)->NewGlobalRef (env, local_jlist_class); + (*env)->DeleteLocalRef (env, local_jlist_class); + if (jlist_class == NULL) + { + return FALSE; + } + + /* and initialize it */ + jlist_init_id = (*env)->GetMethodID (env, jlist_class, "", "()V"); + if (jlist_init_id == NULL) + { + return FALSE; + } + + jlist_add_id = (*env)->GetMethodID (env, jlist_class, "add", + "(Ljava/lang/Object;)Z"); + if (jlist_add_id == NULL) + { + return FALSE; + } + + return TRUE; +} + +static jobject get_jlist_reference (JNIEnv *env, jclass jlist_class) +{ + return (*env)->NewObject (env, jlist_class, jlist_init_id); +} + +/* ***** END: PRIVATE FUNCTIONS IMPLEMENTATION ***** */ diff --git a/libjava/classpath/native/jni/gconf-peer/Makefile.am b/libjava/classpath/native/jni/gconf-peer/Makefile.am new file mode 100644 index 000000000..b07076379 --- /dev/null +++ b/libjava/classpath/native/jni/gconf-peer/Makefile.am @@ -0,0 +1,14 @@ +nativeexeclib_LTLIBRARIES = libgconfpeer.la + +libgconfpeer_la_SOURCES = GConfNativePeer.c + +libgconfpeer_la_LIBADD = $(top_builddir)/native/jni/classpath/jcl.lo + +libgconfpeer_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version + +AM_LDFLAGS = @CLASSPATH_MODULE@ @GCONF_LIBS@ @GDK_LIBS@ + +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ + +AM_CFLAGS = @WARNING_CFLAGS@ @ERROR_CFLAGS@ @GCONF_CFLAGS@ @GDK_CFLAGS@ \ + @EXTRA_CFLAGS@ diff --git a/libjava/classpath/native/jni/gconf-peer/Makefile.in b/libjava/classpath/native/jni/gconf-peer/Makefile.in new file mode 100644 index 000000000..691afd7d2 --- /dev/null +++ b/libjava/classpath/native/jni/gconf-peer/Makefile.in @@ -0,0 +1,612 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +subdir = native/jni/gconf-peer +DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/../../config/depstand.m4 \ + $(top_srcdir)/../../config/lead-dot.m4 \ + $(top_srcdir)/../../config/lib-ld.m4 \ + $(top_srcdir)/../../config/lib-link.m4 \ + $(top_srcdir)/../../config/lib-prefix.m4 \ + $(top_srcdir)/../../config/multi.m4 \ + $(top_srcdir)/../../config/no-executables.m4 \ + $(top_srcdir)/../../config/override.m4 \ + $(top_srcdir)/../../libtool.m4 \ + $(top_srcdir)/../../ltoptions.m4 \ + $(top_srcdir)/../../ltsugar.m4 \ + $(top_srcdir)/../../ltversion.m4 \ + $(top_srcdir)/../../lt~obsolete.m4 \ + $(top_srcdir)/m4/ac_prog_antlr.m4 \ + $(top_srcdir)/m4/ac_prog_java.m4 \ + $(top_srcdir)/m4/ac_prog_java_works.m4 \ + $(top_srcdir)/m4/ac_prog_javac.m4 \ + $(top_srcdir)/m4/ac_prog_javac_works.m4 \ + $(top_srcdir)/m4/acattribute.m4 $(top_srcdir)/m4/accross.m4 \ + $(top_srcdir)/m4/acinclude.m4 \ + $(top_srcdir)/m4/ax_create_stdint_h.m4 \ + $(top_srcdir)/m4/ax_func_which_gethostbyname_r.m4 \ + $(top_srcdir)/m4/gcc_attribute.m4 $(top_srcdir)/m4/iconv.m4 \ + $(top_srcdir)/m4/pkg.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/../../mkinstalldirs +CONFIG_HEADER = $(top_builddir)/include/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__installdirs = "$(DESTDIR)$(nativeexeclibdir)" +LTLIBRARIES = $(nativeexeclib_LTLIBRARIES) +libgconfpeer_la_DEPENDENCIES = \ + $(top_builddir)/native/jni/classpath/jcl.lo +am_libgconfpeer_la_OBJECTS = GConfNativePeer.lo +libgconfpeer_la_OBJECTS = $(am_libgconfpeer_la_OBJECTS) +libgconfpeer_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(libgconfpeer_la_LDFLAGS) $(LDFLAGS) -o $@ +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/include +depcomp = $(SHELL) $(top_srcdir)/../../depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(libgconfpeer_la_SOURCES) +ETAGS = etags +CTAGS = ctags +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +ANTLR = @ANTLR@ +ANTLR_JAR = @ANTLR_JAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CAIRO_CFLAGS = @CAIRO_CFLAGS@ +CAIRO_LIBS = @CAIRO_LIBS@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CLASSPATH_CONVENIENCE = @CLASSPATH_CONVENIENCE@ +CLASSPATH_INCLUDES = @CLASSPATH_INCLUDES@ +CLASSPATH_MODULE = @CLASSPATH_MODULE@ +COLLECTIONS_PREFIX = @COLLECTIONS_PREFIX@ +CP = @CP@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DATE = @DATE@ +DEFAULT_PREFS_PEER = @DEFAULT_PREFS_PEER@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +ECJ_JAR = @ECJ_JAR@ +EGREP = @EGREP@ +ERROR_CFLAGS = @ERROR_CFLAGS@ +EXAMPLESDIR = @EXAMPLESDIR@ +EXEEXT = @EXEEXT@ +EXTRA_CFLAGS = @EXTRA_CFLAGS@ +FGREP = @FGREP@ +FIND = @FIND@ +FREETYPE2_CFLAGS = @FREETYPE2_CFLAGS@ +FREETYPE2_LIBS = @FREETYPE2_LIBS@ +GCONF_CFLAGS = @GCONF_CFLAGS@ +GCONF_LIBS = @GCONF_LIBS@ +GDK_CFLAGS = @GDK_CFLAGS@ +GDK_LIBS = @GDK_LIBS@ +GJDOC = @GJDOC@ +GLIB_CFLAGS = @GLIB_CFLAGS@ +GLIB_LIBS = @GLIB_LIBS@ +GMP_CFLAGS = @GMP_CFLAGS@ +GMP_LIBS = @GMP_LIBS@ +GREP = @GREP@ +GSTREAMER_BASE_CFLAGS = @GSTREAMER_BASE_CFLAGS@ +GSTREAMER_BASE_LIBS = @GSTREAMER_BASE_LIBS@ +GSTREAMER_CFLAGS = @GSTREAMER_CFLAGS@ +GSTREAMER_FILE_READER = @GSTREAMER_FILE_READER@ +GSTREAMER_LIBS = @GSTREAMER_LIBS@ +GSTREAMER_MIXER_PROVIDER = @GSTREAMER_MIXER_PROVIDER@ +GSTREAMER_PLUGINS_BASE_CFLAGS = @GSTREAMER_PLUGINS_BASE_CFLAGS@ +GSTREAMER_PLUGINS_BASE_LIBS = @GSTREAMER_PLUGINS_BASE_LIBS@ +GST_PLUGIN_LDFLAGS = @GST_PLUGIN_LDFLAGS@ +GTK_CFLAGS = @GTK_CFLAGS@ +GTK_LIBS = @GTK_LIBS@ +INIT_LOAD_LIBRARY = @INIT_LOAD_LIBRARY@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAR = @JAR@ +JAVA = @JAVA@ +JAVAC = @JAVAC@ +JAVAC_IS_GCJ = @JAVAC_IS_GCJ@ +JAVAC_MEM_OPT = @JAVAC_MEM_OPT@ +JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION = @JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION@ +JAY = @JAY@ +JAY_SKELETON = @JAY_SKELETON@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBDEBUG = @LIBDEBUG@ +LIBICONV = @LIBICONV@ +LIBMAGIC = @LIBMAGIC@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBVERSION = @LIBVERSION@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBICONV = @LTLIBICONV@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MKDIR = @MKDIR@ +MKDIR_P = @MKDIR_P@ +MOC = @MOC@ +MOZILLA_CFLAGS = @MOZILLA_CFLAGS@ +MOZILLA_LIBS = @MOZILLA_LIBS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PANGOFT2_CFLAGS = @PANGOFT2_CFLAGS@ +PANGOFT2_LIBS = @PANGOFT2_LIBS@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PATH_TO_ESCHER = @PATH_TO_ESCHER@ +PATH_TO_GLIBJ_ZIP = @PATH_TO_GLIBJ_ZIP@ +PERL = @PERL@ +PKG_CONFIG = @PKG_CONFIG@ +PLUGIN_DIR = @PLUGIN_DIR@ +QT_CFLAGS = @QT_CFLAGS@ +QT_LIBS = @QT_LIBS@ +RANLIB = @RANLIB@ +REMOVE = @REMOVE@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRICT_WARNING_CFLAGS = @STRICT_WARNING_CFLAGS@ +STRIP = @STRIP@ +TOOLSDIR = @TOOLSDIR@ +USER_JAVAH = @USER_JAVAH@ +VERSION = @VERSION@ +WANT_NATIVE_BIG_INTEGER = @WANT_NATIVE_BIG_INTEGER@ +WARNING_CFLAGS = @WARNING_CFLAGS@ +XMKMF = @XMKMF@ +XML_CFLAGS = @XML_CFLAGS@ +XML_LIBS = @XML_LIBS@ +XSLT_CFLAGS = @XSLT_CFLAGS@ +XSLT_LIBS = @XSLT_LIBS@ +XTEST_LIBS = @XTEST_LIBS@ +X_CFLAGS = @X_CFLAGS@ +X_EXTRA_LIBS = @X_EXTRA_LIBS@ +X_LIBS = @X_LIBS@ +X_PRE_LIBS = @X_PRE_LIBS@ +ZIP = @ZIP@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_ANTLR = @ac_ct_ANTLR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +default_toolkit = @default_toolkit@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +glibjdir = @glibjdir@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +multi_basedir = @multi_basedir@ +nativeexeclibdir = @nativeexeclibdir@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +toolexeclibdir = @toolexeclibdir@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +uudecode = @uudecode@ +vm_classes = @vm_classes@ +nativeexeclib_LTLIBRARIES = libgconfpeer.la +libgconfpeer_la_SOURCES = GConfNativePeer.c +libgconfpeer_la_LIBADD = $(top_builddir)/native/jni/classpath/jcl.lo +libgconfpeer_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version +AM_LDFLAGS = @CLASSPATH_MODULE@ @GCONF_LIBS@ @GDK_LIBS@ +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ +AM_CFLAGS = @WARNING_CFLAGS@ @ERROR_CFLAGS@ @GCONF_CFLAGS@ @GDK_CFLAGS@ \ + @EXTRA_CFLAGS@ + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu native/jni/gconf-peer/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu native/jni/gconf-peer/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-nativeexeclibLTLIBRARIES: $(nativeexeclib_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(nativeexeclibdir)" || $(MKDIR_P) "$(DESTDIR)$(nativeexeclibdir)" + @list='$(nativeexeclib_LTLIBRARIES)'; test -n "$(nativeexeclibdir)" || list=; \ + list2=; for p in $$list; do \ + if test -f $$p; then \ + list2="$$list2 $$p"; \ + else :; fi; \ + done; \ + test -z "$$list2" || { \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(nativeexeclibdir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(nativeexeclibdir)"; \ + } + +uninstall-nativeexeclibLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(nativeexeclib_LTLIBRARIES)'; test -n "$(nativeexeclibdir)" || list=; \ + for p in $$list; do \ + $(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(nativeexeclibdir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(nativeexeclibdir)/$$f"; \ + done + +clean-nativeexeclibLTLIBRARIES: + -test -z "$(nativeexeclib_LTLIBRARIES)" || rm -f $(nativeexeclib_LTLIBRARIES) + @list='$(nativeexeclib_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libgconfpeer.la: $(libgconfpeer_la_OBJECTS) $(libgconfpeer_la_DEPENDENCIES) + $(libgconfpeer_la_LINK) -rpath $(nativeexeclibdir) $(libgconfpeer_la_OBJECTS) $(libgconfpeer_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/GConfNativePeer.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) +installdirs: + for dir in "$(DESTDIR)$(nativeexeclibdir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-nativeexeclibLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-nativeexeclibLTLIBRARIES + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-nativeexeclibLTLIBRARIES + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-nativeexeclibLTLIBRARIES ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags dvi dvi-am html html-am info info-am install \ + install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-nativeexeclibLTLIBRARIES install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-nativeexeclibLTLIBRARIES + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/libjava/classpath/native/jni/gstreamer-peer/Makefile.am b/libjava/classpath/native/jni/gstreamer-peer/Makefile.am new file mode 100644 index 000000000..d15f0a2ad --- /dev/null +++ b/libjava/classpath/native/jni/gstreamer-peer/Makefile.am @@ -0,0 +1,29 @@ +nativeexeclib_LTLIBRARIES = libgstreamerpeer.la + +libgstreamerpeer_la_SOURCES = gst_peer.c \ + gstreamer_io_peer.c \ + gst_native_data_line.c \ + gst_input_stream.c \ + gst_native_pipeline.c \ + gst_classpath_src.c \ + gst_peer.h \ + gst_classpath_src.h \ + gst_input_stream.h \ + gst_native_pipeline.h + +libgstreamerpeer_la_LIBADD = $(top_builddir)/native/jni/classpath/jcl.lo + +libgstreamerpeer_la_LDFLAGS = $(AM_LDFLAGS) @GST_PLUGIN_LDFLAGS@ -avoid-version + +AM_LDFLAGS = @CLASSPATH_MODULE@ @GSTREAMER_LIBS@ @GSTREAMER_BASE_LIBS@ \ + @GSTREAMER_PLUGINS_BASE_LIBS@ @GDK_LIBS@ + +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ + +# We cannot use -Wwrite-strings and the strict flags since +# gstreamer contain broken prototypes (by design). +AM_CFLAGS = @WARNING_CFLAGS@ -Wno-write-strings \ + -Wno-missing-field-initializers \ + @ERROR_CFLAGS@ -Wno-unused-parameter @GSTREAMER_BASE_CFLAGS@ \ + @GDK_CFLAGS@ @GSTREAMER_CFLAGS@ @GSTREAMER_PLUGINS_BASE_CFLAGS@ \ + @EXTRA_CFLAGS@ diff --git a/libjava/classpath/native/jni/gstreamer-peer/Makefile.in b/libjava/classpath/native/jni/gstreamer-peer/Makefile.in new file mode 100644 index 000000000..4985ff631 --- /dev/null +++ b/libjava/classpath/native/jni/gstreamer-peer/Makefile.in @@ -0,0 +1,637 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +subdir = native/jni/gstreamer-peer +DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/../../config/depstand.m4 \ + $(top_srcdir)/../../config/lead-dot.m4 \ + $(top_srcdir)/../../config/lib-ld.m4 \ + $(top_srcdir)/../../config/lib-link.m4 \ + $(top_srcdir)/../../config/lib-prefix.m4 \ + $(top_srcdir)/../../config/multi.m4 \ + $(top_srcdir)/../../config/no-executables.m4 \ + $(top_srcdir)/../../config/override.m4 \ + $(top_srcdir)/../../libtool.m4 \ + $(top_srcdir)/../../ltoptions.m4 \ + $(top_srcdir)/../../ltsugar.m4 \ + $(top_srcdir)/../../ltversion.m4 \ + $(top_srcdir)/../../lt~obsolete.m4 \ + $(top_srcdir)/m4/ac_prog_antlr.m4 \ + $(top_srcdir)/m4/ac_prog_java.m4 \ + $(top_srcdir)/m4/ac_prog_java_works.m4 \ + $(top_srcdir)/m4/ac_prog_javac.m4 \ + $(top_srcdir)/m4/ac_prog_javac_works.m4 \ + $(top_srcdir)/m4/acattribute.m4 $(top_srcdir)/m4/accross.m4 \ + $(top_srcdir)/m4/acinclude.m4 \ + $(top_srcdir)/m4/ax_create_stdint_h.m4 \ + $(top_srcdir)/m4/ax_func_which_gethostbyname_r.m4 \ + $(top_srcdir)/m4/gcc_attribute.m4 $(top_srcdir)/m4/iconv.m4 \ + $(top_srcdir)/m4/pkg.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/../../mkinstalldirs +CONFIG_HEADER = $(top_builddir)/include/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__installdirs = "$(DESTDIR)$(nativeexeclibdir)" +LTLIBRARIES = $(nativeexeclib_LTLIBRARIES) +libgstreamerpeer_la_DEPENDENCIES = \ + $(top_builddir)/native/jni/classpath/jcl.lo +am_libgstreamerpeer_la_OBJECTS = gst_peer.lo gstreamer_io_peer.lo \ + gst_native_data_line.lo gst_input_stream.lo \ + gst_native_pipeline.lo gst_classpath_src.lo +libgstreamerpeer_la_OBJECTS = $(am_libgstreamerpeer_la_OBJECTS) +libgstreamerpeer_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(libgstreamerpeer_la_LDFLAGS) $(LDFLAGS) -o $@ +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/include +depcomp = $(SHELL) $(top_srcdir)/../../depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(libgstreamerpeer_la_SOURCES) +ETAGS = etags +CTAGS = ctags +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +ANTLR = @ANTLR@ +ANTLR_JAR = @ANTLR_JAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CAIRO_CFLAGS = @CAIRO_CFLAGS@ +CAIRO_LIBS = @CAIRO_LIBS@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CLASSPATH_CONVENIENCE = @CLASSPATH_CONVENIENCE@ +CLASSPATH_INCLUDES = @CLASSPATH_INCLUDES@ +CLASSPATH_MODULE = @CLASSPATH_MODULE@ +COLLECTIONS_PREFIX = @COLLECTIONS_PREFIX@ +CP = @CP@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DATE = @DATE@ +DEFAULT_PREFS_PEER = @DEFAULT_PREFS_PEER@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +ECJ_JAR = @ECJ_JAR@ +EGREP = @EGREP@ +ERROR_CFLAGS = @ERROR_CFLAGS@ +EXAMPLESDIR = @EXAMPLESDIR@ +EXEEXT = @EXEEXT@ +EXTRA_CFLAGS = @EXTRA_CFLAGS@ +FGREP = @FGREP@ +FIND = @FIND@ +FREETYPE2_CFLAGS = @FREETYPE2_CFLAGS@ +FREETYPE2_LIBS = @FREETYPE2_LIBS@ +GCONF_CFLAGS = @GCONF_CFLAGS@ +GCONF_LIBS = @GCONF_LIBS@ +GDK_CFLAGS = @GDK_CFLAGS@ +GDK_LIBS = @GDK_LIBS@ +GJDOC = @GJDOC@ +GLIB_CFLAGS = @GLIB_CFLAGS@ +GLIB_LIBS = @GLIB_LIBS@ +GMP_CFLAGS = @GMP_CFLAGS@ +GMP_LIBS = @GMP_LIBS@ +GREP = @GREP@ +GSTREAMER_BASE_CFLAGS = @GSTREAMER_BASE_CFLAGS@ +GSTREAMER_BASE_LIBS = @GSTREAMER_BASE_LIBS@ +GSTREAMER_CFLAGS = @GSTREAMER_CFLAGS@ +GSTREAMER_FILE_READER = @GSTREAMER_FILE_READER@ +GSTREAMER_LIBS = @GSTREAMER_LIBS@ +GSTREAMER_MIXER_PROVIDER = @GSTREAMER_MIXER_PROVIDER@ +GSTREAMER_PLUGINS_BASE_CFLAGS = @GSTREAMER_PLUGINS_BASE_CFLAGS@ +GSTREAMER_PLUGINS_BASE_LIBS = @GSTREAMER_PLUGINS_BASE_LIBS@ +GST_PLUGIN_LDFLAGS = @GST_PLUGIN_LDFLAGS@ +GTK_CFLAGS = @GTK_CFLAGS@ +GTK_LIBS = @GTK_LIBS@ +INIT_LOAD_LIBRARY = @INIT_LOAD_LIBRARY@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAR = @JAR@ +JAVA = @JAVA@ +JAVAC = @JAVAC@ +JAVAC_IS_GCJ = @JAVAC_IS_GCJ@ +JAVAC_MEM_OPT = @JAVAC_MEM_OPT@ +JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION = @JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION@ +JAY = @JAY@ +JAY_SKELETON = @JAY_SKELETON@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBDEBUG = @LIBDEBUG@ +LIBICONV = @LIBICONV@ +LIBMAGIC = @LIBMAGIC@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBVERSION = @LIBVERSION@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBICONV = @LTLIBICONV@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MKDIR = @MKDIR@ +MKDIR_P = @MKDIR_P@ +MOC = @MOC@ +MOZILLA_CFLAGS = @MOZILLA_CFLAGS@ +MOZILLA_LIBS = @MOZILLA_LIBS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PANGOFT2_CFLAGS = @PANGOFT2_CFLAGS@ +PANGOFT2_LIBS = @PANGOFT2_LIBS@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PATH_TO_ESCHER = @PATH_TO_ESCHER@ +PATH_TO_GLIBJ_ZIP = @PATH_TO_GLIBJ_ZIP@ +PERL = @PERL@ +PKG_CONFIG = @PKG_CONFIG@ +PLUGIN_DIR = @PLUGIN_DIR@ +QT_CFLAGS = @QT_CFLAGS@ +QT_LIBS = @QT_LIBS@ +RANLIB = @RANLIB@ +REMOVE = @REMOVE@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRICT_WARNING_CFLAGS = @STRICT_WARNING_CFLAGS@ +STRIP = @STRIP@ +TOOLSDIR = @TOOLSDIR@ +USER_JAVAH = @USER_JAVAH@ +VERSION = @VERSION@ +WANT_NATIVE_BIG_INTEGER = @WANT_NATIVE_BIG_INTEGER@ +WARNING_CFLAGS = @WARNING_CFLAGS@ +XMKMF = @XMKMF@ +XML_CFLAGS = @XML_CFLAGS@ +XML_LIBS = @XML_LIBS@ +XSLT_CFLAGS = @XSLT_CFLAGS@ +XSLT_LIBS = @XSLT_LIBS@ +XTEST_LIBS = @XTEST_LIBS@ +X_CFLAGS = @X_CFLAGS@ +X_EXTRA_LIBS = @X_EXTRA_LIBS@ +X_LIBS = @X_LIBS@ +X_PRE_LIBS = @X_PRE_LIBS@ +ZIP = @ZIP@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_ANTLR = @ac_ct_ANTLR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +default_toolkit = @default_toolkit@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +glibjdir = @glibjdir@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +multi_basedir = @multi_basedir@ +nativeexeclibdir = @nativeexeclibdir@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +toolexeclibdir = @toolexeclibdir@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +uudecode = @uudecode@ +vm_classes = @vm_classes@ +nativeexeclib_LTLIBRARIES = libgstreamerpeer.la +libgstreamerpeer_la_SOURCES = gst_peer.c \ + gstreamer_io_peer.c \ + gst_native_data_line.c \ + gst_input_stream.c \ + gst_native_pipeline.c \ + gst_classpath_src.c \ + gst_peer.h \ + gst_classpath_src.h \ + gst_input_stream.h \ + gst_native_pipeline.h + +libgstreamerpeer_la_LIBADD = $(top_builddir)/native/jni/classpath/jcl.lo +libgstreamerpeer_la_LDFLAGS = $(AM_LDFLAGS) @GST_PLUGIN_LDFLAGS@ -avoid-version +AM_LDFLAGS = @CLASSPATH_MODULE@ @GSTREAMER_LIBS@ @GSTREAMER_BASE_LIBS@ \ + @GSTREAMER_PLUGINS_BASE_LIBS@ @GDK_LIBS@ + +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ + +# We cannot use -Wwrite-strings and the strict flags since +# gstreamer contain broken prototypes (by design). +AM_CFLAGS = @WARNING_CFLAGS@ -Wno-write-strings \ + -Wno-missing-field-initializers \ + @ERROR_CFLAGS@ -Wno-unused-parameter @GSTREAMER_BASE_CFLAGS@ \ + @GDK_CFLAGS@ @GSTREAMER_CFLAGS@ @GSTREAMER_PLUGINS_BASE_CFLAGS@ \ + @EXTRA_CFLAGS@ + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu native/jni/gstreamer-peer/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu native/jni/gstreamer-peer/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-nativeexeclibLTLIBRARIES: $(nativeexeclib_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(nativeexeclibdir)" || $(MKDIR_P) "$(DESTDIR)$(nativeexeclibdir)" + @list='$(nativeexeclib_LTLIBRARIES)'; test -n "$(nativeexeclibdir)" || list=; \ + list2=; for p in $$list; do \ + if test -f $$p; then \ + list2="$$list2 $$p"; \ + else :; fi; \ + done; \ + test -z "$$list2" || { \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(nativeexeclibdir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(nativeexeclibdir)"; \ + } + +uninstall-nativeexeclibLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(nativeexeclib_LTLIBRARIES)'; test -n "$(nativeexeclibdir)" || list=; \ + for p in $$list; do \ + $(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(nativeexeclibdir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(nativeexeclibdir)/$$f"; \ + done + +clean-nativeexeclibLTLIBRARIES: + -test -z "$(nativeexeclib_LTLIBRARIES)" || rm -f $(nativeexeclib_LTLIBRARIES) + @list='$(nativeexeclib_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libgstreamerpeer.la: $(libgstreamerpeer_la_OBJECTS) $(libgstreamerpeer_la_DEPENDENCIES) + $(libgstreamerpeer_la_LINK) -rpath $(nativeexeclibdir) $(libgstreamerpeer_la_OBJECTS) $(libgstreamerpeer_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gst_classpath_src.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gst_input_stream.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gst_native_data_line.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gst_native_pipeline.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gst_peer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gstreamer_io_peer.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) +installdirs: + for dir in "$(DESTDIR)$(nativeexeclibdir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-nativeexeclibLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-nativeexeclibLTLIBRARIES + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-nativeexeclibLTLIBRARIES + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-nativeexeclibLTLIBRARIES ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags dvi dvi-am html html-am info info-am install \ + install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-nativeexeclibLTLIBRARIES install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-nativeexeclibLTLIBRARIES + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/libjava/classpath/native/jni/gstreamer-peer/gst_classpath_src.c b/libjava/classpath/native/jni/gstreamer-peer/gst_classpath_src.c new file mode 100644 index 000000000..80c679592 --- /dev/null +++ b/libjava/classpath/native/jni/gstreamer-peer/gst_classpath_src.c @@ -0,0 +1,408 @@ +/*gstclasspathsrc.c - Class file for the GstClasspathPlugin + Copyright (C) 2007 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +/* + * We don't really use version numbering here, we give it the same version + * number of classpath, so that gstreamer is happy. + * TODO: Maybe this should be moved in config.h instead? + */ +#define CLASSPATH_GST_PLUGIN_VERSION PACKAGE_VERSION + +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include + +#include "gst_classpath_src.h" +#include "gst_input_stream.h" + +GST_DEBUG_CATEGORY_STATIC (gst_classpath_src_debug); +#define GST_CAT_DEFAULT gst_classpath_src_debug + +enum +{ + ARG_0, + ARG_INPUTSTREAM +}; + +struct _GstClasspathSrcPrivate +{ + GstInputStream *istream; + GstCaps *caps; +}; + +static const GstElementDetails gst_classpath_src_details = +GST_ELEMENT_DETAILS ("ClasspathSrc", + "Source/Network", + "Read from a java input stream", + "Mario Torre "); + +static GstStaticPadTemplate _template = +GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS_ANY); + +/* ***** plugin init ***** */ + +static void +_do_init (GType filesrc_type __attribute__ ((unused))) +{ + GST_DEBUG_CATEGORY_INIT (gst_classpath_src_debug, "classpathsrc", + 0, "classpathsrc"); +} + +GST_BOILERPLATE_FULL (GstClasspathSrc, gst_classpath_src, GstPushSrc, + GST_TYPE_PUSH_SRC, _do_init); + +static gboolean +plugin_init (GstPlugin *plugin) +{ + return gst_element_register (plugin, "classpathsrc", + GST_RANK_NONE, GST_TYPE_CLASSPATH_SRC); +} + +GST_PLUGIN_DEFINE_STATIC (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "classpathsrc", + "Java InputStream Reader", + plugin_init, CLASSPATH_GST_PLUGIN_VERSION, + GST_LICENSE_UNKNOWN, /* GPL + Exception */ + "Classpath", "http://www.classpath.org/") + +/* ***** public class methods ***** */ + +static void gst_classpath_src_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec); + +static void gst_classpath_src_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec); + +static void gst_classpath_src_finalize (GObject *object); + +static GstCaps *gst_classpath_src_getcaps (GstBaseSrc *basesrc); + +static gboolean gst_classpath_src_start (GstBaseSrc *basesrc); + +static gboolean gst_classpath_src_stop (GstBaseSrc *basesrc); + +static GstFlowReturn gst_classpath_src_create (GstPushSrc *src, + GstBuffer **buffer); + +static GstFlowReturn +gst_classpath_src_create_stream (GstClasspathSrc *src, GstBuffer **buffer); + +static GstFlowReturn +check_read (GstClasspathSrc *src, int read, int buffer_size, + GstBuffer **buffer); + +/* ***** public class methods: end ***** */ + +static void +gst_classpath_src_base_init (gpointer gclass) +{ + GstElementClass *gstelement_class = GST_ELEMENT_CLASS (gclass); + + gst_element_class_add_pad_template (gstelement_class, + gst_static_pad_template_get (&_template)); + + gst_element_class_set_details (gstelement_class, &gst_classpath_src_details); +} + +static void +gst_classpath_src_class_init (GstClasspathSrcClass *klass) +{ + GObjectClass *gobject_class; + GstElementClass *gstelement_class; + GstBaseSrcClass *gstbasesrc_class; + GstPushSrcClass *gstpushsrc_class; + + GParamSpec *pspec; + + gobject_class = G_OBJECT_CLASS (klass); + gstelement_class = GST_ELEMENT_CLASS (klass); + gstbasesrc_class = GST_BASE_SRC_CLASS (klass); + gstpushsrc_class = GST_PUSH_SRC_CLASS (klass); + + g_type_class_add_private (klass, sizeof (GstClasspathSrcPrivate)); + + /* getter and setters */ + + gobject_class->set_property = gst_classpath_src_set_property; + gobject_class->get_property = gst_classpath_src_get_property; + + /* register properties */ + pspec = g_param_spec_pointer (GST_CLASSPATH_SRC_ISTREAM, + "GstInputStream instance", + "GstInputStream instance", + G_PARAM_READWRITE); + g_object_class_install_property (gobject_class, ARG_INPUTSTREAM, pspec); + + /* register callbacks */ + gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_classpath_src_finalize); + + gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_classpath_src_getcaps); + gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_classpath_src_start); + gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_classpath_src_stop); + + gstpushsrc_class->create = GST_DEBUG_FUNCPTR (gst_classpath_src_create); +} + +/* ***** */ + +static void +gst_classpath_src_init (GstClasspathSrc *src, + GstClasspathSrcClass * g_class __attribute__ ((unused))) +{ + src->priv = G_TYPE_INSTANCE_GET_PRIVATE (src, GST_TYPE_CLASSPATH_SRC, + GstClasspathSrcPrivate); + + src->priv->istream = NULL; + src->priv->caps = NULL; +} + +static void +gst_classpath_src_finalize (GObject *object) +{ + G_OBJECT_CLASS (parent_class)->finalize (object); +} + +/* ************************************************************************** */ + +static void +gst_classpath_src_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + GstClasspathSrc *src; + + g_return_if_fail (GST_IS_CLASSPATH_SRC (object)); + + src = GST_CLASSPATH_SRC (object); + + GST_OBJECT_LOCK (src); + switch (prop_id) + { + case ARG_INPUTSTREAM: + { + GST_STATE_LOCK (src); + { + GstState state; + state = GST_STATE (src); + + if (state != GST_STATE_READY && state != GST_STATE_NULL) + { + GST_DEBUG_OBJECT (src, "setting reader in wrong state"); + GST_STATE_UNLOCK (src); + break; + } + } + GST_STATE_UNLOCK (src); + + /* FIXME: check if this is a valid instance of GstInputStream */ + src->priv->istream = g_value_get_pointer (value); + } + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } + GST_OBJECT_UNLOCK (src); +} + +static void +gst_classpath_src_get_property (GObject *object, + guint prop_id __attribute__ ((unused)), + GValue *value __attribute__ ((unused)), + GParamSpec *pspec __attribute__ ((unused))) +{ + /* TODO */ +} + +/* ************************************************************************** */ + +static GstCaps *gst_classpath_src_getcaps (GstBaseSrc *basesrc) +{ + GstClasspathSrc *src; + GstCaps *caps = NULL; + + src = GST_CLASSPATH_SRC (basesrc); + + if (src->priv->caps) + caps = gst_caps_copy (src->priv->caps); + else + caps = gst_caps_new_any (); + + GST_DEBUG_OBJECT (src, "returning caps %" GST_PTR_FORMAT, caps); + g_assert (GST_IS_CAPS (caps)); + + return caps; +} + +static GstFlowReturn +gst_classpath_src_create_stream (GstClasspathSrc *src, GstBuffer **buffer) +{ + int buffer_size = 2048; + int read = -1; + + buffer_size = gst_input_stream_available (src->priv->istream); + if (buffer_size < 0) + return GST_FLOW_ERROR; + else if (buffer_size == 0) + return GST_FLOW_WRONG_STATE; + + *buffer = gst_buffer_new_and_alloc (buffer_size); + if (*buffer == NULL) + { + return GST_FLOW_ERROR; + } + + read = gst_input_stream_read (src->priv->istream, + (int *) GST_BUFFER_DATA (*buffer), + 0, + buffer_size); + + return check_read (src, read, buffer_size, buffer); +} + +GstFlowReturn +check_read (GstClasspathSrc *src, int read, int buffer_size, GstBuffer **buffer) +{ + if (G_UNLIKELY (read < 0)) + { + g_warning("GST_FLOW_UNEXPECTED (read < 0)"); + + gst_buffer_unref (*buffer); + *buffer = NULL; + + return GST_FLOW_ERROR; + } + else if (G_UNLIKELY (read == 0)) + { + g_warning("GST_FLOW_WRONG_STATE (read == 0)"); + + gst_buffer_unref (*buffer); + *buffer = NULL; + + return GST_FLOW_WRONG_STATE; + } + else if (G_UNLIKELY (read < buffer_size)) + { + g_warning("shorter read"); + gst_buffer_unref (*buffer); + *buffer = NULL; + + return GST_FLOW_ERROR; + } + + GST_BUFFER_SIZE (*buffer) = read; + gst_buffer_set_caps (*buffer, src->priv->caps); + + return GST_FLOW_OK; +} + +static GstFlowReturn +gst_classpath_src_create (GstPushSrc *basesrc, GstBuffer **buffer) +{ + GstClasspathSrc *src = NULL; + GstFlowReturn ret = GST_FLOW_OK; + + src = GST_CLASSPATH_SRC (basesrc); + + /* create the buffer */ + ret = gst_classpath_src_create_stream (src, buffer); + + return ret; +} + +static gboolean +gst_classpath_src_start (GstBaseSrc *basesrc) +{ + GstClasspathSrc *src; + + src = GST_CLASSPATH_SRC (basesrc); + + if (src->priv->istream == NULL) + { + g_warning("GstInputStream is still null. You need to " \ + "pass a valid InputStream object"); + + GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL), + ("GstInputStream is still null. You need to " \ + "pass a valid InputStream")); + return FALSE; + } + + return TRUE; +} + +static gboolean +gst_classpath_src_stop (GstBaseSrc *basesrc) +{ + GstClasspathSrc *src; + + src = GST_CLASSPATH_SRC (basesrc); + + /* clean the stream */ + if (src->priv->istream != NULL) + gst_input_stream_clean (src->priv->istream); + + if (src->priv->caps) { + gst_caps_unref (src->priv->caps); + src->priv->caps = NULL; + } + + return TRUE; +} diff --git a/libjava/classpath/native/jni/gstreamer-peer/gst_classpath_src.h b/libjava/classpath/native/jni/gstreamer-peer/gst_classpath_src.h new file mode 100644 index 000000000..9e2acb0f2 --- /dev/null +++ b/libjava/classpath/native/jni/gstreamer-peer/gst_classpath_src.h @@ -0,0 +1,88 @@ +/*gstclasspathsrc.h - Header file for the GstClasspathPlugin + Copyright (C) 2007 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#ifndef __GST_CLASSPATH_SRC_H__ +#define __GST_CLASSPATH_SRC_H__ + +#include +#include + +#include "gst_input_stream.h" + +G_BEGIN_DECLS + +/* #defines don't like whitespacey bits */ +#define GST_TYPE_CLASSPATH_SRC (gst_classpath_src_get_type()) + +#define GST_CLASSPATH_SRC(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_CLASSPATH_SRC,GstClasspathSrc)) + +#define GST_CLASSPATH_SRC_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_CLASSPATH_SRC,GstClasspathSrcClass)) + +#define GST_IS_CLASSPATH_SRC(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_CLASSPATH_SRC)) + +#define GST_IS_CLASSPATH_SRC_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_CLASSPATH_SRC)) + +typedef struct _GstClasspathSrcPrivate GstClasspathSrcPrivate; +typedef struct _GstClasspathSrc GstClasspathSrc; +typedef struct _GstClasspathSrcClass GstClasspathSrcClass; + +struct _GstClasspathSrc +{ + GstPushSrc element; + + /* instance members */ + GstClasspathSrcPrivate *priv; +}; + +struct _GstClasspathSrcClass +{ + GstPushSrcClass parent_class; +}; + +GType gst_classpath_src_get_type (void); + +/* exported properties */ + +#define GST_CLASSPATH_SRC_ISTREAM "input-stream" + +G_END_DECLS + +#endif /* __GST_CLASSPATH_SRC_H__ */ diff --git a/libjava/classpath/native/jni/gstreamer-peer/gst_input_stream.c b/libjava/classpath/native/jni/gstreamer-peer/gst_input_stream.c new file mode 100644 index 000000000..c5e512954 --- /dev/null +++ b/libjava/classpath/native/jni/gstreamer-peer/gst_input_stream.c @@ -0,0 +1,290 @@ +/*GstInputStream.c - Header file for the GstClasspathPlugin + Copyright (C) 2007 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include + +#include +#include + +#include + +#include + +#include "gst_peer.h" + +#include "gnu_javax_sound_sampled_gstreamer_io_GstInputStream.h" +#include "gst_input_stream.h" + +/* for caching */ +static jmethodID readID = NULL; +static jmethodID pointerConstructorID = NULL; +static jmethodID availableID = NULL; + +static jfieldID streamID = NULL; +static jfieldID pointerDataID = NULL; + +struct _GstInputStreamPrivate +{ + JavaVM *vm; + jclass readerClass; + jclass pointerClass; + + jobject reader; +}; + +/* ************************************************************************** */ + +static void init_pointer_IDs (JNIEnv* env); + +/* ************************************************************************** */ + +/* JNI Methods */ + +JNIEXPORT void JNICALL +Java_gnu_javax_sound_sampled_gstreamer_io_GstInputStream_init_1id_1cache + (JNIEnv *env, jclass clazz) +{ + readID = (*env)->GetMethodID(env, clazz, "read", "([BII)I"); + availableID = (*env)->GetMethodID(env, clazz, "available", "()I"); + + streamID = (*env)->GetFieldID(env, clazz, "gstInputStream", + "Lgnu/classpath/Pointer;"); + init_pointer_IDs(env); +} + +JNIEXPORT void JNICALL +Java_gnu_javax_sound_sampled_gstreamer_io_GstInputStream_init_1instance + (JNIEnv *env, jobject reader) +{ + GstInputStream *istream = NULL; + + jclass localReader = NULL; + jclass localPointer = NULL; + jobject _pointer = NULL; + + istream = (GstInputStream *) JCL_malloc (env, sizeof (GstInputStream)); + if (istream == NULL) + return; + + istream->priv = (GstInputStreamPrivate *) + JCL_malloc (env, sizeof (GstInputStreamPrivate)); + if (istream->priv == NULL) + { + JCL_free (env, istream); + return; + } + + /* get a local references first */ + localReader = (*env)->GetObjectClass(env, reader); + if (localReader == NULL) + { + JCL_free (env, istream->priv); + JCL_free (env, istream); + JCL_ThrowException (env, "java/lang/InternalError", + "Class Initialization failed."); + + return; + } + +#if SIZEOF_VOID_P == 8 + localPointer = JCL_FindClass (env, "gnu/classpath/Pointer64"); +#else +# if SIZEOF_VOID_P == 4 + localPointer = JCL_FindClass (env, "gnu/classpath/Pointer32"); +# else +# error "Pointer size is not supported." +# endif /* SIZEOF_VOID_P == 4 */ +#endif /* SIZEOF_VOID_P == 8 */ + + if (localReader == NULL || localPointer == NULL) + { + JCL_free (env, istream->priv); + JCL_free (env, istream); + JCL_ThrowException (env, "java/lang/InternalError", + "Class Initialization failed."); + return; + } + + /* fill out our structure */ + istream->priv->readerClass = (*env)->NewGlobalRef(env, localReader); + istream->priv->pointerClass = (*env)->NewGlobalRef(env, localPointer); + (*env)->GetJavaVM(env, &istream->priv->vm); + istream->priv->reader = (*env)->NewGlobalRef(env, reader); + + _pointer = (*env)->GetObjectField(env, reader, streamID); + + /* this should be always null */ + if (_pointer == NULL) + { +#if SIZEOF_VOID_P == 8 + _pointer = (*env)->NewObject(env, istream->priv->pointerClass, + pointerConstructorID, (jlong) istream); +#else + _pointer = (*env)->NewObject(env, istream->priv->pointerClass, + pointerConstructorID, (jint) istream); +#endif + } + else + { +#if SIZEOF_VOID_P == 8 + (*env)->SetLongField(env, reader, streamID, (jlong) istream); +#else + (*env)->SetIntField(env, reader, streamID, (jint) istream); +#endif + } + + /* store back our pointer into the calling class */ + (*env)->SetObjectField(env, reader, streamID, _pointer); +} + +/* exported library functions */ + +void +gst_input_stream_clean (GstInputStream *self) +{ + JNIEnv *env = NULL; + + env = gst_get_jenv (self->priv->vm); + + (*env)->DeleteGlobalRef (env, self->priv->reader); + (*env)->DeleteGlobalRef (env, self->priv->readerClass); + (*env)->DeleteGlobalRef (env, self->priv->pointerClass); + + JCL_free (env, self->priv); + JCL_free (env, self); +} + +int +gst_input_stream_available (GstInputStream *self) +{ + JNIEnv *env = NULL; + + if (self == NULL || self->priv == NULL || + self->priv->vm == NULL || self->priv->reader == NULL) + { + return -1; + } + + env = gst_get_jenv (self->priv->vm); + if (env == NULL) + { + g_warning("GstInputStream::gst_input_stream_available " \ + "failed to get java env"); + return -1; + } + + return (*env)->CallIntMethod (env, self->priv->reader, availableID); +} + +int +gst_input_stream_read (GstInputStream *self, int *data, int offset, + int length) +{ + JNIEnv *env = NULL; + + int ret = -1; + jbyteArray buffer; + jbyte *bytes = NULL; + + if (self == NULL || self->priv == NULL || + self->priv->vm == NULL || self->priv->reader == NULL) + { + return -1; + } + + env = gst_get_jenv (self->priv->vm); + if (env == NULL) + { + g_warning("GstInputStream::gst_input_stream_read failed to get java env"); + return -1; + } + + buffer = (*env)->NewByteArray (env, length); + if (buffer == NULL) + { + g_warning ("GstInputStream::gst_input_stream_read called, failed"); + return -1; + } + + ret = (*env)->CallIntMethod (env, self->priv->reader, readID, buffer, 0, + length); + if (ret < 0) + { + (*env)->DeleteLocalRef(env, buffer); + return ret; + } + + bytes = (*env)->GetByteArrayElements (env, buffer, NULL); + + /* copy bytes and release */ + memcpy (data + offset, bytes, ret); + + (*env)->ReleaseByteArrayElements (env, buffer, bytes, 0); + (*env)->DeleteLocalRef (env, buffer); + + return ret; +} + +/* private functions */ + +static void init_pointer_IDs (JNIEnv* env) +{ + jclass pointerClass = NULL; + +#if SIZEOF_VOID_P == 8 + pointerClass = JCL_FindClass (env, "gnu/classpath/Pointer64"); + if (pointerClass != NULL) + { + pointerDataID = (*env)->GetFieldID (env, pointerClass, "data", "J"); + pointerConstructorID = (*env)->GetMethodID (env, pointerClass, "", + "(J)V"); + } +#else +# if SIZEOF_VOID_P == 4 + pointerClass = JCL_FindClass (env, "gnu/classpath/Pointer32"); + if (pointerClass != NULL) + { + pointerDataID = (*env)->GetFieldID(env, pointerClass, "data", "I"); + pointerConstructorID = (*env)->GetMethodID(env, pointerClass, + "", "(I)V"); + } +# else +# error "Pointer size is not supported." +# endif /* SIZEOF_VOID_P == 4 */ +#endif /* SIZEOF_VOID_P == 8 */ +} diff --git a/libjava/classpath/native/jni/gstreamer-peer/gst_input_stream.h b/libjava/classpath/native/jni/gstreamer-peer/gst_input_stream.h new file mode 100644 index 000000000..8e9d3cf42 --- /dev/null +++ b/libjava/classpath/native/jni/gstreamer-peer/gst_input_stream.h @@ -0,0 +1,71 @@ +/*gstinputstream.h - Header file for the GstClasspathPlugin + Copyright (C) 2007 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#ifndef __GST_INPUT_STREAM_H__ +#define __GST_INPUT_STREAM_H__ + +typedef struct _GstInputStream GstInputStream; +typedef struct _GstInputStreamPrivate GstInputStreamPrivate; + +struct _GstInputStream +{ + /* instance members */ + GstInputStreamPrivate *priv; +}; + +/** + * Clean the given instance of GstInputStream so that the garbage + * collector can collect the cached Java classes. + * Call this fuction when you don't need anymore to use this instance of + * GstInputStream. Note that failure to call this routine will result in + * memroy leaks. + */ +void gst_input_stream_clean (GstInputStream *self); + +/** + * Perform the "read" operation on this GstInputStream. + */ +int gst_input_stream_read (GstInputStream *self, int *data, int offset, + int length); + +/** + * Returns the number of byte currently available for read in this + * GstInputStream. + */ +int gst_input_stream_available (GstInputStream *self); + +#endif /* __GST_INPUT_STREAM_H__ */ diff --git a/libjava/classpath/native/jni/gstreamer-peer/gst_native_data_line.c b/libjava/classpath/native/jni/gstreamer-peer/gst_native_data_line.c new file mode 100644 index 000000000..84e76a1dc --- /dev/null +++ b/libjava/classpath/native/jni/gstreamer-peer/gst_native_data_line.c @@ -0,0 +1,251 @@ +/*gst_native_data_line.c - Implements the native methods of GstNativeDataLine + Copyright (C) 2007 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include + +#include + +#include "jcl.h" +#include "gnu_javax_sound_sampled_gstreamer_lines_GstNativeDataLine.h" + +#include "gst_peer.h" +#include "gst_classpath_src.h" +#include "gst_native_pipeline.h" + +static jfieldID pointerDataFID = NULL; + +/* ************************************************************************** */ + +static GstElement *setup_pipeline (GstNativePipeline *jpipeline, int fd); +static void +gst_newpad (GstElement *decodebin, GstPad *pad, gboolean last, gpointer data); + +/* ************************************************************************** */ + +JNIEXPORT void JNICALL +Java_gnu_javax_sound_sampled_gstreamer_lines_GstNativeDataLine_init_1id_1cache + (JNIEnv *env __attribute__ ((unused)), jclass clazz __attribute__ ((unused))) +{ + jclass pointerClass = NULL; + +#if SIZEOF_VOID_P == 8 + pointerClass = JCL_FindClass (env, "gnu/classpath/Pointer64"); + if (pointerClass != NULL) + { + pointerDataFID = (*env)->GetFieldID (env, pointerClass, "data", "J"); + } +#else +# if SIZEOF_VOID_P == 4 + pointerClass = JCL_FindClass (env, "gnu/classpath/Pointer32"); + if (pointerClass != NULL) + { + pointerDataFID = (*env)->GetFieldID(env, pointerClass, "data", "I"); + } +# else +# error "Pointer size is not supported." +# endif /* SIZEOF_VOID_P == 4 */ +#endif /* SIZEOF_VOID_P == 8 */ +} + +JNIEXPORT jboolean JNICALL +Java_gnu_javax_sound_sampled_gstreamer_lines_GstNativeDataLine_setup_1sink_1pipeline + (JNIEnv *env, jclass clazz __attribute__ ((unused)), + jobject pointer) +{ + GstNativePipeline *jpipeline = NULL; + + GstElement *pipeline = NULL; + GstElement *sink = NULL; + GstElement *audioconv= NULL; + GstElement *resample = NULL; + GstElement *audio = NULL; + GstElement *decodebin = NULL; + + GstPad *audiopad = NULL; + + gst_init (NULL, NULL); + + /* get the pipeline from the pointer, then create it if needed */ + jpipeline = (GstNativePipeline *) get_object_from_pointer (env, pointer, + pointerDataFID); + if (jpipeline == NULL) + return JNI_FALSE; + + pipeline = setup_pipeline (jpipeline, + gst_native_pipeline_get_pipeline_fd (jpipeline)); + if (pipeline == NULL) + return JNI_FALSE; + + /* add the audio sink to the pipeline */ + /* TODO: hardcoded values */ + sink = gst_element_factory_make ("autoaudiosink", "alsa-output"); + if (sink == NULL) + { + gst_object_unref(GST_OBJECT(pipeline)); + gst_object_unref(GST_OBJECT(sink)); + + g_warning ("unable to create sink\n"); + return JNI_FALSE; + } + + audioconv = gst_element_factory_make ("audioconvert", "aconv"); + if (audioconv == NULL) + { + gst_object_unref(GST_OBJECT(pipeline)); + gst_object_unref(GST_OBJECT(sink)); + gst_object_unref(GST_OBJECT(decodebin)); + + g_warning ("unable to create audioconv\n"); + return JNI_FALSE; + } + + audio = gst_bin_new ("audiobin"); + if (audio == NULL) + { + gst_object_unref(GST_OBJECT(pipeline)); + gst_object_unref(GST_OBJECT(sink)); + gst_object_unref(GST_OBJECT(decodebin)); + + g_warning ("unable to create audioconv\n"); + return JNI_FALSE; + } + + resample = gst_element_factory_make ("audioresample", "audioresample"); + if (audioconv == NULL) + { + gst_object_unref(GST_OBJECT(pipeline)); + gst_object_unref(GST_OBJECT(sink)); + gst_object_unref(GST_OBJECT(decodebin)); + gst_object_unref(GST_OBJECT(audio)); + + g_warning ("unable to create resample\n"); + return JNI_FALSE; + } + + audiopad = gst_element_get_pad (audioconv, "sink"); + gst_bin_add_many (GST_BIN (audio), audioconv, resample, sink, NULL); + gst_element_link (audioconv, sink); + + gst_element_add_pad (audio, gst_ghost_pad_new ("sink", audiopad)); + + gst_object_unref (audiopad); + gst_bin_add (GST_BIN (pipeline), audio); + + decodebin = gst_bin_get_by_name (GST_BIN (pipeline), "decodebin"); + g_signal_connect (decodebin, "new-decoded-pad", G_CALLBACK (gst_newpad), + audio); + + gst_native_pipeline_set_pipeline (jpipeline, pipeline); + + return JNI_TRUE; +} + +/* ************************************************************************** */ + +static GstElement *setup_pipeline (GstNativePipeline *jpipeline, int fd) +{ + GstElement *decodebin = NULL; + GstElement *source = NULL; + + GstElement *pipeline = NULL; + + if (fd < 0) + return NULL; + + pipeline = gst_pipeline_new ("java sound pipeline"); + if (pipeline == NULL) + return NULL; + + decodebin = gst_element_factory_make ("decodebin", "decodebin"); + if (decodebin == NULL) + { + gst_object_unref(GST_OBJECT(pipeline)); + gst_object_unref(GST_OBJECT(source)); + + g_warning ("unable to create decodebin\n"); + return NULL; + } + + source = gst_element_factory_make ("fdsrc", "source"); + if (source == NULL) + { + gst_object_unref(GST_OBJECT(pipeline)); + gst_object_unref(GST_OBJECT(source)); + gst_object_unref(GST_OBJECT(decodebin)); + + g_warning ("unable to create a source"); + return JNI_FALSE; + } + g_object_set (G_OBJECT (source), "fd", fd, NULL); + + gst_bin_add_many (GST_BIN (pipeline), source, decodebin, NULL); + gst_element_link (source, decodebin); + + return pipeline; +} + +static void +gst_newpad (GstElement *decodebin, GstPad *pad, gboolean last, gpointer data) +{ + GstCaps *caps; + GstStructure *str; + GstPad *audiopad; + + GstElement *audio = (GstElement *) data; + + /* only link once */ + audiopad = gst_element_get_pad (audio, "sink"); + if (GST_PAD_IS_LINKED (audiopad)) + { + g_object_unref (audiopad); + return; + } + + /* check media type */ + caps = gst_pad_get_caps (pad); + str = gst_caps_get_structure (caps, 0); + if (!g_strrstr (gst_structure_get_name (str), "audio")) + { + gst_caps_unref (caps); + gst_object_unref (audiopad); + return; + } + gst_caps_unref (caps); + + /* link'n'play */ + gst_pad_link (pad, audiopad); +} diff --git a/libjava/classpath/native/jni/gstreamer-peer/gst_native_pipeline.c b/libjava/classpath/native/jni/gstreamer-peer/gst_native_pipeline.c new file mode 100644 index 000000000..e0caa4775 --- /dev/null +++ b/libjava/classpath/native/jni/gstreamer-peer/gst_native_pipeline.c @@ -0,0 +1,611 @@ +/*gst_native_pipeline.c - Header file for the GstClasspathPlugin + Copyright (C) 2007 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include + +#include +#include + +#include +#include +#include + +#include + +#ifdef HAVE_FCNTL_H +#include +#endif /* HAVE_FCNTL_H */ + +#if defined(HAVE_SYS_IOCTL_H) +#define BSD_COMP /* Get FIONREAD on Solaris2 */ +#include +#endif +#if defined(HAVE_SYS_FILIO_H) /* Get FIONREAD on Solaris 2.5 */ +#include +#endif + +#include +#include + +#include + +#include "cpio.h" +#include "gst_peer.h" + +#include "gnu_javax_sound_sampled_gstreamer_lines_GstPipeline.h" +#include "gst_native_pipeline.h" + +static jmethodID pointerConstructorMID = NULL; + +static jfieldID pipelineFID = NULL; +static jfieldID pointerDataFID = NULL; +static jfieldID nameFID = NULL; +static jfieldID capacityFID = NULL; + +/* + * Needed to compute the size of the data still available for processing in the + * pipeline. We give a default here but this will be overwritten by the + * detection routines. + */ +static long GST_DETECTED_PIPE_CAPACITY = 65536; + +/* + * Note: the Java code uses enum classes, these are not mapped into constants + * by the javah tool, changes to these values should be reflected in the Java + * side. + */ +enum +{ + PLAY, + PAUSE, + STOP +}; + +/* + * Defined as constants in the Java code, hence mapped by javah. + */ +enum +{ + READ = gnu_javax_sound_sampled_gstreamer_lines_GstPipeline_READ, + WRITE = gnu_javax_sound_sampled_gstreamer_lines_GstPipeline_WRITE +}; + +struct _GstNativePipelinePrivate +{ + JavaVM *vm; + jclass GstPipelineClass; + jclass PointerClass; + + jobject jni_pipeline; + + char *name; + int fd; + + GstElement *pipeline; +}; + +/* ************************************************************************** */ +/* +static void gst_native_pipeline_clean (GstNativePipeline *self);*/ +static char *create_name (void); +static void init_pointer_IDs (JNIEnv* env); +static jint get_free_space (int fd); +static void detect_pipe_max (void); + +/* ************************************************************************** */ + +/* JNI Methods */ + +JNIEXPORT void JNICALL +Java_gnu_javax_sound_sampled_gstreamer_lines_GstPipeline_init_1id_1cache + (JNIEnv *env, jclass clazz) +{ + pipelineFID = (*env)->GetFieldID (env, clazz, "pipeline", + "Lgnu/classpath/Pointer;"); + nameFID = (*env)->GetFieldID (env, clazz, "name", "Ljava/lang/String;"); + capacityFID = (*env)->GetFieldID (env, clazz, "capacity", "J"); + + init_pointer_IDs (env); +} + +JNIEXPORT void JNICALL +Java_gnu_javax_sound_sampled_gstreamer_lines_GstPipeline_init_1instance + (JNIEnv *env, jobject pipeline) +{ + GstNativePipeline *_pipeline = NULL; + + jclass localGstPipelineClass = NULL; + jclass localPointerClass = NULL; + jobject _pointer = NULL; + + _pipeline = + (GstNativePipeline *) JCL_malloc (env, sizeof (GstNativePipeline)); + if (_pipeline == NULL) + return; + + _pipeline->priv = (GstNativePipelinePrivate *) + JCL_malloc (env, sizeof (GstNativePipelinePrivate)); + if (_pipeline->priv == NULL) + { + JCL_free (env, _pipeline); + return; + } + +#if SIZEOF_VOID_P == 8 + localPointerClass = JCL_FindClass (env, "gnu/classpath/Pointer64"); +#else +# if SIZEOF_VOID_P == 4 + localPointerClass = JCL_FindClass (env, "gnu/classpath/Pointer32"); +# else +# error "Pointer size is not supported." +# endif /* SIZEOF_VOID_P == 4 */ +#endif /* SIZEOF_VOID_P == 8 */ + + localGstPipelineClass = (*env)->GetObjectClass(env, pipeline); + if (localGstPipelineClass == NULL || localGstPipelineClass == NULL) + { + JCL_free (env, _pipeline->priv); + JCL_free (env, _pipeline); + JCL_ThrowException (env, "java/lang/InternalError", + "Class Initialization failed."); + return; + } + + GST_DETECTED_PIPE_CAPACITY = (long) (*env)->GetLongField(env, pipeline, + capacityFID); + + /* fill the object */ + (*env)->GetJavaVM(env, &_pipeline->priv->vm); + _pipeline->priv->jni_pipeline = (*env)->NewGlobalRef(env, pipeline); + _pipeline->priv->GstPipelineClass = + (*env)->NewGlobalRef(env, localGstPipelineClass); + _pipeline->priv->PointerClass = (*env)->NewGlobalRef(env, localPointerClass); + _pipeline->priv->pipeline = NULL; + + _pointer = (*env)->GetObjectField(env, pipeline, pipelineFID); + + if (_pointer == NULL) + { +#if SIZEOF_VOID_P == 8 + _pointer = (*env)->NewObject(env, _pipeline->priv->PointerClass, + pointerConstructorMID, (jlong) _pipeline); +#else + _pointer = (*env)->NewObject(env, _pipeline->priv->PointerClass, + pointerConstructorMID, (jint) _pipeline); +#endif + } + else + { +#if SIZEOF_VOID_P == 8 + (*env)->SetLongField(env, pipeline, pipelineFID, (jlong) _pipeline); +#else + (*env)->SetIntField(env, pipeline, pipelineFID, (jint) _pipeline); +#endif + } + + /* store back our pointer into the calling class */ + (*env)->SetObjectField(env, pipeline, pipelineFID, _pointer); +} + +JNIEXPORT jboolean JNICALL +Java_gnu_javax_sound_sampled_gstreamer_lines_GstPipeline_set_1state + (JNIEnv *env, jclass clazz, jobject pointer, jint state) +{ + GstNativePipeline *jpipeline = NULL; + jboolean result = JNI_FALSE; + + if (pointer == NULL) + { + JCL_ThrowException (env, "javax/sound/sampled/LineUnavailableException", + "Can't change pipeline state: " \ + "pipeline not initialized"); + return result; + } + + jpipeline = (GstNativePipeline *) get_object_from_pointer (env, pointer, + pointerDataFID); + if (jpipeline == NULL) + return JNI_FALSE; + + switch (state) + { + case (PLAY): + gst_element_set_state(GST_ELEMENT(jpipeline->priv->pipeline), + GST_STATE_PLAYING); + result = JNI_TRUE; + break; + + case (PAUSE): + gst_element_set_state(GST_ELEMENT(jpipeline->priv->pipeline), + GST_STATE_PAUSED); + result = JNI_TRUE; + break; + + case (STOP): +#ifndef WITHOUT_FILESYSTEM + /* clean the pipeline and kill named pipe */ + if (jpipeline->priv->name) + { + cpio_removeFile (jpipeline->priv->name); + g_free (jpipeline->priv->name); + jpipeline->priv->name = NULL; + } +#endif /* WITHOUT_FILESYSTEM */ + + if (jpipeline->priv->pipeline != NULL) + gst_object_unref (GST_OBJECT(jpipeline->priv->pipeline)); + result = JNI_TRUE; + break; + + default: + /* nothing */ + result = JNI_FALSE; + break; + } + + return result; +} + +JNIEXPORT void JNICALL +Java_gnu_javax_sound_sampled_gstreamer_lines_GstPipeline_open_1native_1pipe + (JNIEnv *env, jclass clazz, jobject pointer, jint mode) +{ + GstNativePipeline *jpipeline = NULL; + + jpipeline = (GstNativePipeline *) get_object_from_pointer (env, pointer, + pointerDataFID); + switch (mode) + { + case (READ): + jpipeline->priv->fd = + open (jpipeline->priv->name, O_RDONLY | O_NONBLOCK); + break; + + case (WRITE): + /* TODO: no-op currently */ + break; + } +} + +JNIEXPORT void JNICALL +Java_gnu_javax_sound_sampled_gstreamer_lines_GstPipeline_close_1native_1pipe + (JNIEnv *env, jclass clazz, jobject pointer) +{ +#ifndef WITHOUT_FILESYSTEM + GstNativePipeline *jpipeline = NULL; + jpipeline = (GstNativePipeline *) get_object_from_pointer (env, pointer, + pointerDataFID); + /* kill the named pipe */ + if (jpipeline->priv->name) + { + cpio_removeFile (jpipeline->priv->name); + g_free (jpipeline->priv->name); + jpipeline->priv->name = NULL; + } +#endif /* WITHOUT_FILESYSTEM */ +} + +JNIEXPORT jboolean JNICALL +Java_gnu_javax_sound_sampled_gstreamer_lines_GstPipeline_create_1named_1pipe + (JNIEnv *env, jobject GstPipeline, jobject pointer) +{ +#ifndef WITHOUT_FILESYSTEM + /* + * We get a temp name for the named pipe, create the named pipe and then + * set the relative field in the java class. + */ + GstNativePipeline *jpipeline = NULL; + jstring *name = NULL; + + jpipeline = (GstNativePipeline *) get_object_from_pointer (env, pointer, + pointerDataFID); + if (jpipeline == NULL) + return JNI_FALSE; + + jpipeline->priv->name = create_name (); + if (jpipeline->priv->name == NULL) + return JNI_FALSE; + + if (mkfifo (jpipeline->priv->name, 0600) < 0) + { + if (jpipeline->priv->name != NULL) + free (jpipeline->priv->name); + return JNI_FALSE; + } + + /* now set the String field */ + name = (*env)->NewStringUTF(env, jpipeline->priv->name); + if (name == NULL) + { + cpio_removeFile (jpipeline->priv->name); + if (jpipeline->priv->name != NULL) + free (jpipeline->priv->name); + + return JNI_FALSE; + } + + (*env)->SetObjectField(env, GstPipeline, nameFID, name); + + return JNI_TRUE; + +#else /* not WITHOUT_FILESYSTEM */ + return JNI_FALSE; +#endif /* not WITHOUT_FILESYSTEM */ +} + +JNIEXPORT jint JNICALL +Java_gnu_javax_sound_sampled_gstreamer_lines_GstPipeline_available + (JNIEnv *env, jclass clazz, jobject pointer, jint mode) +{ + jint result = -1; + +#ifndef WITHOUT_FILESYSTEM + + GstNativePipeline *jpipeline = NULL; + jpipeline = (GstNativePipeline *) get_object_from_pointer (env, pointer, + pointerDataFID); + + if (mode == READ) + { + result = get_free_space (jpipeline->priv->fd); + } + else + { +# if defined (FIONREAD) + if (ioctl (jpipeline->priv->fd, FIONREAD, &result) == -1) + g_warning("IMPLEMENT ME: ioctl failed"); + +# else /* not defined (FIONREAD) */ + g_warning("IMPLEMENT ME: !defined (FIONREAD"); +# endif /* defined (FIONREAD) */ + + } /* if (mode == READ) */ + +#endif /* not WITHOUT_FILESYSTEM */ + + return result; +} + +JNIEXPORT jlong JNICALL +Java_gnu_javax_sound_sampled_gstreamer_lines_GstPipeline_detect_1pipe_1size + (JNIEnv *env, jobject GstPipeline) +{ + detect_pipe_max (); + + return GST_DETECTED_PIPE_CAPACITY; +} + +/* exported library functions */ +/* +static void gst_native_pipeline_clean (GstNativePipeline *self) +{ + JNIEnv *env = NULL; + + env = gst_get_jenv (self->priv->vm); + + (*env)->DeleteGlobalRef (env, self->priv->jni_pipeline); + (*env)->DeleteGlobalRef (env, self->priv->GstPipelineClass); + (*env)->DeleteGlobalRef (env, self->priv->PointerClass); + + if (self->priv->pipeline != NULL) + gst_object_unref (GST_OBJECT (self->priv->pipeline)); + + if (self->priv->name) + { + cpio_removeFile (self->priv->name); + g_free (self->priv->name); + self->priv->name = NULL; + } + + JCL_free (env, self->priv); + JCL_free (env, self); +} +*/ +void gst_native_pipeline_set_pipeline (GstNativePipeline *self, + GstElement *pipeline) +{ + if (self->priv->pipeline != NULL) + gst_object_unref (GST_OBJECT (self->priv->pipeline)); + + self->priv->pipeline = pipeline; +} + +GstElement *gst_native_pipeline_get_pipeline (GstNativePipeline *self) +{ + return self->priv->pipeline; +} + +char *gst_native_pipeline_get_pipeline_name (GstNativePipeline *self) +{ + return self->priv->name; +} + +int gst_native_pipeline_get_pipeline_fd (GstNativePipeline *self) +{ + return self->priv->fd; +} + +/* private functions */ + +static void init_pointer_IDs (JNIEnv* env) +{ + jclass PointerClass = NULL; + +#if SIZEOF_VOID_P == 8 + PointerClass = JCL_FindClass (env, "gnu/classpath/Pointer64"); + if (PointerClass != NULL) + { + pointerDataFID = (*env)->GetFieldID (env, PointerClass, "data", "J"); + pointerConstructorMID = (*env)->GetMethodID (env, PointerClass, "", + "(J)V"); + } +#else +# if SIZEOF_VOID_P == 4 + PointerClass = JCL_FindClass (env, "gnu/classpath/Pointer32"); + if (PointerClass != NULL) + { + pointerDataFID = (*env)->GetFieldID(env, PointerClass, "data", "I"); + pointerConstructorMID = (*env)->GetMethodID(env, PointerClass, + "", "(I)V"); + } +# else +# error "Pointer size is not supported." +# endif /* SIZEOF_VOID_P == 4 */ +#endif /* SIZEOF_VOID_P == 8 */ +} + +static jint get_free_space (int fd) +{ + jint result = -1; + +#if defined (FIONSPACE) + + if (ioctl (fd, FIONSPACE, &result) == -1) + { + g_warning("IMPLEMENT ME: ioctl failed"); + } + +#elif defined (FIONREAD) + + if (ioctl (fd, FIONREAD, &result) == -1) + { + g_warning("IMPLEMENT ME: ioctl failed"); + } + + result = GST_DETECTED_PIPE_CAPACITY - result; + +#else + g_warning("IMPLEMENT ME!!! - !defined (FIONSPACE), !defined (FIONREAD"); + +#endif + + return result; +} + +static char *create_name (void) +{ + char *buffer = NULL; + char *tmp = NULL; + + buffer = (char *) g_malloc0 (_GST_MALLOC_SIZE_); + if (buffer == NULL) + { + /* huston, we have a problem... */ + return NULL; + } + + tmp = tempnam (NULL, _GST_PIPELINE_PREFIX_); + if (tmp == NULL) + { + g_free (buffer); + return NULL; + } + + g_snprintf (buffer, _GST_MALLOC_SIZE_, "%s%s", tmp, _GST_PIPELINE_SUFFIX_); + g_free (tmp); + + return buffer; +} + +static void detect_pipe_max (void) +{ + int read_fd; + int write_fd; + + /* can be anything! */ + char *character = "a"; + char *pipe = NULL; + + gboolean available = TRUE; + int w = 0; + long wrote = 0; + + pipe = create_name (); + if (pipe == NULL) + { + g_warning ("can't create test pipe name"); + return; + } + + if (mkfifo (pipe, 0600) < 0) + { + g_warning ("unable to create test pipe..."); + g_free (pipe); + + return; + } + + /* open both end of the pipe */ + read_fd = open (pipe, O_RDONLY | O_NONBLOCK); + if (read_fd < 0) + { + cpio_removeFile (pipe); + g_free (pipe); + + return; + } + + write_fd = open (pipe, O_WRONLY | O_NONBLOCK); + if (write_fd < 0) + { + cpio_closeFile (write_fd); + cpio_removeFile (pipe); + g_free (pipe); + + return; + } + + while (available) + { + w = 0; + + cpio_write (write_fd, character, 1, &w); + if (w < 0) + available = FALSE; + else + wrote += w; + } + + GST_DETECTED_PIPE_CAPACITY = wrote; + + cpio_closeFile (write_fd); + cpio_closeFile (read_fd); + cpio_removeFile (pipe); + + g_free (pipe); +} diff --git a/libjava/classpath/native/jni/gstreamer-peer/gst_native_pipeline.h b/libjava/classpath/native/jni/gstreamer-peer/gst_native_pipeline.h new file mode 100644 index 000000000..b5a45b40a --- /dev/null +++ b/libjava/classpath/native/jni/gstreamer-peer/gst_native_pipeline.h @@ -0,0 +1,63 @@ +/*gst_native_pipeline.h - Header file for the GstClasspathPlugin + Copyright (C) 2007 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#ifndef __GST_NATIVE_PIPELINE_H__ +#define __GST_NATIVE_PIPELINE_H__ + +#include + +#include + +typedef struct _GstNativePipeline GstNativePipeline; +typedef struct _GstNativePipelinePrivate GstNativePipelinePrivate; + +struct _GstNativePipeline +{ + /* instance members */ + GstNativePipelinePrivate *priv; +}; + +void gst_native_pipeline_set_pipeline (GstNativePipeline *self, + GstElement *pipeline); + +GstElement *gst_native_pipeline_get_pipeline (GstNativePipeline *self); + +char *gst_native_pipeline_get_pipeline_name (GstNativePipeline *self); + +int gst_native_pipeline_get_pipeline_fd (GstNativePipeline *self); + +#endif /* __GST_NATIVE_PIPELINE_H__ */ diff --git a/libjava/classpath/native/jni/gstreamer-peer/gst_peer.c b/libjava/classpath/native/jni/gstreamer-peer/gst_peer.c new file mode 100644 index 000000000..da83b006b --- /dev/null +++ b/libjava/classpath/native/jni/gstreamer-peer/gst_peer.c @@ -0,0 +1,83 @@ +/*gst_peer.c - Common utility functions for the native peer. + Copyright (C) 2007 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include + +#include +#include "jcl.h" + +#include "gst_peer.h" + +JNIEnv *gst_get_jenv (JavaVM *vm) +{ + void *env = NULL; + + if ((*vm)->GetEnv(vm, &env, JNI_VERSION_1_2) != JNI_OK) + { + if ((*vm)->AttachCurrentThreadAsDaemon(vm, &env, NULL) < 0) + { + g_warning ("GstNativePipeline:- env not attached"); + return NULL; + } + } + + return (JNIEnv *) env; +} + +void * +get_object_from_pointer (JNIEnv *env, jobject pointer, jfieldID pointerDataFID) +{ + void *_object = NULL; + + if (env == NULL) + return NULL; + + if ((*env)->IsSameObject(env, pointer, NULL) == JNI_TRUE) + return NULL; + +#if SIZEOF_VOID_P == 8 + _object = (void *) (*env)->GetLongField(env, pointer, pointerDataFID); +#else +# if SIZEOF_VOID_P == 4 + _object = (void *) (*env)->GetIntField(env, pointer, pointerDataFID); +# else +# error "Pointer size is not supported." +# endif /* SIZEOF_VOID_P == 4 */ +#endif /* SIZEOF_VOID_P == 8 */ + + return _object; +} diff --git a/libjava/classpath/native/jni/gstreamer-peer/gst_peer.h b/libjava/classpath/native/jni/gstreamer-peer/gst_peer.h new file mode 100644 index 000000000..4500001b0 --- /dev/null +++ b/libjava/classpath/native/jni/gstreamer-peer/gst_peer.h @@ -0,0 +1,59 @@ +/*gst_peer.h - Common utility functions for the native peer. + Copyright (C) 2007 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include "jcl.h" + +#ifdef MAXPATHLEN +# define _GST_MALLOC_SIZE_ MAXPATHLEN +#else +# define _GST_MALLOC_SIZE_ 1024 +#endif + +#define _GST_PIPELINE_PREFIX_ "cp-" +#define _GST_PIPELINE_SUFFIX_ "-classpath-gst-audio" + +/** + * Return a reference to the object stored in this Pointer. + */ +void * +get_object_from_pointer (JNIEnv *env, jobject pointer, jfieldID pointerDataFID); + +/** + * Return the JNIEnv valid under the current thread context. + */ +JNIEnv *gst_get_jenv (JavaVM *vm); diff --git a/libjava/classpath/native/jni/gstreamer-peer/gstreamer_io_peer.c b/libjava/classpath/native/jni/gstreamer-peer/gstreamer_io_peer.c new file mode 100644 index 000000000..7e38b91f8 --- /dev/null +++ b/libjava/classpath/native/jni/gstreamer-peer/gstreamer_io_peer.c @@ -0,0 +1,739 @@ +/* gstreamer_io_peer.c -- Implements native methods for class + GStreamerNativePeer + Copyright (C) 2007 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + +#include +#include + +#include + +#include +#include + +#include + +#include + +#include "jcl.h" + +#include "gst_peer.h" + +#include "gnu_javax_sound_sampled_gstreamer_io_GstAudioFileReaderNativePeer.h" + +#include "gst_classpath_src.h" +#include "gst_input_stream.h" + +/* for caching */ +static jfieldID fileFID = NULL; +static jfieldID pointerDataID = NULL; + +static jfieldID mimetypeFID = NULL; +static jfieldID endiannessFID = NULL; +static jfieldID channelsFID = NULL; +static jfieldID rateFID = NULL; +static jfieldID widthFID = NULL; +static jfieldID depthFID = NULL; +static jfieldID isSignedFID = NULL; +static jfieldID nameFID = NULL; +static jfieldID layerFID = NULL; +static jfieldID bitrateFID = NULL; +static jfieldID framedFID = NULL; +static jfieldID typeFID = NULL; + +typedef struct _AudioProperties AudioProperties; +struct _AudioProperties +{ + /* + * NOTE: descriptions of the properties are taken from: + * http://gstreamer.freedesktop.org/data/doc/gstreamer/head/pwg/html/section-types-definitions.html#table-audio-types + */ + + /* decoder name */ + const char *name; + + /* audio endiannes */ + const char *endianness; + + /* header size */ + const char *header_size; + + /* mime */ + const char *mimetype; + + /* The sample rate of the data, in samples (per channel) per second */ + const char *samplerate; + + /* The number of channels of audio data */ + const char *channels; + + const char *layer; + + const char *bitrate; + + const char *framed; + + /* + * Defines if the values of the integer samples are signed or not. + * Signed samples use one bit to indicate sign (negative or positive) + * of the value. Unsigned samples are always positive. + */ + const char *signess; + + /* */ + const char *rate; + + /* Number of bits allocated per sample. */ + const char *width; + + /* + * The number of bits used per sample. + * If the depth is less than the width, the low bits are assumed to be the + * ones used. For example, a width of 32 and a depth of 24 means that + * each sample is stored in a 32 bit word, but only the low + * 24 bits are actually used. + */ + const char *depth; + + /* + * This is set in the case of the mpeg files. + */ + const char *type; + + gboolean done; +}; + +/* ***** PRIVATE FUNCTIONS DECLARATION ***** */ + +static gboolean +set_strings (JNIEnv *env, const AudioProperties *properties, jobject header); + +static gboolean +typefind_callback(GstElement *typefind, guint probability, const GstCaps *caps, + gpointer data); + +static void +element_added (GstBin *bin, GstElement *element, gpointer data); + +static void +new_decoded_pad (GstElement *decoder, GstPad *pad, + gboolean last, gpointer data); + +static gboolean +fill_info (GstElement *decoder, AudioProperties *properties); + +static gchar * +get_string_property (const GstStructure *structure, const gchar *property); + +static gchar * +get_boolean_property (const GstStructure *structure, const gchar *property); + +static gboolean +set_string (JNIEnv *env, jobject header, jfieldID fieldID, + const gchar *property); + +static void +free_properties (AudioProperties *properties); + +static void +reset_properties (AudioProperties *properties); + +static jboolean process_audio (GstElement *source, JNIEnv *env, jobject header); + +/* ***** END: PRIVATE FUNCTIONS DECLARATION ***** */ + +/* ***** NATIVE FUNCTIONS ***** */ + +JNIEXPORT void JNICALL +Java_gnu_javax_sound_sampled_gstreamer_io_GstAudioFileReaderNativePeer_init_1id_1cache + (JNIEnv *env, jclass clazz __attribute__ ((unused))) +{ + jclass pointerClass = NULL; + jclass GstHeader = NULL; + + GstHeader = JCL_FindClass(env, "gnu/javax/sound/sampled/gstreamer/io/GstAudioFileReaderNativePeer$GstHeader"); + fileFID = (*env)->GetFieldID(env, GstHeader, "file", "Ljava/lang/String;"); + + mimetypeFID = (*env)->GetFieldID(env, GstHeader, "mimetype", + "Ljava/lang/String;"); + endiannessFID = (*env)->GetFieldID(env, GstHeader, "endianness", + "Ljava/lang/String;"); + channelsFID = (*env)->GetFieldID(env, GstHeader, "channels", + "Ljava/lang/String;"); + rateFID = (*env)->GetFieldID(env, GstHeader, "rate", "Ljava/lang/String;"); + widthFID = (*env)->GetFieldID(env, GstHeader, "width", "Ljava/lang/String;"); + depthFID = (*env)->GetFieldID(env, GstHeader, "depth", "Ljava/lang/String;"); + isSignedFID = (*env)->GetFieldID(env, GstHeader, "isSigned", + "Ljava/lang/String;"); + nameFID = (*env)->GetFieldID(env, GstHeader, "name", "Ljava/lang/String;"); + layerFID = (*env)->GetFieldID(env, GstHeader, "layer", "Ljava/lang/String;"); + bitrateFID = (*env)->GetFieldID(env, GstHeader, "bitrate", + "Ljava/lang/String;"); + framedFID = (*env)->GetFieldID(env, GstHeader, "framed", + "Ljava/lang/String;"); + typeFID = (*env)->GetFieldID(env, GstHeader, "type", "Ljava/lang/String;"); + +#if SIZEOF_VOID_P == 8 + pointerClass = JCL_FindClass (env, "gnu/classpath/Pointer64"); + if (pointerClass != NULL) + { + pointerDataID = (*env)->GetFieldID (env, pointerClass, "data", "J"); + } +#else +# if SIZEOF_VOID_P == 4 + pointerClass = JCL_FindClass (env, "gnu/classpath/Pointer32"); + if (pointerClass != NULL) + { + pointerDataID = (*env)->GetFieldID(env, pointerClass, "data", "I"); + } +# else +# error "Pointer size is not supported." +# endif /* SIZEOF_VOID_P == 4 */ +#endif /* SIZEOF_VOID_P == 8 */ + +} + +JNIEXPORT jboolean JNICALL +Java_gnu_javax_sound_sampled_gstreamer_io_GstAudioFileReaderNativePeer_gstreamer_1get_1audio_1format_1stream + (JNIEnv *env, jclass clazz __attribute__ ((unused)), jobject header, + jobject pointer) +{ + GstInputStream *istream = NULL; + GstElement *source = NULL; + gboolean result = JNI_FALSE; + + if (header == NULL) + return JNI_FALSE; + + if (pointer == NULL) + return JNI_FALSE; + + gst_init (NULL, NULL); + + istream = (GstInputStream *) get_object_from_pointer (env, pointer, + pointerDataID); + if (istream == NULL) + return JNI_FALSE; + + /* init gstreamer */ + gst_init (NULL, NULL); + + /* SOURCE */ + source = gst_element_factory_make ("classpathsrc", "source"); + if (source == NULL) + { + g_warning ("unable to create a source"); + return JNI_FALSE; + } + g_object_set (G_OBJECT (source), GST_CLASSPATH_SRC_ISTREAM, istream, NULL); + + result = process_audio (source, env, header); + + return result; +} + +JNIEXPORT jboolean JNICALL +Java_gnu_javax_sound_sampled_gstreamer_io_GstAudioFileReaderNativePeer_gstreamer_1get_1audio_1format_1file + (JNIEnv *env, jclass clazz __attribute__ ((unused)), jobject header) +{ + /* source file */ + const char *file = NULL; + + /* GStreamer elements */ + GstElement *source = NULL; + + jboolean result = JNI_FALSE; + + /* java fields */ + jstring _file = NULL; + + _file = (*env)->GetObjectField(env, header, fileFID); + file = JCL_jstring_to_cstring (env, _file); + if (file == NULL) + { + return JNI_FALSE; + } + + gst_init (NULL, NULL); + + /* create the source element, will be used to read the file */ + source = gst_element_factory_make ("filesrc", "source"); + if (source == NULL) + { + JCL_free_cstring (env, _file, file); + return JNI_FALSE; + } + + /* set the file name */ + g_object_set (G_OBJECT (source), "location", file, NULL); + + result = process_audio (source, env, header); + + /* free stuff */ + JCL_free_cstring (env, _file, file); + + return result; +} + +/* ***** END: NATIVE FUNCTIONS ***** */ + +/* ***** PRIVATE FUNCTIONS IMPLEMENTATION ***** */ + +static jboolean process_audio (GstElement *source, JNIEnv *env, jobject header) +{ + /* will contain the properties we need to put into the given GstHeader */ + AudioProperties *properties = NULL; + + /* GStreamer elements */ + GstElement *pipeline = NULL; + GstElement *decoder = NULL; + + GstElement *typefind = NULL; + + GstStateChangeReturn res; + + jboolean result = JNI_FALSE; + + properties = (AudioProperties *) g_malloc0 (sizeof (AudioProperties)); + if (properties == NULL) + { + return result; + } + reset_properties(properties); + + /* + * create the decoder element, this will decode the stream and retrieve + * its properties. + * We connect a signal to this element, to be informed when it is done + * in decoding the stream and to get the needed informations about the + * audio file. + */ + decoder = gst_element_factory_make ("decodebin", "decoder"); + if (decoder == NULL) + { + free_properties(properties); + return result; + } + + /* now, we create a pipeline and fill it with the other elements */ + pipeline = gst_pipeline_new ("pipeline"); + if (pipeline == NULL) + { + gst_object_unref (GST_OBJECT (decoder)); + free_properties(properties); + return result; + } + + g_signal_connect (decoder, "new-decoded-pad", G_CALLBACK (new_decoded_pad), + pipeline); + g_signal_connect (G_OBJECT (decoder), "element-added", + G_CALLBACK (element_added), properties); + + /* + * we get the typefind from the decodebin to catch the additional properties + * that the decodebin does not expose to us + */ + typefind = gst_bin_get_by_name (GST_BIN (decoder), "typefind"); + if (typefind != NULL) + { + /* + * NOTE: the above is not a typo, we can live without the typefind, + * just, our stream detection will not be as accurate as we would. + * Anyway, if this fails, there is some problem, probabily a memory + * error. + */ + g_signal_connect (G_OBJECT (typefind), "have-type", + G_CALLBACK (typefind_callback), properties); + } + + gst_bin_add_many (GST_BIN (pipeline), source, decoder, NULL); + gst_element_link (source, decoder); + + /* + * now, we set the pipeline playing state to pause and traverse it + * to get the info we need. + */ + + res = gst_element_set_state (pipeline, GST_STATE_PAUSED); + if (res == GST_STATE_CHANGE_FAILURE) + { + gst_element_set_state (pipeline, GST_STATE_NULL); + gst_object_unref (GST_OBJECT (pipeline)); + + free_properties(properties); + + return result; + } + + res = gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE); + if (res != GST_STATE_CHANGE_SUCCESS) + { + gst_element_set_state (pipeline, GST_STATE_NULL); + gst_object_unref (GST_OBJECT (pipeline)); + + free_properties(properties); + + return result; + } + + if (fill_info (decoder, properties)) + { + result = set_strings (env, properties, header); + } + + /* free stuff */ + gst_element_set_state (pipeline, GST_STATE_NULL); + + free_properties (properties); + + gst_object_unref (GST_OBJECT (pipeline)); + + return result; +} + + +static gboolean typefind_callback(GstElement *typefind __attribute__ ((unused)), + guint probability __attribute__ ((unused)), + const GstCaps *caps, + gpointer data) +{ + GstStructure *structure = NULL; + AudioProperties *properties = NULL; + + const char *mpeg = NULL; + + properties = (AudioProperties *) data; + + structure = gst_caps_get_structure (caps, 0); + + /* MIMETYPE */ + properties->mimetype = gst_structure_get_name (structure); + mpeg = get_string_property(structure, "mpegversion"); + + if (mpeg != NULL) + { + properties->layer = get_string_property(structure, "layer"); + properties->type = (gchar *) g_malloc0 (_GST_MALLOC_SIZE_); + g_snprintf ((gpointer) properties->type, _GST_MALLOC_SIZE_, + "MPEG%sV%s", mpeg, + properties->layer); + + g_free ((gpointer) mpeg); + } + + return TRUE; +} + +static void +new_decoded_pad (GstElement *decoder __attribute__ ((unused)), + GstPad *pad, + gboolean last __attribute__ ((unused)), + gpointer data) +{ + GstElement *pipeline = NULL; + GstElement *fakesink = NULL; + GstPad *sinkpad = NULL; + + pipeline = (GstElement *) data; + if (pipeline == NULL) + return; + + fakesink = gst_element_factory_make ("fakesink", NULL); + if (fakesink == NULL) + return; + + gst_bin_add (GST_BIN (pipeline), fakesink); + sinkpad = gst_element_get_pad (fakesink, "sink"); + if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sinkpad))) + { + gst_bin_remove (GST_BIN (pipeline), fakesink); + } + else + { + gst_element_set_state (fakesink, GST_STATE_PAUSED); + } +} + +static gboolean +set_strings (JNIEnv *env, const AudioProperties *properties, jobject header) +{ + gboolean result = FALSE; + + /* + * we only need at least one of them to be sure we can handle this + * kind of audio data. + */ + + /* now, map our properties to the java class */ + set_string (env, header, mimetypeFID, properties->mimetype); + + if (set_string (env, header, endiannessFID, properties->endianness)) + result = JNI_TRUE; + + if (set_string (env, header, channelsFID, properties->channels)) + result = JNI_TRUE; + + if (set_string (env, header, rateFID, properties->rate)) + result = JNI_TRUE; + + if (set_string (env, header, widthFID, properties->width)) + result = JNI_TRUE; + + if (set_string (env, header, depthFID, properties->depth)) + result = JNI_TRUE; + + if (set_string (env, header, isSignedFID, properties->signess)) + result = JNI_TRUE; + + if (set_string (env, header, nameFID, properties->name)) + result = JNI_TRUE; + + /* non primary properties */ + set_string (env, header, layerFID, properties->layer); + set_string (env, header, bitrateFID, properties->bitrate); + set_string (env, header, framedFID, properties->framed); + set_string (env, header, typeFID, properties->type); + + return result; +} + +static gboolean fill_info (GstElement *decoder, AudioProperties *properties) +{ + GstIterator *it = NULL; + gpointer data = NULL; + gboolean result = FALSE; + + it = gst_element_iterate_src_pads (decoder); + while (gst_iterator_next (it, &data) == GST_ITERATOR_OK) + { + GstPad *pad = GST_PAD (data); + GstCaps *caps; + + GstStructure *structure; + + const gchar *caps_string = NULL; + + caps = gst_pad_get_caps (pad); + caps_string = gst_caps_to_string (caps); + + if (g_str_has_prefix (caps_string, "video")) + { + /* no video support, this is an audio library */ + + g_free ((gpointer) caps_string); + gst_caps_unref (caps); + gst_object_unref (pad); + + continue; + } + + g_free ((gpointer) caps_string); + + structure = gst_caps_get_structure (GST_CAPS (caps), 0); + + /* fill the properties we need */ + + /* SIGNESS */ + properties->signess = get_boolean_property(structure, "signed"); + if (properties->signess != NULL) + { + result = TRUE; + } + + /* ENDIANNESS */ + properties->endianness = get_string_property(structure, "endianness"); + if (properties->endianness != NULL) + { + result = TRUE; + } + + /* CHANNELS */ + properties->channels = get_string_property(structure, "channels"); + if (properties->channels != NULL) + { + result = TRUE; + } + + /* RATE */ + properties->rate = get_string_property(structure, "rate"); + if (properties->rate != NULL) + { + result = TRUE; + } + + /* WIDTH */ + properties->width = get_string_property(structure, "width"); + if (properties->width != NULL) + { + result = TRUE; + } + + /* DEPTH */ + properties->depth = get_string_property(structure, "depth"); + if (properties->depth != NULL) + { + result = TRUE; + } + + gst_caps_unref (caps); + gst_object_unref (pad); + } + + return result; +} + +static void +free_properties (AudioProperties *properties __attribute__ ((unused))) +{ + /* FIXME this causes a segfault, a string not allocated by us? double free? */ + /* + if (properties->name != NULL) g_free((gpointer) properties->name); + if (properties->endianness != NULL) g_free((gpointer) properties->endianness); + if (properties->channels != NULL) g_free((gpointer) properties->channels); + if (properties->rate != NULL) g_free((gpointer) properties->rate); + if (properties->width != NULL) g_free((gpointer) properties->width); + if (properties->depth != NULL) g_free((gpointer) properties->depth); + if (properties->layer != NULL) g_free((gpointer) properties->layer); + if (properties->bitrate != NULL) g_free((gpointer) properties->bitrate); + if (properties->framed != NULL) g_free((gpointer) properties->framed); + + if (properties != NULL) g_free ((gpointer) properties); + */ +} + +static void reset_properties (AudioProperties *properties) +{ + properties->done = FALSE; + properties->signess = FALSE; + properties->name = NULL; + properties->endianness = NULL; + properties->channels = NULL; + properties->rate = NULL; + properties->width = NULL; + properties->depth = NULL; + properties->layer = NULL; + properties->bitrate = NULL; + properties->framed = NULL; +} + +static gchar *get_string_property (const GstStructure *structure, + const gchar *property) +{ + int props = 0; + gchar *result = NULL; + + if (property == NULL) + { + return NULL; + } + + /* we don't need more */ + result = (gchar *) g_malloc0 (_GST_MALLOC_SIZE_); + if (result == NULL) + { + /* huston, we have a problem here... */ + return NULL; + } + + if (gst_structure_get_int (structure, property, &props)) + { + g_snprintf (result, _GST_MALLOC_SIZE_, "%d", props); + } + else + { + g_free ((gpointer) result); + return NULL; + } + + return result; +} + +static gchar *get_boolean_property (const GstStructure *structure, + const gchar *property) +{ + gchar *result = NULL; + gboolean props = FALSE; + + result = (gchar *) g_malloc0 (_GST_MALLOC_SIZE_); + if (result == NULL) + { + /* huston, we have a problem here... */ + return NULL; + } + + if (gst_structure_get_boolean (structure, property, &props)) + { + g_snprintf (result, _GST_MALLOC_SIZE_, "%s", (props ? "true" : "false" )); + } + else + { + g_free ((gpointer) result); + return NULL; + } + + return result; +} + +static gboolean set_string (JNIEnv *env, jobject header, jfieldID fieldID, + const gchar *property) +{ + jstring property_string_field = NULL; + + if (property == NULL || header == NULL) + { + return JNI_FALSE; + } + + property_string_field = (*env)->NewStringUTF(env, property); + if (property_string_field == NULL) + { + return JNI_FALSE; + } + + (*env)->SetObjectField(env, header, fieldID, property_string_field); + + return JNI_TRUE; +} + +static void element_added (GstBin *bin, GstElement *element, gpointer data) +{ + GstElementFactory *factory; + + factory = gst_element_get_factory (element); + ((AudioProperties *) data)->name = gst_element_factory_get_longname (factory); +} + +/* ***** END: PRIVATE FUNCTIONS IMPLEMENTATION ***** */ diff --git a/libjava/classpath/native/jni/gtk-peer/.cvsignore b/libjava/classpath/native/jni/gtk-peer/.cvsignore new file mode 100644 index 000000000..e9f2658a6 --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/.cvsignore @@ -0,0 +1,8 @@ +*.o +*.a +*.lo +*.la +.libs +.deps +Makefile +Makefile.in diff --git a/libjava/classpath/native/jni/gtk-peer/GtkDragSourceContextPeer.c b/libjava/classpath/native/jni/gtk-peer/GtkDragSourceContextPeer.c new file mode 100644 index 000000000..aee61bd08 --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/GtkDragSourceContextPeer.c @@ -0,0 +1,330 @@ +/* gtkdragsourcecontextpeer.c -- Native implementation of GtkDragSourceContextPeer + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include "gtkpeer.h" +#include "gnu_java_awt_dnd_peer_gtk_GtkDragSourceContextPeer.h" + +#include +#include + +static GtkWidget * get_widget (GtkWidget *widget); +static void connect_signals_for_widget (GtkWidget *widget); + +#define ACTION_COPY 1 +#define ACTION_MOVE 2 +#define ACTION_COPY_OR_MOVE 3 +#define ACTION_LINK 1073741824 + +#define AWT_DEFAULT_CURSOR 0 +#define AWT_CROSSHAIR_CURSOR 1 +#define AWT_TEXT_CURSOR 2 +#define AWT_WAIT_CURSOR 3 +#define AWT_SW_RESIZE_CURSOR 4 +#define AWT_SE_RESIZE_CURSOR 5 +#define AWT_NW_RESIZE_CURSOR 6 +#define AWT_NE_RESIZE_CURSOR 7 +#define AWT_N_RESIZE_CURSOR 8 +#define AWT_S_RESIZE_CURSOR 9 +#define AWT_W_RESIZE_CURSOR 10 +#define AWT_E_RESIZE_CURSOR 11 +#define AWT_HAND_CURSOR 12 +#define AWT_MOVE_CURSOR 13 + +static jmethodID dragEnterID; +static jmethodID dragExitID; +static jmethodID dragDropEndID; +static jmethodID dragMouseMovedID; +static jmethodID dragOverID; +static jmethodID dragActionChangedID; +static jmethodID acceptDragID; +static jmethodID rejectDragID; +static jmethodID acceptDropID; +static jmethodID rejectDropID; +static jmethodID dropCompleteID; + +GtkWidget *widget; +GtkWidget *tgt; +jobject gref; +jobject javaObj; + +JNIEXPORT void JNICALL +Java_gnu_java_awt_dnd_peer_gtk_GtkDragSourceContextPeer_create + (JNIEnv *env, jobject obj, jobject comp) +{ + gdk_threads_enter (); + + javaObj = obj; + gtkpeer_set_global_ref (env, obj); + gtkpeer_set_global_ref (env, comp); + + gref = gtkpeer_get_widget (env, comp); + widget = get_widget (GTK_WIDGET (gref)); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_dnd_peer_gtk_GtkDragSourceContextPeer_nativeSetCursor + (JNIEnv *env, jobject obj, jint type) +{ + void *ptr; + GdkWindow *win; + GdkCursorType gdk_cursor_type; + GdkCursor *gdk_cursor; + + gdk_threads_enter (); + + javaObj = obj; + ptr = gtkpeer_get_global_ref (env, obj); + + switch (type) + { + case AWT_CROSSHAIR_CURSOR: + gdk_cursor_type = GDK_CROSSHAIR; + break; + case AWT_TEXT_CURSOR: + gdk_cursor_type = GDK_XTERM; + break; + case AWT_WAIT_CURSOR: + gdk_cursor_type = GDK_WATCH; + break; + case AWT_SW_RESIZE_CURSOR: + gdk_cursor_type = GDK_BOTTOM_LEFT_CORNER; + break; + case AWT_SE_RESIZE_CURSOR: + gdk_cursor_type = GDK_BOTTOM_RIGHT_CORNER; + break; + case AWT_NW_RESIZE_CURSOR: + gdk_cursor_type = GDK_TOP_LEFT_CORNER; + break; + case AWT_NE_RESIZE_CURSOR: + gdk_cursor_type = GDK_TOP_RIGHT_CORNER; + break; + case AWT_N_RESIZE_CURSOR: + gdk_cursor_type = GDK_TOP_SIDE; + break; + case AWT_S_RESIZE_CURSOR: + gdk_cursor_type = GDK_BOTTOM_SIDE; + break; + case AWT_W_RESIZE_CURSOR: + gdk_cursor_type = GDK_LEFT_SIDE; + break; + case AWT_E_RESIZE_CURSOR: + gdk_cursor_type = GDK_RIGHT_SIDE; + break; + case AWT_HAND_CURSOR: + gdk_cursor_type = GDK_HAND2; + break; + case AWT_MOVE_CURSOR: + gdk_cursor_type = GDK_FLEUR; + break; + default: + gdk_cursor_type = GDK_LEFT_PTR; + } + + win = widget->window; + if ((widget->window) == NULL) + win = widget->window; + + gdk_cursor = gdk_cursor_new (gdk_cursor_type); + + gdk_window_set_cursor (win, gdk_cursor); + gdk_cursor_unref (gdk_cursor); + + gdk_flush(); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_dnd_peer_gtk_GtkDragSourceContextPeer_connectSignals + (JNIEnv *env, jobject obj, jobject comp) +{ + jclass gtkdragsourcecontextpeer; + jclass gtkdroptargetcontextpeer; + + gdk_threads_enter (); + + javaObj = obj; + gref = gtkpeer_get_global_ref (env, comp); + + connect_signals_for_widget (widget); + + gtkdragsourcecontextpeer = (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(), + "gnu/java/awt/dnd/peer/gtk/GtkDragSourceContextPeer"); + + dragEnterID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkdragsourcecontextpeer, + "dragEnter", "(II)V"); + dragExitID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkdragsourcecontextpeer, + "dragExit", "(III)V"); + dragDropEndID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkdragsourcecontextpeer, + "dragDropEnd", "(IZII)V"); + dragMouseMovedID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkdragsourcecontextpeer, + "dragMouseMoved", "(II)V"); + dragOverID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkdragsourcecontextpeer, + "dragOver", "(II)V"); + dragActionChangedID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkdragsourcecontextpeer, + "dragActionChanged", "(II)V"); + + + gtkdroptargetcontextpeer = (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(), + "gnu/java/awt/dnd/peer/gtk/GtkDropTargetContextPeer"); + + acceptDragID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkdroptargetcontextpeer, + "acceptDrag", "(I)V"); + rejectDragID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkdroptargetcontextpeer, + "rejectDrag", "()V"); + acceptDropID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkdroptargetcontextpeer, + "acceptDrop", "(I)V"); + rejectDropID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkdroptargetcontextpeer, + "rejectDrop", "()V"); + dropCompleteID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkdroptargetcontextpeer, + "dropComplete", "(Z)V"); + + gdk_threads_leave (); +} + +static void +connect_signals_for_widget (GtkWidget *w) +{ + /* FIXME: Not implemented. */ + w = NULL; +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_dnd_peer_gtk_GtkDragSourceContextPeer_setTarget + (JNIEnv *env, jobject obj, jobject target) +{ + void *ptr; + + gdk_threads_enter (); + + javaObj = obj; + ptr = gtkpeer_get_widget (env, target); + tgt = get_widget (GTK_WIDGET (ptr)); + connect_signals_for_widget (tgt); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_dnd_peer_gtk_GtkDragSourceContextPeer_nativeStartDrag + (JNIEnv *env, jobject obj, jobject img, jint x, jint y, jint act, + jstring target) +{ + void *ptr; + const gchar *data; + GtkTargetEntry tar[1]; + GdkEvent *event; + GdkPixbuf *image = NULL; + GdkDragContext *context = NULL; + GdkDragAction action = GDK_ACTION_DEFAULT; + + gdk_threads_enter (); + + javaObj = obj; + ptr = gtkpeer_get_global_ref (env, obj); + + data = (*env)->GetStringUTFChars (env, target, NULL); + tar[0].target = (gchar *) data; + event = gdk_event_new (GDK_ALL_EVENTS_MASK); + + switch (act) + { + case ACTION_COPY: + action = GDK_ACTION_COPY; + break; + case ACTION_MOVE: + action = GDK_ACTION_MOVE; + break; + case ACTION_COPY_OR_MOVE: + action = GDK_ACTION_COPY | GDK_ACTION_MOVE; + break; + case ACTION_LINK: + action = GDK_ACTION_LINK; + break; + default: + action = GDK_ACTION_DEFAULT; + } + + gtk_drag_dest_set (widget, GTK_DEST_DEFAULT_ALL, tar, + sizeof (tar) / sizeof (GtkTargetEntry), + action); + context = gtk_drag_begin (widget, + gtk_target_list_new (tar, sizeof (tar) / sizeof (GtkTargetEntry)), + action, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK, event); + + if (img != NULL) + { + image = cp_gtk_image_get_pixbuf (env, img); + gtk_drag_set_icon_pixbuf (context, image, x, y); + } + + if (tgt != NULL) + gtk_drag_dest_set (tgt, GTK_DEST_DEFAULT_ALL, tar, + sizeof (tar) / sizeof (GtkTargetEntry), + action); + + gdk_event_free (event); + (*env)->ReleaseStringUTFChars (env, target, data); + + gdk_threads_leave (); +} + +static GtkWidget * +get_widget (GtkWidget *widget) +{ + GtkWidget *w; + + if (GTK_IS_EVENT_BOX (widget) || GTK_IS_CONTAINER (widget)) + w = gtk_bin_get_child (GTK_BIN(widget)); + else + w = widget; + + return w; +} diff --git a/libjava/classpath/native/jni/gtk-peer/Makefile.am b/libjava/classpath/native/jni/gtk-peer/Makefile.am new file mode 100644 index 000000000..6ab32636b --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/Makefile.am @@ -0,0 +1,61 @@ +nativeexeclib_LTLIBRARIES = libgtkpeer.la + +# GTK JNI sources. +libgtkpeer_la_SOURCES = gnu_java_awt_peer_gtk_CairoSurface.c \ + gnu_java_awt_peer_gtk_CairoGraphics2D.c \ + gnu_java_awt_peer_gtk_ComponentGraphics.c \ + gnu_java_awt_peer_gtk_ComponentGraphicsCopy.c \ + gnu_java_awt_peer_gtk_FreetypeGlyphVector.c \ + gnu_java_awt_peer_gtk_GdkFontPeer.c \ + gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.c \ + gnu_java_awt_peer_gtk_GdkPixbufDecoder.c \ + gnu_java_awt_peer_gtk_GdkRobotPeer.c \ + gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice.c \ + gnu_java_awt_peer_gtk_GtkButtonPeer.c \ + gnu_java_awt_peer_gtk_GtkCanvasPeer.c \ + gnu_java_awt_peer_gtk_GtkCheckboxMenuItemPeer.c \ + gnu_java_awt_peer_gtk_GtkCheckboxPeer.c \ + gnu_java_awt_peer_gtk_GtkChoicePeer.c \ + gnu_java_awt_peer_gtk_GtkClipboard.c \ + gnu_java_awt_peer_gtk_GtkComponentPeer.c \ + gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer.c \ + gnu_java_awt_peer_gtk_GtkFileDialogPeer.c \ + gnu_java_awt_peer_gtk_GtkFramePeer.c \ + gnu_java_awt_peer_gtk_GtkGenericPeer.c \ + gnu_java_awt_peer_gtk_GtkImage.c \ + gnu_java_awt_peer_gtk_GtkLabelPeer.c \ + gnu_java_awt_peer_gtk_GtkListPeer.c \ + gnu_java_awt_peer_gtk_GtkMenuBarPeer.c \ + gnu_java_awt_peer_gtk_GtkMenuComponentPeer.c \ + gnu_java_awt_peer_gtk_GtkMenuItemPeer.c \ + gnu_java_awt_peer_gtk_GtkMenuPeer.c \ + gnu_java_awt_peer_gtk_GtkPanelPeer.c \ + gnu_java_awt_peer_gtk_GtkPopupMenuPeer.c \ + gnu_java_awt_peer_gtk_GtkScrollbarPeer.c \ + gnu_java_awt_peer_gtk_GtkScrollPanePeer.c \ + gnu_java_awt_peer_gtk_GtkSelection.c \ + gnu_java_awt_peer_gtk_GtkTextAreaPeer.c \ + gnu_java_awt_peer_gtk_GtkTextFieldPeer.c \ + gnu_java_awt_peer_gtk_GtkToolkit.c \ + gnu_java_awt_peer_gtk_GtkWindowPeer.c \ + gnu_java_awt_peer_gtk_GtkVolatileImage.c \ + GtkDragSourceContextPeer.c \ + cairographics2d.h \ + gdkdisplay.h \ + gdkfont.h \ + gtk_jawt.c \ + gtkpeer.c \ + gtkpeer.h + +libgtkpeer_la_LIBADD = $(top_builddir)/native/jni/classpath/jcl.lo +libgtkpeer_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version + +AM_LDFLAGS = @CLASSPATH_MODULE@ @GTK_LIBS@ @FREETYPE2_LIBS@ \ + @PANGOFT2_LIBS@ @X_PRE_LIBS@ @X_LIBS@ @X_EXTRA_LIBS@ @XTEST_LIBS@ +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ + +# Just the WARNING_CFLAGS. We cannot use the strict flags since the gtk +# headers contain broken prototypes (by design, see gtkitemfactory.h). +AM_CFLAGS = @WARNING_CFLAGS@ @ERROR_CFLAGS@ \ + @GTK_CFLAGS@ @FREETYPE2_CFLAGS@ @PANGOFT2_CFLAGS@ \ + @X_CFLAGS@ @EXTRA_CFLAGS@ diff --git a/libjava/classpath/native/jni/gtk-peer/Makefile.in b/libjava/classpath/native/jni/gtk-peer/Makefile.in new file mode 100644 index 000000000..3fc29330a --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/Makefile.in @@ -0,0 +1,743 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +subdir = native/jni/gtk-peer +DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/../../config/depstand.m4 \ + $(top_srcdir)/../../config/lead-dot.m4 \ + $(top_srcdir)/../../config/lib-ld.m4 \ + $(top_srcdir)/../../config/lib-link.m4 \ + $(top_srcdir)/../../config/lib-prefix.m4 \ + $(top_srcdir)/../../config/multi.m4 \ + $(top_srcdir)/../../config/no-executables.m4 \ + $(top_srcdir)/../../config/override.m4 \ + $(top_srcdir)/../../libtool.m4 \ + $(top_srcdir)/../../ltoptions.m4 \ + $(top_srcdir)/../../ltsugar.m4 \ + $(top_srcdir)/../../ltversion.m4 \ + $(top_srcdir)/../../lt~obsolete.m4 \ + $(top_srcdir)/m4/ac_prog_antlr.m4 \ + $(top_srcdir)/m4/ac_prog_java.m4 \ + $(top_srcdir)/m4/ac_prog_java_works.m4 \ + $(top_srcdir)/m4/ac_prog_javac.m4 \ + $(top_srcdir)/m4/ac_prog_javac_works.m4 \ + $(top_srcdir)/m4/acattribute.m4 $(top_srcdir)/m4/accross.m4 \ + $(top_srcdir)/m4/acinclude.m4 \ + $(top_srcdir)/m4/ax_create_stdint_h.m4 \ + $(top_srcdir)/m4/ax_func_which_gethostbyname_r.m4 \ + $(top_srcdir)/m4/gcc_attribute.m4 $(top_srcdir)/m4/iconv.m4 \ + $(top_srcdir)/m4/pkg.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/../../mkinstalldirs +CONFIG_HEADER = $(top_builddir)/include/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__installdirs = "$(DESTDIR)$(nativeexeclibdir)" +LTLIBRARIES = $(nativeexeclib_LTLIBRARIES) +libgtkpeer_la_DEPENDENCIES = \ + $(top_builddir)/native/jni/classpath/jcl.lo +am_libgtkpeer_la_OBJECTS = gnu_java_awt_peer_gtk_CairoSurface.lo \ + gnu_java_awt_peer_gtk_CairoGraphics2D.lo \ + gnu_java_awt_peer_gtk_ComponentGraphics.lo \ + gnu_java_awt_peer_gtk_ComponentGraphicsCopy.lo \ + gnu_java_awt_peer_gtk_FreetypeGlyphVector.lo \ + gnu_java_awt_peer_gtk_GdkFontPeer.lo \ + gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.lo \ + gnu_java_awt_peer_gtk_GdkPixbufDecoder.lo \ + gnu_java_awt_peer_gtk_GdkRobotPeer.lo \ + gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice.lo \ + gnu_java_awt_peer_gtk_GtkButtonPeer.lo \ + gnu_java_awt_peer_gtk_GtkCanvasPeer.lo \ + gnu_java_awt_peer_gtk_GtkCheckboxMenuItemPeer.lo \ + gnu_java_awt_peer_gtk_GtkCheckboxPeer.lo \ + gnu_java_awt_peer_gtk_GtkChoicePeer.lo \ + gnu_java_awt_peer_gtk_GtkClipboard.lo \ + gnu_java_awt_peer_gtk_GtkComponentPeer.lo \ + gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer.lo \ + gnu_java_awt_peer_gtk_GtkFileDialogPeer.lo \ + gnu_java_awt_peer_gtk_GtkFramePeer.lo \ + gnu_java_awt_peer_gtk_GtkGenericPeer.lo \ + gnu_java_awt_peer_gtk_GtkImage.lo \ + gnu_java_awt_peer_gtk_GtkLabelPeer.lo \ + gnu_java_awt_peer_gtk_GtkListPeer.lo \ + gnu_java_awt_peer_gtk_GtkMenuBarPeer.lo \ + gnu_java_awt_peer_gtk_GtkMenuComponentPeer.lo \ + gnu_java_awt_peer_gtk_GtkMenuItemPeer.lo \ + gnu_java_awt_peer_gtk_GtkMenuPeer.lo \ + gnu_java_awt_peer_gtk_GtkPanelPeer.lo \ + gnu_java_awt_peer_gtk_GtkPopupMenuPeer.lo \ + gnu_java_awt_peer_gtk_GtkScrollbarPeer.lo \ + gnu_java_awt_peer_gtk_GtkScrollPanePeer.lo \ + gnu_java_awt_peer_gtk_GtkSelection.lo \ + gnu_java_awt_peer_gtk_GtkTextAreaPeer.lo \ + gnu_java_awt_peer_gtk_GtkTextFieldPeer.lo \ + gnu_java_awt_peer_gtk_GtkToolkit.lo \ + gnu_java_awt_peer_gtk_GtkWindowPeer.lo \ + gnu_java_awt_peer_gtk_GtkVolatileImage.lo \ + GtkDragSourceContextPeer.lo gtk_jawt.lo gtkpeer.lo +libgtkpeer_la_OBJECTS = $(am_libgtkpeer_la_OBJECTS) +libgtkpeer_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(libgtkpeer_la_LDFLAGS) $(LDFLAGS) -o $@ +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/include +depcomp = $(SHELL) $(top_srcdir)/../../depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(libgtkpeer_la_SOURCES) +ETAGS = etags +CTAGS = ctags +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +ANTLR = @ANTLR@ +ANTLR_JAR = @ANTLR_JAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CAIRO_CFLAGS = @CAIRO_CFLAGS@ +CAIRO_LIBS = @CAIRO_LIBS@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CLASSPATH_CONVENIENCE = @CLASSPATH_CONVENIENCE@ +CLASSPATH_INCLUDES = @CLASSPATH_INCLUDES@ +CLASSPATH_MODULE = @CLASSPATH_MODULE@ +COLLECTIONS_PREFIX = @COLLECTIONS_PREFIX@ +CP = @CP@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DATE = @DATE@ +DEFAULT_PREFS_PEER = @DEFAULT_PREFS_PEER@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +ECJ_JAR = @ECJ_JAR@ +EGREP = @EGREP@ +ERROR_CFLAGS = @ERROR_CFLAGS@ +EXAMPLESDIR = @EXAMPLESDIR@ +EXEEXT = @EXEEXT@ +EXTRA_CFLAGS = @EXTRA_CFLAGS@ +FGREP = @FGREP@ +FIND = @FIND@ +FREETYPE2_CFLAGS = @FREETYPE2_CFLAGS@ +FREETYPE2_LIBS = @FREETYPE2_LIBS@ +GCONF_CFLAGS = @GCONF_CFLAGS@ +GCONF_LIBS = @GCONF_LIBS@ +GDK_CFLAGS = @GDK_CFLAGS@ +GDK_LIBS = @GDK_LIBS@ +GJDOC = @GJDOC@ +GLIB_CFLAGS = @GLIB_CFLAGS@ +GLIB_LIBS = @GLIB_LIBS@ +GMP_CFLAGS = @GMP_CFLAGS@ +GMP_LIBS = @GMP_LIBS@ +GREP = @GREP@ +GSTREAMER_BASE_CFLAGS = @GSTREAMER_BASE_CFLAGS@ +GSTREAMER_BASE_LIBS = @GSTREAMER_BASE_LIBS@ +GSTREAMER_CFLAGS = @GSTREAMER_CFLAGS@ +GSTREAMER_FILE_READER = @GSTREAMER_FILE_READER@ +GSTREAMER_LIBS = @GSTREAMER_LIBS@ +GSTREAMER_MIXER_PROVIDER = @GSTREAMER_MIXER_PROVIDER@ +GSTREAMER_PLUGINS_BASE_CFLAGS = @GSTREAMER_PLUGINS_BASE_CFLAGS@ +GSTREAMER_PLUGINS_BASE_LIBS = @GSTREAMER_PLUGINS_BASE_LIBS@ +GST_PLUGIN_LDFLAGS = @GST_PLUGIN_LDFLAGS@ +GTK_CFLAGS = @GTK_CFLAGS@ +GTK_LIBS = @GTK_LIBS@ +INIT_LOAD_LIBRARY = @INIT_LOAD_LIBRARY@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAR = @JAR@ +JAVA = @JAVA@ +JAVAC = @JAVAC@ +JAVAC_IS_GCJ = @JAVAC_IS_GCJ@ +JAVAC_MEM_OPT = @JAVAC_MEM_OPT@ +JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION = @JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION@ +JAY = @JAY@ +JAY_SKELETON = @JAY_SKELETON@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBDEBUG = @LIBDEBUG@ +LIBICONV = @LIBICONV@ +LIBMAGIC = @LIBMAGIC@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBVERSION = @LIBVERSION@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBICONV = @LTLIBICONV@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MKDIR = @MKDIR@ +MKDIR_P = @MKDIR_P@ +MOC = @MOC@ +MOZILLA_CFLAGS = @MOZILLA_CFLAGS@ +MOZILLA_LIBS = @MOZILLA_LIBS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PANGOFT2_CFLAGS = @PANGOFT2_CFLAGS@ +PANGOFT2_LIBS = @PANGOFT2_LIBS@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PATH_TO_ESCHER = @PATH_TO_ESCHER@ +PATH_TO_GLIBJ_ZIP = @PATH_TO_GLIBJ_ZIP@ +PERL = @PERL@ +PKG_CONFIG = @PKG_CONFIG@ +PLUGIN_DIR = @PLUGIN_DIR@ +QT_CFLAGS = @QT_CFLAGS@ +QT_LIBS = @QT_LIBS@ +RANLIB = @RANLIB@ +REMOVE = @REMOVE@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRICT_WARNING_CFLAGS = @STRICT_WARNING_CFLAGS@ +STRIP = @STRIP@ +TOOLSDIR = @TOOLSDIR@ +USER_JAVAH = @USER_JAVAH@ +VERSION = @VERSION@ +WANT_NATIVE_BIG_INTEGER = @WANT_NATIVE_BIG_INTEGER@ +WARNING_CFLAGS = @WARNING_CFLAGS@ +XMKMF = @XMKMF@ +XML_CFLAGS = @XML_CFLAGS@ +XML_LIBS = @XML_LIBS@ +XSLT_CFLAGS = @XSLT_CFLAGS@ +XSLT_LIBS = @XSLT_LIBS@ +XTEST_LIBS = @XTEST_LIBS@ +X_CFLAGS = @X_CFLAGS@ +X_EXTRA_LIBS = @X_EXTRA_LIBS@ +X_LIBS = @X_LIBS@ +X_PRE_LIBS = @X_PRE_LIBS@ +ZIP = @ZIP@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_ANTLR = @ac_ct_ANTLR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +default_toolkit = @default_toolkit@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +glibjdir = @glibjdir@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +multi_basedir = @multi_basedir@ +nativeexeclibdir = @nativeexeclibdir@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +toolexeclibdir = @toolexeclibdir@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +uudecode = @uudecode@ +vm_classes = @vm_classes@ +nativeexeclib_LTLIBRARIES = libgtkpeer.la + +# GTK JNI sources. +libgtkpeer_la_SOURCES = gnu_java_awt_peer_gtk_CairoSurface.c \ + gnu_java_awt_peer_gtk_CairoGraphics2D.c \ + gnu_java_awt_peer_gtk_ComponentGraphics.c \ + gnu_java_awt_peer_gtk_ComponentGraphicsCopy.c \ + gnu_java_awt_peer_gtk_FreetypeGlyphVector.c \ + gnu_java_awt_peer_gtk_GdkFontPeer.c \ + gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.c \ + gnu_java_awt_peer_gtk_GdkPixbufDecoder.c \ + gnu_java_awt_peer_gtk_GdkRobotPeer.c \ + gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice.c \ + gnu_java_awt_peer_gtk_GtkButtonPeer.c \ + gnu_java_awt_peer_gtk_GtkCanvasPeer.c \ + gnu_java_awt_peer_gtk_GtkCheckboxMenuItemPeer.c \ + gnu_java_awt_peer_gtk_GtkCheckboxPeer.c \ + gnu_java_awt_peer_gtk_GtkChoicePeer.c \ + gnu_java_awt_peer_gtk_GtkClipboard.c \ + gnu_java_awt_peer_gtk_GtkComponentPeer.c \ + gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer.c \ + gnu_java_awt_peer_gtk_GtkFileDialogPeer.c \ + gnu_java_awt_peer_gtk_GtkFramePeer.c \ + gnu_java_awt_peer_gtk_GtkGenericPeer.c \ + gnu_java_awt_peer_gtk_GtkImage.c \ + gnu_java_awt_peer_gtk_GtkLabelPeer.c \ + gnu_java_awt_peer_gtk_GtkListPeer.c \ + gnu_java_awt_peer_gtk_GtkMenuBarPeer.c \ + gnu_java_awt_peer_gtk_GtkMenuComponentPeer.c \ + gnu_java_awt_peer_gtk_GtkMenuItemPeer.c \ + gnu_java_awt_peer_gtk_GtkMenuPeer.c \ + gnu_java_awt_peer_gtk_GtkPanelPeer.c \ + gnu_java_awt_peer_gtk_GtkPopupMenuPeer.c \ + gnu_java_awt_peer_gtk_GtkScrollbarPeer.c \ + gnu_java_awt_peer_gtk_GtkScrollPanePeer.c \ + gnu_java_awt_peer_gtk_GtkSelection.c \ + gnu_java_awt_peer_gtk_GtkTextAreaPeer.c \ + gnu_java_awt_peer_gtk_GtkTextFieldPeer.c \ + gnu_java_awt_peer_gtk_GtkToolkit.c \ + gnu_java_awt_peer_gtk_GtkWindowPeer.c \ + gnu_java_awt_peer_gtk_GtkVolatileImage.c \ + GtkDragSourceContextPeer.c \ + cairographics2d.h \ + gdkdisplay.h \ + gdkfont.h \ + gtk_jawt.c \ + gtkpeer.c \ + gtkpeer.h + +libgtkpeer_la_LIBADD = $(top_builddir)/native/jni/classpath/jcl.lo +libgtkpeer_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version +AM_LDFLAGS = @CLASSPATH_MODULE@ @GTK_LIBS@ @FREETYPE2_LIBS@ \ + @PANGOFT2_LIBS@ @X_PRE_LIBS@ @X_LIBS@ @X_EXTRA_LIBS@ @XTEST_LIBS@ + +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ + +# Just the WARNING_CFLAGS. We cannot use the strict flags since the gtk +# headers contain broken prototypes (by design, see gtkitemfactory.h). +AM_CFLAGS = @WARNING_CFLAGS@ @ERROR_CFLAGS@ \ + @GTK_CFLAGS@ @FREETYPE2_CFLAGS@ @PANGOFT2_CFLAGS@ \ + @X_CFLAGS@ @EXTRA_CFLAGS@ + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu native/jni/gtk-peer/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu native/jni/gtk-peer/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-nativeexeclibLTLIBRARIES: $(nativeexeclib_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(nativeexeclibdir)" || $(MKDIR_P) "$(DESTDIR)$(nativeexeclibdir)" + @list='$(nativeexeclib_LTLIBRARIES)'; test -n "$(nativeexeclibdir)" || list=; \ + list2=; for p in $$list; do \ + if test -f $$p; then \ + list2="$$list2 $$p"; \ + else :; fi; \ + done; \ + test -z "$$list2" || { \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(nativeexeclibdir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(nativeexeclibdir)"; \ + } + +uninstall-nativeexeclibLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(nativeexeclib_LTLIBRARIES)'; test -n "$(nativeexeclibdir)" || list=; \ + for p in $$list; do \ + $(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(nativeexeclibdir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(nativeexeclibdir)/$$f"; \ + done + +clean-nativeexeclibLTLIBRARIES: + -test -z "$(nativeexeclib_LTLIBRARIES)" || rm -f $(nativeexeclib_LTLIBRARIES) + @list='$(nativeexeclib_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libgtkpeer.la: $(libgtkpeer_la_OBJECTS) $(libgtkpeer_la_DEPENDENCIES) + $(libgtkpeer_la_LINK) -rpath $(nativeexeclibdir) $(libgtkpeer_la_OBJECTS) $(libgtkpeer_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/GtkDragSourceContextPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_CairoGraphics2D.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_CairoSurface.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_ComponentGraphics.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_ComponentGraphicsCopy.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_FreetypeGlyphVector.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GdkFontPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GdkPixbufDecoder.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GdkRobotPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkButtonPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkCanvasPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkCheckboxMenuItemPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkCheckboxPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkChoicePeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkClipboard.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkComponentPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkFileDialogPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkFramePeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkGenericPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkImage.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkLabelPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkListPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkMenuBarPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkMenuComponentPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkMenuItemPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkMenuPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkPanelPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkPopupMenuPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkScrollPanePeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkScrollbarPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkSelection.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkTextAreaPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkTextFieldPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkToolkit.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkVolatileImage.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_awt_peer_gtk_GtkWindowPeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gtk_jawt.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gtkpeer.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) +installdirs: + for dir in "$(DESTDIR)$(nativeexeclibdir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-nativeexeclibLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-nativeexeclibLTLIBRARIES + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-nativeexeclibLTLIBRARIES + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-nativeexeclibLTLIBRARIES ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags dvi dvi-am html html-am info info-am install \ + install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-nativeexeclibLTLIBRARIES install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-nativeexeclibLTLIBRARIES + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/libjava/classpath/native/jni/gtk-peer/cairographics2d.h b/libjava/classpath/native/jni/gtk-peer/cairographics2d.h new file mode 100644 index 000000000..d5611bff6 --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/cairographics2d.h @@ -0,0 +1,116 @@ +/* cairographics2d.h -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#ifndef CAIROGRAPHICS2D_H +#define CAIROGRAPHICS2D_H + + +#include +#include +#include +#include +#include +#include +#include + +#include + +/* + * These public final constants are part of the java2d public API, so we + * write them explicitly here to save fetching them from the constant pool + * all the time. + */ +enum java_awt_alpha_composite_rule + { + java_awt_alpha_composite_CLEAR = 1, + java_awt_alpha_composite_SRC = 2, + java_awt_alpha_composite_SRC_OVER = 3, + java_awt_alpha_composite_DST_OVER = 4, + java_awt_alpha_composite_SRC_IN = 5, + java_awt_alpha_composite_DST_IN = 6, + java_awt_alpha_composite_SRC_OUT = 7, + java_awt_alpha_composite_DST_OUT = 8, + java_awt_alpha_composite_DST = 9, + java_awt_alpha_composite_SRC_ATOP = 10, + java_awt_alpha_composite_DST_ATOP = 11, + java_awt_alpha_composite_XOR = 12 + }; + +enum java_awt_basic_stroke_join_rule + { + java_awt_basic_stroke_JOIN_MITER = 0, + java_awt_basic_stroke_JOIN_ROUND = 1, + java_awt_basic_stroke_JOIN_BEVEL = 2 + }; + +enum java_awt_basic_stroke_cap_rule + { + java_awt_basic_stroke_CAP_BUTT = 0, + java_awt_basic_stroke_CAP_ROUND = 1, + java_awt_basic_stroke_CAP_SQUARE = 2 + }; + +enum java_awt_geom_path_iterator_winding_rule + { + java_awt_geom_path_iterator_WIND_EVEN_ODD = 0, + java_awt_geom_path_iterator_WIND_NON_ZERO = 1 + }; + +enum java_awt_rendering_hints_filter + { + java_awt_rendering_hints_VALUE_INTERPOLATION_NEAREST_NEIGHBOR = 0, + java_awt_rendering_hints_VALUE_INTERPOLATION_BILINEAR = 1, + java_awt_rendering_hints_VALUE_ALPHA_INTERPOLATION_SPEED = 2, + java_awt_rendering_hints_VALUE_ALPHA_INTERPOLATION_QUALITY = 3, + java_awt_rendering_hints_VALUE_ALPHA_INTERPOLATION_DEFAULT = 4, + java_awt_rendering_hints_VALUE_INTERPOLATION_BICUBIC = 5 + + }; + +/** + * A structure which basically contains the cairo_t pointer. + * The rest is for gradient and texture fills. + */ +struct cairographics2d +{ + cairo_t *cr; + cairo_surface_t *pattern_surface; + cairo_pattern_t *pattern; + char *pattern_pixels; +}; + +#endif diff --git a/libjava/classpath/native/jni/gtk-peer/gdkdisplay.h b/libjava/classpath/native/jni/gtk-peer/gdkdisplay.h new file mode 100644 index 000000000..e15f08e69 --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gdkdisplay.h @@ -0,0 +1,43 @@ +#ifndef __GDKDISPLAY_H__ +#define __GDKDISPLAY_H__ + +/* gdkdisplay.h -- Some global stuff related to displays & screens + Copyright (C) 2006 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + +#include "gtkpeer.h" + +#endif /* __GDKDISPLAY_H__ */ diff --git a/libjava/classpath/native/jni/gtk-peer/gdkfont.h b/libjava/classpath/native/jni/gtk-peer/gdkfont.h new file mode 100644 index 000000000..241a05f7d --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gdkfont.h @@ -0,0 +1,105 @@ +#ifndef __GDKFONT_H__ +#define __GDKFONT_H__ + +/* gdkfont.h -- Some global stuff related to fonts and glyphs + Copyright (C) 2003 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + +#include "gtkpeer.h" + +#define PANGO_ENABLE_ENGINE +#include +#include +#include +#include + +#define FONT_METRICS_ASCENT 0 +#define FONT_METRICS_MAX_ASCENT 1 +#define FONT_METRICS_DESCENT 2 +#define FONT_METRICS_MAX_DESCENT 3 +#define FONT_METRICS_MAX_ADVANCE 4 +#define FONT_METRICS_HEIGHT 5 +#define FONT_METRICS_UNDERLINE_OFFSET 6 +#define FONT_METRICS_UNDERLINE_THICKNESS 7 +#define NUM_FONT_METRICS 8 + +#define TEXT_METRICS_X_BEARING 0 +#define TEXT_METRICS_Y_BEARING 1 +#define TEXT_METRICS_WIDTH 2 +#define TEXT_METRICS_HEIGHT 3 +#define TEXT_METRICS_X_ADVANCE 4 +#define TEXT_METRICS_Y_ADVANCE 5 +#define NUM_TEXT_METRICS 6 + +#define NUM_GLYPH_METRICS 10 + +#define GLYPH_LOG_X(i) (NUM_GLYPH_METRICS * (i) ) +#define GLYPH_LOG_Y(i) (NUM_GLYPH_METRICS * (i) + 1) +#define GLYPH_LOG_WIDTH(i) (NUM_GLYPH_METRICS * (i) + 2) +#define GLYPH_LOG_HEIGHT(i) (NUM_GLYPH_METRICS * (i) + 3) + +#define GLYPH_INK_X(i) (NUM_GLYPH_METRICS * (i) + 4) +#define GLYPH_INK_Y(i) (NUM_GLYPH_METRICS * (i) + 5) +#define GLYPH_INK_WIDTH(i) (NUM_GLYPH_METRICS * (i) + 6) +#define GLYPH_INK_HEIGHT(i) (NUM_GLYPH_METRICS * (i) + 7) + +#define GLYPH_POS_X(i) (NUM_GLYPH_METRICS * (i) + 8) +#define GLYPH_POS_Y(i) (NUM_GLYPH_METRICS * (i) + 9) + +struct peerfont +{ + PangoFont *font; + PangoFontset *set; + PangoFontDescription *desc; + PangoContext *ctx; + PangoLayout *layout; + /* + * The GdkGraphics2D (using cairo) may store a pointer to a + * cairo_font_t here; since we want to work equally well with + * the GdkGraphics class (using GDK) we do not explicitly mention + * cairo types here; it is up to the higher level driver routine + * in GdkClasspathFontPeer.java to decide which backend functions + * to invoke. + */ + void *graphics_resource; +}; + +struct textlayout +{ + PangoLayout *pango_layout; +}; + +#endif /* __GDKFONT_H__ */ diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c new file mode 100644 index 000000000..58f003e86 --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c @@ -0,0 +1,749 @@ +/* gnu_java_awt_peer_gtk_CairoGraphics2d.c + Copyright (C) 2006, 2008 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include "jcl.h" +#include "gdkfont.h" +#include "cairographics2d.h" +#include "gnu_java_awt_peer_gtk_CairoGraphics2D.h" +#include +#include + +#include + +#include +#include + +static void update_pattern_transform (struct cairographics2d *gr); + +/** + * Allocates the cairographics2d structure. + */ +JNIEXPORT jlong JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_init + (JNIEnv *env __attribute__ ((unused)), + jobject obj __attribute__ ((unused)), + jlong cairo_t_pointer) +{ + struct cairographics2d *g = NULL; + cairo_t *cr = JLONG_TO_PTR(cairo_t, cairo_t_pointer); + g_assert(cr != NULL); + + g = (struct cairographics2d *) g_malloc (sizeof (struct cairographics2d)); + + g_assert (g != NULL); + memset (g, 0, sizeof(struct cairographics2d)); + g->cr = cr; + + return PTR_TO_JLONG(g); +} + +/** + * Disposes of the cairographics2d structure. + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_disposeNative + (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + + if (gr == NULL) + return; + + if (gr->cr) + { + gdk_threads_enter(); + cairo_destroy (gr->cr); + gdk_threads_leave(); + } + + if (gr->pattern) + cairo_pattern_destroy (gr->pattern); + gr->pattern = NULL; + + if (gr->pattern_surface) + cairo_surface_destroy (gr->pattern_surface); + gr->pattern_surface = NULL; + + if (gr->pattern_pixels) + g_free(gr->pattern_pixels); + gr->pattern_pixels = NULL; + + g_free( gr ); +} + +/** + * Set the gradient. + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_setGradient + (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer, + jdouble x1, jdouble y1, + jdouble x2, jdouble y2, + jint r1, jint g1, jint b1, jint a1, + jint r2, jint g2, jint b2, jint a2, + jboolean cyclic) +{ + struct cairographics2d *gr = NULL; + cairo_pattern_t* pattern; + cairo_extend_t extend; + + gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert( gr != NULL ); + + pattern = cairo_pattern_create_linear(x1, y1, x2, y2); + g_assert( pattern != NULL ); + + cairo_pattern_add_color_stop_rgba(pattern, 0.0, r1 / 255.0, g1 / 255.0, + b1 / 255.0, a1 / 255.0); + + cairo_pattern_add_color_stop_rgba(pattern, 1.0, r2 / 255.0, g2 / 255.0, + b2 / 255.0, a2 / 255.0); + + #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 2, 0) + extend = (cyclic == JNI_TRUE) ? CAIRO_EXTEND_REFLECT : CAIRO_EXTEND_PAD; + #else + extend = (cyclic == JNI_TRUE) ? CAIRO_EXTEND_REFLECT : CAIRO_EXTEND_NONE; + #endif + + cairo_pattern_set_extend( pattern, extend ); + + gr->pattern = pattern; + cairo_set_source(gr->cr, gr->pattern); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_setPaintPixels + (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer, jintArray jarr, jint w, jint h, jint stride, jboolean repeat, + jint x, jint y) +{ + struct cairographics2d *gr = NULL; + jint *jpixels = NULL; + + gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + if (gr->pattern) + cairo_pattern_destroy (gr->pattern); + + if (gr->pattern_surface) + cairo_surface_destroy (gr->pattern_surface); + + if (gr->pattern_pixels) + g_free (gr->pattern_pixels); + + gr->pattern = NULL; + gr->pattern_surface = NULL; + gr->pattern_pixels = NULL; + + gr->pattern_pixels = (char *) g_malloc (h * stride * 4); + g_assert (gr->pattern_pixels != NULL); + + jpixels = (*env)->GetIntArrayElements (env, jarr, NULL); + g_assert (jpixels != NULL); + memcpy (gr->pattern_pixels, jpixels, h * stride * 4); + (*env)->ReleaseIntArrayElements (env, jarr, jpixels, 0); + + gr->pattern_surface = cairo_image_surface_create_for_data ((unsigned char *)gr->pattern_pixels, + CAIRO_FORMAT_ARGB32, + w, h, stride * 4); + g_assert (gr->pattern_surface != NULL); + gr->pattern = cairo_pattern_create_for_surface (gr->pattern_surface); + g_assert (gr->pattern != NULL); + + cairo_set_source_surface(gr->cr, gr->pattern_surface, x, y); + + if (repeat) + cairo_pattern_set_extend(cairo_get_source(gr->cr), CAIRO_EXTEND_REPEAT); + else + cairo_pattern_set_extend(cairo_get_source(gr->cr), CAIRO_EXTEND_NONE); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_drawPixels +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer, jintArray java_pixels, + jint w, jint h, jint stride, jdoubleArray java_matrix, jdouble alpha, + jint interpolation) +{ + jint *native_pixels = NULL; + jdouble *native_matrix = NULL; + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + native_pixels = (*env)->GetIntArrayElements (env, java_pixels, NULL); + native_matrix = (*env)->GetDoubleArrayElements (env, java_matrix, NULL); + g_assert (native_pixels != NULL); + g_assert (native_matrix != NULL); + g_assert ((*env)->GetArrayLength (env, java_matrix) == 6); + + { + cairo_matrix_t mat; + cairo_pattern_t *p; + cairo_surface_t *surf = cairo_image_surface_create_for_data ((unsigned char *)native_pixels, + CAIRO_FORMAT_ARGB32, + w, h, stride * 4); + cairo_matrix_init_identity (&mat); + cairo_matrix_init (&mat, + native_matrix[0], native_matrix[1], + native_matrix[2], native_matrix[3], + native_matrix[4], native_matrix[5]); + + p = cairo_pattern_create_for_surface (surf); + cairo_pattern_set_matrix (p, &mat); + switch ((enum java_awt_rendering_hints_filter) interpolation) + { + case java_awt_rendering_hints_VALUE_INTERPOLATION_NEAREST_NEIGHBOR: + cairo_pattern_set_filter (p, CAIRO_FILTER_NEAREST); + break; + case java_awt_rendering_hints_VALUE_INTERPOLATION_BILINEAR: + cairo_pattern_set_filter (p, CAIRO_FILTER_BILINEAR); + break; + case java_awt_rendering_hints_VALUE_INTERPOLATION_BICUBIC: + cairo_pattern_set_filter (p, CAIRO_FILTER_GAUSSIAN); + break; + case java_awt_rendering_hints_VALUE_ALPHA_INTERPOLATION_SPEED: + cairo_pattern_set_filter (p, CAIRO_FILTER_FAST); + break; + case java_awt_rendering_hints_VALUE_ALPHA_INTERPOLATION_DEFAULT: + cairo_pattern_set_filter (p, CAIRO_FILTER_NEAREST); + break; + case java_awt_rendering_hints_VALUE_ALPHA_INTERPOLATION_QUALITY: + cairo_pattern_set_filter (p, CAIRO_FILTER_BEST); + break; + } + + cairo_set_source (gr->cr, p); + if (alpha == 1.) + cairo_paint (gr->cr); + else + cairo_paint_with_alpha(gr->cr, alpha); + + cairo_pattern_destroy (p); + cairo_surface_destroy (surf); + } + + (*env)->ReleaseIntArrayElements (env, java_pixels, native_pixels, 0); + (*env)->ReleaseDoubleArrayElements (env, java_matrix, native_matrix, 0); +} + + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoSetMatrix +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer, jdoubleArray java_matrix) +{ + jdouble *native_matrix = NULL; + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + native_matrix = (*env)->GetDoubleArrayElements (env, java_matrix, NULL); + g_assert (native_matrix != NULL); + g_assert ((*env)->GetArrayLength (env, java_matrix) == 6); + + { + cairo_matrix_t mat; + + cairo_matrix_init_identity (&mat); + cairo_matrix_init (&mat, + native_matrix[0], native_matrix[1], + native_matrix[2], native_matrix[3], + native_matrix[4], native_matrix[5]); + g_assert (gr != NULL); + cairo_set_matrix (gr->cr, &mat); + } + + (*env)->ReleaseDoubleArrayElements (env, java_matrix, native_matrix, 0); + update_pattern_transform (gr); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoScale +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer, jdouble x, jdouble y) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + cairo_scale (gr->cr, x, y); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoDrawGlyphVector +(JNIEnv *env, jobject obj __attribute__((unused)), jlong pointer, + jobject font, + jfloat x, jfloat y, jint n, + jintArray java_codes, + jfloatArray java_positions, jlongArray java_fontset) +{ + struct cairographics2d *gr = NULL; + struct peerfont *pfont = NULL; + cairo_glyph_t *glyphs = NULL; + int *native_codes; + float *native_positions; + jint i = 0; + + g_assert (java_codes != NULL); + g_assert (java_positions != NULL); + + gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + pfont = (struct peerfont *) gtkpeer_get_font(env, font); + g_assert (pfont != NULL); + + glyphs = g_malloc( sizeof(cairo_glyph_t) * n); + g_assert (glyphs != NULL); + + native_codes = (*env)->GetIntArrayElements (env, java_codes, NULL); + native_positions = (*env)->GetFloatArrayElements (env, java_positions, NULL); + + /* Set up glyphs and layout */ + for (i = 0; i < n; ++i) + { + glyphs[i].index = native_codes[i]; + glyphs[i].x = x + native_positions[ 2*i ]; + glyphs[i].y = y + native_positions[ 2*i + 1]; + } + + (*env)->ReleaseFloatArrayElements (env, java_positions, native_positions, 0); + (*env)->ReleaseIntArrayElements (env, java_codes, native_codes, 0); + + /* Iterate through glyphs and draw */ + jlong* fonts = (*env)->GetLongArrayElements (env, java_fontset, NULL); + gdk_threads_enter(); + for (i = 0; i < n; i++) + { + PangoFcFont *font = JLONG_TO_PTR(PangoFcFont, fonts[i]); + + /* Draw as many glyphs as possible with the current font */ + int length = 0; + while (i < n-1 && fonts[i] == fonts[i+1]) + { + length++; + i++; + } + + FT_Face face = pango_fc_font_lock_face( font ); + cairo_font_face_t *ft = cairo_ft_font_face_create_for_ft_face (face, 0); + g_assert (ft != NULL); + + cairo_set_font_face (gr->cr, ft); + cairo_show_glyphs (gr->cr, &glyphs[i-length], length+1); + + cairo_font_face_destroy (ft); + pango_fc_font_unlock_face(font); + } + gdk_threads_leave(); + + (*env)->ReleaseLongArrayElements (env, java_fontset, fonts, 0); + g_free(glyphs); +} + + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoSetFont +(JNIEnv *env __attribute__ ((unused)), jobject obj __attribute__ ((unused)), + jlong pointer, jobject font) +{ + struct cairographics2d *gr = NULL; + struct peerfont *pfont = NULL; + FT_Face face = NULL; + cairo_font_face_t *ft = NULL; + + gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + pfont = (struct peerfont *) gtkpeer_get_font(env, font); + g_assert (pfont != NULL); + + gdk_threads_enter(); + face = pango_fc_font_lock_face( (PangoFcFont *)pfont->font ); + g_assert (face != NULL); + + ft = cairo_ft_font_face_create_for_ft_face (face, 0); + g_assert (ft != NULL); + + cairo_set_font_face (gr->cr, ft); + cairo_set_font_size (gr->cr, + (pango_font_description_get_size (pfont->desc) / + (double)PANGO_SCALE)); + + cairo_font_face_destroy (ft); + pango_fc_font_unlock_face((PangoFcFont *)pfont->font); + gdk_threads_leave(); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoSetOperator +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer, jint op) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + switch ((enum java_awt_alpha_composite_rule) op) + { + case java_awt_alpha_composite_CLEAR: + cairo_set_operator (gr->cr, CAIRO_OPERATOR_CLEAR); + break; + + case java_awt_alpha_composite_SRC: + cairo_set_operator (gr->cr, CAIRO_OPERATOR_SOURCE); + break; + + case java_awt_alpha_composite_SRC_OVER: + cairo_set_operator (gr->cr, CAIRO_OPERATOR_OVER); + break; + + case java_awt_alpha_composite_DST_OVER: + cairo_set_operator (gr->cr, CAIRO_OPERATOR_DEST_OVER); + break; + + case java_awt_alpha_composite_SRC_IN: + cairo_set_operator (gr->cr, CAIRO_OPERATOR_IN); + break; + + case java_awt_alpha_composite_DST_IN: + cairo_set_operator (gr->cr, CAIRO_OPERATOR_DEST_IN); + break; + + case java_awt_alpha_composite_SRC_OUT: + cairo_set_operator (gr->cr, CAIRO_OPERATOR_OUT); + break; + + case java_awt_alpha_composite_DST_OUT: + cairo_set_operator (gr->cr, CAIRO_OPERATOR_DEST_OUT); + break; + + case java_awt_alpha_composite_DST: + cairo_set_operator (gr->cr, CAIRO_OPERATOR_DEST); + break; + + case java_awt_alpha_composite_SRC_ATOP: + cairo_set_operator (gr->cr, CAIRO_OPERATOR_ATOP); + break; + + case java_awt_alpha_composite_DST_ATOP: + cairo_set_operator (gr->cr, CAIRO_OPERATOR_DEST_ATOP); + break; + + case java_awt_alpha_composite_XOR: + cairo_set_operator (gr->cr, CAIRO_OPERATOR_XOR); + break; + } +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoSetRGBAColor +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer, jdouble r, jdouble g, jdouble b, jdouble a) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + cairo_set_source_rgba (gr->cr, r, g, b, a); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoSetFillRule +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer, jint rule) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + switch ((enum java_awt_geom_path_iterator_winding_rule) rule) + { + case java_awt_geom_path_iterator_WIND_NON_ZERO: + cairo_set_fill_rule (gr->cr, CAIRO_FILL_RULE_WINDING); + break; + case java_awt_geom_path_iterator_WIND_EVEN_ODD: + cairo_set_fill_rule (gr->cr, CAIRO_FILL_RULE_EVEN_ODD); + break; + } +} + +/** + * Set the line style, except for dashes. + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoSetLine +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer, jdouble width, jint cap, jint join, jdouble miterLimit) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + /* set width */ + cairo_set_line_width (gr->cr, width); + + /* set cap */ + switch ((enum java_awt_basic_stroke_cap_rule) cap) + { + case java_awt_basic_stroke_CAP_BUTT: + cairo_set_line_cap (gr->cr, CAIRO_LINE_CAP_BUTT); + break; + + case java_awt_basic_stroke_CAP_ROUND: + cairo_set_line_cap (gr->cr, CAIRO_LINE_CAP_ROUND); + break; + + case java_awt_basic_stroke_CAP_SQUARE: + cairo_set_line_cap (gr->cr, CAIRO_LINE_CAP_SQUARE); + break; + } + + /* set join */ + switch ((enum java_awt_basic_stroke_join_rule) join) + { + case java_awt_basic_stroke_JOIN_MITER: + cairo_set_line_join (gr->cr, CAIRO_LINE_JOIN_MITER); + break; + + case java_awt_basic_stroke_JOIN_ROUND: + cairo_set_line_join (gr->cr, CAIRO_LINE_JOIN_ROUND); + break; + + case java_awt_basic_stroke_JOIN_BEVEL: + cairo_set_line_join (gr->cr, CAIRO_LINE_JOIN_BEVEL); + break; + } + + /* set miter */ + cairo_set_miter_limit (gr->cr, miterLimit); +} + +/** + * Set the line dashes + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoSetDash +(JNIEnv *env, jobject obj __attribute__((unused)), + jlong pointer, jdoubleArray dashes, jint ndash, jdouble offset) +{ + jdouble *dasharr = NULL; + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + dasharr = (*env)->GetDoubleArrayElements (env, dashes, NULL); + g_assert (dasharr != NULL); + + cairo_set_dash (gr->cr, dasharr, ndash, offset); + + (*env)->ReleaseDoubleArrayElements (env, dashes, dasharr, 0); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoSave +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + cairo_save (gr->cr); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoRestore +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + cairo_restore (gr->cr); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoNewPath +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + cairo_new_path (gr->cr); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoMoveTo +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer, jdouble x, jdouble y) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + cairo_move_to (gr->cr, x, y); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoLineTo +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer, jdouble x, jdouble y) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + cairo_line_to (gr->cr, x, y); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoCurveTo +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer, jdouble x1, jdouble y1, + jdouble x2, jdouble y2, jdouble x3, jdouble y3) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + cairo_curve_to (gr->cr, x1, y1, x2, y2, x3, y3); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoRectangle +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer, jdouble x, jdouble y, jdouble width, jdouble height) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + + cairo_rectangle (gr->cr, x, y, width, height); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoArc +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer, jdouble x, jdouble y, jdouble radius, jdouble angle1, + jdouble angle2) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + + cairo_arc (gr->cr, x, y, radius, angle1, angle2); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoClosePath +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + cairo_close_path (gr->cr); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoStroke +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + cairo_stroke (gr->cr); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoFill +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer, jdouble alpha) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + if (alpha == 1.0) + cairo_fill (gr->cr); + else + { + cairo_save(gr->cr); + cairo_clip(gr->cr); + cairo_paint_with_alpha(gr->cr, alpha); + cairo_restore(gr->cr); + } +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoClip +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert( gr != NULL ); + + cairo_clip( gr->cr ); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoResetClip +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + cairo_reset_clip( gr->cr ); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoSetAntialias +(JNIEnv *env __attribute__ ((unused)), jobject obj __attribute__ ((unused)), + jlong pointer, jboolean aa) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer); + g_assert (gr != NULL); + + if (aa) + cairo_set_antialias(gr->cr, CAIRO_ANTIALIAS_GRAY); + else + cairo_set_antialias(gr->cr, CAIRO_ANTIALIAS_NONE); +} + +static void +update_pattern_transform (struct cairographics2d *gr) +{ + cairo_matrix_t mat; + + g_assert (gr != NULL); + if (gr->pattern == NULL) + return; + + cairo_get_matrix (gr->cr, &mat); + cairo_pattern_set_matrix (gr->pattern, &mat); +} + diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c new file mode 100644 index 000000000..23340fb5b --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c @@ -0,0 +1,333 @@ +/* gnu_java_awt_peer_gtk_CairoSurface.c + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include "jcl.h" +#include "gtkpeer.h" + +#include "gnu_java_awt_peer_gtk_CairoSurface.h" +#include "cairographics2d.h" + +/** + * Field names in CairoSurface.java + */ +#define SURFACE "surfacePointer" +#define SHARED "sharedBuffer" + +/* prototypes */ +static void setNativeObject( JNIEnv *env, jobject obj, void *ptr, const char *pointer ); + +/** + * Creates a cairo surface, ARGB32, native ordering, premultiplied alpha. + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoSurface_create +(JNIEnv *env, jobject obj, jint width, jint height, jint stride, + jintArray buf ) +{ + cairo_surface_t* surface; + jboolean isCopy; + + /* Retrieve java-created data array */ + void *data = (*env)->GetIntArrayElements (env, buf, &isCopy); + + /* Set sharedBuffer variable */ + jclass cls = (*env)->GetObjectClass (env, obj); + jfieldID field = (*env)->GetFieldID (env, cls, SHARED, "Z"); + g_assert (field != 0); + + if (isCopy == JNI_TRUE) + { + (*env)->SetBooleanField (env, obj, field, JNI_FALSE); + void* temp = g_malloc(stride * height * 4); + memcpy(temp, data, stride * height * 4); + (*env)->ReleaseIntArrayElements (env, buf, data, 0); + data = temp; + } + else + (*env)->SetBooleanField (env, obj, field, JNI_TRUE); + + /* Create the cairo surface and set the java pointer */ + surface = cairo_image_surface_create_for_data + (data, CAIRO_FORMAT_ARGB32, width, height, stride * 4); + + setNativeObject(env, obj, surface, SURFACE); +} + +/** + * Destroy the surface + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoSurface_destroy +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong surfacePointer, jintArray buf) +{ + cairo_surface_t* surface = JLONG_TO_PTR(void, surfacePointer); + void *data = cairo_image_surface_get_data(surface); + if( surface != NULL ) + { + /* Release or free the data buffer as appropriate */ + jclass cls = (*env)->GetObjectClass (env, obj); + jfieldID field = (*env)->GetFieldID (env, cls, SHARED, "Z"); + g_assert (field != 0); + jboolean sharedBuffer = (*env)->GetBooleanField (env, obj, field); + + if (sharedBuffer == JNI_TRUE) + (*env)->ReleaseIntArrayElements (env, buf, data, 0); + else + g_free(data); + + /* Destroy the cairo surface itself */ + cairo_surface_destroy(surface); + } +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoSurface_nativeDrawSurface +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong surfacePointer, jlong context, jdoubleArray java_matrix, double alpha, + jint interpolation) +{ + struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, context); + cairo_t *cr = gr->cr; + jdouble *native_matrix = NULL; + cairo_surface_t* surface = JLONG_TO_PTR(void, surfacePointer); + g_assert(surface != NULL); + g_assert(cr != NULL); + + native_matrix = (*env)->GetDoubleArrayElements (env, java_matrix, NULL); + g_assert (native_matrix != NULL); + g_assert ((*env)->GetArrayLength (env, java_matrix) == 6); + + { + cairo_matrix_t mat; + cairo_pattern_t *p; + cairo_matrix_init_identity (&mat); + cairo_matrix_init (&mat, + native_matrix[0], native_matrix[1], + native_matrix[2], native_matrix[3], + native_matrix[4], native_matrix[5]); + + p = cairo_pattern_create_for_surface (surface); + cairo_pattern_set_matrix (p, &mat); + switch ((enum java_awt_rendering_hints_filter) interpolation) + { + case java_awt_rendering_hints_VALUE_INTERPOLATION_NEAREST_NEIGHBOR: + cairo_pattern_set_filter (p, CAIRO_FILTER_NEAREST); + break; + case java_awt_rendering_hints_VALUE_INTERPOLATION_BILINEAR: + cairo_pattern_set_filter (p, CAIRO_FILTER_BILINEAR); + break; + case java_awt_rendering_hints_VALUE_INTERPOLATION_BICUBIC: + cairo_pattern_set_filter (p, CAIRO_FILTER_GAUSSIAN); + break; + case java_awt_rendering_hints_VALUE_ALPHA_INTERPOLATION_SPEED: + cairo_pattern_set_filter (p, CAIRO_FILTER_FAST); + break; + case java_awt_rendering_hints_VALUE_ALPHA_INTERPOLATION_DEFAULT: + cairo_pattern_set_filter (p, CAIRO_FILTER_NEAREST); + break; + case java_awt_rendering_hints_VALUE_ALPHA_INTERPOLATION_QUALITY: + cairo_pattern_set_filter (p, CAIRO_FILTER_BEST); + break; + } + + cairo_set_source(cr, p); + if (alpha == 1.0) + cairo_paint(cr); + else + cairo_paint_with_alpha(cr, alpha); + + cairo_pattern_destroy(p); + } + + (*env)->ReleaseDoubleArrayElements (env, java_matrix, native_matrix, 0); +} + +JNIEXPORT jlong JNICALL +Java_gnu_java_awt_peer_gtk_CairoSurface_getFlippedBuffer +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong surfacePointer) +{ + cairo_surface_t* surface; + jint *src; + jint *dst; + int i, t, width, height; + jclass cls; + jfieldID field; + + /* Retrieve pointer to cairo data buffer */ + surface = JLONG_TO_PTR(void, surfacePointer); + src = (jint*)cairo_image_surface_get_data(surface); + + /* Retrieve dimensions of surface, from java fields */ + cls = (*env)->GetObjectClass (env, obj); + field = (*env)->GetFieldID (env, cls, "width", "I"); + g_assert (field != 0); + width = (*env)->GetIntField (env, obj, field); + + field = (*env)->GetFieldID (env, cls, "height", "I"); + g_assert (field != 0); + height = (*env)->GetIntField (env, obj, field); + + /* Create destination array */ + g_assert( src != NULL ); + dst = g_malloc( width * height * sizeof( jint ) ); + + /* Copy data into destination array, reversing sample order of each pixel */ + for(i = 0; i < (height * width); i++ ) + { + t = (src[i] & 0x0000FF) << 16; + dst[i] = (src[i] & 0x00FF0000) >> 16; + dst[i] |= (src[i] & 0xFF00FF00); + dst[i] |= t; + } + + return PTR_TO_JLONG(dst); +} + +/** + * Create and return a cairo context for drawing to the surface. + */ +JNIEXPORT jlong JNICALL +Java_gnu_java_awt_peer_gtk_CairoSurface_nativeNewCairoContext +(JNIEnv *env __attribute((unused)), jobject obj __attribute((unused)), + jlong surfacePointer) +{ + cairo_surface_t* surface = JLONG_TO_PTR(cairo_surface_t, surfacePointer); + cairo_t *ptr; + g_assert(surface != NULL); + ptr = cairo_create(surface); + g_assert(ptr != NULL); + + return PTR_TO_JLONG(ptr); +} + +/** + * copyArea. + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoSurface_copyAreaNative2 +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong surfacePointer, + jint x, jint y, jint w, jint h, jint dx, jint dy, jint stride) +{ + int row; + int srcOffset, dstOffset; + jint *temp; + + /* Retrieve pointer to cairo data buffer */ + cairo_surface_t* surface = JLONG_TO_PTR(void, surfacePointer); + jint *pixeldata = (jint*)cairo_image_surface_get_data(surface); + g_assert( pixeldata != NULL ); + + /* Create temporary buffer and calculate offsets */ + temp = g_malloc( h * w * 4 ); + g_assert( temp != NULL ); + + srcOffset = x + (y * stride); + dstOffset = (x + dx) + ((y + dy) * stride); + + /* Copy desired region into temporary buffer */ + for( row = 0; row < h; row++ ) + memcpy( temp + (w * row), pixeldata + srcOffset + (stride * row), w * 4 ); + + /* Copy out of buffer and to destination */ + for( row = 0; row < h; row++ ) + memcpy( pixeldata + dstOffset + (stride * row), temp + (w * row), w * 4 ); + + g_free( temp ); +} + +/* + * Synchronizes the java and native data buffers, copying any changes made in + * the java array into the native array. + * This method should only be called if (sharedBuffer == false). + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoSurface_syncJavaToNative +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong surfacePointer, jintArray buffer) +{ + /* Get size of java array */ + int size = (*env)->GetArrayLength(env, buffer); + + /* Get native data buffer */ + cairo_surface_t* surface = JLONG_TO_PTR(void, surfacePointer); + g_assert(surface != NULL); + void* nativeBuffer = cairo_image_surface_get_data(surface); + + /* Sync buffers */ + (*env)->GetIntArrayRegion(env, buffer, 0, size, nativeBuffer); +} + +/* + * Synchronizes the java and native data buffers, copying any changes made in + * the native array into the java array. + * This method should only be called if (sharedBuffer == false). + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_CairoSurface_syncNativeToJava +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong surfacePointer, jintArray buffer) +{ + /* Get size of java array */ + int size = (*env)->GetArrayLength(env, buffer); + + /* Get native data buffer */ + cairo_surface_t* surface = JLONG_TO_PTR(void, surfacePointer); + g_assert(surface != NULL); + void* nativeBuffer = cairo_image_surface_get_data(surface); + + /* Sync buffers */ + (*env)->SetIntArrayRegion(env, buffer, 0, size, nativeBuffer); +} + +/* + * Sets the native object field. + */ +static void +setNativeObject( JNIEnv *env, jobject obj, void *ptr, const char *pointer ) +{ + jclass cls; + jlong value; + jfieldID nofid; + cls = (*env)->GetObjectClass( env, obj ); + value = PTR_TO_JLONG(ptr); + nofid = (*env)->GetFieldID( env, cls, pointer, "J" ); + (*env)->SetLongField( env, obj, nofid, value ); + (*env)->DeleteLocalRef( env, cls ); +} diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c new file mode 100644 index 000000000..3364640a0 --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c @@ -0,0 +1,295 @@ +/* gnu_java_awt_peer_gtk_ComponentGraphics.c + Copyright (C) 2006, 2007 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include "jcl.h" +#include "gtkpeer.h" +#include +#include + +#include +#include + +#include + +#include +#include + +#if HAVE_XRENDER +#include +#include +#endif + +#include "gnu_java_awt_peer_gtk_ComponentGraphics.h" + +#include "cairographics2d.h" + +static short flush_scheduled = 0; + +static gboolean flush (gpointer data __attribute__((unused))) +{ + gdk_threads_enter (); + + gdk_display_flush (gdk_display_get_default ()); + flush_scheduled = 0; + + gdk_threads_leave (); + + return FALSE; +} + +/* The minimum time period between calls to XFlush, in + milliseconds. */ +#define MINIMUM_FLUSH_PERIOD 20 + +/* schedule_flush must be called with the GDK lock held. */ +static void +schedule_flush () +{ + if (!flush_scheduled) + { + g_timeout_add (MINIMUM_FLUSH_PERIOD, flush, NULL); + flush_scheduled = 1; + } +} + +void cp_gtk_grab_current_drawable(GtkWidget *widget, GdkDrawable **draw, + GdkWindow **win) +{ + g_assert (widget != NULL); + g_assert (draw != NULL); + g_assert (win != NULL); + + *win = widget->window; + + *draw = *win; + gdk_window_get_internal_paint_info (*win, draw, 0, 0); +} + +/** + * Returns whether the XRender extension is supported + */ +JNIEXPORT jboolean JNICALL +Java_gnu_java_awt_peer_gtk_ComponentGraphics_hasXRender + (JNIEnv *env __attribute__ ((unused)), jclass cls __attribute__ ((unused))) +{ +#if HAVE_XRENDER + int ev = 0, err = 0; + if( XRenderQueryExtension (GDK_DISPLAY(), &ev, &err) ) + return JNI_TRUE; +#endif + return JNI_FALSE; +} + + +JNIEXPORT jlong JNICALL +Java_gnu_java_awt_peer_gtk_ComponentGraphics_initState + (JNIEnv *env, jobject obj __attribute__ ((unused)), jobject peer) +{ + GdkDrawable *drawable; + GtkWidget *widget; + int width, height; + cairo_t *cr; + void *ptr; + + gdk_threads_enter(); + + ptr = gtkpeer_get_widget (env, peer); + g_assert (ptr != NULL); + + widget = GTK_WIDGET (ptr); + g_assert (widget != NULL); + + drawable = widget->window; + g_assert (drawable != NULL); + + width = widget->allocation.width; + height = widget->allocation.height; + + cr = gdk_cairo_create(drawable); + + g_assert(cr != NULL); + + gdk_threads_leave(); + + return PTR_TO_JLONG(cr); +} + +JNIEXPORT jlong JNICALL +Java_gnu_java_awt_peer_gtk_ComponentGraphics_initFromVolatile + (JNIEnv *env __attribute__ ((unused)), jobject obj __attribute__ ((unused)), + jlong ptr) +{ + GdkDrawable *drawable; + cairo_t *cr; + + gdk_threads_enter(); + + drawable = JLONG_TO_PTR(GdkDrawable, ptr); + g_assert (drawable != NULL); + + cr = gdk_cairo_create (drawable); + g_assert(cr != NULL); + + gdk_threads_leave(); + + return PTR_TO_JLONG(cr); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_ComponentGraphics_start_1gdk_1drawing + (JNIEnv *env __attribute__ ((unused)), jobject obj __attribute__ ((unused))) +{ + gdk_threads_enter(); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_ComponentGraphics_end_1gdk_1drawing + (JNIEnv *env __attribute__ ((unused)), jobject obj __attribute__ ((unused))) +{ + schedule_flush (); + gdk_threads_leave(); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_ComponentGraphics_copyAreaNative + (JNIEnv *env, jobject obj __attribute__((unused)), jobject peer, + jint x, jint y, jint w, jint h, jint dx, jint dy) +{ + GdkPixbuf *pixbuf; + GdkDrawable *drawable; + GdkWindow *win; + GtkWidget *widget = NULL; + void *ptr = NULL; + + gdk_threads_enter(); + + ptr = gtkpeer_get_widget (env, peer); + g_assert (ptr != NULL); + + widget = GTK_WIDGET (ptr); + g_assert (widget != NULL); + + cp_gtk_grab_current_drawable (widget, &drawable, &win); + g_assert (drawable != NULL); + + pixbuf = gdk_pixbuf_new( GDK_COLORSPACE_RGB, TRUE, 8, w, h ); + gdk_pixbuf_get_from_drawable( pixbuf, drawable, NULL, x, y, 0, 0, w, h ); + gdk_draw_pixbuf (drawable, NULL, pixbuf, + 0, 0, x + dx, y + dy, + w, h, + GDK_RGB_DITHER_NORMAL, 0, 0); + gdk_threads_leave(); +} + +JNIEXPORT jobject JNICALL +Java_gnu_java_awt_peer_gtk_ComponentGraphics_nativeGrab +(JNIEnv *env, jclass cls __attribute__((unused)), jobject peer ) +{ + GdkPixbuf *pixbuf; + GdkDrawable *drawable; + GdkWindow *win; + gint w,h; + GtkWidget *widget = NULL; + void *ptr = NULL; + + gdk_threads_enter(); + + ptr = gtkpeer_get_widget (env, peer); + g_assert (ptr != NULL); + + widget = GTK_WIDGET (ptr); + g_assert (widget != NULL); + + cp_gtk_grab_current_drawable (widget, &drawable, &win); + g_assert (drawable != NULL); + + gdk_drawable_get_size ( drawable, &w, &h ); + + pixbuf = gdk_pixbuf_new( GDK_COLORSPACE_RGB, TRUE, 8, w, h ); + gdk_pixbuf_get_from_drawable( pixbuf, drawable, NULL, 0, 0, 0, 0, w, h ); + g_object_ref( pixbuf ); + gdk_draw_pixbuf (drawable, NULL, pixbuf, + 0, 0, 0, 0, + w, h, + GDK_RGB_DITHER_NORMAL, 0, 0); + gdk_threads_leave(); + + return JCL_NewRawDataObject (env, pixbuf); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_ComponentGraphics_drawVolatile +(JNIEnv *env, jobject obj __attribute__ ((unused)), jobject peer, + jlong img, jint x, jint y, jint w, jint h, jint cx, jint cy, jint cw, jint ch) +{ + GdkPixmap *pixmap; + GtkWidget *widget = NULL; + GdkGC *gc; + GdkRectangle clip; + void *ptr; + + gdk_threads_enter(); + + ptr = gtkpeer_get_widget (env, peer); + g_assert (ptr != NULL); + + widget = GTK_WIDGET (ptr); + g_assert (widget != NULL); + + pixmap = JLONG_TO_PTR(GdkPixmap, img); + + gc = gdk_gc_new(widget->window); + + clip.x = cx; + clip.y = cy; + clip.width = cw; + clip.height = ch; + gdk_gc_set_clip_rectangle(gc, &clip); + + gdk_draw_drawable(widget->window, + gc, + pixmap, + 0, 0, + x, y, + w, h); + + g_object_unref( gc ); + + schedule_flush (); + + gdk_threads_leave(); +} diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphicsCopy.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphicsCopy.c new file mode 100644 index 000000000..df700f559 --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphicsCopy.c @@ -0,0 +1,129 @@ +/* gnu_java_awt_peer_gtk_ComponentGraphicsCopy.c + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include "jcl.h" +#include "gtkpeer.h" +#include +#include + +#include +#include + +#include + +#include +#include + +#include "gnu_java_awt_peer_gtk_ComponentGraphicsCopy.h" + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_ComponentGraphicsCopy_getPixbuf + (JNIEnv *env, jobject obj __attribute__((unused)), + jobject peer, jobject image) +{ + gint width, height; + GdkPixbuf *pixbuf; + GdkDrawable *drawable; + GdkWindow *win; + GtkWidget *widget = NULL; + void *ptr = NULL; + + gdk_threads_enter(); + + ptr = gtkpeer_get_widget (env, peer); + g_assert (ptr != NULL); + + widget = GTK_WIDGET (ptr); + g_assert (widget != NULL); + + cp_gtk_grab_current_drawable (widget, &drawable, &win); + g_assert (drawable != NULL); + + pixbuf = cp_gtk_image_get_pixbuf( env, image ); + g_assert( pixbuf != NULL); + + width = gdk_pixbuf_get_width( pixbuf ); + height = gdk_pixbuf_get_height( pixbuf ); + + gdk_pixbuf_get_from_drawable( pixbuf, /* destination pixbuf */ + drawable, + NULL, /* colormap */ + 0, 0, 0, 0, + width, height ); + gdk_threads_leave(); +} + + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_ComponentGraphicsCopy_copyPixbuf + (JNIEnv *env, jobject obj __attribute__((unused)), + jobject peer, jobject image, + jint x __attribute__((unused)), jint y __attribute__((unused)), + jint width __attribute__((unused)), jint height __attribute__((unused))) +{ + gint pwidth, pheight; + GdkPixbuf *pixbuf; + GdkDrawable *drawable; + GdkWindow *win; + GtkWidget *widget = NULL; + void *ptr = NULL; + + gdk_threads_enter(); + + ptr = gtkpeer_get_widget (env, peer); + g_assert (ptr != NULL); + + widget = GTK_WIDGET (ptr); + g_assert (widget != NULL); + + cp_gtk_grab_current_drawable (widget, &drawable, &win); + g_assert (drawable != NULL); + + pixbuf = cp_gtk_image_get_pixbuf( env, image ); + g_assert( pixbuf != NULL); + + pwidth = gdk_pixbuf_get_width( pixbuf ); + pheight = gdk_pixbuf_get_height( pixbuf ); + + gdk_draw_pixbuf (drawable, NULL, pixbuf, + 0, 0, 0, 0, + pwidth, pheight, + GDK_RGB_DITHER_NORMAL, 0, 0); + + gdk_threads_leave(); +} + diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_FreetypeGlyphVector.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_FreetypeGlyphVector.c new file mode 100644 index 000000000..cb7bf43dc --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_FreetypeGlyphVector.c @@ -0,0 +1,449 @@ +/* gnu_java_awt_FreetypeGlyphVector.c + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#define PANGO_ENABLE_ENGINE +#include +#include +#include +#include +#include +#include +#include +#include +#include "jcl.h" +#include "gdkfont.h" +#include "gnu_java_awt_peer_gtk_FreetypeGlyphVector.h" +#include "cairographics2d.h" + +typedef struct gp +{ + JNIEnv *env; + jobject obj; + double px; + double py; + double sx; + double sy; +} generalpath ; + +static PangoFcFont * +getFont(JNIEnv *env, jobject obj) +{ + jfieldID fid; + jobject data; + jclass cls; + struct peerfont *pfont; + + cls = (*env)->GetObjectClass (env, obj); + fid = (*env)->GetFieldID (env, cls, "peer", + "Lgnu/java/awt/peer/gtk/GdkFontPeer;"); + g_assert (fid != 0); + + data = (*env)->GetObjectField (env, obj, fid); + g_assert (data != NULL); + + pfont = (struct peerfont *) gtkpeer_get_font(env, data); + g_assert (pfont != NULL); + g_assert (pfont->font != NULL); + + return (PangoFcFont *)pfont->font; +} + +static PangoFontset * +getFontSet(JNIEnv *env, jobject obj) +{ + jfieldID fid; + jobject data; + jclass cls; + struct peerfont *pfont; + + cls = (*env)->GetObjectClass (env, obj); + fid = (*env)->GetFieldID (env, cls, "peer", + "Lgnu/java/awt/peer/gtk/GdkFontPeer;"); + g_assert (fid != 0); + + data = (*env)->GetObjectField (env, obj, fid); + g_assert (data != NULL); + + pfont = (struct peerfont *) gtkpeer_get_font (env, data); + g_assert (pfont != NULL); + g_assert (pfont->font != NULL); + + return (PangoFontset *)pfont->set; +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_FreetypeGlyphVector_getGlyphs + (JNIEnv *env, jobject obj, jintArray codepoints, jintArray glyphs, + jlongArray fonts) +{ + PangoFcFont *default_font, *current_font; + PangoFontset *pfs; + jint *cpvals; + jint length; + int i; + + /* Set up default font and fontset */ + default_font = getFont(env, obj); + current_font = default_font; + pfs = getFontSet(env, obj); + + /* Retrieve string information */ + length = (*env)->GetArrayLength (env, codepoints); + cpvals = (*env)->GetIntArrayElements (env, codepoints, NULL); + + jint *glyphArray = (*env)->GetIntArrayElements (env, glyphs, NULL); + jlong *fontArray = (*env)->GetLongArrayElements (env, fonts, NULL); + + /* A design goal of Pango is to be threadsafe, but it's admitted that it is + * not actually threadsafe at the moment. Using gdk locking here to be safe, + * but I don't know if if actually helps at all... */ + gdk_threads_enter(); + + for( i = 0; i < length; i++ ) + { + /* Ensure the current font has the requested character; if it doesn't, + * try the default font before pulling a new font out of the fontset. + * Once chosen, a font will be used until a character not in the font is + * encountered. */ + if (!pango_fc_font_has_char(current_font, cpvals[i])) + { + if (pango_fc_font_has_char(default_font, cpvals[i])) + { + current_font = default_font; + g_object_ref(current_font); + } + else + { + current_font = (PangoFcFont*)pango_fontset_get_font(pfs, cpvals[i]); + } + } + else + { + g_object_ref(current_font); + } + + /* Get glyph, and store both glyph and pointer to font */ + glyphArray[i] = (int)pango_fc_font_get_glyph(current_font, + (gunichar)cpvals[i]); + fontArray[i] = PTR_TO_JLONG(current_font); + } + + gdk_threads_leave(); + + (*env)->ReleaseIntArrayElements (env, glyphs, glyphArray, 0); + (*env)->ReleaseIntArrayElements (env, codepoints, cpvals, 0); + (*env)->ReleaseLongArrayElements (env, fonts, fontArray, 0); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_FreetypeGlyphVector_getKerning + (JNIEnv *env, jobject obj __attribute__((unused)), jint rightGlyph, + jint leftGlyph, jlong fnt, jfloatArray p) +{ + FT_Face ft_face; + FT_Vector kern; + PangoFcFont *font; + + font = JLONG_TO_PTR(PangoFcFont, fnt); + ft_face = pango_fc_font_lock_face( font ); + g_assert (ft_face != NULL); + FT_Get_Kerning( ft_face, rightGlyph, leftGlyph, FT_KERNING_DEFAULT, &kern ); + + pango_fc_font_unlock_face( font ); + + jfloat *pelements = (*env)->GetPrimitiveArrayCritical(env, p, NULL); + pelements[0] = (jfloat)kern.x/64.0; + pelements[1] = (jfloat)kern.y/64.0; + (*env)->ReleasePrimitiveArrayCritical (env, p, pelements, 0); +} + +JNIEXPORT jdoubleArray JNICALL +Java_gnu_java_awt_peer_gtk_FreetypeGlyphVector_getMetricsNative +(JNIEnv *env, jobject obj __attribute__((unused)), jint glyphIndex, jlong fnt) +{ + FT_Face ft_face; + jdouble *values; + jdoubleArray retArray = NULL; + PangoFcFont *font; + + font = JLONG_TO_PTR(PangoFcFont, fnt); + ft_face = pango_fc_font_lock_face( font ); + + g_assert (ft_face != NULL); + + FT_Set_Transform( ft_face, NULL, NULL ); + + if( FT_Load_Glyph( ft_face, glyphIndex, FT_LOAD_NO_BITMAP ) != 0 ) + { + pango_fc_font_unlock_face( font ); + printf("Couldn't load glyph %i\n", glyphIndex); + return NULL; + } + + retArray = (*env)->NewDoubleArray (env, 8); + values = (*env)->GetDoubleArrayElements (env, retArray, NULL); + + values[0] = 0; + values[1] = (jdouble)ft_face->glyph->advance.x/64.0; + values[2] = (jdouble)ft_face->glyph->advance.y/64.0; + values[3] = (jdouble)ft_face->glyph->metrics.horiBearingX/64.0; + values[4] = -(jdouble)ft_face->glyph->metrics.horiBearingY/64.0; + values[5] = (jdouble)ft_face->glyph->metrics.width/64.0; + values[6] = (jdouble)ft_face->glyph->metrics.height/64.0; + values[7] = 0; + + (*env)->ReleaseDoubleArrayElements (env, retArray, values, 0); + pango_fc_font_unlock_face( font ); + + return retArray; +} + +/* GetOutline code follows ****************************/ +/********* Freetype callback functions *****************************/ + +static int _moveTo( const FT_Vector* to, + void *p) +{ + JNIEnv *env; + jobject obj; + jclass cls; + jmethodID method; + jvalue values[2]; + generalpath *path = (generalpath *) p; + + env = path->env; + obj = path->obj; + + values[0].f = (jfloat)(to->x * path->sx + path->px); + values[1].f = (jfloat)(to->y * path->sy + path->py); + + cls = (*env)->FindClass (env, "java/awt/geom/GeneralPath"); + method = (*env)->GetMethodID (env, cls, "moveTo", "(FF)V"); + (*env)->CallVoidMethodA(env, obj, method, values ); + + return 0; +} + +static int _lineTo( const FT_Vector* to, + void *p) +{ + JNIEnv *env; + jobject obj; + jclass cls; + jmethodID method; + jvalue values[2]; + generalpath *path = (generalpath *) p; + + env = path->env; + obj = path->obj; + values[0].f = (jfloat)(to->x * path->sx + path->px); + values[1].f = (jfloat)(to->y * path->sy + path->py); + + cls = (*env)->FindClass (env, "java/awt/geom/GeneralPath"); + method = (*env)->GetMethodID (env, cls, "lineTo", "(FF)V"); + (*env)->CallVoidMethodA(env, obj, method, values ); + + return 0; +} + +static int _quadTo( const FT_Vector* cp, + const FT_Vector* to, + void *p) +{ + JNIEnv *env; + jobject obj; + jclass cls; + jmethodID method; + jvalue values[4]; + generalpath *path = (generalpath *) p; + + env = path->env; + obj = path->obj; + values[0].f = (jfloat)(cp->x * path->sx + path->px); + values[1].f = (jfloat)(cp->y * path->sy + path->py); + values[2].f = (jfloat)(to->x * path->sx + path->px); + values[3].f = (jfloat)(to->y * path->sy + path->py); + + cls = (*env)->FindClass (env, "java/awt/geom/GeneralPath"); + method = (*env)->GetMethodID (env, cls, "quadTo", "(FFFF)V"); + (*env)->CallVoidMethodA(env, obj, method, values ); + + return 0; +} + +static int _curveTo( const FT_Vector* cp1, + const FT_Vector* cp2, + const FT_Vector* to, + void *p) +{ + JNIEnv *env; + jobject obj; + jclass cls; + jmethodID method; + jvalue values[6]; + generalpath *path = (generalpath *) p; + + env = path->env; + obj = path->obj; + values[0].f = (jfloat)(cp1->x * path->sx + path->px); + values[1].f = (jfloat)(cp1->y * path->sy + path->py); + values[2].f = (jfloat)(cp2->x * path->sx + path->px); + values[3].f = (jfloat)(cp2->y * path->sy + path->py); + values[4].f = (jfloat)(to->x * path->sx + path->px); + values[5].f = (jfloat)(to->y * path->sy + path->py); + + cls = (*env)->FindClass (env, "java/awt/geom/GeneralPath"); + method = (*env)->GetMethodID (env, cls, "curveTo", "(FFFFFF)V"); + (*env)->CallVoidMethodA(env, obj, method, values ); + + return 0; +} + + +JNIEXPORT jobject JNICALL +Java_gnu_java_awt_peer_gtk_FreetypeGlyphVector_getGlyphOutlineNative + (JNIEnv *env, jobject obj __attribute__((unused)), jint glyphIndex, jlong fnt) +{ + generalpath *path; + jobject gp; + FT_Outline_Funcs ftCallbacks = + { + (FT_Outline_MoveToFunc) _moveTo, + (FT_Outline_LineToFunc) _lineTo, + (FT_Outline_ConicToFunc) _quadTo, + (FT_Outline_CubicToFunc) _curveTo, + 0, + 0 + }; + PangoFcFont *font; + FT_Face ft_face; + FT_Glyph glyph; + + font = JLONG_TO_PTR(PangoFcFont, fnt); + ft_face = pango_fc_font_lock_face( font ); + + g_assert (ft_face != NULL); + + path = g_malloc0 (sizeof (generalpath)); + g_assert(path != NULL); + path->env = env; + + path->px = path->py = 0.0; + path->sx = 1.0/64.0; + path->sy = -1.0/64.0; + + { /* create a GeneralPath instance */ + jclass cls; + jmethodID method; + + cls = (*env)->FindClass (env, "java/awt/geom/GeneralPath"); + method = (*env)->GetMethodID (env, cls, "", "()V"); + gp = path->obj = (*env)->NewObject (env, cls, method); + } + + if(FT_Load_Glyph(ft_face, + (FT_UInt)(glyphIndex), + FT_LOAD_DEFAULT | FT_LOAD_NO_BITMAP) != 0) + { + pango_fc_font_unlock_face( font ); + g_free(path); + return NULL; + } + + FT_Get_Glyph( ft_face->glyph, &glyph ); + if (glyph->format == FT_GLYPH_FORMAT_OUTLINE) + { + FT_Outline_Decompose (&(((FT_OutlineGlyph)glyph)->outline), + &ftCallbacks, path); + } + else + { + char format[5]; + + format[0] = (glyph->format & 0xFF000000) >> 24; + format[1] = (glyph->format & 0x00FF0000) >> 16; + format[2] = (glyph->format & 0x0000FF00) >> 8; + format[3] = (glyph->format & 0x000000FF); + format[4] = '\0'; + printf("WARNING: Unable to create outline for font %s %s of format %s\n", + ft_face->family_name, ft_face->style_name, format); + } + FT_Done_Glyph( glyph ); + + pango_fc_font_unlock_face( font ); + + g_free(path); + + return gp; +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_FreetypeGlyphVector_dispose + (JNIEnv *env, jobject obj __attribute__((unused)), jlongArray fontset) +{ + PangoFcFont *font; + jlong *fontArray; + int i, length; + + length = (*env)->GetArrayLength (env, fontset); + fontArray = (*env)->GetLongArrayElements (env, fontset, NULL); + + gdk_threads_enter(); + + for( i = 0; i < length; i++ ) + { + font = JLONG_TO_PTR(PangoFcFont, fontArray[i]); + g_object_unref(font); + } + + gdk_threads_leave(); + + (*env)->ReleaseLongArrayElements (env, fontset, fontArray, 0); +} + +JNIEXPORT jlong JNICALL +Java_gnu_java_awt_peer_gtk_FreetypeGlyphVector_getNativeFontPointer + (JNIEnv *env, jobject obj, jint n) +{ + int i; + PangoFcFont *font = getFont(env, obj); + + for (i = 0; i < n; i++) + g_object_ref(font); + + return PTR_TO_JLONG(font); +} diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c new file mode 100644 index 000000000..a5e59f7e4 --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c @@ -0,0 +1,370 @@ +/* gnu_java_awt_GdkFont.c + Copyright (C) 2003, 2004 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + +#define PANGO_ENABLE_ENGINE +#include +#include +#include +#include +#include +#include +#include +#include "gdkfont.h" +#include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GdkFontPeer.h" + +enum java_awt_font_style { + java_awt_font_PLAIN = 0, + java_awt_font_BOLD = 1, + java_awt_font_ITALIC = 2 +}; + +enum java_awt_font_baseline { + java_awt_font_ROMAN_BASELINE = 0, + java_awt_font_CENTER_BASELINE = 1, + java_awt_font_HANGING_BASELINE = 2 +}; + +static PangoFT2FontMap *ft2_map = NULL; + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkFontPeer_initStaticState + (JNIEnv *env, jclass clazz __attribute__((unused))) +{ + gtkpeer_init_font_IDs(env); + ft2_map = PANGO_FT2_FONT_MAP(pango_ft2_font_map_new()); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkFontPeer_initState + (JNIEnv *env, jobject self) +{ + struct peerfont *pfont = NULL; + + gdk_threads_enter (); + + g_assert (self != NULL); + pfont = (struct peerfont *) g_malloc0 (sizeof (struct peerfont)); + g_assert (pfont != NULL); + gtkpeer_set_font (env, self, pfont); + + gdk_threads_leave (); +} + + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkFontPeer_dispose + (JNIEnv *env, jobject self) +{ + struct peerfont *pfont = NULL; + + gdk_threads_enter (); + + pfont = (struct peerfont *) gtkpeer_get_font (env, self); + g_assert (pfont != NULL); + if (pfont->layout != NULL) + g_object_unref (pfont->layout); + if (pfont->font != NULL) + g_object_unref (pfont->font); + if (pfont->set != NULL) + g_object_unref (pfont->set); + if (pfont->ctx != NULL) + g_object_unref (pfont->ctx); + if (pfont->desc != NULL) + pango_font_description_free (pfont->desc); + g_free (pfont); + + gdk_threads_leave (); +} + + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkFontPeer_releasePeerGraphicsResource + (JNIEnv *env, jobject java_font) +{ + struct peerfont *pfont = NULL; + + gdk_threads_enter(); + + pfont = (struct peerfont *) gtkpeer_get_font (env, java_font); + g_assert (pfont != NULL); + if (pfont->graphics_resource != NULL) + { + cairo_font_face_destroy ((cairo_font_face_t *) pfont->graphics_resource); + pfont->graphics_resource = NULL; + } + + gdk_threads_leave(); +} + + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkFontPeer_getFontMetrics +(JNIEnv *env, jobject java_font, jdoubleArray java_metrics) +{ + FT_Face face; + struct peerfont *pfont = NULL; + jdouble *native_metrics = NULL; + short x_ppem; + short y_ppem; + short units_per_em; + double factorx; + double factory; + + gdk_threads_enter(); + + pfont = (struct peerfont *) gtkpeer_get_font (env, java_font); + g_assert (pfont != NULL); + face = pango_fc_font_lock_face ((PangoFcFont *)pfont->font); + + native_metrics + = (*env)->GetDoubleArrayElements (env, java_metrics, NULL); + + g_assert (native_metrics != NULL); + + x_ppem = face->size->metrics.x_ppem; + y_ppem = face->size->metrics.y_ppem; + units_per_em = face->units_per_EM; + factorx = units_per_em / x_ppem; + factory = units_per_em / y_ppem; + native_metrics[FONT_METRICS_ASCENT] = face->ascender / factory; + native_metrics[FONT_METRICS_MAX_ASCENT] = face->bbox.yMax / factory; + native_metrics[FONT_METRICS_DESCENT] = - face->descender / factory; + native_metrics[FONT_METRICS_MAX_DESCENT] = - face->bbox.yMin / factory; + native_metrics[FONT_METRICS_MAX_ADVANCE] = face->max_advance_width / factorx; + native_metrics[FONT_METRICS_HEIGHT] = face->height / factory; + native_metrics[FONT_METRICS_UNDERLINE_OFFSET] = + face->underline_position / factory; + native_metrics[FONT_METRICS_UNDERLINE_THICKNESS] = + face->underline_thickness / factory; + + pango_fc_font_unlock_face((PangoFcFont *)pfont->font); + + (*env)->ReleaseDoubleArrayElements (env, + java_metrics, + native_metrics, 0); + + gdk_threads_leave(); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkFontPeer_getTextMetrics + (JNIEnv *env, jobject java_font, jstring str, jdoubleArray java_metrics) +{ + struct peerfont *pfont = NULL; + const char *cstr = NULL; + jdouble *native_metrics = NULL; + PangoRectangle log; + PangoRectangle log2; + int line_count = 0; + int i = 0; + int width = 0; + + gdk_threads_enter(); + + pfont = (struct peerfont *) gtkpeer_get_font(env, java_font); + g_assert (pfont != NULL); + + cstr = (*env)->GetStringUTFChars (env, str, NULL); + g_assert(cstr != NULL); + + pango_layout_set_text (pfont->layout, cstr, -1); + pango_layout_get_extents (pfont->layout, NULL, &log); + + line_count = pango_layout_get_line_count (pfont->layout); + for (i = 0; i < line_count; i++) + { + pango_layout_line_get_extents (pango_layout_get_line (pfont->layout, i), + NULL, &log2); + width += log2.width; + } + + (*env)->ReleaseStringUTFChars (env, str, cstr); + pango_layout_set_text (pfont->layout, "", -1); + + native_metrics = (*env)->GetDoubleArrayElements (env, java_metrics, NULL); + g_assert (native_metrics != NULL); + + native_metrics[TEXT_METRICS_X_BEARING] + = PANGO_PIXELS( ((double)log.x) ); + + native_metrics[TEXT_METRICS_Y_BEARING] + = PANGO_PIXELS( ((double)log.y) ); + + native_metrics[TEXT_METRICS_HEIGHT] + = PANGO_PIXELS( ((double)log.height) ); + + native_metrics[TEXT_METRICS_WIDTH] + = PANGO_PIXELS( ((double)width) ); + + native_metrics[TEXT_METRICS_X_ADVANCE] + = PANGO_PIXELS( ((double) (log.x + log.width)) ); + + native_metrics[TEXT_METRICS_Y_ADVANCE] + = PANGO_PIXELS( ((double) (log.y + log.height)) ); + + (*env)->ReleaseDoubleArrayElements (env, java_metrics, native_metrics, 0); + + gdk_threads_leave(); +} + + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkFontPeer_setFont + (JNIEnv *env, jobject self, jstring family_name_str, jint style_int, jint size) +{ + struct peerfont *pfont = NULL; + char const *family_name = NULL; + enum java_awt_font_style style; + + gdk_threads_enter (); + + style = (enum java_awt_font_style) style_int; + + g_assert (self != NULL); + pfont = (struct peerfont *) gtkpeer_get_font(env, self); + g_assert (pfont != NULL); + + /* Clear old font information */ + if (pfont->ctx != NULL) + g_object_unref (pfont->ctx); + if (pfont->font != NULL) + g_object_unref (pfont->font); + if (pfont->set != NULL) + g_object_unref (pfont->set); + if (pfont->desc != NULL) + pango_font_description_free (pfont->desc); + + /* Set new description information */ + pfont->desc = pango_font_description_new (); + g_assert (pfont->desc != NULL); + + family_name = (*env)->GetStringUTFChars(env, family_name_str, 0); + g_assert (family_name != NULL); + pango_font_description_set_family (pfont->desc, family_name); + (*env)->ReleaseStringUTFChars(env, family_name_str, family_name); + + if (style & java_awt_font_BOLD) + pango_font_description_set_weight (pfont->desc, PANGO_WEIGHT_BOLD); + + if (style & java_awt_font_ITALIC) + pango_font_description_set_style (pfont->desc, PANGO_STYLE_ITALIC); + + pango_font_description_set_size (pfont->desc, size * PANGO_SCALE); + + /* Create new context */ + pfont->ctx = pango_ft2_font_map_create_context (ft2_map); + g_assert (pfont->ctx != NULL); + + pango_context_set_font_description (pfont->ctx, pfont->desc); + pango_context_set_language (pfont->ctx, gtk_get_default_language()); + + /* Create new fontset and default font */ + pfont->set = pango_context_load_fontset(pfont->ctx, pfont->desc, + gtk_get_default_language()); + pfont->font = pango_context_load_font (pfont->ctx, pfont->desc); + g_assert (pfont->font != NULL); + + if (pfont->layout == NULL) + pfont->layout = pango_layout_new (pfont->ctx); + g_assert (pfont->layout != NULL); + + gdk_threads_leave (); +} + + +JNIEXPORT jbyteArray JNICALL +Java_gnu_java_awt_peer_gtk_GdkFontPeer_getTrueTypeTable + (JNIEnv *env, jobject self, jbyte n, jbyte a, jbyte m, jbyte e) +{ + struct peerfont *pfont = NULL; + FT_Face face; + FT_ULong length = 0; + FT_ULong tag; + int error; + FT_Byte *buffer; + jbyteArray result_array; + jbyte *rbuf; + + pfont = (struct peerfont *) gtkpeer_get_font(env, self); + if(pfont == NULL) + return NULL; + + gdk_threads_enter (); + face = pango_fc_font_lock_face ((PangoFcFont *)pfont->font); + tag = FT_MAKE_TAG( n, a, m, e ); + + /* Get the length of the table requested */ + error = FT_Load_Sfnt_Table( face, tag, 0, NULL, &length ); + if ( error ) + { + pango_fc_font_unlock_face ((PangoFcFont *)pfont->font); + gdk_threads_leave (); + return NULL; + } + + buffer = (FT_Byte *)g_malloc0( length ); + if ( buffer == NULL ) + { + pango_fc_font_unlock_face ((PangoFcFont *)pfont->font); + gdk_threads_leave (); + return NULL; + } + /* get the table data */ + error = FT_Load_Sfnt_Table( face, tag, 0, buffer, &length ); + if ( error ) + { + pango_fc_font_unlock_face ((PangoFcFont *)pfont->font); + g_free(buffer); + gdk_threads_leave (); + return NULL; + } + + /* copy to a jbytearray */ + result_array = (*env)->NewByteArray (env, length); + + rbuf = (*env)->GetByteArrayElements (env, result_array, NULL); + memcpy(rbuf, buffer, length); + (*env)->ReleaseByteArrayElements (env, result_array, rbuf, 0); + + g_free(buffer); + pango_fc_font_unlock_face ((PangoFcFont *)pfont->font); + gdk_threads_leave (); + + /* done */ + return result_array; +} diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.c new file mode 100644 index 000000000..6066a6bb2 --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.c @@ -0,0 +1,299 @@ +/* gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.c + Copyright (C) 2004, 2006 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + +#include +#include + +#include "gdkfont.h" +#include "gdkdisplay.h" +#include "gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.h" + +jclass gdkGraphicsEnvironment_class; + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkGraphicsEnvironment_initIDs +(JNIEnv *env, jclass klazz __attribute__((unused))) +{ + gtkpeer_init_display_IDs(env); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkGraphicsEnvironment_nativeInitState +(JNIEnv *env, jobject obj) +{ + GdkDisplay *defaultDisplay; + + gdk_threads_enter(); + + /* Retrieve the default display. */ + defaultDisplay = gdk_display_get_default(); + + gdk_threads_leave(); + + /* Store display pointer in GdkGraphicsEnvironment instance. */ + gtkpeer_set_display(env, obj, (void *) defaultDisplay); +} + +static gint +cmp_families (const void *a, const void *b) +{ + const char *a_name = pango_font_family_get_name (*(PangoFontFamily **)a); + const char *b_name = pango_font_family_get_name (*(PangoFontFamily **)b); + + return g_utf8_collate (a_name, b_name); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkGraphicsEnvironment_nativeGetFontFamilies +(JNIEnv *env, jobject self __attribute__((unused)), jobjectArray family_name) +{ + PangoContext *context = NULL; + PangoFontFamily **families = NULL; + int n_families = 0; + int idx = 0; + + gdk_threads_enter (); + + context = gdk_pango_context_get(); + g_assert (context != NULL); + + pango_context_list_families (context, &families, &n_families); + + qsort (families, n_families, sizeof (PangoFontFamily *), cmp_families); + + for (idx = 0; idx < n_families; idx++) + { + const char *name_tmp = pango_font_family_get_name (families[idx]); + jstring name = (*env)->NewStringUTF (env, name_tmp); + (*env)->SetObjectArrayElement (env, family_name, idx, name); + (*env)->DeleteLocalRef(env, name); + } + g_free (families); + + gdk_threads_leave (); +} + +JNIEXPORT jint JNICALL +Java_gnu_java_awt_peer_gtk_GdkGraphicsEnvironment_nativeGetNumFontFamilies +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused))) +{ + PangoContext *context = NULL; + PangoFontFamily **families = NULL; + gint n_families = 0; + gint num = 0; + + gdk_threads_enter (); + + context = gdk_pango_context_get(); + g_assert (context != NULL); + + pango_context_list_families (context, &families, &n_families); + + num = n_families; + g_free (families); + + gdk_threads_leave (); + + return num; +} + +JNIEXPORT jobjectArray JNICALL +Java_gnu_java_awt_peer_gtk_GdkGraphicsEnvironment_nativeGetScreenDevices +(JNIEnv *env, jobject obj) +{ + jmethodID gdkScreenGraphicsDevice_ctor, gdkScreenGraphicsDevice_init; + jclass gdkScreenGraphicsDevice_class; + int numScreens = 0, i = 0; + GdkDisplay *display; + jobjectArray array; + jobject instance; + + gdkScreenGraphicsDevice_class = (*env)->FindClass + (env, "gnu/java/awt/peer/gtk/GdkScreenGraphicsDevice"); + + gdkScreenGraphicsDevice_ctor = (*env)->GetMethodID + (env, gdkScreenGraphicsDevice_class, "", + "(Lgnu/java/awt/peer/gtk/GdkGraphicsEnvironment;)V"); + + gdkScreenGraphicsDevice_init = (*env)->GetMethodID + (env, gdkScreenGraphicsDevice_class, "init", "()V"); + + display = (GdkDisplay *) gtkpeer_get_display(env, obj); + + gdk_threads_enter(); + + numScreens = gdk_display_get_n_screens(display); + + + /* Create a suitably sized array. */ + array = (*env)->NewObjectArray(env, + numScreens, + gdkScreenGraphicsDevice_class, + NULL); + + /* Create GdkScreenGraphicsDevice instances, store the native pointer to + * the GScreen object with them, run a 2nd initialization phase and + * put the new instance into the result array. + */ + for ( ; i < numScreens ; i++) + { + instance = (*env)->NewObject (env, + gdkScreenGraphicsDevice_class, + gdkScreenGraphicsDevice_ctor, + obj); + + gtkpeer_set_screen(env, instance, gdk_display_get_screen(display, i)); + + gdk_threads_leave(); + (*env)->CallVoidMethod(env, + instance, + gdkScreenGraphicsDevice_init); + gdk_threads_enter(); + + (*env)->SetObjectArrayElement(env, array, i, instance); + } + + gdk_threads_leave(); + + return array; +} + +JNIEXPORT jobject JNICALL +Java_gnu_java_awt_peer_gtk_GdkGraphicsEnvironment_nativeGetDefaultScreenDevice +(JNIEnv *env, jobject obj) +{ + jclass gdkScreenGraphicsDevice_class; + jmethodID gdkScreenGraphicsDevice_ctor, gdkScreenGraphicsDevice_init; + jobject defaultDevice; + GdkScreen *defaultScreen; + + gdkScreenGraphicsDevice_class = (*env)->FindClass + (env, "gnu/java/awt/peer/gtk/GdkScreenGraphicsDevice"); + + gdkScreenGraphicsDevice_ctor = (*env)->GetMethodID + (env, gdkScreenGraphicsDevice_class, "", + "(Lgnu/java/awt/peer/gtk/GdkGraphicsEnvironment;)V"); + gdkScreenGraphicsDevice_init = (*env)->GetMethodID + (env, gdkScreenGraphicsDevice_class, "init", "()V"); + + /* Create the GdkScreenGraphicsDevice instance. */ + defaultDevice = (*env)->NewObject(env, gdkScreenGraphicsDevice_class, + gdkScreenGraphicsDevice_ctor, obj); + + gdk_threads_enter(); + + defaultScreen = gdk_screen_get_default(); + + gdk_threads_leave(); + + /* Class initialization will have set up the native_state storage + * mechanism for GdkScreenGraphicsDevice. + */ + gtkpeer_set_screen(env, defaultDevice, defaultScreen); + + (*env)->CallVoidMethod(env, + defaultDevice, + gdkScreenGraphicsDevice_init); + + return defaultDevice; +} + +JNIEXPORT jintArray JNICALL +Java_gnu_java_awt_peer_gtk_GdkGraphicsEnvironment_getMouseCoordinates +(JNIEnv *env, jobject obj) +{ + jintArray retArray; + jint *values; + GdkDisplay *display; + gint x, y, screenIndex; + GdkScreen *screen; + + display = (GdkDisplay *) gtkpeer_get_display(env, obj); + g_assert (display != NULL); + + gdk_threads_enter (); + + gdk_display_get_pointer (display, &screen, &x, &y, NULL); + screenIndex = gdk_screen_get_number( screen ); + + gdk_threads_leave (); + + retArray = (*env)->NewIntArray (env, 3); + values = (*env)->GetIntArrayElements (env, retArray, NULL); + + values[0] = screenIndex; + values[1] = x; + values[2] = y; + + (*env)->ReleaseIntArrayElements (env, retArray, values, 0); + + return retArray; +} + +JNIEXPORT jboolean JNICALL +Java_gnu_java_awt_peer_gtk_GdkGraphicsEnvironment_isWindowUnderMouse +(JNIEnv *env, jobject obj, jobject windowPeer) +{ + GdkDisplay *display = NULL; + gint x = 0; + gint y = 0; + GtkWidget *windowToTest = NULL; + GdkWindow *windowAtPointer = NULL; + jboolean retVal = JNI_FALSE; + + display = (GdkDisplay *) gtkpeer_get_display (env, obj); + g_assert (display != NULL); + + windowToTest = (GtkWidget *) gtkpeer_get_widget (env, windowPeer); + + gdk_threads_enter (); + + windowAtPointer = gdk_display_get_window_at_pointer (display, &x, &y); + + while (windowAtPointer + && windowAtPointer != windowToTest->window) + windowAtPointer = gdk_window_get_parent (windowAtPointer); + + gdk_threads_leave (); + + if (windowAtPointer) + retVal = JNI_TRUE; + else + retVal = JNI_FALSE; + + return retVal; +} diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkPixbufDecoder.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkPixbufDecoder.c new file mode 100644 index 000000000..5ed39521a --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkPixbufDecoder.c @@ -0,0 +1,470 @@ +/* gdkpixbufdecoder.c + Copyright (C) 1999, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + +#include +#include +#include +#include + +#include +#include +#include "gnu_java_awt_peer_gtk_GdkPixbufDecoder.h" + +#include +#include + +/* Union used for type punning. */ +union env_union +{ + void **void_env; + JNIEnv **jni_env; +}; + +static JavaVM *vm; + +static jmethodID areaPreparedID; +static jmethodID areaUpdatedID; +static jmethodID dataOutputWriteID; +static jmethodID registerFormatID; + +static void +area_prepared_cb (GdkPixbufLoader *loader, + jobject *decoder) +{ + JNIEnv *env = NULL; + union env_union e; + jint width = 0; + jint height = 0; + GdkPixbuf *pixbuf = NULL; + + pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); + g_assert (pixbuf != NULL); + + width = gdk_pixbuf_get_width (pixbuf); + height = gdk_pixbuf_get_height (pixbuf); + + g_assert (decoder != NULL); + + e.jni_env = &env; + (*vm)->GetEnv (vm, e.void_env, JNI_VERSION_1_1); + + (*env)->CallVoidMethod (env, + *decoder, + areaPreparedID, + width, height); +} + +static void +area_updated_cb (GdkPixbufLoader *loader, + gint x, gint y, + gint width, gint height, + jobject *decoder) +{ + JNIEnv *env; + union env_union e; + jint stride_bytes, stride_pixels, n_channels, n_pixels; + jintArray jpixels; + jint *java_pixels; + guchar *gdk_pixels; + + GdkPixbuf *pixbuf_no_alpha = NULL; + GdkPixbuf *pixbuf = NULL; + +#ifndef WORDS_BIGENDIAN + int i; +#endif + + pixbuf_no_alpha = gdk_pixbuf_loader_get_pixbuf (loader); + if (pixbuf_no_alpha == NULL) + return; + + pixbuf = gdk_pixbuf_add_alpha(pixbuf_no_alpha, FALSE, 0, 0, 0); + g_assert (gdk_pixbuf_get_has_alpha (pixbuf)); + + stride_bytes = gdk_pixbuf_get_rowstride (pixbuf); + n_channels = gdk_pixbuf_get_n_channels (pixbuf); + stride_pixels = stride_bytes / n_channels; + n_pixels = height * stride_pixels; + gdk_pixels = gdk_pixbuf_get_pixels (pixbuf); + + e.jni_env = &env; + (*vm)->GetEnv (vm, e.void_env, JNI_VERSION_1_1); + + jpixels = (*env)->NewIntArray (env, n_pixels); + + java_pixels = (*env)->GetIntArrayElements (env, jpixels, NULL); + + memcpy (java_pixels, + gdk_pixels + (y * stride_bytes), + (height * stride_bytes)); + +#ifndef WORDS_BIGENDIAN + /* convert pixels from 0xBBGGRRAA to 0xAARRGGBB */ + for (i = 0; i < n_pixels; ++i) + { + java_pixels[i] = SWAPU32 ((unsigned)java_pixels[i]); + } +#endif + + g_object_unref (pixbuf); + + (*env)->ReleaseIntArrayElements (env, jpixels, java_pixels, 0); + + (*env)->CallVoidMethod (env, + *decoder, + areaUpdatedID, + (jint) x, (jint) y, + (jint) width, (jint) height, + jpixels, + stride_pixels); + + (*env)->DeleteLocalRef(env, jpixels); +} + +static void +closed_cb (GdkPixbufLoader *loader __attribute__((unused)), jobject *decoder) +{ + JNIEnv *env; + union env_union e; + e.jni_env = &env; + (*vm)->GetEnv (vm, e.void_env, JNI_VERSION_1_1); + + (*env)->DeleteGlobalRef (env, *decoder); + g_free (decoder); +} + + + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkPixbufDecoder_initState + (JNIEnv *env, jobject obj) +{ + GdkPixbufLoader *loader = NULL; + jobject *decoder = NULL; + + decoder = (jobject *) g_malloc (sizeof (jobject)); + g_assert (decoder != NULL); + *decoder = (*env)->NewGlobalRef (env, obj); + + loader = gdk_pixbuf_loader_new (); + g_assert (loader != NULL); + g_signal_connect (loader, "area-prepared", G_CALLBACK (area_prepared_cb), decoder); + g_signal_connect (loader, "area-updated", G_CALLBACK (area_updated_cb), decoder); + g_signal_connect (loader, "closed", G_CALLBACK (closed_cb), decoder); + + gtkpeer_set_pixbuf_loader (env, obj, loader); +} + +static void +query_formats (JNIEnv *env, jclass clazz) +{ + jobject jformat; + GSList *formats, *f; + GdkPixbufFormat *format; + gchar **ch, *name; + gint count; + + jclass formatClass; + jmethodID addExtensionID; + jmethodID addMimeTypeID; + jobject string; + + formatClass = (*env)->FindClass + (env, "gnu/java/awt/peer/gtk/GdkPixbufDecoder$ImageFormatSpec"); + + g_assert(formatClass != NULL); + + addExtensionID = (*env)->GetMethodID (env, formatClass, + "addExtension", + "(Ljava/lang/String;)V"); + + addMimeTypeID = (*env)->GetMethodID (env, formatClass, + "addMimeType", + "(Ljava/lang/String;)V"); + + formats = gdk_pixbuf_get_formats (); + + for (f = formats; f; f = f->next) + { + format = (GdkPixbufFormat *) f->data; + name = gdk_pixbuf_format_get_name(format); + + string = (*env)->NewStringUTF(env, name); + g_assert(string != NULL); + + jformat = (*env)->CallStaticObjectMethod + (env, clazz, registerFormatID, string, + (jboolean) gdk_pixbuf_format_is_writable(format)); + (*env)->DeleteLocalRef(env, string); + g_free(name); + + g_assert(jformat != NULL); + + ch = gdk_pixbuf_format_get_extensions(format); + count = 0; + while (*ch) + { + string = (*env)->NewStringUTF(env, *ch); + g_assert(string != NULL); + (*env)->CallVoidMethod (env, jformat, addExtensionID, string); + (*env)->DeleteLocalRef(env, string); + ++ch; + ++count; + } + g_strfreev(ch - count); + + ch = gdk_pixbuf_format_get_mime_types(format); + count = 0; + while (*ch) + { + string = (*env)->NewStringUTF(env, *ch); + g_assert(string != NULL); + (*env)->CallVoidMethod (env, jformat, addMimeTypeID, string); + (*env)->DeleteLocalRef(env, string); + ++ch; + ++count; + } + g_strfreev(ch - count); + (*env)->DeleteLocalRef(env, jformat); + } + + g_slist_free(formats); +} + + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkPixbufDecoder_initStaticState + (JNIEnv *env, jclass clazz) +{ + jclass writerClass; + + (*env)->GetJavaVM(env, &vm); + + areaPreparedID = (*env)->GetMethodID (env, clazz, + "areaPrepared", + "(II)V"); + + areaUpdatedID = (*env)->GetMethodID (env, clazz, + "areaUpdated", + "(IIII[II)V"); + + registerFormatID = (*env)->GetStaticMethodID + (env, clazz, + "registerFormat", + "(Ljava/lang/String;Z)" + "Lgnu/java/awt/peer/gtk/GdkPixbufDecoder$ImageFormatSpec;"); + + writerClass = (*env)->FindClass + (env, "gnu/java/awt/peer/gtk/GdkPixbufDecoder$GdkPixbufWriter"); + dataOutputWriteID = (*env)->GetMethodID (env, writerClass, + "write", "([B)V"); + + query_formats (env, clazz); + + gtkpeer_init_pixbuf_IDs (env); +} + + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkPixbufDecoder_finish +(JNIEnv *env, jobject obj, jboolean needs_close) +{ + GdkPixbufLoader *loader = NULL; + + loader = (GdkPixbufLoader *) gtkpeer_get_pixbuf_loader(env, obj); + if (loader == NULL) + return; + + if (needs_close) + gdk_pixbuf_loader_close (loader, NULL); + g_object_unref (loader); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkPixbufDecoder_pumpDone +(JNIEnv *env, jobject obj) +{ + GError *err = NULL; + GdkPixbufLoader *loader = NULL; + + loader = (GdkPixbufLoader *) gtkpeer_get_pixbuf_loader (env, obj); + g_assert (loader != NULL); + + gdk_pixbuf_loader_close (loader, &err); + + if (err != NULL) + { + JCL_ThrowException (env, "java/io/IOException", err->message); + g_error_free (err); + } +} + +struct stream_save_request +{ + JNIEnv *env; + jobject *writer; +}; + +static gboolean +save_to_stream(const gchar *buf, + gsize count, + GError **error __attribute__((unused)), + gpointer data) +{ + struct stream_save_request *ssr = (struct stream_save_request *)data; + + jbyteArray jbuf; + jbyte *cbuf; + + jbuf = (*(ssr->env))->NewByteArray ((ssr->env), count); + cbuf = (*(ssr->env))->GetByteArrayElements ((ssr->env), jbuf, NULL); + memcpy (cbuf, buf, count); + (*(ssr->env))->ReleaseByteArrayElements ((ssr->env), jbuf, cbuf, 0); + (*(ssr->env))->CallVoidMethod ((ssr->env), *(ssr->writer), + dataOutputWriteID, jbuf); + (*(ssr->env))->DeleteLocalRef((ssr->env), jbuf); + + return TRUE; +} + + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkPixbufDecoder_streamImage +(JNIEnv *env, jclass clazz __attribute__((unused)), + jintArray jarr, jstring jenctype, jint width, jint height, + jboolean hasAlpha, jobject writer) +{ + GdkPixbuf* pixbuf; + jint *ints; + guchar a, r, g, b, *pix, *p; + GError *err = NULL; + const char *enctype; + int i; + struct stream_save_request ssr; + + ssr.writer = &writer; + ssr.env = env; + + ints = (*env)->GetIntArrayElements (env, jarr, NULL); + pix = g_malloc(width * height * (hasAlpha ? 4 : 3)); + + enctype = (*env)->GetStringUTFChars (env, jenctype, NULL); + g_assert(enctype != NULL); + + g_assert (pix != NULL); + g_assert (ints != NULL); + + p = pix; + for (i = 0; i < width*height; ++i) + { + /* + * Java encodes pixels as integers in a predictable arithmetic order: + * 0xAARRGGBB. Since these are jints, JNI has already byte-swapped + * them for us if necessary, so they're in "our" endianness, whatever + * that is. It uses 4 bytes per pixel whether or not there's an alpha + * channel. + */ + + a = 0xff & (ints[i] >> 24); + r = 0xff & (ints[i] >> 16); + g = 0xff & (ints[i] >> 8); + b = 0xff & ints[i]; + + /* + * GDK-pixbuf has a very different storage model: + * + * - A different alpha order (alpha after colors). + * - A different packing model (no alpha -> 3-bytes-per-pixel). + * - A different "RGB" order (host memory order, not endian-neutral). + */ + + *p++ = r; + *p++ = g; + *p++ = b; + if (hasAlpha) + *p++ = a; + } + + pixbuf = gdk_pixbuf_new_from_data (pix, + GDK_COLORSPACE_RGB, + (gboolean) hasAlpha, + 8, width, height, + width * (hasAlpha ? 4 : 3), /* rowstride */ + NULL, NULL); + g_assert (pixbuf != NULL); + + g_assert(gdk_pixbuf_save_to_callback (pixbuf, + &save_to_stream, + &ssr, + enctype, + &err, NULL)); + + g_object_unref (pixbuf); + + g_free(pix); + + (*env)->ReleaseStringUTFChars (env, jenctype, enctype); + (*env)->ReleaseIntArrayElements (env, jarr, ints, 0); +} + + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkPixbufDecoder_pumpBytes + (JNIEnv *env, jobject obj, jbyteArray jarr, jint len) +{ + GdkPixbufLoader *loader = NULL; + jbyte *bytes = NULL; + GError *err = NULL; + + g_assert (len >= 1); + g_assert (jarr != NULL); + + bytes = (*env)->GetByteArrayElements (env, jarr, NULL); + g_assert (bytes != NULL); + loader = (GdkPixbufLoader *) gtkpeer_get_pixbuf_loader (env, obj); + g_assert (loader != NULL); + + gdk_pixbuf_loader_write (loader, (const guchar *) bytes, len, &err); + + (*env)->ReleaseByteArrayElements (env, jarr, bytes, 0); + + if (err != NULL) + { + JCL_ThrowException (env, "java/io/IOException", err->message); + g_error_free (err); + } +} diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkRobotPeer.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkRobotPeer.c new file mode 100644 index 000000000..4240f112e --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkRobotPeer.c @@ -0,0 +1,430 @@ +/* gdkrobotpeer.c + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GdkRobotPeer.h" + +#ifdef HAVE_XTEST +#include +#include +#endif + +#ifdef HAVE_XTEST + +static int +awt_button_mask_to_num (int buttons) +{ + switch (buttons) + { + case AWT_BUTTON1_MASK: + return 1; + case AWT_BUTTON2_MASK: + return 2; + case AWT_BUTTON3_MASK: + return 3; + } + + return 0; +} + +#endif + +JNIEXPORT jboolean JNICALL +Java_gnu_java_awt_peer_gtk_GdkRobotPeer_initXTest + (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused))) +{ + +#ifdef HAVE_XTEST + + GdkDisplay *display; + Display *xdisplay; + int event_basep; + int error_basep; + int majorp; + int minorp; + jboolean result; + + gdk_threads_enter (); + + display = gdk_display_get_default (); + xdisplay = GDK_DISPLAY_XDISPLAY (display); + + result = XTestQueryExtension (xdisplay, + &event_basep, + &error_basep, + &majorp, + &minorp); + + gdk_threads_leave (); + + return result; + +#else + + return JNI_FALSE; + +#endif + +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkRobotPeer_mouseMove + (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), jint x, jint y) +{ + +#ifdef HAVE_XTEST + + GdkDisplay *display; + Display *xdisplay; + int result; + + gdk_threads_enter (); + + display = gdk_display_get_default (); + xdisplay = GDK_DISPLAY_XDISPLAY (display); + + result = XTestFakeMotionEvent (xdisplay, + -1, + x, y, CurrentTime); + + XFlush (xdisplay); + + gdk_threads_leave (); + +#else + + (void) x; // Unused. + (void) y; // Unused. + +#endif + +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkRobotPeer_mousePress + (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), jint buttons) +{ + +#ifdef HAVE_XTEST + + GdkDisplay *display; + Display *xdisplay; + int result; + + gdk_threads_enter (); + + display = gdk_display_get_default (); + xdisplay = GDK_DISPLAY_XDISPLAY (display); + + result = XTestFakeButtonEvent (xdisplay, + awt_button_mask_to_num (buttons), + True, CurrentTime); + + XFlush (xdisplay); + + gdk_threads_leave (); + +#else + + (void) buttons; // Unused. + +#endif + +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkRobotPeer_mouseRelease + (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), jint buttons) +{ + +#ifdef HAVE_XTEST + + GdkDisplay *display; + Display *xdisplay; + int result; + + gdk_threads_enter (); + + display = gdk_display_get_default (); + xdisplay = GDK_DISPLAY_XDISPLAY (display); + + result = XTestFakeButtonEvent (xdisplay, + awt_button_mask_to_num (buttons), + False, CurrentTime); + + XFlush (xdisplay); + + gdk_threads_leave (); + +#else + + (void) buttons; // Unused. + +#endif + +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkRobotPeer_mouseWheel + (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), jint wheelAmt) +{ + +#ifdef HAVE_XTEST + + GdkDisplay *display; + Display *xdisplay; + int i = 0; + + gdk_threads_enter (); + + display = gdk_display_get_default (); + xdisplay = GDK_DISPLAY_XDISPLAY (display); + + if (wheelAmt < 0) + for (i = 0; i < -wheelAmt; i++) + { + XTestFakeButtonEvent (xdisplay, + 4, + True, CurrentTime); + XTestFakeButtonEvent (xdisplay, + 4, + False, CurrentTime); + } + else + for (i = 0; i < wheelAmt; i++) + { + XTestFakeButtonEvent (xdisplay, + 5, + True, CurrentTime); + XTestFakeButtonEvent (xdisplay, + 5, + False, CurrentTime); + } + + XFlush (xdisplay); + + gdk_threads_leave (); + +#else + + (void) wheelAmt; // Unused. + +#endif + +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkRobotPeer_keyPress + (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), jint keycode) +{ + +#ifdef HAVE_XTEST + + GdkDisplay *display; + Display *xdisplay; + GdkKeymapKey *keymap_keys = NULL; + gint n_keys = 0; + guint lookup_keyval = 0; + int result; + + gdk_threads_enter (); + + display = gdk_display_get_default (); + xdisplay = GDK_DISPLAY_XDISPLAY (display); + + lookup_keyval = cp_gtk_awt_keycode_to_keysym (keycode, + AWT_KEY_LOCATION_LEFT); + + if (!gdk_keymap_get_entries_for_keyval (gdk_keymap_get_default (), + lookup_keyval, + &keymap_keys, + &n_keys)) + { + /* No matching keymap entry was found. */ + g_printerr ("No matching keymap entries were found\n"); + gdk_threads_leave (); + return; + } + + /* If n_keys > 1 then there are multiple hardware keycodes that + translate to lookup_keyval. We arbitrarily choose the first + hardware keycode from the list returned by + gdk_keymap_get_entries_for_keyval. */ + result = XTestFakeKeyEvent (xdisplay, + keymap_keys[0].keycode, + True, CurrentTime); + + g_free (keymap_keys); + + XFlush (xdisplay); + + gdk_threads_leave (); + +#else + + (void) keycode; // Unused. + +#endif + +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkRobotPeer_keyRelease + (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), jint keycode) +{ + +#ifdef HAVE_XTEST + + GdkDisplay *display; + Display *xdisplay; + GdkKeymapKey *keymap_keys = NULL; + gint n_keys = 0; + guint lookup_keyval = 0; + int result; + + gdk_threads_enter (); + + display = gdk_display_get_default (); + xdisplay = GDK_DISPLAY_XDISPLAY (display); + + lookup_keyval = cp_gtk_awt_keycode_to_keysym (keycode, + AWT_KEY_LOCATION_LEFT); + + if (!gdk_keymap_get_entries_for_keyval (gdk_keymap_get_default (), + lookup_keyval, + &keymap_keys, + &n_keys)) + { + /* No matching keymap entry was found. */ + g_printerr ("No matching keymap entries were found\n"); + gdk_threads_leave (); + return; + } + + /* If n_keys > 1 then there are multiple hardware keycodes that + translate to lookup_keyval. We arbitrarily choose the first + hardware keycode from the list returned by + gdk_keymap_get_entries_for_keyval. */ + result = XTestFakeKeyEvent (xdisplay, + keymap_keys[0].keycode, + False, CurrentTime); + + g_free (keymap_keys); + + XFlush (xdisplay); + + gdk_threads_leave (); + +#else + + (void) keycode; // Unused. + +#endif + +} + +JNIEXPORT jintArray JNICALL +Java_gnu_java_awt_peer_gtk_GdkRobotPeer_nativeGetRGBPixels + (JNIEnv *env, jobject obj __attribute__((unused)), jint x, jint y, + jint width, jint height) +{ + +#ifdef HAVE_XTEST + + jint stride_bytes, stride_pixels, n_channels, n_pixels; + jintArray jpixels; + jint *java_pixels; + guchar *gdk_pixels; + GdkPixbuf *pixbuf_no_alpha = NULL; + GdkPixbuf *pixbuf = NULL; + +#ifndef WORDS_BIGENDIAN + int i; +#endif + + gdk_threads_enter (); + + pixbuf_no_alpha = gdk_pixbuf_get_from_drawable (NULL, + gdk_get_default_root_window (), + NULL, x, y, 0, 0, + width, height); + + pixbuf = gdk_pixbuf_add_alpha(pixbuf_no_alpha, FALSE, 0, 0, 0); + g_assert (gdk_pixbuf_get_has_alpha (pixbuf)); + + stride_bytes = gdk_pixbuf_get_rowstride (pixbuf); + n_channels = gdk_pixbuf_get_n_channels (pixbuf); + stride_pixels = stride_bytes / n_channels; + n_pixels = height * stride_pixels; + gdk_pixels = gdk_pixbuf_get_pixels (pixbuf); + + jpixels = (*env)->NewIntArray (env, n_pixels); + + java_pixels = (*env)->GetIntArrayElements (env, jpixels, NULL); + + memcpy (java_pixels, + gdk_pixels, + (height * stride_bytes)); + +#ifndef WORDS_BIGENDIAN + /* convert pixels from 0xBBGGRRAA to 0xAARRGGBB */ + for (i = 0; i < n_pixels; ++i) + { + java_pixels[i] = SWAPU32 ((unsigned)java_pixels[i]); + } +#endif + + g_object_unref (pixbuf); + + (*env)->ReleaseIntArrayElements (env, jpixels, java_pixels, 0); + + gdk_threads_leave (); + + return jpixels; + +#else + + (void) env; + (void) x; + (void) y; + (void) width; + (void) height; + return NULL; + +#endif + +} diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice.c new file mode 100644 index 000000000..14ba2a123 --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice.c @@ -0,0 +1,351 @@ +/* gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice.c + Copyright (C) 2006 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + +#include + +#include +#include + +#ifdef HAVE_XRANDR +#include +#include +#endif + +#include "gdkdisplay.h" + +#include "gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice.h" + +struct state_table *cp_gtk_native_screen_state_table; + +jclass gdkScreenGraphicsDevice_class; + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_initIDs +(JNIEnv *env, jclass klazz __attribute__((unused))) +{ + gtkpeer_init_screen_IDs(env); +} + +JNIEXPORT jobject JNICALL +Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeGetFixedDisplayMode +(JNIEnv *env, jobject obj, jobject gdkGraphicsEnv __attribute__((unused))) +{ + jclass displayMode_class; + jmethodID displayMode_ctor; + GdkScreen *screen; + jobject fixedDisplayMode = NULL; +#ifdef HAVE_XRANDR + int temp1, temp2; + GdkDisplay *display; + + display = (GdkDisplay *) gtkpeer_get_display(env, gdkGraphicsEnv); + + gdk_threads_enter(); + + if (!XRRQueryExtension(GDK_DISPLAY_XDISPLAY(display), &temp1, &temp2)) + { + displayMode_class = (*env)->FindClass(env, "java/awt/DisplayMode"); + displayMode_ctor = (*env)->GetMethodID(env, + displayMode_class, + "", + "(IIII)V"); + + screen = (GdkScreen *) gtkpeer_get_screen(env, obj); + + fixedDisplayMode = (*env)->NewObject(env, + displayMode_class, + displayMode_ctor, + gdk_screen_get_width(screen), + gdk_screen_get_height(screen), + -1, + 0); + } + + gdk_threads_leave(); + +#else + + displayMode_class = (*env)->FindClass(env, "java/awt/DisplayMode"); + displayMode_ctor = (*env)->GetMethodID(env, + displayMode_class, + "", + "(IIII)V"); + + screen = (GdkScreen *) gtkpeer_get_screen(env, obj); + + fixedDisplayMode = (*env)->NewObject(env, + displayMode_class, + displayMode_ctor, + gdk_screen_get_width(screen), + gdk_screen_get_height(screen), + -1, + 0); + +#endif + return fixedDisplayMode; +} + +JNIEXPORT jstring JNICALL +Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeGetIDString +(JNIEnv *env, jobject obj) +{ + GdkScreen *screen; + gchar* displayName; + jstring string; + + screen = (GdkScreen *) gtkpeer_get_screen(env, obj); + + gdk_threads_enter(); + + displayName = gdk_screen_make_display_name(screen); + + gdk_threads_leave(); + + string = (*env)->NewStringUTF(env, displayName); + + g_free(displayName); + + return string; +} + +JNIEXPORT jint JNICALL +Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeGetDisplayModeRate +(JNIEnv *env, jobject obj __attribute__((unused)), jobject gdkGraphicsEnv __attribute__((unused))) +{ +#ifdef HAVE_XRANDR + + GdkDisplay *display; + XRRScreenConfiguration *config; + int rate; + + display = (GdkDisplay *) gtkpeer_get_display(env, gdkGraphicsEnv); + + gdk_threads_enter(); + + config = XRRGetScreenInfo (GDK_DISPLAY_XDISPLAY(display), GDK_ROOT_WINDOW()); + + rate = (int) XRRConfigCurrentRate (config); + + XRRFreeScreenConfigInfo (config); + + gdk_threads_leave(); + + return rate; +#else + JCL_ThrowException(env, + "java/lang/InternalError", + "Method should not have been invoked."); + + return -1; +#endif +} + +JNIEXPORT jint JNICALL +Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeGetDisplayModeIndex +(JNIEnv *env, jobject obj __attribute__((unused)), jobject gdkGraphicsEnv __attribute__((unused))) +{ +#ifdef HAVE_XRANDR + + GdkDisplay *display; + XRRScreenConfiguration *config; + SizeID index; + Rotation rotation; + + display = (GdkDisplay *) gtkpeer_get_display(env, gdkGraphicsEnv); + + gdk_threads_enter(); + + config = XRRGetScreenInfo (GDK_DISPLAY_XDISPLAY(display), GDK_ROOT_WINDOW()); + + index = XRRConfigCurrentConfiguration (config, &rotation); + + XRRFreeScreenConfigInfo (config); + + gdk_threads_leave(); + + return (int) index; + +#else + + JCL_ThrowException(env, + "java/lang/InternalError", + "Method should not have been invoked."); + + return -1; + +#endif +} + +JNIEXPORT jobjectArray JNICALL +Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeGetDisplayModes +(JNIEnv *env, jobject obj __attribute__((unused)), jobject gdkGraphicsEnv __attribute__((unused))) +{ +#ifdef HAVE_XRANDR + GdkDisplay *display; + XRRScreenConfiguration *config; + XRRScreenSize *screenSizes; + int nsizes = 0, nrates = 0, i = 0; + jclass x11DisplayMode_class; + jmethodID x11DisplayMode_ctor; + jobjectArray array; + jobject instance; + short *rates; + jshortArray shortArray; + + display = (GdkDisplay *) gtkpeer_get_display(env, gdkGraphicsEnv); + + gdk_threads_enter(); + + config = XRRGetScreenInfo (GDK_DISPLAY_XDISPLAY(display), GDK_ROOT_WINDOW()); + + screenSizes = XRRConfigSizes(config, &nsizes); + + x11DisplayMode_class = (*env)->FindClass(env, "gnu/java/awt/peer/gtk/GdkScreenGraphicsDevice$X11DisplayMode"); + + x11DisplayMode_ctor = (*env)->GetMethodID(env, x11DisplayMode_class, "", "(II[S)V"); + + array = (*env)->NewObjectArray(env, nsizes, x11DisplayMode_class, NULL); + + for (; i < nsizes ; i++) + { + /* Retrieves refresh rate information. */ + rates = XRRConfigRates(config, i, &nrates); + + /* Create a Java short array and put them in. */ + shortArray = (*env)->NewShortArray(env, nrates); + (*env)->SetShortArrayRegion(env, shortArray, 0, nrates, (jshort *) rates); + + /* Create a GdkScreenGraphicsDevice.X11DisplayMode instance. */ + instance = (*env)->NewObject(env, + x11DisplayMode_class, + x11DisplayMode_ctor, + screenSizes[i].width, + screenSizes[i].height, + shortArray); + + /* Put it into the result array. */ + (*env)->SetObjectArrayElement(env, array, i, instance); + } + + /* Free everything acquired by xlib. */ + XRRFreeScreenConfigInfo (config); + + gdk_threads_leave(); + + return array; +#else + JCL_ThrowException(env, + "java/lang/InternalError", + "Method should not have been invoked."); + + return NULL; + +#endif +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeSetDisplayMode +(JNIEnv *env, jobject obj __attribute__((unused)), jobject gdkGraphicsEnv __attribute__((unused)), jint index __attribute__((unused)), jshort rate __attribute__((unused))) +{ +#ifdef HAVE_XRANDR + GdkDisplay *display; + XRRScreenConfiguration *config; + Rotation rotation; + + display = (GdkDisplay *) gtkpeer_get_display(env, gdkGraphicsEnv); + + gdk_threads_enter(); + + config = XRRGetScreenInfo (GDK_DISPLAY_XDISPLAY(display), GDK_ROOT_WINDOW()); + + /* The rotation is not exposed to the Java API. So we retrieve its current + * value and set it to the same when switching resolution. + */ + XRRConfigCurrentConfiguration (config, &rotation); + + XRRSetScreenConfigAndRate (GDK_DISPLAY_XDISPLAY(display), + config, + GDK_ROOT_WINDOW(), + index, + rotation, + rate, + CurrentTime); + + XRRFreeScreenConfigInfo(config); + + gdk_threads_leave(); + +#else + JCL_ThrowException(env, + "java/lang/InternalError", + "Method should not have been invoked."); +#endif +} + +JNIEXPORT jobject JNICALL +Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeGetBounds +(JNIEnv *env, jobject obj) +{ + jclass rectangle_class; + jmethodID rectangle_ctor; + GdkScreen *screen; + GdkWindow *window; + int x, y, w, h; + jobject instance; + + rectangle_class = (*env)->FindClass(env, "java/awt/Rectangle"); + + rectangle_ctor = (*env)->GetMethodID + (env, rectangle_class, "", "(IIII)V"); + + screen = (GdkScreen *) gtkpeer_get_screen(env, obj); + + gdk_threads_enter(); + + window = gdk_screen_get_root_window(screen); + + gdk_window_get_geometry(window, &x, &y, &w, &h, NULL); + + gdk_threads_leave(); + + instance = (*env)->NewObject(env, + rectangle_class, + rectangle_ctor, + x, y, w, h); + + return instance; +} diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c new file mode 100644 index 000000000..3e39b0ee2 --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c @@ -0,0 +1,376 @@ +/* gtkbuttonpeer.c -- Native implementation of GtkButtonPeer + Copyright (C) 1998, 1999 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkButtonPeer.h" + +static jmethodID postActionEventID; + +void +cp_gtk_button_init_jni (JNIEnv* env) +{ + jclass gtkbuttonpeer; + + gtkbuttonpeer = (*env)->FindClass (env, + "gnu/java/awt/peer/gtk/GtkButtonPeer"); + + postActionEventID = (*env)->GetMethodID (cp_gtk_gdk_env(), gtkbuttonpeer, + "postActionEvent", "(I)V"); +} + +static void clicked_cb (GtkButton *button, + jobject peer); + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkButtonPeer_create + (JNIEnv *env, jobject obj, jstring label) +{ + const char *c_label; + GtkWidget *eventbox; + GtkWidget *button; + + gdk_threads_enter (); + + gtkpeer_set_global_ref (env, obj); + + c_label = (*env)->GetStringUTFChars (env, label, NULL); + + eventbox = gtk_event_box_new (); + button = gtk_button_new_with_label (c_label); + gtk_container_add (GTK_CONTAINER (eventbox), button); + gtk_widget_show (button); + + (*env)->ReleaseStringUTFChars (env, label, c_label); + gtkpeer_set_widget (env, obj, eventbox); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkButtonPeer_gtkWidgetGetPreferredDimensions + (JNIEnv *env, jobject obj, jintArray jdims) +{ + void *ptr; + jint *dims; + GtkWidget *button; + GtkWidget *label; + GtkRequisition current_req; + GtkRequisition current_label_req; + GtkRequisition natural_req; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + button = gtk_bin_get_child (GTK_BIN (ptr)); + label = gtk_bin_get_child (GTK_BIN (button)); + + dims = (*env)->GetIntArrayElements (env, jdims, 0); + dims[0] = dims[1] = 0; + + /* Save the button's current size request. */ + gtk_widget_size_request (GTK_WIDGET (button), ¤t_req); + + /* Save the label's current size request. */ + gtk_widget_size_request (GTK_WIDGET (label), ¤t_label_req); + + /* Get the widget's "natural" size request. */ + gtk_widget_set_size_request (GTK_WIDGET (button), -1, -1); + gtk_widget_set_size_request (GTK_WIDGET (label), -1, -1); + + gtk_widget_size_request (GTK_WIDGET (button), &natural_req); + + /* Reset the button's size request. */ + gtk_widget_set_size_request (GTK_WIDGET (button), + current_req.width, current_req.height); + + /* Reset the label's size request. */ + gtk_widget_set_size_request (GTK_WIDGET (label), + current_label_req.width, current_label_req.height); + + dims[0] = natural_req.width; + dims[1] = natural_req.height; + + (*env)->ReleaseIntArrayElements (env, jdims, dims, 0); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkButtonPeer_connectSignals + (JNIEnv *env, jobject obj) +{ + GtkWidget *widget; + jobject gref; + GtkWidget *button; + + gdk_threads_enter (); + + widget = gtkpeer_get_widget (env, obj); + gref = gtkpeer_get_global_ref (env, obj); + + button = gtk_bin_get_child (GTK_BIN (widget)); + + /* Button signals */ + g_signal_connect (G_OBJECT (button), "clicked", + G_CALLBACK (clicked_cb), gref); + + /* Component signals */ + cp_gtk_component_connect_signals (G_OBJECT (button), gref); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkButtonPeer_gtkSetLabel + (JNIEnv *env, jobject obj, jstring jtext) +{ + const char *text; + GtkWidget *button; + GtkWidget *label; + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + text = (*env)->GetStringUTFChars (env, jtext, NULL); + + button = gtk_bin_get_child (GTK_BIN (ptr)); + label = gtk_bin_get_child (GTK_BIN (button)); + gtk_label_set_text (GTK_LABEL (label), text); + + (*env)->ReleaseStringUTFChars (env, jtext, text); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkButtonPeer_gtkWidgetModifyFont + (JNIEnv *env, jobject obj, jstring name, jint style, jint size) +{ + const char *font_name; + void *ptr; + GtkWidget *button; + GtkWidget *label; + PangoFontDescription *font_desc; + + gdk_threads_enter(); + + ptr = gtkpeer_get_widget (env, obj); + + font_name = (*env)->GetStringUTFChars (env, name, NULL); + + button = gtk_bin_get_child (GTK_BIN (ptr)); + label = gtk_bin_get_child (GTK_BIN (button)); + + font_desc = pango_font_description_from_string (font_name); + pango_font_description_set_size (font_desc, + size * cp_gtk_dpi_conversion_factor); + + if (style & AWT_STYLE_BOLD) + pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD); + + if (style & AWT_STYLE_ITALIC) + pango_font_description_set_style (font_desc, PANGO_STYLE_OBLIQUE); + + gtk_widget_modify_font (GTK_WIDGET(label), font_desc); + + pango_font_description_free (font_desc); + + (*env)->ReleaseStringUTFChars (env, name, font_name); + + gdk_threads_leave(); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkButtonPeer_gtkWidgetSetBackground + (JNIEnv *env, jobject obj, jint red, jint green, jint blue) +{ + GdkColor normal_color; + GdkColor prelight_color; + GdkColor active_color; + int prelight_red; + int prelight_blue; + int prelight_green; + GtkWidget *button; + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + normal_color.red = (red / 255.0) * 65535; + normal_color.green = (green / 255.0) * 65535; + normal_color.blue = (blue / 255.0) * 65535; + + /* This calculation only approximate the active color produced by + Sun's AWT. */ + active_color.red = 0.85 * (red / 255.0) * 65535; + active_color.green = 0.85 * (green / 255.0) * 65535; + active_color.blue = 0.85 * (blue / 255.0) * 65535; + + /* There is no separate prelight color in Motif. */ + prelight_red = 1.15 * (red / 255.0) * 65535; + prelight_green = 1.15 * (green / 255.0) * 65535; + prelight_blue = 1.15 * (blue / 255.0) * 65535; + + prelight_color.red = prelight_red > 65535 ? 65535 : prelight_red; + prelight_color.green = prelight_green > 65535 ? 65535 : prelight_green; + prelight_color.blue = prelight_blue > 65535 ? 65535 : prelight_blue; + + button = gtk_bin_get_child (GTK_BIN (ptr)); + + gtk_widget_modify_bg (button, GTK_STATE_NORMAL, &normal_color); + gtk_widget_modify_bg (button, GTK_STATE_ACTIVE, &active_color); + gtk_widget_modify_bg (button, GTK_STATE_PRELIGHT, &prelight_color); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkButtonPeer_gtkWidgetSetForeground + (JNIEnv *env, jobject obj, jint red, jint green, jint blue) +{ + GdkColor color; + GtkWidget *button; + GtkWidget *label; + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + color.red = (red / 255.0) * 65535; + color.green = (green / 255.0) * 65535; + color.blue = (blue / 255.0) * 65535; + + button = gtk_bin_get_child (GTK_BIN (ptr)); + label = gtk_bin_get_child (GTK_BIN (button)); + + gtk_widget_modify_fg (label, GTK_STATE_NORMAL, &color); + gtk_widget_modify_fg (label, GTK_STATE_ACTIVE, &color); + gtk_widget_modify_fg (label, GTK_STATE_PRELIGHT, &color); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkButtonPeer_gtkActivate + (JNIEnv *env, jobject obj) +{ + GtkWidget *button; + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + button = gtk_bin_get_child (GTK_BIN (ptr)); + gtk_widget_activate (GTK_WIDGET (button)); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkButtonPeer_gtkWidgetRequestFocus + (JNIEnv *env, jobject obj) +{ + void *ptr; + GtkWidget *button; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + button = gtk_bin_get_child (GTK_BIN (ptr)); + gtk_widget_grab_focus (button); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkButtonPeer_setNativeBounds + (JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height) +{ + GtkWidget *widget, *child; + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + widget = GTK_WIDGET (ptr); + + /* We assume that -1 is a width or height and not a request for the + widget's natural size. */ + width = width < 0 ? 0 : width; + height = height < 0 ? 0 : height; + child = gtk_bin_get_child (GTK_BIN (widget)); + + if (!(width == 0 && height == 0)) + { + /* Set the event box's size request... */ + gtk_widget_set_size_request (widget, width, height); + /* ...and the button's size request... */ + gtk_widget_set_size_request (child, width, height); + /* ...and the label's size request. */ + gtk_widget_set_size_request (gtk_bin_get_child (GTK_BIN (child)), width, + height); + if (widget->parent != NULL && GTK_IS_FIXED (widget->parent)) + gtk_fixed_move (GTK_FIXED (widget->parent), widget, x, y); + } + + gdk_threads_leave (); +} + +static void +clicked_cb (GtkButton* button __attribute__((unused)), + jobject peer) +{ + GdkEventButton* event; + + event = (GdkEventButton*) gtk_get_current_event (); + g_assert (event); + + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postActionEventID, + cp_gtk_state_to_awt_mods (event->state)); + + gdk_event_free ((GdkEvent*) event); +} diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCanvasPeer.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCanvasPeer.c new file mode 100644 index 000000000..600b61a33 --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCanvasPeer.c @@ -0,0 +1,58 @@ +/* gtkcanvaspeer.c -- Native implementation of GtkCanvasPeer + Copyright (C) 1999 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkCanvasPeer.h" + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkCanvasPeer_create + (JNIEnv *env, jobject obj) +{ + gpointer widget; + + gdk_threads_enter (); + + /* Create global reference and save it for future use */ + gtkpeer_set_global_ref (env, obj); + + widget = gtk_drawing_area_new (); + + gtkpeer_set_widget (env, obj, widget); + + gdk_threads_leave (); +} diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxMenuItemPeer.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxMenuItemPeer.c new file mode 100644 index 000000000..a30eba449 --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxMenuItemPeer.c @@ -0,0 +1,78 @@ +/* gtkmenuitempeer.c -- Native implementation of GtkMenuItemPeer + Copyright (C) 1999 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkCheckboxMenuItemPeer.h" + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkCheckboxMenuItemPeer_create + (JNIEnv *env, jobject obj, jstring label) +{ + GtkWidget *widget; + const char *str; + + gdk_threads_enter (); + + gtkpeer_set_global_ref (env, obj); + + str = (*env)->GetStringUTFChars (env, label, NULL); + + widget = gtk_check_menu_item_new_with_label (str); + gtk_widget_show (widget); + + (*env)->ReleaseStringUTFChars (env, label, str); + + gtkpeer_set_widget (env, obj, widget); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkCheckboxMenuItemPeer_setState + (JNIEnv *env, jobject obj, jboolean state) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (ptr), state); + + gdk_threads_leave (); +} diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxPeer.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxPeer.c new file mode 100644 index 000000000..96230aadf --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxPeer.c @@ -0,0 +1,407 @@ +/* gtkcheckboxpeer.c -- Native implementation of GtkCheckboxPeer + Copyright (C) 1998, 1999, 2002, 2003, 2004, 2006 + Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkCheckboxPeer.h" +#include "gnu_java_awt_peer_gtk_GtkComponentPeer.h" +#include "jcl.h" + +static jmethodID postItemEventID; +static jmethodID addToGroupMapID; +static GtkWidget *checkbox_get_widget (GtkWidget *widget); +static void item_toggled_cb (GtkToggleButton *item, jobject peer); + +void +cp_gtk_checkbox_init_jni (void) +{ + jclass gtkcheckboxpeer; + + gtkcheckboxpeer = (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(), + "gnu/java/awt/peer/gtk/GtkCheckboxPeer"); + + postItemEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtkcheckboxpeer, + "postItemEvent", + "(Ljava/lang/Object;Z)V"); + + addToGroupMapID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtkcheckboxpeer, + "addToGroupMap", + "(J)V"); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_connectSignals + (JNIEnv *env, jobject obj) +{ + void *ptr; + jobject gref; + GtkWidget *bin; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + gref = gtkpeer_get_global_ref (env, obj); + bin = checkbox_get_widget (GTK_WIDGET (ptr)); + + /* Checkbox signals */ + g_signal_connect (G_OBJECT (bin), "toggled", + G_CALLBACK (item_toggled_cb), gref); + + /* Component signals */ + cp_gtk_component_connect_signals (G_OBJECT (bin), gref); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_gtkToggleButtonSetActive + (JNIEnv *env, jobject obj, jboolean is_active) +{ + void *ptr; + GtkWidget *bin; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + bin = checkbox_get_widget (GTK_WIDGET (ptr)); + + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bin), is_active); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_gtkWidgetModifyFont + (JNIEnv *env, jobject obj, jstring name, jint style, jint size) +{ + const char *font_name; + void *ptr; + GtkWidget *button; + GtkWidget *label; + PangoFontDescription *font_desc; + + gdk_threads_enter(); + + ptr = gtkpeer_get_widget (env, obj); + + button = checkbox_get_widget (GTK_WIDGET (ptr)); + label = gtk_bin_get_child (GTK_BIN(button)); + + if (!label) + return; + + font_name = (*env)->GetStringUTFChars (env, name, NULL); + + font_desc = pango_font_description_from_string (font_name); + pango_font_description_set_size (font_desc, + size * cp_gtk_dpi_conversion_factor); + + if (style & AWT_STYLE_BOLD) + pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD); + + if (style & AWT_STYLE_ITALIC) + pango_font_description_set_style (font_desc, PANGO_STYLE_OBLIQUE); + + gtk_widget_modify_font (GTK_WIDGET(label), font_desc); + + pango_font_description_free (font_desc); + + (*env)->ReleaseStringUTFChars (env, name, font_name); + + gdk_threads_leave(); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_gtkButtonSetLabel + (JNIEnv *env, jobject obj, jstring label) +{ + const char *c_label; + GtkWidget *label_widget; + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + c_label = (*env)->GetStringUTFChars (env, label, NULL); + + label_widget = gtk_bin_get_child (GTK_BIN (checkbox_get_widget (GTK_WIDGET (ptr)))); + gtk_label_set_text (GTK_LABEL (label_widget), c_label); + + (*env)->ReleaseStringUTFChars (env, label, c_label); + + gdk_threads_leave (); +} + +/* A check button is created if we are not part of + a group. + This function is called when initially creating the + button, so an eventbox is created. + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_createCheckButton + (JNIEnv *env, jobject obj) +{ + GtkWidget *button; + GtkWidget *eventbox; + + gdk_threads_enter (); + + gtkpeer_set_global_ref (env, obj); + eventbox = gtk_event_box_new (); + + button = gtk_check_button_new_with_label (""); + gtk_container_add (GTK_CONTAINER (eventbox), button); + gtk_widget_show (button); + + gtkpeer_set_widget (env, obj, eventbox); + + gdk_threads_leave (); +} + +/* A radio button is created if we are part of a group. + groupPointer points to the corresponding group. If 0, + a new group is created. + This function is called when initially creating the + button, so an eventbox is created. + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_createRadioButton + (JNIEnv *env, jobject obj, jlong groupPointer) +{ + GtkWidget *button; + GtkWidget *eventbox; + GSList *native_group = NULL; + + gdk_threads_enter (); + + gtkpeer_set_global_ref (env, obj); + eventbox = gtk_event_box_new (); + + if (groupPointer != 0) + { + native_group = JLONG_TO_PTR (GSList, groupPointer); + g_assert (GTK_IS_RADIO_BUTTON (native_group->data)); + } + button = gtk_radio_button_new_with_label (native_group, ""); + + if (native_group == NULL) + native_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button)); + if (g_slist_index (native_group, GTK_RADIO_BUTTON (button)) == -1) + { + native_group = g_slist_prepend (native_group, GTK_RADIO_BUTTON (button)); + GTK_RADIO_BUTTON(button)->group = native_group; + } + + gtk_container_add (GTK_CONTAINER (eventbox), button); + gtk_widget_show (button); + + gtkpeer_set_widget (env, obj, eventbox); + + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), obj, + addToGroupMapID, + PTR_TO_JLONG (native_group)); + + gdk_threads_leave (); +} + +/* Add the object to the group pointed to by groupPointer. + If groupPointer is 0, create a new group and create + a radio button. Otherwise, creating a radio button in an + existing group. + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_addToGroup + (JNIEnv *env, jobject obj, jlong groupPointer) +{ + void *ptr; + GtkWidget *container; + GtkWidget *check_button; + GtkWidget *radio_button; + const gchar *label; + GSList *native_group = NULL; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + container = GTK_WIDGET (ptr); + check_button = checkbox_get_widget (container); + label = gtk_label_get_text (GTK_LABEL (gtk_bin_get_child + (GTK_BIN (check_button)))); + + /* Need to remove the check_button, and replace it with + a radio button in a group. + */ + if (groupPointer != 0) + { + native_group = JLONG_TO_PTR (GSList, groupPointer); + g_assert (GTK_IS_RADIO_BUTTON (native_group->data)); + } + + radio_button = gtk_radio_button_new_with_label (native_group, label); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio_button), + gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_button))); + + if (native_group == NULL) + native_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio_button)); + if (g_slist_index (native_group, GTK_RADIO_BUTTON (radio_button)) == -1) + { + native_group = g_slist_prepend (native_group, GTK_RADIO_BUTTON (radio_button)); + GTK_RADIO_BUTTON(radio_button)->group = native_group; + } + + gtk_container_remove (GTK_CONTAINER (container), check_button); + gtk_container_add (GTK_CONTAINER (container), radio_button); + gtk_widget_show (radio_button); + + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), obj, + addToGroupMapID, + PTR_TO_JLONG (native_group)); + + gdk_threads_leave (); +} + +/* Remove the object from the group pointed to by groupPointer. + We are removing the radio button and creating a check button. + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_removeFromGroup + (JNIEnv *env, jobject obj) +{ + void *ptr; + GtkWidget *container; + GtkWidget *check_button; + GtkWidget *radio_button; + GSList *native_group; + const gchar *label; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + container = GTK_WIDGET (ptr); + radio_button = checkbox_get_widget (container); + label = gtk_label_get_text (GTK_LABEL (gtk_bin_get_child + (GTK_BIN (radio_button)))); + + /* Need to remove the radio_button, and replace it with + a check button. + */ + check_button = gtk_check_button_new_with_label (label); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button), + gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radio_button))); + + native_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio_button)); + native_group = g_slist_remove (native_group, GTK_RADIO_BUTTON (radio_button)); + + if (native_group && ! GTK_IS_RADIO_BUTTON (native_group->data)) + native_group = NULL; + + GTK_RADIO_BUTTON(radio_button)->group = NULL; + + gtk_container_remove (GTK_CONTAINER (container), radio_button); + gtk_container_add (GTK_CONTAINER (container), check_button); + gtk_widget_show (check_button); + + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), obj, + addToGroupMapID, + PTR_TO_JLONG (native_group)); + + gdk_threads_leave (); +} + +/* Move the radio button to a new group. If groupPointer is + 0, create a new group. + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_switchToGroup + (JNIEnv *env, jobject obj, jlong groupPointer) +{ + void *ptr; + GtkWidget *radio_button; + GSList *native_group = NULL; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + radio_button = checkbox_get_widget (GTK_WIDGET (ptr)); + + native_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio_button)); + native_group = g_slist_remove (native_group, GTK_RADIO_BUTTON (radio_button)); + GTK_RADIO_BUTTON(radio_button)->group = NULL; + + if (groupPointer != 0) + { + native_group = JLONG_TO_PTR (GSList, groupPointer); + g_assert (GTK_IS_RADIO_BUTTON (native_group->data)); + } + gtk_radio_button_set_group (GTK_RADIO_BUTTON (radio_button), native_group); + + native_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio_button)); + if (g_slist_index (native_group, GTK_RADIO_BUTTON (radio_button)) == -1) + { + native_group = g_slist_prepend (native_group, GTK_RADIO_BUTTON (radio_button)); + GTK_RADIO_BUTTON(radio_button)->group = native_group; + } + + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), obj, + addToGroupMapID, + PTR_TO_JLONG (native_group)); + + gdk_threads_leave (); +} + +static void +item_toggled_cb (GtkToggleButton *item, jobject peer) +{ + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postItemEventID, + peer, + item->active); +} + +static GtkWidget * +checkbox_get_widget (GtkWidget *widget) +{ + GtkWidget *wid; + + g_assert (GTK_IS_EVENT_BOX (widget)); + wid = gtk_bin_get_child (GTK_BIN(widget)); + + return wid; +} + diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkChoicePeer.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkChoicePeer.c new file mode 100644 index 000000000..6f3d9c0e1 --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkChoicePeer.c @@ -0,0 +1,237 @@ +/* gtkchoicepeer.c -- Native implementation of GtkChoicePeer + Copyright (C) 1998, 1999, 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkChoicePeer.h" + +static jmethodID postChoiceItemEventID; +static GtkWidget *choice_get_widget (GtkWidget *widget); + +void +cp_gtk_choice_init_jni (void) +{ + jclass gtkchoicepeer; + + gtkchoicepeer = (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(), + "gnu/java/awt/peer/gtk/GtkChoicePeer"); + + postChoiceItemEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtkchoicepeer, + "postChoiceItemEvent", + "(I)V"); +} + +static void selection_changed_cb (GtkComboBox *combobox, jobject peer); + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkChoicePeer_create + (JNIEnv *env, jobject obj) +{ + GtkWidget *combobox; + GtkWidget *eventbox; + + gdk_threads_enter (); + + gtkpeer_set_global_ref (env, obj); + + eventbox = gtk_event_box_new (); + combobox = gtk_combo_box_new_text (); + gtk_container_add (GTK_CONTAINER (eventbox), combobox); + gtk_widget_show (combobox); + + gtkpeer_set_widget (env, obj, eventbox); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkChoicePeer_connectSignals + (JNIEnv *env, jobject obj) +{ + void *ptr = NULL; + jobject gref; + GtkWidget *bin; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + gref = gtkpeer_get_global_ref (env, obj); + + bin = choice_get_widget (GTK_WIDGET (ptr)); + + /* Choice signals */ + g_signal_connect (G_OBJECT (bin), "changed", + G_CALLBACK (selection_changed_cb), gref); + + /* Component signals */ + cp_gtk_component_connect_signals (G_OBJECT (bin), gref); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkChoicePeer_add + (JNIEnv *env, jobject obj, jstring item, jint index) +{ + void *ptr; + const char *label; + GtkWidget *bin; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + bin = choice_get_widget (GTK_WIDGET (ptr)); + + label = (*env)->GetStringUTFChars (env, item, 0); + + gtk_combo_box_insert_text (GTK_COMBO_BOX (bin), index, label); + + (*env)->ReleaseStringUTFChars (env, item, label); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeRemove + (JNIEnv *env, jobject obj, jint index) +{ + void *ptr; + GtkWidget *bin; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + bin = choice_get_widget (GTK_WIDGET (ptr)); + + /* First, unselect everything, to avoid problems when removing items. */ + gtk_combo_box_set_active (GTK_COMBO_BOX (bin), -1); + gtk_combo_box_remove_text (GTK_COMBO_BOX (bin), index); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeRemoveAll + (JNIEnv *env, jobject obj) +{ + void *ptr; + GtkTreeModel *model; + GtkWidget *bin; + gint count, i; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + bin = choice_get_widget (GTK_WIDGET (ptr)); + + model = gtk_combo_box_get_model (GTK_COMBO_BOX (bin)); + count = gtk_tree_model_iter_n_children (model, NULL); + + /* First, unselect everything, to avoid problems when removing items. */ + gtk_combo_box_set_active (GTK_COMBO_BOX (bin), -1); + + for (i = count - 1; i >= 0; i--) { + gtk_combo_box_remove_text (GTK_COMBO_BOX (bin), i); + } + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkChoicePeer_selectNative + (JNIEnv *env, jobject obj, jint index) +{ + gdk_threads_enter (); + + Java_gnu_java_awt_peer_gtk_GtkChoicePeer_selectNativeUnlocked + (env, obj, index); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkChoicePeer_selectNativeUnlocked + (JNIEnv *env, jobject obj, jint index) +{ + void *ptr; + GtkWidget *bin; + + ptr = gtkpeer_get_widget (env, obj); + bin = choice_get_widget (GTK_WIDGET (ptr)); + gtk_combo_box_set_active (GTK_COMBO_BOX (bin), (gint)index); +} + +JNIEXPORT jint JNICALL +Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeGetSelected + (JNIEnv *env, jobject obj) +{ + void *ptr; + int index; + GtkWidget *bin; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + bin = choice_get_widget (GTK_WIDGET (ptr)); + + index = gtk_combo_box_get_active (GTK_COMBO_BOX (bin)); + + gdk_threads_leave (); + + return index; +} + +static void +selection_changed_cb (GtkComboBox *combobox, jobject peer) +{ + gint index = gtk_combo_box_get_active(combobox); + + if (index >= 0) + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postChoiceItemEventID, (jint)index ); +} + +static GtkWidget * +choice_get_widget (GtkWidget *widget) +{ + GtkWidget *wid; + + g_assert (GTK_IS_EVENT_BOX (widget)); + wid = gtk_bin_get_child (GTK_BIN(widget)); + + return wid; +} diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkClipboard.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkClipboard.c new file mode 100644 index 000000000..0b076f864 --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkClipboard.c @@ -0,0 +1,422 @@ +/* gtkclipboard.c + Copyright (C) 1998, 1999, 2005, 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#include "jcl.h" +#include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkClipboard.h" + +#define OBJECT_TARGET 1 +#define TEXT_TARGET 2 +#define IMAGE_TARGET 3 +#define URI_TARGET 4 + +/* The clipboard and selection plus corresponding GtkClipboard objects. */ +GtkClipboard *cp_gtk_clipboard; +GtkClipboard *cp_gtk_selection; + +jobject cp_gtk_clipboard_instance; +jobject cp_gtk_selection_instance; + +/* Standard (string targets) shared with GtkSelection. */ +jstring cp_gtk_stringTarget; +jstring cp_gtk_imageTarget; +jstring cp_gtk_filesTarget; + +static jclass gtk_clipboard_class; + +static jmethodID setSystemContentsID; +static jmethodID provideContentID; +static jmethodID provideTextID; +static jmethodID provideImageID; +static jmethodID provideURIsID; + +/* Called when clipboard owner changes. Used to update available targets. */ +#if GTK_MINOR_VERSION > 4 +static void +clipboard_owner_change_cb (GtkClipboard *clipboard, + GdkEvent *event __attribute__((unused)), + gpointer user_data __attribute__((unused))) +{ + JNIEnv *env = cp_gtk_gdk_env (); + if (clipboard == cp_gtk_clipboard) + (*env)->CallVoidMethod (env, cp_gtk_clipboard_instance, + setSystemContentsID, JNI_FALSE); + else + (*env)->CallVoidMethod (env, cp_gtk_selection_instance, + setSystemContentsID, JNI_FALSE); + +} +#endif + +JNIEXPORT jboolean JNICALL +Java_gnu_java_awt_peer_gtk_GtkClipboard_initNativeState (JNIEnv *env, + jclass clz, + jobject gtkclipboard, + jobject gtkselection, + jstring string, + jstring image, + jstring files) +{ + GdkDisplay* display; + jboolean can_cache; + + gtk_clipboard_class = clz; + setSystemContentsID = (*env)->GetMethodID (env, gtk_clipboard_class, + "setSystemContents", + "(Z)V"); + if (setSystemContentsID == NULL) + return JNI_FALSE; + + provideContentID = (*env)->GetMethodID (env, gtk_clipboard_class, + "provideContent", + "(Ljava/lang/String;)[B"); + if (provideContentID == NULL) + return JNI_FALSE; + + provideTextID = (*env)->GetMethodID (env, gtk_clipboard_class, + "provideText", + "()Ljava/lang/String;"); + if (provideTextID == NULL) + return JNI_FALSE; + + provideImageID = (*env)->GetMethodID (env, gtk_clipboard_class, + "provideImage", + "()Lgnu/java/awt/peer/gtk/GtkImage;"); + if (provideImageID == NULL) + return JNI_FALSE; + + provideURIsID = (*env)->GetMethodID (env, gtk_clipboard_class, + "provideURIs", + "()[Ljava/lang/String;"); + if (provideURIsID == NULL) + return JNI_FALSE; + + cp_gtk_clipboard_instance = (*env)->NewGlobalRef(env, gtkclipboard); + cp_gtk_selection_instance = (*env)->NewGlobalRef(env, gtkselection); + + cp_gtk_stringTarget = (*env)->NewGlobalRef(env, string); + cp_gtk_imageTarget = (*env)->NewGlobalRef(env, image); + cp_gtk_filesTarget = (*env)->NewGlobalRef(env, files); + + gdk_threads_enter (); + cp_gtk_clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); + cp_gtk_selection = gtk_clipboard_get (GDK_SELECTION_PRIMARY); + + display = gtk_clipboard_get_display (cp_gtk_clipboard); + /* Check for support for clipboard owner changes. */ +#if GTK_MINOR_VERSION > 4 + if (gdk_display_supports_selection_notification (display)) + { + g_signal_connect (cp_gtk_clipboard, "owner-change", + G_CALLBACK (clipboard_owner_change_cb), NULL); + g_signal_connect (cp_gtk_selection, "owner-change", + G_CALLBACK (clipboard_owner_change_cb), NULL); + gdk_display_request_selection_notification (display, + GDK_SELECTION_CLIPBOARD); + gdk_display_request_selection_notification (display, + GDK_SELECTION_PRIMARY); + can_cache = JNI_TRUE; + } + else +#endif + can_cache = JNI_FALSE; + + gdk_threads_leave (); + + return can_cache; +} + +static void +clipboard_get_func (GtkClipboard *clipboard, + GtkSelectionData *selection, + guint info, + gpointer user_data __attribute__((unused))) +{ + jobject gtk_clipboard_instance; + JNIEnv *env = cp_gtk_gdk_env (); + + if (clipboard == cp_gtk_clipboard) + gtk_clipboard_instance = cp_gtk_clipboard_instance; + else + gtk_clipboard_instance = cp_gtk_selection_instance; + + if (info == OBJECT_TARGET) + { + const gchar *target_name; + jstring target_string; + jbyteArray bytes; + jint len; + jbyte *barray; + + target_name = gdk_atom_name (selection->target); + if (target_name == NULL) + return; + target_string = (*env)->NewStringUTF (env, target_name); + if (target_string == NULL) + return; + bytes = (*env)->CallObjectMethod(env, + gtk_clipboard_instance, + provideContentID, + target_string); + (*env)->DeleteLocalRef(env, target_string); + if (bytes == NULL) + return; + len = (*env)->GetArrayLength(env, bytes); + if (len <= 0) + return; + barray = (*env)->GetByteArrayElements(env, bytes, NULL); + if (barray == NULL) + return; + gtk_selection_data_set (selection, selection->target, 8, + (guchar *) barray, len); + + (*env)->ReleaseByteArrayElements(env, bytes, barray, 0); + + } + else if (info == TEXT_TARGET) + { + jstring string; + const gchar *text; + int len; + string = (*env)->CallObjectMethod(env, + gtk_clipboard_instance, + provideTextID); + if (string == NULL) + return; + len = (*env)->GetStringUTFLength (env, string); + if (len == -1) + return; + text = (*env)->GetStringUTFChars (env, string, NULL); + if (text == NULL) + return; + + gtk_selection_data_set_text (selection, text, len); + (*env)->ReleaseStringUTFChars (env, string, text); + } + /* Images and URIs/Files support only available with gtk+2.6 or higher. */ +#if GTK_MINOR_VERSION > 4 + else if (info == IMAGE_TARGET) + { + jobject gtkimage; + GdkPixbuf *pixbuf = NULL; + + gtkimage = (*env)->CallObjectMethod(env, + gtk_clipboard_instance, + provideImageID); + if (gtkimage == NULL) + return; + + pixbuf = cp_gtk_image_get_pixbuf (env, gtkimage); + if (pixbuf != NULL) + gtk_selection_data_set_pixbuf (selection, pixbuf); + } + else if (info == URI_TARGET) + { + jobjectArray uris; + jint count; + int i; + gchar **list; + + uris = (*env)->CallObjectMethod(env, + gtk_clipboard_instance, + provideURIsID); + if (uris == NULL) + return; + count = (*env)->GetArrayLength (env, uris); + if (count <= 0) + return; + + list = (gchar **) JCL_malloc (env, (count + 1) * sizeof (gchar *)); + for (i = 0; i < count; i++) + { + const char *text; + jstring uri; + + /* Mark NULL in so case of some error we can find the end. */ + list[i] = NULL; + uri = (*env)->GetObjectArrayElement (env, uris, i); + if (uri == NULL) + break; + text = (*env)->GetStringUTFChars (env, uri, NULL); + if (text == NULL) + { + (*env)->DeleteLocalRef(env, uri); + break; + } + list[i] = strdup (text); + (*env)->ReleaseStringUTFChars (env, uri, text); + (*env)->DeleteLocalRef(env, uri); + } + + if (i == count) + { + list[count] = NULL; + gtk_selection_data_set_uris (selection, list); + } + + for (i = 0; list[i] != NULL; i++) + free (list[i]); + JCL_free (env, list); + } +#endif +} + +static void +clipboard_clear_func (GtkClipboard *clipboard, + gpointer user_data __attribute__((unused))) +{ + JNIEnv *env = cp_gtk_gdk_env(); + if (clipboard == cp_gtk_clipboard) + (*env)->CallVoidMethod (env, cp_gtk_clipboard_instance, + setSystemContentsID, JNI_TRUE); + else + (*env)->CallVoidMethod (env, cp_gtk_selection_instance, + setSystemContentsID, JNI_TRUE); + +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkClipboard_advertiseContent +(JNIEnv *env, + jobject instance, + jobjectArray mime_array, +#if GTK_MINOR_VERSION > 4 + jboolean add_text, jboolean add_images, jboolean add_uris) +#else + jboolean add_text __attribute__((unused)), + jboolean add_images __attribute__((unused)), + jboolean add_uris __attribute__((unused))) +#endif +{ + GtkTargetList *target_list; + GList *list; + GtkTargetEntry *targets; + gint n, i; + + gdk_threads_enter (); + target_list = gtk_target_list_new (NULL, 0); + + if (mime_array != NULL) + { + n = (*env)->GetArrayLength (env, mime_array); + for (i = 0; i < n; i++) + { + const char *text; + jstring target; + GdkAtom atom; + + target = (*env)->GetObjectArrayElement (env, mime_array, i); + if (target == NULL) + break; + text = (*env)->GetStringUTFChars (env, target, NULL); + if (text == NULL) + break; + + atom = gdk_atom_intern (text, FALSE); + gtk_target_list_add (target_list, atom, 0, OBJECT_TARGET); + + (*env)->ReleaseStringUTFChars (env, target, text); + } + } + + /* Add extra targets that gtk+ can provide/translate for us. */ +#if GTK_MINOR_VERSION > 4 + if (add_text) + gtk_target_list_add_text_targets (target_list, TEXT_TARGET); + if (add_images) + gtk_target_list_add_image_targets (target_list, IMAGE_TARGET, TRUE); + if (add_uris) + gtk_target_list_add_uri_targets (target_list, URI_TARGET); +#else + if (add_text) + gtk_target_list_add (target_list, + gdk_atom_intern ("STRING", FALSE), + 0, TEXT_TARGET); +#endif + + + /* Turn list into a target table. */ + n = g_list_length (target_list->list); + if (n > 0) + { + targets = g_new (GtkTargetEntry, n); + for (list = target_list->list, i = 0; + list != NULL; + list = list->next, i++) + { + GtkTargetPair *pair = (GtkTargetPair *) list->data; + targets[i].target = gdk_atom_name (pair->target); + targets[i].flags = pair->flags; + targets[i].info = pair->info; + } + + /* Set the targets plus callback functions and ask for the clipboard + to be stored when the application exists if supported. */ + if ((*env)->IsSameObject(env, instance, cp_gtk_clipboard_instance)) + { + if (gtk_clipboard_set_with_data (cp_gtk_clipboard, targets, n, + clipboard_get_func, + clipboard_clear_func, + NULL)) + { +#if GTK_MINOR_VERSION > 4 + gtk_clipboard_set_can_store (cp_gtk_clipboard, NULL, 0); +#endif + } + } + else + { + if (gtk_clipboard_set_with_data (cp_gtk_selection, targets, n, + clipboard_get_func, + clipboard_clear_func, + NULL)) + { +#if GTK_MINOR_VERSION > 4 + gtk_clipboard_set_can_store (cp_gtk_selection, NULL, 0); +#endif + } + } + + for (i = 0; i < n; i++) + g_free (targets[i].target); + g_free (targets); + } + + gtk_target_list_unref (target_list); + gdk_threads_leave (); +} diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c new file mode 100644 index 000000000..5de5d82a6 --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c @@ -0,0 +1,1260 @@ +/* gtkcomponentpeer.c -- Native implementation of GtkComponentPeer + Copyright (C) 1998, 1999, 2002, 2004, 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkComponentPeer.h" + +#include + +#define AWT_DEFAULT_CURSOR 0 +#define AWT_CROSSHAIR_CURSOR 1 +#define AWT_TEXT_CURSOR 2 +#define AWT_WAIT_CURSOR 3 +#define AWT_SW_RESIZE_CURSOR 4 +#define AWT_SE_RESIZE_CURSOR 5 +#define AWT_NW_RESIZE_CURSOR 6 +#define AWT_NE_RESIZE_CURSOR 7 +#define AWT_N_RESIZE_CURSOR 8 +#define AWT_S_RESIZE_CURSOR 9 +#define AWT_W_RESIZE_CURSOR 10 +#define AWT_E_RESIZE_CURSOR 11 +#define AWT_HAND_CURSOR 12 +#define AWT_MOVE_CURSOR 13 + +/* FIXME: use gtk-double-click-time, gtk-double-click-distance */ +#define MULTI_CLICK_TIME 250 +/* as opposed to a MULTI_PASS_TIME :) */ + +#define AWT_MOUSE_CLICKED 500 +#define AWT_MOUSE_PRESSED 501 +#define AWT_MOUSE_RELEASED 502 +#define AWT_MOUSE_MOVED 503 +#define AWT_MOUSE_ENTERED 504 +#define AWT_MOUSE_EXITED 505 +#define AWT_MOUSE_DRAGGED 506 +#define AWT_MOUSE_WHEEL 507 + +#define AWT_WHEEL_UNIT_SCROLL 0 + +#define AWT_FOCUS_GAINED 1004 +#define AWT_FOCUS_LOST 1005 + +static GtkWidget *find_fg_color_widget (GtkWidget *widget); +static GtkWidget *find_bg_color_widget (GtkWidget *widget); +static GtkWidget *get_widget (GtkWidget *widget); + +static jmethodID postMouseEventID; +static jmethodID postMouseWheelEventID; +static jmethodID postExposeEventID; +static jmethodID postFocusEventID; + +void +cp_gtk_component_init_jni (void) + { + jclass gtkcomponentpeer; + + gtkcomponentpeer = (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(), + "gnu/java/awt/peer/gtk/GtkComponentPeer"); + + postMouseEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtkcomponentpeer, + "postMouseEvent", "(IJIIIIZ)V"); + + postMouseWheelEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkcomponentpeer, + "postMouseWheelEvent", + "(IJIIIIZIII)V"); + + postExposeEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtkcomponentpeer, + "postExposeEvent", "(IIII)V"); + + postFocusEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtkcomponentpeer, + "postFocusEvent", "(IZ)V"); +} + +static gboolean component_button_press_cb (GtkWidget *widget, + GdkEventButton *event, + jobject peer); +static gboolean component_button_release_cb (GtkWidget *widget, + GdkEventButton *event, + jobject peer); +static gboolean component_motion_notify_cb (GtkWidget *widget, + GdkEventMotion *event, + jobject peer); +static gboolean component_scroll_cb (GtkWidget *widget, + GdkEventScroll *event, + jobject peer); +static gboolean component_enter_notify_cb (GtkWidget *widget, + GdkEventCrossing *event, + jobject peer); +static gboolean component_leave_notify_cb (GtkWidget *widget, + GdkEventCrossing *event, + jobject peer); +static gboolean component_expose_cb (GtkWidget *widget, + GdkEventExpose *event, + jobject peer); +static gboolean component_focus_in_cb (GtkWidget *widget, + GdkEventFocus *event, + jobject peer); +static gboolean component_focus_out_cb (GtkWidget *widget, + GdkEventFocus *event, + jobject peer); + +static jint +button_to_awt_mods (int button) +{ + switch (button) + { + case 1: + return AWT_BUTTON1_DOWN_MASK | AWT_BUTTON1_MASK; + case 2: + return AWT_BUTTON2_DOWN_MASK | AWT_BUTTON2_MASK; + case 3: + return AWT_BUTTON3_DOWN_MASK | AWT_BUTTON3_MASK; + } + + return 0; +} + +jint +cp_gtk_state_to_awt_mods (guint state) +{ + jint result = 0; + + if (state & GDK_SHIFT_MASK) + result |= (AWT_SHIFT_DOWN_MASK | AWT_SHIFT_MASK); + if (state & GDK_CONTROL_MASK) + result |= (AWT_CTRL_DOWN_MASK | AWT_CTRL_MASK); + if (state & GDK_MOD1_MASK) + result |= (AWT_ALT_DOWN_MASK | AWT_ALT_MASK); + + return result; +} + +static jint +state_to_awt_mods_with_button_states (guint state) +{ + jint result = 0; + + if (state & GDK_SHIFT_MASK) + result |= AWT_SHIFT_DOWN_MASK | AWT_SHIFT_MASK; + if (state & GDK_CONTROL_MASK) + result |= AWT_CTRL_DOWN_MASK | AWT_CTRL_MASK; + if (state & GDK_MOD1_MASK) + result |= AWT_ALT_DOWN_MASK | AWT_ALT_MASK; + if (state & GDK_BUTTON1_MASK) + result |= AWT_BUTTON1_DOWN_MASK | AWT_BUTTON1_MASK; + if (state & GDK_BUTTON2_MASK) + result |= AWT_BUTTON2_DOWN_MASK; + if (state & GDK_BUTTON3_MASK) + result |= AWT_BUTTON3_DOWN_MASK; + + return result; +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetSetCursor + (JNIEnv *env, jobject obj, jint type, jobject image, jint x, jint y) +{ + gdk_threads_enter (); + + Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetSetCursorUnlocked + (env, obj, type, image, x, y); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetSetCursorUnlocked + (JNIEnv *env, jobject obj, jint type, jobject image, jint x, jint y) +{ + void *ptr; + GtkWidget *widget; + GdkWindow *win; + GdkCursorType gdk_cursor_type; + GdkCursor *gdk_cursor; + + ptr = gtkpeer_get_widget (env, obj); + + switch (type) + { + case AWT_CROSSHAIR_CURSOR: + gdk_cursor_type = GDK_CROSSHAIR; + break; + case AWT_TEXT_CURSOR: + gdk_cursor_type = GDK_XTERM; + break; + case AWT_WAIT_CURSOR: + gdk_cursor_type = GDK_WATCH; + break; + case AWT_SW_RESIZE_CURSOR: + gdk_cursor_type = GDK_BOTTOM_LEFT_CORNER; + break; + case AWT_SE_RESIZE_CURSOR: + gdk_cursor_type = GDK_BOTTOM_RIGHT_CORNER; + break; + case AWT_NW_RESIZE_CURSOR: + gdk_cursor_type = GDK_TOP_LEFT_CORNER; + break; + case AWT_NE_RESIZE_CURSOR: + gdk_cursor_type = GDK_TOP_RIGHT_CORNER; + break; + case AWT_N_RESIZE_CURSOR: + gdk_cursor_type = GDK_TOP_SIDE; + break; + case AWT_S_RESIZE_CURSOR: + gdk_cursor_type = GDK_BOTTOM_SIDE; + break; + case AWT_W_RESIZE_CURSOR: + gdk_cursor_type = GDK_LEFT_SIDE; + break; + case AWT_E_RESIZE_CURSOR: + gdk_cursor_type = GDK_RIGHT_SIDE; + break; + case AWT_HAND_CURSOR: + gdk_cursor_type = GDK_HAND2; + break; + case AWT_MOVE_CURSOR: + gdk_cursor_type = GDK_FLEUR; + break; + default: + gdk_cursor_type = GDK_LEFT_PTR; + } + + widget = get_widget(GTK_WIDGET(ptr)); + + win = widget->window; + if ((widget->window) == NULL) + win = GTK_WIDGET(ptr)->window; + + if (image == NULL) + gdk_cursor = gdk_cursor_new (gdk_cursor_type); + else + gdk_cursor + = gdk_cursor_new_from_pixbuf (gdk_drawable_get_display (win), + cp_gtk_image_get_pixbuf (env, image), + x, y); + + gdk_window_set_cursor (win, gdk_cursor); + gdk_cursor_unref (gdk_cursor); + + /* Make sure the cursor is replaced on screen. */ + gdk_flush(); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetSetParent + (JNIEnv *env, jobject obj, jobject parent) +{ + void *ptr; + void *parent_ptr; + GtkWidget *widget; + GtkWidget *parent_widget; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + parent_ptr = gtkpeer_get_widget (env, parent); + + widget = GTK_WIDGET (ptr); + parent_widget = get_widget(GTK_WIDGET (parent_ptr)); + + if (widget->parent == NULL) + { + if (GTK_IS_WINDOW (parent_widget)) + { + GList *children = gtk_container_get_children + (GTK_CONTAINER (parent_widget)); + + if (GTK_IS_MENU_BAR (children->data)) + gtk_fixed_put (GTK_FIXED (children->next->data), widget, 0, 0); + else + gtk_fixed_put (GTK_FIXED (children->data), widget, 0, 0); + } + else + if (GTK_IS_SCROLLED_WINDOW (parent_widget)) + { + gtk_scrolled_window_add_with_viewport + (GTK_SCROLLED_WINDOW (parent_widget), widget); + gtk_viewport_set_shadow_type (GTK_VIEWPORT (widget->parent), + GTK_SHADOW_NONE); + + } + else + { + if (widget->parent == NULL) + gtk_fixed_put (GTK_FIXED (parent_widget), widget, 0, 0); + } + } + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetSetSensitive + (JNIEnv *env, jobject obj, jboolean sensitive) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + gtk_widget_set_sensitive (get_widget(GTK_WIDGET (ptr)), sensitive); + + gdk_threads_leave (); +} + +JNIEXPORT jboolean JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetHasFocus +(JNIEnv *env, jobject obj) +{ + void *ptr; + jboolean retval; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + retval = GTK_WIDGET_HAS_FOCUS((GTK_WIDGET (ptr))); + + gdk_threads_leave (); + + return retval; +} + +JNIEXPORT jboolean JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetCanFocus +(JNIEnv *env, jobject obj) +{ + void *ptr; + jboolean retval; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + retval = GTK_WIDGET_CAN_FOCUS((GTK_WIDGET (ptr))); + + gdk_threads_leave (); + + return retval; +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetRequestFocus + (JNIEnv *env, jobject obj) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + gtk_widget_grab_focus (get_widget(GTK_WIDGET (ptr))); + + gdk_threads_leave (); +} + +/* + * Translate a Java KeyEvent object into a GdkEventKey event, then + * pass it to the GTK main loop for processing. + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetDispatchKeyEvent + (JNIEnv *env, jobject obj, jint id, jlong when, jint mods, + jint keyCode, jint keyLocation) +{ + void *ptr; + GdkEvent *event = NULL; + GdkKeymapKey *keymap_keys = NULL; + gint n_keys = 0; + guint lookup_keyval = 0; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + if (id == AWT_KEY_PRESSED) + event = gdk_event_new (GDK_KEY_PRESS); + else if (id == AWT_KEY_RELEASED) + event = gdk_event_new (GDK_KEY_RELEASE); + else + { + gdk_threads_leave (); + /* Don't send AWT KEY_TYPED events to GTK. */ + return; + } + + if (GTK_IS_BUTTON (ptr)) + event->key.window = GTK_BUTTON (get_widget(GTK_WIDGET (ptr)))->event_window; + else if (GTK_IS_SCROLLED_WINDOW (get_widget(GTK_WIDGET (ptr)))) + event->key.window = GTK_WIDGET (GTK_SCROLLED_WINDOW (get_widget(GTK_WIDGET (ptr)))->container.child)->window; + else + event->key.window = get_widget(GTK_WIDGET (ptr))->window; + + event->key.send_event = 0; + event->key.time = (guint32) when; + + if (mods & AWT_SHIFT_DOWN_MASK) + event->key.state |= GDK_SHIFT_MASK; + if (mods & AWT_CTRL_DOWN_MASK) + event->key.state |= GDK_CONTROL_MASK; + if (mods & AWT_ALT_DOWN_MASK) + event->key.state |= GDK_MOD1_MASK; + + /* This hack is needed because the AWT has no notion of num lock. + It infers numlock state from the only Java virtual keys that are + affected by it. */ + if (keyCode == VK_NUMPAD9 + || keyCode == VK_NUMPAD8 + || keyCode == VK_NUMPAD7 + || keyCode == VK_NUMPAD6 + || keyCode == VK_NUMPAD5 + || keyCode == VK_NUMPAD4 + || keyCode == VK_NUMPAD3 + || keyCode == VK_NUMPAD2 + || keyCode == VK_NUMPAD1 + || keyCode == VK_NUMPAD0 + || keyCode == VK_DECIMAL) + event->key.state |= GDK_MOD2_MASK; + + /* These values don't need to be filled in since GTK doesn't use + them. */ + event->key.length = 0; + event->key.string = NULL; + + lookup_keyval = cp_gtk_awt_keycode_to_keysym (keyCode, keyLocation); + + if (!gdk_keymap_get_entries_for_keyval (gdk_keymap_get_default (), + lookup_keyval, + &keymap_keys, + &n_keys)) + { + /* No matching keymap entry was found. */ + g_printerr ("No matching keymap entries were found\n"); + gdk_threads_leave (); + return; + } + + /* Note: if n_keys > 1 then there are multiple hardware keycodes + that translate to lookup_keyval. We arbitrarily choose the first + hardware keycode from the list returned by + gdk_keymap_get_entries_for_keyval. */ + + event->key.hardware_keycode = keymap_keys[0].keycode; + event->key.group = keymap_keys[0].group; + + g_free (keymap_keys); + + if (!gdk_keymap_translate_keyboard_state (gdk_keymap_get_default (), + event->key.hardware_keycode, + event->key.state, + event->key.group, + &event->key.keyval, + NULL, NULL, NULL)) + { + /* No matching keyval was found. */ + g_printerr ("No matching keyval was found\n"); + gdk_threads_leave (); + return; + } + + /* keyevent = (GdkEventKey *) event; */ + /* g_printerr ("generated event: sent: %d time: %d state: %d keyval: %d length: %d string: %s hardware_keycode: %d group: %d\n", keyevent->send_event, keyevent->time, keyevent->state, keyevent->keyval, keyevent->length, keyevent->string, keyevent->hardware_keycode, keyevent->group); */ + + /* We already received the original key event on the window itself, + so we don't want to resend it. */ + if (!GTK_IS_WINDOW (ptr)) + { + if (GTK_IS_SCROLLED_WINDOW (get_widget(GTK_WIDGET (ptr)))) + gtk_widget_event (GTK_WIDGET (GTK_SCROLLED_WINDOW (get_widget(GTK_WIDGET (ptr)))->container.child), event); + else + gtk_widget_event (get_widget(GTK_WIDGET (ptr)), event); + } + + gdk_threads_leave (); +} + +/* + * Find the origin of a widget's window. + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWindowGetLocationOnScreen + (JNIEnv * env, jobject obj, jintArray jpoint) +{ + gdk_threads_enter(); + + Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWindowGetLocationOnScreenUnlocked + (env, obj, jpoint); + + gdk_threads_leave(); + +} +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWindowGetLocationOnScreenUnlocked + (JNIEnv * env, jobject obj, jintArray jpoint) +{ + void *ptr; + jint *point; + + ptr = gtkpeer_get_widget (env, obj); + point = (*env)->GetIntArrayElements (env, jpoint, 0); + + gdk_window_get_root_origin (get_widget(GTK_WIDGET (ptr))->window, point, point+1); + + (*env)->ReleaseIntArrayElements(env, jpoint, point, 0); +} + +/* + * Find the origin of a widget + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetGetLocationOnScreen + (JNIEnv * env, jobject obj, jintArray jpoint) +{ + gdk_threads_enter(); + + Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetGetLocationOnScreenUnlocked + (env, obj, jpoint); + + gdk_threads_leave(); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetGetLocationOnScreenUnlocked + (JNIEnv * env, jobject obj, jintArray jpoint) +{ + void *ptr; + jint *point; + GtkWidget *widget; + + ptr = gtkpeer_get_widget (env, obj); + point = (*env)->GetIntArrayElements (env, jpoint, 0); + + widget = get_widget(GTK_WIDGET (ptr)); + while(gtk_widget_get_parent(widget) != NULL) + widget = gtk_widget_get_parent(widget); + gdk_window_get_position (GTK_WIDGET(widget)->window, point, point+1); + + *point += GTK_WIDGET(ptr)->allocation.x; + *(point+1) += GTK_WIDGET(ptr)->allocation.y; + + (*env)->ReleaseIntArrayElements(env, jpoint, point, 0); +} + +/* + * Find this widget's current size. + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetGetDimensions + (JNIEnv *env, jobject obj, jintArray jdims) +{ + void *ptr; + jint *dims; + GtkRequisition requisition; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + dims = (*env)->GetIntArrayElements (env, jdims, 0); + dims[0] = dims[1] = 0; + + gtk_widget_size_request (get_widget(GTK_WIDGET (ptr)), &requisition); + + dims[0] = requisition.width; + dims[1] = requisition.height; + + (*env)->ReleaseIntArrayElements (env, jdims, dims, 0); + + gdk_threads_leave (); +} + +/* + * Find this widget's preferred size. + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetGetPreferredDimensions + (JNIEnv *env, jobject obj, jintArray jdims) +{ + void *ptr; + jint *dims; + GtkRequisition current_req; + GtkRequisition natural_req; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + dims = (*env)->GetIntArrayElements (env, jdims, 0); + dims[0] = dims[1] = 0; + + /* Widgets that extend GtkWindow such as GtkFileChooserDialog may have + a default size. These values seem more useful then the natural + requisition values, particularly for GtkFileChooserDialog. */ + if (GTK_IS_WINDOW (get_widget(GTK_WIDGET (ptr)))) + { + gint width, height; + gtk_window_get_default_size (GTK_WINDOW (get_widget(GTK_WIDGET (ptr))), &width, &height); + + dims[0] = width; + dims[1] = height; + } + else + { + /* Save the widget's current size request. */ + gtk_widget_size_request (get_widget(GTK_WIDGET (ptr)), ¤t_req); + + /* Get the widget's "natural" size request. */ + gtk_widget_set_size_request (get_widget(GTK_WIDGET (ptr)), -1, -1); + gtk_widget_size_request (get_widget(GTK_WIDGET (ptr)), &natural_req); + + /* Reset the widget's size request. */ + gtk_widget_set_size_request (get_widget(GTK_WIDGET (ptr)), + current_req.width, current_req.height); + + dims[0] = natural_req.width; + dims[1] = natural_req.height; + } + + (*env)->ReleaseIntArrayElements (env, jdims, dims, 0); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_setNativeBounds + (JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height) +{ + GtkWidget *widget; + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + widget = GTK_WIDGET (ptr); + + /* We assume that -1 is a width or height and not a request for the + widget's natural size. */ + width = width < 0 ? 0 : width; + height = height < 0 ? 0 : height; + + if (!(width == 0 && height == 0)) + { + gtk_widget_set_size_request (widget, width, height); + /* The GTK_IS_FIXED check here prevents gtk_fixed_move being + called when our parent is a GtkScrolledWindow. In that + case though, moving the child widget is invalid since a + ScrollPane only has one child and that child is always + located at (0, 0) in viewport coordinates. */ + if (widget->parent != NULL && GTK_IS_FIXED (widget->parent)) + gtk_fixed_move (GTK_FIXED (widget->parent), widget, x, y); + } + + gdk_threads_leave (); +} + +JNIEXPORT jintArray JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetGetBackground + (JNIEnv *env, jobject obj) +{ + void *ptr; + jintArray array; + int *rgb; + GdkColor bg; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + bg = GTK_WIDGET (ptr)->style->bg[GTK_STATE_NORMAL]; + + array = (*env)->NewIntArray (env, 3); + + rgb = (*env)->GetIntArrayElements (env, array, NULL); + /* convert color data from 16 bit values down to 8 bit values */ + rgb[0] = bg.red >> 8; + rgb[1] = bg.green >> 8; + rgb[2] = bg.blue >> 8; + (*env)->ReleaseIntArrayElements (env, array, rgb, 0); + + gdk_threads_leave (); + + return array; +} + +JNIEXPORT jintArray JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetGetForeground + (JNIEnv *env, jobject obj) +{ + void *ptr; + jintArray array; + jint *rgb; + GdkColor fg; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + fg = get_widget(GTK_WIDGET (ptr))->style->fg[GTK_STATE_NORMAL]; + + array = (*env)->NewIntArray (env, 3); + + rgb = (*env)->GetIntArrayElements (env, array, NULL); + /* convert color data from 16 bit values down to 8 bit values */ + rgb[0] = fg.red >> 8; + rgb[1] = fg.green >> 8; + rgb[2] = fg.blue >> 8; + (*env)->ReleaseIntArrayElements (env, array, rgb, 0); + + gdk_threads_leave (); + + return array; +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetSetBackground + (JNIEnv *env, jobject obj, jint red, jint green, jint blue) +{ + GdkColor normal_color; + GdkColor active_color; + GtkWidget *widget; + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + normal_color.red = (red / 255.0) * 65535; + normal_color.green = (green / 255.0) * 65535; + normal_color.blue = (blue / 255.0) * 65535; + + /* This calculation only approximates the active colors produced by + Sun's AWT. */ + active_color.red = 0.85 * (red / 255.0) * 65535; + active_color.green = 0.85 * (green / 255.0) * 65535; + active_color.blue = 0.85 * (blue / 255.0) * 65535; + + widget = find_bg_color_widget (GTK_WIDGET (ptr)); + + gtk_widget_modify_bg (widget, GTK_STATE_NORMAL, &normal_color); + gtk_widget_modify_bg (widget, GTK_STATE_ACTIVE, &active_color); + gtk_widget_modify_bg (widget, GTK_STATE_PRELIGHT, &normal_color); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetSetForeground + (JNIEnv *env, jobject obj, jint red, jint green, jint blue) +{ + GdkColor color; + GtkWidget *widget; + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + color.red = (red / 255.0) * 65535; + color.green = (green / 255.0) * 65535; + color.blue = (blue / 255.0) * 65535; + + widget = find_fg_color_widget (GTK_WIDGET (ptr)); + + gtk_widget_modify_fg (widget, GTK_STATE_NORMAL, &color); + gtk_widget_modify_fg (widget, GTK_STATE_ACTIVE, &color); + gtk_widget_modify_fg (widget, GTK_STATE_PRELIGHT, &color); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_realize (JNIEnv *env, jobject obj) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + gtk_widget_realize (GTK_WIDGET (ptr)); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_setVisibleNative + (JNIEnv *env, jobject obj, jboolean visible) +{ + gdk_threads_enter(); + + Java_gnu_java_awt_peer_gtk_GtkComponentPeer_setVisibleNativeUnlocked + (env, obj, visible); + + gdk_threads_leave(); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_setVisibleNativeUnlocked + (JNIEnv *env, jobject obj, jboolean visible) +{ + void *ptr; + + ptr = gtkpeer_get_widget (env, obj); + + if (visible) + gtk_widget_show (GTK_WIDGET (ptr)); + else + gtk_widget_hide (GTK_WIDGET (ptr)); +} + +JNIEXPORT jboolean JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_isEnabled + (JNIEnv *env, jobject obj) +{ + void *ptr; + jboolean ret_val; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + ret_val = GTK_WIDGET_IS_SENSITIVE (get_widget(GTK_WIDGET (ptr))); + + gdk_threads_leave (); + + return ret_val; +} + +JNIEXPORT jboolean JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_modalHasGrab + (JNIEnv *env __attribute__((unused)), jclass clazz __attribute__((unused))) +{ + GtkWidget *widget; + jboolean retval; + + gdk_threads_enter (); + + widget = gtk_grab_get_current (); + retval = (widget && GTK_IS_WINDOW (widget) && GTK_WINDOW (widget)->modal); + + gdk_threads_leave (); + + return retval; +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectSignals + (JNIEnv *env, jobject obj) +{ + void *ptr; + jobject gref; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + gref = gtkpeer_get_global_ref (env, obj); + + cp_gtk_component_connect_signals (ptr, gref); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkComponentPeer_setNativeEventMask + (JNIEnv *env, jobject obj) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + gtk_widget_add_events (get_widget(GTK_WIDGET (ptr)), + GDK_POINTER_MOTION_MASK + | GDK_BUTTON_MOTION_MASK + | GDK_BUTTON_PRESS_MASK + | GDK_BUTTON_RELEASE_MASK + | GDK_KEY_PRESS_MASK + | GDK_KEY_RELEASE_MASK + | GDK_ENTER_NOTIFY_MASK + | GDK_LEAVE_NOTIFY_MASK + | GDK_STRUCTURE_MASK + | GDK_KEY_PRESS_MASK + | GDK_FOCUS_CHANGE_MASK); + + gdk_threads_leave (); +} + +static GtkWidget * +get_widget (GtkWidget *widget) +{ + GtkWidget *w; + + if (GTK_IS_EVENT_BOX (widget)) + w = gtk_bin_get_child (GTK_BIN(widget)); + else + w = widget; + + return w; +} + +/* FIXME: these functions should be implemented by overridding the + appropriate GtkComponentPeer methods. */ +static GtkWidget * +find_fg_color_widget (GtkWidget *widget) +{ + GtkWidget *fg_color_widget; + + if (GTK_IS_EVENT_BOX (widget) + || (GTK_IS_BUTTON (widget) + && !GTK_IS_COMBO_BOX (widget))) + fg_color_widget = gtk_bin_get_child (GTK_BIN(widget)); + else + fg_color_widget = widget; + + return fg_color_widget; +} + +static GtkWidget * +find_bg_color_widget (GtkWidget *widget) +{ + GtkWidget *bg_color_widget; + + bg_color_widget = widget; + + return bg_color_widget; +} + +void +cp_gtk_component_connect_expose_signals (GObject *ptr, jobject gref) +{ + g_signal_connect (G_OBJECT (ptr), "expose-event", + G_CALLBACK (component_expose_cb), gref); +} + +void +cp_gtk_component_connect_focus_signals (GObject *ptr, jobject gref) +{ + g_signal_connect (G_OBJECT (ptr), "focus-in-event", + G_CALLBACK (component_focus_in_cb), gref); + + g_signal_connect (G_OBJECT (ptr), "focus-out-event", + G_CALLBACK (component_focus_out_cb), gref); +} + +void +cp_gtk_component_connect_mouse_signals (GObject *ptr, jobject gref) +{ + g_signal_connect (G_OBJECT (ptr), "button-press-event", + G_CALLBACK (component_button_press_cb), gref); + + g_signal_connect (G_OBJECT (ptr), "button-release-event", + G_CALLBACK (component_button_release_cb), gref); + + g_signal_connect (G_OBJECT (ptr), "enter-notify-event", + G_CALLBACK (component_enter_notify_cb), gref); + + g_signal_connect (G_OBJECT (ptr), "leave-notify-event", + G_CALLBACK (component_leave_notify_cb), gref); + + g_signal_connect (G_OBJECT (ptr), "motion-notify-event", + G_CALLBACK (component_motion_notify_cb), gref); + + g_signal_connect (G_OBJECT (ptr), "scroll-event", + G_CALLBACK (component_scroll_cb), gref); +} + +void +cp_gtk_component_connect_signals (GObject *ptr, jobject gref) +{ + cp_gtk_component_connect_expose_signals (ptr, gref); + cp_gtk_component_connect_focus_signals (ptr, gref); + cp_gtk_component_connect_mouse_signals (ptr, gref); +} + +/* These variables are used to keep track of click counts. The AWT + allows more than a triple click to occur but GTK doesn't report + more-than-triple clicks. Also used for keeping track of scroll events.*/ +static jint click_count = 1; +static guint32 button_click_time = 0; +static GdkWindow *button_window = NULL; +static guint button_number_direction = -1; +static int hasBeenDragged; + +static gboolean +component_button_press_cb (GtkWidget *widget __attribute__((unused)), + GdkEventButton *event, + jobject peer) +{ + /* Ignore double and triple click events. */ + if (event->type == GDK_2BUTTON_PRESS + || event->type == GDK_3BUTTON_PRESS) + return FALSE; + + if ((event->time < (button_click_time + MULTI_CLICK_TIME)) + && (event->window == button_window) + && (event->button == button_number_direction)) + click_count++; + else + click_count = 1; + + button_click_time = event->time; + button_window = event->window; + button_number_direction = event->button; + + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postMouseEventID, + AWT_MOUSE_PRESSED, + (jlong)event->time, + cp_gtk_state_to_awt_mods (event->state) + | button_to_awt_mods (event->button), + (jint)event->x, + (jint)event->y, + click_count, + (event->button == 3) ? JNI_TRUE : + JNI_FALSE); + + hasBeenDragged = FALSE; + + return FALSE; +} + +static gboolean +component_button_release_cb (GtkWidget *widget __attribute__((unused)), + GdkEventButton *event, + jobject peer) +{ + int width, height; + + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postMouseEventID, + AWT_MOUSE_RELEASED, + (jlong)event->time, + cp_gtk_state_to_awt_mods (event->state) + | button_to_awt_mods (event->button), + (jint)event->x, + (jint)event->y, + click_count, + JNI_FALSE); + + /* Generate an AWT click event only if the release occured in the + window it was pressed in, and the mouse has not been dragged since + the last time it was pressed. */ + gdk_drawable_get_size (event->window, &width, &height); + if (! hasBeenDragged + && event->x >= 0 + && event->y >= 0 + && event->x <= width + && event->y <= height) + { + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postMouseEventID, + AWT_MOUSE_CLICKED, + (jlong)event->time, + cp_gtk_state_to_awt_mods (event->state) + | button_to_awt_mods (event->button), + (jint)event->x, + (jint)event->y, + click_count, + JNI_FALSE); + } + return FALSE; +} + +static gboolean +component_motion_notify_cb (GtkWidget *widget __attribute__((unused)), + GdkEventMotion *event, + jobject peer) +{ + if (event->state & (GDK_BUTTON1_MASK + | GDK_BUTTON2_MASK + | GDK_BUTTON3_MASK + | GDK_BUTTON4_MASK + | GDK_BUTTON5_MASK)) + { + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postMouseEventID, + AWT_MOUSE_DRAGGED, + (jlong)event->time, + state_to_awt_mods_with_button_states (event->state), + (jint)event->x, + (jint)event->y, + 0, + JNI_FALSE); + + hasBeenDragged = TRUE; + } + else + { + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, postMouseEventID, + AWT_MOUSE_MOVED, + (jlong)event->time, + cp_gtk_state_to_awt_mods (event->state), + (jint)event->x, + (jint)event->y, + 0, + JNI_FALSE); + } + return FALSE; +} + +static gboolean +component_scroll_cb (GtkWidget *widget __attribute__((unused)), + GdkEventScroll *event, + jobject peer) +{ + int rotation; + /** Record click count for specific direction. */ + if ((event->time < (button_click_time + MULTI_CLICK_TIME)) + && (event->window == button_window) + && (event->direction == button_number_direction)) + click_count++; + else + click_count = 1; + + button_click_time = event->time; + button_window = event->window; + button_number_direction = event->direction; + + if (event->direction == GDK_SCROLL_UP + || event->direction == GDK_SCROLL_LEFT) + rotation = -1; + else + rotation = 1; + + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postMouseWheelEventID, + AWT_MOUSE_WHEEL, + (jlong)event->time, + cp_gtk_state_to_awt_mods (event->state), + (jint)event->x, + (jint)event->y, + click_count, + JNI_FALSE, + AWT_WHEEL_UNIT_SCROLL, + 1 /* amount */, + rotation); + return FALSE; +} + +static gboolean +component_enter_notify_cb (GtkWidget *widget __attribute__((unused)), + GdkEventCrossing *event, + jobject peer) +{ + /* We are not interested in enter events that are due to + grab/ungrab and not to actually crossing boundaries */ + if (event->mode == GDK_CROSSING_NORMAL) + { + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, postMouseEventID, + AWT_MOUSE_ENTERED, + (jlong)event->time, + state_to_awt_mods_with_button_states (event->state), + (jint)event->x, + (jint)event->y, + 0, + JNI_FALSE); + } + return FALSE; +} + +static gboolean +component_leave_notify_cb (GtkWidget *widget __attribute__((unused)), + GdkEventCrossing *event, + jobject peer) +{ + /* We are not interested in leave events that are due to + grab/ungrab and not to actually crossing boundaries */ + if (event->mode == GDK_CROSSING_NORMAL) + { + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postMouseEventID, + AWT_MOUSE_EXITED, + (jlong)event->time, + state_to_awt_mods_with_button_states (event->state), + (jint)event->x, + (jint)event->y, + 0, + JNI_FALSE); + } + return FALSE; +} + +static gboolean +component_expose_cb (GtkWidget *widget __attribute__((unused)), + GdkEventExpose *event, + jobject peer) +{ + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postExposeEventID, + (jint)event->area.x, + (jint)event->area.y, + (jint)event->area.width, + (jint)event->area.height); + + return FALSE; +} + +static gboolean +component_focus_in_cb (GtkWidget *widget __attribute((unused)), + GdkEventFocus *event __attribute((unused)), + jobject peer) +{ + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postFocusEventID, + AWT_FOCUS_GAINED, + JNI_FALSE); + + return FALSE; +} + +static gboolean +component_focus_out_cb (GtkWidget *widget __attribute((unused)), + GdkEventFocus *event __attribute((unused)), + jobject peer) +{ + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postFocusEventID, + AWT_FOCUS_LOST, + JNI_FALSE); + + return FALSE; +} diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer.c new file mode 100644 index 000000000..fabadc8ca --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer.c @@ -0,0 +1,84 @@ +/* gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer.c -- Native + implementation of GtkEmbeddedWindowPeer + Copyright (C) 2003, 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer.h" + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer_create + (JNIEnv *env, jobject obj, jlong socket_id) +{ + GtkWidget *window; + GtkWidget *fixed; + + gdk_threads_enter (); + + gtkpeer_set_global_ref (env, obj); + + window = gtk_plug_new ((GdkNativeWindow) socket_id); + + gtk_window_set_decorated (GTK_WINDOW (window), FALSE); + + fixed = gtk_fixed_new (); + gtk_container_add (GTK_CONTAINER (window), fixed); + + gtk_widget_show (fixed); + + gtkpeer_set_widget (env, obj, window); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer_construct + (JNIEnv *env, jobject obj, jlong socket_id) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + if (GTK_WIDGET_REALIZED (GTK_WIDGET (ptr))) + g_printerr ("ERROR: GtkPlug is already realized\n"); + + gtk_plug_construct (GTK_PLUG (ptr), (GdkNativeWindow) socket_id); + + gdk_threads_leave (); +} diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFileDialogPeer.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFileDialogPeer.c new file mode 100644 index 000000000..10f512f29 --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFileDialogPeer.c @@ -0,0 +1,302 @@ +/* gtkfiledialogpeer.c -- Native implementation of GtkFileDialogPeer + Copyright (C) 1998, 1999, 2002, 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkComponentPeer.h" +#include "gnu_java_awt_peer_gtk_GtkFileDialogPeer.h" + +#define AWT_FILEDIALOG_LOAD 0 +#define AWT_FILEDIALOG_SAVE 1 + +static void handle_response_cb (GtkDialog *dialog, + gint responseId, + jobject peer_obj); + +static jmethodID gtkSetFilenameID; +static jmethodID gtkHideFileDialogID; +static jmethodID gtkDisposeFileDialogID; +static jmethodID filenameFilterCallbackID; + +void +cp_gtk_filedialog_init_jni (void) +{ + jclass gtkfiledialogpeer; + + gtkfiledialogpeer = + (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(), + "gnu/java/awt/peer/gtk/GtkFileDialogPeer"); + + gtkDisposeFileDialogID = + (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkfiledialogpeer, + "gtkDisposeFileDialog", "()V"); + + gtkHideFileDialogID = + (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkfiledialogpeer, + "gtkHideFileDialog", "()V"); + + gtkSetFilenameID = + (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkfiledialogpeer, + "gtkSetFilename", + "(Ljava/lang/String;)V"); + + filenameFilterCallbackID = + (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkfiledialogpeer, + "filenameFilterCallback", + "(Ljava/lang/String;)Z"); +} + +/* + * Make a new file selection dialog + */ + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_create + (JNIEnv *env, jobject obj, jobject parent, jint mode) +{ + void *parentp; + gpointer widget; + + gdk_threads_enter (); + + /* Create global reference and save it for future use */ + gtkpeer_set_global_ref (env, obj); + + parentp = gtkpeer_get_widget(env, parent); + + if (mode == AWT_FILEDIALOG_LOAD) + widget = gtk_file_chooser_dialog_new + ("Open File", + GTK_WINDOW(parentp), + GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, + NULL); + else + { + widget = gtk_file_chooser_dialog_new + ("Save File", + GTK_WINDOW(parentp), + GTK_FILE_CHOOSER_ACTION_SAVE, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, + NULL); +#if GTK_MINOR_VERSION >= 8 + gtk_file_chooser_set_do_overwrite_confirmation + (GTK_FILE_CHOOSER (widget), TRUE); +#endif + } + + + /* GtkFileChooserDialog is not modal by default */ + gtk_window_set_modal (GTK_WINDOW (widget), TRUE); + + /* We must add this window to the group so input in the others are + disable while it is being shown */ + gtk_window_group_add_window (cp_gtk_global_window_group, + GTK_WINDOW (widget)); + + gtkpeer_set_widget (env, obj, widget); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_connectSignals + (JNIEnv *env, jobject obj) +{ + void *ptr = NULL; + jobject gref; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + gref = gtkpeer_get_global_ref (env, obj); + + /* FileDialog signals */ + g_signal_connect (G_OBJECT (ptr), "response", + G_CALLBACK (handle_response_cb), gref); + + /* Component signals */ + cp_gtk_component_connect_signals (G_OBJECT (ptr), gref); + + gdk_threads_leave (); +} + +JNIEXPORT jstring JNICALL +Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_nativeGetDirectory + (JNIEnv *env, jobject obj) +{ + void *ptr; + const char *str; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + str = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER(ptr)); + + gdk_threads_leave (); + + return (*env)->NewStringUTF(env, str); +} + + +/* This function interfaces with the Java callback method of the same name. + This function extracts the filename from the GtkFileFilterInfo object, + and passes it to the Java method. The Java method will call the filter's + accept() method and will give back the return value. */ +static gboolean filename_filter_cb (const GtkFileFilterInfo *filter_info, + gpointer obj) +{ + jstring *filename; + gboolean accepted; + + filename = (*cp_gtk_gdk_env())->NewStringUTF(cp_gtk_gdk_env(), filter_info->filename); + + accepted = (*cp_gtk_gdk_env())->CallBooleanMethod(cp_gtk_gdk_env(), obj, + filenameFilterCallbackID, + filename); + + return accepted; +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_nativeSetFilenameFilter + (JNIEnv *env, jobject obj, jobject filter_obj __attribute__((unused))) +{ + void *ptr; + GtkFileFilter *filter; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + filter = gtk_file_filter_new(); + gtk_file_filter_add_custom(filter, GTK_FILE_FILTER_FILENAME, + filename_filter_cb, obj, NULL); + + gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(ptr), filter); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_nativeSetDirectory + (JNIEnv *env, jobject obj, jstring directory) +{ + void *ptr; + const char *str; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + str = (*env)->GetStringUTFChars (env, directory, 0); + + gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(ptr), str); + + (*env)->ReleaseStringUTFChars (env, directory, str); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_nativeSetFile + (JNIEnv *env, jobject obj, jstring filename) +{ + void *ptr; + const char *str; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + str = (*env)->GetStringUTFChars (env, filename, 0); + + gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (ptr), str); + + (*env)->ReleaseStringUTFChars (env, filename, str); + + gdk_threads_leave (); +} + +static void +handle_response_cb (GtkDialog *dialog __attribute__((unused)), + gint responseId, + jobject peer_obj) +{ + void *ptr; + G_CONST_RETURN gchar *fileName; + jstring str_fileName = NULL; + + /* We only need this for the case when the user closed the window, + or clicked ok or cancel. */ + if (responseId != GTK_RESPONSE_DELETE_EVENT + && responseId != GTK_RESPONSE_ACCEPT + && responseId != GTK_RESPONSE_CANCEL) + return; + + ptr = gtkpeer_get_widget (cp_gtk_gdk_env(), peer_obj); + + if (responseId == GTK_RESPONSE_DELETE_EVENT) + { + /* We can dispose of the dialog now (and unblock show) */ + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer_obj, + gtkDisposeFileDialogID); + + return; + } + + if (responseId == GTK_RESPONSE_ACCEPT) + { + fileName = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (GTK_WIDGET (ptr))); + str_fileName = (*cp_gtk_gdk_env())->NewStringUTF (cp_gtk_gdk_env(), fileName); + } + + /* Set the Java object field 'file' with this value. */ + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer_obj, + gtkSetFilenameID, str_fileName); + + /* We can hide the dialog now (and unblock show) */ + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer_obj, + gtkHideFileDialogID); +} diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFramePeer.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFramePeer.c new file mode 100644 index 000000000..ef7df0f03 --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFramePeer.c @@ -0,0 +1,234 @@ +/* gtkframepeer.c -- Native implementation of GtkFramePeer + Copyright (C) 1998, 1999, 2002 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + +#include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkFramePeer.h" + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkFramePeer_removeMenuBarPeer + (JNIEnv *env, jobject obj) +{ + void *ptr; + void *mptr; + void *fixed; + GList* children; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + fixed = gtk_container_get_children (GTK_CONTAINER (ptr))->data; + children = gtk_container_get_children (GTK_CONTAINER (fixed)); + + while (children != NULL && !GTK_IS_MENU_SHELL (children->data)) + { + children = children->next; + } + + /* If there's a menu bar, remove it. */ + if (children != NULL) + { + mptr = children->data; + + /* This will actually destroy the MenuBar. By removing it from + its parent, the reference count for the MenuBar widget will + decrement to 0. The widget will be automatically destroyed by + GTK. */ + gtk_container_remove (GTK_CONTAINER (fixed), GTK_WIDGET (mptr)); + } + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkFramePeer_setMenuBarPeer + (JNIEnv *env, jobject obj, jobject menubar) +{ + void *ptr; + void *mptr; + void *fixed; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + if (menubar) + { + mptr = gtkpeer_get_widget (env, menubar); + + fixed = gtk_container_get_children (GTK_CONTAINER (ptr))->data; + gtk_fixed_put (GTK_FIXED (fixed), mptr, 0, 0); + gtk_widget_show (mptr); + } + + gdk_threads_leave (); +} + +JNIEXPORT jint JNICALL +Java_gnu_java_awt_peer_gtk_GtkFramePeer_getMenuBarHeight + (JNIEnv *env, jobject obj __attribute__((unused)), jobject menubar) +{ + GtkWidget *ptr; + GtkRequisition requisition; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, menubar); + + gtk_widget_size_request (ptr, &requisition); + + gdk_threads_leave (); + + return requisition.height; +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkFramePeer_setMenuBarWidth + (JNIEnv *env, jobject obj, jobject menubar, jint width) +{ + gdk_threads_enter (); + + Java_gnu_java_awt_peer_gtk_GtkFramePeer_setMenuBarWidthUnlocked + (env, obj, menubar, width); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkFramePeer_setMenuBarWidthUnlocked + (JNIEnv *env, jobject obj __attribute__((unused)), jobject menubar, jint width) +{ + GtkWidget *ptr; + GtkRequisition natural_req; + + if (menubar) + { + ptr = gtkpeer_get_widget (env, menubar); + + /* Get the menubar's natural size request. */ + gtk_widget_set_size_request (GTK_WIDGET (ptr), -1, -1); + gtk_widget_size_request (GTK_WIDGET (ptr), &natural_req); + + /* Set the menubar's size request to width by natural_req.height. */ + gtk_widget_set_size_request (GTK_WIDGET (ptr), + width, natural_req.height); + } +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkFramePeer_gtkFixedSetVisible + (JNIEnv *env, jobject obj, jboolean visible) +{ + void *ptr; + void *fixed; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + fixed = gtk_container_get_children (GTK_CONTAINER (ptr))->data; + + if (visible) + gtk_widget_show (GTK_WIDGET (fixed)); + else + gtk_widget_hide (GTK_WIDGET (fixed)); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkFramePeer_nativeSetIconImage + (JNIEnv *env, jobject obj, jobject gtkimage) +{ + void *ptr; + GdkPixbuf *pixbuf = NULL; + + gdk_threads_enter (); + + pixbuf = cp_gtk_image_get_pixbuf (env, gtkimage); + g_assert (pixbuf != NULL); + + ptr = gtkpeer_get_widget (env, obj); + + gtk_window_set_icon (GTK_WINDOW (ptr), pixbuf); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkFramePeer_maximize +(JNIEnv *env, jobject obj) +{ + void *ptr; + gdk_threads_enter (); + ptr = gtkpeer_get_widget (env, obj); + gtk_window_maximize (GTK_WINDOW (ptr)); + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkFramePeer_unmaximize +(JNIEnv *env, jobject obj) +{ + void *ptr; + gdk_threads_enter (); + ptr = gtkpeer_get_widget (env, obj); + gtk_window_unmaximize (GTK_WINDOW (ptr)); + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkFramePeer_iconify +(JNIEnv *env, jobject obj) +{ + void *ptr; + gdk_threads_enter (); + ptr = gtkpeer_get_widget (env, obj); + gtk_window_iconify (GTK_WINDOW (ptr)); + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkFramePeer_deiconify +(JNIEnv *env, jobject obj) +{ + void *ptr; + gdk_threads_enter (); + ptr = gtkpeer_get_widget (env, obj); + gtk_window_deiconify (GTK_WINDOW (ptr)); + gdk_threads_leave (); +} diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkGenericPeer.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkGenericPeer.c new file mode 100644 index 000000000..e0ba50849 --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkGenericPeer.c @@ -0,0 +1,100 @@ +/* gtkgenericpeer.c -- Native implementation of GtkGenericPeer + Copyright (C) 1998, 1999, 2002, 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkGenericPeer.h" + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkGenericPeer_initIDs +(JNIEnv *env, jclass clz __attribute__((unused))) +{ + gtkpeer_init_widget_IDs(env); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkGenericPeer_dispose + (JNIEnv *env, jobject obj) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + /* For now the native state for any object must be a widget. + However, a subclass could override dispose() if required. */ + gtk_widget_destroy (GTK_WIDGET (ptr)); + + /* Delete global reference. */ + gtkpeer_del_global_ref(env, obj); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkGenericPeer_gtkWidgetModifyFont + (JNIEnv *env, jobject obj, jstring name, jint style, jint size) +{ + const char *font_name; + void *ptr; + PangoFontDescription *font_desc; + + gdk_threads_enter(); + + ptr = gtkpeer_get_widget (env, obj); + + font_name = (*env)->GetStringUTFChars (env, name, NULL); + + font_desc = pango_font_description_from_string (font_name); + pango_font_description_set_size (font_desc, + size * cp_gtk_dpi_conversion_factor); + + if (style & AWT_STYLE_BOLD) + pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD); + + if (style & AWT_STYLE_ITALIC) + pango_font_description_set_style (font_desc, PANGO_STYLE_OBLIQUE); + + gtk_widget_modify_font (GTK_WIDGET(ptr), font_desc); + + pango_font_description_free (font_desc); + + (*env)->ReleaseStringUTFChars (env, name, font_name); + + gdk_threads_leave(); +} diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkImage.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkImage.c new file mode 100644 index 000000000..c2fbba212 --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkImage.c @@ -0,0 +1,434 @@ +/* gtkimage.c + Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include "jcl.h" +#include "gtkpeer.h" + +#include "gnu_java_awt_peer_gtk_GtkImage.h" + +/* The constant fields in java.awt.Image */ +#define SCALE_DEFAULT 1 +#define SCALE_FAST 2 +#define SCALE_SMOOTH 4 +#define SCALE_REPLICATE 8 +#define SCALE_AREA_AVERAGING 16 + +/* local stuff */ +static GdkInterpType mapHints(jint hints); +static void createRawData (JNIEnv * env, jobject obj, void *ptr); +static void setWidthHeight (JNIEnv * env, jobject obj, int width, int height); + +/** + * Loads a pixbuf from a file. + */ +JNIEXPORT jboolean JNICALL +Java_gnu_java_awt_peer_gtk_GtkImage_loadPixbuf + (JNIEnv *env, jobject obj, jstring name) +{ + const char *filename; + int width, height; + GdkPixbuf *pixbuf; + + /* Don't use the JCL convert function because it throws an exception + on failure */ + filename = (*env)->GetStringUTFChars (env, name, 0); + + if (filename == NULL) + return JNI_FALSE; + + pixbuf = gdk_pixbuf_new_from_file (filename, NULL); + if (pixbuf == NULL) + { + (*env)->ReleaseStringUTFChars (env, name, filename); + return JNI_FALSE; + } + + width = gdk_pixbuf_get_width (pixbuf); + height = gdk_pixbuf_get_height (pixbuf); + + createRawData (env, obj, pixbuf); + setWidthHeight(env, obj, width, height); + (*env)->ReleaseStringUTFChars (env, name, filename); + + return JNI_TRUE; +} + +/* + * Creates the image from an array of java bytes. + */ +JNIEXPORT jboolean JNICALL +Java_gnu_java_awt_peer_gtk_GtkImage_loadImageFromData + (JNIEnv *env, jobject obj, jbyteArray data) +{ + jbyte *src; + GdkPixbuf* pixbuf; + GdkPixbufLoader* loader; + int len; + int width; + int height; + + src = (*env)->GetByteArrayElements (env, data, NULL); + len = (*env)->GetArrayLength (env, data); + + loader = gdk_pixbuf_loader_new (); + + gdk_pixbuf_loader_write (loader, (guchar *)src, len, NULL); + gdk_pixbuf_loader_close (loader, NULL); + + (*env)->ReleaseByteArrayElements (env, data, src, 0); + + pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); + + if (pixbuf == NULL) + { + g_object_unref (loader); + createRawData (env, obj, NULL); + return JNI_FALSE; + } + + g_object_ref (pixbuf); + g_object_unref (loader); + + width = gdk_pixbuf_get_width (pixbuf); + height = gdk_pixbuf_get_height (pixbuf); + + createRawData (env, obj, pixbuf); + setWidthHeight(env, obj, width, height); + + return JNI_TRUE; +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkImage_createFromPixbuf +(JNIEnv *env, jobject obj) +{ + int width, heigth; + GdkPixbuf *pixbuf = cp_gtk_image_get_pixbuf (env, obj); + width = gdk_pixbuf_get_width (pixbuf); + heigth = gdk_pixbuf_get_height (pixbuf); + setWidthHeight(env, obj, width, heigth); +} + +/** + * Returns a copy of the pixel data as a java array. + */ +JNIEXPORT jintArray JNICALL +Java_gnu_java_awt_peer_gtk_GtkImage_getPixels(JNIEnv *env, jobject obj) +{ + GdkPixbuf *pixbuf; + int width, height, rowstride; + guchar *pixeldata; + jintArray result_array; + jint *result_array_iter, *dst; + int i,j; + + gdk_threads_enter (); + + pixbuf = cp_gtk_image_get_pixbuf (env, obj); + width = gdk_pixbuf_get_width (pixbuf); + height = gdk_pixbuf_get_height (pixbuf); + rowstride = gdk_pixbuf_get_rowstride (pixbuf); + + result_array = (*env)->NewIntArray (env, (width * height)); + if (result_array == NULL) + { + gdk_threads_leave (); + return NULL; + } + + dst = result_array_iter = + (*env)->GetIntArrayElements (env, result_array, NULL); + + + pixeldata = gdk_pixbuf_get_pixels (pixbuf); + + g_assert (gdk_pixbuf_get_bits_per_sample (pixbuf) == 8); + + if (gdk_pixbuf_get_has_alpha (pixbuf)) + { + for(i = 0 ; i < height; i++) + { + memcpy(dst, (void *)pixeldata, width * 4); + dst += width; + pixeldata += rowstride; + } + } else { + + /* Add a default alpha value of 0xFF to the pixeldata without alpha + information and keep it in the same format as the pixeldata with alpha + information. On Little Endian systems: AABBGGRR and on Big Endian + systems: RRGGBBAA. */ + + for(i = 0; i < height; i++) + { + for(j = 0; j < width; j++) + +#ifndef WORDS_BIGENDIAN + dst[j] = 0xFF000000 + | (pixeldata[j*3 + 2] & 0xFF) << 16 + | (pixeldata[j*3 + 1] & 0xFF) << 8 + | (pixeldata[j*3] & 0xFF); +#else + dst[j] = (pixeldata[j*3] & 0xFF) << 24 + | (pixeldata[j*3 + 1] & 0xFF) << 16 + | (pixeldata[j*3 + 2] & 0xFF) << 8 + | 0xFF; +#endif + dst += width; + pixeldata += rowstride; + } + } + + (*env)->ReleaseIntArrayElements (env, result_array, result_array_iter, 0); + + gdk_threads_leave (); + return result_array; +} + +/** + * Returns a copy of the pixel data as a java array. + * (GdkPixbuf only) + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkImage_setPixels(JNIEnv *env, jobject obj, + jintArray pixels) +{ + GdkPixbuf *pixbuf = cp_gtk_image_get_pixbuf (env, obj); + int width, height, rowstride; + guchar *pixeldata; + jint *src_array_iter, *src; + int i; + + width = gdk_pixbuf_get_width (pixbuf); + height = gdk_pixbuf_get_height (pixbuf); + rowstride = gdk_pixbuf_get_rowstride (pixbuf); + + src = src_array_iter = + (*env)->GetIntArrayElements (env, pixels, NULL); + + pixeldata = gdk_pixbuf_get_pixels (pixbuf); + for(i = 0 ; i < height; i++) + { + memcpy((void *)pixeldata, (void *)src, width * 4); + src += width; + pixeldata += rowstride; + } + + (*env)->ReleaseIntArrayElements (env, pixels, src_array_iter, 0); +} + +/** + * Allocates a Gtk Pixbuf + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkImage_createPixbuf(JNIEnv *env, jobject obj) +{ + int width, height; + jclass cls; + jfieldID field; + + cls = (*env)->GetObjectClass (env, obj); + field = (*env)->GetFieldID (env, cls, "width", "I"); + g_assert (field != 0); + width = (*env)->GetIntField (env, obj, field); + + field = (*env)->GetFieldID (env, cls, "height", "I"); + g_assert (field != 0); + height = (*env)->GetIntField (env, obj, field); + + createRawData (env, obj, gdk_pixbuf_new (GDK_COLORSPACE_RGB, + TRUE, + 8, + width, + height)); +} + +/** + * Allocates a Gtk Pixbuf + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkImage_initFromBuffer(JNIEnv *env, jobject obj, + jlong bufferPointer) +{ + int width, height; + jclass cls; + jfieldID field; + GdkPixbuf *pixbuf; + const guchar *bp = JLONG_TO_PTR(const guchar, bufferPointer); + + g_assert(bp != NULL); + cls = (*env)->GetObjectClass( env, obj ); + field = (*env)->GetFieldID( env, cls, "width", "I" ); + g_assert( field != 0 ); + width = (*env)->GetIntField( env, obj, field ); + + field = (*env)->GetFieldID( env, cls, "height", "I" ); + g_assert( field != 0 ); + height = (*env)->GetIntField( env, obj, field ); + + pixbuf = gdk_pixbuf_new_from_data( bp, + GDK_COLORSPACE_RGB, TRUE, 8, + width, height, width * 4, NULL, NULL ); + g_assert( pixbuf != NULL ); + createRawData( env, obj, pixbuf ); +} + +/** + * Frees the Gtk Pixbuf. + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkImage_freePixbuf(JNIEnv *env, jobject obj) +{ + gdk_pixbuf_unref (cp_gtk_image_get_pixbuf (env, obj)); +} + +/** + * Sets this to a scaled version of the original pixbuf + * width and height of the destination GtkImage must be set. + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkImage_createScaledPixbuf(JNIEnv *env, + jobject destination, + jobject source, + jint hints) +{ + GdkPixbuf* dst; + int width, height; + jclass cls; + jfieldID field; + + GdkPixbuf *pixbuf; + + cls = (*env)->GetObjectClass (env, destination); + field = (*env)->GetFieldID (env, cls, "width", "I"); + g_assert (field != 0); + width = (*env)->GetIntField (env, destination, field); + + field = (*env)->GetFieldID (env, cls, "height", "I"); + g_assert (field != 0); + height = (*env)->GetIntField (env, destination, field); + + pixbuf = cp_gtk_image_get_pixbuf (env, source); + + dst = gdk_pixbuf_scale_simple(pixbuf, + width, height, + mapHints(hints)); + + createRawData (env, destination, (void *)dst); +} + +/** + * Used by GtkFramePeer + */ +GdkPixbuf *cp_gtk_image_get_pixbuf (JNIEnv *env, jobject obj) +{ + jclass cls; + jfieldID data_fid; + jobject data; + + cls = (*env)->GetObjectClass (env, obj); + data_fid = (*env)->GetFieldID (env, cls, "pixbuf", + "Lgnu/classpath/Pointer;"); + g_assert (data_fid != 0); + data = (*env)->GetObjectField (env, obj, data_fid); + + if (data == NULL) + return NULL; + + return (GdkPixbuf *)JCL_GetRawData (env, data); +} + +/** + * Maps java.awt.Image scaling hints to the native GDK ones. + */ +static GdkInterpType mapHints(jint hints) +{ + switch ( hints ) + { + /* For FAST, we use the nearest-neighbor. Fastest and lowest quality. */ + case SCALE_FAST: + case SCALE_REPLICATE: + return GDK_INTERP_NEAREST; + + /* Hyperbolic for smooth. Slowest too. */ + case SCALE_SMOOTH: + return GDK_INTERP_HYPER; + + /* the inbetweenish method */ + case SCALE_AREA_AVERAGING: + return GDK_INTERP_TILES; + + /* default to bilinear */ + } + return GDK_INTERP_BILINEAR; +} + +/* Sets the width and height fields of a GtkImage object. */ +static void setWidthHeight (JNIEnv * env, jobject obj, int width, int height) +{ + jclass cls; + jfieldID field; + + cls = (*env)->GetObjectClass (env, obj); + g_assert (cls != 0); + field = (*env)->GetFieldID (env, cls, "width", "I"); + g_assert (field != 0); + (*env)->SetIntField (env, obj, field, (jint)width); + + field = (*env)->GetFieldID (env, cls, "height", "I"); + g_assert (field != 0); + (*env)->SetIntField (env, obj, field, (jint)height); +} + +/* Store and get the pixbuf pointer */ +static void +createRawData (JNIEnv * env, jobject obj, void *ptr) +{ + jclass cls; + jobject data; + jfieldID data_fid; + + cls = (*env)->GetObjectClass (env, obj); + data_fid = (*env)->GetFieldID (env, cls, "pixbuf", + "Lgnu/classpath/Pointer;"); + g_assert (data_fid != 0); + + data = JCL_NewRawDataObject (env, ptr); + + (*env)->SetObjectField (env, obj, data_fid, data); +} + diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c new file mode 100644 index 000000000..3703858fe --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c @@ -0,0 +1,221 @@ +/* gtklabelpeer.c -- Native implementation of GtkLabelPeer + Copyright (C) 1998, 1999 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkLabelPeer.h" + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkLabelPeer_create + (JNIEnv *env, jobject obj, jstring text, jfloat xalign) +{ + GtkWidget *label; + GtkWidget *eventbox; + const char *str; + + gdk_threads_enter (); + + gtkpeer_set_global_ref (env, obj); + + str = (*env)->GetStringUTFChars (env, text, 0); + + eventbox = gtk_event_box_new (); + label = gtk_label_new (str); + gtk_misc_set_alignment (GTK_MISC (label), xalign, 0.5); + gtk_container_add (GTK_CONTAINER (eventbox), label); + gtk_widget_show (label); + + (*env)->ReleaseStringUTFChars (env, text, str); + + gtkpeer_set_widget (env, obj, eventbox); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkLabelPeer_gtkWidgetGetPreferredDimensions + (JNIEnv *env, jobject obj, jintArray jdims) +{ + void *ptr; + jint *dims; + GtkWidget *label; + GtkRequisition current_req; + GtkRequisition natural_req; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + label = gtk_bin_get_child (GTK_BIN (ptr)); + + dims = (*env)->GetIntArrayElements (env, jdims, 0); + dims[0] = dims[1] = 0; + + /* Save the widget's current size request. */ + gtk_widget_size_request (GTK_WIDGET (label), ¤t_req); + + /* Get the widget's "natural" size request. */ + gtk_widget_set_size_request (GTK_WIDGET (label), -1, -1); + gtk_widget_size_request (GTK_WIDGET (label), &natural_req); + + /* Reset the widget's size request. */ + gtk_widget_set_size_request (GTK_WIDGET (label), + current_req.width, current_req.height); + + dims[0] = natural_req.width; + dims[1] = natural_req.height; + + (*env)->ReleaseIntArrayElements (env, jdims, dims, 0); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkLabelPeer_gtkWidgetModifyFont + (JNIEnv *env, jobject obj, jstring name, jint style, jint size) +{ + const char *font_name; + void *ptr; + GtkWidget *label; + PangoFontDescription *font_desc; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + font_name = (*env)->GetStringUTFChars (env, name, NULL); + + label = gtk_bin_get_child (GTK_BIN (ptr)); + + if (!label) + { + gdk_threads_leave (); + return; + } + + font_desc = pango_font_description_from_string (font_name); + pango_font_description_set_size (font_desc, + size * cp_gtk_dpi_conversion_factor); + + if (style & AWT_STYLE_BOLD) + pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD); + + if (style & AWT_STYLE_ITALIC) + pango_font_description_set_style (font_desc, PANGO_STYLE_OBLIQUE); + + gtk_widget_modify_font (GTK_WIDGET (label), font_desc); + + pango_font_description_free (font_desc); + + (*env)->ReleaseStringUTFChars (env, name, font_name); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkLabelPeer_setNativeText + (JNIEnv *env, jobject obj, jstring text) +{ + const char *str; + void *ptr; + GtkWidget *label; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + str = (*env)->GetStringUTFChars (env, text, 0); + + label = gtk_bin_get_child (GTK_BIN (ptr)); + + gtk_label_set_label (GTK_LABEL (label), str); + + (*env)->ReleaseStringUTFChars (env, text, str); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkLabelPeer_nativeSetAlignment + (JNIEnv *env, jobject obj, jfloat xalign) +{ + void *ptr; + GtkWidget *label; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + label = gtk_bin_get_child (GTK_BIN(ptr)); + + gtk_misc_set_alignment (GTK_MISC (label), xalign, 0.5); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkLabelPeer_setNativeBounds + (JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height) +{ + GtkWidget *widget; + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + widget = GTK_WIDGET (ptr); + + /* We assume that -1 is a width or height and not a request for the + widget's natural size. */ + width = width < 0 ? 0 : width; + height = height < 0 ? 0 : height; + + if (!(width == 0 && height == 0)) + { + /* Set the event box's size request... */ + gtk_widget_set_size_request (widget, width, height); + /* ...and the label's size request. */ + gtk_widget_set_size_request (gtk_bin_get_child (GTK_BIN (widget)), + width, height); + + if (widget->parent != NULL && GTK_IS_FIXED (widget->parent)) + gtk_fixed_move (GTK_FIXED (widget->parent), widget, x, y); + } + + gdk_threads_leave (); +} diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkListPeer.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkListPeer.c new file mode 100644 index 000000000..4b7b63e6d --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkListPeer.c @@ -0,0 +1,549 @@ +/* GtkListPeer.c -- implements GtkListPeer's native methods + Copyright (C) 1998, 1999, 2003, 2004 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + +#include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkListPeer.h" + +static jmethodID postListItemEventID; +static GtkWidget *list_get_widget (GtkWidget *widget); + +void +cp_gtk_list_init_jni (void) +{ + jclass gtklistpeer; + + gtklistpeer = (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(), + "gnu/java/awt/peer/gtk/GtkListPeer"); + + postListItemEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtklistpeer, + "postItemEvent", + "(II)V"); +} + +enum + { + COLUMN_STRING, + N_COLUMNS + }; + +static gboolean item_highlighted_cb (GtkTreeSelection *selection, + GtkTreeModel *model, + GtkTreePath *path, + gboolean path_currently_selected, + jobject peer); + + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkListPeer_create + (JNIEnv *env, jobject obj, jint rows) +{ + GtkWidget *sw; + GtkWidget *list; + GtkWidget *eventbox; + GtkCellRenderer *renderer; + GtkTreeViewColumn *column; + GtkListStore *list_store; + GtkTreeIter iter; + GtkRequisition req; + gint i; + + gdk_threads_enter (); + + /* Create global reference and save it for future use */ + gtkpeer_set_global_ref (env, obj); + + list_store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING); + /* Add the number of rows so that we can calculate the tree view's + size request. */ + for (i = 0; i < rows; i++) + { + gtk_list_store_append (list_store, &iter); + gtk_list_store_set (list_store, &iter, + COLUMN_STRING, "", + -1); + } + list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list_store)); + renderer = gtk_cell_renderer_text_new (); + column = gtk_tree_view_column_new_with_attributes (NULL, + renderer, + "text", + COLUMN_STRING, + NULL); + + eventbox = gtk_event_box_new (); + sw = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_AUTOMATIC); + gtk_container_add (GTK_CONTAINER (eventbox), sw); + + gtk_tree_view_append_column (GTK_TREE_VIEW (list), column); + + gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (list), FALSE); + + gtk_widget_size_request (GTK_WIDGET (list), &req); + + gtk_widget_set_size_request (GTK_WIDGET (list), req.width, req.height); + + gtk_container_add (GTK_CONTAINER (sw), list); + + /* Remove the blank rows. */ + gtk_list_store_clear (list_store); + + gtk_widget_show (list); + gtk_widget_show (sw); + + gtkpeer_set_widget (env, obj, eventbox); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkListPeer_connectSignals + (JNIEnv *env, jobject obj) +{ + void *ptr; + jobject gref; + GtkWidget *list; + GtkTreeSelection *selection; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + gref = gtkpeer_get_global_ref (env, obj); + + list = list_get_widget (GTK_WIDGET (ptr)); + + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (list)); + gtk_tree_selection_set_select_function (selection, item_highlighted_cb, + gref, NULL); + + cp_gtk_component_connect_signals (G_OBJECT (list), gref); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkListPeer_gtkWidgetModifyFont + (JNIEnv *env, jobject obj, jstring name, jint style, jint size) +{ + const char *font_name; + void *ptr; + GtkWidget *list; + PangoFontDescription *font_desc; + + gdk_threads_enter(); + + ptr = gtkpeer_get_widget (env, obj); + + list = list_get_widget (GTK_WIDGET (ptr)); + + font_name = (*env)->GetStringUTFChars (env, name, NULL); + + font_desc = pango_font_description_from_string (font_name); + pango_font_description_set_size (font_desc, + size * cp_gtk_dpi_conversion_factor); + + if (style & AWT_STYLE_BOLD) + pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD); + + if (style & AWT_STYLE_ITALIC) + pango_font_description_set_style (font_desc, PANGO_STYLE_OBLIQUE); + + gtk_widget_modify_font (GTK_WIDGET (list), font_desc); + + pango_font_description_free (font_desc); + + (*env)->ReleaseStringUTFChars (env, name, font_name); + + gdk_threads_leave(); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkListPeer_gtkWidgetRequestFocus + (JNIEnv *env, jobject obj) +{ + void *ptr; + GtkWidget *list; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + list = list_get_widget (GTK_WIDGET (ptr)); + gtk_widget_grab_focus (list); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkListPeer_append + (JNIEnv *env, jobject obj, jobjectArray items) +{ + void *ptr; + GtkWidget *list; + GtkTreeIter iter; + GtkTreeModel *list_store; + jint count; + jint i; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + count = (*env)->GetArrayLength (env, items); + + list = list_get_widget (GTK_WIDGET (ptr)); + list_store = gtk_tree_view_get_model (GTK_TREE_VIEW (list)); + + for (i = 0; i < count; i++) + { + const char *text; + jobject item; + + item = (*env)->GetObjectArrayElement (env, items, i); + + text = (*env)->GetStringUTFChars (env, item, NULL); + gtk_list_store_append (GTK_LIST_STORE (list_store), &iter); + gtk_list_store_set (GTK_LIST_STORE (list_store), &iter, + COLUMN_STRING, text, + -1); + (*env)->ReleaseStringUTFChars (env, item, text); + (*env)->DeleteLocalRef(env, item); + } + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkListPeer_add + (JNIEnv *env, jobject obj, jstring text, jint index) +{ + void *ptr; + const char *str; + GtkWidget *list; + GtkTreeIter iter; + GtkTreeModel *list_store; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + str = (*env)->GetStringUTFChars (env, text, NULL); + + list = list_get_widget (GTK_WIDGET (ptr)); + list_store = gtk_tree_view_get_model (GTK_TREE_VIEW (list)); + + if (index == -1) + gtk_list_store_append (GTK_LIST_STORE (list_store), &iter); + else + gtk_list_store_insert (GTK_LIST_STORE (list_store), &iter, index); + + gtk_list_store_set (GTK_LIST_STORE (list_store), &iter, + COLUMN_STRING, str, -1); + + (*env)->ReleaseStringUTFChars (env, text, str); + + gdk_threads_leave (); +} + + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkListPeer_delItems + (JNIEnv *env, jobject obj, jint start, jint end) +{ + void *ptr; + GtkWidget *list; + GtkTreeIter iter; + GtkTreeModel *list_store; + jint i; + jint num_items; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + list = list_get_widget (GTK_WIDGET (ptr)); + list_store = gtk_tree_view_get_model (GTK_TREE_VIEW (list)); + + /* Special case: remove all rows. */ + if (end == -1) + gtk_list_store_clear (GTK_LIST_STORE (list_store)); + else + { + i = 0; + num_items = end - start + 1; + gtk_tree_model_iter_nth_child (list_store, &iter, NULL, start); + while (i < num_items) + { + gtk_list_store_remove (GTK_LIST_STORE (list_store), &iter); + i++; + } + } + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkListPeer_select + (JNIEnv *env, jobject obj, jint index) +{ + void *ptr; + GtkWidget *list; + GtkTreePath *path; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + list = list_get_widget (GTK_WIDGET (ptr)); + path = gtk_tree_path_new_from_indices (index, -1); + gtk_tree_view_set_cursor (GTK_TREE_VIEW (list), path, NULL, FALSE); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkListPeer_deselect + (JNIEnv *env, jobject obj, jint index) +{ + void *ptr; + GtkWidget *list; + GtkTreeSelection *selection; + GtkTreePath *path; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + list = list_get_widget (GTK_WIDGET (ptr)); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (list)); + path = gtk_tree_path_new_from_indices (index, -1); + gtk_tree_selection_unselect_path (selection, path); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkListPeer_getSize + (JNIEnv *env, jobject obj, jint rows, jint visible_rows, jintArray jdims) +{ + void *ptr; + jint *dims; + GtkRequisition current_req; + GtkRequisition natural_req; + GtkWidget* bin; + + gdk_threads_enter (); + + dims = (*env)->GetIntArrayElements (env, jdims, NULL); + dims[0] = dims[1] = 0; + + ptr = gtkpeer_get_widget (env, obj); + bin = list_get_widget (GTK_WIDGET (ptr)); + + /* Save the widget's current size request. */ + gtk_widget_size_request (bin, ¤t_req); + + /* Get the widget's "natural" size request. */ + gtk_widget_set_size_request (GTK_WIDGET (ptr), -1, -1); + gtk_widget_size_request (bin, &natural_req); + + /* Reset the widget's size request. */ + gtk_widget_set_size_request (bin, + current_req.width, current_req.height); + + dims[0] = natural_req.width; + + /* Calculate the final height, by comparing the number of rows + in the list to the number of rows requested by the caller. + FIXME: Is there a GTK method that counts the number of rows + in the list? If so, we don't need to bring visible_rows from + the Java peer. */ + if (rows == visible_rows) + dims[1] = natural_req.height; + else + dims[1] = natural_req.height / visible_rows * rows; + + (*env)->ReleaseIntArrayElements (env, jdims, dims, 0); + + gdk_threads_leave (); +} + + +JNIEXPORT jintArray JNICALL +Java_gnu_java_awt_peer_gtk_GtkListPeer_getSelectedIndexes + (JNIEnv *env, jobject obj) +{ + void *ptr; + GtkWidget *list; + GtkTreeSelection *selection; + jintArray result_array; + jint *result_array_iter; + GList *current_row; + GList *rows; + gint *indices; + jint count; + jint i; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + list = list_get_widget (GTK_WIDGET (ptr)); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (list)); + count = gtk_tree_selection_count_selected_rows (selection); + if (count > 0) + { + current_row = rows = gtk_tree_selection_get_selected_rows (selection, NULL); + + result_array = (*env)->NewIntArray (env, count); + + result_array_iter = (*env)->GetIntArrayElements (env, result_array, NULL); + + for (i = 0; i < count; i++) + { + indices = gtk_tree_path_get_indices (current_row->data); + result_array_iter[i] = indices ? indices[0] : -1; + current_row = g_list_next (current_row); + } + + if (rows) + { + g_list_foreach (rows, (GFunc) gtk_tree_path_free, NULL); + g_list_free (rows); + } + + (*env)->ReleaseIntArrayElements (env, result_array, result_array_iter, 0); + } + else + result_array = NULL; + + gdk_threads_leave (); + + return result_array; +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkListPeer_makeVisible + (JNIEnv *env, jobject obj, jint index) +{ + void *ptr; + GtkWidget *list; + GtkTreePath *path; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + list = list_get_widget (GTK_WIDGET (ptr)); + path = gtk_tree_path_new_from_indices (index, -1); + gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (list), path, + NULL, FALSE, 0.0, 0.0); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkListPeer_setMultipleMode + (JNIEnv *env, jobject obj, jboolean mode) +{ + void *ptr; + GtkWidget *list; + GtkTreeSelection *selection; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + list = list_get_widget (GTK_WIDGET (ptr)); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (list)); + gtk_tree_selection_set_mode (selection, + mode ? GTK_SELECTION_MULTIPLE + : GTK_SELECTION_SINGLE); + + gdk_threads_leave (); +} + +static gboolean +item_highlighted_cb (GtkTreeSelection *selection __attribute__((unused)), + GtkTreeModel *model, + GtkTreePath *path, + gboolean path_currently_selected, + jobject peer) +{ + GtkTreeIter iter; + jint row; + gint *indices; + + if (gtk_tree_model_get_iter (model, &iter, path)) + { + indices = gtk_tree_path_get_indices (path); + row = indices ? indices[0] : -1; + + if (!path_currently_selected) + { + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postListItemEventID, + row, + (jint) AWT_ITEM_SELECTED); + } + else + { + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postListItemEventID, + row, + (jint) AWT_ITEM_DESELECTED); + } + } + + return TRUE; +} + +static GtkWidget * +list_get_widget (GtkWidget *widget) +{ + GtkWidget *wid; + g_assert (GTK_IS_EVENT_BOX (widget)); + + wid = gtk_bin_get_child (GTK_BIN (widget)); + g_assert (GTK_IS_SCROLLED_WINDOW (wid)); + + wid = gtk_bin_get_child (GTK_BIN (wid)); + + return wid; +} + diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuBarPeer.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuBarPeer.c new file mode 100644 index 000000000..ac3fab78b --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuBarPeer.c @@ -0,0 +1,92 @@ +/* gtkmenubarpeer.c -- Native implementation of GtkMenuBarPeer + Copyright (C) 1999, 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkMenuBarPeer.h" + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkMenuBarPeer_create + (JNIEnv *env, jobject obj) +{ + GtkWidget *widget; + + gdk_threads_enter (); + + gtkpeer_set_global_ref (env, obj); + + widget = gtk_menu_bar_new (); + gtk_widget_show (widget); + + gtkpeer_set_widget (env, obj, widget); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkMenuBarPeer_addMenu + (JNIEnv *env, jobject obj, jobject menupeer) +{ + void *mbar, *menu; + + gdk_threads_enter (); + + mbar = gtkpeer_get_widget (env, obj); + menu = gtkpeer_get_widget (env, menupeer); + + gtk_menu_shell_append (GTK_MENU_SHELL (mbar), GTK_WIDGET (menu)); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkMenuBarPeer_delMenu + (JNIEnv *env, jobject obj, jint index) +{ + void *ptr; + GList *list; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + list = gtk_container_get_children (GTK_CONTAINER (ptr)); + list = g_list_nth (list, index); + gtk_container_remove (GTK_CONTAINER (ptr), GTK_WIDGET (list->data)); + + gdk_threads_leave (); +} diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuComponentPeer.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuComponentPeer.c new file mode 100644 index 000000000..6da949488 --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuComponentPeer.c @@ -0,0 +1,55 @@ +/* gtkmenucomponentpeer.c -- Native implementation of GtkMenuComponentPeer + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkMenuComponentPeer.h" + +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkMenuComponentPeer_dispose + (JNIEnv *env, jobject obj) +{ + /* For MenuComponents and its subclasses, the widgets are + automatically destroyed by Gtk when the parent MenuBar + is removed from the Frame. So we avoid the widget + destruction in GtkGenericPeer dispose() by overriding + it here. */ + + /* However, references to the Java objects still exist in the + state tables, so we still have to remove those. */ + + gtkpeer_del_global_ref (env, obj); +} diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuItemPeer.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuItemPeer.c new file mode 100644 index 000000000..965435545 --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuItemPeer.c @@ -0,0 +1,191 @@ +/* gtkmenuitempeer.c -- Native implementation of GtkMenuItemPeer + Copyright (C) 1999 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkMenuItemPeer.h" +#include "gnu_java_awt_peer_gtk_GtkComponentPeer.h" + +static jmethodID postMenuActionEventID; + +void +cp_gtk_menuitem_init_jni (void) +{ + jclass gtkmenuitempeer; + + gtkmenuitempeer = (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(), + "gnu/java/awt/peer/gtk/GtkMenuItemPeer"); + + postMenuActionEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkmenuitempeer, + "postMenuActionEvent", + "()V"); +} + +static void item_activate_cb (GtkMenuItem *item __attribute__((unused)), + jobject peer_obj); + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_create + (JNIEnv *env, jobject obj, jstring label) +{ + GtkWidget *widget; + const char *str; + + gdk_threads_enter (); + + gtkpeer_set_global_ref (env, obj); + + str = (*env)->GetStringUTFChars (env, label, NULL); + + /* "-" signals that we need a separator. */ + if (strcmp (str, "-") == 0) + widget = gtk_menu_item_new (); + else + widget = gtk_menu_item_new_with_label (str); + + gtk_widget_show (widget); + + (*env)->ReleaseStringUTFChars (env, label, str); + + gtkpeer_set_widget (env, obj, widget); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_connectSignals + (JNIEnv *env, jobject obj) +{ + void *ptr; + jobject gref; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + gref = gtkpeer_get_global_ref (env, obj); + + g_signal_connect (G_OBJECT (ptr), "activate", + G_CALLBACK (item_activate_cb), gref); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_gtkWidgetModifyFont + (JNIEnv *env, jobject obj, jstring name, jint style, jint size) +{ + const char *font_name; + void *ptr; + GtkWidget *label; + PangoFontDescription *font_desc; + + gdk_threads_enter(); + + ptr = gtkpeer_get_widget (env, obj); + + font_name = (*env)->GetStringUTFChars (env, name, NULL); + + label = gtk_bin_get_child (GTK_BIN (ptr)); + + if (label) + { + font_desc = pango_font_description_from_string (font_name); + pango_font_description_set_size (font_desc, + size * cp_gtk_dpi_conversion_factor); + + if (style & AWT_STYLE_BOLD) + pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD); + + if (style & AWT_STYLE_ITALIC) + pango_font_description_set_style (font_desc, PANGO_STYLE_OBLIQUE); + + gtk_widget_modify_font (GTK_WIDGET(label), font_desc); + + pango_font_description_free (font_desc); + } + + (*env)->ReleaseStringUTFChars (env, name, font_name); + + gdk_threads_leave(); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_setEnabled + (JNIEnv *env, jobject obj, jboolean enabled) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + gtk_widget_set_sensitive (GTK_WIDGET (ptr), enabled); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_setLabel + (JNIEnv *env, jobject obj, jstring label) +{ + void *ptr; + const char *str; + GtkAccelLabel *accel_label; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + str = (*env)->GetStringUTFChars (env, label, NULL); + + accel_label = GTK_ACCEL_LABEL (GTK_BIN (ptr)->child); + + gtk_label_set_text (GTK_LABEL (accel_label), str); + gtk_accel_label_refetch (accel_label); + + (*env)->ReleaseStringUTFChars (env, label, str); + + gdk_threads_leave (); +} + +static void +item_activate_cb (GtkMenuItem *item __attribute__((unused)), jobject peer_obj) +{ + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer_obj, + postMenuActionEventID); +} diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuPeer.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuPeer.c new file mode 100644 index 000000000..1081de253 --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuPeer.c @@ -0,0 +1,176 @@ +/* gtkmenupeer.c -- Native implementation of GtkMenuPeer + Copyright (C) 1999, 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkMenuPeer.h" + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkMenuPeer_setupAccelGroup + (JNIEnv *env, jobject obj, jobject parent) +{ + void *ptr1, *ptr2; + + gdk_threads_enter (); + + ptr1 = gtkpeer_get_widget (env, obj); + + if (!parent) + { + gtk_menu_set_accel_group (GTK_MENU (GTK_MENU_ITEM (ptr1)->submenu), + gtk_accel_group_new ()); + } + else + { + GtkAccelGroup *parent_accel; + + ptr2 = gtkpeer_get_widget (env, parent); + parent_accel = gtk_menu_get_accel_group (GTK_MENU (GTK_MENU_ITEM (ptr2)->submenu)); + + gtk_menu_set_accel_group (GTK_MENU (GTK_MENU_ITEM (ptr1)->submenu), + parent_accel); + } + + gdk_threads_leave (); +} + + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkMenuPeer_create + (JNIEnv *env, jobject obj, jstring label) +{ + GtkWidget *menu_title, *menu, *toplevel; + const char *str; + + gdk_threads_enter (); + + gtkpeer_set_global_ref (env, obj); + + str = (*env)->GetStringUTFChars (env, label, NULL); + + menu = gtk_menu_new (); + + if (str != NULL) + menu_title = gtk_menu_item_new_with_label (str); + else + menu_title = gtk_menu_item_new(); + + gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_title), menu); + + /* Allow this menu to grab the pointer. */ + toplevel = gtk_widget_get_toplevel (menu); + if (GTK_IS_WINDOW (toplevel)) + { + gtk_window_group_add_window (cp_gtk_global_window_group, + GTK_WINDOW(toplevel)); + } + + gtk_widget_show (menu_title); + + gtkpeer_set_widget (env, obj, menu_title); + + (*env)->ReleaseStringUTFChars (env, label, str); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkMenuPeer_addTearOff + (JNIEnv *env, jobject obj) +{ + void *ptr1; + GtkWidget *menu, *item; + + gdk_threads_enter (); + + ptr1 = gtkpeer_get_widget (env, obj); + + menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (ptr1)); + item = gtk_tearoff_menu_item_new (); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + gtk_widget_show (item); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkMenuPeer_addItem + (JNIEnv *env, jobject obj, jobject menuitempeer, jint key, jboolean shift) +{ + void *ptr1, *ptr2; + GtkWidget *menu; + + gdk_threads_enter (); + + ptr1 = gtkpeer_get_widget (env, obj); + ptr2 = gtkpeer_get_widget (env, menuitempeer); + + menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(ptr1)); + gtk_menu_shell_append (GTK_MENU_SHELL(menu), GTK_WIDGET (ptr2)); + + if (key) + { + gtk_widget_add_accelerator (GTK_WIDGET (ptr2), "activate", + gtk_menu_get_accel_group (GTK_MENU (menu)), key, + (GDK_CONTROL_MASK + | ((shift) ? GDK_SHIFT_MASK : 0)), + GTK_ACCEL_VISIBLE); + } + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkMenuPeer_delItem + (JNIEnv *env, jobject obj, jint index) +{ + void *ptr; + GList *list; + GtkWidget *menu; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(ptr)); + + list = gtk_container_get_children (GTK_CONTAINER (menu)); + list = g_list_nth (list, index); + gtk_container_remove (GTK_CONTAINER (menu), GTK_WIDGET (list->data)); + + gdk_threads_leave (); +} diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPanelPeer.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPanelPeer.c new file mode 100644 index 000000000..e52e6de51 --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPanelPeer.c @@ -0,0 +1,112 @@ +/* gtkpanelpeer.c -- Native implementation of GtkPanelPeer + Copyright (C) 1998, 1999, 2002 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkComponentPeer.h" +#include "gnu_java_awt_peer_gtk_GtkPanelPeer.h" + +static gboolean panel_focus_in_cb (GtkWidget * widget, + GdkEventFocus *event, + jobject peer); +static gboolean panel_focus_out_cb (GtkWidget * widget, + GdkEventFocus *event, + jobject peer); + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkPanelPeer_create + (JNIEnv *env, jobject obj) +{ + GtkWidget *widget; + + gdk_threads_enter (); + + gtkpeer_set_global_ref (env, obj); + + widget = gtk_fixed_new (); + + gtk_fixed_set_has_window (GTK_FIXED (widget), TRUE); + + GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS); + + gtkpeer_set_widget (env, obj, widget); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkPanelPeer_connectSignals + (JNIEnv *env, jobject obj) +{ + void *ptr; + jobject gref; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + gref = gtkpeer_get_global_ref (env, obj); + + /* Panel signals. These callbacks prevent expose events being + delivered to the panel when it is focused. */ + g_signal_connect (G_OBJECT (ptr), "focus-in-event", + G_CALLBACK (panel_focus_in_cb), gref); + + g_signal_connect (G_OBJECT (ptr), "focus-out-event", + G_CALLBACK (panel_focus_out_cb), gref); + + /* Component signals. Exclude focus signals. */ + cp_gtk_component_connect_expose_signals (ptr, gref); + cp_gtk_component_connect_mouse_signals (ptr, gref); + + gdk_threads_leave (); +} + +static gboolean +panel_focus_in_cb (GtkWidget * widget __attribute__((unused)), + GdkEventFocus *event __attribute__((unused)), + jobject peer __attribute__((unused))) +{ + return TRUE; +} + +static gboolean +panel_focus_out_cb (GtkWidget * widget __attribute__((unused)), + GdkEventFocus *event __attribute__((unused)), + jobject peer __attribute__((unused))) +{ + return TRUE; +} diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPopupMenuPeer.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPopupMenuPeer.c new file mode 100644 index 000000000..b7b1c3322 --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPopupMenuPeer.c @@ -0,0 +1,105 @@ +/* gtkpopupmenupeer.c -- Native implementation of GtkPopupMenuPeer + Copyright (C) 1999, 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkPopupMenuPeer.h" + +struct pos +{ + gint x; + gint y; +}; + +static void +menu_pos (GtkMenu *menu __attribute__((unused)), + gint *x, gint *y, + gboolean *push_in, + gpointer user_data) +{ + struct pos *p = (struct pos *) user_data; + + *x = p->x; + *y = p->y; + *push_in = TRUE; +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkPopupMenuPeer_show + (JNIEnv *env, jobject obj, jint x, jint y, jlong time) +{ + void *ptr; + struct pos *p; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + p = g_malloc (sizeof (struct pos)); + p->x = x; + p->y = y; + + gtk_menu_popup (GTK_MENU (GTK_MENU_ITEM (ptr)->submenu), + NULL, NULL, menu_pos, p, 0, time); + + g_free (p); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkPopupMenuPeer_setupAccelGroup + (JNIEnv *env, jobject obj, jobject parent) +{ + void *ptr1, *ptr2; + GtkMenu *menu; + + gdk_threads_enter (); + + ptr1 = gtkpeer_get_widget (env, obj); + ptr2 = gtkpeer_get_widget (env, parent); + + menu = GTK_MENU (GTK_MENU_ITEM (ptr1)->submenu); + gtk_menu_set_accel_group (menu, gtk_accel_group_new ()); + /* FIXME: update this to use GTK-2.4 GtkActions. */ +#if 0 + _gtk_accel_group_attach (gtk_menu_get_accel_group (menu), + G_OBJECT (gtk_widget_get_toplevel (ptr2))); +#endif + + gdk_threads_leave (); +} diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkScrollPanePeer.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkScrollPanePeer.c new file mode 100644 index 000000000..0d67b0b78 --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkScrollPanePeer.c @@ -0,0 +1,222 @@ +/* gtkscrollpanepeer.c -- Native implementation of GtkScrollPanePeer + Copyright (C) 1998, 1999, 2002 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkScrollPanePeer.h" + +#define AWT_SCROLLPANE_SCROLLBARS_AS_NEEDED 0 +#define AWT_SCROLLPANE_SCROLLBARS_ALWAYS 1 +#define AWT_SCROLLPANE_SCROLLBARS_NEVER 2 + +static GtkWidget *scrollpane_get_widget (GtkWidget *widget); + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkScrollPanePeer_create + (JNIEnv *env, jobject obj, int width, int height) +{ + GtkWidget *sw; + GtkWidget *eventbox; + + gdk_threads_enter (); + + /* Create global reference and save it for future use */ + gtkpeer_set_global_ref (env, obj); + + sw = gtk_scrolled_window_new (NULL, NULL); + gtk_widget_set_size_request (sw, width, height); + eventbox = gtk_event_box_new (); + gtk_container_add (GTK_CONTAINER (eventbox), sw); + gtk_widget_show (sw); + + gtkpeer_set_widget (env, obj, eventbox); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkScrollPanePeer_setScrollPosition + (JNIEnv *env, jobject obj, jint x, jint y) +{ + GtkAdjustment *hadj, *vadj; + GtkScrolledWindow *sw; + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + sw = GTK_SCROLLED_WINDOW (scrollpane_get_widget (GTK_WIDGET (ptr))); + + hadj = gtk_scrolled_window_get_hadjustment (sw); + vadj = gtk_scrolled_window_get_vadjustment (sw); + + gtk_adjustment_set_value (hadj, x); + gtk_adjustment_set_value (vadj, y); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkScrollPanePeer_gtkScrolledWindowSetHScrollIncrement + (JNIEnv *env, jobject obj, jint u) +{ + GtkAdjustment *hadj; + GtkScrolledWindow *sw; + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + sw = GTK_SCROLLED_WINDOW (scrollpane_get_widget (GTK_WIDGET (ptr))); + + hadj = gtk_scrolled_window_get_hadjustment (sw); + hadj->step_increment = u; + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkScrollPanePeer_gtkScrolledWindowSetVScrollIncrement + (JNIEnv *env, jobject obj, jint u) +{ + GtkAdjustment *vadj; + GtkScrolledWindow *sw; + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + sw = GTK_SCROLLED_WINDOW (scrollpane_get_widget (GTK_WIDGET (ptr))); + + vadj = gtk_scrolled_window_get_hadjustment (sw); + vadj->step_increment = u; + + gdk_threads_leave (); +} + +JNIEXPORT jint JNICALL +Java_gnu_java_awt_peer_gtk_GtkScrollPanePeer_getHScrollbarHeight + (JNIEnv *env, jobject obj) +{ + void *ptr; + GtkScrolledWindow *sw; + GtkRequisition requisition; + jint height = 0; + jint spacing = 0; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + sw = GTK_SCROLLED_WINDOW (scrollpane_get_widget (GTK_WIDGET (ptr))); + + gtk_widget_size_request (sw->hscrollbar, &requisition); + gtk_widget_style_get (GTK_WIDGET (sw), "scrollbar_spacing", &spacing, NULL); + height = requisition.height + spacing; + + gdk_threads_leave (); + + return height; +} + +JNIEXPORT jint JNICALL +Java_gnu_java_awt_peer_gtk_GtkScrollPanePeer_getVScrollbarWidth + (JNIEnv *env, jobject obj) +{ + void *ptr; + GtkScrolledWindow *sw; + GtkRequisition requisition; + jint width = 0; + jint spacing = 0; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + sw = GTK_SCROLLED_WINDOW (scrollpane_get_widget (GTK_WIDGET (ptr))); + + gtk_widget_size_request (sw->vscrollbar, &requisition); + gtk_widget_style_get (GTK_WIDGET (sw), "scrollbar_spacing", &spacing, NULL); + width = requisition.width + spacing; + + gdk_threads_leave (); + + return width; +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkScrollPanePeer_setPolicy + (JNIEnv *env, jobject obj, jint policy) +{ + void *ptr; + GtkWidget *sw; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + switch (policy) + { + case AWT_SCROLLPANE_SCROLLBARS_AS_NEEDED: + policy = GTK_POLICY_AUTOMATIC; + break; + case AWT_SCROLLPANE_SCROLLBARS_ALWAYS: + policy = GTK_POLICY_ALWAYS; + break; + case AWT_SCROLLPANE_SCROLLBARS_NEVER: + policy = GTK_POLICY_NEVER; + break; + } + + sw = scrollpane_get_widget (GTK_WIDGET (ptr)); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), policy, policy); + + gdk_threads_leave (); +} + +static GtkWidget * +scrollpane_get_widget (GtkWidget *widget) +{ + GtkWidget *wid; + g_assert (GTK_IS_EVENT_BOX (widget)); + wid = gtk_bin_get_child (GTK_BIN(widget)); + + return wid; +} diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkScrollbarPeer.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkScrollbarPeer.c new file mode 100644 index 000000000..64d91d2b2 --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkScrollbarPeer.c @@ -0,0 +1,296 @@ +/* gtkscrollbarpeer.c -- Native implementation of GtkScrollbarPeer + Copyright (C) 1998, 1999, 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#include +#include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkComponentPeer.h" +#include "gnu_java_awt_peer_gtk_GtkScrollbarPeer.h" + +#define AWT_ADJUSTMENT_UNIT_INCREMENT 1 +#define AWT_ADJUSTMENT_UNIT_DECREMENT 2 +#define AWT_ADJUSTMENT_BLOCK_DECREMENT 3 +#define AWT_ADJUSTMENT_BLOCK_INCREMENT 4 +#define AWT_ADJUSTMENT_TRACK 5 + +static jmethodID postAdjustmentEventID; +static GtkWidget *scrollbar_get_widget (GtkWidget *widget); + +void +cp_gtk_scrollbar_init_jni (void) +{ + jclass gtkscrollbarpeer; + + gtkscrollbarpeer = (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(), + "gnu/java/awt/peer/gtk/GtkScrollbarPeer"); + + postAdjustmentEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), + gtkscrollbarpeer, + "postAdjustmentEvent", + "(II)V"); +} + +#if GTK_MINOR_VERSION > 4 +static gboolean slider_moved_cb (GtkRange *range, + GtkScrollType scroll, + gdouble value, + jobject obj); +#else +static void post_change_event_cb (GtkRange *range, + jobject peer); +#endif + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkScrollbarPeer_create + (JNIEnv *env, jobject obj, jint orientation, jint value, + jint min, jint max, jint step_incr, jint page_incr, jint visible_amount) +{ + GtkWidget *scrollbar; + GtkWidget *eventbox; + GtkObject *adj; + + /* Create global reference and save it for future use */ + gtkpeer_set_global_ref (env, obj); + + gdk_threads_enter (); + + /* A little hack because gtk_range_set_range() doesn't allow min == max. */ + if (min == max) + { + if (visible_amount == 0) + visible_amount = 1; + max++; + } + + adj = gtk_adjustment_new ((gdouble) value, + (gdouble) min, + (gdouble) max, + (gdouble) step_incr, + (gdouble) page_incr, + (gdouble) visible_amount); + + scrollbar = orientation + ? gtk_vscrollbar_new (GTK_ADJUSTMENT (adj)) + : gtk_hscrollbar_new (GTK_ADJUSTMENT (adj)); + eventbox = gtk_event_box_new (); + gtk_container_add (GTK_CONTAINER (eventbox), scrollbar); + gtk_widget_show (scrollbar); + + GTK_RANGE (scrollbar)->round_digits = 0; + /* These calls seem redundant but they are not. They clamp values + so that the slider's entirety is always between the two + steppers. */ + gtk_range_set_range (GTK_RANGE (scrollbar), (gdouble) min, (gdouble) max); + gtk_range_set_value (GTK_RANGE (scrollbar), (gdouble) value); + + gdk_threads_leave (); + + gtkpeer_set_widget (env, obj, eventbox); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkScrollbarPeer_connectSignals + (JNIEnv *env, jobject obj) +{ + void *ptr = gtkpeer_get_widget (env, obj); + GtkWidget *wid = scrollbar_get_widget (GTK_WIDGET (ptr)); + jobject gref = gtkpeer_get_global_ref (env, obj); + g_assert (gref); + + gdk_threads_enter (); + + /* Scrollbar signals */ +#if GTK_MINOR_VERSION > 4 + g_signal_connect (G_OBJECT (wid), "change-value", + G_CALLBACK (slider_moved_cb), gref); +#else + g_signal_connect (G_OBJECT (wid), "value-changed", + G_CALLBACK (post_change_event_cb), gref); +#endif + + /* Component signals */ + cp_gtk_component_connect_signals (G_OBJECT (wid), gref); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkScrollbarPeer_setLineIncrement + (JNIEnv *env, jobject obj, jint amount) +{ + void *ptr; + GtkAdjustment *adj; + GtkWidget *wid; + + ptr = gtkpeer_get_widget (env, obj); + wid = scrollbar_get_widget (GTK_WIDGET (ptr)); + + gdk_threads_enter (); + + adj = gtk_range_get_adjustment (GTK_RANGE (wid)); + adj->step_increment = (gdouble) amount; + gtk_adjustment_changed (adj); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkScrollbarPeer_setPageIncrement + (JNIEnv *env, jobject obj, jint amount) +{ + void *ptr; + GtkAdjustment *adj; + GtkWidget *wid; + + ptr = gtkpeer_get_widget (env, obj); + wid = scrollbar_get_widget (GTK_WIDGET (ptr)); + + gdk_threads_enter (); + + adj = gtk_range_get_adjustment (GTK_RANGE (wid)); + adj->page_increment = (gdouble) amount; + gtk_adjustment_changed (adj); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkScrollbarPeer_setBarValues + (JNIEnv *env, jobject obj, jint value, jint visible, jint min, jint max) +{ + void *ptr; + GtkAdjustment *adj; + GtkWidget *wid; + + ptr = gtkpeer_get_widget (env, obj); + wid = scrollbar_get_widget (GTK_WIDGET (ptr)); + + gdk_threads_enter (); + + /* A little hack because gtk_range_set_range() doesn't allow min == max. */ + if (min == max) + { + if (visible == 0) + visible = 1; + max++; + } + + adj = gtk_range_get_adjustment (GTK_RANGE (wid)); + adj->page_size = (gdouble) visible; + + gtk_range_set_range (GTK_RANGE (wid), (gdouble) min, (gdouble) max); + gtk_range_set_value (GTK_RANGE (wid), (gdouble) value); + + gdk_threads_leave (); +} + +#if GTK_MINOR_VERSION > 4 +static gboolean +slider_moved_cb (GtkRange *range, + GtkScrollType scroll, + gdouble value, + jobject obj) +{ + GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (range)); + + value = CLAMP (value, adj->lower, + (adj->upper - adj->page_size)); + + if (range->round_digits >= 0) + { + gdouble power; + gint i; + + i = range->round_digits; + power = 1; + while (i--) + power *= 10; + + value = floor ((value * power) + 0.5) / power; + } + + switch (scroll) + { + case GTK_SCROLL_STEP_BACKWARD: + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), obj, postAdjustmentEventID, + AWT_ADJUSTMENT_UNIT_DECREMENT, + (jint) value); + break; + case GTK_SCROLL_STEP_FORWARD: + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), obj, postAdjustmentEventID, + AWT_ADJUSTMENT_UNIT_INCREMENT, + (jint) value); + break; + case GTK_SCROLL_PAGE_BACKWARD: + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), obj, postAdjustmentEventID, + AWT_ADJUSTMENT_BLOCK_DECREMENT, + (jint) value); + break; + case GTK_SCROLL_PAGE_FORWARD: + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), obj, postAdjustmentEventID, + AWT_ADJUSTMENT_BLOCK_INCREMENT, + (jint) value); + break; + default: + /* GTK_SCROLL_JUMP: */ + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), obj, postAdjustmentEventID, + AWT_ADJUSTMENT_TRACK, + (jint) value); + break; + } + return FALSE; +} +#else +static void +post_change_event_cb (GtkRange *range, jobject peer) +{ + GtkAdjustment *adj; + adj = gtk_range_get_adjustment (range); + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, postAdjustmentEventID, + AWT_ADJUSTMENT_TRACK, (jint) adj->value); +} +#endif + +static GtkWidget * +scrollbar_get_widget (GtkWidget *widget) +{ + GtkWidget *wid; + g_assert (GTK_IS_EVENT_BOX (widget)); + wid = gtk_bin_get_child (GTK_BIN(widget)); + + return wid; +} diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkSelection.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkSelection.c new file mode 100644 index 000000000..e5ba4c7b1 --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkSelection.c @@ -0,0 +1,489 @@ +/* gtkselection.c -- Native C functions for GtkSelection class using gtk+. + Copyright (C) 2005, 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#include "jcl.h" +#include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkSelection.h" + +static jmethodID mimeTypesAvailableID; + +/* Note this is actually just a GtkClipboardReceivedFunc, not a real + GtkClipboardTargetsReceivedFunc, see requestMimeTypes. */ +static void +clipboard_targets_received (GtkClipboard *clipboard + __attribute__((unused)), + GtkSelectionData *target_data, + gpointer selection) +{ + GdkAtom *targets = NULL; + gint targets_len = 0; + gchar **target_strings = NULL; + jobjectArray strings = NULL; + int strings_len = 0; + gboolean include_text = FALSE; + gboolean include_image = FALSE; + gboolean include_uris = FALSE; + jobject selection_obj = (jobject) selection; + JNIEnv *env = cp_gtk_gdk_env (); + + if (target_data != NULL && target_data->length > 0) + { + include_text = gtk_selection_data_targets_include_text (target_data); + +#if GTK_MINOR_VERSION > 4 + include_image = gtk_selection_data_targets_include_image (target_data, + TRUE); +#endif + if (gtk_selection_data_get_targets (target_data, &targets, &targets_len)) + { + int i; + GdkAtom uri_list_atom = gdk_atom_intern ("text/uri-list", FALSE); + target_strings = g_new (gchar*, targets_len); + if (target_strings != NULL) + for (i = 0; i < targets_len; i++) + { + gchar *name = gdk_atom_name (targets[i]); + if (strchr (name, '/') != NULL) + { + target_strings[i] = name; + strings_len++; + if (! include_uris && targets[i] == uri_list_atom) + include_uris = TRUE; + } + else + target_strings[i] = NULL; + } + } + + if (target_strings != NULL) + { + int i = 0, j = 0; + jclass stringClass; + + if (include_text) + strings_len++; + if (include_image) + strings_len++; + if (include_uris) + strings_len++; + + stringClass = (*env)->FindClass (env, "java/lang/String"); + strings = (*env)->NewObjectArray (env, strings_len, stringClass, + NULL); + (*env)->DeleteLocalRef(env, stringClass); + + if (strings != NULL) + { + if (include_text) + (*env)->SetObjectArrayElement (env, strings, i++, + cp_gtk_stringTarget); + if (include_image) + (*env)->SetObjectArrayElement (env, strings, i++, + cp_gtk_imageTarget); + if (include_uris) + (*env)->SetObjectArrayElement (env, strings, i++, + cp_gtk_filesTarget); + + while(i < strings_len) + { + if (target_strings[j] == NULL) + j++; + else + { + jstring string; + string = (*env)->NewStringUTF (env, + target_strings[j++]); + if (string == NULL) + break; + (*env)->SetObjectArrayElement (env, strings, i++, + string); + (*env)->DeleteLocalRef (env, string); + } + } + + (*env)->DeleteLocalRef(env, strings); + } + + for (i = 0; i < targets_len; i++) + g_free (target_strings[i]); + g_free (target_strings); + } + } + + (*env)->CallVoidMethod (env, selection_obj, + mimeTypesAvailableID, + strings); + (*env)->DeleteGlobalRef (env, selection_obj); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkSelection_requestMimeTypes +(JNIEnv *env, jobject selection, jboolean clipboard) +{ + jobject selection_obj; + GtkClipboard *gtk_clipboard; + selection_obj = (*env)->NewGlobalRef(env, selection); + if (selection_obj == NULL) + return; + + if (mimeTypesAvailableID == NULL) + { + jclass gtk_selection_class; + gtk_selection_class = (*env)->GetObjectClass (env, selection_obj); + mimeTypesAvailableID = (*env)->GetMethodID (env, gtk_selection_class, + "mimeTypesAvailable", + "([Ljava/lang/String;)V"); + if (mimeTypesAvailableID == NULL) + return; + } + + if (clipboard) + gtk_clipboard = cp_gtk_clipboard; + else + gtk_clipboard = cp_gtk_selection; + + /* We would have liked to call gtk_clipboard_request_targets () + since that is more general. But the result of that, an array of + GdkAtoms, cannot be used with the + gtk_selection_data_targets_include_ functions (despite what + the name suggests). */ + gdk_threads_enter (); + gtk_clipboard_request_contents (gtk_clipboard, + gdk_atom_intern ("TARGETS", FALSE), + clipboard_targets_received, + (gpointer) selection_obj); + gdk_threads_leave (); +} + + +static jmethodID textAvailableID; + +static void +clipboard_text_received (GtkClipboard *clipboard + __attribute__((unused)), + const gchar *text, + gpointer selection) +{ + jstring string; + jobject selection_obj = (jobject) selection; + + JNIEnv *env = cp_gtk_gdk_env (); + if (text != NULL) + string = (*env)->NewStringUTF (env, text); + else + string = NULL; + + (*env)->CallVoidMethod (env, selection_obj, + textAvailableID, + string); + (*env)->DeleteGlobalRef (env, selection_obj); + + if (string != NULL) + (*env)->DeleteLocalRef (env, string); + +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkSelection_requestText +(JNIEnv *env, jobject selection, jboolean clipboard) +{ + jobject selection_obj; + GtkClipboard *gtk_clipboard; + selection_obj = (*env)->NewGlobalRef(env, selection); + if (selection_obj == NULL) + return; + + if (textAvailableID == NULL) + { + jclass gtk_selection_class; + gtk_selection_class = (*env)->GetObjectClass (env, selection_obj); + textAvailableID = (*env)->GetMethodID (env, gtk_selection_class, + "textAvailable", + "(Ljava/lang/String;)V"); + if (textAvailableID == NULL) + return; + } + + if (clipboard) + gtk_clipboard = cp_gtk_clipboard; + else + gtk_clipboard = cp_gtk_selection; + + gdk_threads_enter (); + gtk_clipboard_request_text (gtk_clipboard, + clipboard_text_received, + (gpointer) selection_obj); + gdk_threads_leave (); +} + +static jmethodID imageAvailableID; + +static void +clipboard_image_received (GtkClipboard *clipboard + __attribute__((unused)), + GdkPixbuf *pixbuf, + gpointer selection) +{ + jobject pointer = NULL; + jobject selection_obj = (jobject) selection; + JNIEnv *env = cp_gtk_gdk_env (); + + if (pixbuf != NULL) + { + g_object_ref (pixbuf); + pointer = JCL_NewRawDataObject (env, (void *) pixbuf); + } + + (*env)->CallVoidMethod (env, selection_obj, + imageAvailableID, + pointer); + (*env)->DeleteGlobalRef (env, selection_obj); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkSelection_requestImage (JNIEnv *env, + jobject obj, + jboolean clipboard) +{ + jobject selection_obj; + GtkClipboard *gtk_clipboard; + selection_obj = (*env)->NewGlobalRef(env, obj); + if (selection_obj == NULL) + return; + + if (imageAvailableID == NULL) + { + jclass gtk_selection_class; + gtk_selection_class = (*env)->GetObjectClass (env, selection_obj); + imageAvailableID = (*env)->GetMethodID (env, gtk_selection_class, + "imageAvailable", + "(Lgnu/classpath/Pointer;)V"); + if (imageAvailableID == NULL) + return; + } + + if (clipboard) + gtk_clipboard = cp_gtk_clipboard; + else + gtk_clipboard = cp_gtk_selection; + +#if GTK_MINOR_VERSION > 4 + gdk_threads_enter (); + gtk_clipboard_request_image (gtk_clipboard, + clipboard_image_received, + (gpointer) selection_obj); + gdk_threads_leave (); +#else + clipboard_image_received (gtk_clipboard, NULL, (gpointer) selection_obj); +#endif +} + +static jmethodID urisAvailableID; + +static void +clipboard_uris_received (GtkClipboard *clipboard + __attribute__((unused)), + GtkSelectionData *uri_data, + gpointer selection) +{ + gchar **uris = NULL; + jobjectArray strings = NULL; + jobject selection_obj = (jobject) selection; + JNIEnv *env = cp_gtk_gdk_env (); + +#if GTK_MINOR_VERSION > 4 + if (uri_data != NULL) + uris = gtk_selection_data_get_uris (uri_data); +#else + if (uri_data != NULL) + uris = NULL; +#endif + + if (uris != NULL) + { + int len, i; + gchar **count = uris; + jclass stringClass = (*env)->FindClass (env, "java/lang/String"); + + len = 0; + while (count[len]) + len++; + + strings = (*env)->NewObjectArray (env, len, stringClass, NULL); + (*env)->DeleteLocalRef(env, stringClass); + + if (strings != NULL) + { + for (i = 0; i < len; i++) + { + jstring string = (*env)->NewStringUTF (env, uris[i]); + if (string == NULL) + break; + (*env)->SetObjectArrayElement (env, strings, i, string); + (*env)->DeleteLocalRef (env, string); + } + + (*env)->DeleteLocalRef(env, strings); + } + g_strfreev (uris); + } + + (*env)->CallVoidMethod (env, selection_obj, + urisAvailableID, + strings); + (*env)->DeleteGlobalRef (env, selection_obj); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkSelection_requestURIs (JNIEnv *env, + jobject obj, + jboolean clipboard) +{ +#if GTK_MINOR_VERSION > 4 + GdkAtom uri_atom; +#endif + jobject selection_obj; + GtkClipboard *gtk_clipboard; + selection_obj = (*env)->NewGlobalRef(env, obj); + if (selection_obj == NULL) + return; + + if (urisAvailableID == NULL) + { + jclass gtk_selection_class; + gtk_selection_class = (*env)->GetObjectClass (env, selection_obj); + urisAvailableID = (*env)->GetMethodID (env, gtk_selection_class, + "urisAvailable", + "([Ljava/lang/String;)V"); + if (urisAvailableID == NULL) + return; + } + + if (clipboard) + gtk_clipboard = cp_gtk_clipboard; + else + gtk_clipboard = cp_gtk_selection; + +#if GTK_MINOR_VERSION > 4 + /* There is no real request_uris so we have to make one ourselves. */ + gdk_threads_enter (); + uri_atom = gdk_atom_intern ("text/uri-list", FALSE); + gtk_clipboard_request_contents (gtk_clipboard, + uri_atom, + clipboard_uris_received, + (gpointer) selection_obj); + gdk_threads_leave (); +#else + clipboard_uris_received (gtk_clipboard, NULL, (gpointer) selection_obj); +#endif +} + +static jmethodID bytesAvailableID; + +static void +clipboard_bytes_received (GtkClipboard *clipboard + __attribute__((unused)), + GtkSelectionData *selection_data, + gpointer selection) +{ + jbyteArray bytes = NULL; + jobject selection_obj = (jobject) selection; + JNIEnv *env = cp_gtk_gdk_env (); + + if (selection_data != NULL && selection_data->length > 0) + { + bytes = (*env)->NewByteArray (env, selection_data->length); + if (bytes != NULL) + (*env)->SetByteArrayRegion(env, bytes, 0, selection_data->length, + (jbyte *) selection_data->data); + } + + (*env)->CallVoidMethod (env, selection_obj, + bytesAvailableID, + bytes); + (*env)->DeleteGlobalRef (env, selection_obj); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkSelection_requestBytes (JNIEnv *env, + jobject obj, + jboolean clipboard, + jstring target_string) +{ + int len; + const gchar *target_text; + GdkAtom target_atom; + jobject selection_obj; + GtkClipboard *gtk_clipboard; + selection_obj = (*env)->NewGlobalRef(env, obj); + if (selection_obj == NULL) + return; + + if (bytesAvailableID == NULL) + { + jclass gtk_selection_class; + gtk_selection_class = (*env)->GetObjectClass (env, selection_obj); + bytesAvailableID = (*env)->GetMethodID (env, gtk_selection_class, + "bytesAvailable", + "([B)V"); + if (bytesAvailableID == NULL) + return; + } + + len = (*env)->GetStringUTFLength (env, target_string); + if (len == -1) + return; + target_text = (*env)->GetStringUTFChars (env, target_string, NULL); + if (target_text == NULL) + return; + + if (clipboard) + gtk_clipboard = cp_gtk_clipboard; + else + gtk_clipboard = cp_gtk_selection; + + gdk_threads_enter (); + target_atom = gdk_atom_intern (target_text, FALSE); + gtk_clipboard_request_contents (gtk_clipboard, + target_atom, + clipboard_bytes_received, + (gpointer) selection_obj); + gdk_threads_leave (); + + (*env)->ReleaseStringUTFChars (env, target_string, target_text); +} diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextAreaPeer.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextAreaPeer.c new file mode 100644 index 000000000..4d768fa33 --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextAreaPeer.c @@ -0,0 +1,547 @@ +/* gtktextareapeer.c -- Native implementation of GtkTextAreaPeer + Copyright (C) 1998, 1999, 2003 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkTextAreaPeer.h" + +#define AWT_TEXTAREA_SCROLLBARS_BOTH 0 +#define AWT_TEXTAREA_SCROLLBARS_VERTICAL_ONLY 1 +#define AWT_TEXTAREA_SCROLLBARS_HORIZONTAL_ONLY 2 + +static GtkWidget *textarea_get_widget (GtkWidget *widget); + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_create + (JNIEnv *env, jobject obj, + jint textview_width, jint textview_height, jint scroll) +{ + GtkWidget *text; + GtkWidget *sw; + GtkWidget *eventbox; + + gdk_threads_enter (); + + /* Create global reference and save it for future use */ + gtkpeer_set_global_ref (env, obj); + + text = gtk_text_view_new (); + gtk_widget_set_size_request (text, textview_width, textview_height); + gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW (text), TRUE); + + gtk_widget_show (text); + + eventbox = gtk_event_box_new (); + sw = gtk_scrolled_window_new (NULL, NULL); + gtk_container_add (GTK_CONTAINER (sw), text); + gtk_container_add (GTK_CONTAINER (eventbox), sw); + gtk_widget_show (sw); + + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), + /* horizontal scrollbar */ + (scroll == AWT_TEXTAREA_SCROLLBARS_BOTH + || scroll == AWT_TEXTAREA_SCROLLBARS_HORIZONTAL_ONLY) ? + GTK_POLICY_ALWAYS : GTK_POLICY_NEVER, + /* vertical scrollbar */ + (scroll == AWT_TEXTAREA_SCROLLBARS_BOTH + || scroll == AWT_TEXTAREA_SCROLLBARS_VERTICAL_ONLY) ? + GTK_POLICY_ALWAYS : GTK_POLICY_NEVER); + + gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text), + (scroll == AWT_TEXTAREA_SCROLLBARS_BOTH + || scroll == AWT_TEXTAREA_SCROLLBARS_HORIZONTAL_ONLY) + ? GTK_WRAP_NONE : GTK_WRAP_WORD); + + gtkpeer_set_widget (env, obj, eventbox); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_connectSignals + (JNIEnv *env, jobject obj) +{ + GtkWidget *text = NULL; + GtkTextBuffer *buf; + void *ptr; + jobject gref; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + gref = gtkpeer_get_global_ref (env, obj); + + /* Unwrap the text view from the scrolled window */ + text = textarea_get_widget (GTK_WIDGET (ptr)); + + buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text)); + + /* TextComponent signals */ + cp_gtk_textcomponent_connect_signals (G_OBJECT (buf), gref); + + /* Component signals */ + cp_gtk_component_connect_signals (G_OBJECT (text), gref); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_insert + (JNIEnv *env, jobject obj, jstring contents, jint position) +{ + GtkTextBuffer *buf; + GtkTextIter iter; + GtkWidget *text; + void *ptr; + const char *str; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + str = (*env)->GetStringUTFChars (env, contents, NULL); + + text = textarea_get_widget (GTK_WIDGET (ptr)); + + buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text)); + gtk_text_buffer_get_iter_at_offset (buf, &iter, position); + gtk_text_buffer_insert (buf, &iter, str, strlen (str)); + + (*env)->ReleaseStringUTFChars (env, contents, str); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_replaceRange + (JNIEnv *env, jobject obj, jstring contents, jint start, jint end) +{ + GtkWidget *text; + GtkTextBuffer *buf; + GtkTextIter iter, startIter, endIter; + void *ptr; + const char *str; + int mystart = start; + int myend = end; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + str = (*env)->GetStringUTFChars (env, contents, NULL); + + text = textarea_get_widget (GTK_WIDGET (ptr)); + + buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text)); + + gtk_text_buffer_get_iter_at_offset (buf, &startIter, mystart); + gtk_text_buffer_get_iter_at_offset (buf, &endIter, myend); + gtk_text_buffer_delete (buf, &startIter, &endIter); + + gtk_text_buffer_get_iter_at_offset (buf, &iter, mystart); + gtk_text_buffer_insert(buf, &iter, str, strlen (str)); + + (*env)->ReleaseStringUTFChars (env, contents, str); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_gtkWidgetModifyFont + (JNIEnv *env, jobject obj, jstring name, jint style, jint size) +{ + const char *font_name; + void *ptr; + GtkWidget *text; + PangoFontDescription *font_desc; + + gdk_threads_enter(); + + ptr = gtkpeer_get_widget (env, obj); + + text = textarea_get_widget (GTK_WIDGET (ptr)); + + font_name = (*env)->GetStringUTFChars (env, name, NULL); + + font_desc = pango_font_description_from_string (font_name); + pango_font_description_set_size (font_desc, + size * cp_gtk_dpi_conversion_factor); + + if (style & AWT_STYLE_BOLD) + pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD); + + if (style & AWT_STYLE_ITALIC) + pango_font_description_set_style (font_desc, PANGO_STYLE_OBLIQUE); + + gtk_widget_modify_font (GTK_WIDGET (text), font_desc); + + pango_font_description_free (font_desc); + + (*env)->ReleaseStringUTFChars (env, name, font_name); + + gdk_threads_leave(); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_gtkWidgetRequestFocus + (JNIEnv *env, jobject obj) +{ + void *ptr; + GtkWidget *text; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + text = textarea_get_widget (GTK_WIDGET (ptr)); + + gtk_widget_grab_focus (text); + + gdk_threads_leave (); +} + +JNIEXPORT jint JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_getHScrollbarHeight + (JNIEnv *env, jobject obj) +{ + void *ptr; + GtkWidget *bin; + GtkScrolledWindow *sw; + GtkRequisition requisition; + jint height = 0; + jint spacing = 0; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + bin = gtk_bin_get_child (GTK_BIN (ptr)); + sw = GTK_SCROLLED_WINDOW (bin); + + if (sw) + { + gtk_widget_size_request (sw->hscrollbar, &requisition); + gtk_widget_style_get (GTK_WIDGET (sw), "scrollbar_spacing", &spacing, NULL); + height = requisition.height + spacing; + } + + gdk_threads_leave (); + + return height; +} + +JNIEXPORT jint JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_getVScrollbarWidth + (JNIEnv *env, jobject obj) +{ + void *ptr; + GtkWidget *bin; + GtkScrolledWindow *sw; + GtkRequisition requisition; + jint width = 0; + jint spacing = 0; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + bin = gtk_bin_get_child (GTK_BIN (ptr)); + sw = GTK_SCROLLED_WINDOW (bin); + + if (sw) + { + gtk_widget_size_request (sw->vscrollbar, &requisition); + gtk_widget_style_get (GTK_WIDGET (sw), "scrollbar_spacing", &spacing, NULL); + width = requisition.width + spacing; + } + + gdk_threads_leave (); + + return width; +} + +JNIEXPORT jint JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_getCaretPosition + (JNIEnv *env, jobject obj) +{ + void *ptr; + int pos = 0; + GtkWidget *text = NULL; + GtkTextBuffer *buf; + GtkTextMark *mark; + GtkTextIter iter; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + text = textarea_get_widget (GTK_WIDGET (ptr)); + + buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text)); + mark = gtk_text_buffer_get_insert (buf); + gtk_text_buffer_get_iter_at_mark (buf, &iter, mark); + pos = gtk_text_iter_get_offset (&iter); + + gdk_threads_leave (); + + return pos; +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_setCaretPosition + (JNIEnv *env, jobject obj, jint pos) +{ + void *ptr; + GtkWidget *text = NULL; + GtkTextBuffer *buf; + GtkTextIter iter; + GtkTextMark *oldmark; + GtkTextIter olditer; + int oldpos; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + text = textarea_get_widget (GTK_WIDGET (ptr)); + + buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text)); + + /* Save old position. */ + oldmark = gtk_text_buffer_get_insert (buf); + gtk_text_buffer_get_iter_at_mark (buf, &olditer, oldmark); + oldpos = gtk_text_iter_get_offset (&olditer); + + /* Move to new position. */ + gtk_text_buffer_get_iter_at_offset (buf, &iter, pos); + gtk_text_buffer_place_cursor (buf, &iter); + + /* Scroll to new position. Alignment is determined + comparing the new position to the old position. */ + if (oldpos > pos) + gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (text), + &iter, 0, TRUE, 0, 0); + else if (oldpos < pos) + gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (text), + &iter, 0, TRUE, 1, 1); + + gdk_threads_leave (); +} + +JNIEXPORT jint JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_getSelectionStart + (JNIEnv *env, jobject obj) +{ + void *ptr; + int pos = 0; + GtkWidget *text = NULL; + GtkTextBuffer *buf; + GtkTextIter start; + GtkTextIter end; + GtkTextMark *mark; + GtkTextIter iter; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + text = textarea_get_widget (GTK_WIDGET (ptr)); + + buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text)); + + if (gtk_text_buffer_get_selection_bounds (buf, &start, &end)) + { + pos = gtk_text_iter_get_offset (&start); + } + else + { + mark = gtk_text_buffer_get_insert (buf); + gtk_text_buffer_get_iter_at_mark (buf, &iter, mark); + pos = gtk_text_iter_get_offset (&iter); + } + + gdk_threads_leave (); + + return pos; +} + +JNIEXPORT jint JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_getSelectionEnd + (JNIEnv *env, jobject obj) +{ + void *ptr; + int pos = 0; + GtkWidget *text = NULL; + GtkTextBuffer *buf; + GtkTextIter start; + GtkTextIter end; + GtkTextMark *mark; + GtkTextIter iter; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + text = textarea_get_widget (GTK_WIDGET (ptr)); + + buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text)); + + if (gtk_text_buffer_get_selection_bounds (buf, &start, &end)) + { + pos = gtk_text_iter_get_offset (&end); + } + else + { + mark = gtk_text_buffer_get_insert (buf); + gtk_text_buffer_get_iter_at_mark (buf, &iter, mark); + pos = gtk_text_iter_get_offset (&iter); + } + + gdk_threads_leave (); + + return pos; +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_select + (JNIEnv *env, jobject obj, jint start, jint end) +{ + void *ptr; + GtkWidget *text = NULL; + GtkTextBuffer *buf; + GtkTextIter iter; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + text = textarea_get_widget (GTK_WIDGET (ptr)); + + buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text)); + gtk_text_buffer_get_iter_at_offset (buf, &iter, start); + /* quickly move both 'insert' and 'selection_bound' to the + same position */ + gtk_text_buffer_place_cursor (buf, &iter); + gtk_text_buffer_get_iter_at_offset (buf, &iter, end); + gtk_text_buffer_move_mark_by_name (buf, "selection_bound", &iter); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_setEditable + (JNIEnv *env, jobject obj, jboolean state) +{ + void *ptr; + GtkWidget *text = NULL; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + text = textarea_get_widget (GTK_WIDGET (ptr)); + + gtk_text_view_set_editable (GTK_TEXT_VIEW (text), state); + + gdk_threads_leave (); +} + +JNIEXPORT jstring JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_getText + (JNIEnv *env, jobject obj) +{ + void *ptr; + char *contents = NULL; + jstring jcontents; + GtkWidget *text = NULL; + GtkTextBuffer *buf; + GtkTextIter start, end; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + text = textarea_get_widget (GTK_WIDGET (ptr)); + + buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text)); + gtk_text_buffer_get_start_iter (buf, &start); + gtk_text_buffer_get_end_iter (buf, &end); + contents = gtk_text_buffer_get_text (buf, &start, &end, FALSE); + + jcontents = (*env)->NewStringUTF (env, contents); + g_free (contents); + + gdk_threads_leave (); + + return jcontents; +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_setText + (JNIEnv *env, jobject obj, jstring contents) +{ + void *ptr; + const char *str; + GtkWidget *text = NULL; + GtkTextBuffer *buf; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + str = (*env)->GetStringUTFChars (env, contents, NULL); + + text = textarea_get_widget (GTK_WIDGET (ptr)); + + buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text)); + gtk_text_buffer_set_text (buf, str, strlen (str)); + + (*env)->ReleaseStringUTFChars (env, contents, str); + + gdk_threads_leave (); +} + +static GtkWidget * +textarea_get_widget (GtkWidget *widget) +{ + GtkWidget *wid; + g_assert (GTK_IS_EVENT_BOX (widget)); + + wid = gtk_bin_get_child (GTK_BIN (widget)); + g_assert (GTK_IS_SCROLLED_WINDOW (wid)); + + wid = gtk_bin_get_child (GTK_BIN (wid)); + + return wid; +} diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextFieldPeer.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextFieldPeer.c new file mode 100644 index 000000000..df82ff091 --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextFieldPeer.c @@ -0,0 +1,388 @@ +/* gtktextfieldpeer.c -- Native implementation of GtkTextFieldPeer + Copyright (C) 1998, 1999, 2002 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkTextFieldPeer.h" + +/* the color used for highlighting when the foreground is black, + since black highlights aren't a Good Idea. */ +#define BB_RED 16962 +#define BB_GREEN 26985 +#define BB_BLUE 31611 + +static jmethodID postTextEventID; + +void +cp_gtk_textcomponent_init_jni (void) +{ + jclass gtkcomponentpeer; + + gtkcomponentpeer = (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(), + "gnu/java/awt/peer/gtk/GtkComponentPeer"); + + postTextEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtkcomponentpeer, + "postTextEvent", + "()V"); +} + +static void textcomponent_changed_cb (GtkEditable *editable, jobject peer); + +static jint get_border_width (GtkWidget *entry); + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_create + (JNIEnv *env, jobject obj, jint text_width) +{ + GtkWidget *entry; + + gdk_threads_enter (); + + /* Create global reference and save it for future use */ + gtkpeer_set_global_ref (env, obj); + + entry = gtk_entry_new (); + gtk_widget_set_size_request (entry, + text_width + 2 * get_border_width (entry), -1); + + gtkpeer_set_widget (env, obj, entry); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_connectSignals + (JNIEnv *env, jobject obj) +{ + void *ptr; + jobject gref; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + gref = gtkpeer_get_global_ref (env, obj); + + /* TextComponent signals */ + cp_gtk_textcomponent_connect_signals (G_OBJECT (ptr), gref); + + /* Component signals */ + cp_gtk_component_connect_signals (G_OBJECT (ptr), gref); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_gtkWidgetSetBackground + (JNIEnv *env, jobject obj, jint red, jint green, jint blue) +{ + GdkColor color; + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + color.red = (red / 255.0) * 65535; + color.green = (green / 255.0) * 65535; + color.blue = (blue / 255.0) * 65535; + + gtk_widget_modify_base (GTK_WIDGET (ptr), GTK_STATE_NORMAL, &color); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_gtkWidgetSetForeground + (JNIEnv *env, jobject obj, jint red, jint green, jint blue) +{ + GdkColor color; + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + color.red = (red / 255.0) * 65535; + color.green = (green / 255.0) * 65535; + color.blue = (blue / 255.0) * 65535; + + gtk_widget_modify_text (GTK_WIDGET (ptr), GTK_STATE_NORMAL, &color); + + if ( red == 0 && green == 0 && blue == 0) + { + color.red = BB_RED; + color.green = BB_GREEN; + color.blue = BB_BLUE; + } + gtk_widget_modify_base (GTK_WIDGET (ptr), GTK_STATE_SELECTED, &color); + + gdk_threads_leave (); +} + +JNIEXPORT jint JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_gtkEntryGetBorderWidth + (JNIEnv *env, jobject obj) +{ + void *ptr; + int border_width = 0; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + border_width = get_border_width (GTK_WIDGET (ptr)); + + gdk_threads_leave (); + + return border_width; +} + +/* GTK hard-codes this value. It is the space between a GtkEntry's + frame and its text. */ +#define INNER_BORDER 2 + +static jint +get_border_width (GtkWidget *entry) +{ + gint focus_width; + gboolean interior_focus; + int x_border_width = INNER_BORDER; + + gtk_widget_style_get (entry, + "interior-focus", &interior_focus, + "focus-line-width", &focus_width, + NULL); + + if (GTK_ENTRY (entry)->has_frame) + x_border_width += entry->style->xthickness; + + if (!interior_focus) + x_border_width += focus_width; + + return x_border_width; +} + +#undef INNER_BORDER + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_setEchoChar + (JNIEnv *env, jobject obj, jchar c) +{ + void *ptr; + GtkEntry *entry; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + entry = GTK_ENTRY (ptr); + + if (c != 0) + { + /* FIXME: use gtk_entry_set_invisible_char (GtkEntry *entry, + gunichar ch) here. That means we must convert from jchar + (utf16) to gunichar (ucs4). */ + gtk_entry_set_visibility (entry, FALSE); + } + else + gtk_entry_set_visibility (entry, TRUE); + + gdk_threads_leave (); +} + +JNIEXPORT jint JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_getCaretPosition + (JNIEnv *env, jobject obj) +{ + void *ptr; + int pos = 0; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + pos = gtk_editable_get_position (GTK_EDITABLE (ptr)); + + gdk_threads_leave (); + + return pos; +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_setCaretPosition + (JNIEnv *env, jobject obj, jint pos) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + gtk_editable_set_position (GTK_EDITABLE (ptr), pos); + + gdk_threads_leave (); +} + +JNIEXPORT jint JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_getSelectionStart + (JNIEnv *env, jobject obj) +{ + void *ptr; + int pos = 0; + int starti, endi; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + if (gtk_editable_get_selection_bounds (GTK_EDITABLE (ptr), &starti, &endi)) + pos = starti; + else + pos = gtk_editable_get_position (GTK_EDITABLE (ptr)); + + gdk_threads_leave (); + + return pos; +} + +JNIEXPORT jint JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_getSelectionEnd + (JNIEnv *env, jobject obj) +{ + void *ptr; + int pos = 0; + int starti, endi; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + if (gtk_editable_get_selection_bounds (GTK_EDITABLE (ptr), &starti, &endi)) + pos = endi; + else + pos = gtk_editable_get_position (GTK_EDITABLE (ptr)); + + gdk_threads_leave (); + + return pos; +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_select + (JNIEnv *env, jobject obj, jint start, jint end) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + gtk_editable_select_region (GTK_EDITABLE (ptr), start, end); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_setEditable + (JNIEnv *env, jobject obj, jboolean state) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + gtk_editable_set_editable (GTK_EDITABLE (ptr), state); + + gdk_threads_leave (); +} + +JNIEXPORT jstring JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_getText + (JNIEnv *env, jobject obj) +{ + void *ptr; + char *contents = NULL; + jstring jcontents; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + contents = gtk_editable_get_chars (GTK_EDITABLE (ptr), 0, -1); + + jcontents = (*env)->NewStringUTF (env, contents); + + g_free (contents); + + gdk_threads_leave (); + + return jcontents; +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_setText + (JNIEnv *env, jobject obj, jstring contents) +{ + void *ptr; + const char *str; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + str = (*env)->GetStringUTFChars (env, contents, NULL); + + gtk_entry_set_text (GTK_ENTRY (ptr), str); + + (*env)->ReleaseStringUTFChars (env, contents, str); + + gdk_threads_leave (); +} + +void +cp_gtk_textcomponent_connect_signals (GObject *ptr, jobject gref) +{ + g_signal_connect (G_OBJECT(ptr), "changed", + G_CALLBACK (textcomponent_changed_cb), gref); +} + +static void +textcomponent_changed_cb (GtkEditable *editable __attribute__((unused)), + jobject peer) +{ + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, postTextEventID); +} diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c new file mode 100644 index 000000000..b2097970c --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c @@ -0,0 +1,626 @@ + +/* gtktoolkit.c -- Native portion of GtkToolkit + Copyright (C) 1998, 1999, 2005, 2007 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkToolkit.h" +#include "jcl.h" + +#define RC_FILE ".classpath-gtkrc" + +/* From java.awt.SystemColor */ +#define AWT_DESKTOP 0 +#define AWT_ACTIVE_CAPTION 1 +#define AWT_ACTIVE_CAPTION_TEXT 2 +#define AWT_ACTIVE_CAPTION_BORDER 3 +#define AWT_INACTIVE_CAPTION 4 +#define AWT_INACTIVE_CAPTION_TEXT 5 +#define AWT_INACTIVE_CAPTION_BORDER 6 +#define AWT_WINDOW 7 +#define AWT_WINDOW_BORDER 8 +#define AWT_WINDOW_TEXT 9 +#define AWT_MENU 10 +#define AWT_MENU_TEXT 11 +#define AWT_TEXT 12 +#define AWT_TEXT_TEXT 13 +#define AWT_TEXT_HIGHLIGHT 14 +#define AWT_TEXT_HIGHLIGHT_TEXT 15 +#define AWT_TEXT_INACTIVE_TEXT 16 +#define AWT_CONTROL 17 +#define AWT_CONTROL_TEXT 18 +#define AWT_CONTROL_HIGHLIGHT 19 +#define AWT_CONTROL_LT_HIGHLIGHT 20 +#define AWT_CONTROL_SHADOW 21 +#define AWT_CONTROL_DK_SHADOW 22 +#define AWT_SCROLLBAR 23 +#define AWT_INFO 24 +#define AWT_INFO_TEXT 25 +#define AWT_NUM_COLORS 26 + +#define VK_SHIFT 16 +#define VK_CONTROL 17 +#define VK_ALT 18 +#define VK_CAPS_LOCK 20 +#define VK_META 157 + +static jclass gtkgenericpeer; +static jclass gtktoolkit; +static JavaVM *java_vm; +static jmethodID printCurrentThreadID; +static jmethodID setRunningID; + +/** + * The global AWT lock object. + */ +static jobject global_lock; + +union env_union +{ + void *void_env; + JNIEnv *jni_env; +}; + +JNIEnv * +cp_gtk_gdk_env() +{ + union env_union tmp; + g_assert((*java_vm)->GetEnv(java_vm, &tmp.void_env, JNI_VERSION_1_2) == JNI_OK); + return tmp.jni_env; +} + + +GtkWindowGroup *cp_gtk_global_window_group; +double cp_gtk_dpi_conversion_factor; + +static void jni_lock_cb(); +static void jni_unlock_cb(); +static void init_glib_threads(JNIEnv*, jint, jobject); +static gboolean post_set_running_flag (gpointer); +static gboolean set_running_flag (gpointer); +static gboolean clear_running_flag (gpointer); +static void init_dpi_conversion_factor (void); +static void dpi_changed_cb (GtkSettings *settings, + GParamSpec *pspec); + +#if GTK_MINOR_VERSION > 4 +static GLogFunc old_glog_func; +static void glog_func (const gchar *log_domain, + GLogLevelFlags log_level, + const gchar *message, + gpointer user_data); +#endif + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkToolkit_initIDs +(JNIEnv *env, jclass cls __attribute__((unused))) +{ + gtkpeer_init_pointer_IDs(env); +} + +/* + * Call gtk_init. It is very important that this happen before any other + * gtk calls. + * + * The portableNativeSync argument may have the values: + * 1 if the Java property gnu.classpath.awt.gtk.portable.native.sync + * is set to "true". + * 0 if it is set to "false" + * -1 if unset. + */ + + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkToolkit_gtkInit (JNIEnv *env, + jclass clazz __attribute__((unused)), + jint portableNativeSync, + jobject lock) +{ + int argc = 1; + char **argv; + char *homedir, *rcpath = NULL; + + gtkgenericpeer = (*env)->FindClass(env, "gnu/java/awt/peer/gtk/GtkGenericPeer"); + + gtkgenericpeer = (*env)->NewGlobalRef(env, gtkgenericpeer); + + printCurrentThreadID = (*env)->GetStaticMethodID (env, gtkgenericpeer, + "printCurrentThread", "()V"); + + g_assert((*env)->GetJavaVM(env, &java_vm) == 0); + + /* GTK requires a program's argc and argv variables, and requires that they + be valid. Set it up. */ + argv = (char **) g_malloc (sizeof (char *) * 2); + argv[0] = (char *) g_malloc(1); + argv[0][0] = '\0'; + argv[1] = NULL; + + init_glib_threads(env, portableNativeSync, lock); + + /* From GDK 2.0 onwards we have to explicitly call gdk_threads_init */ + gdk_threads_init(); + + gtk_init (&argc, &argv); + +#if SYNCHRONIZE_GDK + XSynchronize (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), True); +#endif + + gtk_widget_set_default_colormap (gdk_rgb_get_colormap ()); + + if ((homedir = getenv ("HOME"))) + { + rcpath = (char *) g_malloc (strlen (homedir) + strlen (RC_FILE) + 2); + sprintf (rcpath, "%s/%s", homedir, RC_FILE); + } + + gtk_rc_parse ((rcpath) ? rcpath : RC_FILE); + + g_free (rcpath); + g_free (argv[0]); + g_free (argv); + + /* On errors or warning print a whole stacktrace. */ +#if GTK_MINOR_VERSION > 4 + old_glog_func = g_log_set_default_handler (&glog_func, NULL); +#endif + + cp_gtk_button_init_jni (env); + cp_gtk_checkbox_init_jni (); + cp_gtk_choice_init_jni (); + cp_gtk_component_init_jni (); + cp_gtk_filedialog_init_jni (); + cp_gtk_list_init_jni (); + cp_gtk_menuitem_init_jni (); + cp_gtk_scrollbar_init_jni (); + cp_gtk_textcomponent_init_jni (); + cp_gtk_window_init_jni (); + + cp_gtk_global_window_group = gtk_window_group_new (); + + init_dpi_conversion_factor (); + + gtktoolkit = (*env)->FindClass(env, "gnu/java/awt/peer/gtk/GtkMainThread"); + setRunningID = (*env)->GetStaticMethodID (env, gtktoolkit, + "setRunning", "(Z)V"); +} + +/** + * A callback function that implements gdk_threads_enter(). This is + * implemented to wrap the JNI MonitorEnter() function. + */ +static void jni_lock_cb() +{ + JNIEnv * env = cp_gtk_gdk_env(); + if ((*env)->MonitorEnter(env, global_lock) != JNI_OK) + { + printf("failure while entering GTK monitor\n"); + } +} + +/** + * A callback function that implements gdk_threads_leave(). This is + * implemented to wrap the JNI MonitorExit() function. + */ +static void jni_unlock_cb() +{ + + JNIEnv * env = cp_gtk_gdk_env(); + if ((*env)->MonitorExit(env, global_lock)) + { + printf("failure while exiting GTK monitor\n"); + } +} + +/** Initialize GLIB's threads properly, based on the value of the + gnu.classpath.awt.gtk.portable.native.sync Java system property. If + that's unset, use the PORTABLE_NATIVE_SYNC config.h macro. (TODO: + In some release following 0.10, that config.h macro will go away.) + */ +static void +init_glib_threads(JNIEnv *env, jint portableNativeSync, jobject lock) +{ + if (portableNativeSync < 0) + { +#ifdef PORTABLE_NATIVE_SYNC /* Default value, if not set by the Java system + property */ + portableNativeSync = 1; +#else + portableNativeSync = 0; +#endif + } + + if (!g_thread_supported ()) + { + if (portableNativeSync) + { + global_lock = (*env)->NewGlobalRef(env, lock); + gdk_threads_set_lock_functions(&jni_lock_cb, &jni_unlock_cb); + } + g_thread_init(NULL); + } + else + { + /* Warn if portable native sync is desired but the threading + system is already initialized. In that case we can't + override the threading implementation with our portable + native sync functions. */ + if (portableNativeSync) + g_printerr ("peer warning: portable native sync disabled.\n"); + } + + /* Debugging progress message; uncomment if needed: */ + /* printf("called gthread init\n"); */ +} + +void +cp_gtk_print_current_thread (void) +{ + (*cp_gtk_gdk_env())->CallStaticVoidMethod (cp_gtk_gdk_env(), gtkgenericpeer, printCurrentThreadID); +} + +/* This is a big hack, needed until this pango bug is resolved: + http://bugzilla.gnome.org/show_bug.cgi?id=119081. + See: http://mail.gnome.org/archives/gtk-i18n-list/2003-August/msg00001.html + for details. */ +static void +init_dpi_conversion_factor () +{ + GtkSettings *settings = gtk_settings_get_default (); + GObjectClass *klass; + + klass = G_OBJECT_CLASS (GTK_SETTINGS_GET_CLASS (settings)); + if (g_object_class_find_property (klass, "gtk-xft-dpi")) + { + int int_dpi; + g_object_get (settings, "gtk-xft-dpi", &int_dpi, NULL); + /* If int_dpi == -1 gtk-xft-dpi returns the default value. So we + have to do approximate calculation here. */ + if (int_dpi < 0) + cp_gtk_dpi_conversion_factor = PANGO_SCALE * 72.0 / 96.; + else + cp_gtk_dpi_conversion_factor = + PANGO_SCALE * 72.0 / (int_dpi / PANGO_SCALE); + + g_signal_connect (settings, "notify::gtk-xft-dpi", + G_CALLBACK (dpi_changed_cb), NULL); + } + else + /* Approximate. */ + cp_gtk_dpi_conversion_factor = PANGO_SCALE * 72.0 / 96.; +} + +static void +dpi_changed_cb (GtkSettings *settings, + GParamSpec *pspec __attribute__((unused))) +{ + int int_dpi; + g_object_get (settings, "gtk-xft-dpi", &int_dpi, NULL); + if (int_dpi < 0) + cp_gtk_dpi_conversion_factor = PANGO_SCALE * 72.0 / 96.; + else + cp_gtk_dpi_conversion_factor = + PANGO_SCALE * 72.0 / (int_dpi / PANGO_SCALE); +} + +#if GTK_MINOR_VERSION > 4 +static void +glog_func (const gchar *log_domain, + GLogLevelFlags log_level, + const gchar *message, + gpointer user_data) +{ + old_glog_func (log_domain, log_level, message, user_data); + if (log_level & (G_LOG_LEVEL_ERROR + | G_LOG_LEVEL_CRITICAL + | G_LOG_LEVEL_WARNING)) + { + JNIEnv *env = cp_gtk_gdk_env (); + jthrowable *exc = (*env)->ExceptionOccurred(env); + gchar *detail = g_strconcat (log_domain, ": ", message, NULL); + JCL_ThrowException (env, "java/lang/InternalError", detail); + g_free (detail); + (*env)->ExceptionDescribe (env); + if (exc != NULL) + (*env)->Throw (env, exc); + else + (*env)->ExceptionClear (env); + } +} +#endif + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkToolkit_gtkMain +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused))) +{ + gdk_threads_enter(); + + gtk_init_add (post_set_running_flag, NULL); + gtk_quit_add (gtk_main_level (), clear_running_flag, NULL); + + gtk_main (); + + gdk_threads_leave(); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkToolkit_gtkQuit +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused))) +{ + gdk_threads_enter (); + + gtk_main_quit (); + + gdk_threads_leave (); +} + + +static jint gdk_color_to_java_color (GdkColor color); + + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkToolkit_beep + (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused))) +{ + gdk_threads_enter (); + + gdk_beep (); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkToolkit_sync + (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused))) +{ + gdk_threads_enter (); + + gdk_flush (); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkToolkit_getScreenSizeDimensions + (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jintArray jdims) +{ + jint *dims = (*env)->GetIntArrayElements (env, jdims, 0); + + gdk_threads_enter (); + + dims[0] = gdk_screen_width (); + dims[1] = gdk_screen_height (); + + gdk_threads_leave (); + + (*env)->ReleaseIntArrayElements(env, jdims, dims, 0); +} + +JNIEXPORT jint JNICALL +Java_gnu_java_awt_peer_gtk_GtkToolkit_getScreenResolution + (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused))) +{ + jint res; + + gdk_threads_enter (); + + res = gdk_screen_width () / (gdk_screen_width_mm () / 25.4); + + gdk_threads_leave (); + + return res; +} + +/** + * Report the number of mouse buttons + * Returns the number of buttons of the first mouse found, or -1 if no mouse + * seems to be connected. + */ +JNIEXPORT jint JNICALL +Java_gnu_java_awt_peer_gtk_GtkToolkit_getMouseNumberOfButtons + (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused))) +{ + jint res = -1; + GList *devices; + GdkDevice *d; + + gdk_threads_enter (); + + /* FIXME: Why doesn't this return the correct number? */ + devices = gdk_devices_list(); + + while( res == -1 && devices != NULL ) + { + d = GDK_DEVICE( devices->data ); + if( d->source == GDK_SOURCE_MOUSE ) + res = d->num_keys; + devices = devices->next; + } + + gdk_threads_leave (); + + return res; +} + +#define CONVERT(type, state) \ + gdk_color_to_java_color (style->type[GTK_STATE_ ## state]) + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkToolkit_loadSystemColors + (JNIEnv *env, jobject obj __attribute__((unused)), + jintArray jcolors) +{ + jint *colors; + GtkStyle *style; + + /* FIXME: this was deadlocking so assume it is thread-safe for now; + we need to replace this call with a .properties file anyway. */ +#if 0 + gdk_threads_enter (); +#endif + + colors = (*env)->GetIntArrayElements (env, jcolors, 0); + + style = gtk_widget_get_default_style (); + + colors[AWT_DESKTOP] = CONVERT (bg, SELECTED); + colors[AWT_ACTIVE_CAPTION] = CONVERT (bg, SELECTED); + colors[AWT_ACTIVE_CAPTION_TEXT] = CONVERT (text, SELECTED); + colors[AWT_ACTIVE_CAPTION_BORDER] = CONVERT (fg, NORMAL); + colors[AWT_INACTIVE_CAPTION] = CONVERT (base, INSENSITIVE); + colors[AWT_INACTIVE_CAPTION_TEXT] = CONVERT (fg, INSENSITIVE); + colors[AWT_INACTIVE_CAPTION_BORDER] = CONVERT (fg, INSENSITIVE); + colors[AWT_WINDOW] = CONVERT (bg, NORMAL); + colors[AWT_WINDOW_BORDER] = CONVERT (fg, NORMAL); + colors[AWT_WINDOW_TEXT] = CONVERT (fg, NORMAL); + colors[AWT_MENU] = CONVERT (bg, NORMAL); + colors[AWT_MENU_TEXT] = CONVERT (fg, NORMAL); + colors[AWT_TEXT] = CONVERT (bg, NORMAL); + colors[AWT_TEXT_TEXT] = CONVERT (fg, NORMAL); + colors[AWT_TEXT_HIGHLIGHT] = CONVERT (bg, SELECTED); + colors[AWT_TEXT_HIGHLIGHT_TEXT] = CONVERT (fg, SELECTED); + colors[AWT_TEXT_INACTIVE_TEXT] = CONVERT (bg, INSENSITIVE); + colors[AWT_CONTROL] = CONVERT (bg, NORMAL); + colors[AWT_CONTROL_TEXT] = CONVERT (fg, NORMAL); + colors[AWT_CONTROL_HIGHLIGHT] = CONVERT (base, ACTIVE); + colors[AWT_CONTROL_LT_HIGHLIGHT] = CONVERT (bg, PRELIGHT); + colors[AWT_CONTROL_SHADOW] = CONVERT (bg, ACTIVE); + colors[AWT_CONTROL_DK_SHADOW] = CONVERT (fg, INSENSITIVE); + colors[AWT_SCROLLBAR] = CONVERT (base, INSENSITIVE); + colors[AWT_INFO] = CONVERT (bg, NORMAL); + colors[AWT_INFO_TEXT] = CONVERT (fg, NORMAL); + + (*env)->ReleaseIntArrayElements(env, jcolors, colors, 0); + +#if 0 + gdk_threads_leave (); +#endif +} + +#undef CONVERT + +static jint +gdk_color_to_java_color (GdkColor gdk_color) +{ + guchar red; + guchar green; + guchar blue; + float factor; + + factor = 255.0 / 65535.0; + + red = (float) gdk_color.red * factor; + green = (float) gdk_color.green * factor; + blue = (float) gdk_color.blue * factor; + + return (jint) (0xff000000 | (red << 16) | (green << 8) | blue); +} + +JNIEXPORT jint JNICALL +Java_gnu_java_awt_peer_gtk_GtkToolkit_getLockState + (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jint key) +{ + gint coord; + GdkModifierType state, mask; + GdkWindow *root_window; + + gdk_threads_enter (); + + root_window = gdk_get_default_root_window (); + gdk_window_get_pointer (root_window, &coord, &coord, &state); + + switch (key) + { + case VK_SHIFT: + mask = GDK_SHIFT_MASK; + break; + case VK_CONTROL: + mask = GDK_CONTROL_MASK; + break; + case VK_ALT: + /* This is dubious, since MOD1 could have been mapped to something + other than ALT. */ + mask = GDK_MOD1_MASK; + break; +#if GTK_CHECK_VERSION(2, 10, 0) + case VK_META: + mask = GDK_META_MASK; + break; +#endif + case VK_CAPS_LOCK: + mask = GDK_LOCK_MASK; + break; + default: + mask = 0; + } + + gdk_threads_leave (); + + if (mask == 0) + return -1; + + return state & mask ? 1 : 0; +} + +static gboolean +post_set_running_flag (gpointer data __attribute__((unused))) +{ + g_idle_add (set_running_flag, NULL); + return FALSE; +} + +static gboolean +set_running_flag (gpointer data __attribute__((unused))) +{ + (*cp_gtk_gdk_env ())->CallStaticVoidMethod (cp_gtk_gdk_env (), + gtktoolkit, + setRunningID, TRUE); + return FALSE; +} + +static gboolean +clear_running_flag (gpointer data __attribute__((unused))) +{ + (*cp_gtk_gdk_env ())->CallStaticVoidMethod (cp_gtk_gdk_env (), + gtktoolkit, + setRunningID, FALSE); + return FALSE; +} + diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkVolatileImage.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkVolatileImage.c new file mode 100644 index 000000000..50197cab0 --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkVolatileImage.c @@ -0,0 +1,204 @@ +/* gnu_java_awt_peer_gtk_VolatileImage.c + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include "jcl.h" +#include "gtkpeer.h" +#include +#include +#include +#include + +#include "gnu_java_awt_peer_gtk_GtkVolatileImage.h" +#include "cairographics2d.h" + + +/** + * Creates a cairo surface, ARGB32, native ordering, premultiplied alpha. + */ +JNIEXPORT jlong JNICALL +Java_gnu_java_awt_peer_gtk_GtkVolatileImage_init (JNIEnv *env, + jobject obj __attribute__ ((__unused__)), + jobject peer, + jint width, jint height) +{ + GtkWidget *widget = NULL; + GdkPixmap* pixmap; + void *ptr = NULL; + + gdk_threads_enter(); + + if( peer != NULL ) + { + ptr = gtkpeer_get_widget (env, peer); + g_assert (ptr != NULL); + + widget = GTK_WIDGET (ptr); + g_assert (widget != NULL); + pixmap = gdk_pixmap_new( widget->window, width, height, -1 ); + } + else + pixmap = gdk_pixmap_new( NULL, width, height, + gdk_rgb_get_visual()->depth ); + + gdk_threads_leave(); + + g_assert( pixmap != NULL ); + + return PTR_TO_JLONG( pixmap ); +} + +/** + * Destroy the surface + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkVolatileImage_destroy +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer) +{ + GdkPixmap* pixmap = JLONG_TO_PTR(GdkPixmap, pointer); + if( pixmap != NULL ) + { + gdk_threads_enter(); + g_object_unref( pixmap ); + gdk_threads_leave(); + } +} + +/** + * Gets all pixels in an array + */ +JNIEXPORT jintArray JNICALL +Java_gnu_java_awt_peer_gtk_GtkVolatileImage_nativeGetPixels +(JNIEnv *env, jobject obj, jlong pointer) +{ + /* jint *pixeldata, *jpixdata; */ + jint *jpixdata; + GdkPixmap *pixmap; + GdkPixbuf *pixbuf; + jintArray jpixels; + int width, height, depth, size; + jclass cls; + jfieldID field; + guchar *pixels; + + cls = (*env)->GetObjectClass (env, obj); + field = (*env)->GetFieldID (env, cls, "width", "I"); + g_assert (field != 0); + width = (*env)->GetIntField (env, obj, field); + + field = (*env)->GetFieldID (env, cls, "height", "I"); + g_assert (field != 0); + height = (*env)->GetIntField (env, obj, field); + + pixmap = JLONG_TO_PTR(GdkPixmap, pointer); + g_assert(pixmap != NULL); + + gdk_threads_enter(); + + /* get depth in bytes */ + depth = gdk_drawable_get_depth( pixmap ) >> 3; + size = width * height; + jpixels = (*env)->NewIntArray ( env, size ); + jpixdata = (*env)->GetIntArrayElements (env, jpixels, NULL); + + pixbuf = gdk_pixbuf_new( GDK_COLORSPACE_RGB, TRUE, 8, width, height ); + gdk_pixbuf_get_from_drawable( pixbuf, pixmap, NULL, 0, 0, 0, 0, width, height ); + + if (pixbuf != NULL) + { + pixels = gdk_pixbuf_get_pixels(pixbuf); + memcpy (jpixdata, pixels, size * sizeof(jint)); + } + + (*env)->ReleaseIntArrayElements (env, jpixels, jpixdata, 0); + + gdk_threads_leave(); + + return jpixels; +} + +/** + * Copy area + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkVolatileImage_nativeCopyArea +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer, jint x, jint y, jint w, jint h, jint dx, jint dy) +{ + GdkPixbuf *pixbuf; + GdkPixmap* pixmap = JLONG_TO_PTR(GdkPixmap, pointer); + + g_assert (pixmap != NULL); + + gdk_threads_enter(); + + pixbuf = gdk_pixbuf_new( GDK_COLORSPACE_RGB, TRUE, 8, w, h ); + gdk_pixbuf_get_from_drawable( pixbuf, pixmap, NULL, x, y, 0, 0, w, h ); + gdk_draw_pixbuf (pixmap, NULL, pixbuf, + 0, 0, x + dx, y + dy, + w, h, + GDK_RGB_DITHER_NORMAL, 0, 0); + gdk_threads_leave(); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkVolatileImage_nativeDrawVolatile +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), + jlong pointer, jlong srcptr, jint x, jint y, jint w, jint h) +{ + GdkPixmap *dst, *src; + GdkGC *gc; + + src = JLONG_TO_PTR(GdkPixmap, srcptr); + dst = JLONG_TO_PTR(GdkPixmap, pointer); + g_assert (src != NULL); + g_assert (dst != NULL); + + gdk_threads_enter(); + + gc = gdk_gc_new( dst ); + gdk_draw_drawable(dst, + gc, + src, + 0, 0, + x, y, + w, h); + g_object_unref( gc ); + + gdk_threads_leave(); +} + diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c new file mode 100644 index 000000000..6ba8d4767 --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c @@ -0,0 +1,2164 @@ +/* gtkwindowpeer.c -- Native implementation of GtkWindowPeer + Copyright (C) 1998, 1999, 2002, 2004, 2005, 2006 + Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkWindowPeer.h" +#include +#include +#include +#include + +#define AWT_WINDOW_CLOSING 201 +#define AWT_WINDOW_CLOSED 202 +#define AWT_WINDOW_ICONIFIED 203 +#define AWT_WINDOW_DEICONIFIED 204 +#define AWT_WINDOW_ACTIVATED 205 +#define AWT_WINDOW_DEACTIVATED 206 +#define AWT_WINDOW_GAINED_FOCUS 207 +#define AWT_WINDOW_LOST_FOCUS 208 +#define AWT_WINDOW_STATE_CHANGED 209 + +#define AWT_FRAME_NORMAL 0 +#define AWT_FRAME_ICONIFIED 1 +#define AWT_FRAME_MAXIMIZED_BOTH 6 + +/* Virtual Keys */ +/* This list should be kept in the same order as the VK_ field + declarations in KeyEvent.java. */ +#define VK_ENTER '\n' +#define VK_BACK_SPACE '\b' +#define VK_TAB '\t' +#define VK_CANCEL 3 +#define VK_CLEAR 12 +#define VK_SHIFT 16 +#define VK_CONTROL 17 +#define VK_ALT 18 +#define VK_PAUSE 19 +#define VK_CAPS_LOCK 20 +#define VK_ESCAPE 27 +#define VK_SPACE ' ' +#define VK_PAGE_UP 33 +#define VK_PAGE_DOWN 34 +#define VK_END 35 +#define VK_HOME 36 +#define VK_LEFT 37 +#define VK_UP 38 +#define VK_RIGHT 39 +#define VK_DOWN 40 +#define VK_COMMA ',' +#define VK_MINUS '-' +#define VK_PERIOD '.' +#define VK_SLASH '/' +#define VK_0 '0' +#define VK_1 '1' +#define VK_2 '2' +#define VK_3 '3' +#define VK_4 '4' +#define VK_5 '5' +#define VK_6 '6' +#define VK_7 '7' +#define VK_8 '8' +#define VK_9 '9' +#define VK_SEMICOLON ';' +#define VK_EQUALS '=' +#define VK_A 'A' +#define VK_B 'B' +#define VK_C 'C' +#define VK_D 'D' +#define VK_E 'E' +#define VK_F 'F' +#define VK_G 'G' +#define VK_H 'H' +#define VK_I 'I' +#define VK_J 'J' +#define VK_K 'K' +#define VK_L 'L' +#define VK_M 'M' +#define VK_N 'N' +#define VK_O 'O' +#define VK_P 'P' +#define VK_Q 'Q' +#define VK_R 'R' +#define VK_S 'S' +#define VK_T 'T' +#define VK_U 'U' +#define VK_V 'V' +#define VK_W 'W' +#define VK_X 'X' +#define VK_Y 'Y' +#define VK_Z 'Z' +#define VK_OPEN_BRACKET '[' +#define VK_BACK_SLASH '\\' +#define VK_CLOSE_BRACKET ']' +/* See gtkpeer.h */ +/* #define VK_NUMPAD0 96 */ +/* #define VK_NUMPAD1 97 */ +/* #define VK_NUMPAD2 98 */ +/* #define VK_NUMPAD3 99 */ +/* #define VK_NUMPAD4 100 */ +/* #define VK_NUMPAD5 101 */ +/* #define VK_NUMPAD6 102 */ +/* #define VK_NUMPAD7 103 */ +/* #define VK_NUMPAD8 104 */ +/* #define VK_NUMPAD9 105 */ +#define VK_MULTIPLY 106 +#define VK_ADD 107 +#define VK_SEPARATER 108 +#define VK_SEPARATOR 108 +#define VK_SUBTRACT 109 +/* See gtkpeer.h */ +/* #define VK_DECIMAL 110 */ +#define VK_DIVIDE 111 +#define VK_DELETE 127 +#define VK_NUM_LOCK 144 +#define VK_SCROLL_LOCK 145 +#define VK_F1 112 +#define VK_F2 113 +#define VK_F3 114 +#define VK_F4 115 +#define VK_F5 116 +#define VK_F6 117 +#define VK_F7 118 +#define VK_F8 119 +#define VK_F9 120 +#define VK_F10 121 +#define VK_F11 122 +#define VK_F12 123 +#define VK_F13 61440 +#define VK_F14 61441 +#define VK_F15 61442 +#define VK_F16 61443 +#define VK_F17 61444 +#define VK_F18 61445 +#define VK_F19 61446 +#define VK_F20 61447 +#define VK_F21 61448 +#define VK_F22 61449 +#define VK_F23 61450 +#define VK_F24 61451 +#define VK_PRINTSCREEN 154 +#define VK_INSERT 155 +#define VK_HELP 156 +#define VK_META 157 +#define VK_BACK_QUOTE 192 +#define VK_QUOTE 222 +#define VK_KP_UP 224 +#define VK_KP_DOWN 225 +#define VK_KP_LEFT 226 +#define VK_KP_RIGHT 227 +#define VK_DEAD_GRAVE 128 +#define VK_DEAD_ACUTE 129 +#define VK_DEAD_CIRCUMFLEX 130 +#define VK_DEAD_TILDE 131 +#define VK_DEAD_MACRON 132 +#define VK_DEAD_BREVE 133 +#define VK_DEAD_ABOVEDOT 134 +#define VK_DEAD_DIAERESIS 135 +#define VK_DEAD_ABOVERING 136 +#define VK_DEAD_DOUBLEACUTE 137 +#define VK_DEAD_CARON 138 +#define VK_DEAD_CEDILLA 139 +#define VK_DEAD_OGONEK 140 +#define VK_DEAD_IOTA 141 +#define VK_DEAD_VOICED_SOUND 142 +#define VK_DEAD_SEMIVOICED_SOUND 143 +#define VK_AMPERSAND 150 +#define VK_ASTERISK 151 +#define VK_QUOTEDBL 152 +#define VK_LESS 153 +#define VK_GREATER 160 +#define VK_BRACELEFT 161 +#define VK_BRACERIGHT 162 +#define VK_AT 512 +#define VK_COLON 513 +#define VK_CIRCUMFLEX 514 +#define VK_DOLLAR 515 +#define VK_EURO_SIGN 516 +#define VK_EXCLAMATION_MARK 517 +#define VK_INVERTED_EXCLAMATION_MARK 518 +#define VK_LEFT_PARENTHESIS 519 +#define VK_NUMBER_SIGN 520 +#define VK_PLUS 521 +#define VK_RIGHT_PARENTHESIS 522 +#define VK_UNDERSCORE 523 +#define VK_FINAL 24 +#define VK_CONVERT 28 +#define VK_NONCONVERT 29 +#define VK_ACCEPT 30 +#define VK_MODECHANGE 31 +#define VK_KANA 21 +#define VK_KANJI 25 +#define VK_ALPHANUMERIC 240 +#define VK_KATAKANA 241 +#define VK_HIRAGANA 242 +#define VK_FULL_WIDTH 243 +#define VK_HALF_WIDTH 244 +#define VK_ROMAN_CHARACTERS 245 +#define VK_ALL_CANDIDATES 256 +#define VK_PREVIOUS_CANDIDATE 257 +#define VK_CODE_INPUT 258 +#define VK_JAPANESE_KATAKANA 259 +#define VK_JAPANESE_HIRAGANA 260 +#define VK_JAPANESE_ROMAN 261 +#define VK_KANA_LOCK 262 +#define VK_INPUT_METHOD_ON_OFF 263 +#define VK_CUT 65489 +#define VK_COPY 65485 +#define VK_PASTE 65487 +#define VK_UNDO 65483 +#define VK_AGAIN 65481 +#define VK_FIND 65488 +#define VK_PROPS 65482 +#define VK_STOP 65480 +#define VK_COMPOSE 65312 +#define VK_ALT_GRAPH 65406 +#define VK_UNDEFINED 0 +#define VK_BEGIN 65368 +#define VK_CONTEXT_MENU 525 +#define VK_WINDOWS 524 + + +#define AWT_KEY_CHAR_UNDEFINED 0 + +#define AWT_FRAME_STATE_NORMAL 0 +#define AWT_FRAME_STATE_ICONIFIED 1 +#define AWT_FRAME_STATE_MAXIMIZED_HORIZ 2 +#define AWT_FRAME_STATE_MAXIMIZED_VERT 4 +#define AWT_FRAME_STATE_MAXIMIZED_BOTH 6 + +static jmethodID postKeyEventID; +static jmethodID postWindowEventID; +static jmethodID postConfigureEventID; +static jmethodID postInsetsChangedEventID; +static jmethodID windowGetWidthID; +static jmethodID windowGetHeightID; + +void +cp_gtk_window_init_jni (void) +{ + jclass gtkwindowpeer; + + gtkwindowpeer = (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(), + "gnu/java/awt/peer/gtk/GtkWindowPeer"); + + postKeyEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtkwindowpeer, + "postKeyEvent", "(IJIICI)V"); + + postWindowEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtkwindowpeer, + "postWindowEvent", + "(ILjava/awt/Window;I)V"); + + postConfigureEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtkwindowpeer, + "postConfigureEvent", "(IIII)V"); + + postInsetsChangedEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtkwindowpeer, + "postInsetsChangedEvent", + "(IIII)V"); + + windowGetWidthID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtkwindowpeer, + "getWidth", "()I"); + + windowGetHeightID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtkwindowpeer, + "getHeight", "()I"); + + gtkwindowpeer = (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(), + "gnu/java/awt/peer/gtk/GtkWindowPeer"); +} + +/* Get the first keyval in the keymap for this event's keycode. The + first keyval corresponds roughly to Java's notion of a virtual key. + Returns the uppercase version of the first keyval or -1 if no + keyval was found for the given hardware keycode. */ +static gint +get_first_keyval_from_keymap (GdkEventKey *event) +{ + guint keyval; + guint *keyvals; + gint n_entries; + + if (!gdk_keymap_get_entries_for_keycode (NULL, + event->hardware_keycode, + NULL, + &keyvals, + &n_entries)) + { + /* No keyval found for hardware keycode */ + return -1; + } + keyval = keyvals[0]; + g_free (keyvals); + + return gdk_keyval_to_upper (keyval); +} + +/* Return the AWT key code for the given keysym or -1 if no keyval was + found for the given hardware keycode. */ +#ifdef __GNUC__ +__inline +#endif +static jint +keysym_to_awt_keycode (GdkEventKey *event) +{ + gint ukeyval; + guint state; + + ukeyval = get_first_keyval_from_keymap (event); + + if (ukeyval < 0) + return -1; + + state = event->state; + + /* VK_A through VK_Z */ + if (ukeyval >= GDK_A && ukeyval <= GDK_Z) + return ukeyval; + + /* VK_0 through VK_9 */ + if (ukeyval >= GDK_0 && ukeyval <= GDK_9) + return ukeyval; + + switch (ukeyval) + { + case GDK_Return: + case GDK_KP_Enter: + return VK_ENTER; + case GDK_BackSpace: + return VK_BACK_SPACE; + case GDK_Tab: + return VK_TAB; + case GDK_Cancel: + return VK_CANCEL; + case GDK_Clear: + return VK_CLEAR; + case GDK_Shift_L: + case GDK_Shift_R: + return VK_SHIFT; + case GDK_Control_L: + case GDK_Control_R: + return VK_CONTROL; + case GDK_Alt_L: + case GDK_Alt_R: + return VK_ALT; + case GDK_Pause: + return VK_PAUSE; + case GDK_Caps_Lock: + return VK_CAPS_LOCK; + case GDK_Escape: + return VK_ESCAPE; + case GDK_space: + return VK_SPACE; + case GDK_KP_Page_Up: + /* For keys on the numeric keypad, the JVM produces one of two + virtual keys, depending on the num lock state. */ + if (state & GDK_MOD2_MASK) + return VK_NUMPAD9; + else + return VK_PAGE_UP; + case GDK_Page_Up: + return VK_PAGE_UP; + case GDK_KP_Page_Down: + if (state & GDK_MOD2_MASK) + return VK_NUMPAD3; + else + return VK_PAGE_DOWN; + case GDK_Page_Down: + return VK_PAGE_DOWN; + case GDK_KP_End: + if (state & GDK_MOD2_MASK) + return VK_NUMPAD1; + else + return VK_END; + case GDK_End: + return VK_END; + case GDK_KP_Home: + if (state & GDK_MOD2_MASK) + return VK_NUMPAD7; + else + return VK_HOME; + case GDK_Home: + return VK_HOME; + case GDK_KP_Begin: + if (state & GDK_MOD2_MASK) + return VK_NUMPAD5; + else + return VK_UNDEFINED; + case GDK_Left: + return VK_LEFT; + case GDK_Up: + return VK_UP; + case GDK_Right: + return VK_RIGHT; + case GDK_Down: + return VK_DOWN; + case GDK_comma: + return VK_COMMA; + case GDK_minus: + return VK_MINUS; + case GDK_period: + return VK_PERIOD; + case GDK_slash: + return VK_SLASH; + /* + return VK_0; + return VK_1; + return VK_2; + return VK_3; + return VK_4; + return VK_5; + return VK_6; + return VK_7; + return VK_8; + return VK_9; + */ + case GDK_semicolon: + return VK_SEMICOLON; + case GDK_equal: + return VK_EQUALS; + /* + return VK_A; + return VK_B; + return VK_C; + return VK_D; + return VK_E; + return VK_F; + return VK_G; + return VK_H; + return VK_I; + return VK_J; + return VK_K; + return VK_L; + return VK_M; + return VK_N; + return VK_O; + return VK_P; + return VK_Q; + return VK_R; + return VK_S; + return VK_T; + return VK_U; + return VK_V; + return VK_W; + return VK_X; + return VK_Y; + return VK_Z; + */ + case GDK_bracketleft: + return VK_OPEN_BRACKET; + case GDK_backslash: + return VK_BACK_SLASH; + case GDK_bracketright: + return VK_CLOSE_BRACKET; + case GDK_KP_0: + return VK_NUMPAD0; + case GDK_KP_1: + return VK_NUMPAD1; + case GDK_KP_2: + return VK_NUMPAD2; + case GDK_KP_3: + return VK_NUMPAD3; + case GDK_KP_4: + return VK_NUMPAD4; + case GDK_KP_5: + return VK_NUMPAD5; + case GDK_KP_6: + return VK_NUMPAD6; + case GDK_KP_7: + return VK_NUMPAD7; + case GDK_KP_8: + return VK_NUMPAD8; + case GDK_KP_9: + return VK_NUMPAD9; + case GDK_KP_Multiply: + return VK_MULTIPLY; + case GDK_KP_Add: + return VK_ADD; + /* + return VK_SEPARATER; + */ + case GDK_KP_Separator: + return VK_SEPARATOR; + case GDK_KP_Subtract: + return VK_SUBTRACT; + case GDK_KP_Decimal: + return VK_DECIMAL; + case GDK_KP_Divide: + return VK_DIVIDE; + case GDK_KP_Delete: + if (state & GDK_MOD2_MASK) + return VK_DECIMAL; + else + return VK_DELETE; + case GDK_Delete: + return VK_DELETE; + case GDK_Num_Lock: + return VK_NUM_LOCK; + case GDK_Scroll_Lock: + return VK_SCROLL_LOCK; + case GDK_F1: + return VK_F1; + case GDK_F2: + return VK_F2; + case GDK_F3: + return VK_F3; + case GDK_F4: + return VK_F4; + case GDK_F5: + return VK_F5; + case GDK_F6: + return VK_F6; + case GDK_F7: + return VK_F7; + case GDK_F8: + return VK_F8; + case GDK_F9: + return VK_F9; + case GDK_F10: + return VK_F10; + case GDK_F11: + return VK_F11; + case GDK_F12: + return VK_F12; + case GDK_F13: + return VK_F13; + case GDK_F14: + return VK_F14; + case GDK_F15: + return VK_F15; + case GDK_F16: + return VK_F16; + case GDK_F17: + return VK_F17; + case GDK_F18: + return VK_F18; + case GDK_F19: + return VK_F19; + case GDK_F20: + return VK_F20; + case GDK_F21: + return VK_F21; + case GDK_F22: + return VK_F22; + case GDK_F23: + return VK_F23; + case GDK_F24: + return VK_F24; + case GDK_Print: + return VK_PRINTSCREEN; + case GDK_KP_Insert: + if (state & GDK_MOD2_MASK) + return VK_NUMPAD0; + else + return VK_INSERT; + case GDK_Insert: + return VK_INSERT; + case GDK_Help: + return VK_HELP; + case GDK_Meta_L: + case GDK_Meta_R: + return VK_META; + case GDK_grave: + return VK_BACK_QUOTE; + case GDK_apostrophe: + return VK_QUOTE; + case GDK_KP_Up: + if (state & GDK_MOD2_MASK) + return VK_NUMPAD8; + else + return VK_KP_UP; + case GDK_KP_Down: + if (state & GDK_MOD2_MASK) + return VK_NUMPAD2; + else + return VK_KP_DOWN; + case GDK_KP_Left: + if (state & GDK_MOD2_MASK) + return VK_NUMPAD4; + else + return VK_KP_LEFT; + case GDK_KP_Right: + if (state & GDK_MOD2_MASK) + return VK_NUMPAD6; + else + return VK_KP_RIGHT; + case GDK_dead_grave: + return VK_DEAD_GRAVE; + case GDK_dead_acute: + return VK_DEAD_ACUTE; + case GDK_dead_circumflex: + return VK_DEAD_CIRCUMFLEX; + case GDK_dead_tilde: + return VK_DEAD_TILDE; + case GDK_dead_macron: + return VK_DEAD_MACRON; + case GDK_dead_breve: + return VK_DEAD_BREVE; + case GDK_dead_abovedot: + return VK_DEAD_ABOVEDOT; + case GDK_dead_diaeresis: + return VK_DEAD_DIAERESIS; + case GDK_dead_abovering: + return VK_DEAD_ABOVERING; + case GDK_dead_doubleacute: + return VK_DEAD_DOUBLEACUTE; + case GDK_dead_caron: + return VK_DEAD_CARON; + case GDK_dead_cedilla: + return VK_DEAD_CEDILLA; + case GDK_dead_ogonek: + return VK_DEAD_OGONEK; + case GDK_dead_iota: + return VK_DEAD_IOTA; + case GDK_dead_voiced_sound: + return VK_DEAD_VOICED_SOUND; + case GDK_dead_semivoiced_sound: + return VK_DEAD_SEMIVOICED_SOUND; + case GDK_ampersand: + return VK_AMPERSAND; + case GDK_asterisk: + return VK_ASTERISK; + case GDK_quotedbl: + return VK_QUOTEDBL; + case GDK_less: + return VK_LESS; + case GDK_greater: + return VK_GREATER; + case GDK_braceleft: + return VK_BRACELEFT; + case GDK_braceright: + return VK_BRACERIGHT; + case GDK_at: + return VK_AT; + case GDK_colon: + return VK_COLON; + case GDK_asciicircum: + return VK_CIRCUMFLEX; + case GDK_dollar: + return VK_DOLLAR; + case GDK_EuroSign: + return VK_EURO_SIGN; + case GDK_exclam: + return VK_EXCLAMATION_MARK; + case GDK_exclamdown: + return VK_INVERTED_EXCLAMATION_MARK; + case GDK_parenleft: + return VK_LEFT_PARENTHESIS; + case GDK_numbersign: + return VK_NUMBER_SIGN; + case GDK_plus: + return VK_PLUS; + case GDK_parenright: + return VK_RIGHT_PARENTHESIS; + case GDK_underscore: + return VK_UNDERSCORE; + /* + return VK_FINAL; + return VK_CONVERT; + return VK_NONCONVERT; + return VK_ACCEPT; + */ + case GDK_Mode_switch: + return VK_MODECHANGE; + /* + return VK_KANA; + */ + case GDK_Kanji: + return VK_KANJI; + /* + return VK_ALPHANUMERIC; + */ + case GDK_Katakana: + return VK_KATAKANA; + case GDK_Hiragana: + return VK_HIRAGANA; + /* + return VK_FULL_WIDTH; + return VK_HALF_WIDTH; + return VK_ROMAN_CHARACTERS; + return VK_ALL_CANDIDATES; + */ + case GDK_PreviousCandidate: + return VK_PREVIOUS_CANDIDATE; + case GDK_Codeinput: + return VK_CODE_INPUT; + /* + return VK_JAPANESE_KATAKANA; + return VK_JAPANESE_HIRAGANA; + return VK_JAPANESE_ROMAN; + */ + case GDK_Kana_Lock: + return VK_KANA_LOCK; + /* + return VK_INPUT_METHOD_ON_OFF; + return VK_CUT; + return VK_COPY; + return VK_PASTE; + */ + case GDK_Undo: + return VK_UNDO; + case GDK_Redo: + return VK_AGAIN; + /* + return VK_FIND; + return VK_PROPS; + return VK_STOP; + return VK_COMPOSE; + */ + case GDK_ISO_Level3_Shift: + return VK_ALT_GRAPH; + /* + case VK_BEGIN: + */ + case GDK_Menu: + return VK_CONTEXT_MENU; + case GDK_Super_L: + case GDK_Super_R: + return VK_WINDOWS; + + default: + return VK_UNDEFINED; + } +} + +/* Return the AWT key location code for the given keysym or -1 if no + keyval was found for the given hardware keycode. */ +static jint +keysym_to_awt_keylocation (GdkEventKey *event) +{ + gint ukeyval; + + ukeyval = get_first_keyval_from_keymap (event); + + if (ukeyval < 0) + return -1; + + /* VK_A through VK_Z */ + if (ukeyval >= GDK_A && ukeyval <= GDK_Z) + return AWT_KEY_LOCATION_STANDARD; + + /* VK_0 through VK_9 */ + if (ukeyval >= GDK_0 && ukeyval <= GDK_9) + return AWT_KEY_LOCATION_STANDARD; + + switch (ukeyval) + { + case GDK_Shift_L: + case GDK_Control_L: + case GDK_Alt_L: + case GDK_Meta_L: + return AWT_KEY_LOCATION_LEFT; + + case GDK_Shift_R: + case GDK_Control_R: + case GDK_Alt_R: + case GDK_Meta_R: + return AWT_KEY_LOCATION_RIGHT; + + case GDK_Return: + case GDK_BackSpace: + case GDK_Tab: + case GDK_Cancel: + case GDK_Clear: + case GDK_Pause: + case GDK_Caps_Lock: + case GDK_Escape: + case GDK_space: + case GDK_Page_Up: + case GDK_Page_Down: + case GDK_End: + case GDK_Home: + case GDK_Left: + case GDK_Up: + case GDK_Right: + case GDK_Down: + case GDK_comma: + case GDK_minus: + case GDK_period: + case GDK_slash: + case GDK_semicolon: + case GDK_equal: + case GDK_bracketleft: + case GDK_backslash: + case GDK_bracketright: + case GDK_Delete: + case GDK_Scroll_Lock: + case GDK_F1: + case GDK_F2: + case GDK_F3: + case GDK_F4: + case GDK_F5: + case GDK_F6: + case GDK_F7: + case GDK_F8: + case GDK_F9: + case GDK_F10: + case GDK_F11: + case GDK_F12: + case GDK_F13: + case GDK_F14: + case GDK_F15: + case GDK_F16: + case GDK_F17: + case GDK_F18: + case GDK_F19: + case GDK_F20: + case GDK_F21: + case GDK_F22: + case GDK_F23: + case GDK_F24: + case GDK_Print: + case GDK_Insert: + case GDK_Help: + case GDK_grave: + case GDK_apostrophe: + case GDK_dead_grave: + case GDK_dead_acute: + case GDK_dead_circumflex: + case GDK_dead_tilde: + case GDK_dead_macron: + case GDK_dead_breve: + case GDK_dead_abovedot: + case GDK_dead_diaeresis: + case GDK_dead_abovering: + case GDK_dead_doubleacute: + case GDK_dead_caron: + case GDK_dead_cedilla: + case GDK_dead_ogonek: + case GDK_dead_iota: + case GDK_dead_voiced_sound: + case GDK_dead_semivoiced_sound: + case GDK_ampersand: + case GDK_asterisk: + case GDK_quotedbl: + case GDK_less: + case GDK_greater: + case GDK_braceleft: + case GDK_braceright: + case GDK_at: + case GDK_colon: + case GDK_asciicircum: + case GDK_dollar: + case GDK_EuroSign: + case GDK_exclam: + case GDK_exclamdown: + case GDK_parenleft: + case GDK_numbersign: + case GDK_plus: + case GDK_parenright: + case GDK_underscore: + case GDK_Mode_switch: + case GDK_Kanji: + case GDK_Katakana: + case GDK_Hiragana: + case GDK_PreviousCandidate: + case GDK_Codeinput: + case GDK_Kana_Lock: + return AWT_KEY_LOCATION_STANDARD; + + case GDK_KP_Enter: + case GDK_KP_Page_Up: + case GDK_KP_Page_Down: + case GDK_KP_End: + case GDK_KP_Home: + case GDK_KP_Begin: + case GDK_KP_0: + case GDK_KP_1: + case GDK_KP_2: + case GDK_KP_3: + case GDK_KP_4: + case GDK_KP_5: + case GDK_KP_6: + case GDK_KP_7: + case GDK_KP_8: + case GDK_KP_9: + case GDK_KP_Multiply: + case GDK_KP_Add: + case GDK_KP_Separator: + case GDK_KP_Subtract: + case GDK_KP_Decimal: + case GDK_KP_Divide: + case GDK_KP_Delete: + case GDK_Num_Lock: + case GDK_KP_Insert: + case GDK_KP_Up: + case GDK_KP_Down: + case GDK_KP_Left: + case GDK_KP_Right: + return AWT_KEY_LOCATION_NUMPAD; + + default: + return AWT_KEY_LOCATION_UNKNOWN; + } +} + +static jchar +keyevent_to_awt_keychar (GdkEventKey *event) +{ + if (event->length > 0) + { + /* Translate GDK carriage return to Java linefeed. */ + if (event->string[0] == 13) + return VK_ENTER; + else + return event->string[0]; + } + else + { + switch (event->keyval) + { + case GDK_BackSpace: + return VK_BACK_SPACE; + case GDK_Tab: + return VK_TAB; + case GDK_Delete: + case GDK_KP_Delete: + return VK_DELETE; + default: + return AWT_KEY_CHAR_UNDEFINED; + } + } +} + +/* Modifier key events need special treatment. In Sun's peer + implementation, when a modifier key is pressed, the KEY_PRESSED + event has that modifier in its modifiers list. The corresponding + KEY_RELEASED event's modifier list does not contain the modifier. + For example, pressing and releasing the shift key will produce a + key press event with modifiers=Shift, and a key release event with + no modifiers. GDK's key events behave in the exact opposite way, + so this translation code is needed. */ +static jint +keyevent_state_to_awt_mods (GdkEventKey *event) +{ + jint result = 0; + guint state; + + if (event->type == GDK_KEY_PRESS) + { + state = event->state; + + if (event->keyval == GDK_Shift_L + || event->keyval == GDK_Shift_R) + result |= AWT_SHIFT_DOWN_MASK | AWT_SHIFT_MASK; + else + { + if (state & GDK_SHIFT_MASK) + result |= AWT_SHIFT_DOWN_MASK | AWT_SHIFT_MASK; + } + + if (event->keyval == GDK_Control_L + || event->keyval == GDK_Control_R) + result |= AWT_CTRL_DOWN_MASK | AWT_CTRL_MASK; + else + { + if (state & GDK_CONTROL_MASK) + result |= AWT_CTRL_DOWN_MASK | AWT_CTRL_MASK; + } + + if (event->keyval == GDK_Alt_L + || event->keyval == GDK_Alt_R) + result |= AWT_ALT_DOWN_MASK | AWT_ALT_MASK; + else + { + if (state & GDK_MOD1_MASK) + result |= AWT_ALT_DOWN_MASK | AWT_ALT_MASK; + } + } + else if (event->type == GDK_KEY_RELEASE) + { + state = event->state; + + if (event->keyval != GDK_Shift_L + && event->keyval != GDK_Shift_R) + { + if (state & GDK_SHIFT_MASK) + result |= AWT_SHIFT_DOWN_MASK | AWT_SHIFT_MASK; + } + if (event->keyval != GDK_Control_L + && event->keyval != GDK_Control_R) + { + if (state & GDK_CONTROL_MASK) + result |= AWT_CTRL_DOWN_MASK | AWT_CTRL_MASK; + } + + if (event->keyval != GDK_Alt_L + && event->keyval != GDK_Alt_R) + { + if (state & GDK_MOD1_MASK) + result |= AWT_ALT_DOWN_MASK | AWT_ALT_MASK; + } + } + + return result; +} + +static gboolean window_configure_cb (GtkWidget *widget, + GdkEventConfigure *event, + jobject peer); + +/* FIXME: we're currently seeing the double-activation that occurs + with metacity and GTK. See + http://bugzilla.gnome.org/show_bug.cgi?id=140977 for details. */ + +static void window_get_frame_extents (GtkWidget *window, + int *top, int *left, + int *bottom, int *right); + +static void request_frame_extents (GtkWidget *window); + +static Bool property_notify_predicate (Display *display, + XEvent *xevent, + XPointer arg); + +static gboolean window_delete_cb (GtkWidget *widget, GdkEvent *event, + jobject peer); +static void window_destroy_cb (GtkWidget *widget, GdkEvent *event, + jobject peer); +static void window_focus_state_change_cb (GtkWidget *widget, + GParamSpec *pspec, + jobject peer); +static gboolean window_focus_in_cb (GtkWidget * widget, + GdkEventFocus *event, + jobject peer); +static gboolean window_focus_out_cb (GtkWidget * widget, + GdkEventFocus *event, + jobject peer); +static gboolean window_window_state_cb (GtkWidget *widget, + GdkEvent *event, + jobject peer); +static gboolean window_property_changed_cb (GtkWidget *widget, + GdkEventProperty *event, + jobject peer); +static void realize_cb (GtkWidget *widget, jobject peer); + +static gboolean +window_configure_cb (GtkWidget *widget __attribute__((unused)), + GdkEventConfigure *event, + jobject peer) +{ + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postConfigureEventID, + (jint) event->x, + (jint) event->y, + (jint) event->width, + (jint) event->height); + + return FALSE; +} + +static gboolean +key_press_cb (GtkWidget *widget __attribute__((unused)), + GdkEventKey *event, + jobject peer) +{ + jint keycode; + jint keylocation; + + keycode = keysym_to_awt_keycode (event); + keylocation = keysym_to_awt_keylocation (event); + + /* Return immediately if an error occurs translating a hardware + keycode to a keyval. */ + if (keycode < 0 || keylocation < 0) + return TRUE; + + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postKeyEventID, + (jint) AWT_KEY_PRESSED, + (jlong) event->time, + keyevent_state_to_awt_mods (event), + keycode, + keyevent_to_awt_keychar (event), + keylocation); + + /* FIXME: generation of key typed events needs to be moved + to GtkComponentPeer.postKeyEvent. If the key in a key + press event is not an "action" key + (KeyEvent.isActionKey) and is not a modifier key, then + it should generate a key typed event. */ + return TRUE; +} + + +static gboolean +key_release_cb (GtkWidget *widget __attribute__((unused)), + GdkEventKey *event, + jobject peer) +{ + jint keycode; + jint keylocation; + + keycode = keysym_to_awt_keycode (event); + keylocation = keysym_to_awt_keylocation (event); + + /* Return immediately if an error occurs translating a hardware + keycode to a keyval. */ + if (keycode < 0 || keylocation < 0) + return TRUE; + + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postKeyEventID, + (jint) AWT_KEY_RELEASED, + (jlong) event->time, + keyevent_state_to_awt_mods (event), + keycode, + keyevent_to_awt_keychar (event), + keylocation); + + return TRUE; +} + +/* Union used for type punning. */ +union extents_union +{ + guchar **gu_extents; + unsigned long **extents; +}; + +union atom_list_union +{ + guchar **gu_extents; + Atom **atom_list; +}; + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_create + (JNIEnv *env, jobject obj, jint type, jboolean decorated, jobject parent) +{ + GtkWidget *window_widget; + GtkWindow *window; + void *window_parent; + GtkWidget *fixed; + + gdk_threads_enter (); + + gtkpeer_set_global_ref (env, obj); + + window_widget = gtk_window_new (GTK_WINDOW_TOPLEVEL); + window = GTK_WINDOW (window_widget); + + /* Keep this window in front of its parent, if it has one. */ + if (parent) + { + window_parent = gtkpeer_get_widget (env, parent); + gtk_window_set_transient_for (window, GTK_WINDOW(window_parent)); + } + + gtk_window_set_decorated (window, decorated); + + gtk_window_set_type_hint (window, type); + + gtk_window_group_add_window (cp_gtk_global_window_group, window); + + fixed = gtk_fixed_new (); + + gtk_container_add (GTK_CONTAINER (window_widget), fixed); + + gtk_widget_show (fixed); + + gtkpeer_set_widget (env, obj, window_widget); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_gtkWindowSetTitle + (JNIEnv *env, jobject obj, jstring title) +{ + const char *c_title; + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + c_title = (*env)->GetStringUTFChars (env, title, NULL); + + gtk_window_set_title (GTK_WINDOW (ptr), c_title); + + (*env)->ReleaseStringUTFChars (env, title, c_title); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_gtkWindowSetResizable + (JNIEnv *env, jobject obj, jboolean resizable) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + gtk_window_set_resizable (GTK_WINDOW (ptr), resizable); + g_object_set (G_OBJECT (ptr), "allow-shrink", resizable, NULL); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_gtkWindowSetModal + (JNIEnv *env, jobject obj, jboolean modal) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + gtk_window_set_modal (GTK_WINDOW (ptr), modal); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_gtkWindowSetAlwaysOnTop + (JNIEnv *env, jobject obj, jboolean alwaysOnTop) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + gtk_window_set_keep_above (GTK_WINDOW (ptr), alwaysOnTop); + + gdk_threads_leave (); +} + +JNIEXPORT jboolean JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_gtkWindowHasFocus +(JNIEnv *env, jobject obj) +{ + void *ptr; + jboolean retval; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + retval = gtk_window_has_toplevel_focus (GTK_WINDOW (ptr)); + + gdk_threads_leave (); + return retval; +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_setVisibleNative + (JNIEnv *env, jobject obj, jboolean visible) +{ + gdk_threads_enter (); + + Java_gnu_java_awt_peer_gtk_GtkWindowPeer_setVisibleNativeUnlocked + (env, obj, visible); + + gdk_flush (); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_setVisibleNativeUnlocked + (JNIEnv *env, jobject obj, jboolean visible) +{ + void *ptr; + + ptr = gtkpeer_get_widget (env, obj); + + if (visible) + gtk_widget_show (GTK_WIDGET (ptr)); + else + gtk_widget_hide (GTK_WIDGET (ptr)); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_connectSignals + (JNIEnv *env, jobject obj) +{ + void *ptr; + jobject gref; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + gref = (jobject) gtkpeer_get_global_ref (env, obj); + + g_signal_connect (G_OBJECT (ptr), "delete-event", + G_CALLBACK (window_delete_cb), gref); + + g_signal_connect (G_OBJECT (ptr), "destroy-event", + G_CALLBACK (window_destroy_cb), gref); + + g_signal_connect (G_OBJECT (ptr), "notify::has-toplevel-focus", + G_CALLBACK (window_focus_state_change_cb), gref); + + g_signal_connect (G_OBJECT (ptr), "focus-in-event", + G_CALLBACK (window_focus_in_cb), gref); + + g_signal_connect (G_OBJECT (ptr), "focus-out-event", + G_CALLBACK (window_focus_out_cb), gref); + + g_signal_connect (G_OBJECT (ptr), "window-state-event", + G_CALLBACK (window_window_state_cb), gref); + + g_signal_connect (G_OBJECT (ptr), "property-notify-event", + G_CALLBACK (window_property_changed_cb), gref); + + g_signal_connect_after (G_OBJECT (ptr), "realize", + G_CALLBACK (realize_cb), gref); + + g_signal_connect (G_OBJECT (ptr), "key-press-event", + G_CALLBACK (key_press_cb), gref); + + g_signal_connect (G_OBJECT (ptr), "key-release-event", + G_CALLBACK (key_release_cb), gref); + + g_signal_connect_after (G_OBJECT (ptr), "window-state-event", + G_CALLBACK (window_window_state_cb), gref); + + g_signal_connect (G_OBJECT (ptr), "configure-event", + G_CALLBACK (window_configure_cb), gref); + + cp_gtk_component_connect_expose_signals (ptr, gref); + cp_gtk_component_connect_mouse_signals (ptr, gref); + + /* FIXME: override focus signals here to prevent child fixed repaint? */ + + gdk_threads_leave (); +} + +/* Realize the window here so that its frame extents are known now. + That way Window.pack can operate with the accurate insets returned + by the window manager rather than the default estimates. */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_realize (JNIEnv *env, jobject obj) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + gtk_widget_realize (GTK_WIDGET (ptr)); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_toBack (JNIEnv *env, + jobject obj) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + gdk_window_lower (GTK_WIDGET (ptr)->window); + gdk_flush (); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_toFront (JNIEnv *env, + jobject obj) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + gdk_window_raise (GTK_WIDGET (ptr)->window); + gdk_flush (); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_setSize + (JNIEnv *env, jobject obj, jint width, jint height) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = gtkpeer_get_widget (env, obj); + + /* Avoid GTK runtime assertion failures. */ + width = (width < 1) ? 1 : width; + height = (height < 1) ? 1 : height; + + gtk_widget_set_size_request (GTK_WIDGET(ptr), width, height); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_nativeSetBounds + (JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height) +{ + gdk_threads_enter (); + + Java_gnu_java_awt_peer_gtk_GtkWindowPeer_nativeSetBoundsUnlocked + (env, obj, x, y, width, height); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_nativeSetLocationUnlocked + (JNIEnv *env, jobject obj, jint x, jint y) +{ + void *ptr; + + ptr = gtkpeer_get_widget (env, obj); + + gtk_window_move (GTK_WINDOW(ptr), x, y); + + if (GTK_WIDGET (ptr)->window != NULL) + gdk_window_move (GTK_WIDGET (ptr)->window, x, y); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_nativeSetLocation + (JNIEnv *env, jobject obj, jint x, jint y) +{ + gdk_threads_enter (); + + Java_gnu_java_awt_peer_gtk_GtkWindowPeer_nativeSetLocationUnlocked + (env, obj, x, y); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_nativeSetBoundsUnlocked + (JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height) +{ + void *ptr; + gint current_width; + gint current_height; + + ptr = gtkpeer_get_widget (env, obj); + + /* Avoid GTK runtime assertion failures. */ + width = (width < 1) ? 1 : width; + height = (height < 1) ? 1 : height; + + gtk_window_move (GTK_WINDOW(ptr), x, y); + /* The call to gdk_window_move is needed in addition to the call to + gtk_window_move. If gdk_window_move isn't called, then the + following set of operations doesn't give the expected results: + + 1. show a window + 2. manually move it to another position on the screen + 3. hide the window + 4. reposition the window with Component.setLocation + 5. show the window + + Instead of being at the position set by setLocation, the window + is reshown at the position to which it was moved manually. */ + if (GTK_WIDGET (ptr)->window != NULL) + gdk_window_move (GTK_WIDGET (ptr)->window, x, y); + + /* Only request resizing if the actual width or height change, otherwise + * we get unnecessary flickers because resizing causes GTK to clear the + * window content, even if the actual size doesn't change. */ + gtk_window_get_size(GTK_WINDOW(ptr), ¤t_width, ¤t_height); + if (current_width != width || current_height != height) + { + /* Need to change the widget's request size. */ + gtk_widget_set_size_request (GTK_WIDGET(ptr), width, height); + /* Also need to call gtk_window_resize. If the resize is requested + by the program and the window's "resizable" property is true then + the size request will not be honoured. */ + gtk_window_resize (GTK_WINDOW (ptr), width, height); + } +} + +static void +window_get_frame_extents (GtkWidget *window, + int *top, int *left, int *bottom, int *right) +{ + unsigned long *extents = NULL; + union extents_union gu_ex; + + /* Guess frame extents in case _NET_FRAME_EXTENTS is not + supported. */ + if (!gtk_window_get_decorated (GTK_WINDOW (window))) + { + *top = 0; + *left = 0; + *bottom = 0; + *right = 0; + + return; + } + + *top = 23; + *left = 6; + *bottom = 6; + *right = 6; + + /* Request that the window manager set window's + _NET_FRAME_EXTENTS property. */ + request_frame_extents (window); + + /* Attempt to retrieve window's frame extents. */ + gu_ex.extents = &extents; + if (gdk_property_get (window->window, + gdk_atom_intern ("_NET_FRAME_EXTENTS", FALSE), + gdk_atom_intern ("CARDINAL", FALSE), + 0, + sizeof (unsigned long) * 4, + FALSE, + NULL, + NULL, + NULL, + gu_ex.gu_extents)) + { + *left = extents [0]; + *right = extents [1]; + *top = extents [2]; + *bottom = extents [3]; + } +} + +static Atom extents_atom = 0; + +/* Requests that the window manager set window's + _NET_FRAME_EXTENTS property. */ +static void +request_frame_extents (GtkWidget *window) +{ + const char *request_str = "_NET_REQUEST_FRAME_EXTENTS"; + GdkAtom request_extents = gdk_atom_intern (request_str, FALSE); + + /* Check if the current window manager supports + _NET_REQUEST_FRAME_EXTENTS. */ + if (gdk_net_wm_supports (request_extents)) + { + GdkDisplay *display = gtk_widget_get_display (window); + Display *xdisplay = GDK_DISPLAY_XDISPLAY (display); + + GdkWindow *root_window = gdk_get_default_root_window (); + Window xroot_window = GDK_WINDOW_XID (root_window); + + Atom extents_request_atom = + gdk_x11_get_xatom_by_name_for_display (display, request_str); + + XEvent xevent; + XEvent notify_xevent; + + unsigned long window_id = GDK_WINDOW_XID (GDK_DRAWABLE(window->window)); + + if (!extents_atom) + { + const char *extents_str = "_NET_FRAME_EXTENTS"; + extents_atom = + gdk_x11_get_xatom_by_name_for_display (display, extents_str); + } + + xevent.xclient.type = ClientMessage; + xevent.xclient.message_type = extents_request_atom; + xevent.xclient.display = xdisplay; + xevent.xclient.window = window_id; + xevent.xclient.format = 32; + xevent.xclient.data.l[0] = 0; + xevent.xclient.data.l[1] = 0; + xevent.xclient.data.l[2] = 0; + xevent.xclient.data.l[3] = 0; + xevent.xclient.data.l[4] = 0; + + XSendEvent (xdisplay, xroot_window, False, + (SubstructureRedirectMask | SubstructureNotifyMask), + &xevent); + + XIfEvent(xdisplay, ¬ify_xevent, + property_notify_predicate, (XPointer) &window_id); + } +} + +static Bool +property_notify_predicate (Display *xdisplay __attribute__((unused)), + XEvent *event, + XPointer window_id) +{ + unsigned long *window = (unsigned long *) window_id; + + if (event->xany.type == PropertyNotify + && event->xany.window == *window + && event->xproperty.atom == extents_atom) + return True; + else + return False; +} + +static gboolean +window_delete_cb (GtkWidget *widget __attribute__((unused)), + GdkEvent *event __attribute__((unused)), + jobject peer) +{ + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postWindowEventID, + (jint) AWT_WINDOW_CLOSING, + (jobject) NULL, (jint) 0); + + /* Prevents that the Window dissappears ("destroy" + not being signalled). This is necessary because it + should be up to a WindowListener implementation + how the AWT Frame responds to close requests. */ + return TRUE; +} + +static void +window_destroy_cb (GtkWidget *widget __attribute__((unused)), + GdkEvent *event __attribute__((unused)), + jobject peer) +{ + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postWindowEventID, + (jint) AWT_WINDOW_CLOSED, + (jobject) NULL, (jint) 0); +} + +static void +window_focus_state_change_cb (GtkWidget *widget, + GParamSpec *pspec __attribute__((unused)), + jobject peer) +{ + if (GTK_WINDOW (widget)->has_toplevel_focus) + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postWindowEventID, + (jint) AWT_WINDOW_ACTIVATED, + (jobject) NULL, (jint) 0); + else + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postWindowEventID, + (jint) AWT_WINDOW_DEACTIVATED, + (jobject) NULL, (jint) 0); +} + +static gboolean +window_focus_in_cb (GtkWidget * widget __attribute__((unused)), + GdkEventFocus *event __attribute__((unused)), + jobject peer) +{ + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postWindowEventID, + (jint) AWT_WINDOW_GAINED_FOCUS, + (jobject) NULL, (jint) 0); + + return FALSE; +} + +static gboolean +window_focus_out_cb (GtkWidget * widget __attribute__((unused)), + GdkEventFocus *event __attribute__((unused)), + jobject peer) +{ + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postWindowEventID, + (jint) AWT_WINDOW_LOST_FOCUS, + (jobject) NULL, (jint) 0); + + return FALSE; +} + +static gboolean +window_window_state_cb (GtkWidget *widget __attribute__((unused)), + GdkEvent *event, + jobject peer) +{ + jint new_java_state = 0; + /* Put together the new state and let the java side figure out what + * to post */ + GdkWindowState new_state = event->window_state.new_window_state; + /* The window can be either iconfified, maximized, iconified + maximized + * or normal. */ + if ((new_state & GDK_WINDOW_STATE_ICONIFIED) != 0) + new_java_state |= AWT_FRAME_ICONIFIED; + if ((new_state & GDK_WINDOW_STATE_MAXIMIZED) != 0) + new_java_state |= AWT_FRAME_MAXIMIZED_BOTH; + if ((new_state & (GDK_WINDOW_STATE_MAXIMIZED | GDK_WINDOW_STATE_ICONIFIED)) + == 0) + new_java_state = AWT_FRAME_NORMAL; + + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postWindowEventID, + (jint) AWT_WINDOW_STATE_CHANGED, + (jobject) NULL, new_java_state); + + return TRUE; +} + +static gboolean +window_property_changed_cb (GtkWidget *widget __attribute__((unused)), + GdkEventProperty *event, + jobject peer) +{ + unsigned long *extents; + union extents_union gu_ex; + + gu_ex.extents = &extents; + if (gdk_atom_intern ("_NET_FRAME_EXTENTS", FALSE) == event->atom + && gdk_property_get (event->window, + gdk_atom_intern ("_NET_FRAME_EXTENTS", FALSE), + gdk_atom_intern ("CARDINAL", FALSE), + 0, + sizeof (unsigned long) * 4, + FALSE, + NULL, + NULL, + NULL, + gu_ex.gu_extents)) + { + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postInsetsChangedEventID, + (jint) extents[2], /* top */ + (jint) extents[0], /* left */ + (jint) extents[3], /* bottom */ + (jint) extents[1]); /* right */ + } + + + return FALSE; +} + +static void +realize_cb (GtkWidget *widget, jobject peer) +{ + jint top = 0; + jint left = 0; + jint bottom = 0; + jint right = 0; + jint width = 0; + jint height = 0; + + width = (*cp_gtk_gdk_env())->CallIntMethod (cp_gtk_gdk_env(), peer, windowGetWidthID); + height = (*cp_gtk_gdk_env())->CallIntMethod (cp_gtk_gdk_env(), peer, windowGetHeightID); + + window_get_frame_extents (widget, &top, &left, &bottom, &right); + + (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, + postInsetsChangedEventID, + top, left, bottom, right); + + gtk_window_set_default_size (GTK_WINDOW (widget), + MAX (1, width - left - right), + MAX (1, height - top - bottom)); + + /* set the size like we do in nativeSetBounds */ + gtk_widget_set_size_request (widget, + MAX (1, width - left - right), + MAX (1, height - top - bottom)); + + gtk_window_resize (GTK_WINDOW (widget), + MAX (1, width - left - right), + MAX (1, height - top - bottom)); +} + +/* + * This method returns a GDK keyval that corresponds to one of the + * keysyms in the X keymap table. The return value is only used to + * determine the keyval's corresponding hardware keycode, and doesn't + * reflect an accurate translation of a Java virtual key value to a + * GDK keyval. + */ +#ifdef __GNUC__ +__inline +#endif +guint +cp_gtk_awt_keycode_to_keysym (jint keyCode, jint keyLocation) +{ + /* GDK_A through GDK_Z */ + if (keyCode >= VK_A && keyCode <= VK_Z) + return gdk_keyval_to_lower (keyCode); + + /* GDK_0 through GDK_9 */ + if (keyCode >= VK_0 && keyCode <= VK_9) + return keyCode; + + switch (keyCode) + { + case VK_ENTER: + return keyLocation == AWT_KEY_LOCATION_NUMPAD ? GDK_KP_Enter : GDK_Return; + case VK_BACK_SPACE: + return GDK_BackSpace; + case VK_TAB: + return GDK_Tab; + case VK_CANCEL: + return GDK_Cancel; + case VK_CLEAR: + return GDK_Clear; + case VK_SHIFT: + return keyLocation == AWT_KEY_LOCATION_LEFT ? GDK_Shift_L : GDK_Shift_R; + case VK_CONTROL: + return keyLocation == AWT_KEY_LOCATION_LEFT ? GDK_Control_L : GDK_Control_R; + case VK_ALT: + return keyLocation == AWT_KEY_LOCATION_LEFT ? GDK_Alt_L : GDK_Alt_R; + case VK_PAUSE: + return GDK_Pause; + case VK_CAPS_LOCK: + return GDK_Caps_Lock; + case VK_ESCAPE: + return GDK_Escape; + case VK_SPACE: + return GDK_space; + case VK_PAGE_UP: + return keyLocation == AWT_KEY_LOCATION_NUMPAD ? GDK_KP_Page_Up : GDK_Page_Up; + case VK_PAGE_DOWN: + return keyLocation == AWT_KEY_LOCATION_NUMPAD ? GDK_KP_Page_Down : GDK_Page_Down; + case VK_END: + return keyLocation == AWT_KEY_LOCATION_NUMPAD ? GDK_KP_End : GDK_End; + case VK_HOME: + return keyLocation == AWT_KEY_LOCATION_NUMPAD ? GDK_KP_Home : GDK_Home; + case VK_LEFT: + return GDK_Left; + case VK_UP: + return GDK_Up; + case VK_RIGHT: + return GDK_Right; + case VK_DOWN: + return GDK_Down; + case VK_COMMA: + return GDK_comma; + case VK_MINUS: + return GDK_minus; + case VK_PERIOD: + return GDK_period; + case VK_SLASH: + return GDK_slash; + /* + case VK_0: + case VK_1: + case VK_2: + case VK_3: + case VK_4: + case VK_5: + case VK_6: + case VK_7: + case VK_8: + case VK_9: + */ + case VK_SEMICOLON: + return GDK_semicolon; + case VK_EQUALS: + return GDK_equal; + /* + case VK_A: + case VK_B: + case VK_C: + case VK_D: + case VK_E: + case VK_F: + case VK_G: + case VK_H: + case VK_I: + case VK_J: + case VK_K: + case VK_L: + case VK_M: + case VK_N: + case VK_O: + case VK_P: + case VK_Q: + case VK_R: + case VK_S: + case VK_T: + case VK_U: + case VK_V: + case VK_W: + case VK_X: + case VK_Y: + case VK_Z: + */ + case VK_OPEN_BRACKET: + return GDK_bracketleft; + case VK_BACK_SLASH: + return GDK_backslash; + case VK_CLOSE_BRACKET: + return GDK_bracketright; + case VK_NUMPAD0: + return GDK_KP_0; + case VK_NUMPAD1: + return GDK_KP_1; + case VK_NUMPAD2: + return GDK_KP_2; + case VK_NUMPAD3: + return GDK_KP_3; + case VK_NUMPAD4: + return GDK_KP_4; + case VK_NUMPAD5: + return GDK_KP_5; + case VK_NUMPAD6: + return GDK_KP_6; + case VK_NUMPAD7: + return GDK_KP_7; + case VK_NUMPAD8: + return GDK_KP_8; + case VK_NUMPAD9: + return GDK_KP_9; + case VK_MULTIPLY: + return GDK_KP_Multiply; + case VK_ADD: + return GDK_KP_Add; + /* + case VK_SEPARATER: + */ + case VK_SEPARATOR: + return GDK_KP_Separator; + case VK_SUBTRACT: + return GDK_KP_Subtract; + case VK_DECIMAL: + return GDK_KP_Decimal; + case VK_DIVIDE: + return GDK_KP_Divide; + case VK_DELETE: + return keyLocation == AWT_KEY_LOCATION_NUMPAD ? GDK_KP_Delete : GDK_Delete; + case VK_NUM_LOCK: + return GDK_Num_Lock; + case VK_SCROLL_LOCK: + return GDK_Scroll_Lock; + case VK_F1: + return GDK_F1; + case VK_F2: + return GDK_F2; + case VK_F3: + return GDK_F3; + case VK_F4: + return GDK_F4; + case VK_F5: + return GDK_F5; + case VK_F6: + return GDK_F6; + case VK_F7: + return GDK_F7; + case VK_F8: + return GDK_F8; + case VK_F9: + return GDK_F9; + case VK_F10: + return GDK_F10; + case VK_F11: + return GDK_F11; + case VK_F12: + return GDK_F12; + case VK_F13: + return GDK_F13; + case VK_F14: + return GDK_F14; + case VK_F15: + return GDK_F15; + case VK_F16: + return GDK_F16; + case VK_F17: + return GDK_F17; + case VK_F18: + return GDK_F18; + case VK_F19: + return GDK_F19; + case VK_F20: + return GDK_F20; + case VK_F21: + return GDK_F21; + case VK_F22: + return GDK_F22; + case VK_F23: + return GDK_F23; + case VK_F24: + return GDK_F24; + case VK_PRINTSCREEN: + return GDK_Print; + case VK_INSERT: + return keyLocation == AWT_KEY_LOCATION_NUMPAD ? GDK_KP_Insert : GDK_Insert; + case VK_HELP: + return GDK_Help; + case VK_META: + return keyLocation == AWT_KEY_LOCATION_LEFT ? GDK_Meta_L : GDK_Meta_R; + case VK_BACK_QUOTE: + return GDK_grave; + case VK_QUOTE: + return GDK_apostrophe; + case VK_KP_UP: + return GDK_KP_Up; + case VK_KP_DOWN: + return GDK_KP_Down; + case VK_KP_LEFT: + return GDK_KP_Left; + case VK_KP_RIGHT: + return GDK_KP_Right; + case VK_DEAD_GRAVE: + return GDK_dead_grave; + case VK_DEAD_ACUTE: + return GDK_dead_acute; + case VK_DEAD_CIRCUMFLEX: + return GDK_dead_circumflex; + case VK_DEAD_TILDE: + return GDK_dead_tilde; + case VK_DEAD_MACRON: + return GDK_dead_macron; + case VK_DEAD_BREVE: + return GDK_dead_breve; + case VK_DEAD_ABOVEDOT: + return GDK_dead_abovedot; + case VK_DEAD_DIAERESIS: + return GDK_dead_diaeresis; + case VK_DEAD_ABOVERING: + return GDK_dead_abovering; + case VK_DEAD_DOUBLEACUTE: + return GDK_dead_doubleacute; + case VK_DEAD_CARON: + return GDK_dead_caron; + case VK_DEAD_CEDILLA: + return GDK_dead_cedilla; + case VK_DEAD_OGONEK: + return GDK_dead_ogonek; + case VK_DEAD_IOTA: + return GDK_dead_iota; + case VK_DEAD_VOICED_SOUND: + return GDK_dead_voiced_sound; + case VK_DEAD_SEMIVOICED_SOUND: + return GDK_dead_semivoiced_sound; + case VK_AMPERSAND: + return GDK_ampersand; + case VK_ASTERISK: + return GDK_asterisk; + case VK_QUOTEDBL: + return GDK_quotedbl; + case VK_LESS: + return GDK_less; + case VK_GREATER: + return GDK_greater; + case VK_BRACELEFT: + return GDK_braceleft; + case VK_BRACERIGHT: + return GDK_braceright; + case VK_AT: + return GDK_at; + case VK_COLON: + return GDK_colon; + case VK_CIRCUMFLEX: + return GDK_asciicircum; + case VK_DOLLAR: + return GDK_dollar; + case VK_EURO_SIGN: + return GDK_EuroSign; + case VK_EXCLAMATION_MARK: + return GDK_exclam; + case VK_INVERTED_EXCLAMATION_MARK: + return GDK_exclamdown; + case VK_LEFT_PARENTHESIS: + return GDK_parenleft; + case VK_NUMBER_SIGN: + return GDK_numbersign; + case VK_PLUS: + return GDK_plus; + case VK_RIGHT_PARENTHESIS: + return GDK_parenright; + case VK_UNDERSCORE: + return GDK_underscore; + /* + case VK_FINAL: + case VK_CONVERT: + case VK_NONCONVERT: + case VK_ACCEPT: + */ + case VK_MODECHANGE: + return GDK_Mode_switch; + /* + case VK_KANA: + */ + case VK_KANJI: + return GDK_Kanji; + /* + case VK_ALPHANUMERIC: + */ + case VK_KATAKANA: + return GDK_Katakana; + case VK_HIRAGANA: + return GDK_Hiragana; + /* + case VK_FULL_WIDTH: + case VK_HALF_WIDTH: + case VK_ROMAN_CHARACTERS: + case VK_ALL_CANDIDATES: + */ + case VK_PREVIOUS_CANDIDATE: + return GDK_PreviousCandidate; + case VK_CODE_INPUT: + return GDK_Codeinput; + /* + case VK_JAPANESE_KATAKANA: + case VK_JAPANESE_HIRAGANA: + case VK_JAPANESE_ROMAN: + */ + case VK_KANA_LOCK: + return GDK_Kana_Lock; + /* + case VK_INPUT_METHOD_ON_OFF: + case VK_CUT: + case VK_COPY: + case VK_PASTE: + */ + case VK_UNDO: + return GDK_Undo; + case VK_AGAIN: + return GDK_Redo; + /* + case VK_FIND: + case VK_PROPS: + case VK_STOP: + case VK_COMPOSE: + */ + case VK_ALT_GRAPH: + return GDK_ISO_Level3_Shift; + /* + case VK_BEGIN: + */ + case VK_CONTEXT_MENU: + return GDK_Menu; + case VK_WINDOWS: + return GDK_Super_R; + + default: + return GDK_VoidSymbol; + } +} diff --git a/libjava/classpath/native/jni/gtk-peer/gtk_jawt.c b/libjava/classpath/native/jni/gtk-peer/gtk_jawt.c new file mode 100644 index 000000000..72130376f --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gtk_jawt.c @@ -0,0 +1,203 @@ +/* gtk_jawt.c -- GTK implementation of classpath_jawt.h + Copyright (C) 2005 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + + +#include "gtkpeer.h" +#include +#include +#include "classpath_jawt.h" + +jint +classpath_jawt_get_awt_version () +{ + return CLASSPATH_JAWT_VERSION; +} + +/* Does not require locking: meant to be called after the drawing + surface is locked. */ +Display* +classpath_jawt_get_default_display (JNIEnv* env, jobject canvas) +{ + GdkDisplay *display; + Display *xdisplay; + GtkWidget *widget; + void *ptr; + jobject peer; + jclass class_id; + jmethodID method_id; + + /* retrieve peer object */ + class_id = (*env)->GetObjectClass (env, canvas); + + method_id = (*env)->GetMethodID (env, class_id, + "getPeer", + "()Ljava/awt/peer/ComponentPeer;"); + + peer = (*env)->CallObjectMethod (env, canvas, method_id); + + ptr = gtkpeer_get_widget (env, peer); + + widget = GTK_WIDGET (ptr); + + if (GTK_WIDGET_REALIZED (widget)) + { + display = gtk_widget_get_display (widget); + + xdisplay = GDK_DISPLAY_XDISPLAY (display); + + return xdisplay; + } + else + return NULL; +} + +/* Does not require locking: meant to be called after the drawing + surface is locked. */ +VisualID +classpath_jawt_get_visualID (JNIEnv* env, jobject canvas) +{ + GtkWidget *widget; + Visual *visual; + void *ptr; + jobject peer; + jclass class_id; + jmethodID method_id; + + class_id = (*env)->GetObjectClass (env, canvas); + + method_id = (*env)->GetMethodID (env, class_id, + "getPeer", + "()Ljava/awt/peer/ComponentPeer;"); + + peer = (*env)->CallObjectMethod (env, canvas, method_id); + + ptr = gtkpeer_get_widget (env, peer); + + widget = GTK_WIDGET (ptr); + + if (GTK_WIDGET_REALIZED (widget)) + { + visual = gdk_x11_visual_get_xvisual (gtk_widget_get_visual (widget)); + g_assert (visual != NULL); + + return visual->visualid; + } + else + return (VisualID) NULL; +} + +/* Does not require locking: meant to be called after the drawing + surface is locked. */ +int +classpath_jawt_get_depth (JNIEnv* env, jobject canvas) +{ + GtkWidget *widget; + GdkVisual *visual; + void *ptr; + jobject peer; + jclass class_id; + jmethodID method_id; + + class_id = (*env)->GetObjectClass (env, canvas); + + method_id = (*env)->GetMethodID (env, class_id, + "getPeer", + "()Ljava/awt/peer/ComponentPeer;"); + + peer = (*env)->CallObjectMethod (env, canvas, method_id); + + ptr = gtkpeer_get_widget (env, peer); + + widget = GTK_WIDGET (ptr); + + if (GTK_WIDGET_REALIZED (widget)) + { + visual = gtk_widget_get_visual (widget); + g_assert (visual != NULL); + + return visual->depth; + } + else + return (VisualID) NULL; +} + +/* Does not require locking: meant to be called after the drawing + surface is locked. */ +Drawable +classpath_jawt_get_drawable (JNIEnv* env, jobject canvas) +{ + GtkWidget *widget; + int drawable; + void *ptr; + jobject peer; + jclass class_id; + jmethodID method_id; + + class_id = (*env)->GetObjectClass (env, canvas); + + method_id = (*env)->GetMethodID (env, class_id, + "getPeer", + "()Ljava/awt/peer/ComponentPeer;"); + + peer = (*env)->CallObjectMethod (env, canvas, method_id); + + ptr = gtkpeer_get_widget (env, peer); + + widget = GTK_WIDGET (ptr); + + if (GTK_WIDGET_REALIZED (widget)) + { + drawable = GDK_DRAWABLE_XID (widget->window); + + return drawable; + } + else + return (Drawable) NULL; +} + +jint +classpath_jawt_lock () +{ + gdk_threads_enter (); + return 0; +} + +void +classpath_jawt_unlock () +{ + gdk_threads_leave (); +} diff --git a/libjava/classpath/native/jni/gtk-peer/gtkpeer.c b/libjava/classpath/native/jni/gtk-peer/gtkpeer.c new file mode 100644 index 000000000..b57626e94 --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gtkpeer.c @@ -0,0 +1,586 @@ +/* gtkpeer.c -- Some GTK peer specific helper functions + Copyright (C) 2007 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include "gtkpeer.h" +#include "jni.h" + +/** + * The Pointer class. + */ +static jclass pointerClass; + +/** + * The Pointer constructor. + */ +static jmethodID pointerConstructorMID; + +/** + * The field ID of the data field in the Pointer class. + */ +static jfieldID pointerDataFID; + +/** + * The field ID of the widget field in the GtkGenericPeer class. + */ +static jfieldID widgetFID; + +/** + * The field ID of the globalRef field in the GtkGenericPeer class. + */ +static jfieldID globalRefFID; + +/** + * The field ID of the display field in the GdkGraphicsEnvironment class. + */ +static jfieldID displayFID; + +/** + * The field ID of the screen field in the GdkScreenGraphicsDevice class. + */ +static jfieldID screenFID; + +/** + * The field ID of the nativeFont field in GdkFontPeer. + */ +static jfieldID fontFID; + +/** + * The field ID of the nativeDecoder field in GdkPixbufDecoder. + */ +static jfieldID pixbufLoaderFID; + +/** + * Initializes the IDs of the Pointer* classes. + * + * @param env the JNI environment + */ +void gtkpeer_init_pointer_IDs(JNIEnv* env) +{ +#if SIZEOF_VOID_P == 8 + pointerClass = (*env)->FindClass (env, "gnu/classpath/Pointer64"); + if (pointerClass != NULL) + { + pointerClass = (*env)->NewGlobalRef (env, pointerClass); + pointerDataFID = (*env)->GetFieldID (env, pointerClass, "data", "J"); + pointerConstructorMID = (*env)->GetMethodID (env, pointerClass, "", + "(J)V"); + } +#else +#if SIZEOF_VOID_P == 4 + pointerClass = (*env)->FindClass(env, "gnu/classpath/Pointer32"); + if (pointerClass != NULL) + { + pointerClass = (*env)->NewGlobalRef (env, pointerClass); + pointerDataFID = (*env)->GetFieldID (env, pointerClass, "data", "I"); + pointerConstructorMID = (*env)->GetMethodID (env, pointerClass, "", + "(I)V"); + } +#else +#error "Pointer size is not supported." +#endif /* SIZEOF_VOID_P == 4 */ +#endif /* SIZEOF_VOID_P == 8 */ +} + +/** + * Initializes the field IDs for the widget reference. + * + * @param env the JNI environment + */ +void gtkpeer_init_widget_IDs(JNIEnv *env) +{ + jclass cls; + + /* Find the widget field ID in GtkGenericPeer. */ + cls = (*env)->FindClass(env, "gnu/java/awt/peer/gtk/GtkGenericPeer"); + widgetFID = (*env)->GetFieldID(env, cls, "widget", + "Lgnu/classpath/Pointer;"); + + /* Find the globalRef field in GtkGenericPeer. */ + globalRefFID = (*env)->GetFieldID(env, cls, "globalRef", + "Lgnu/classpath/Pointer;"); +} + +/** + * Stores the GTK widget reference in the GtkGenericPeer object. + * + * @param env the JNI environment + * @param peer the actual peer object + * @param widget the widget reference to store + */ +void gtkpeer_set_widget(JNIEnv *env, jobject peer, void *widget) +{ + jobject obj; + + /* Fetch the widget field object. */ + obj = (*env)->GetObjectField(env, peer, widgetFID); + if (obj == NULL) + { + /* Create if necessary. */ +#if SIZEOF_VOID_P == 8 + obj = (*env)->NewObject(env, pointerClass, pointerConstructorMID, + (jlong) widget); +#else + obj = (*env)->NewObject(env, pointerClass, pointerConstructorMID, + (jint) widget); +#endif + (*env)->SetObjectField(env, peer, widgetFID, obj); + } + else + { +#if SIZEOF_VOID_P == 8 + (*env)->SetLongField(env, obj, pointerDataFID, (jlong) widget); +#else + (*env)->SetIntField(env, obj, pointerDataFID, (jint) widget); +#endif + } +} + +/** + * Retrieves the GTK widget reference from a GtkGenericPeer object. + * + * @param env the JNI environment + * @param peer the actual peer object + * + * @return the widget reference + */ +void* gtkpeer_get_widget(JNIEnv *env, jobject peer) +{ + jobject obj; + void *widget; + + /* Fetch the widget field from the peer object. */ + obj = (*env)->GetObjectField(env, peer, widgetFID); + + /* Fetch actual widget pointer. */ +#if SIZEOF_VOID_P == 8 + widget = (void*) (*env)->GetLongField(env, obj, pointerDataFID); +#else + widget = (void*) (*env)->GetIntField(env, obj, pointerDataFID); +#endif + return widget; +} + + +/** + * Stores the global JNI reference of a peer inside the peer. + * + * @param env the JNI environment + * @param peer the peer object + */ +void gtkpeer_set_global_ref(JNIEnv *env, jobject peer) +{ + jobject obj; + void* globalRef; + + /* Create global reference. */ + globalRef = (*env)->NewGlobalRef(env, peer); + + /* Fetch the globalRef field object. */ + obj = (*env)->GetObjectField(env, peer, globalRefFID); + if (obj == NULL) + { + /* Create if necessary. */ +#if SIZEOF_VOID_P == 8 + obj = (*env)->NewObject(env, pointerClass, pointerConstructorMID, + (jlong) globalRef); +#else + obj = (*env)->NewObject(env, pointerClass, pointerConstructorMID, + (jint) globalRef); +#endif + (*env)->SetObjectField(env, peer, globalRefFID, obj); + } + else + { +#if SIZEOF_VOID_P == 8 + (*env)->SetLongField(env, obj, pointerDataFID, (jlong) globalRef); +#else + (*env)->SetIntField(env, obj, pointerDataFID, (jint) globalRef); +#endif + } +} + +/** + * Retrieves the global reference from a peer. + * + * @param env the JNI environment + * @param peer the peer object + * + * @return the global reference + */ +void* gtkpeer_get_global_ref(JNIEnv *env, jobject peer) +{ + jobject obj; + void *globalRef; + + /* Fetch the globalRef field from the peer object. */ + obj = (*env)->GetObjectField(env, peer, globalRefFID); + + /* Fetch actual globalRef pointer. */ +#if SIZEOF_VOID_P == 8 + globalRef = (void*) (*env)->GetLongField(env, obj, pointerDataFID); +#else + globalRef = (void*) (*env)->GetIntField(env, obj, pointerDataFID); +#endif + return globalRef; +} + +/** + * Deletes the global reference of a peer. This is necessary in order to + * allow the peer to be garbage collected. + * + * @param env the JNI environment + * @param peer the peer object. + */ +void gtkpeer_del_global_ref(JNIEnv* env, jobject peer) +{ + jobject obj; + void *globalRef; + + /* Fetch the globalRef field from the peer object. */ + obj = (*env)->GetObjectField(env, peer, globalRefFID); + + /* Fetch actual globalRef pointer. */ +#if SIZEOF_VOID_P == 8 + globalRef = (void*) (*env)->GetLongField(env, obj, pointerDataFID); +#else + globalRef = (void*) (*env)->GetIntField(env, obj, pointerDataFID); +#endif + (*env)->DeleteGlobalRef(env, globalRef); +} + +/** + * Initializes the fieldIDs for the display and screen fields. + * + * @param env the JNI environment + */ +void gtkpeer_init_display_IDs(JNIEnv* env) +{ + jclass cls; + + /* Find the display field ID in GdkGraphicsEnvironment. */ + cls = (*env)->FindClass(env, "gnu/java/awt/peer/gtk/GdkGraphicsEnvironment"); + displayFID = (*env)->GetFieldID(env, cls, "display", + "Lgnu/classpath/Pointer;"); +} + +/** + * Sets the native display pointer in the GdkGraphicsEnvironment object. + * + * @param env the JNI environment + * @param graphicsenv the GdkGraphicsEnvironment object + * @param display the native display pointer + */ +void gtkpeer_set_display(JNIEnv* env, jobject graphicsenv, void* display) +{ + jobject obj; + + /* Fetch the display field object. */ + obj = (*env)->GetObjectField(env, graphicsenv, displayFID); + if (obj == NULL) + { + /* Create if necessary. */ +#if SIZEOF_VOID_P == 8 + obj = (*env)->NewObject(env, pointerClass, pointerConstructorMID, + (jlong) display); +#else + obj = (*env)->NewObject(env, pointerClass, pointerConstructorMID, + (jint) display); +#endif + (*env)->SetObjectField(env, graphicsenv, displayFID, obj); + } + else + { +#if SIZEOF_VOID_P == 8 + (*env)->SetLongField(env, obj, pointerDataFID, (jlong) display); +#else + (*env)->SetIntField(env, obj, pointerDataFID, (jint) display); +#endif + } +} + +/** + * Fetches the native display pointer from the GdkGraphicsEnvironment object. + * + * @param env the JNI environment + * @param graphicsenv the GdkGraphicsEnvironment object + * + * @return the native display pointer + */ +void* gtkpeer_get_display(JNIEnv* env, jobject graphicsenv) +{ + jobject obj; + void *display; + + /* Fetch the display field from the peer object. */ + obj = (*env)->GetObjectField(env, graphicsenv, displayFID); + + /* Fetch actual display pointer. */ +#if SIZEOF_VOID_P == 8 + display = (void*) (*env)->GetLongField(env, obj, pointerDataFID); +#else + display = (void*) (*env)->GetIntField(env, obj, pointerDataFID); +#endif + return display; +} + +/** + * Initializes the fieldIDs for the screen field. + * + * @param env the JNI environment + */ +void gtkpeer_init_screen_IDs(JNIEnv* env) +{ + jclass cls; + + /* Find the display field ID in GdkScreenGraphicsDevice. */ + cls = (*env)->FindClass(env, + "gnu/java/awt/peer/gtk/GdkScreenGraphicsDevice"); + screenFID = (*env)->GetFieldID(env, cls, "screen", + "Lgnu/classpath/Pointer;"); +} + +/** + * Sets the native screen in the GdkScreenGraphicsDevice object. + * + * @param env the JNI environment + * @param screen_graphics_device the GdkScreenGraphicsDevice object + * @param ptr the native screen pointer + */ +void gtkpeer_set_screen(JNIEnv* env, jobject screen_graphics_device, + void* ptr) +{ + jobject obj; + + /* Fetch the screen field object. */ + obj = (*env)->GetObjectField(env, screen_graphics_device, screenFID); + if (obj == NULL) + { + /* Create if necessary. */ +#if SIZEOF_VOID_P == 8 + obj = (*env)->NewObject(env, pointerClass, pointerConstructorMID, + (jlong) ptr); +#else + obj = (*env)->NewObject(env, pointerClass, pointerConstructorMID, + (jint) ptr); +#endif + (*env)->SetObjectField(env, screen_graphics_device, screenFID, obj); + } + else + { +#if SIZEOF_VOID_P == 8 + (*env)->SetLongField(env, obj, pointerDataFID, (jlong) ptr); +#else + (*env)->SetIntField(env, obj, pointerDataFID, (jint) ptr); +#endif + } +} + +/** + * Fetches the native screen pointer from the GdkScreenGraphicsDevice object. + * + * @param env the JNI environment + * @param screen_graphics_device the GdkScreenGraphicsDevice object + * + * @return the native screen pointer + */ +void* gtkpeer_get_screen(JNIEnv* env, jobject screen_graphics_device) +{ + jobject obj; + void *screen; + + /* Fetch the display field from the peer object. */ + obj = (*env)->GetObjectField(env, screen_graphics_device, screenFID); + + /* Fetch actual display pointer. */ +#if SIZEOF_VOID_P == 8 + screen = (void*) (*env)->GetLongField(env, obj, pointerDataFID); +#else + screen = (void*) (*env)->GetIntField(env, obj, pointerDataFID); +#endif + return screen; +} + +/** + * Initializes the field IDs for fonts. + * + * @param env the JNI environment + */ +void gtkpeer_init_font_IDs(JNIEnv* env) +{ + jclass cls; + + /* Find the nativeFont field ID in GdkFontPeer. */ + cls = (*env)->FindClass(env, "gnu/java/awt/peer/gtk/GdkFontPeer"); + fontFID = (*env)->GetFieldID(env, cls, "nativeFont", + "Lgnu/classpath/Pointer;"); +} + +/** + * Sets the native font in the nativeFont field in GdkFontPeer. + * + * @param env the JNI environment + * @param font_peer the font peer object + * @param font the actual native font reference + */ +void gtkpeer_set_font(JNIEnv* env, jobject font_peer, void* font) +{ + jobject obj; + + /* Fetch the nativeFont field object. */ + obj = (*env)->GetObjectField(env, font_peer, fontFID); + if (obj == NULL) + { + /* Create if necessary. */ +#if SIZEOF_VOID_P == 8 + obj = (*env)->NewObject(env, pointerClass, pointerConstructorMID, + (jlong) font); +#else + obj = (*env)->NewObject(env, pointerClass, pointerConstructorMID, + (jint) font); +#endif + (*env)->SetObjectField(env, font_peer, fontFID, obj); + } + else + { +#if SIZEOF_VOID_P == 8 + (*env)->SetLongField(env, obj, pointerDataFID, (jlong) font); +#else + (*env)->SetIntField(env, obj, pointerDataFID, (jint) font); +#endif + } +} + +/** + * Fetches the native font reference from the GdkFontPeer object. + * + * @param env the JNI environment + * @param font_peer the font peer object + * + * @return the native font structure + */ +void* gtkpeer_get_font(JNIEnv* env, jobject font_peer) +{ + jobject obj; + void *font; + + /* Fetch the nativeFont field from the peer object. */ + obj = (*env)->GetObjectField(env, font_peer, fontFID); + + /* Fetch actual font pointer. */ +#if SIZEOF_VOID_P == 8 + font = (void*) (*env)->GetLongField(env, obj, pointerDataFID); +#else + font = (void*) (*env)->GetIntField(env, obj, pointerDataFID); +#endif + return font; +} + +/** + * Initializes the field IDs for pixbuf decoder. + * + * @param env the JNI environment + */ +void gtkpeer_init_pixbuf_IDs(JNIEnv* env) +{ + jclass cls; + + /* Find the nativeFont field ID in GdkFontPeer. */ + cls = (*env)->FindClass(env, "gnu/java/awt/peer/gtk/GdkPixbufDecoder"); + pixbufLoaderFID = (*env)->GetFieldID(env, cls, "nativeDecoder", + "Lgnu/classpath/Pointer;"); +} + +/** + * Sets the native font in the nativeFont field in GdkFontPeer. + * + * @param env the JNI environment + * @param pixbuf_dec the pixbuf decoder object + * @param pixbuf_loader the native pixbuf loader + */ +void gtkpeer_set_pixbuf_loader(JNIEnv* env, jobject pixbuf_dec, + void* pixbuf_loader) +{ + jobject obj; + + /* Fetch the nativeDecoder field object. */ + obj = (*env)->GetObjectField(env, pixbuf_dec, pixbufLoaderFID); + if (obj == NULL) + { + /* Create if necessary. */ +#if SIZEOF_VOID_P == 8 + obj = (*env)->NewObject(env, pointerClass, pointerConstructorMID, + (jlong) pixbuf_loader); +#else + obj = (*env)->NewObject(env, pointerClass, pointerConstructorMID, + (jint) pixbuf_loader); +#endif + (*env)->SetObjectField(env, pixbuf_dec, pixbufLoaderFID, obj); + } + else + { +#if SIZEOF_VOID_P == 8 + (*env)->SetLongField(env, obj, pointerDataFID, (jlong) pixbuf_loader); +#else + (*env)->SetIntField(env, obj, pointerDataFID, (jint) pixbuf_loader); +#endif + } +} + +/** + * Fetches the native pixbuf loader reference from the GdkPixbufDecoder object. + * + * @param env the JNI environment + * @param pixbuf_dec the pixbuf decoder object + * + * @return the native pixbuf loader + */ +void* gtkpeer_get_pixbuf_loader(JNIEnv* env, jobject pixbuf_dec) +{ + jobject obj; + void *loader; + + /* Fetch the nativeFont field from the peer object. */ + obj = (*env)->GetObjectField(env, pixbuf_dec, pixbufLoaderFID); + + /* Fetch actual font pointer. */ +#if SIZEOF_VOID_P == 8 + loader = (void*) (*env)->GetLongField(env, obj, pointerDataFID); +#else + loader = (void*) (*env)->GetIntField(env, obj, pointerDataFID); +#endif + return loader; +} diff --git a/libjava/classpath/native/jni/gtk-peer/gtkpeer.h b/libjava/classpath/native/jni/gtk-peer/gtkpeer.h new file mode 100644 index 000000000..8b677aff7 --- /dev/null +++ b/libjava/classpath/native/jni/gtk-peer/gtkpeer.h @@ -0,0 +1,360 @@ +/* gtkpeer.h -- Some global variables and #defines + Copyright (C) 1998, 1999, 2004, 2005, 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#include +#include +#include +#include +#include +#include +#include + +#include + +#ifndef __GTKPEER_H__ +#define __GTKPEER_H__ + +#ifndef __GNUC__ +#define __attribute__(x) /* nothing */ +#endif + +/** + * Initializes the IDs of the Pointer* classes. + * + * @param env the JNI environment + */ +void gtkpeer_init_pointer_IDs(JNIEnv* env); + +/** + * Initializes the field IDs for the widget reference. + * + * @param env the JNI environment + */ +void gtkpeer_init_widget_IDs(JNIEnv *env); + +/** + * Stores the GTK widget reference in the GtkComponentPeer object. + * + * @param env the JNI environment + * @param peer the actual peer object + * @param widget the widget reference to store + */ +void gtkpeer_set_widget(JNIEnv *env, jobject peer, void *widget); + +/** + * Retrieves the GTK widget reference from a GtkComponentPeer object. + * + * @param env the JNI environment + * @param peer the actual peer object + * + * @return the widget reference + */ +void* gtkpeer_get_widget(JNIEnv *env, jobject peer); + +/** + * Stores the global JNI reference of a peer inside the peer. + * + * @param env the JNI environment + * @param peer the peer object + */ +void gtkpeer_set_global_ref(JNIEnv *env, jobject peer); + +/** + * Retrieves the global reference from a peer. + * + * @param env the JNI environment + * @param peer the peer object + * + * @return the global reference + */ +void* gtkpeer_get_global_ref(JNIEnv *env, jobject peer); + +/** + * Deletes the global reference of a peer. This is necessary in order to + * allow the peer to be garbage collected. + * + * @param env the JNI environment + * @param peer the peer object. + */ +void gtkpeer_del_global_ref(JNIEnv* env, jobject peer); + + +/** + * Initializes the fieldIDs for the display and screen fields. + * + * @param env the JNI environment + */ +void gtkpeer_init_display_IDs(JNIEnv* env); + +/** + * Sets the native display pointer in the GdkGraphicsEnvironment object. + * + * @param env the JNI environment + * @param graphicsenv the GdkGraphicsEnvironment object + * @param display the native display pointer + */ +void gtkpeer_set_display(JNIEnv* env, jobject graphicsenv, void* display); + +/** + * Fetches the native display pointer from the GdkGraphicsEnvironment object. + * + * @param env the JNI environment + * @param graphicsenv the GdkGraphicsEnvironment object + * + * @return the native display pointer + */ +void* gtkpeer_get_display(JNIEnv* env, jobject graphicsenv); + +/** + * Initializes the fieldIDs for the screen field. + * + * @param env the JNI environment + */ +void gtkpeer_init_screen_IDs(JNIEnv* env); + +/** + * Sets the native screen in the GdkScreenGraphicsDevice object. + * + * @param env the JNI environment + * @param screen_graphics_device the GdkScreenGraphicsDevice object + * @param ptr the native screen pointer + */ +void gtkpeer_set_screen(JNIEnv* env, jobject screen_graphics_device, + void* ptr); + +/** + * Fetches the native screen pointer from the GdkScreenGraphicsDevice object. + * + * @param env the JNI environment + * @param screen_graphics_device the GdkScreenGraphicsDevice object + * + * @return the native screen pointer + */ +void* gtkpeer_get_screen(JNIEnv* env, jobject screen_graphics_device); + +/** + * Initializes the field IDs for fonts. + * + * @param env the JNI environment + */ +void gtkpeer_init_font_IDs(JNIEnv* env); + +/** + * Sets the native font in the nativeFont field in GdkFontPeer. + * + * @param env the JNI environment + * @param font_peer the font peer object + * @param font the actual native font reference + */ +void gtkpeer_set_font(JNIEnv* env, jobject font_peer, void* font); + +/** + * Fetches the native font reference from the GdkFontPeer object. + * + * @param env the JNI environment + * @param font_peer the font peer object + * + * @return the native font structure + */ +void* gtkpeer_get_font(JNIEnv* env, jobject font_peer); + +/** + * Initializes the field IDs for pixbuf decoder. + * + * @param env the JNI environment + */ +void gtkpeer_init_pixbuf_IDs(JNIEnv* env); + +/** + * Sets the native font in the nativeFont field in GdkFontPeer. + * + * @param env the JNI environment + * @param pixbuf_dec the pixbuf decoder object + * @param pixbuf_loader the native pixbuf loader + */ +void gtkpeer_set_pixbuf_loader(JNIEnv* env, jobject pixbuf_dec, + void* pixbuf_loader); + +/** + * Fetches the native pixbuf loader reference from the GdkPixbufDecoder object. + * + * @param env the JNI environment + * @param pixbuf_dec the pixbuf decoder object + * + * @return the native pixbuf loader + */ +void* gtkpeer_get_pixbuf_loader(JNIEnv* env, jobject pixbuf_dec); + + +#define SWAPU32(w) \ + (((w) << 24) | (((w) & 0xff00) << 8) | (((w) >> 8) & 0xff00) | ((w) >> 24)) + +/* New-style event masks. */ +#define AWT_BUTTON1_DOWN_MASK (1 << 10) +#define AWT_BUTTON2_DOWN_MASK (1 << 11) +#define AWT_BUTTON3_DOWN_MASK (1 << 12) + +#define AWT_SHIFT_DOWN_MASK (1 << 6) +#define AWT_CTRL_DOWN_MASK (1 << 7) +#define AWT_META_DOWN_MASK (1 << 8) +#define AWT_ALT_DOWN_MASK (1 << 9) + +/* Old-style event masks. */ +#define AWT_BUTTON1_MASK (1 << 4) +#define AWT_BUTTON2_MASK (1 << 3) +#define AWT_BUTTON3_MASK (1 << 2) + +#define AWT_SHIFT_MASK (1 << 0) +#define AWT_CTRL_MASK (1 << 1) +#define AWT_META_MASK (1 << 2) +#define AWT_ALT_MASK (1 << 3) + +#define AWT_ITEM_SELECTED 1 +#define AWT_ITEM_DESELECTED 2 + +#define AWT_KEY_TYPED 400 +#define AWT_KEY_PRESSED 401 +#define AWT_KEY_RELEASED 402 + +#define AWT_KEY_LOCATION_UNKNOWN 0 +#define AWT_KEY_LOCATION_STANDARD 1 +#define AWT_KEY_LOCATION_LEFT 2 +#define AWT_KEY_LOCATION_RIGHT 3 +#define AWT_KEY_LOCATION_NUMPAD 4 + +#define AWT_STYLE_PLAIN 0 +#define AWT_STYLE_BOLD 1 +#define AWT_STYLE_ITALIC 2 + +/* Used in GtkComponentPeer and GtkWindowPeer */ +#define VK_NUMPAD0 96 +#define VK_NUMPAD1 97 +#define VK_NUMPAD2 98 +#define VK_NUMPAD3 99 +#define VK_NUMPAD4 100 +#define VK_NUMPAD5 101 +#define VK_NUMPAD6 102 +#define VK_NUMPAD7 103 +#define VK_NUMPAD8 104 +#define VK_NUMPAD9 105 +#define VK_DECIMAL 110 + +JNIEnv *cp_gtk_gdk_env(void); + +/* Global variables */ +extern double cp_gtk_dpi_conversion_factor; +extern GtkWindowGroup *cp_gtk_global_window_group; + +/* Shared global clipboard and selection for GtkClipboard and GtkSelection. */ +extern GtkClipboard *cp_gtk_clipboard; +extern GtkClipboard *cp_gtk_selection; + +extern jobject cp_gtk_clipboard_instance; +extern jobject cp_gtk_selection_instance; + +/* Standard target (strings) for GtkClipboard and GtkSelection. */ +extern jstring cp_gtk_stringTarget; +extern jstring cp_gtk_imageTarget; +extern jstring cp_gtk_filesTarget; + +/* Union used for type punning. */ +union widget_union +{ + void **void_widget; + GtkWidget **widget; +}; + +/* Constant conversion helpers */ +guint cp_gtk_awt_keycode_to_keysym (jint keyCode, jint keyLocation); +jint cp_gtk_state_to_awt_mods (guint state); + +/* Image helpers */ +GdkPixbuf *cp_gtk_image_get_pixbuf (JNIEnv *env, jobject obj); + +/* Component Graphics helpers */ +void cp_gtk_grab_current_drawable(GtkWidget *widget, GdkDrawable **draw, + GdkWindow **win); + +/* JNI initialization functions */ +void cp_gtk_button_init_jni (JNIEnv*); +void cp_gtk_checkbox_init_jni (void); +void cp_gtk_choice_init_jni (void); +void cp_gtk_component_init_jni (void); +void cp_gtk_filedialog_init_jni (void); +void cp_gtk_list_init_jni (void); +void cp_gtk_menuitem_init_jni (void); +void cp_gtk_scrollbar_init_jni (void); +void cp_gtk_textcomponent_init_jni (void); +void cp_gtk_window_init_jni (void); + +/* Signal connection convience functions */ +void cp_gtk_component_connect_expose_signals (GObject *ptr, jobject gref); +void cp_gtk_component_connect_focus_signals (GObject *ptr, jobject gref); +void cp_gtk_component_connect_mouse_signals (GObject *ptr, jobject gref); +void cp_gtk_component_connect_signals (GObject *ptr, jobject gref); +void cp_gtk_textcomponent_connect_signals (GObject *ptr, jobject gref); + +/* Debugging */ +void cp_gtk_print_current_thread (void); + +GdkPixmap *cp_gtk_get_pixmap( JNIEnv *env, jobject obj); + +#define SYNCHRONIZE_GDK 0 + +#define DEBUG_LOCKING 0 + +#if DEBUG_LOCKING +#define gdk_threads_enter() \ +{ \ + g_print ("locking: %s, %d\n", __FILE__, __LINE__); \ + cp_gtk_print_current_thread (); \ + gdk_threads_enter (); \ + g_print ("locked: %s, %d\n", __FILE__, __LINE__); \ + cp_gtk_print_current_thread (); \ +} +#define gdk_threads_leave() \ +{ \ + g_print ("unlocking: %s, %d\n", __FILE__, __LINE__); \ + cp_gtk_print_current_thread (); \ + gdk_threads_leave (); \ + g_print ("unlocked: %s, %d\n", __FILE__, __LINE__); \ + cp_gtk_print_current_thread (); \ +} +#endif + +#endif /* __GTKPEER_H */ diff --git a/libjava/classpath/native/jni/java-io/.cvsignore b/libjava/classpath/native/jni/java-io/.cvsignore new file mode 100644 index 000000000..e9f2658a6 --- /dev/null +++ b/libjava/classpath/native/jni/java-io/.cvsignore @@ -0,0 +1,8 @@ +*.o +*.a +*.lo +*.la +.libs +.deps +Makefile +Makefile.in diff --git a/libjava/classpath/native/jni/java-io/Makefile.am b/libjava/classpath/native/jni/java-io/Makefile.am new file mode 100644 index 000000000..58bd973e2 --- /dev/null +++ b/libjava/classpath/native/jni/java-io/Makefile.am @@ -0,0 +1,13 @@ +nativeexeclib_LTLIBRARIES = libjavaio.la + +libjavaio_la_SOURCES = java_io_VMFile.c \ + java_io_VMObjectInputStream.c \ + java_io_VMObjectStreamClass.c + +libjavaio_la_LIBADD = $(top_builddir)/native/jni/classpath/jcl.lo \ + $(top_builddir)/native/jni/native-lib/libclasspathnative.la + +AM_LDFLAGS = @CLASSPATH_MODULE@ +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ +AM_CFLAGS = @WARNING_CFLAGS@ @STRICT_WARNING_CFLAGS@ @ERROR_CFLAGS@ \ + @EXTRA_CFLAGS@ diff --git a/libjava/classpath/native/jni/java-io/Makefile.in b/libjava/classpath/native/jni/java-io/Makefile.in new file mode 100644 index 000000000..beb9ce6c7 --- /dev/null +++ b/libjava/classpath/native/jni/java-io/Makefile.in @@ -0,0 +1,617 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +subdir = native/jni/java-io +DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/../../config/depstand.m4 \ + $(top_srcdir)/../../config/lead-dot.m4 \ + $(top_srcdir)/../../config/lib-ld.m4 \ + $(top_srcdir)/../../config/lib-link.m4 \ + $(top_srcdir)/../../config/lib-prefix.m4 \ + $(top_srcdir)/../../config/multi.m4 \ + $(top_srcdir)/../../config/no-executables.m4 \ + $(top_srcdir)/../../config/override.m4 \ + $(top_srcdir)/../../libtool.m4 \ + $(top_srcdir)/../../ltoptions.m4 \ + $(top_srcdir)/../../ltsugar.m4 \ + $(top_srcdir)/../../ltversion.m4 \ + $(top_srcdir)/../../lt~obsolete.m4 \ + $(top_srcdir)/m4/ac_prog_antlr.m4 \ + $(top_srcdir)/m4/ac_prog_java.m4 \ + $(top_srcdir)/m4/ac_prog_java_works.m4 \ + $(top_srcdir)/m4/ac_prog_javac.m4 \ + $(top_srcdir)/m4/ac_prog_javac_works.m4 \ + $(top_srcdir)/m4/acattribute.m4 $(top_srcdir)/m4/accross.m4 \ + $(top_srcdir)/m4/acinclude.m4 \ + $(top_srcdir)/m4/ax_create_stdint_h.m4 \ + $(top_srcdir)/m4/ax_func_which_gethostbyname_r.m4 \ + $(top_srcdir)/m4/gcc_attribute.m4 $(top_srcdir)/m4/iconv.m4 \ + $(top_srcdir)/m4/pkg.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/../../mkinstalldirs +CONFIG_HEADER = $(top_builddir)/include/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__installdirs = "$(DESTDIR)$(nativeexeclibdir)" +LTLIBRARIES = $(nativeexeclib_LTLIBRARIES) +libjavaio_la_DEPENDENCIES = \ + $(top_builddir)/native/jni/classpath/jcl.lo \ + $(top_builddir)/native/jni/native-lib/libclasspathnative.la +am_libjavaio_la_OBJECTS = java_io_VMFile.lo \ + java_io_VMObjectInputStream.lo java_io_VMObjectStreamClass.lo +libjavaio_la_OBJECTS = $(am_libjavaio_la_OBJECTS) +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/include +depcomp = $(SHELL) $(top_srcdir)/../../depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(libjavaio_la_SOURCES) +ETAGS = etags +CTAGS = ctags +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +ANTLR = @ANTLR@ +ANTLR_JAR = @ANTLR_JAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CAIRO_CFLAGS = @CAIRO_CFLAGS@ +CAIRO_LIBS = @CAIRO_LIBS@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CLASSPATH_CONVENIENCE = @CLASSPATH_CONVENIENCE@ +CLASSPATH_INCLUDES = @CLASSPATH_INCLUDES@ +CLASSPATH_MODULE = @CLASSPATH_MODULE@ +COLLECTIONS_PREFIX = @COLLECTIONS_PREFIX@ +CP = @CP@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DATE = @DATE@ +DEFAULT_PREFS_PEER = @DEFAULT_PREFS_PEER@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +ECJ_JAR = @ECJ_JAR@ +EGREP = @EGREP@ +ERROR_CFLAGS = @ERROR_CFLAGS@ +EXAMPLESDIR = @EXAMPLESDIR@ +EXEEXT = @EXEEXT@ +EXTRA_CFLAGS = @EXTRA_CFLAGS@ +FGREP = @FGREP@ +FIND = @FIND@ +FREETYPE2_CFLAGS = @FREETYPE2_CFLAGS@ +FREETYPE2_LIBS = @FREETYPE2_LIBS@ +GCONF_CFLAGS = @GCONF_CFLAGS@ +GCONF_LIBS = @GCONF_LIBS@ +GDK_CFLAGS = @GDK_CFLAGS@ +GDK_LIBS = @GDK_LIBS@ +GJDOC = @GJDOC@ +GLIB_CFLAGS = @GLIB_CFLAGS@ +GLIB_LIBS = @GLIB_LIBS@ +GMP_CFLAGS = @GMP_CFLAGS@ +GMP_LIBS = @GMP_LIBS@ +GREP = @GREP@ +GSTREAMER_BASE_CFLAGS = @GSTREAMER_BASE_CFLAGS@ +GSTREAMER_BASE_LIBS = @GSTREAMER_BASE_LIBS@ +GSTREAMER_CFLAGS = @GSTREAMER_CFLAGS@ +GSTREAMER_FILE_READER = @GSTREAMER_FILE_READER@ +GSTREAMER_LIBS = @GSTREAMER_LIBS@ +GSTREAMER_MIXER_PROVIDER = @GSTREAMER_MIXER_PROVIDER@ +GSTREAMER_PLUGINS_BASE_CFLAGS = @GSTREAMER_PLUGINS_BASE_CFLAGS@ +GSTREAMER_PLUGINS_BASE_LIBS = @GSTREAMER_PLUGINS_BASE_LIBS@ +GST_PLUGIN_LDFLAGS = @GST_PLUGIN_LDFLAGS@ +GTK_CFLAGS = @GTK_CFLAGS@ +GTK_LIBS = @GTK_LIBS@ +INIT_LOAD_LIBRARY = @INIT_LOAD_LIBRARY@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAR = @JAR@ +JAVA = @JAVA@ +JAVAC = @JAVAC@ +JAVAC_IS_GCJ = @JAVAC_IS_GCJ@ +JAVAC_MEM_OPT = @JAVAC_MEM_OPT@ +JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION = @JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION@ +JAY = @JAY@ +JAY_SKELETON = @JAY_SKELETON@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBDEBUG = @LIBDEBUG@ +LIBICONV = @LIBICONV@ +LIBMAGIC = @LIBMAGIC@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBVERSION = @LIBVERSION@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBICONV = @LTLIBICONV@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MKDIR = @MKDIR@ +MKDIR_P = @MKDIR_P@ +MOC = @MOC@ +MOZILLA_CFLAGS = @MOZILLA_CFLAGS@ +MOZILLA_LIBS = @MOZILLA_LIBS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PANGOFT2_CFLAGS = @PANGOFT2_CFLAGS@ +PANGOFT2_LIBS = @PANGOFT2_LIBS@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PATH_TO_ESCHER = @PATH_TO_ESCHER@ +PATH_TO_GLIBJ_ZIP = @PATH_TO_GLIBJ_ZIP@ +PERL = @PERL@ +PKG_CONFIG = @PKG_CONFIG@ +PLUGIN_DIR = @PLUGIN_DIR@ +QT_CFLAGS = @QT_CFLAGS@ +QT_LIBS = @QT_LIBS@ +RANLIB = @RANLIB@ +REMOVE = @REMOVE@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRICT_WARNING_CFLAGS = @STRICT_WARNING_CFLAGS@ +STRIP = @STRIP@ +TOOLSDIR = @TOOLSDIR@ +USER_JAVAH = @USER_JAVAH@ +VERSION = @VERSION@ +WANT_NATIVE_BIG_INTEGER = @WANT_NATIVE_BIG_INTEGER@ +WARNING_CFLAGS = @WARNING_CFLAGS@ +XMKMF = @XMKMF@ +XML_CFLAGS = @XML_CFLAGS@ +XML_LIBS = @XML_LIBS@ +XSLT_CFLAGS = @XSLT_CFLAGS@ +XSLT_LIBS = @XSLT_LIBS@ +XTEST_LIBS = @XTEST_LIBS@ +X_CFLAGS = @X_CFLAGS@ +X_EXTRA_LIBS = @X_EXTRA_LIBS@ +X_LIBS = @X_LIBS@ +X_PRE_LIBS = @X_PRE_LIBS@ +ZIP = @ZIP@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_ANTLR = @ac_ct_ANTLR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +default_toolkit = @default_toolkit@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +glibjdir = @glibjdir@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +multi_basedir = @multi_basedir@ +nativeexeclibdir = @nativeexeclibdir@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +toolexeclibdir = @toolexeclibdir@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +uudecode = @uudecode@ +vm_classes = @vm_classes@ +nativeexeclib_LTLIBRARIES = libjavaio.la +libjavaio_la_SOURCES = java_io_VMFile.c \ + java_io_VMObjectInputStream.c \ + java_io_VMObjectStreamClass.c + +libjavaio_la_LIBADD = $(top_builddir)/native/jni/classpath/jcl.lo \ + $(top_builddir)/native/jni/native-lib/libclasspathnative.la + +AM_LDFLAGS = @CLASSPATH_MODULE@ +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ +AM_CFLAGS = @WARNING_CFLAGS@ @STRICT_WARNING_CFLAGS@ @ERROR_CFLAGS@ \ + @EXTRA_CFLAGS@ + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu native/jni/java-io/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu native/jni/java-io/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-nativeexeclibLTLIBRARIES: $(nativeexeclib_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(nativeexeclibdir)" || $(MKDIR_P) "$(DESTDIR)$(nativeexeclibdir)" + @list='$(nativeexeclib_LTLIBRARIES)'; test -n "$(nativeexeclibdir)" || list=; \ + list2=; for p in $$list; do \ + if test -f $$p; then \ + list2="$$list2 $$p"; \ + else :; fi; \ + done; \ + test -z "$$list2" || { \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(nativeexeclibdir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(nativeexeclibdir)"; \ + } + +uninstall-nativeexeclibLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(nativeexeclib_LTLIBRARIES)'; test -n "$(nativeexeclibdir)" || list=; \ + for p in $$list; do \ + $(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(nativeexeclibdir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(nativeexeclibdir)/$$f"; \ + done + +clean-nativeexeclibLTLIBRARIES: + -test -z "$(nativeexeclib_LTLIBRARIES)" || rm -f $(nativeexeclib_LTLIBRARIES) + @list='$(nativeexeclib_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libjavaio.la: $(libjavaio_la_OBJECTS) $(libjavaio_la_DEPENDENCIES) + $(LINK) -rpath $(nativeexeclibdir) $(libjavaio_la_OBJECTS) $(libjavaio_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/java_io_VMFile.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/java_io_VMObjectInputStream.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/java_io_VMObjectStreamClass.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) +installdirs: + for dir in "$(DESTDIR)$(nativeexeclibdir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-nativeexeclibLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-nativeexeclibLTLIBRARIES + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-nativeexeclibLTLIBRARIES + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-nativeexeclibLTLIBRARIES ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags dvi dvi-am html html-am info info-am install \ + install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-nativeexeclibLTLIBRARIES install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-nativeexeclibLTLIBRARIES + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/libjava/classpath/native/jni/java-io/java_io_VMFile.c b/libjava/classpath/native/jni/java-io/java_io_VMFile.c new file mode 100644 index 000000000..a15cec769 --- /dev/null +++ b/libjava/classpath/native/jni/java-io/java_io_VMFile.c @@ -0,0 +1,1214 @@ +/* java_io_VMFile.c - Native methods for java.io.File class + Copyright (C) 1998, 2004, 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +/* do not move; needed here because of some macro definitions */ +#include + +#include +#include +#include + +#if defined (HAVE_LSTAT) && defined (HAVE_READLINK) +#include +#include +#include +#endif + +#include +#include +#include "cpio.h" +#include "cpnative.h" + +#include "java_io_VMFile.h" + +/* ***** PRIVATE FUNCTIONS DELCARATION ***** */ + +/** + * Enables of disables the passed permission bit of a file. + */ +static jboolean set_file_permissions (JNIEnv *env, jstring name, + jboolean enable, + jboolean ownerOnly, + int permissions); + +/* ***** END: PRIVATE FUNCTIONS DELCARATION ***** */ + +/*************************************************************************/ + +/* + * Method to create an empty file. + * + * Class: java_io_VMFile + * Method: create + * Signature: (Ljava/lang/String;)Z + */ + +JNIEXPORT jboolean JNICALL +Java_java_io_VMFile_create (JNIEnv * env, + jclass clazz __attribute__ ((__unused__)), + jstring name) +{ +#ifndef WITHOUT_FILESYSTEM + const char *filename; + int fd; + int result; + + filename = JCL_jstring_to_cstring (env, name); + if (filename == NULL) + { + return 0; + } + + result = cpio_openFile (filename, &fd, CPFILE_FLAG_CREATE|CPFILE_FLAG_WRITE, CPFILE_PERMISSION_NORMAL); + if (result != CPNATIVE_OK) + { + if (result != EEXIST) + JCL_ThrowException (env, + "java/io/IOException", + cpnative_getErrorString (result)); + JCL_free_cstring (env, name, filename); + return 0; + } + cpio_closeFile (fd); + + JCL_free_cstring (env, name, filename); + return 1; +#else /* not WITHOUT_FILESYSTEM */ + return 0; +#endif /* not WITHOUT_FILESYSTEM */ +} + +/*************************************************************************/ + +/* + * This method checks to see if we have read permission on a file. + * + * Class: java_io_VMFile + * Method: canRead + * Signature: (Ljava/lang/String;)Z + */ + +JNIEXPORT jboolean JNICALL +Java_java_io_VMFile_canRead (JNIEnv * env, + jclass clazz __attribute__ ((__unused__)), + jstring name) +{ +#ifndef WITHOUT_FILESYSTEM + const char *filename; + int result; + + /* Don't use the JCL convert function because it throws an exception + on failure */ + filename = (*env)->GetStringUTFChars (env, name, 0); + if (filename == NULL) + { + return JNI_FALSE; + } + + result = cpio_checkAccess (filename, CPFILE_FLAG_READ); + + (*env)->ReleaseStringUTFChars (env, name, filename); + if (result != CPNATIVE_OK) + return JNI_FALSE; + + return JNI_TRUE; +#else /* not WITHOUT_FILESYSTEM */ + return JNI_FALSE; +#endif /* not WITHOUT_FILESYSTEM */ +} + +/*************************************************************************/ + +/* + * This method checks to see if we have write permission on a file. + * + * Class: java_io_VMFile + * Method: canWrite + * Signature: (Ljava/lang/String;)Z + */ + +JNIEXPORT jboolean JNICALL +Java_java_io_VMFile_canWrite (JNIEnv * env, + jclass clazz __attribute__ ((__unused__)), + jstring name) +{ +#ifndef WITHOUT_FILESYSTEM + const char *filename; + int result; + + /* Don't use the JCL convert function because it throws an exception + on failure */ + filename = (*env)->GetStringUTFChars (env, name, 0); + if (filename == NULL) + { + return JNI_FALSE; + } + + result = cpio_checkAccess (filename, CPFILE_FLAG_WRITE); + + (*env)->ReleaseStringUTFChars (env, name, filename); + if (result != CPNATIVE_OK) + { + return JNI_FALSE; + } + + return JNI_TRUE; +#else /* not WITHOUT_FILESYSTEM */ + return JNI_FALSE; +#endif /* not WITHOUT_FILESYSTEM */ +} + +/*************************************************************************/ + +JNIEXPORT jboolean JNICALL +Java_java_io_VMFile_canWriteDirectory (JNIEnv *env, jclass clazz, jstring path) +{ + /* this is only valid on *nix systems */ + return Java_java_io_VMFile_canWrite(env, clazz, path); +} + +/*************************************************************************/ + +/* + * This method checks to see if we have execute permission on a file. + * + * Class: java_io_VMFile + * Method: canExecute + * Signature: (Ljava/lang/String;)Z + */ + +JNIEXPORT jboolean JNICALL +Java_java_io_VMFile_canExecute (JNIEnv * env, + jclass clazz __attribute__ ((__unused__)), + jstring name) +{ +#ifndef WITHOUT_FILESYSTEM + const char *filename; + int result; + + /* Don't use the JCL convert function because it throws an exception + on failure */ + filename = (*env)->GetStringUTFChars (env, name, 0); + if (filename == NULL) + { + return JNI_FALSE; + } + + result = cpio_checkAccess (filename, CPFILE_FLAG_EXEC); + + (*env)->ReleaseStringUTFChars (env, name, filename); + if (result != CPNATIVE_OK) + return JNI_FALSE; + + return JNI_TRUE; +#else /* not WITHOUT_FILESYSTEM */ + return JNI_FALSE; +#endif /* not WITHOUT_FILESYSTEM */ +} + + +/*************************************************************************/ + +/* + * This method makes a file read only. + * + * Class: java_io_VMFile + * Method: setReadOnly + * Signature: (Ljava/lang/String;)Z + */ + +JNIEXPORT jboolean JNICALL +Java_java_io_VMFile_setReadOnly (JNIEnv * env, + jclass clazz __attribute__ ((__unused__)), + jstring name) +{ +#ifndef WITHOUT_FILESYSTEM + const char *filename; + int result; + + /* Don't use the JCL convert function because it throws an exception + on failure */ + filename = (*env)->GetStringUTFChars (env, name, 0); + if (filename == NULL) + { + return 0; + } + + result = cpio_setFileReadonly (filename); + (*env)->ReleaseStringUTFChars (env, name, filename); + + return result == CPNATIVE_OK ? 1 : 0; +#else /* not WITHOUT_FILESYSTEM */ + return 0; +#endif /* not WITHOUT_FILESYSTEM */ +} + +/*************************************************************************/ + +/* + * This method changes the read permission bit of a file. + * + * Class: java_io_VMFile + * Method: setReadable + * Signature: (Ljava/lang/String;ZZ)Z + */ +JNIEXPORT jboolean JNICALL +Java_java_io_VMFile_setReadable (JNIEnv *env, + jclass clazz __attribute__ ((__unused__)), + jstring name, + jboolean readable, + jboolean ownerOnly) +{ + return set_file_permissions (env, name, readable, ownerOnly, + CPFILE_FLAG_READ); +} + + +/*************************************************************************/ + +/* + * This method changes the write permission bit of a file. + * + * Class: java_io_VMFile + * Method: setWritable + * Signature: (Ljava/lang/String;ZZ)Z + */ +JNIEXPORT jboolean JNICALL +Java_java_io_VMFile_setWritable (JNIEnv *env, + jclass clazz __attribute__ ((__unused__)), + jstring name, + jboolean writable, + jboolean ownerOnly) +{ + return set_file_permissions (env, name, writable, ownerOnly, + CPFILE_FLAG_WRITE); +} + +/*************************************************************************/ + +/* + * This method changes the execute permission bit of a file. + * + * Class: java_io_VMFile + * Method: setExecutable + * Signature: (Ljava/lang/String;ZZ)Z + */ +JNIEXPORT jboolean JNICALL +Java_java_io_VMFile_setExecutable (JNIEnv *env, + jclass clazz __attribute__ ((__unused__)), + jstring name, + jboolean executable, + jboolean ownerOnly) +{ + return set_file_permissions (env, name, executable, ownerOnly, + CPFILE_FLAG_EXEC); +} + +/*************************************************************************/ + +JNIEXPORT jlong JNICALL +Java_java_io_VMFile_getTotalSpace (JNIEnv *env, + jclass clazz __attribute__ ((__unused__)), + jstring path) +{ +#ifndef WITHOUT_FILESYSTEM + + jlong result; + const char *_path = NULL; + + _path = (*env)->GetStringUTFChars (env, path, 0); + if (_path == NULL) + { + return 0L; + } + + result = cpio_df (_path, TOTAL); + + (*env)->ReleaseStringUTFChars (env, path, _path); + + return result; + +#else /* not WITHOUT_FILESYSTEM */ + return 0L; +#endif /* not WITHOUT_FILESYSTEM */ +} + +/*************************************************************************/ + +JNIEXPORT jlong JNICALL +Java_java_io_VMFile_getFreeSpace (JNIEnv *env, + jclass clazz __attribute__ ((__unused__)), + jstring path) +{ +#ifndef WITHOUT_FILESYSTEM + + jlong result; + const char *_path = NULL; + + _path = (*env)->GetStringUTFChars (env, path, 0); + if (_path == NULL) + { + return 0L; + } + + result = cpio_df (_path, FREE); + + (*env)->ReleaseStringUTFChars (env, path, _path); + + return result; + +#else /* not WITHOUT_FILESYSTEM */ + return 0L; +#endif /* not WITHOUT_FILESYSTEM */ +} + +/*************************************************************************/ + +JNIEXPORT jlong JNICALL +Java_java_io_VMFile_getUsableSpace (JNIEnv *env, + jclass clazz __attribute__ ((__unused__)), + jstring path) +{ +#ifndef WITHOUT_FILESYSTEM + + jlong result; + const char *_path = NULL; + + _path = (*env)->GetStringUTFChars (env, path, 0); + if (_path == NULL) + { + return 0L; + } + + result = cpio_df (_path, USABLE); + + (*env)->ReleaseStringUTFChars (env, path, _path); + + return result; + +#else /* not WITHOUT_FILESYSTEM */ + return 0L; +#endif /* not WITHOUT_FILESYSTEM */ +} + +/*************************************************************************/ + +/* + * This method checks to see if a file exists. + * + * Class: java_io_VMFile + * Method: exists + * Signature: (Ljava/lang/String;)Z + */ + +JNIEXPORT jboolean JNICALL +Java_java_io_VMFile_exists (JNIEnv * env, + jclass clazz __attribute__ ((__unused__)), + jstring name) +{ +#ifndef WITHOUT_FILESYSTEM + const char *filename; + int result; + + /* Don't use the JCL convert function because it throws an exception + on failure */ + filename = (*env)->GetStringUTFChars (env, name, 0); + if (filename == NULL) + { + return 0; + } + + result = cpio_isFileExists (filename); + (*env)->ReleaseStringUTFChars (env, name, filename); + + return result == CPNATIVE_OK ? 1 : 0; +#else /* not WITHOUT_FILESYSTEM */ + return 0; +#endif /* not WITHOUT_FILESYSTEM */ +} + +/*************************************************************************/ + +/* + * This method checks to see if a file is a "plain" file; that is, not + * a directory, pipe, etc. + * + * Class: java_io_VMFile + * Method: isFile + * Signature: (Ljava/lang/String;)Z + */ + +JNIEXPORT jboolean JNICALL +Java_java_io_VMFile_isFile (JNIEnv * env, + jclass clazz __attribute__ ((__unused__)), + jstring name) +{ +#ifndef WITHOUT_FILESYSTEM + const char *filename; + int result; + jint entryType; + + /* Don't use the JCL convert function because it throws an exception + on failure */ + filename = (*env)->GetStringUTFChars (env, name, 0); + if (filename == NULL) + { + return 0; + } + + result = cpio_checkType (filename, &entryType); + (*env)->ReleaseStringUTFChars (env, name, filename); + + return result == CPNATIVE_OK && entryType == CPFILE_FILE ? 1 : 0; +#else /* not WITHOUT_FILESYSTEM */ + return 0; +#endif /* not WITHOUT_FILESYSTEM */ +} + +/*************************************************************************/ + +/* + * This method checks to see if a file is a directory or not. + * + * Class: java_io_VMFile + * Method: isDirectory + * Signature: (Ljava/lang/String;)Z + */ + +JNIEXPORT jboolean JNICALL +Java_java_io_VMFile_isDirectory (JNIEnv * env, + jclass clazz __attribute__ ((__unused__)), + jstring name) +{ +#ifndef WITHOUT_FILESYSTEM + const char *filename; + int result; + jint entryType; + + /* Don't use the JCL convert function because it throws an exception + on failure */ + filename = (*env)->GetStringUTFChars (env, name, 0); + if (filename == NULL) + { + return 0; + } + + result = cpio_checkType (filename, &entryType); + (*env)->ReleaseStringUTFChars (env, name, filename); + + return result == CPNATIVE_OK && entryType == CPFILE_DIRECTORY ? 1 : 0; +#else /* not WITHOUT_FILESYSTEM */ + return 0; +#endif /* not WITHOUT_FILESYSTEM */ +} + +/*************************************************************************/ + +/* + * This method returns the length of the file. + * + * Class: java_io_VMFile + * Method: length + * Signature: (Ljava/lang/String;)J + */ + +JNIEXPORT jlong JNICALL +Java_java_io_VMFile_length (JNIEnv * env, + jclass clazz __attribute__ ((__unused__)), + jstring name) +{ +#ifndef WITHOUT_FILESYSTEM + const char *filename; + int tmpfd; + jlong length; + int result; + + /* Don't use the JCL convert function because it throws an exception + on failure */ + filename = (*env)->GetStringUTFChars (env, name, 0); + if (filename == NULL) + return 0; + + /* open file for reading, get size and close file */ + result = cpio_openFile (filename, &tmpfd, CPFILE_FLAG_READ, 0); + if (result != CPNATIVE_OK) + return 0; + + result = cpio_getFileSize (tmpfd, &length); + if (result != CPNATIVE_OK) + { + cpio_closeFile (tmpfd); + return 0; + } + + result = cpio_closeFile (tmpfd); + (*env)->ReleaseStringUTFChars (env, name, filename); + + return result == CPNATIVE_OK ? length : 0; +#else /* not WITHOUT_FILESYSTEM */ + return 0; +#endif /* not WITHOUT_FILESYSTEM */ +} + +/*************************************************************************/ + +/* + * This method returns the modification date of the file. + * + * Class: java_io_VMFile + * Method: lastModified + * Signature: (Ljava/lang/String;)J + */ + +JNIEXPORT jlong JNICALL +Java_java_io_VMFile_lastModified (JNIEnv * env, + jclass clazz __attribute__ ((__unused__)), + jstring name) +{ +#ifndef WITHOUT_FILESYSTEM + const char *filename; + jlong mtime; + int result; + + /* Don't use the JCL convert function because it throws an exception + on failure */ + filename = (*env)->GetStringUTFChars (env, name, 0); + if (filename == NULL) + { + return 0; + } + + result = cpio_getModificationTime (filename, &mtime); + (*env)->ReleaseStringUTFChars (env, name, filename); + + return result == CPNATIVE_OK ? mtime : 0; +#else /* not WITHOUT_FILESYSTEM */ + return 0; +#endif /* not WITHOUT_FILESYSTEM */ +} + +/*************************************************************************/ + +/* + * This method sets the modification date of the file. + * + * Class: java_io_VMFile + * Method: setLastModified + * Signature: (Ljava/lang/String;J)Z + */ + +JNIEXPORT jboolean JNICALL +Java_java_io_VMFile_setLastModified (JNIEnv * env, + jclass clazz __attribute__ ((__unused__)), + jstring name, jlong newtime) +{ +#ifndef WITHOUT_FILESYSTEM + const char *filename; + int result; + + /* Don't use the JCL convert function because it throws an exception + on failure */ + filename = (*env)->GetStringUTFChars (env, name, 0); + if (filename == NULL) + { + return 0; + } + + result = cpio_setModificationTime (filename, newtime); + (*env)->ReleaseStringUTFChars (env, name, filename); + + return result == CPNATIVE_OK ? 1 : 0; +#else /* not WITHOUT_FILESYSTEM */ + return 0; +#endif /* not WITHOUT_FILESYSTEM */ +} + +/*************************************************************************/ + +/* + * This method deletes a file (actually a name for a file - additional + * links could exist). + * + * Class: java_io_VMFile + * Method: delete + * Signature: (Ljava/lang/String;)Z + */ + +JNIEXPORT jboolean JNICALL +Java_java_io_VMFile_delete (JNIEnv * env, + jclass clazz __attribute__ ((__unused__)), + jstring name) +{ +#ifndef WITHOUT_FILESYSTEM + const char *filename; + int result; + + /* Don't use the JCL convert function because it throws an exception + on failure */ + filename = (*env)->GetStringUTFChars (env, name, 0); + if (filename == NULL) + { + return 0; + } + + result = cpio_removeFile (filename); + (*env)->ReleaseStringUTFChars (env, name, filename); + + return result == CPNATIVE_OK ? 1 : 0; +#else /* not WITHOUT_FILESYSTEM */ + return 0; +#endif /* not WITHOUT_FILESYSTEM */ +} + +/*************************************************************************/ + +/* + * This method creates a directory. + * + * Class: java_io_VMFile + * Method: mkdir + * Signature: (Ljava/lang/String;)Z + */ + +JNIEXPORT jboolean JNICALL +Java_java_io_VMFile_mkdir (JNIEnv * env, + jclass clazz __attribute__ ((__unused__)), + jstring name) +{ +#ifndef WITHOUT_FILESYSTEM + const char *pathname; + int result; + + /* Don't use the JCL convert function because it throws an exception + on failure */ + pathname = (*env)->GetStringUTFChars (env, name, 0); + if (pathname == NULL) + { + return 0; + } + + result = cpio_mkdir (pathname); + (*env)->ReleaseStringUTFChars (env, name, pathname); + + return (result == CPNATIVE_OK) ? 1 : 0; +#else /* not WITHOUT_FILESYSTEM */ + return 0; +#endif /* not WITHOUT_FILESYSTEM */ +} + +/*************************************************************************/ + +/* + * This method renames a (link to a) file. + * + * Class: java_io_VMFile + * Method: renameTo + * Signature: (Ljava/lang/String;Ljava/lang/String;)Z + */ + +JNIEXPORT jboolean JNICALL +Java_java_io_VMFile_renameTo (JNIEnv * env, + jclass clazz __attribute__ ((__unused__)), + jstring t, jstring d) +{ +#ifndef WITHOUT_FILESYSTEM + const char *old_filename, *new_filename; + int result; + + /* Don't use the JCL convert function because it throws an exception + on failure */ + old_filename = (*env)->GetStringUTFChars (env, t, 0); + if (old_filename == NULL) + { + return 0; + } + + new_filename = (*env)->GetStringUTFChars (env, d, 0); + if (new_filename == NULL) + { + (*env)->ReleaseStringUTFChars (env, t, old_filename); + return 0; + } + + result = cpio_rename (old_filename, new_filename); + (*env)->ReleaseStringUTFChars (env, d, new_filename); + (*env)->ReleaseStringUTFChars (env, t, old_filename); + + return (result == CPNATIVE_OK) ? 1 : 0; +#else /* not WITHOUT_FILESYSTEM */ + return 0; +#endif /* not WITHOUT_FILESYSTEM */ +} + +/*************************************************************************/ + +/* + * This method returns an array of String representing all the files + * in a directory except "." and "..". + * + * Class: java_io_VMFile + * Method: list + * Signature: (Ljava/lang/String;)[Ljava/lang/String; + */ + +JNIEXPORT jobjectArray JNICALL +Java_java_io_VMFile_list (JNIEnv * env, + jclass clazz __attribute__ ((__unused__)), + jstring name) +{ +#ifndef WITHOUT_FILESYSTEM + const int REALLOC_SIZE = 10; + + const char *dirname; + int result; + char **filelist; + void *handle; + char *filename = (char *) JCL_malloc (env, FILENAME_MAX); + unsigned long int filelist_count, max_filelist_count; + char **tmp_filelist; + jclass str_clazz; + jobjectArray filearray; + unsigned long int i; + jstring str; + + /* Don't use the JCL convert function because it throws an exception + on failure */ + dirname = (*env)->GetStringUTFChars (env, name, 0); + if (dirname == NULL) + { + return 0; + } + + /* open directory for reading */ + result = cpio_openDir (dirname, &handle); + + (*env)->ReleaseStringUTFChars (env, name, dirname); + + if (result != CPNATIVE_OK) + { + return 0; + } + + /* allocate filelist */ + filelist = (char **) JCL_malloc (env, sizeof (char *) * REALLOC_SIZE); + if (filelist == NULL) + { + result = cpio_closeDir (handle); + return 0; + } + filelist_count = 0; + max_filelist_count = REALLOC_SIZE; + + /* read the files from the directory */ + result = cpio_readDir (handle, filename); + while (result == CPNATIVE_OK) + { + if ((strcmp (filename, ".") != 0) && (strcmp (filename, "..") != 0)) + { + /* allocate more memory if necessary */ + if (filelist_count >= max_filelist_count) + { + tmp_filelist = (char **) JCL_realloc (env, + filelist, + (max_filelist_count + + REALLOC_SIZE) * + sizeof (char *)); + if (tmp_filelist == NULL) + { + for (i = 0; i < filelist_count; i++) + { + JCL_free (env, filelist[i]); + } + JCL_free (env, filelist); + result = cpio_closeDir (handle); + return 0; + } + filelist = tmp_filelist; + max_filelist_count += REALLOC_SIZE; + } + + /* save entry in list (avoid strdup, because it is not ANSI C, thus difficult to port) */ + filelist[filelist_count] = + (char *) JCL_malloc (env, strlen (filename) + 1); + assert (filelist[filelist_count] != NULL); + strcpy (filelist[filelist_count], filename); + filelist_count++; + } + + /* read next directory entry */ + result = cpio_readDir (handle, filename); + } + + JCL_free (env, filename); + + /* close directory */ + result = cpio_closeDir (handle); + + /* put the list of files into a Java String array and return it */ + str_clazz = (*env)->FindClass (env, "java/lang/String"); + if (str_clazz == NULL) + { + for (i = 0; i < filelist_count; i++) + { + JCL_free (env, filelist[i]); + } + JCL_free (env, filelist); + return 0; + } + filearray = (*env)->NewObjectArray (env, filelist_count, str_clazz, 0); + if (filearray == NULL) + { + for (i = 0; i < filelist_count; i++) + { + JCL_free (env, filelist[i]); + } + JCL_free (env, filelist); + return 0; + } + + (*env)->DeleteLocalRef (env, str_clazz); + + for (i = 0; i < filelist_count; i++) + { + /* create new string */ + str = (*env)->NewStringUTF (env, filelist[i]); + if (str == NULL) + { + /* We don't clean up everything here, but if this failed, + something serious happened anyway */ + for (i = 0; i < filelist_count; i++) + { + JCL_free (env, filelist[i]); + } + JCL_free (env, filelist); + return 0; + } + + /* save into array */ + (*env)->SetObjectArrayElement (env, filearray, i, str); + + /* delete local reference */ + (*env)->DeleteLocalRef (env, str); + } + + /* free resources */ + for (i = 0; i < filelist_count; i++) + { + JCL_free (env, filelist[i]); + } + JCL_free (env, filelist); + + return filearray; +#else /* not WITHOUT_FILESYSTEM */ + return 0; +#endif /* not WITHOUT_FILESYSTEM */ +} + +/*************************************************************************/ + +/* + * These two methods are used to maintain dynamically allocated + * buffers for getCanonicalPath without the overhead of calling + * realloc every time a buffer is modified. Buffers are sized + * at the smallest multiple of CHUNKSIZ that is greater than or + * equal to the desired length. The default CHUNKSIZ is 256, + * longer than most paths, so in most cases a getCanonicalPath + * will require only one malloc per buffer. + */ + +#define CHUNKLOG 8 +#define CHUNKSIZ (1 << CHUNKLOG) + +static int +nextChunkSize (int size) +{ + return ((size >> CHUNKLOG) + ((size & (CHUNKSIZ - 1)) ? 1 : 0)) << CHUNKLOG; +} + +static char * +maybeGrowBuf (JNIEnv *env, char *buf, int *size, int required) +{ + if (required > *size) + { + *size = nextChunkSize (required); + buf = JCL_realloc (env, buf, *size); + } + return buf; +} + +/*************************************************************************/ + +/* + * This method converts a path to canonical form on GNU/Posix systems. + * This involves the removal of redundant separators, references to + * "." and "..", and symbolic links. + * + * The conversion proceeds on a component-by-component basis: symbolic + * links and references to ".." are resolved as and when they occur. + * This means that if "/foo/bar" is a symbolic link to "/baz" then the + * canonical form of "/foo/bar/.." is "/" and not "/foo". + * + * In order to mimic the behaviour of proprietary JVMs, non-existant + * path components are allowed (a departure from the normal GNU system + * convention). This means that if "/foo/bar" is a symbolic link to + * "/baz", the canonical form of "/non-existant-directory/../foo/bar" + * is "/baz". + * + * Class: java_io_VMFile + * Method: toCanonicalForm + * Signature: (Ljava/lang/String)Ljava/lang/String + */ + +JNIEXPORT jstring JNICALL +Java_java_io_VMFile_toCanonicalForm (JNIEnv *env, + jclass class __attribute__ ((__unused__)), + jstring jpath) +{ +#ifndef WITHOUT_FILESYSTEM + const char *path; + char *src, *dst; + int srci, dsti; + int srcl, dstl; + int len; + int fschecks; +#if defined (HAVE_LSTAT) && defined (HAVE_READLINK) + struct stat sb; +#endif /* HAVE_LSTAT && HAVE_READLINK */ + + path = JCL_jstring_to_cstring (env, jpath); + if (path == NULL) + return NULL; + + /* It is the caller's responsibility to ensure the path is absolute. */ + if (path[0] == 0 || path[0] != '/') + { + JCL_free_cstring (env, jpath, path); + JCL_ThrowException (env, "java/lang/RuntimeException", "Not absolute"); + return NULL; + } + + len = strlen (path); + srcl = nextChunkSize (len + 1); + src = JCL_malloc (env, srcl); + if (src == NULL) + { + JCL_free_cstring (env, jpath, path); + return NULL; + } + strcpy (src, path); + JCL_free_cstring (env, jpath, path); + srci = 1; + + dstl = nextChunkSize (2); + dst = JCL_malloc (env, dstl); + if (dst == NULL) + { + JCL_free (env, src); + return NULL; + } + dst[0] = '/'; + dsti = 1; + + fschecks = JNI_TRUE; + + while (src[srci] != '\0') + { + int tmpi, dsti_save; + + /* Skip slashes. */ + while (src[srci] == '/') + srci++; + tmpi = srci; + /* Find next slash. */ + while (src[srci] != '/' && src[srci] != '\0') + srci++; + if (srci == tmpi) + /* We hit the end. */ + break; + len = srci - tmpi; + + /* Handle "." and "..". */ + if (len == 1 && src[tmpi] == '.') + continue; + if (len == 2 && src[tmpi] == '.' && src[tmpi + 1] == '.') + { + while (dsti > 1 && dst[dsti - 1] != '/') + dsti--; + if (dsti != 1) + dsti--; + /* Reenable filesystem checking if disabled, as we might + * have reversed over whatever caused the problem before. + * At least one proprietary JVM has inconsistencies because + * it does not do this. + */ + fschecks = JNI_TRUE; + continue; + } + + /* Handle real path components. */ + dst = maybeGrowBuf (env, + dst, &dstl, dsti + (dsti > 1 ? 1 : 0) + len + 1); + if (dst == NULL) + { + JCL_free (env, src); + return NULL; + } + dsti_save = dsti; + if (dsti > 1) + dst[dsti++] = '/'; + strncpy (&dst[dsti], &src[tmpi], len); + dsti += len; + if (fschecks == JNI_FALSE) + continue; + +#if defined (HAVE_LSTAT) && defined (HAVE_READLINK) + dst[dsti] = '\0'; + if (lstat (dst, &sb) == 0) + { + if (S_ISLNK (sb.st_mode)) + { + int tmpl = CHUNKSIZ; + char *tmp = JCL_malloc (env, tmpl); + if (tmp == NULL) + { + JCL_free (env, src); + JCL_free (env, dst); + return NULL; + } + + while (1) + { + tmpi = readlink (dst, tmp, tmpl); + if (tmpi < 1) + { + JCL_free (env, src); + JCL_free (env, dst); + JCL_free (env, tmp); + JCL_ThrowException (env, "java/io/IOException", + "readlink failed"); + return NULL; + } + if (tmpi < tmpl) + break; + tmpl += CHUNKSIZ; + tmp = JCL_realloc (env, tmp, tmpl); + } + + /* Prepend the link's path to src. */ + tmp = maybeGrowBuf (env, + tmp, &tmpl, tmpi + strlen (&src[srci]) + 1); + if (tmp == NULL) + { + JCL_free (env, src); + JCL_free (env, dst); + return NULL; + } + + strcpy (&tmp[tmpi], &src[srci]); + JCL_free (env, src); + src = tmp; + srcl = tmpl; + srci = 0; + + /* Either replace or append dst depending on whether the + * link is relative or absolute. + */ + dsti = src[0] == '/' ? 1 : dsti_save; + } + } + else + { + /* Something doesn't exist, or we don't have permission to + * read it, or a previous path component is a directory, or + * a symlink is looped. Whatever, we can't check the + * filesystem any more. + */ + fschecks = JNI_FALSE; + } +#endif /* HAVE_LSTAT && HAVE_READLINK */ + } + dst[dsti] = '\0'; + + jpath = (*env)->NewStringUTF (env, dst); + JCL_free (env, src); + JCL_free (env, dst); + return jpath; +#else /* not WITHOUT_FILESYSTEM */ + return NULL; +#endif /* not WITHOUT_FILESYSTEM */ +} + +/*************************************************************************/ + +/* ***** PRIVATE FUNCTIONS IMPLEMENTATION ***** */ + +static jboolean set_file_permissions (JNIEnv *env, jstring name, + jboolean enable, + jboolean ownerOnly, + int permissions) +{ +#ifndef WITHOUT_FILESYSTEM + const char *filename; + int result = JNI_FALSE; + + /* Don't use the JCL convert function because it throws an exception + on failure */ + filename = (*env)->GetStringUTFChars (env, name, 0); + if (filename == NULL) + { + return JNI_FALSE; + } + + if (ownerOnly) + { + permissions |= CPFILE_FLAG_USR; + } + + if (!enable) + { + permissions |= CPFILE_FLAG_OFF; + } + + result = cpio_chmod (filename, permissions); + (*env)->ReleaseStringUTFChars (env, name, filename); + + return result == CPNATIVE_OK ? JNI_TRUE : JNI_FALSE; + +#else /* not WITHOUT_FILESYSTEM */ + return JNI_FALSE; +#endif /* not WITHOUT_FILESYSTEM */ +} diff --git a/libjava/classpath/native/jni/java-io/java_io_VMObjectInputStream.c b/libjava/classpath/native/jni/java-io/java_io_VMObjectInputStream.c new file mode 100644 index 000000000..d8d807149 --- /dev/null +++ b/libjava/classpath/native/jni/java-io/java_io_VMObjectInputStream.c @@ -0,0 +1,69 @@ +/* java_io_VMObjectInputStream.c -- Native methods for ObjectInputStream class + Copyright (C) 1998, 2004, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +/* TODO: check exceptions */ +/* comments */ + +/* do not move; needed here because of some macro definitions */ +#include + +#include +#include + +#include "java_io_VMObjectInputStream.h" + +/* + * Class: java_io_VMObjectInputStream + * Method: allocateObject + * Signature: (Ljava/lang/Class;)Ljava/lang/Object; + */ +JNIEXPORT jobject JNICALL +Java_java_io_VMObjectInputStream_allocateObject (JNIEnv * env, + jclass clazz + __attribute__((__unused__)), + jclass target_clazz, + jclass constr_clazz, + jobject constructor) +{ + jobject obj = (*env)->AllocObject (env, target_clazz); + jmethodID id = (*env)->FromReflectedMethod (env, constructor); + + (*env)->CallNonvirtualVoidMethod (env, obj, constr_clazz, id); + + return obj; +} diff --git a/libjava/classpath/native/jni/java-io/java_io_VMObjectStreamClass.c b/libjava/classpath/native/jni/java-io/java_io_VMObjectStreamClass.c new file mode 100644 index 000000000..f5d785ecd --- /dev/null +++ b/libjava/classpath/native/jni/java-io/java_io_VMObjectStreamClass.c @@ -0,0 +1,381 @@ +/* java_io_VMObjectStreamClass.c -- Native methods for VMObjectStreamClass.java + Copyright (C) 2003, 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#include +#include + +#include +#include + +#include "java_io_VMObjectStreamClass.h" + +/* + * Class: java_io_VMObjectOutputStream + * Method: hasClassInitializer + * Signature: (Ljava/lang/Class;)Z + */ +JNIEXPORT jboolean JNICALL +Java_java_io_VMObjectStreamClass_hasClassInitializer (JNIEnv * env, + jclass vmosklass + __attribute__ ((__unused__)), jclass klass) +{ + jmethodID mid = (*env)->GetStaticMethodID (env, klass, "", "()V"); + if (mid == NULL) + { + (*env)->ExceptionClear (env); + return JNI_FALSE; + } + return JNI_TRUE; +} + +static void +throwInternalError (JNIEnv * env) +{ + jclass internalErrorClass; + jthrowable previousException, newException; + jmethodID initException, getMessageID, initCauseID; + jstring message; + + internalErrorClass = (*env)->FindClass (env, "java/lang/InternalError"); + /** Just give up if this also fails. */ + if (internalErrorClass == NULL) + return; + + previousException = (*env)->ExceptionOccurred (env); + + if (previousException == NULL) + { + (*env)->ThrowNew (env, internalErrorClass, + "Unknown error raised by the VM"); + return; + } + + initException = (*env)->GetMethodID + (env, internalErrorClass, "", "(Ljava/lang/String;)V"); + getMessageID = (*env)->GetMethodID + (env, (*env)->GetObjectClass (env, previousException), + "getMessage", "()Ljava/lang/String;"); + initCauseID = (*env)->GetMethodID + (env, internalErrorClass, "initCause", "(Ljava/lang/Throwable;)V"); + + message = (*env)->CallObjectMethod (env, previousException, getMessageID); + + newException = (*env)->NewObject (env, internalErrorClass, initException, + message); + (*env)->CallVoidMethod (env, newException, initCauseID, previousException); + + (*env)->ExceptionClear (env); + (*env)->Throw (env, newException); +} + +static jfieldID +getFieldReference (JNIEnv * env, jobject field, const char *type) +{ + jclass classClass; + jclass fieldClass; + jclass declaringClass; + jclass typeClass; + jfieldID fid; + const char *field_name; + const char *type_name; + int type_len; + jmethodID mid; + jstring name; + jstring tname; + int i; + + fieldClass = (*env)->GetObjectClass (env, field); + + mid = + (*env)->GetMethodID (env, fieldClass, "getName", "()Ljava/lang/String;"); + if (mid == NULL || (*env)->ExceptionOccurred (env) != NULL) + { + throwInternalError (env); + return NULL; + } + + name = (*env)->CallObjectMethod (env, field, mid); + field_name = (*env)->GetStringUTFChars (env, name, NULL); + + mid = (*env)->GetMethodID (env, fieldClass, + "getDeclaringClass", "()Ljava/lang/Class;"); + if (mid == NULL || (*env)->ExceptionOccurred (env) != NULL) + { + throwInternalError (env); + return NULL; + } + + declaringClass = (*env)->CallObjectMethod (env, field, mid); + + /* Do we need to find out the exact type descriptor of the field? */ + if (type == NULL) + { + char *the_type; + + mid = (*env)->GetMethodID (env, fieldClass, + "getType", "()Ljava/lang/Class;"); + + if (mid == NULL || (*env)->ExceptionOccurred (env) != NULL) + { + throwInternalError (env); + return NULL; + } + + typeClass = (*env)->CallObjectMethod (env, field, mid); + classClass = (*env)->FindClass (env, "java/lang/Class"); + + mid = (*env)->GetMethodID (env, classClass, + "getName", "()Ljava/lang/String;"); + + if (mid == NULL || (*env)->ExceptionOccurred (env) != NULL) + { + throwInternalError (env); + return NULL; + } + + tname = (*env)->CallObjectMethod (env, typeClass, mid); + type_name = (*env)->GetStringUTFChars (env, tname, NULL); + + /* + * If it isn't an array class then the actual field type descriptor + * starts with 'L', ends with ';' and has '/' instead of '.'. + */ + type_len = strlen (type_name); + if (type_name[0] != '[') + { + /* XXX - FIXME - should not use dynamic allocation in core lib. */ + the_type = (char *) malloc (type_len + 3); + the_type[0] = 'L'; + the_type[type_len + 1] = ';'; + the_type[type_len + 2] = '\0'; + the_type++; + } + else + { + /* XXX - FIXME - should not use dynamic allocation in core lib. */ + the_type = (char *) malloc (type_len + 1); + the_type[type_len] = '\0'; + } + + for (i = 0; i < type_len; i++) + if (type_name[i] == '.') + the_type[i] = '/'; + else + the_type[i] = type_name[i]; + + if (type_name[0] != '[') + the_type--; + + (*env)->ReleaseStringUTFChars (env, tname, type_name); + fid = (*env)->GetFieldID (env, declaringClass, field_name, the_type); + free (the_type); + } + else + { + type_len = -1; + fid = (*env)->GetFieldID (env, declaringClass, field_name, type); + } + + if (fid == NULL) + { + throwInternalError (env); + return NULL; + } + (*env)->ReleaseStringUTFChars (env, name, field_name); + + return fid; +} + +/* + * Class: java_io_VMObjectOutputStream + * Method: setBooleanNative + * Signature: (Ljava/lang/reflect/Field;Ljava/lang/Object;Z)V + */ +JNIEXPORT void JNICALL +Java_java_io_VMObjectStreamClass_setBooleanNative (JNIEnv * env, + jclass vmosklass + __attribute__ ((__unused__)), jobject field, jobject object, jboolean value) +{ + jfieldID fid = getFieldReference (env, field, "Z"); + + if (fid != NULL) + (*env)->SetBooleanField (env, object, fid, value); +} + +/* + * Class: java_io_VMObjectOutputStream + * Method: setCharNative + * Signature: (Ljava/lang/reflect/Field;Ljava/lang/Object;C)V + */ +JNIEXPORT void JNICALL +Java_java_io_VMObjectStreamClass_setCharNative (JNIEnv * env, + jclass vmosklass + __attribute__ ((__unused__)), + jobject field, + jobject object, jchar value) +{ + jfieldID fid = getFieldReference (env, field, "C"); + + if (fid != NULL) + (*env)->SetCharField (env, object, fid, value); +} + +/* + * Class: java_io_VMObjectOutputStream + * Method: setByteNative + * Signature: (Ljava/lang/reflect/Field;Ljava/lang/Object;B)V + */ +JNIEXPORT void JNICALL +Java_java_io_VMObjectStreamClass_setByteNative (JNIEnv * env, + jclass vmosklass + __attribute__ ((__unused__)), + jobject field, + jobject object, jbyte value) +{ + jfieldID fid = getFieldReference (env, field, "B"); + + if (fid != NULL) + (*env)->SetByteField (env, object, fid, value); +} + + +/* + * Class: java_io_VMObjectOutputStream + * Method: setShortNative + * Signature: (Ljava/lang/reflect/Field;Ljava/lang/Object;S)V + */ +JNIEXPORT void JNICALL +Java_java_io_VMObjectStreamClass_setShortNative (JNIEnv * env, + jclass vmosklass + __attribute__ ((__unused__)), + jobject field, + jobject object, jshort value) +{ + jfieldID fid = getFieldReference (env, field, "S"); + + if (fid != NULL) + (*env)->SetShortField (env, object, fid, value); +} + +/* + * Class: java_io_VMObjectOutputStream + * Method: setIntNative + * Signature: (Ljava/lang/reflect/Field;Ljava/lang/Object;I)V + */ +JNIEXPORT void JNICALL +Java_java_io_VMObjectStreamClass_setIntNative (JNIEnv * env, + jclass vmosklass + __attribute__ ((__unused__)), + jobject field, + jobject object, jint value) +{ + jfieldID fid = getFieldReference (env, field, "I"); + + if (fid != NULL) + (*env)->SetIntField (env, object, fid, value); +} + + +/* + * Class: java_io_VMObjectOutputStream + * Method: setLongNative + * Signature: (Ljava/lang/reflect/Field;Ljava/lang/Object;J)V + */ +JNIEXPORT void JNICALL +Java_java_io_VMObjectStreamClass_setLongNative (JNIEnv * env, + jclass vmosklass + __attribute__ ((__unused__)), + jobject field, + jobject object, jlong value) +{ + jfieldID fid = getFieldReference (env, field, "J"); + + if (fid != NULL) + (*env)->SetLongField (env, object, fid, value); +} + + +/* + * Class: java_io_VMObjectOutputStream + * Method: setFloatNative + * Signature: (Ljava/lang/reflect/Field;Ljava/lang/Object;F)V + */ +JNIEXPORT void JNICALL +Java_java_io_VMObjectStreamClass_setFloatNative (JNIEnv * env, + jclass vmosklass + __attribute__ ((__unused__)), + jobject field, + jobject object, jfloat value) +{ + jfieldID fid = getFieldReference (env, field, "F"); + + if (fid != NULL) + (*env)->SetFloatField (env, object, fid, value); +} + +/* + * Class: java_io_VMObjectOutputStream + * Method: setDoubleNative + * Signature: (Ljava/lang/reflect/Field;Ljava/lang/Object;D)V + */ +JNIEXPORT void JNICALL +Java_java_io_VMObjectStreamClass_setDoubleNative (JNIEnv * env, + jclass vmosklass + __attribute__ ((__unused__)), jobject field, jobject object, jdouble value) +{ + jfieldID fid = getFieldReference (env, field, "D"); + + if (fid != NULL) + (*env)->SetDoubleField (env, object, fid, value); +} + +/* + * Class: java_io_VMObjectOutputStream + * Method: setObjectNative + * Signature: (Ljava/lang/reflect/Field;Ljava/lang/Object;Ljava/lang/Object;)V + */ +JNIEXPORT void JNICALL +Java_java_io_VMObjectStreamClass_setObjectNative (JNIEnv * env, + jclass vmosklass + __attribute__ ((__unused__)), jobject field, jobject object, jobject value) +{ + jfieldID fid = getFieldReference (env, field, NULL); + + if (fid != NULL) + (*env)->SetObjectField (env, object, fid, value); +} diff --git a/libjava/classpath/native/jni/java-lang/.cvsignore b/libjava/classpath/native/jni/java-lang/.cvsignore new file mode 100644 index 000000000..e9f2658a6 --- /dev/null +++ b/libjava/classpath/native/jni/java-lang/.cvsignore @@ -0,0 +1,8 @@ +*.o +*.a +*.lo +*.la +.libs +.deps +Makefile +Makefile.in diff --git a/libjava/classpath/native/jni/java-lang/Makefile.am b/libjava/classpath/native/jni/java-lang/Makefile.am new file mode 100644 index 000000000..e1bc7ce71 --- /dev/null +++ b/libjava/classpath/native/jni/java-lang/Makefile.am @@ -0,0 +1,20 @@ +nativeexeclib_LTLIBRARIES = libjavalang.la libjavalangreflect.la libjavalangmanagement.la + +libjavalang_la_SOURCES = java_lang_VMSystem.c \ + java_lang_VMFloat.c \ + java_lang_VMDouble.c \ + java_lang_VMMath.c \ + java_lang_VMProcess.c + +libjavalang_la_LIBADD = $(top_builddir)/native/fdlibm/libfdlibm.la \ + $(top_builddir)/native/jni/classpath/jcl.lo \ + $(top_builddir)/native/jni/native-lib/libclasspathnative.la + +libjavalangreflect_la_SOURCES = java_lang_reflect_VMArray.c + +libjavalangmanagement_la_SOURCES = gnu_java_lang_management_VMOperatingSystemMXBeanImpl.c + +AM_LDFLAGS = @CLASSPATH_MODULE@ +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ -I$(top_srcdir)/native/fdlibm +AM_CFLAGS = @WARNING_CFLAGS@ @STRICT_WARNING_CFLAGS@ @ERROR_CFLAGS@ \ + @EXTRA_CFLAGS@ diff --git a/libjava/classpath/native/jni/java-lang/Makefile.in b/libjava/classpath/native/jni/java-lang/Makefile.in new file mode 100644 index 000000000..148ba7f8c --- /dev/null +++ b/libjava/classpath/native/jni/java-lang/Makefile.in @@ -0,0 +1,642 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +subdir = native/jni/java-lang +DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/../../config/depstand.m4 \ + $(top_srcdir)/../../config/lead-dot.m4 \ + $(top_srcdir)/../../config/lib-ld.m4 \ + $(top_srcdir)/../../config/lib-link.m4 \ + $(top_srcdir)/../../config/lib-prefix.m4 \ + $(top_srcdir)/../../config/multi.m4 \ + $(top_srcdir)/../../config/no-executables.m4 \ + $(top_srcdir)/../../config/override.m4 \ + $(top_srcdir)/../../libtool.m4 \ + $(top_srcdir)/../../ltoptions.m4 \ + $(top_srcdir)/../../ltsugar.m4 \ + $(top_srcdir)/../../ltversion.m4 \ + $(top_srcdir)/../../lt~obsolete.m4 \ + $(top_srcdir)/m4/ac_prog_antlr.m4 \ + $(top_srcdir)/m4/ac_prog_java.m4 \ + $(top_srcdir)/m4/ac_prog_java_works.m4 \ + $(top_srcdir)/m4/ac_prog_javac.m4 \ + $(top_srcdir)/m4/ac_prog_javac_works.m4 \ + $(top_srcdir)/m4/acattribute.m4 $(top_srcdir)/m4/accross.m4 \ + $(top_srcdir)/m4/acinclude.m4 \ + $(top_srcdir)/m4/ax_create_stdint_h.m4 \ + $(top_srcdir)/m4/ax_func_which_gethostbyname_r.m4 \ + $(top_srcdir)/m4/gcc_attribute.m4 $(top_srcdir)/m4/iconv.m4 \ + $(top_srcdir)/m4/pkg.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/../../mkinstalldirs +CONFIG_HEADER = $(top_builddir)/include/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__installdirs = "$(DESTDIR)$(nativeexeclibdir)" +LTLIBRARIES = $(nativeexeclib_LTLIBRARIES) +libjavalang_la_DEPENDENCIES = \ + $(top_builddir)/native/fdlibm/libfdlibm.la \ + $(top_builddir)/native/jni/classpath/jcl.lo \ + $(top_builddir)/native/jni/native-lib/libclasspathnative.la +am_libjavalang_la_OBJECTS = java_lang_VMSystem.lo java_lang_VMFloat.lo \ + java_lang_VMDouble.lo java_lang_VMMath.lo \ + java_lang_VMProcess.lo +libjavalang_la_OBJECTS = $(am_libjavalang_la_OBJECTS) +libjavalangmanagement_la_LIBADD = +am_libjavalangmanagement_la_OBJECTS = \ + gnu_java_lang_management_VMOperatingSystemMXBeanImpl.lo +libjavalangmanagement_la_OBJECTS = \ + $(am_libjavalangmanagement_la_OBJECTS) +libjavalangreflect_la_LIBADD = +am_libjavalangreflect_la_OBJECTS = java_lang_reflect_VMArray.lo +libjavalangreflect_la_OBJECTS = $(am_libjavalangreflect_la_OBJECTS) +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/include +depcomp = $(SHELL) $(top_srcdir)/../../depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(libjavalang_la_SOURCES) \ + $(libjavalangmanagement_la_SOURCES) \ + $(libjavalangreflect_la_SOURCES) +ETAGS = etags +CTAGS = ctags +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +ANTLR = @ANTLR@ +ANTLR_JAR = @ANTLR_JAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CAIRO_CFLAGS = @CAIRO_CFLAGS@ +CAIRO_LIBS = @CAIRO_LIBS@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CLASSPATH_CONVENIENCE = @CLASSPATH_CONVENIENCE@ +CLASSPATH_INCLUDES = @CLASSPATH_INCLUDES@ +CLASSPATH_MODULE = @CLASSPATH_MODULE@ +COLLECTIONS_PREFIX = @COLLECTIONS_PREFIX@ +CP = @CP@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DATE = @DATE@ +DEFAULT_PREFS_PEER = @DEFAULT_PREFS_PEER@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +ECJ_JAR = @ECJ_JAR@ +EGREP = @EGREP@ +ERROR_CFLAGS = @ERROR_CFLAGS@ +EXAMPLESDIR = @EXAMPLESDIR@ +EXEEXT = @EXEEXT@ +EXTRA_CFLAGS = @EXTRA_CFLAGS@ +FGREP = @FGREP@ +FIND = @FIND@ +FREETYPE2_CFLAGS = @FREETYPE2_CFLAGS@ +FREETYPE2_LIBS = @FREETYPE2_LIBS@ +GCONF_CFLAGS = @GCONF_CFLAGS@ +GCONF_LIBS = @GCONF_LIBS@ +GDK_CFLAGS = @GDK_CFLAGS@ +GDK_LIBS = @GDK_LIBS@ +GJDOC = @GJDOC@ +GLIB_CFLAGS = @GLIB_CFLAGS@ +GLIB_LIBS = @GLIB_LIBS@ +GMP_CFLAGS = @GMP_CFLAGS@ +GMP_LIBS = @GMP_LIBS@ +GREP = @GREP@ +GSTREAMER_BASE_CFLAGS = @GSTREAMER_BASE_CFLAGS@ +GSTREAMER_BASE_LIBS = @GSTREAMER_BASE_LIBS@ +GSTREAMER_CFLAGS = @GSTREAMER_CFLAGS@ +GSTREAMER_FILE_READER = @GSTREAMER_FILE_READER@ +GSTREAMER_LIBS = @GSTREAMER_LIBS@ +GSTREAMER_MIXER_PROVIDER = @GSTREAMER_MIXER_PROVIDER@ +GSTREAMER_PLUGINS_BASE_CFLAGS = @GSTREAMER_PLUGINS_BASE_CFLAGS@ +GSTREAMER_PLUGINS_BASE_LIBS = @GSTREAMER_PLUGINS_BASE_LIBS@ +GST_PLUGIN_LDFLAGS = @GST_PLUGIN_LDFLAGS@ +GTK_CFLAGS = @GTK_CFLAGS@ +GTK_LIBS = @GTK_LIBS@ +INIT_LOAD_LIBRARY = @INIT_LOAD_LIBRARY@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAR = @JAR@ +JAVA = @JAVA@ +JAVAC = @JAVAC@ +JAVAC_IS_GCJ = @JAVAC_IS_GCJ@ +JAVAC_MEM_OPT = @JAVAC_MEM_OPT@ +JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION = @JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION@ +JAY = @JAY@ +JAY_SKELETON = @JAY_SKELETON@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBDEBUG = @LIBDEBUG@ +LIBICONV = @LIBICONV@ +LIBMAGIC = @LIBMAGIC@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBVERSION = @LIBVERSION@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBICONV = @LTLIBICONV@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MKDIR = @MKDIR@ +MKDIR_P = @MKDIR_P@ +MOC = @MOC@ +MOZILLA_CFLAGS = @MOZILLA_CFLAGS@ +MOZILLA_LIBS = @MOZILLA_LIBS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PANGOFT2_CFLAGS = @PANGOFT2_CFLAGS@ +PANGOFT2_LIBS = @PANGOFT2_LIBS@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PATH_TO_ESCHER = @PATH_TO_ESCHER@ +PATH_TO_GLIBJ_ZIP = @PATH_TO_GLIBJ_ZIP@ +PERL = @PERL@ +PKG_CONFIG = @PKG_CONFIG@ +PLUGIN_DIR = @PLUGIN_DIR@ +QT_CFLAGS = @QT_CFLAGS@ +QT_LIBS = @QT_LIBS@ +RANLIB = @RANLIB@ +REMOVE = @REMOVE@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRICT_WARNING_CFLAGS = @STRICT_WARNING_CFLAGS@ +STRIP = @STRIP@ +TOOLSDIR = @TOOLSDIR@ +USER_JAVAH = @USER_JAVAH@ +VERSION = @VERSION@ +WANT_NATIVE_BIG_INTEGER = @WANT_NATIVE_BIG_INTEGER@ +WARNING_CFLAGS = @WARNING_CFLAGS@ +XMKMF = @XMKMF@ +XML_CFLAGS = @XML_CFLAGS@ +XML_LIBS = @XML_LIBS@ +XSLT_CFLAGS = @XSLT_CFLAGS@ +XSLT_LIBS = @XSLT_LIBS@ +XTEST_LIBS = @XTEST_LIBS@ +X_CFLAGS = @X_CFLAGS@ +X_EXTRA_LIBS = @X_EXTRA_LIBS@ +X_LIBS = @X_LIBS@ +X_PRE_LIBS = @X_PRE_LIBS@ +ZIP = @ZIP@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_ANTLR = @ac_ct_ANTLR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +default_toolkit = @default_toolkit@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +glibjdir = @glibjdir@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +multi_basedir = @multi_basedir@ +nativeexeclibdir = @nativeexeclibdir@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +toolexeclibdir = @toolexeclibdir@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +uudecode = @uudecode@ +vm_classes = @vm_classes@ +nativeexeclib_LTLIBRARIES = libjavalang.la libjavalangreflect.la libjavalangmanagement.la +libjavalang_la_SOURCES = java_lang_VMSystem.c \ + java_lang_VMFloat.c \ + java_lang_VMDouble.c \ + java_lang_VMMath.c \ + java_lang_VMProcess.c + +libjavalang_la_LIBADD = $(top_builddir)/native/fdlibm/libfdlibm.la \ + $(top_builddir)/native/jni/classpath/jcl.lo \ + $(top_builddir)/native/jni/native-lib/libclasspathnative.la + +libjavalangreflect_la_SOURCES = java_lang_reflect_VMArray.c +libjavalangmanagement_la_SOURCES = gnu_java_lang_management_VMOperatingSystemMXBeanImpl.c +AM_LDFLAGS = @CLASSPATH_MODULE@ +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ -I$(top_srcdir)/native/fdlibm +AM_CFLAGS = @WARNING_CFLAGS@ @STRICT_WARNING_CFLAGS@ @ERROR_CFLAGS@ \ + @EXTRA_CFLAGS@ + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu native/jni/java-lang/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu native/jni/java-lang/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-nativeexeclibLTLIBRARIES: $(nativeexeclib_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(nativeexeclibdir)" || $(MKDIR_P) "$(DESTDIR)$(nativeexeclibdir)" + @list='$(nativeexeclib_LTLIBRARIES)'; test -n "$(nativeexeclibdir)" || list=; \ + list2=; for p in $$list; do \ + if test -f $$p; then \ + list2="$$list2 $$p"; \ + else :; fi; \ + done; \ + test -z "$$list2" || { \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(nativeexeclibdir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(nativeexeclibdir)"; \ + } + +uninstall-nativeexeclibLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(nativeexeclib_LTLIBRARIES)'; test -n "$(nativeexeclibdir)" || list=; \ + for p in $$list; do \ + $(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(nativeexeclibdir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(nativeexeclibdir)/$$f"; \ + done + +clean-nativeexeclibLTLIBRARIES: + -test -z "$(nativeexeclib_LTLIBRARIES)" || rm -f $(nativeexeclib_LTLIBRARIES) + @list='$(nativeexeclib_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libjavalang.la: $(libjavalang_la_OBJECTS) $(libjavalang_la_DEPENDENCIES) + $(LINK) -rpath $(nativeexeclibdir) $(libjavalang_la_OBJECTS) $(libjavalang_la_LIBADD) $(LIBS) +libjavalangmanagement.la: $(libjavalangmanagement_la_OBJECTS) $(libjavalangmanagement_la_DEPENDENCIES) + $(LINK) -rpath $(nativeexeclibdir) $(libjavalangmanagement_la_OBJECTS) $(libjavalangmanagement_la_LIBADD) $(LIBS) +libjavalangreflect.la: $(libjavalangreflect_la_OBJECTS) $(libjavalangreflect_la_DEPENDENCIES) + $(LINK) -rpath $(nativeexeclibdir) $(libjavalangreflect_la_OBJECTS) $(libjavalangreflect_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_lang_management_VMOperatingSystemMXBeanImpl.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/java_lang_VMDouble.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/java_lang_VMFloat.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/java_lang_VMMath.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/java_lang_VMProcess.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/java_lang_VMSystem.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/java_lang_reflect_VMArray.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) +installdirs: + for dir in "$(DESTDIR)$(nativeexeclibdir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-nativeexeclibLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-nativeexeclibLTLIBRARIES + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-nativeexeclibLTLIBRARIES + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-nativeexeclibLTLIBRARIES ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags dvi dvi-am html html-am info info-am install \ + install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-nativeexeclibLTLIBRARIES install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-nativeexeclibLTLIBRARIES + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/libjava/classpath/native/jni/java-lang/gnu_java_lang_management_VMOperatingSystemMXBeanImpl.c b/libjava/classpath/native/jni/java-lang/gnu_java_lang_management_VMOperatingSystemMXBeanImpl.c new file mode 100644 index 000000000..d6f99ae9f --- /dev/null +++ b/libjava/classpath/native/jni/java-lang/gnu_java_lang_management_VMOperatingSystemMXBeanImpl.c @@ -0,0 +1,65 @@ +/* VMOperatingSystemMXBeanImpl.c - gnu.java.lang.management native functions + Copyright (C) 2006 + Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include + +#if defined HAVE_SYS_LOADAVG_H /* Get getloadavg() on Solaris 9 */ +#include +#else +#include +#endif + +#include "gnu_java_lang_management_VMOperatingSystemMXBeanImpl.h" + +/* + * Class: gnu_java_lang_management_VMOperatingSystemMXBeanImpl + * Method: getSystemLoadAverage + * Signature: ()D + */ +JNIEXPORT jdouble JNICALL +Java_gnu_java_lang_management_VMOperatingSystemMXBeanImpl_getSystemLoadAverage (JNIEnv * env __attribute__ ((__unused__)), jclass cls __attribute__ ((__unused__))) +{ +#ifdef HAVE_GETLOADAVG + double avg[1]; + int nos = getloadavg(avg, 1); + if (nos == 1) + return avg[0]; + else +#endif + return -1; +} diff --git a/libjava/classpath/native/jni/java-lang/java_lang_VMDouble.c b/libjava/classpath/native/jni/java-lang/java_lang_VMDouble.c new file mode 100644 index 000000000..e915a3089 --- /dev/null +++ b/libjava/classpath/native/jni/java-lang/java_lang_VMDouble.c @@ -0,0 +1,455 @@ +/* VMDouble.c - java.lang.VMDouble native functions + Copyright (C) 1998, 1999, 2001, 2003, 2004, 2005, 2006, 2007 + Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#include +#include +#include +#include +#include + +#include "mprec.h" +#include "fdlibm.h" +#include "jcl.h" + +#include "java_lang_VMDouble.h" + +static jclass clsDouble; +static jmethodID isNaNID; +static jdouble NEGATIVE_INFINITY; +static jdouble POSITIVE_INFINITY; +static jdouble NaN; + +/* + * Class: java_lang_VMDouble + * Method: initIDs + * Signature: ()V + */ +JNIEXPORT void JNICALL +Java_java_lang_VMDouble_initIDs (JNIEnv * env, jclass cls __attribute__ ((__unused__))) +{ + jfieldID negInfID; + jfieldID posInfID; + jfieldID nanID; + + clsDouble = (*env)->FindClass (env, "java/lang/Double"); + if (clsDouble == NULL) + { + DBG ("unable to get class java.lang.Double\n") return; + } + clsDouble = (*env)->NewGlobalRef(env, clsDouble); + if (clsDouble == NULL) + { + DBG ("unable to register class java.lang.Double as global ref\n") return; + } + isNaNID = (*env)->GetStaticMethodID (env, clsDouble, "isNaN", "(D)Z"); + if (isNaNID == NULL) + { + DBG ("unable to determine method id of isNaN\n") return; + } + negInfID = (*env)->GetStaticFieldID (env, clsDouble, "NEGATIVE_INFINITY", "D"); + if (negInfID == NULL) + { + DBG ("unable to determine field id of NEGATIVE_INFINITY\n") return; + } + posInfID = (*env)->GetStaticFieldID (env, clsDouble, "POSITIVE_INFINITY", "D"); + if (posInfID == NULL) + { + DBG ("unable to determine field id of POSITIVE_INFINITY\n") return; + } + nanID = (*env)->GetStaticFieldID (env, clsDouble, "NaN", "D"); + if (posInfID == NULL) + { + DBG ("unable to determine field id of NaN\n") return; + } + POSITIVE_INFINITY = (*env)->GetStaticDoubleField (env, clsDouble, posInfID); + NEGATIVE_INFINITY = (*env)->GetStaticDoubleField (env, clsDouble, negInfID); + NaN = (*env)->GetStaticDoubleField (env, clsDouble, nanID); + +#ifdef DEBUG + fprintf (stderr, "java.lang.Double.initIDs() POSITIVE_INFINITY = %g\n", + POSITIVE_INFINITY); + fprintf (stderr, "java.lang.Double.initIDs() NEGATIVE_INFINITY = %g\n", + NEGATIVE_INFINITY); + fprintf (stderr, "java.lang.Double.initIDs() NaN = %g\n", NaN); +#endif +} + +/* + * Class: java_lang_VMDouble + * Method: doubleToRawLongBits + * Signature: (D)J + */ +JNIEXPORT jlong JNICALL +Java_java_lang_VMDouble_doubleToRawLongBits + (JNIEnv * env __attribute__ ((__unused__)), + jclass cls __attribute__ ((__unused__)), jdouble doubleValue) +{ + jvalue val; + + val.d = doubleValue; + +#if defined(__IEEE_BYTES_LITTLE_ENDIAN) + /* On little endian ARM processors when using FPA, word order of + doubles is still big endian. So take that into account here. When + using VFP, word order of doubles follows byte order. */ + +#define SWAP_DOUBLE(a) (((a) << 32) | (((a) >> 32) & 0x00000000ffffffff)) + + val.j = SWAP_DOUBLE(val.j); +#endif + + return val.j; +} + +/* + * Class: java_lang_VMDouble + * Method: longBitsToDouble + * Signature: (J)D + */ +JNIEXPORT jdouble JNICALL +Java_java_lang_VMDouble_longBitsToDouble + (JNIEnv * env __attribute__ ((__unused__)), + jclass cls __attribute__ ((__unused__)), jlong longValue) +{ + jvalue val; + + val.j = longValue; + +#if defined(__IEEE_BYTES_LITTLE_ENDIAN) + val.j = SWAP_DOUBLE(val.j); +#endif + + return val.d; +} + +/** + * Parse a double from a char array. + */ +static jdouble +parseDoubleFromChars(JNIEnv * env, const char * buf) +{ + char *endptr; + jdouble val = 0.0; + const char *p = buf, *end, *last_non_ws, *temp; + int ok = 1; + +#ifdef DEBUG + fprintf (stderr, "java.lang.VMDouble.parseDouble (%s)\n", buf); +#endif + + /* Trim the buffer, similar to String.trim(). First the leading + characters. */ + while (*p && *p <= ' ') + ++p; + + /* Find the last non-whitespace character. This method is safe + even with multi-byte UTF-8 characters. */ + end = p; + last_non_ws = NULL; + while (*end) + { + if (*end > ' ') + last_non_ws = end; + ++end; + } + + if (last_non_ws == NULL) + last_non_ws = p + strlen (p); + else + { + /* Skip past the last non-whitespace character. */ + ++last_non_ws; + } + + /* Check for infinity and NaN */ + temp = p; + if (temp[0] == '+' || temp[0] == '-') + temp++; + if (strncmp ("Infinity", temp, (size_t) 8) == 0) + { + if (p[0] == '-') + return NEGATIVE_INFINITY; + return POSITIVE_INFINITY; + } + if (strncmp ("NaN", temp, (size_t) 3) == 0) + return NaN; + + /* Skip a trailing `f' or `d'. */ + if (last_non_ws > p + && (last_non_ws[-1] == 'f' + || last_non_ws[-1] == 'F' + || last_non_ws[-1] == 'd' || last_non_ws[-1] == 'D')) + --last_non_ws; + + if (last_non_ws > p) + { + struct _Jv_reent reent; + memset (&reent, 0, sizeof reent); + + val = _strtod_r (&reent, p, &endptr); + +#ifdef DEBUG + fprintf (stderr, "java.lang.VMDouble.parseDouble val = %g\n", val); + fprintf (stderr, "java.lang.VMDouble.parseDouble %p != %p ???\n", + endptr, last_non_ws); +#endif + if (endptr != last_non_ws) + ok = 0; + } + else + ok = 0; + + if (!ok) + { + val = 0.0; + JCL_ThrowException (env, + "java/lang/NumberFormatException", + "unable to parse double"); + } + + return val; +} + +#define MAXIMAL_DECIMAL_STRING_LENGTH 64 + +/** + * Use _dtoa to print a double or a float as a string with the given precision. + */ +static void +dtoa_toString +(char * buffer, jdouble value, jint precision, jboolean isFloat) +{ + const int DTOA_MODE = 2; + char result[MAXIMAL_DECIMAL_STRING_LENGTH]; + int decpt, sign; + char *s, *d; + int i; + + /* use mode 2 to get at the digit stream, all other modes are useless + * + * since mode 2 only gives us as many digits as we need in precision, we need to + * add the digits in front of the floating point to it, if there is more than one + * to be printed. That's the case if the value is going to be printed using the + * normal notation, i.e. if it is 0 or >= 1.0e-3 and < 1.0e7. + */ + int digits_in_front_of_floating_point = ceil(log10(value)); + + if (digits_in_front_of_floating_point > 1 && digits_in_front_of_floating_point < 7) + precision += digits_in_front_of_floating_point; + + _dtoa (value, DTOA_MODE, precision, &decpt, &sign, NULL, buffer, (int) isFloat); + + value = fabs (value); + + s = buffer; + d = result; + + /* Handle negative sign */ + if (sign) + *d++ = '-'; + + /* Handle normal represenation */ + if ((value >= 1e-3 && value < 1e7) || (value == 0)) + { + if (decpt <= 0) + *d++ = '0'; + else + { + for (i = 0; i < decpt; i++) + if (*s) + *d++ = *s++; + else + *d++ = '0'; + } + + *d++ = '.'; + + if (*s == 0) + { + *d++ = '0'; + decpt++; + } + + while (decpt++ < 0) + *d++ = '0'; + + while (*s) + *d++ = *s++; + + *d = 0; + + } + /* Handle scientific representaiton */ + else + { + *d++ = *s++; + decpt--; + *d++ = '.'; + + if (*s == 0) + *d++ = '0'; + + while (*s) + *d++ = *s++; + + *d++ = 'E'; + + if (decpt < 0) + { + *d++ = '-'; + decpt = -decpt; + } + + { + char exp[4]; + char *e = exp + sizeof exp; + + *--e = 0; + do + { + *--e = '0' + decpt % 10; + decpt /= 10; + } + while (decpt > 0); + + while (*e) + *d++ = *e++; + } + + *d = 0; + } + + /* copy the result into the buffer */ + memcpy(buffer, result, MAXIMAL_DECIMAL_STRING_LENGTH); +} + +/* + * Class: java_lang_VMDouble + * Method: toString + * Signature: (DZ)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL +Java_java_lang_VMDouble_toString + (JNIEnv * env, jclass cls __attribute__ ((__unused__)), jdouble value, jboolean isFloat) +{ + char buf[MAXIMAL_DECIMAL_STRING_LENGTH]; + const jint MAXIMAL_FLOAT_PRECISION = 10; + const jint MAXIMAL_DOUBLE_PRECISION = 19; + + jint maximal_precision; + jint least_necessary_precision = 2; + jboolean parsed_value_unequal; + + if ((*env)->CallStaticBooleanMethod (env, clsDouble, isNaNID, value)) + return (*env)->NewStringUTF (env, "NaN"); + + if (value == POSITIVE_INFINITY) + return (*env)->NewStringUTF (env, "Infinity"); + + if (value == NEGATIVE_INFINITY) + return (*env)->NewStringUTF (env, "-Infinity"); + + if (isFloat) + maximal_precision = MAXIMAL_FLOAT_PRECISION; + else + maximal_precision = MAXIMAL_DOUBLE_PRECISION; + + /* Try to find the 'good enough' precision, + * that results in enough digits being printed to be able to + * convert the number back into the original double, but no + * further digits. + */ + + do { + jdouble parsed_value; + + assert(least_necessary_precision <= maximal_precision); + + /* Convert the value to a string and back. */ + dtoa_toString(buf, value, least_necessary_precision, isFloat); + + parsed_value = parseDoubleFromChars(env, buf); + + /* Check whether the original value, and the value after conversion match. */ + /* We need to cast floats to float to make sure that our ineqality check works + * well for floats as well as for doubles. + */ + parsed_value_unequal = ( isFloat ? + (float) parsed_value != (float) value : + parsed_value != value); + + least_necessary_precision++; + } + while (parsed_value_unequal); + + return (*env)->NewStringUTF (env, buf); +} + +/* + * Class: java_lang_VMDouble + * Method: parseDouble + * Signature: (Ljava/lang/String;)D + */ +JNIEXPORT jdouble JNICALL +Java_java_lang_VMDouble_parseDouble + (JNIEnv * env, jclass cls __attribute__ ((__unused__)), jstring str) +{ + jboolean isCopy; + const char *buf; + jdouble val = 0.0; + + if (str == NULL) + { + JCL_ThrowException (env, "java/lang/NullPointerException", "null"); + return val; + } + + buf = (*env)->GetStringUTFChars (env, str, &isCopy); + if (buf == NULL) + { + /* OutOfMemoryError already thrown */ + } + else + { + val = parseDoubleFromChars(env, buf); + (*env)->ReleaseStringUTFChars (env, str, buf); + } + + return val; +} diff --git a/libjava/classpath/native/jni/java-lang/java_lang_VMFloat.c b/libjava/classpath/native/jni/java-lang/java_lang_VMFloat.c new file mode 100644 index 000000000..acd07ffa5 --- /dev/null +++ b/libjava/classpath/native/jni/java-lang/java_lang_VMFloat.c @@ -0,0 +1,71 @@ +/* VMFloat.c - java.lang.VMFloat native functions + Copyright (C) 1998, 1999, 2003, 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#include + +#include "java_lang_VMFloat.h" + +/* + * Class: java_lang_VMFloat + * Method: floatToRawIntBits + * Signature: (F)I + */ +JNIEXPORT jint JNICALL +Java_java_lang_VMFloat_floatToRawIntBits + (JNIEnv * env __attribute__ ((__unused__)), + jclass cls __attribute__ ((__unused__)), jfloat value) +{ + jvalue u; + u.f = value; + return u.i; +} + +/* + * Class: java_lang_VMFloat + * Method: intBitsToFloat + * Signature: (I)F + */ +JNIEXPORT jfloat JNICALL +Java_java_lang_VMFloat_intBitsToFloat + (JNIEnv * env __attribute__ ((__unused__)), + jclass cls __attribute__ ((__unused__)), jint bits) +{ + jvalue u; + u.i = bits; + return u.f; +} diff --git a/libjava/classpath/native/jni/java-lang/java_lang_VMMath.c b/libjava/classpath/native/jni/java-lang/java_lang_VMMath.c new file mode 100644 index 000000000..de7851f9b --- /dev/null +++ b/libjava/classpath/native/jni/java-lang/java_lang_VMMath.c @@ -0,0 +1,225 @@ +/* VMMath.c - java.lang.VMMath native functions + Copyright (C) 1998, 1999, 2004, 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#include +#include +#include + +JNIEXPORT jdouble JNICALL +Java_java_lang_VMMath_sin + (JNIEnv * env __attribute__ ((__unused__)), + jclass cls __attribute__ ((__unused__)), jdouble x) +{ + return sin (x); +} + +JNIEXPORT jdouble JNICALL +Java_java_lang_VMMath_cos + (JNIEnv * env __attribute__ ((__unused__)), + jclass cls __attribute__ ((__unused__)), jdouble x) +{ + return cos (x); +} + +JNIEXPORT jdouble JNICALL +Java_java_lang_VMMath_tan + (JNIEnv * env __attribute__ ((__unused__)), + jclass cls __attribute__ ((__unused__)), jdouble x) +{ + return tan (x); +} + +JNIEXPORT jdouble JNICALL +Java_java_lang_VMMath_asin + (JNIEnv * env __attribute__ ((__unused__)), + jclass cls __attribute__ ((__unused__)), jdouble x) +{ + return asin (x); +} + +JNIEXPORT jdouble JNICALL +Java_java_lang_VMMath_acos + (JNIEnv * env __attribute__ ((__unused__)), + jclass cls __attribute__ ((__unused__)), jdouble x) +{ + return acos (x); +} + +JNIEXPORT jdouble JNICALL +Java_java_lang_VMMath_atan + (JNIEnv * env __attribute__ ((__unused__)), + jclass cls __attribute__ ((__unused__)), jdouble x) +{ + return atan (x); +} + +JNIEXPORT jdouble JNICALL +Java_java_lang_VMMath_atan2 + (JNIEnv * env __attribute__ ((__unused__)), + jclass cls __attribute__ ((__unused__)), jdouble y, jdouble x) +{ + return atan2 (y, x); +} + +JNIEXPORT jdouble JNICALL +Java_java_lang_VMMath_exp + (JNIEnv * env __attribute__ ((__unused__)), + jclass cls __attribute__ ((__unused__)), jdouble x) +{ + return exp (x); +} + +JNIEXPORT jdouble JNICALL +Java_java_lang_VMMath_log + (JNIEnv * env __attribute__ ((__unused__)), + jclass cls __attribute__ ((__unused__)), jdouble x) +{ + return log (x); +} + +JNIEXPORT jdouble JNICALL +Java_java_lang_VMMath_sqrt + (JNIEnv * env __attribute__ ((__unused__)), + jclass cls __attribute__ ((__unused__)), jdouble x) +{ + return sqrt (x); +} + +JNIEXPORT jdouble JNICALL +Java_java_lang_VMMath_pow + (JNIEnv * env __attribute__ ((__unused__)), + jclass cls __attribute__ ((__unused__)), jdouble x, jdouble y) +{ + return pow (x, y); +} + +JNIEXPORT jdouble JNICALL +Java_java_lang_VMMath_IEEEremainder + (JNIEnv * env __attribute__ ((__unused__)), + jclass cls __attribute__ ((__unused__)), jdouble x, jdouble y) +{ + return remainder (x, y); +} + +JNIEXPORT jdouble JNICALL +Java_java_lang_VMMath_ceil + (JNIEnv * env __attribute__ ((__unused__)), + jclass cls __attribute__ ((__unused__)), jdouble x) +{ + return ceil (x); +} + +JNIEXPORT jdouble JNICALL +Java_java_lang_VMMath_floor + (JNIEnv * env __attribute__ ((__unused__)), + jclass cls __attribute__ ((__unused__)), jdouble x) +{ + return floor (x); +} + +JNIEXPORT jdouble JNICALL +Java_java_lang_VMMath_rint + (JNIEnv * env __attribute__ ((__unused__)), + jclass cls __attribute__ ((__unused__)), jdouble x) +{ + return rint (x); +} + +JNIEXPORT jdouble JNICALL +Java_java_lang_VMMath_cbrt + (JNIEnv * env __attribute__ ((__unused__)), + jclass cls __attribute__ ((__unused__)), jdouble x) +{ + return cbrt (x); +} + +JNIEXPORT jdouble JNICALL +Java_java_lang_VMMath_cosh + (JNIEnv * env __attribute__ ((__unused__)), + jclass cls __attribute__ ((__unused__)), jdouble x) +{ + return cosh (x); +} + +JNIEXPORT jdouble JNICALL +Java_java_lang_VMMath_expm1 + (JNIEnv * env __attribute__ ((__unused__)), + jclass cls __attribute__ ((__unused__)), jdouble x) +{ + return expm1 (x); +} + +JNIEXPORT jdouble JNICALL +Java_java_lang_VMMath_hypot + (JNIEnv * env __attribute__ ((__unused__)), + jclass cls __attribute__ ((__unused__)), jdouble x, jdouble y) +{ + return hypot (x, y); +} + +JNIEXPORT jdouble JNICALL +Java_java_lang_VMMath_log10 + (JNIEnv * env __attribute__ ((__unused__)), + jclass cls __attribute__ ((__unused__)), jdouble x) +{ + return log10 (x); +} + +JNIEXPORT jdouble JNICALL +Java_java_lang_VMMath_log1p + (JNIEnv * env __attribute__ ((__unused__)), + jclass cls __attribute__ ((__unused__)), jdouble x) +{ + return log1p (x); +} + +JNIEXPORT jdouble JNICALL +Java_java_lang_VMMath_sinh + (JNIEnv * env __attribute__ ((__unused__)), + jclass cls __attribute__ ((__unused__)), jdouble x) +{ + return sinh (x); +} + +JNIEXPORT jdouble JNICALL +Java_java_lang_VMMath_tanh + (JNIEnv * env __attribute__ ((__unused__)), + jclass cls __attribute__ ((__unused__)), jdouble x) +{ + return tanh (x); +} diff --git a/libjava/classpath/native/jni/java-lang/java_lang_VMProcess.c b/libjava/classpath/native/jni/java-lang/java_lang_VMProcess.c new file mode 100644 index 000000000..a6076f2ae --- /dev/null +++ b/libjava/classpath/native/jni/java-lang/java_lang_VMProcess.c @@ -0,0 +1,409 @@ +/* java_lang_VMProcess.c -- native code for java.lang.VMProcess + Copyright (C) 1998, 1999, 2000, 2002, 2004, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include + +#include "java_lang_VMProcess.h" +#include "gnu_java_nio_FileChannelImpl.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "cpnative.h" +#include "cpproc.h" + +/* Internal functions */ +static char *copy_string (JNIEnv * env, jobject string); +static char *copy_elem (JNIEnv * env, jobject stringArray, jint i); + +/* + * Internal helper function to copy a String in UTF-8 format. + */ +static char * +copy_string (JNIEnv * env, jobject string) +{ + const char *utf; + jclass clazz; + char *copy; + + /* Check for null */ + if (string == NULL) + { + clazz = (*env)->FindClass (env, "java/lang/NullPointerException"); + if ((*env)->ExceptionOccurred (env)) + return NULL; + (*env)->ThrowNew (env, clazz, NULL); + (*env)->DeleteLocalRef (env, clazz); + return NULL; + } + + /* Extract UTF-8 */ + utf = (*env)->GetStringUTFChars (env, string, NULL); + if ((*env)->ExceptionOccurred (env)) + return NULL; + + /* Copy it */ + if ((copy = strdup (utf)) == NULL) + { + clazz = (*env)->FindClass (env, "java/lang/InternalError"); + if ((*env)->ExceptionOccurred (env)) + return NULL; + (*env)->ThrowNew (env, clazz, "strdup returned NULL"); + (*env)->DeleteLocalRef (env, clazz); + } + + /* Done */ + (*env)->ReleaseStringUTFChars (env, string, utf); + return copy; +} + +/* + * Internal helper function to copy a String[] element in UTF-8 format. + */ +static char * +copy_elem (JNIEnv * env, jobject stringArray, jint i) +{ + jobject elem; + char *rtn; + + elem = (*env)->GetObjectArrayElement (env, stringArray, i); + if ((*env)->ExceptionOccurred (env)) + return NULL; + if ((rtn = copy_string (env, elem)) == NULL) + return NULL; + (*env)->DeleteLocalRef (env, elem); + return rtn; +} + +/* + * private final native void nativeSpawn(String[], String[], File) + * throws java/io/IOException + */ +JNIEXPORT void JNICALL +Java_java_lang_VMProcess_nativeSpawn (JNIEnv * env, jobject this, + jobjectArray cmdArray, + jobjectArray envArray, jobject dirFile, + jboolean redirect) +{ + int fds[CPIO_EXEC_NUM_PIPES]; + jobject streams[CPIO_EXEC_NUM_PIPES] = { NULL, NULL, NULL }; + jobject dirString = NULL; + char **newEnviron = NULL; + jsize cmdArrayLen = 0; + jsize envArrayLen = 0; + char **strings = NULL; + int num_strings = 0; + char *dir = NULL; + pid_t pid = -1; + char errbuf[64]; + jmethodID method, vmmethod; + jclass clazz, vmclazz; + int i; + int pipe_count = redirect ? 2 : 3; + int err; + + /* Check for null */ + if (cmdArray == NULL) + goto null_pointer_exception; + + /* Invoke dirFile.getPath() */ + if (dirFile != NULL) + { + clazz = (*env)->FindClass (env, "java/io/File"); + if ((*env)->ExceptionOccurred (env)) + return; + method = (*env)->GetMethodID (env, + clazz, "getPath", "()Ljava/lang/String;"); + if ((*env)->ExceptionOccurred (env)) + return; + dirString = (*env)->CallObjectMethod (env, dirFile, method); + if ((*env)->ExceptionOccurred (env)) + return; + (*env)->DeleteLocalRef (env, clazz); + } + + /* + * Allocate array of C strings. We put all the C strings we need to + * handle the command parameters, the new environment, and the new + * directory into a single array for simplicity of (de)allocation. + */ + cmdArrayLen = (*env)->GetArrayLength (env, cmdArray); + if (cmdArrayLen == 0) + goto null_pointer_exception; + if (envArray != NULL) + envArrayLen = (*env)->GetArrayLength (env, envArray); + if ((strings = malloc (((cmdArrayLen + 1) + + (envArray != NULL ? envArrayLen + 1 : 0) + + (dirString != + NULL ? 1 : 0)) * sizeof (*strings))) == NULL) + { + strncpy (errbuf, "malloc failed", sizeof(errbuf)); + goto out_of_memory; + } + + /* Extract C strings from the various String parameters */ + for (i = 0; i < cmdArrayLen; i++) + { + if ((strings[num_strings++] = copy_elem (env, cmdArray, i)) == NULL) + goto done; + } + strings[num_strings++] = NULL; /* terminate array with NULL */ + if (envArray != NULL) + { + newEnviron = strings + num_strings; + for (i = 0; i < envArrayLen; i++) + { + if ((strings[num_strings++] = copy_elem (env, envArray, i)) == NULL) + goto done; + } + strings[num_strings++] = NULL; /* terminate array with NULL */ + } + if (dirString != NULL) + { + if ((dir = copy_string (env, dirString)) == NULL) + goto done; + } + + /* Create inter-process pipes */ + err = cpproc_forkAndExec(strings, newEnviron, fds, pipe_count, &pid, dir); + if (err != 0) + { + strncpy(errbuf, cpnative_getErrorString (err), sizeof(errbuf)); + goto system_error; + } + + /* Create Input/OutputStream objects around parent file descriptors */ + vmclazz = (*env)->FindClass (env, "gnu/java/nio/VMChannel"); + clazz = (*env)->FindClass (env, "gnu/java/nio/FileChannelImpl"); + if ((*env)->ExceptionOccurred (env)) + goto done; + vmmethod = (*env)->GetMethodID (env, vmclazz, "", "(I)V"); + method = (*env)->GetMethodID (env, clazz, "", "(Lgnu/java/nio/VMChannel;I)V"); + if ((*env)->ExceptionOccurred (env)) + goto done; + for (i = 0; i < pipe_count; i++) + { + /* Mode is WRITE (2) for in and READ (1) for out and err. */ + const int fd = fds[i]; + const int mode = ((i == CPIO_EXEC_STDIN) ? 2 : 1); + jclass sclazz; + jmethodID smethod; + + jobject vmchannel; + jobject channel; + vmchannel = (*env)->NewObject (env, vmclazz, vmmethod, fd); + if ((*env)->ExceptionOccurred (env)) + goto done; + channel = (*env)->NewObject (env, clazz, method, vmchannel, mode); + if ((*env)->ExceptionOccurred (env)) + goto done; + + if (mode == gnu_java_nio_FileChannelImpl_WRITE) + sclazz = (*env)->FindClass (env, "java/io/FileOutputStream"); + else + sclazz = (*env)->FindClass (env, "java/io/FileInputStream"); + if ((*env)->ExceptionOccurred (env)) + goto done; + + smethod = (*env)->GetMethodID (env, sclazz, "", + "(Lgnu/java/nio/FileChannelImpl;)V"); + if ((*env)->ExceptionOccurred (env)) + goto done; + + streams[i] = (*env)->NewObject (env, sclazz, smethod, channel); + if ((*env)->ExceptionOccurred (env)) + goto done; + + (*env)->DeleteLocalRef (env, sclazz); + } + (*env)->DeleteLocalRef (env, clazz); + + /* Invoke VMProcess.setProcessInfo() to update VMProcess object */ + method = (*env)->GetMethodID (env, + (*env)->GetObjectClass (env, this), + "setProcessInfo", + "(Ljava/io/OutputStream;Ljava/io/InputStream;Ljava/io/InputStream;J)V"); + if ((*env)->ExceptionOccurred (env)) + goto done; + (*env)->CallVoidMethod (env, this, method, + streams[CPIO_EXEC_STDIN], + streams[CPIO_EXEC_STDOUT], + streams[CPIO_EXEC_STDERR], + (jlong) pid); + if ((*env)->ExceptionOccurred (env)) + goto done; + +done: + /* + * We get here in both the success and failure cases in the + * parent process. Our goal is to clean up the mess we created. + */ + + /* + * Close parent's ends of pipes if Input/OutputStreams never got created. + * This can only happen in a failure case. If a Stream object + * was created for a file descriptor, we don't close it because it + * will get closed when the Stream object is finalized. + */ + for (i = 0; i < pipe_count; i++) + { + const int fd = fds[i]; + + if (fd != -1 && streams[i] == NULL) + close (fd); + } + + /* Free C strings */ + while (num_strings > 0) + free (strings[--num_strings]); + free (strings); + if (dir != NULL) + free(dir); + /* Done */ + return; + +null_pointer_exception: + clazz = (*env)->FindClass (env, "java/lang/NullPointerException"); + if ((*env)->ExceptionOccurred (env)) + goto done; + (*env)->ThrowNew (env, clazz, NULL); + (*env)->DeleteLocalRef (env, clazz); + goto done; + +out_of_memory: + clazz = (*env)->FindClass (env, "java/lang/InternalError"); + if ((*env)->ExceptionOccurred (env)) + goto done; + (*env)->ThrowNew (env, clazz, errbuf); + (*env)->DeleteLocalRef (env, clazz); + goto done; + +system_error: + clazz = (*env)->FindClass (env, "java/io/IOException"); + if ((*env)->ExceptionOccurred (env)) + goto done; + (*env)->ThrowNew (env, clazz, errbuf); + (*env)->DeleteLocalRef (env, clazz); + goto done; +} + +/* + * private static final native boolean nativeReap() + */ +JNIEXPORT jboolean JNICALL +Java_java_lang_VMProcess_nativeReap (JNIEnv * env, jclass clazz) +{ + char ebuf[64]; + jfieldID field; + jint status; + pid_t pid; + int err; + + /* Try to reap a child process, but don't block */ + err = cpproc_waitpid((pid_t)-1, &status, &pid, WNOHANG); + if (err == 0 && pid == 0) + return JNI_FALSE; + + /* Check result from waitpid() */ + if (err != 0) + { + if (err == ECHILD || err == EINTR) + return JNI_FALSE; + snprintf(ebuf, sizeof (ebuf), "waitpid(%ld): %s", + (long) pid, cpnative_getErrorString(errno)); + clazz = (*env)->FindClass (env, "java/lang/InternalError"); + if ((*env)->ExceptionOccurred (env)) + return JNI_FALSE; + (*env)->ThrowNew (env, clazz, ebuf); + (*env)->DeleteLocalRef (env, clazz); + return JNI_FALSE; + } + + /* Get exit code; for signal termination return negative signal value XXX */ + if (WIFEXITED (status)) + status = (jint) (jbyte) WEXITSTATUS (status); + else if (WIFSIGNALED (status)) + status = -(jint) WTERMSIG (status); + else + return JNI_FALSE; /* process merely stopped; ignore */ + + /* Return process pid and exit status */ + field = (*env)->GetStaticFieldID (env, clazz, "reapedPid", "J"); + if ((*env)->ExceptionOccurred (env)) + return JNI_FALSE; + (*env)->SetStaticLongField (env, clazz, field, (jlong) pid); + if ((*env)->ExceptionOccurred (env)) + return JNI_FALSE; + field = (*env)->GetStaticFieldID (env, clazz, "reapedExitValue", "I"); + if ((*env)->ExceptionOccurred (env)) + return JNI_FALSE; + (*env)->SetStaticIntField (env, clazz, field, status); + if ((*env)->ExceptionOccurred (env)) + return JNI_FALSE; + + /* Done */ + return JNI_TRUE; +} + +/* + * private static final native void nativeKill(long) + */ +JNIEXPORT void JNICALL +Java_java_lang_VMProcess_nativeKill (JNIEnv * env, jclass clazz, jlong pid) +{ + char ebuf[64]; + int err; + + err = cpproc_kill((pid_t) pid, SIGKILL); + if (err != 0) + { + snprintf (ebuf, sizeof (ebuf), "kill(%ld): %s", + (long) pid, cpnative_getErrorString (err)); + clazz = (*env)->FindClass (env, "java/lang/InternalError"); + if ((*env)->ExceptionOccurred (env)) + return; + (*env)->ThrowNew (env, clazz, ebuf); + (*env)->DeleteLocalRef (env, clazz); + } +} diff --git a/libjava/classpath/native/jni/java-lang/java_lang_VMSystem.c b/libjava/classpath/native/jni/java-lang/java_lang_VMSystem.c new file mode 100644 index 000000000..d20322791 --- /dev/null +++ b/libjava/classpath/native/jni/java-lang/java_lang_VMSystem.c @@ -0,0 +1,189 @@ +/* System.c -- native code for java.lang.System + Copyright (C) 1998, 1999, 2000, 2002, 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include "java_lang_VMSystem.h" + +#include + +#include +#include + +/* + * Class: java_lang_VMSystem + * Method: setIn0 + * Signature: (Ljava/io/InputStream;)V + */ +JNIEXPORT void JNICALL +Java_java_lang_VMSystem_setIn (JNIEnv * env, + jclass thisClass __attribute__ ((__unused__)), + jobject obj) +{ + jclass cls; + jfieldID field; + + cls = JCL_FindClass (env, "java/lang/System"); + if (!cls) + return; + + field = (*env)->GetStaticFieldID (env, cls, "in", "Ljava/io/InputStream;"); + if (!field) + return; + (*env)->SetStaticObjectField (env, cls, field, obj); +} + +/* + * Class: java_lang_VMSystem + * Method: setOut0 + * Signature: (Ljava/io/PrintStream;)V + */ +JNIEXPORT void JNICALL +Java_java_lang_VMSystem_setOut (JNIEnv * env, + jclass thisClass __attribute__ ((__unused__)), + jobject obj) +{ + jclass cls; + jfieldID field; + + cls = JCL_FindClass (env, "java/lang/System"); + if (!cls) + return; + + field = (*env)->GetStaticFieldID (env, cls, "out", "Ljava/io/PrintStream;"); + if (!field) + return; + (*env)->SetStaticObjectField (env, cls, field, obj); +} + +/* + * Class: java_lang_VMSystem + * Method: setErr0 + * Signature: (Ljava/io/PrintStream;)V + */ +JNIEXPORT void JNICALL +Java_java_lang_VMSystem_setErr (JNIEnv * env, + jclass thisClass __attribute__ ((__unused__)), + jobject obj) +{ + jclass cls; + jfieldID field; + + cls = JCL_FindClass (env, "java/lang/System"); + if (!cls) + return; + + field = (*env)->GetStaticFieldID (env, cls, "err", "Ljava/io/PrintStream;"); + if (!field) + return; + (*env)->SetStaticObjectField (env, cls, field, obj); +} + +/* + * Class: java_lang_VMSystem + * Method: nanoTime + * Signature: ()J + */ +JNIEXPORT jlong JNICALL +Java_java_lang_VMSystem_nanoTime + (JNIEnv * env __attribute__ ((__unused__)), + jclass thisClass __attribute__ ((__unused__))) +{ + /* Note: this implementation copied directly from Japhar's, by Chris Toshok. */ + jlong result; + struct timeval tp; + + if (gettimeofday (&tp, NULL) == -1) + (*env)->FatalError (env, "gettimeofday call failed."); + + result = (jlong) tp.tv_sec; + result *= (jlong)1000000L; + result += (jlong)tp.tv_usec; + result *= (jlong)1000; + + return result; +} + +JNIEXPORT jstring JNICALL +Java_java_lang_VMSystem_getenv (JNIEnv * env, + jclass klass __attribute__ ((__unused__)), + jstring jname) +{ + const char *cname; + const char *envname; + + cname = JCL_jstring_to_cstring (env, jname); + if (cname == NULL) + return NULL; + + envname = getenv (cname); + if (envname == NULL) + return NULL; + + JCL_free_cstring (env, jname, cname); + return (*env)->NewStringUTF (env, envname); +} + +JNIEXPORT jobject JNICALL +Java_java_lang_VMSystem_environ (JNIEnv *env, + jclass klass __attribute__((__unused__))) +{ + char **env_pointer; + jobject variables; + jclass list_class; + jmethodID list_constructor; + jmethodID add; + + list_class = (*env)->FindClass(env, "java/util/LinkedList"); + if (list_class == NULL) + return NULL; + list_constructor = (*env)->GetMethodID(env, list_class, "", "()V"); + if (list_constructor == NULL) + return NULL; + variables = (*env)->NewObject(env, list_class, list_constructor); + if (variables == NULL) + return NULL; + add = (*env)->GetMethodID(env, list_class, "add", "(Ljava/lang/Object;)Z"); + if (add == NULL) + return NULL; + env_pointer = environ; + while (*env_pointer != NULL) + { + jstring string = (*env)->NewStringUTF(env, *env_pointer); + (*env)->CallBooleanMethod(env, variables, add, string); + ++env_pointer; + } + return variables; +} diff --git a/libjava/classpath/native/jni/java-lang/java_lang_reflect_VMArray.c b/libjava/classpath/native/jni/java-lang/java_lang_reflect_VMArray.c new file mode 100644 index 000000000..2db68ebf9 --- /dev/null +++ b/libjava/classpath/native/jni/java-lang/java_lang_reflect_VMArray.c @@ -0,0 +1,62 @@ +/* java.lang.reflect.Array native functions + Copyright (C) 1998, 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +/* + * java.lang.reflect.Array native functions. + * Author: John Keiser + * Version: 1.1.0 + * Date: 2 Jun 1998 + */ + +#include +#include + +#include "java_lang_reflect_VMArray.h" + +/* + * Class: java_lang_reflect_Array + * Method: createObjectArray + * Signature: (Ljava/lang/Class;I)Ljava/lang/Object; + */ +JNIEXPORT jobject JNICALL +Java_java_lang_reflect_VMArray_createObjectArray + (JNIEnv * env, + jclass thisClass __attribute__ ((__unused__)), + jclass arrayType, jint arrayLength) +{ + return (jobject) (*env)->NewObjectArray (env, arrayLength, arrayType, NULL); +} diff --git a/libjava/classpath/native/jni/java-math/Makefile.am b/libjava/classpath/native/jni/java-math/Makefile.am new file mode 100644 index 000000000..9bc756b6d --- /dev/null +++ b/libjava/classpath/native/jni/java-math/Makefile.am @@ -0,0 +1,11 @@ +nativeexeclib_LTLIBRARIES = libjavamath.la + +libjavamath_la_SOURCES = gnu_java_math_GMP.c + +libjavamath_la_LIBADD = $(top_builddir)/native/jni/classpath/jcl.lo + +libjavamath_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version + +AM_LDFLAGS = @CLASSPATH_MODULE@ @GMP_LIBS@ +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ +AM_CFLAGS = @WARNING_CFLAGS@ @ERROR_CFLAGS@ @GMP_CFLAGS@ diff --git a/libjava/classpath/native/jni/java-math/Makefile.in b/libjava/classpath/native/jni/java-math/Makefile.in new file mode 100644 index 000000000..3b7072586 --- /dev/null +++ b/libjava/classpath/native/jni/java-math/Makefile.in @@ -0,0 +1,610 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +subdir = native/jni/java-math +DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/../../config/depstand.m4 \ + $(top_srcdir)/../../config/lead-dot.m4 \ + $(top_srcdir)/../../config/lib-ld.m4 \ + $(top_srcdir)/../../config/lib-link.m4 \ + $(top_srcdir)/../../config/lib-prefix.m4 \ + $(top_srcdir)/../../config/multi.m4 \ + $(top_srcdir)/../../config/no-executables.m4 \ + $(top_srcdir)/../../config/override.m4 \ + $(top_srcdir)/../../libtool.m4 \ + $(top_srcdir)/../../ltoptions.m4 \ + $(top_srcdir)/../../ltsugar.m4 \ + $(top_srcdir)/../../ltversion.m4 \ + $(top_srcdir)/../../lt~obsolete.m4 \ + $(top_srcdir)/m4/ac_prog_antlr.m4 \ + $(top_srcdir)/m4/ac_prog_java.m4 \ + $(top_srcdir)/m4/ac_prog_java_works.m4 \ + $(top_srcdir)/m4/ac_prog_javac.m4 \ + $(top_srcdir)/m4/ac_prog_javac_works.m4 \ + $(top_srcdir)/m4/acattribute.m4 $(top_srcdir)/m4/accross.m4 \ + $(top_srcdir)/m4/acinclude.m4 \ + $(top_srcdir)/m4/ax_create_stdint_h.m4 \ + $(top_srcdir)/m4/ax_func_which_gethostbyname_r.m4 \ + $(top_srcdir)/m4/gcc_attribute.m4 $(top_srcdir)/m4/iconv.m4 \ + $(top_srcdir)/m4/pkg.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/../../mkinstalldirs +CONFIG_HEADER = $(top_builddir)/include/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__installdirs = "$(DESTDIR)$(nativeexeclibdir)" +LTLIBRARIES = $(nativeexeclib_LTLIBRARIES) +libjavamath_la_DEPENDENCIES = \ + $(top_builddir)/native/jni/classpath/jcl.lo +am_libjavamath_la_OBJECTS = gnu_java_math_GMP.lo +libjavamath_la_OBJECTS = $(am_libjavamath_la_OBJECTS) +libjavamath_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(libjavamath_la_LDFLAGS) $(LDFLAGS) -o $@ +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/include +depcomp = $(SHELL) $(top_srcdir)/../../depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(libjavamath_la_SOURCES) +ETAGS = etags +CTAGS = ctags +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +ANTLR = @ANTLR@ +ANTLR_JAR = @ANTLR_JAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CAIRO_CFLAGS = @CAIRO_CFLAGS@ +CAIRO_LIBS = @CAIRO_LIBS@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CLASSPATH_CONVENIENCE = @CLASSPATH_CONVENIENCE@ +CLASSPATH_INCLUDES = @CLASSPATH_INCLUDES@ +CLASSPATH_MODULE = @CLASSPATH_MODULE@ +COLLECTIONS_PREFIX = @COLLECTIONS_PREFIX@ +CP = @CP@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DATE = @DATE@ +DEFAULT_PREFS_PEER = @DEFAULT_PREFS_PEER@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +ECJ_JAR = @ECJ_JAR@ +EGREP = @EGREP@ +ERROR_CFLAGS = @ERROR_CFLAGS@ +EXAMPLESDIR = @EXAMPLESDIR@ +EXEEXT = @EXEEXT@ +EXTRA_CFLAGS = @EXTRA_CFLAGS@ +FGREP = @FGREP@ +FIND = @FIND@ +FREETYPE2_CFLAGS = @FREETYPE2_CFLAGS@ +FREETYPE2_LIBS = @FREETYPE2_LIBS@ +GCONF_CFLAGS = @GCONF_CFLAGS@ +GCONF_LIBS = @GCONF_LIBS@ +GDK_CFLAGS = @GDK_CFLAGS@ +GDK_LIBS = @GDK_LIBS@ +GJDOC = @GJDOC@ +GLIB_CFLAGS = @GLIB_CFLAGS@ +GLIB_LIBS = @GLIB_LIBS@ +GMP_CFLAGS = @GMP_CFLAGS@ +GMP_LIBS = @GMP_LIBS@ +GREP = @GREP@ +GSTREAMER_BASE_CFLAGS = @GSTREAMER_BASE_CFLAGS@ +GSTREAMER_BASE_LIBS = @GSTREAMER_BASE_LIBS@ +GSTREAMER_CFLAGS = @GSTREAMER_CFLAGS@ +GSTREAMER_FILE_READER = @GSTREAMER_FILE_READER@ +GSTREAMER_LIBS = @GSTREAMER_LIBS@ +GSTREAMER_MIXER_PROVIDER = @GSTREAMER_MIXER_PROVIDER@ +GSTREAMER_PLUGINS_BASE_CFLAGS = @GSTREAMER_PLUGINS_BASE_CFLAGS@ +GSTREAMER_PLUGINS_BASE_LIBS = @GSTREAMER_PLUGINS_BASE_LIBS@ +GST_PLUGIN_LDFLAGS = @GST_PLUGIN_LDFLAGS@ +GTK_CFLAGS = @GTK_CFLAGS@ +GTK_LIBS = @GTK_LIBS@ +INIT_LOAD_LIBRARY = @INIT_LOAD_LIBRARY@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAR = @JAR@ +JAVA = @JAVA@ +JAVAC = @JAVAC@ +JAVAC_IS_GCJ = @JAVAC_IS_GCJ@ +JAVAC_MEM_OPT = @JAVAC_MEM_OPT@ +JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION = @JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION@ +JAY = @JAY@ +JAY_SKELETON = @JAY_SKELETON@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBDEBUG = @LIBDEBUG@ +LIBICONV = @LIBICONV@ +LIBMAGIC = @LIBMAGIC@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBVERSION = @LIBVERSION@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBICONV = @LTLIBICONV@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MKDIR = @MKDIR@ +MKDIR_P = @MKDIR_P@ +MOC = @MOC@ +MOZILLA_CFLAGS = @MOZILLA_CFLAGS@ +MOZILLA_LIBS = @MOZILLA_LIBS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PANGOFT2_CFLAGS = @PANGOFT2_CFLAGS@ +PANGOFT2_LIBS = @PANGOFT2_LIBS@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PATH_TO_ESCHER = @PATH_TO_ESCHER@ +PATH_TO_GLIBJ_ZIP = @PATH_TO_GLIBJ_ZIP@ +PERL = @PERL@ +PKG_CONFIG = @PKG_CONFIG@ +PLUGIN_DIR = @PLUGIN_DIR@ +QT_CFLAGS = @QT_CFLAGS@ +QT_LIBS = @QT_LIBS@ +RANLIB = @RANLIB@ +REMOVE = @REMOVE@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRICT_WARNING_CFLAGS = @STRICT_WARNING_CFLAGS@ +STRIP = @STRIP@ +TOOLSDIR = @TOOLSDIR@ +USER_JAVAH = @USER_JAVAH@ +VERSION = @VERSION@ +WANT_NATIVE_BIG_INTEGER = @WANT_NATIVE_BIG_INTEGER@ +WARNING_CFLAGS = @WARNING_CFLAGS@ +XMKMF = @XMKMF@ +XML_CFLAGS = @XML_CFLAGS@ +XML_LIBS = @XML_LIBS@ +XSLT_CFLAGS = @XSLT_CFLAGS@ +XSLT_LIBS = @XSLT_LIBS@ +XTEST_LIBS = @XTEST_LIBS@ +X_CFLAGS = @X_CFLAGS@ +X_EXTRA_LIBS = @X_EXTRA_LIBS@ +X_LIBS = @X_LIBS@ +X_PRE_LIBS = @X_PRE_LIBS@ +ZIP = @ZIP@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_ANTLR = @ac_ct_ANTLR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +default_toolkit = @default_toolkit@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +glibjdir = @glibjdir@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +multi_basedir = @multi_basedir@ +nativeexeclibdir = @nativeexeclibdir@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +toolexeclibdir = @toolexeclibdir@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +uudecode = @uudecode@ +vm_classes = @vm_classes@ +nativeexeclib_LTLIBRARIES = libjavamath.la +libjavamath_la_SOURCES = gnu_java_math_GMP.c +libjavamath_la_LIBADD = $(top_builddir)/native/jni/classpath/jcl.lo +libjavamath_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version +AM_LDFLAGS = @CLASSPATH_MODULE@ @GMP_LIBS@ +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ +AM_CFLAGS = @WARNING_CFLAGS@ @ERROR_CFLAGS@ @GMP_CFLAGS@ +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu native/jni/java-math/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu native/jni/java-math/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-nativeexeclibLTLIBRARIES: $(nativeexeclib_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(nativeexeclibdir)" || $(MKDIR_P) "$(DESTDIR)$(nativeexeclibdir)" + @list='$(nativeexeclib_LTLIBRARIES)'; test -n "$(nativeexeclibdir)" || list=; \ + list2=; for p in $$list; do \ + if test -f $$p; then \ + list2="$$list2 $$p"; \ + else :; fi; \ + done; \ + test -z "$$list2" || { \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(nativeexeclibdir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(nativeexeclibdir)"; \ + } + +uninstall-nativeexeclibLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(nativeexeclib_LTLIBRARIES)'; test -n "$(nativeexeclibdir)" || list=; \ + for p in $$list; do \ + $(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(nativeexeclibdir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(nativeexeclibdir)/$$f"; \ + done + +clean-nativeexeclibLTLIBRARIES: + -test -z "$(nativeexeclib_LTLIBRARIES)" || rm -f $(nativeexeclib_LTLIBRARIES) + @list='$(nativeexeclib_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libjavamath.la: $(libjavamath_la_OBJECTS) $(libjavamath_la_DEPENDENCIES) + $(libjavamath_la_LINK) -rpath $(nativeexeclibdir) $(libjavamath_la_OBJECTS) $(libjavamath_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_math_GMP.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) +installdirs: + for dir in "$(DESTDIR)$(nativeexeclibdir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-nativeexeclibLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-nativeexeclibLTLIBRARIES + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-nativeexeclibLTLIBRARIES + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-nativeexeclibLTLIBRARIES ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags dvi dvi-am html html-am info info-am install \ + install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-nativeexeclibLTLIBRARIES install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-nativeexeclibLTLIBRARIES + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/libjava/classpath/native/jni/java-math/gnu_java_math_GMP.c b/libjava/classpath/native/jni/java-math/gnu_java_math_GMP.c new file mode 100644 index 000000000..85c2e6b0f --- /dev/null +++ b/libjava/classpath/native/jni/java-math/gnu_java_math_GMP.c @@ -0,0 +1,1396 @@ +/* gnu_java_math_GMP.c -- Native MPI implemenetation over GNU MP + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include "gnu_java_math_GMP.h" +#include + +#if defined(HAVE_GMP_H) +#include +#endif /* defined(HAVE_GMP_H) */ + +#if defined(WITH_GNU_MP) +#else +#warning GNU MP not available or wanted! +#warning Invocation of natXXX() methods will raise an exception +#endif + +/* + * This is the implementation of the native BigInteger$NativeMPI methods which + * use the GNU MP (GMP) library. + * + * In all the Java non-statically declared native methods, the second argument, + * an instance of jobject, refers to the current NativeMPI instance; i.e. + * "this" in Java parlance. The corresponding allocated data structure + * representing the GMP's counter-part is pointed-to by the pointer stored in a + * transient java field named "native_ptr". The first thing these methods do is + * (a) access that field with a JNI GetObjectField() call to obtain the + * reference to the gnu.classpath.Pointer subclass instance, then (b) obtain + * the native GMP pointer (an mpz_ptr), in order to perform their job; e.g. + * + * JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)) + * + * For static methods the second argument, an instance of jclass, is almost + * always unused --except when initializing the library, which is the only time + * we get hold of the native pointer field. + * + * This code was written and tested with GNU MP version 4.1.2. More recent + * versions of that library offer more operations; e.g. in the implementation + * of the method Java_java_math_BigInteger_00024NativeMPI_natFlipBit, mpz_combit() + * should be used with GNU MP versions later than 4.2. As a consequence, this + * code should be reviewed, from time to time, to use newer features of the GNU + * MP library. + */ + +static jfieldID native_ptr; + +#ifdef DEBUG +#define TRACE(msg) fprintf (stderr, "%s(%s:%d) -- %s\n", __FUNCTION__, __FILE__, __LINE__, msg) +#else +#define TRACE(msg) +#endif + +#define throw_config_exception(env) JCL_ThrowException (env, "java/lang/Error", "GNU MP was not specified/found by configure") + +/* + * Initialize the native library. Specifically this method: + * + * a. Pass NULLs to the mp_set_memory_functions implying that GMP should use + * malloc, realloc and free for memory allocation, and if they fail GMP + * will print a message to the standard error output and terminates the + * program. + * b. Find out and store the reference to the NativeMPI class's 'native_ptr' + * field. This is done so later in the method invocations we can access that + * field and acquire the native value associated with that Pointer instance. + */ +JNIEXPORT void JNICALL +Java_gnu_java_math_GMP_natInitializeLibrary (JNIEnv *env, + jclass nativeMPI) +{ +#if defined(WITH_GNU_MP) + TRACE("Loading GMP-based BigInteger native library"); + mp_set_memory_functions (NULL, NULL, NULL); + native_ptr = (*env)->GetFieldID (env, nativeMPI, "native_ptr", + "Lgnu/classpath/Pointer;"); + TRACE("Loaded GMP-based BigInteger native library"); +#else /* !defined(WITH_GNU_MP) */ + (void) nativeMPI; + throw_config_exception(env); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * Allocate and initialize the data structure for an instance of a NativeMPI. + * + * @param this an instance of NativeMPI. + */ +JNIEXPORT void JNICALL +Java_gnu_java_math_GMP_natInitialize(JNIEnv *env, jobject this) +{ +#if defined(WITH_GNU_MP) + mpz_ptr _this; + + TRACE("begin"); + _this = (mpz_ptr)JCL_malloc (env, sizeof (mpz_t)); + /* initialize --GMP sets the value to zero. */ + mpz_init (_this); + /* instantiate the Pointer instance for this NativeMPI. */ + jobject native_ptr_fld = JCL_NewRawDataObject (env, _this); + /* ... and assign it to the native_ptr field. */ + (*env)->SetObjectField (env, this, native_ptr, native_ptr_fld); + TRACE("end"); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + throw_config_exception(env); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * Clear and free the data structure for an instance of a NativeMPI. + * + * @param this an instance of NativeMPI. + */ +JNIEXPORT void JNICALL +Java_gnu_java_math_GMP_natFinalize(JNIEnv *env, jobject this) +{ +#if defined(WITH_GNU_MP) + mpz_ptr _this; + + TRACE("begin"); + _this = (mpz_ptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + if (_this != NULL) + { + mpz_clear (_this); + free (_this); + _this = NULL; + } + else + { + TRACE("WARNING: Already cleared + freed"); + } + TRACE("end"); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + throw_config_exception(env); +#endif /* defined(WITH_GNU_MP) */ +} + + +/* + * @param this an instance of NativeMPI. On exit, this will have a value of n. + * @param n a Java long primitive value. + */ +JNIEXPORT void JNICALL +Java_gnu_java_math_GMP_natFromLong(JNIEnv *env, jobject this, + jlong n) +{ +#if defined(WITH_GNU_MP) + mpz_ptr _this; + + TRACE("begin"); + _this = (mpz_ptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + /* the size of jlong (64-bit) is either the same as a long, or that of a long long. + * if it's the former, we use as is. */ + if (sizeof (jlong) == sizeof (long)) + { + mpz_set_si (_this, (signed long)n); + } + else + { + /* ...otherwise, we operate on the two halves of the long long, each half + * being 32-bit wide. for simplicity, we work with positive + * values negating, if necessary, the final outcome. + */ + const int isnegative = n < 0 ? 1 : 0; + if (isnegative) + { + n = -n; + } + mpz_set_ui (_this, (unsigned long)(((unsigned long long)n) >> 32)); + mpz_mul_2exp (_this, _this, 32); /* shift left by 32 bits */ + mpz_add_ui (_this, _this, (unsigned long)n); + if (isnegative) + { + mpz_neg (_this, _this); + } + } + TRACE("end"); +#else /* !defined(WITH_GNU_MP) */ + (void) n; + (void) r; + throw_config_exception(env); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this an instance of NativeMPI. On exit, this will have the same + * value as x. + * @param x an instance of a NativeMPI's Pointer. + */ +JNIEXPORT void JNICALL +Java_gnu_java_math_GMP_natFromBI(JNIEnv *env, jobject this, + jobject x) +{ +#if defined(WITH_GNU_MP) + mpz_ptr _this; + mpz_srcptr _x; + + TRACE("begin"); + _this = (mpz_ptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + _x = (mpz_srcptr)JCL_GetRawData (env, x); + mpz_set (_this, _x); + TRACE("end"); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + (void) x; + throw_config_exception(env); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this an instance of NativeMPI. On exit, this will have the value + * represented by the v Java byte array (in 2's complement with most + * significant byte at index position 0). The sign is implied by the + * value of the most significant byte. + * @param v a Java byte array containing the byte representation, in 2's + * complement of the signed value to assign to this. + */ +JNIEXPORT void JNICALL +Java_gnu_java_math_GMP_natFromByteArray(JNIEnv *env, + jobject this, + jbyteArray v) +{ +#if defined(WITH_GNU_MP) + mpz_ptr _this; + jbyte *_v; + unsigned long b; + int vlength, isnegative, i; + + TRACE("begin"); + _this = (mpz_ptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + _v = (*env)->GetByteArrayElements (env, v, NULL); + vlength = (*env)->GetArrayLength (env, v); + b = (unsigned long)(_v[0] & 0xFF); + isnegative = (b > 0x7F) ? 1 : 0; + mpz_set_ui (_this, 0); + for (i = 0; i < vlength; i++) + { + mpz_mul_2exp (_this, _this, 8); /* shift left 8 positions. */ + b = (unsigned long)(_v[i] & 0xFF); + b = (isnegative) ? ~b : b; + mpz_add_ui (_this, _this, (unsigned long)(b & 0xFF)); + } + (*env)->ReleaseByteArrayElements (env, v, _v, JNI_ABORT); + if (isnegative) + { + mpz_add_ui (_this, _this, 1); + mpz_neg (_this, _this); + } + TRACE("end"); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + (void) v; + throw_config_exception(env); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this an instance of NativeMPI. On exit, this will have the value + * represented by the s Java string. + * @param s a Java string containing, a possibly signed, value to assign to + * this. + * @param rdx the base in which the symbols, in s, are represented. + * @return 0 if the entire string is a valid number in base rdx. Otherwise it + * returns -1. + * + * Implementation note: + * While the GMP library is more tolerant in what it accepts as parameter values + * for conversions from strings, the BigInteger code, which calls this method, + * ensures that the contract described in the RI's documentation is respected; + * e.g. no white spaces in the middle, limited valid radix values, etc... + */ +JNIEXPORT jint JNICALL +Java_gnu_java_math_GMP_natFromString(JNIEnv *env, + jobject this, jstring s, + jint rdx) +{ +#if defined(WITH_GNU_MP) + mpz_ptr _this; + const char *_s; + int result; + + TRACE("begin"); + _this = (mpz_ptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + _s = (*env)->GetStringUTFChars (env, s, NULL); + result = mpz_set_str (_this, _s, (int)rdx); + JCL_free_cstring (env, s, _s); + TRACE("end"); + return (result); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + (void) s; + (void) rdx; + throw_config_exception(env); + return (-1); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this an instance of NativeMPI. On exit, this will have the value + * represented by the m Java byte array (most significant byte at + * index position 0). It will be positive, or negative, depending on + * the value of isnegative. + * @param m a Java byte array containing the byte representation of the + * absolute value (most significant byte being at index position 0) + * to assign to this. + * @param isnegative true if this should be negative and false if it should + * be positive. + */ +JNIEXPORT void JNICALL +Java_gnu_java_math_GMP_natFromSignedMagnitude(JNIEnv *env, + jobject this, + jbyteArray m, + jboolean isnegative) +{ +#if defined(WITH_GNU_MP) + mpz_ptr _this; + jbyte *_m; + int mlength, i; + + TRACE("begin"); + _this = (mpz_ptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + _m = (*env)->GetByteArrayElements (env, m, NULL); + mlength = (*env)->GetArrayLength (env, m); + mpz_set_ui (_this, 0); + for (i = 0; i < mlength; i++) + { + mpz_mul_2exp (_this, _this, 8); + mpz_add_ui (_this, _this, (unsigned long)(_m[i] & 0xFF)); + } + (*env)->ReleaseByteArrayElements (env, m, _m, JNI_ABORT); + if (isnegative == JNI_TRUE) + { + mpz_neg (_this, _this); + } + TRACE("end"); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + (void) m; + (void) isnegative; + throw_config_exception(env); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this an instance of NativeMPI. + * @param n the base in which to represent this. + * @return the Java string representing the value of this in base n. + */ +JNIEXPORT jstring JNICALL +Java_gnu_java_math_GMP_natToString(JNIEnv *env, jobject this, + jint n) +{ +#if defined(WITH_GNU_MP) + mpz_srcptr _this; + char *cstr; + jstring result; + + TRACE("begin"); + _this = (mpz_srcptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + cstr = mpz_get_str (NULL, (int)n, _this); + result = (*env)->NewStringUTF (env, cstr); + free (cstr); + TRACE("end"); + return (result); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + (void) n; + throw_config_exception(env); + return (NULL); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this a non-ZERO instance of NativeMPI. + * + * output: + * @param r a Java byte array which shall contain the byte representation of + * this. + */ +JNIEXPORT void JNICALL +Java_gnu_java_math_GMP_natToByteArray(JNIEnv *env, + jobject this, + jbyteArray r) +{ +#if defined(WITH_GNU_MP) + mpz_srcptr _this; + mpz_t _w; /* a temporary work mpi */ + jbyte *_r; + int rlength, sign, i; + unsigned long b; + + TRACE("begin"); + _this = (mpz_srcptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + _r = (*env)->GetByteArrayElements (env, r, NULL); + rlength = (*env)->GetArrayLength (env, r); + mpz_init (_w); + /* if this is negative set w to its 2's complement otherwise use as is. */ + sign = mpz_sgn (_this); + if (sign == 1) + { + mpz_set (_w, _this); + } + else + { + mpz_neg (_w, _this); + mpz_sub_ui (_w, _w, 1); + } + /* _w SHOULD be >= 0. + * start filling the array starting from the least significant byte. */ + for (i = rlength; --i >= 0; ) + { + b = mpz_tdiv_q_ui (_w, _w, 256); + b = (sign == -1) ? ~b : b; + _r[i] = (unsigned long)(b & 0xFF); + } + (*env)->ReleaseByteArrayElements (env, r, _r, JNI_COMMIT); + /* if _w > 0 the byte array was short. */ + if (mpz_cmp_ui (_w, 0) > 0) + { + TRACE("WARNING: byte array is too short"); + } + mpz_clear (_w); + TRACE("end"); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + (void) r; + throw_config_exception(env); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this an instance of NativeMPI. + * @return the "int" value (least significant 32 bits) of the absolute value + * of this NativeMPI. The calling code MUST handle the sign. We do + * this so we can use the same method when computing the "long" value + * as well. + */ +JNIEXPORT jint JNICALL +Java_gnu_java_math_GMP_natAbsIntValue(JNIEnv *env, + jobject this) +{ +#if defined(WITH_GNU_MP) + mpz_srcptr _this; + + TRACE("begin"); + _this = (mpz_srcptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + TRACE("end"); + return ((jint)mpz_get_ui (_this)); +#else /* !defined(WITH_GNU_MP) */ + (void) s; + throw_config_exception(env); + return (-1); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this an instance of NativeMPI. + * @return the, eventually truncated, double value of this NativeMPI. + */ +JNIEXPORT jdouble JNICALL +Java_gnu_java_math_GMP_natDoubleValue(JNIEnv *env, + jobject this) +{ +#if defined(WITH_GNU_MP) + mpz_srcptr _this; + + TRACE("begin"); + _this = (mpz_srcptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + TRACE("end"); + return ((jdouble)mpz_get_d (_this)); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + throw_config_exception(env); + return (0.0); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this a NativeMPI instance. + * @param x an instance of NativeMPI's Pointer. + * @return -1, 0, +1 if x is respectively less than, equal to, or greater + * than y. + */ +JNIEXPORT jint JNICALL +Java_gnu_java_math_GMP_natCompare(JNIEnv *env, jobject this, + jobject x) +{ +#if defined(WITH_GNU_MP) + mpz_ptr _this, _x; + int res; + + TRACE("begin"); + _this = (mpz_ptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + _x = (mpz_ptr)JCL_GetRawData (env, x); + res = mpz_cmp (_this, _x); + TRACE("end"); + if (res == 0) + return ((jint)0); + else if (res < 0) + return ((jint)-1); + else + return ((jint)1); +#else /* !defined(WITH_GNU_MP) */ + (void) x; + (void) y; + throw_config_exception(env); + return (0); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this an instance of NativeMPI. + * @param x an instance of NativeMPI's Pointer. + * + * output: + * @param r a NativeMPI's Pointer such that r = this + x. + */ +JNIEXPORT void JNICALL +Java_gnu_java_math_GMP_natAdd(JNIEnv *env, jobject this, + jobject x, jobject r) +{ +#if defined(WITH_GNU_MP) + mpz_srcptr _this, _x; + mpz_ptr _r; + + TRACE("begin"); + _this = (mpz_srcptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + _x = (mpz_srcptr)JCL_GetRawData (env, x); + _r = (mpz_ptr)JCL_GetRawData (env, r); + mpz_add (_r, _this, _x); + TRACE("end"); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + (void) x; + (void) r; + throw_config_exception(env); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this an instance of NativeMPI. + * @param x an instance of NativeMPI's Pointer. + * + * output: + * @param r a NativeMPI's Pointer such that r = this - x. + */ +JNIEXPORT void JNICALL +Java_gnu_java_math_GMP_natSubtract(JNIEnv *env, jobject this, + jobject x, jobject r) +{ +#if defined(WITH_GNU_MP) + mpz_srcptr _this, _x; + mpz_ptr _r; + + TRACE("begin"); + _this = (mpz_srcptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + _x = (mpz_srcptr)JCL_GetRawData (env, x); + _r = (mpz_ptr)JCL_GetRawData (env, r); + mpz_sub (_r, _this, _x); + TRACE("end"); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + (void) x; + (void) r; + throw_config_exception(env); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this an instance of NativeMPI. + * @param x an instance of NativeMPI's Pointer. + * + * output: + * @param r a NativeMPI's Pointer such that r = this * x. + */ +JNIEXPORT void JNICALL +Java_gnu_java_math_GMP_natMultiply(JNIEnv *env, jobject this, + jobject x, jobject r) +{ +#if defined(WITH_GNU_MP) + mpz_srcptr _this, _x; + mpz_ptr _r; + + TRACE("begin"); + _this = (mpz_srcptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + _x = (mpz_srcptr)JCL_GetRawData (env, x); + _r = (mpz_ptr)JCL_GetRawData (env, r); + mpz_mul (_r, _this, _x); + TRACE("end"); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + (void) x; + (void) r; + throw_config_exception(env); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this an instance of NativeMPI. + * @param x an instance of NativeMPI's Pointer. + * + * output: + * @param r a NativeMPI's Pointer such that r = this div x. + */ +JNIEXPORT void JNICALL +Java_gnu_java_math_GMP_natQuotient(JNIEnv *env, jobject this, + jobject x, jobject r) +{ +#if defined(WITH_GNU_MP) + mpz_srcptr _this, _x; + mpz_ptr _r; + + TRACE("begin"); + _this = (mpz_srcptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + _x = (mpz_srcptr)JCL_GetRawData (env, x); + _r = (mpz_ptr)JCL_GetRawData (env, r); + mpz_tdiv_q (_r, _this, _x); + TRACE("end"); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + (void) x; + (void) r; + throw_config_exception(env); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this an instance of NativeMPI. + * @param x an instance of NativeMPI's Pointer. + * + * output: + * @param r a NativeMPI's Pointer such that r = this mod x. + */ +JNIEXPORT void JNICALL +Java_gnu_java_math_GMP_natRemainder(JNIEnv *env, jobject this, + jobject x, jobject r) +{ +#if defined(WITH_GNU_MP) + mpz_srcptr _this, _x; + mpz_ptr _r; + + TRACE("begin"); + _this = (mpz_srcptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + _x = (mpz_srcptr)JCL_GetRawData (env, x); + _r = (mpz_ptr)JCL_GetRawData (env, r); + mpz_tdiv_r (_r, _this, _x); + TRACE("end"); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + (void) x; + (void) r; + throw_config_exception(env); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this an instance of NativeMPI. + * @param x an instance of NativeMPI's Pointer. + * + * output: + * @param q a NativeMPI's Pointer such that q = this div x. + * @param r a NativeMPI's Pointer such that r = this mod x. + */ +JNIEXPORT void JNICALL +Java_gnu_java_math_GMP_natQuotientAndRemainder(JNIEnv *env, + jobject this, + jobject x, + jobject q, + jobject r) +{ +#if defined(WITH_GNU_MP) + mpz_srcptr _this, _x; + mpz_ptr _q, _r; + + TRACE("begin"); + _this = (mpz_srcptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + _x = (mpz_srcptr)JCL_GetRawData (env, x); + _q = (mpz_ptr)JCL_GetRawData (env, q); + _r = (mpz_ptr)JCL_GetRawData (env, r); + mpz_tdiv_qr (_q, _r, _this, _x); + TRACE("end"); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + (void) x; + (void) q; + (void) r; + throw_config_exception(env); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this an instance of NativeMPI. + * @param x an instance of NativeMPI's Pointer. + * + * output: + * @param r a NativeMPI's Pointer such that r = this mod x. + */ +JNIEXPORT void JNICALL +Java_gnu_java_math_GMP_natModulo(JNIEnv *env, jobject this, + jobject x, jobject r) +{ +#if defined(WITH_GNU_MP) + mpz_srcptr _this, _x; + mpz_ptr _r; + + TRACE("begin"); + _this = (mpz_srcptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + _x = (mpz_srcptr)JCL_GetRawData (env, x); + _r = (mpz_ptr)JCL_GetRawData (env, r); + mpz_mod (_r, _this, _x); + TRACE("end"); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + (void) x; + (void) r; + throw_config_exception(env); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this an instance of NativeMPI. + * @param n a non-negative number to raise this to. + * + * output: + * @param r a NativeMPI's Pointer such that r = this ** n. + */ +JNIEXPORT void JNICALL +Java_gnu_java_math_GMP_natPow(JNIEnv *env, jobject this, + jint n, jobject r) +{ +#if defined(WITH_GNU_MP) + mpz_srcptr _this; + mpz_ptr _r; + + TRACE("begin"); + _this = (mpz_srcptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + _r = (mpz_ptr)JCL_GetRawData (env, r); + mpz_pow_ui (_r, _this, (unsigned long)n); + TRACE("end"); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + (void) n; + (void) r; + throw_config_exception(env); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this an instance of NativeMPI. + * @param e an instance of NativeMPI's Pointer. + * @param m another instance of NativeMPI's Pointer. + * + * output: + * @param r a NativeMPI's Pointer such that r = (this**e) mod m. + * + * @throws java.lang.ArithmeticException if e is negative and (1 / this) mod m + * has no multiplicative inverse. + */ +JNIEXPORT void JNICALL +Java_gnu_java_math_GMP_natModPow(JNIEnv *env, jobject this, + jobject e, jobject m, + jobject r) +{ +#if defined(WITH_GNU_MP) + mpz_srcptr _this, _e, _m; + mpz_ptr _r; + + TRACE("begin"); + _this = (mpz_srcptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + _e = (mpz_srcptr)JCL_GetRawData (env, e); + _m = (mpz_srcptr)JCL_GetRawData (env, m); + _r = (mpz_ptr)JCL_GetRawData (env, r); + /* the documentation of mpz_powm(rop, b, e, m) states that it: "Set rop to + * (b raised to e) modulo m. Negative e is supported if an inverse b^-1 mod m + * exists.... If an inverse doesn't exist then a divide by zero is raised." + * to work around this case we use the same code as in the pure java class; + * i.e.: + * if (e.isNegative()) + * return this.modInverse(m).modPow(e.negate(), m); */ + if (mpz_sgn (_e) == -1) + { + mpz_t _w; /* a temporary work mpi */ + const int res = mpz_invert (_r, _this, _m); + if (res == 0) + { + JCL_ThrowException (env, "java/lang/ArithmeticException", + "No multiplicative inverse modulo the designated number exists"); + } + mpz_init (_w); + mpz_neg (_w, _e); + mpz_powm (_r, _r, _w, _m); + mpz_clear (_w); + } + else + { + mpz_powm (_r, _this, _e, _m); + } + + while (mpz_sgn (_r) == -1) + { + mpz_add (_r, _r, _m); + } + TRACE("end"); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + (void) e; + (void) m; + (void) r; + throw_config_exception(env); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this an instance of NativeMPI. + * @param m an instance of NativeMPI's Pointer. + * + * output: + * @param r a NativeMPI's Pointer such that r = (1 / this) mod m. + * @throws java.lang.ArithmeticException if (1 / this) mod m has no + * multiplicative inverse. + */ +JNIEXPORT void JNICALL +Java_gnu_java_math_GMP_natModInverse(JNIEnv *env, + jobject this, + jobject m, jobject r) +{ +#if defined(WITH_GNU_MP) + mpz_srcptr _this, _m; + mpz_ptr _r; + int res; + + TRACE("begin"); + _this = (mpz_srcptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + _m = (mpz_srcptr)JCL_GetRawData (env, m); + _r = (mpz_ptr)JCL_GetRawData (env, r); + res = mpz_invert (_r, _this, _m); + if (res == 0) + { + JCL_ThrowException (env, "java/lang/ArithmeticException", + "No multiplicative inverse modulo the designated number exists"); + } + + while (mpz_sgn (_r) == -1) + { + mpz_add (_r, _r, _m); + } + TRACE("end"); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + (void) x; + (void) r; + throw_config_exception(env); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this an instance of NativeMPI. + * @param x an instance of NativeMPI's Pointer. + * + * output: + * @param r a NativeMPI's Pointer such that r is the GCD of this and x. + */ +JNIEXPORT void JNICALL +Java_gnu_java_math_GMP_natGCD(JNIEnv *env, jobject this, + jobject x, jobject r) +{ +#if defined(WITH_GNU_MP) + mpz_srcptr _this, _x; + mpz_ptr _r; + + TRACE("begin"); + _this = (mpz_srcptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + _x = (mpz_srcptr)JCL_GetRawData (env, x); + _r = (mpz_ptr)JCL_GetRawData (env, r); + mpz_gcd (_r, _this, _x); + TRACE("end"); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + (void) x; + (void) r; + throw_config_exception(env); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this an instance of NativeMPI. + * @param n number of Miller-Rabin tests to conduct. + * @return 2 if this is definitely prime. Returns 1 if this is probably prime + * (without being certain). Finally, returns 0 if this is definitely + * composite. + */ +JNIEXPORT jint JNICALL +Java_gnu_java_math_GMP_natTestPrimality(JNIEnv *env, + jobject this, jint n) +{ +#if defined(WITH_GNU_MP) + mpz_srcptr _this; + + TRACE("begin"); + _this = (mpz_srcptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + TRACE("end"); + return ((jint)mpz_probab_prime_p (_this, (int)n)); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + (void) n; + throw_config_exception(env); + return (0); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this an instance of NativeMPI. + * @param n the non-negative number of positions to shift right this by. + * + * output: + * @param r a NativeMPI's Pointer such that r = this * 2**n. + */ +JNIEXPORT void JNICALL +Java_gnu_java_math_GMP_natShiftLeft(JNIEnv *env, jobject this, + jint n, jobject r) +{ +#if defined(WITH_GNU_MP) + mpz_srcptr _this; + mpz_ptr _r; + + TRACE("begin"); + _this = (mpz_srcptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + _r = (mpz_ptr)JCL_GetRawData (env, r); + mpz_mul_2exp (_r, _this, (unsigned long)n); + TRACE("end"); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + (void) n; + (void) r; + throw_config_exception(env); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this an instance of NativeMPI. + * @param n the non-negative number of positions to shift left this by. + * + * output: + * @param r a NativeMPI's Pointer such that r = floor(this / 2**n). + */ +JNIEXPORT void JNICALL +Java_gnu_java_math_GMP_natShiftRight(JNIEnv *env, + jobject this, jint n, + jobject r) +{ +#if defined(WITH_GNU_MP) + mpz_srcptr _this; + mpz_ptr _r; + + TRACE("begin"); + _this = (mpz_srcptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + _r = (mpz_ptr)JCL_GetRawData (env, r); + mpz_fdiv_q_2exp (_r, _this, (unsigned long)n); + TRACE("end"); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + (void) n; + (void) r; + throw_config_exception(env); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this an instance of NativeMPI. + * @return the 0-based index of the lowest significant bit set (to 1) in this. + */ +JNIEXPORT jint JNICALL +Java_gnu_java_math_GMP_natLowestSetBit(JNIEnv *env, + jobject this) +{ +#if defined(WITH_GNU_MP) + mpz_srcptr _this; + + TRACE("begin"); + _this = (mpz_srcptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + TRACE("end"); + return ((jint)mpz_scan1 (_this, 0)); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + throw_config_exception(env); + return (-1); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this an instance of NativeMPI. + * + * output: + * @param r a NativeMPI's Pointer such that r = abs(x). + */ +JNIEXPORT void JNICALL +Java_gnu_java_math_GMP_natAbs(JNIEnv *env, jobject this, + jobject r) +{ +#if defined(WITH_GNU_MP) + mpz_srcptr _this; + mpz_ptr _r; + + TRACE("begin"); + _this = (mpz_srcptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + _r = (mpz_ptr)JCL_GetRawData (env, r); + mpz_abs (_r, _this); + TRACE("end"); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + (void) r; + throw_config_exception(env); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this an instance of NativeMPI. + * + * output: + * @param r a NativeMPI's Pointer such that r = -x. + */ +JNIEXPORT void JNICALL +Java_gnu_java_math_GMP_natNegate(JNIEnv *env, jobject this, + jobject r) +{ +#if defined(WITH_GNU_MP) + mpz_srcptr _this; + mpz_ptr _r; + + TRACE("begin"); + _this = (mpz_srcptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + _r = (mpz_ptr)JCL_GetRawData (env, r); + mpz_neg (_r, _this); + TRACE("end"); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + (void) r; + throw_config_exception(env); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this an instance of NativeMPI. + * @return the number of bits needed to represent this. + */ +JNIEXPORT jint JNICALL +Java_gnu_java_math_GMP_natBitLength(JNIEnv *env, jobject this) +{ +#if defined(WITH_GNU_MP) + mpz_srcptr _this; + + TRACE("begin"); + _this = (mpz_srcptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + TRACE("end"); + return ((jint)mpz_sizeinbase (_this, 2)); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + throw_config_exception(env); + return (-1); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this an instance of NativeMPI. It MUST be >= ZERO. + * @return the number of bits set (to 1) in this. + */ +JNIEXPORT jint JNICALL +Java_gnu_java_math_GMP_natSetBitCount(JNIEnv *env, + jobject this) +{ +#if defined(WITH_GNU_MP) + mpz_srcptr _this; + mpz_ptr _bi; + unsigned long res = 0; + + TRACE("begin"); + _this = (mpz_srcptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + switch (mpz_sgn (_this)) + { + case -1: + /* initialize --GMP sets the value to zero. */ + _bi = (mpz_ptr)JCL_malloc (env, sizeof (mpz_t)); + mpz_init (_bi); + mpz_neg (_bi, _this); + res = mpz_popcount (_bi); + mpz_clear (_bi); + free (_bi); + break; + case 0: + res = 0; + break; + case 1: + res = mpz_popcount (_this); + default: + JCL_ThrowException (env, "java/lang/Error", + "Unexpected sign value for a native MPI"); + } + TRACE("end"); + return ((jint)res); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + throw_config_exception(env); + return (ULONG_MAX); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this an instance of NativeMPI. + * @param x an instance of NativeMPI's Pointer. + * + * output: + * @param r a NativeMPI's Pointer such that r = this ^ x. + */ +JNIEXPORT void JNICALL +Java_gnu_java_math_GMP_natXor(JNIEnv *env, jobject this, + jobject x, jobject r) +{ +#if defined(WITH_GNU_MP) + mpz_srcptr _this, _x; + mpz_ptr _r; + + TRACE("begin"); + _this = (mpz_srcptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + _x = (mpz_srcptr)JCL_GetRawData (env, x); + _r = (mpz_ptr)JCL_GetRawData (env, r); + mpz_xor (_r, _this, _x); + TRACE("end"); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + (void) x; + (void) r; + throw_config_exception(env); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this an instance of NativeMPI. + * @param x an instance of NativeMPI's Pointer. + * + * output: + * @param r a NativeMPI's Pointer such that r = this | x. + */ +JNIEXPORT void JNICALL +Java_gnu_java_math_GMP_natOr(JNIEnv *env, jobject this, + jobject x, jobject r) +{ +#if defined(WITH_GNU_MP) + mpz_srcptr _this, _x; + mpz_ptr _r; + + TRACE("begin"); + _this = (mpz_srcptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + _x = (mpz_srcptr)JCL_GetRawData (env, x); + _r = (mpz_ptr)JCL_GetRawData (env, r); + mpz_ior (_r, _this, _x); + TRACE("end"); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + (void) x; + (void) r; + throw_config_exception(env); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this an instance of NativeMPI. + * @param x an instance of NativeMPI's Pointer. + * + * output: + * @param r a NativeMPI's Pointer such that r = this & x. + */ +JNIEXPORT void JNICALL +Java_gnu_java_math_GMP_natAnd(JNIEnv *env, jobject this, + jobject x, jobject r) +{ +#if defined(WITH_GNU_MP) + mpz_srcptr _this, _x; + mpz_ptr _r; + + TRACE("begin"); + _this = (mpz_srcptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + _x = (mpz_srcptr)JCL_GetRawData (env, x); + _r = (mpz_ptr)JCL_GetRawData (env, r); + mpz_and (_r, _this, _x); + TRACE("end"); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + (void) x; + (void) r; + throw_config_exception(env); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this an instance of NativeMPI. + * @param x an instance of NativeMPI's Pointer. + * + * output: + * @param r a NativeMPI's Pointer such that r = this & ~x. + */ +JNIEXPORT void JNICALL +Java_gnu_java_math_GMP_natAndNot(JNIEnv *env, jobject this, + jobject x, jobject r) +{ +#if defined(WITH_GNU_MP) + mpz_srcptr _this, _x; + mpz_ptr _r; + + TRACE("begin"); + _this = (mpz_srcptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + _x = (mpz_srcptr)JCL_GetRawData (env, x); + _r = (mpz_ptr)JCL_GetRawData (env, r); + mpz_com (_r, _x); + mpz_and (_r, _this, _r); + TRACE("end"); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + (void) x; + (void) r; + throw_config_exception(env); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this an instance of NativeMPI. + * @param n the 0-based index position of the bit to flip in this. n MUST be + * greater than, or equal to 0. + * + * output: + * @param r a copy of this NativeMPI's Pointer with its n-th bit flipped. + */ +JNIEXPORT void JNICALL +Java_gnu_java_math_GMP_natFlipBit(JNIEnv *env, jobject this, + jint n, jobject r) +{ +#if defined(WITH_GNU_MP) + mpz_srcptr _this; + mpz_ptr _r; + + TRACE("begin"); + _this = (mpz_srcptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + _r = (mpz_ptr)JCL_GetRawData (env, r); + mpz_set (_r, _this); + /* GNU MP versions earlier than 4.2 do not define this method: + * mpz_combit (_r, (unsigned long)n); */ + if (mpz_tstbit (_r, (unsigned long)n) == 1) + { + mpz_clrbit (_r, (unsigned long)n); + } + else + { + mpz_setbit (_r, (unsigned long)n); + } + TRACE("end"); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + (void) n; + (void) r; + throw_config_exception(env); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this an instance of NativeMPI. + * @param n the 0-based index position of the bit to test in this. n MUST be + * greater than, or equal to 0. + * @return +1, or -1 depending on whether the n-th bit in this is set or not + * respectively. + */ +JNIEXPORT jint JNICALL +Java_gnu_java_math_GMP_natTestBit(JNIEnv *env, jobject this, + jint n) +{ +#if defined(WITH_GNU_MP) + mpz_srcptr _this; + + TRACE("begin"); + _this = (mpz_srcptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + TRACE("end"); + return ((jint)mpz_tstbit (_this, (unsigned long)n)); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + (void) n; + throw_config_exception(env); + return (-1); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this an instance of NativeMPI. + * @param n the 0-based index position of the bit to set, or clear, in this. + * n MUST be greater than, or equal to 0. + * @param setIt if true, then the n-th bit in this will be set, otherwise it + * will be cleared. + * + * output: + * @param r a copy of this NativeMPI's Pointer with its n-th bit set or cleared + * as requested. + */ +JNIEXPORT void JNICALL +Java_gnu_java_math_GMP_natSetBit(JNIEnv *env, jobject this, + jint n, jboolean setIt, + jobject r) +{ +#if defined(WITH_GNU_MP) + mpz_srcptr _this; + mpz_ptr _r; + + TRACE("begin"); + _this = (mpz_srcptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + _r = (mpz_ptr)JCL_GetRawData (env, r); + mpz_set (_r, _this); + if (setIt == JNI_TRUE) + { + mpz_setbit (_r, (unsigned long)n); + } + else + { + mpz_clrbit (_r, (unsigned long)n); + } + TRACE("end"); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + (void) n; + (void) setIt; + (void) r; + throw_config_exception(env); +#endif /* defined(WITH_GNU_MP) */ +} + +/* + * @param this an instance of NativeMPI. + * + * output: + * @param r a NativeMPI's Pointer such that r = ~this. + */ +JNIEXPORT void JNICALL +Java_gnu_java_math_GMP_natNot(JNIEnv *env, jobject this, + jobject r) +{ +#if defined(WITH_GNU_MP) + mpz_srcptr _this; + mpz_ptr _r; + + TRACE("begin"); + _this = (mpz_srcptr)JCL_GetRawData (env, (*env)->GetObjectField (env, this, native_ptr)); + _r = (mpz_ptr)JCL_GetRawData (env, r); + mpz_com (_r, _this); + TRACE("end"); +#else /* !defined(WITH_GNU_MP) */ + (void) this; + (void) r; + throw_config_exception(env); +#endif /* defined(WITH_GNU_MP) */ +} diff --git a/libjava/classpath/native/jni/java-net/.cvsignore b/libjava/classpath/native/jni/java-net/.cvsignore new file mode 100644 index 000000000..e9f2658a6 --- /dev/null +++ b/libjava/classpath/native/jni/java-net/.cvsignore @@ -0,0 +1,8 @@ +*.o +*.a +*.lo +*.la +.libs +.deps +Makefile +Makefile.in diff --git a/libjava/classpath/native/jni/java-net/Makefile.am b/libjava/classpath/native/jni/java-net/Makefile.am new file mode 100644 index 000000000..f70086d93 --- /dev/null +++ b/libjava/classpath/native/jni/java-net/Makefile.am @@ -0,0 +1,26 @@ +nativeexeclib_LTLIBRARIES = libjavanet.la + +if ENABLE_LOCAL_SOCKETS +local_sources = gnu_java_net_local_LocalSocketImpl.c \ + local.c \ + local.h +else +local_sources = gnu_java_net_local_LocalSocketImpl.c +endif + +libjavanet_la_SOURCES = javanet.c \ + javanet.h \ + java_net_VMInetAddress.c \ + java_net_VMNetworkInterface.c \ + java_net_VMURLConnection.c \ + gnu_java_net_VMPlainSocketImpl.c \ + $(local_sources) + +libjavanet_la_LIBADD = $(top_builddir)/native/jni/classpath/jcl.lo \ + $(top_builddir)/native/jni/native-lib/libclasspathnative.la \ + $(LIBMAGIC) + +AM_LDFLAGS = @CLASSPATH_MODULE@ +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ +AM_CFLAGS = @WARNING_CFLAGS@ @STRICT_WARNING_CFLAGS@ @ERROR_CFLAGS@ \ + @EXTRA_CFLAGS@ diff --git a/libjava/classpath/native/jni/java-net/Makefile.in b/libjava/classpath/native/jni/java-net/Makefile.in new file mode 100644 index 000000000..ca3e16311 --- /dev/null +++ b/libjava/classpath/native/jni/java-net/Makefile.in @@ -0,0 +1,637 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +subdir = native/jni/java-net +DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/../../config/depstand.m4 \ + $(top_srcdir)/../../config/lead-dot.m4 \ + $(top_srcdir)/../../config/lib-ld.m4 \ + $(top_srcdir)/../../config/lib-link.m4 \ + $(top_srcdir)/../../config/lib-prefix.m4 \ + $(top_srcdir)/../../config/multi.m4 \ + $(top_srcdir)/../../config/no-executables.m4 \ + $(top_srcdir)/../../config/override.m4 \ + $(top_srcdir)/../../libtool.m4 \ + $(top_srcdir)/../../ltoptions.m4 \ + $(top_srcdir)/../../ltsugar.m4 \ + $(top_srcdir)/../../ltversion.m4 \ + $(top_srcdir)/../../lt~obsolete.m4 \ + $(top_srcdir)/m4/ac_prog_antlr.m4 \ + $(top_srcdir)/m4/ac_prog_java.m4 \ + $(top_srcdir)/m4/ac_prog_java_works.m4 \ + $(top_srcdir)/m4/ac_prog_javac.m4 \ + $(top_srcdir)/m4/ac_prog_javac_works.m4 \ + $(top_srcdir)/m4/acattribute.m4 $(top_srcdir)/m4/accross.m4 \ + $(top_srcdir)/m4/acinclude.m4 \ + $(top_srcdir)/m4/ax_create_stdint_h.m4 \ + $(top_srcdir)/m4/ax_func_which_gethostbyname_r.m4 \ + $(top_srcdir)/m4/gcc_attribute.m4 $(top_srcdir)/m4/iconv.m4 \ + $(top_srcdir)/m4/pkg.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/../../mkinstalldirs +CONFIG_HEADER = $(top_builddir)/include/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__installdirs = "$(DESTDIR)$(nativeexeclibdir)" +LTLIBRARIES = $(nativeexeclib_LTLIBRARIES) +am__DEPENDENCIES_1 = +libjavanet_la_DEPENDENCIES = \ + $(top_builddir)/native/jni/classpath/jcl.lo \ + $(top_builddir)/native/jni/native-lib/libclasspathnative.la \ + $(am__DEPENDENCIES_1) +@ENABLE_LOCAL_SOCKETS_FALSE@am__objects_1 = gnu_java_net_local_LocalSocketImpl.lo +@ENABLE_LOCAL_SOCKETS_TRUE@am__objects_1 = gnu_java_net_local_LocalSocketImpl.lo \ +@ENABLE_LOCAL_SOCKETS_TRUE@ local.lo +am_libjavanet_la_OBJECTS = javanet.lo java_net_VMInetAddress.lo \ + java_net_VMNetworkInterface.lo java_net_VMURLConnection.lo \ + gnu_java_net_VMPlainSocketImpl.lo $(am__objects_1) +libjavanet_la_OBJECTS = $(am_libjavanet_la_OBJECTS) +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/include +depcomp = $(SHELL) $(top_srcdir)/../../depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(libjavanet_la_SOURCES) +ETAGS = etags +CTAGS = ctags +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +ANTLR = @ANTLR@ +ANTLR_JAR = @ANTLR_JAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CAIRO_CFLAGS = @CAIRO_CFLAGS@ +CAIRO_LIBS = @CAIRO_LIBS@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CLASSPATH_CONVENIENCE = @CLASSPATH_CONVENIENCE@ +CLASSPATH_INCLUDES = @CLASSPATH_INCLUDES@ +CLASSPATH_MODULE = @CLASSPATH_MODULE@ +COLLECTIONS_PREFIX = @COLLECTIONS_PREFIX@ +CP = @CP@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DATE = @DATE@ +DEFAULT_PREFS_PEER = @DEFAULT_PREFS_PEER@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +ECJ_JAR = @ECJ_JAR@ +EGREP = @EGREP@ +ERROR_CFLAGS = @ERROR_CFLAGS@ +EXAMPLESDIR = @EXAMPLESDIR@ +EXEEXT = @EXEEXT@ +EXTRA_CFLAGS = @EXTRA_CFLAGS@ +FGREP = @FGREP@ +FIND = @FIND@ +FREETYPE2_CFLAGS = @FREETYPE2_CFLAGS@ +FREETYPE2_LIBS = @FREETYPE2_LIBS@ +GCONF_CFLAGS = @GCONF_CFLAGS@ +GCONF_LIBS = @GCONF_LIBS@ +GDK_CFLAGS = @GDK_CFLAGS@ +GDK_LIBS = @GDK_LIBS@ +GJDOC = @GJDOC@ +GLIB_CFLAGS = @GLIB_CFLAGS@ +GLIB_LIBS = @GLIB_LIBS@ +GMP_CFLAGS = @GMP_CFLAGS@ +GMP_LIBS = @GMP_LIBS@ +GREP = @GREP@ +GSTREAMER_BASE_CFLAGS = @GSTREAMER_BASE_CFLAGS@ +GSTREAMER_BASE_LIBS = @GSTREAMER_BASE_LIBS@ +GSTREAMER_CFLAGS = @GSTREAMER_CFLAGS@ +GSTREAMER_FILE_READER = @GSTREAMER_FILE_READER@ +GSTREAMER_LIBS = @GSTREAMER_LIBS@ +GSTREAMER_MIXER_PROVIDER = @GSTREAMER_MIXER_PROVIDER@ +GSTREAMER_PLUGINS_BASE_CFLAGS = @GSTREAMER_PLUGINS_BASE_CFLAGS@ +GSTREAMER_PLUGINS_BASE_LIBS = @GSTREAMER_PLUGINS_BASE_LIBS@ +GST_PLUGIN_LDFLAGS = @GST_PLUGIN_LDFLAGS@ +GTK_CFLAGS = @GTK_CFLAGS@ +GTK_LIBS = @GTK_LIBS@ +INIT_LOAD_LIBRARY = @INIT_LOAD_LIBRARY@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAR = @JAR@ +JAVA = @JAVA@ +JAVAC = @JAVAC@ +JAVAC_IS_GCJ = @JAVAC_IS_GCJ@ +JAVAC_MEM_OPT = @JAVAC_MEM_OPT@ +JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION = @JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION@ +JAY = @JAY@ +JAY_SKELETON = @JAY_SKELETON@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBDEBUG = @LIBDEBUG@ +LIBICONV = @LIBICONV@ +LIBMAGIC = @LIBMAGIC@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBVERSION = @LIBVERSION@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBICONV = @LTLIBICONV@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MKDIR = @MKDIR@ +MKDIR_P = @MKDIR_P@ +MOC = @MOC@ +MOZILLA_CFLAGS = @MOZILLA_CFLAGS@ +MOZILLA_LIBS = @MOZILLA_LIBS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PANGOFT2_CFLAGS = @PANGOFT2_CFLAGS@ +PANGOFT2_LIBS = @PANGOFT2_LIBS@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PATH_TO_ESCHER = @PATH_TO_ESCHER@ +PATH_TO_GLIBJ_ZIP = @PATH_TO_GLIBJ_ZIP@ +PERL = @PERL@ +PKG_CONFIG = @PKG_CONFIG@ +PLUGIN_DIR = @PLUGIN_DIR@ +QT_CFLAGS = @QT_CFLAGS@ +QT_LIBS = @QT_LIBS@ +RANLIB = @RANLIB@ +REMOVE = @REMOVE@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRICT_WARNING_CFLAGS = @STRICT_WARNING_CFLAGS@ +STRIP = @STRIP@ +TOOLSDIR = @TOOLSDIR@ +USER_JAVAH = @USER_JAVAH@ +VERSION = @VERSION@ +WANT_NATIVE_BIG_INTEGER = @WANT_NATIVE_BIG_INTEGER@ +WARNING_CFLAGS = @WARNING_CFLAGS@ +XMKMF = @XMKMF@ +XML_CFLAGS = @XML_CFLAGS@ +XML_LIBS = @XML_LIBS@ +XSLT_CFLAGS = @XSLT_CFLAGS@ +XSLT_LIBS = @XSLT_LIBS@ +XTEST_LIBS = @XTEST_LIBS@ +X_CFLAGS = @X_CFLAGS@ +X_EXTRA_LIBS = @X_EXTRA_LIBS@ +X_LIBS = @X_LIBS@ +X_PRE_LIBS = @X_PRE_LIBS@ +ZIP = @ZIP@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_ANTLR = @ac_ct_ANTLR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +default_toolkit = @default_toolkit@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +glibjdir = @glibjdir@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +multi_basedir = @multi_basedir@ +nativeexeclibdir = @nativeexeclibdir@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +toolexeclibdir = @toolexeclibdir@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +uudecode = @uudecode@ +vm_classes = @vm_classes@ +nativeexeclib_LTLIBRARIES = libjavanet.la +@ENABLE_LOCAL_SOCKETS_FALSE@local_sources = gnu_java_net_local_LocalSocketImpl.c +@ENABLE_LOCAL_SOCKETS_TRUE@local_sources = gnu_java_net_local_LocalSocketImpl.c \ +@ENABLE_LOCAL_SOCKETS_TRUE@ local.c \ +@ENABLE_LOCAL_SOCKETS_TRUE@ local.h + +libjavanet_la_SOURCES = javanet.c \ + javanet.h \ + java_net_VMInetAddress.c \ + java_net_VMNetworkInterface.c \ + java_net_VMURLConnection.c \ + gnu_java_net_VMPlainSocketImpl.c \ + $(local_sources) + +libjavanet_la_LIBADD = $(top_builddir)/native/jni/classpath/jcl.lo \ + $(top_builddir)/native/jni/native-lib/libclasspathnative.la \ + $(LIBMAGIC) + +AM_LDFLAGS = @CLASSPATH_MODULE@ +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ +AM_CFLAGS = @WARNING_CFLAGS@ @STRICT_WARNING_CFLAGS@ @ERROR_CFLAGS@ \ + @EXTRA_CFLAGS@ + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu native/jni/java-net/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu native/jni/java-net/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-nativeexeclibLTLIBRARIES: $(nativeexeclib_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(nativeexeclibdir)" || $(MKDIR_P) "$(DESTDIR)$(nativeexeclibdir)" + @list='$(nativeexeclib_LTLIBRARIES)'; test -n "$(nativeexeclibdir)" || list=; \ + list2=; for p in $$list; do \ + if test -f $$p; then \ + list2="$$list2 $$p"; \ + else :; fi; \ + done; \ + test -z "$$list2" || { \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(nativeexeclibdir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(nativeexeclibdir)"; \ + } + +uninstall-nativeexeclibLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(nativeexeclib_LTLIBRARIES)'; test -n "$(nativeexeclibdir)" || list=; \ + for p in $$list; do \ + $(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(nativeexeclibdir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(nativeexeclibdir)/$$f"; \ + done + +clean-nativeexeclibLTLIBRARIES: + -test -z "$(nativeexeclib_LTLIBRARIES)" || rm -f $(nativeexeclib_LTLIBRARIES) + @list='$(nativeexeclib_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libjavanet.la: $(libjavanet_la_OBJECTS) $(libjavanet_la_DEPENDENCIES) + $(LINK) -rpath $(nativeexeclibdir) $(libjavanet_la_OBJECTS) $(libjavanet_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_net_VMPlainSocketImpl.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_net_local_LocalSocketImpl.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/java_net_VMInetAddress.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/java_net_VMNetworkInterface.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/java_net_VMURLConnection.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/javanet.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/local.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) +installdirs: + for dir in "$(DESTDIR)$(nativeexeclibdir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-nativeexeclibLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-nativeexeclibLTLIBRARIES + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-nativeexeclibLTLIBRARIES + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-nativeexeclibLTLIBRARIES ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags dvi dvi-am html html-am info info-am install \ + install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-nativeexeclibLTLIBRARIES install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-nativeexeclibLTLIBRARIES + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/libjava/classpath/native/jni/java-net/gnu_java_net_VMPlainSocketImpl.c b/libjava/classpath/native/jni/java-net/gnu_java_net_VMPlainSocketImpl.c new file mode 100644 index 000000000..c9620a4e7 --- /dev/null +++ b/libjava/classpath/native/jni/java-net/gnu_java_net_VMPlainSocketImpl.c @@ -0,0 +1,965 @@ +/* VMPlainSocketImpl.c - Native methods for PlainSocketImpl class + Copyright (C) 2005, 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#ifdef HAVE_CONFIG_H +#include +#endif /* HAVE_CONFIG_H */ + +#include + +#include +#include +#include +#include +#ifdef HAVE_IFADDRS_H +#include +#endif +#include +#include +#ifdef HAVE_NET_IF_H +#include +#endif +#include +#include +#include +#include +#include + +#include +#include + +#include "cpnative.h" +#include "cpnet.h" +#include "cpio.h" +#include "javanet.h" + +#include "gnu_java_net_VMPlainSocketImpl.h" + +#define THROW_NO_NETWORK(env) JCL_ThrowException (env, "java/lang/InternalError", "this platform not configured for network support") +#define THROW_NO_IPV6(env) JCL_ThrowException (env, "java/lang/InternalError", "IPv6 support not available") + +/* + * Class: gnu_java_net_VMPlainSocketImpl + * Method: bind + * Signature: (I[BI)V + */ +JNIEXPORT void JNICALL +Java_gnu_java_net_VMPlainSocketImpl_bind (JNIEnv *env, + jclass clazz __attribute__((unused)), + jint fd, jbyteArray addr, jint port) +{ + struct sockaddr_in sockaddr; + jbyte *elems = NULL; + int ret; + + if (addr != NULL) + elems = (*env)->GetByteArrayElements (env, addr, NULL); + + memset(&sockaddr, 0, sizeof (struct sockaddr_in)); + sockaddr.sin_family = AF_INET; + sockaddr.sin_port = htons (port); + /* addr is already in network byte order. */ + if (elems != NULL) + sockaddr.sin_addr.s_addr = *((uint32_t *) elems); + else + sockaddr.sin_addr.s_addr = INADDR_ANY; + + /* bind(2) from BSD says bind will never return EINTR */ + /* bind is not a blocking system call */ + ret = bind (fd, (struct sockaddr *) &sockaddr, sizeof (struct sockaddr_in)); + + if (elems != NULL) + (*env)->ReleaseByteArrayElements (env, addr, elems, JNI_ABORT); + + if (-1 == ret) + JCL_ThrowException (env, BIND_EXCEPTION, strerror (errno)); + + cpio_closeOnExec(ret); +} + + +/* + * Class: gnu_java_net_VMPlainSocketImpl + * Method: bind6 + * Signature: (I[BI)V + */ +JNIEXPORT void JNICALL +Java_gnu_java_net_VMPlainSocketImpl_bind6 (JNIEnv *env, + jclass c __attribute__((unused)), + jint fd, jbyteArray addr, jint port) +{ +#ifdef HAVE_INET6 + struct sockaddr_in6 sockaddr; + jbyte *elems; + int ret; + + elems = (*env)->GetByteArrayElements (env, addr, NULL); + + memset (&sockaddr, 0, sizeof (struct sockaddr_in6)); + sockaddr.sin6_family = AF_INET6; + sockaddr.sin6_port = htons (port); + memcpy (&sockaddr.sin6_addr.s6_addr, elems, 16); + + /* bind(2) from BSD says bind will never return EINTR */ + /* bind is not a blocking system call */ + ret = bind (fd, (struct sockaddr *) &sockaddr, + sizeof (struct sockaddr_in6)); + + (*env)->ReleaseByteArrayElements (env, addr, elems, JNI_ABORT); + + if (-1 == ret) + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); +#else + THROW_NO_IPV6(env); +#endif +} + + +/* + * Class: gnu_java_net_VMPlainSocketImpl + * Method: listen + * Signature: (II)V + */ +JNIEXPORT void JNICALL +Java_gnu_java_net_VMPlainSocketImpl_listen (JNIEnv *env, + jclass c __attribute__((unused)), + jint fd, jint backlog) +{ + int ret; + + /* listen(2) says that this call will never return EINTR */ + /* listen is not a blocking system call */ + if ((ret = listen (fd, backlog)) == -1) + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); +} + + +/* These constants are also defined in java/net/SocketOptions.java. + * Except for CPNET_IP_TTL which is defined in + * vm/reference/gnu/java/net/VMPlainSocketImpl.java . + */ +enum java_sockopt { + CPNET_SO_KEEPALIVE = 0x8, + CPNET_SO_LINGER = 0x80, + CPNET_SO_TIMEOUT = 0x1006, + CPNET_SO_BINDADDR = 0x0F, + CPNET_SO_SNDBUF = 0x1001, + CPNET_SO_RCVBUF = 0x1002, + CPNET_SO_REUSEADDR = 0x04, + CPNET_SO_BROADCAST = 0x20, + CPNET_SO_OOBINLINE = 0x1003, + CPNET_TCP_NODELAY = 0x01, + CPNET_IP_MULTICAST_IF = 0x10, + CPNET_IP_MULTICAST_IF2 = 0x1F, + CPNET_IP_MULTICAST_LOOP = 0x12, + CPNET_IP_TOS = 0x03, + CPNET_IP_TTL = 0x1E61 +}; + + +/* + * Class: gnu_java_net_VMPlainSocketImpl + * Method: setOption + * Signature: (III)V + */ +JNIEXPORT void JNICALL +Java_gnu_java_net_VMPlainSocketImpl_setOption (JNIEnv *env, + jclass c __attribute__((unused)), + jint fd, jint option, jint value) +{ + enum java_sockopt joption = (enum java_sockopt) option; + int optname = -1; + int level = SOL_SOCKET; + const int _value = value; + struct linger _linger; + struct timeval _timeo; + void *optval = (void *) &_value; + socklen_t optlen = sizeof (int); + + switch (joption) + { + case CPNET_IP_MULTICAST_LOOP: + level = IPPROTO_IP; + optname = IP_MULTICAST_LOOP; + break; + + case CPNET_SO_KEEPALIVE: + optname = SO_KEEPALIVE; + break; + + case CPNET_SO_LINGER: + optname = SO_LINGER; + if (_value == -1) + _linger.l_onoff = 0; + else + _linger.l_onoff = 1; + _linger.l_linger = _value; + optval = &_linger; + optlen = sizeof (struct linger); + break; + + case CPNET_SO_TIMEOUT: + optname = SO_RCVTIMEO; + _timeo.tv_sec = value / 1000; + _timeo.tv_usec = (value % 1000) * 1000; + optval = &_timeo; + optlen = sizeof (struct timeval); + break; + + case CPNET_SO_SNDBUF: + optname = SO_SNDBUF; + break; + + case CPNET_SO_RCVBUF: + optname = SO_RCVBUF; + break; + + case CPNET_SO_REUSEADDR: + optname = SO_REUSEADDR; + break; + + case CPNET_SO_BROADCAST: + optname = SO_BROADCAST; + break; + + case CPNET_SO_OOBINLINE: + optname = SO_OOBINLINE; + break; + + case CPNET_TCP_NODELAY: + level = IPPROTO_TCP; + optname = TCP_NODELAY; + break; + + case CPNET_IP_TOS: + level = IPPROTO_IP; + optname = IP_TOS; + break; + + case CPNET_IP_TTL: + level = IPPROTO_IP; + optname = IP_TTL; + break; + + case CPNET_SO_BINDADDR: + case CPNET_IP_MULTICAST_IF: + case CPNET_IP_MULTICAST_IF2: + JCL_ThrowException (env, IO_EXCEPTION, "argument not a boolean or integer option"); + return; + } + + if (setsockopt (fd, level, optname, (const void *) optval, optlen) == -1) + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); +} + +/* + * Class: gnu_java_net_VMPlainSocketImpl + * Method: getOption + * Signature: (II)I + */ +JNIEXPORT jint JNICALL +Java_gnu_java_net_VMPlainSocketImpl_getOption (JNIEnv *env, + jclass c __attribute__((unused)), + jint fd, jint option) +{ + enum java_sockopt joption = (enum java_sockopt) option; + int optname = -1; + int level = SOL_SOCKET; + int value; + struct linger linger; + struct timeval timeo; + void *optval = &value; + socklen_t optlen = sizeof (int); + + switch (joption) + { + case CPNET_IP_MULTICAST_LOOP: + level = IPPROTO_IP; + optname = IP_MULTICAST_LOOP; + break; + + case CPNET_SO_KEEPALIVE: + optname = SO_KEEPALIVE; + break; + + case CPNET_SO_LINGER: + optname = SO_LINGER; + optval = &linger; + optlen = sizeof (struct linger); + break; + + case CPNET_SO_TIMEOUT: + optname = SO_RCVTIMEO; + optval = &timeo; + optlen = sizeof (struct timeval); + break; + + case CPNET_SO_SNDBUF: + optname = SO_SNDBUF; + break; + + case CPNET_SO_RCVBUF: + optname = SO_RCVBUF; + break; + + case CPNET_SO_REUSEADDR: + optname = SO_REUSEADDR; + break; + + case CPNET_SO_BROADCAST: + optname = SO_BROADCAST; + break; + + case CPNET_SO_OOBINLINE: + optname = SO_OOBINLINE; + break; + + case CPNET_TCP_NODELAY: + level = IPPROTO_TCP; + optname = TCP_NODELAY; + break; + + case CPNET_IP_TOS: + level = IPPROTO_IP; + optname = IP_TOS; + break; + + case CPNET_IP_TTL: + level = IPPROTO_IP; + optname = IP_TTL; + break; + + case CPNET_SO_BINDADDR: + case CPNET_IP_MULTICAST_IF: + case CPNET_IP_MULTICAST_IF2: + JCL_ThrowException (env, IO_EXCEPTION, "argument not a boolean or integer option"); + return -1; + } + + if (getsockopt (fd, level, optname, optval, &optlen) == -1) + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); + + /* Returns the linger value if it is enabled or -1 in case + * it is disabled. This is how the Java API expects it. + */ + if (joption == CPNET_SO_LINGER) + return (linger.l_onoff) ? linger.l_linger : -1; + if (joption == CPNET_SO_TIMEOUT) + return (timeo.tv_sec * 1000) + (timeo.tv_usec / 1000); + + return value; +} + +JNIEXPORT void JNICALL +Java_gnu_java_net_VMPlainSocketImpl_setMulticastInterface (JNIEnv *env, + jclass c __attribute__((unused)), + jint fd, + jint optionId __attribute__((unused)), + jobject addr) +{ + int result; + cpnet_address *cpaddr = _javanet_get_ip_netaddr (env, addr); + + if ((*env)->ExceptionOccurred (env)) + return; + + result = setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, + (struct sockaddr *) cpaddr->data, cpaddr->len); + + cpnet_freeAddress (env, cpaddr); + + if (result == -1) + JCL_ThrowException (env, SOCKET_EXCEPTION, cpnative_getErrorString (errno)); +} + +JNIEXPORT void JNICALL +Java_gnu_java_net_VMPlainSocketImpl_setMulticastInterface6 (JNIEnv *env, + jclass c __attribute__((unused)), + jint fd, + jint optionId __attribute__((unused)), + jstring ifname) +{ +#ifdef HAVE_SETSOCKOPT +#ifdef HAVE_INET6 + int result; + const char *str_ifname = JCL_jstring_to_cstring (env, ifname); + unsigned int if_index; + + if ((*env)->ExceptionOccurred (env)) + { + JCL_free_cstring(env, ifname, str_ifname); + return; + } + + if_index = if_nametoindex(str_ifname); + if (!if_index) + { + JCL_free_cstring(env, ifname, str_ifname); + JCL_ThrowException (env, SOCKET_EXCEPTION, "interface does not exist"); + return; + } + + result = setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_IF, + (unsigned int *) &if_index, sizeof(if_index)); + + JCL_free_cstring(env, ifname, str_ifname); + + if (result == -1) + JCL_ThrowException (env, SOCKET_EXCEPTION, cpnative_getErrorString (errno)); +#else + (void) fd; + JCL_ThrowException (env, "java/lang/InternalError", + "IPv6 support not available"); +#endif /* HAVE_INET6 */ +#else + (void) fd; + THROW_NO_IPV6(env); +#endif /* HAVE_SETSOCKOPT */ +} + +JNIEXPORT jobject JNICALL +Java_gnu_java_net_VMPlainSocketImpl_getMulticastInterface (JNIEnv *env, + jclass c __attribute__((unused)), + jint fd, + jint optionId __attribute__((unused))) +{ + jobject obj; + cpnet_address *cpaddr; + int result = cpnet_getMulticastIF (env, fd, &cpaddr); + + if (result != CPNATIVE_OK) + { + JCL_ThrowException (env, SOCKET_EXCEPTION, + cpnative_getErrorString (result)); + return (0); + } + + obj = _javanet_create_inetaddress (env, cpaddr); + cpnet_freeAddress (env, cpaddr); + + return obj; +} + + +/* + * Class: gnu_java_net_VMPlainSocketImpl + * Method: shutdownInput + * Signature: (I)V + */ +JNIEXPORT void JNICALL +Java_gnu_java_net_VMPlainSocketImpl_shutdownInput (JNIEnv *env, + jclass c __attribute__((unused)), + jint fd) +{ + if (shutdown (fd, SHUT_RD) == -1) + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); +} + +/* + * Class: gnu_java_net_VMPlainSocketImpl + * Method: shutdownOutput + * Signature: (I)V + */ +JNIEXPORT void JNICALL +Java_gnu_java_net_VMPlainSocketImpl_shutdownOutput (JNIEnv *env, + jclass c __attribute__((unused)), + jint fd) +{ + if (shutdown (fd, SHUT_WR) == -1) + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); +} + + +/* + * Class: gnu_java_net_VMPlainSocketImpl + * Method: sendUrgentData + * Signature: (II)V + */ +JNIEXPORT void JNICALL +Java_gnu_java_net_VMPlainSocketImpl_sendUrgentData (JNIEnv *env, + jclass c __attribute__((unused)), + jint fd, jint data) +{ + const char x = (char) data; + + if (send (fd, &x, 1, MSG_OOB) == -1) + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); +} + + +/* + * Class: gnu_java_net_VMPlainSocketImpl + * Method: join + * Signature: (I[B)V + */ +JNIEXPORT void JNICALL +Java_gnu_java_net_VMPlainSocketImpl_join (JNIEnv *env, + jclass clazz __attribute__((unused)), + jint fd, jbyteArray addr) +{ +#ifdef HAVE_SETSOCKOPT + struct ip_mreq maddr; + jbyte *addr_elems; + + addr_elems = (*env)->GetByteArrayElements (env, addr, NULL); + if (addr_elems == NULL) + return; + + maddr.imr_multiaddr.s_addr = * ((uint32_t *) addr_elems); + maddr.imr_interface.s_addr = INADDR_ANY; + + (*env)->ReleaseByteArrayElements (env, addr, addr_elems, JNI_ABORT); + + if (-1 == setsockopt (fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, + &maddr, sizeof (struct ip_mreq))) + JCL_ThrowException (env, SOCKET_EXCEPTION, strerror (errno)); +#else + (void) fd; + (void) addr; + JCL_ThrowException (env, "java/lang/InternalError", + "socket options not supported"); +#endif /* HAVE_SETSOCKOPT */ +} + + +/* + * Class: gnu_java_net_VMPlainSocketImpl + * Method: join6 + * Signature: (I[B)V + */ +JNIEXPORT void JNICALL +Java_gnu_java_net_VMPlainSocketImpl_join6 (JNIEnv *env, + jclass clazz __attribute__((unused)), + jint fd, jbyteArray addr) +{ +#ifdef HAVE_SETSOCKOPT +#ifdef HAVE_INET6 + struct ipv6_mreq maddr; + jbyte *addr_elems; + + addr_elems = (*env)->GetByteArrayElements (env, addr, NULL); + if (addr_elems == NULL) + return; + + memcpy (&(maddr.ipv6mr_multiaddr.s6_addr), addr_elems, 16); + maddr.ipv6mr_interface = 0; + + (*env)->ReleaseByteArrayElements (env, addr, addr_elems, JNI_ABORT); + + if (-1 == setsockopt (fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, + &maddr, sizeof (struct ipv6_mreq))) + JCL_ThrowException (env, SOCKET_EXCEPTION, strerror (errno)); +#else + (void) fd; + (void) addr; + THROW_NO_IPV6(env); +#endif /* HAVE_INET6 */ +#else + (void) fd; + (void) addr; + JCL_ThrowException (env, "java/lang/InternalError", + "socket options not supported"); +#endif /* HAVE_SETSOCKOPT */ +} + +/* + * Class: gnu_java_net_VMPlainSocketImpl + * Method: leave + * Signature: (I[B)V + */ +JNIEXPORT void JNICALL +Java_gnu_java_net_VMPlainSocketImpl_leave (JNIEnv *env, + jclass c __attribute__((unused)), + jint fd, jbyteArray addr) +{ +#ifdef HAVE_SETSOCKOPT + struct ip_mreq maddr; + jbyte *addr_elems; + + addr_elems = (*env)->GetByteArrayElements (env, addr, NULL); + if (addr_elems == NULL) + return; + + maddr.imr_multiaddr.s_addr = * ((uint32_t *) addr_elems); + maddr.imr_interface.s_addr = INADDR_ANY; + + (*env)->ReleaseByteArrayElements (env, addr, addr_elems, JNI_ABORT); + + if (-1 == setsockopt (fd, IPPROTO_IP, IP_DROP_MEMBERSHIP, + &maddr, sizeof (struct ip_mreq))) + JCL_ThrowException (env, SOCKET_EXCEPTION, strerror (errno)); +#else + (void) fd; + (void) addr; + JCL_ThrowException (env, "java/lang/InternalError", + "socket options not supported"); +#endif /* HAVE_SETSOCKOPT */ +} + +/* + * Class: gnu_java_net_VMPlainSocketImpl + * Method: leave6 + * Signature: (I[B)V + */ +JNIEXPORT void JNICALL +Java_gnu_java_net_VMPlainSocketImpl_leave6 (JNIEnv *env, + jclass c __attribute__((unused)), + jint fd, jbyteArray addr) +{ +#ifdef HAVE_SETSOCKOPT +#ifdef HAVE_INET6 + struct ipv6_mreq maddr; + jbyte *addr_elems; + + addr_elems = (*env)->GetByteArrayElements (env, addr, NULL); + if (addr_elems == NULL) + return; + + memcpy (&(maddr.ipv6mr_multiaddr.s6_addr), addr_elems, 16); + maddr.ipv6mr_interface = 0; + + (*env)->ReleaseByteArrayElements (env, addr, addr_elems, JNI_ABORT); + + if (-1 == setsockopt (fd, IPPROTO_IPV6, IPV6_LEAVE_GROUP, + &maddr, sizeof (struct ipv6_mreq))) + JCL_ThrowException (env, SOCKET_EXCEPTION, strerror (errno)); +#else + (void) fd; + (void) addr; + THROW_NO_IPV6(env); +#endif /* HAVE_INET6 */ +#else + (void) fd; + (void) addr; + JCL_ThrowException (env, "java/lang/InternalError", + "socket options not supported"); +#endif /* HAVE_SETSOCKOPT */ +} + +static uint32_t getif_address (JNIEnv *env, const char *ifname); +static int getif_index (JNIEnv *env, const char *ifname); + +/* + * Class: gnu_java_net_VMPlainSocketImpl + * Method: joinGroup + * Signature: (I[BILjava/lang/String;)V + */ +JNIEXPORT void JNICALL +Java_gnu_java_net_VMPlainSocketImpl_joinGroup (JNIEnv *env, + jclass c __attribute__((unused)), + jint fd, jbyteArray addr, + jstring ifname) +{ +#ifdef HAVE_SETSOCKOPT + struct ip_mreq maddr; + jbyte *addr_elems; + const char *str_ifname; + + if (ifname != NULL) + { + str_ifname = JCL_jstring_to_cstring(env, ifname); + maddr.imr_interface.s_addr = getif_address (env, str_ifname); + JCL_free_cstring(env, ifname, str_ifname); + + if ((*env)->ExceptionCheck (env)) + return; + } + else + maddr.imr_interface.s_addr = INADDR_ANY; + + addr_elems = (*env)->GetByteArrayElements (env, addr, NULL); + if (addr_elems == NULL) + return; + + maddr.imr_multiaddr.s_addr = * ((uint32_t *) addr_elems); + + (*env)->ReleaseByteArrayElements (env, addr, addr_elems, JNI_ABORT); + + if (-1 == setsockopt (fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, + &maddr, sizeof (struct ip_mreq))) + JCL_ThrowException (env, SOCKET_EXCEPTION, strerror (errno)); + +#else + (void) fd; + (void) addr; + (void) ifname; + JCL_ThrowException (env, "java/lang/InternalError", + "socket options not supported"); +#endif /* HAVE_SETSOCKOPT */ +} + +/* + * Class: gnu_java_net_VMPlainSocketImpl + * Method: joinGroup6 + * Signature: (I[BILjava/lang/String;)V + */ +JNIEXPORT void JNICALL +Java_gnu_java_net_VMPlainSocketImpl_joinGroup6 (JNIEnv *env, + jclass c __attribute__((unused)), + jint fd, jbyteArray addr, + jstring ifname) +{ +#ifdef HAVE_SETSOCKOPT +#ifdef HAVE_INET6 + struct ipv6_mreq maddr; + jbyte *addr_elems; + const char *str_ifname; + + if (ifname == NULL) + { + str_ifname = JCL_jstring_to_cstring(env, ifname); + maddr.ipv6mr_interface = getif_index (env, str_ifname); + JCL_free_cstring(env, ifname, str_ifname); + + if ((*env)->ExceptionCheck (env)) + return; + } + else + maddr.ipv6mr_interface = 0; + + addr_elems = (*env)->GetByteArrayElements (env, addr, NULL); + if (addr_elems == NULL) + return; + + memcpy (&(maddr.ipv6mr_multiaddr.s6_addr), addr_elems, 16); + + (*env)->ReleaseByteArrayElements (env, addr, addr_elems, JNI_ABORT); + + if (-1 == setsockopt (fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, + &maddr, sizeof (struct ipv6_mreq))) + JCL_ThrowException (env, SOCKET_EXCEPTION, strerror (errno)); +#else + (void) fd; + (void) addr; + THROW_NO_IPV6(env); +#endif /* HAVE_INET6 */ +#else + (void) fd; + (void) addr; + JCL_ThrowException (env, "java/lang/InternalError", + "socket options not supported"); +#endif /* HAVE_SETSOCKOPT */ +} + +/* + * Class: gnu_java_net_VMPlainSocketImpl + * Method: leaveGroup + * Signature: (I[BILjava/lang/String;)V + */ +JNIEXPORT void JNICALL +Java_gnu_java_net_VMPlainSocketImpl_leaveGroup (JNIEnv *env, + jclass c __attribute__((unused)), + jint fd, jbyteArray addr, + jstring ifname) +{ +#ifdef HAVE_SETSOCKOPT + struct ip_mreq maddr; + jbyte *addr_elems; + const char *str_ifname; + + if (ifname != NULL) + { + str_ifname = JCL_jstring_to_cstring(env, ifname); + maddr.imr_interface.s_addr = getif_address (env, str_ifname); + JCL_free_cstring(env, ifname, str_ifname); + + if ((*env)->ExceptionCheck (env)) + return; + } + else + maddr.imr_interface.s_addr = INADDR_ANY; + + addr_elems = (*env)->GetByteArrayElements (env, addr, NULL); + if (addr_elems == NULL) + return; + + maddr.imr_multiaddr.s_addr = * ((uint32_t *) addr_elems); + + (*env)->ReleaseByteArrayElements (env, addr, addr_elems, JNI_ABORT); + + if (-1 == setsockopt (fd, IPPROTO_IP, IP_DROP_MEMBERSHIP, + &maddr, sizeof (struct ip_mreq))) + JCL_ThrowException (env, SOCKET_EXCEPTION, strerror (errno)); +#else + (void) fd; + (void) addr; + (void) ifname; + JCL_ThrowException (env, "java/lang/InternalError", + "socket options not supported"); +#endif /* HAVE_SETSOCKOPT */ +} + +/* + * Class: gnu_java_net_VMPlainSocketImpl + * Method: leaveGroup6 + * Signature: (I[BILjava/lang/String;)V + */ +JNIEXPORT void JNICALL +Java_gnu_java_net_VMPlainSocketImpl_leaveGroup6 (JNIEnv *env, + jclass c __attribute__((unused)), + jint fd, jbyteArray addr, + jstring ifname) +{ +#ifdef HAVE_SETSOCKOPT +#ifdef HAVE_INET6 + struct ipv6_mreq maddr; + jbyte *addr_elems; + const char *str_ifname; + + if (ifname == NULL) + { + str_ifname = JCL_jstring_to_cstring(env, ifname); + maddr.ipv6mr_interface = getif_index (env, str_ifname); + JCL_free_cstring(env, ifname, str_ifname); + + if ((*env)->ExceptionCheck (env)) + return; + } + else + maddr.ipv6mr_interface = 0; + + addr_elems = (*env)->GetByteArrayElements (env, addr, NULL); + if (addr_elems == NULL) + return; + + memcpy (&(maddr.ipv6mr_multiaddr.s6_addr), addr_elems, 16); + + (*env)->ReleaseByteArrayElements (env, addr, addr_elems, JNI_ABORT); + + if (-1 == setsockopt (fd, IPPROTO_IPV6, IPV6_LEAVE_GROUP, + &maddr, sizeof (struct ipv6_mreq))) + JCL_ThrowException (env, SOCKET_EXCEPTION, strerror (errno)); +#else + (void) fd; + (void) addr; + THROW_NO_IPV6(env); +#endif /* HAVE_INET6 */ +#else + (void) fd; + (void) addr; + JCL_ThrowException (env, "java/lang/InternalError", + "socket options not supported"); +#endif /* HAVE_SETSOCKOPT */ +} + +static uint32_t +getif_address (JNIEnv *env, const char *ifname) +{ +#if defined (HAVE_IFADDRS_H) && defined (HAVE_GETIFADDRS) + struct ifaddrs *ifaddrs, *i; + uint32_t addr = 0; + int foundaddr = 0; + + if (getifaddrs (&ifaddrs) == -1) + { + JCL_ThrowException (env, SOCKET_EXCEPTION, strerror (errno)); + return 0; + } + + for (i = ifaddrs; i != NULL; i = i->ifa_next) + { + if (strcmp (ifname, i->ifa_name) == 0) + { + /* Matched the name; see if there is an IPv4 address. */ + if (i->ifa_addr->sa_family == AF_INET) + { + foundaddr = 1; + addr = ((struct sockaddr_in *) i->ifa_addr)->sin_addr.s_addr; + break; + } + } + } + + if (!foundaddr) + JCL_ThrowException (env, SOCKET_EXCEPTION, "interface has no IPv4 address"); + + freeifaddrs (ifaddrs); + + return addr; +#else + (void) ifname; + JCL_ThrowException (env, "java/lang/InternalError", + "getifaddrs not available"); + return 0; +#endif /* HAVE_IFADDRS_H && HAVE_GETIFADDRS */ +} + +static int +getif_index (JNIEnv *env, const char *ifname) +{ +#if defined (HAVE_IFADDRS_H) && defined (HAVE_GETIFADDRS) + struct ifaddrs *ifaddrs, *i; + char *lastname = NULL; + int index = 1; + int foundname = 0; + + if (getifaddrs (&ifaddrs) == -1) + { + JCL_ThrowException (env, SOCKET_EXCEPTION, strerror (errno)); + return -1; + } + + lastname = ifaddrs->ifa_name; + for (i = ifaddrs; i != NULL; i = i->ifa_next) + { + if (strcmp (lastname, ifaddrs->ifa_name) != 0) + { + lastname = ifaddrs->ifa_name; + index++; + } + if (strcmp (ifname, ifaddrs->ifa_name) == 0) + { + foundname = 1; + break; + } + } + + if (!foundname) + JCL_ThrowException (env, SOCKET_EXCEPTION, + "no interface with that name"); + + freeifaddrs (ifaddrs); + + return index; +#else + (void) ifname; + JCL_ThrowException (env, "java/lang/InternalError", + "getifaddrs not available"); + return -1; +#endif /* HAVE_GETIFADDRS */ +} diff --git a/libjava/classpath/native/jni/java-net/gnu_java_net_local_LocalSocketImpl.c b/libjava/classpath/native/jni/java-net/gnu_java_net_local_LocalSocketImpl.c new file mode 100644 index 000000000..288653d51 --- /dev/null +++ b/libjava/classpath/native/jni/java-net/gnu_java_net_local_LocalSocketImpl.c @@ -0,0 +1,517 @@ +/* gnu_java_net_local_LocalSocketImpl.c -- native local socket implementation. + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#include "config.h" + +#include + +#include +#include "local.h" + +#ifdef DEBUG +#define TRACE(msg) fprintf (stderr, "%s(%s:%d) -- %s\n", __FUNCTION__, __FILE__, __LINE__, msg) +#else +#define TRACE(msg) +#endif + +static void +_throw (JNIEnv *env, const char *exception, const char *msg) +{ + jclass _theclass = (*env)->FindClass (env, exception); + TRACE("begin"); + if (!_theclass) + { + (*env)->FatalError (env, "exception class not found"); + } + (*env)->ThrowNew (env, _theclass, msg); + TRACE("end"); +} + +void +Java_gnu_java_net_local_LocalSocketImpl_create (JNIEnv *env, jobject this, jboolean stream) +{ +#ifdef ENABLE_LOCAL_SOCKETS + jfieldID socket_fd, created; + jclass clazz; + jint fd = (jint) local_create ((int) stream); + + TRACE("begin"); + + if (fd < 0) + { + _throw (env, "java/io/IOException", local_error ()); + return; + } + clazz = (*env)->GetObjectClass (env, this); + socket_fd = (*env)->GetFieldID (env, clazz, "socket_fd", "I"); + if (!socket_fd) + { + return; + } + created = (*env)->GetFieldID (env, clazz, "created", "Z"); + if (!created) + { + return; + } + (*env)->SetIntField (env, this, socket_fd, fd); + (*env)->SetBooleanField (env, this, created, JNI_TRUE); + + TRACE("end"); +#else + (void) this; + (void) stream; + _throw (env, "java/lang/Error", "support for local sockets not available"); +#endif /* ENABLE_LOCAL_SOCKETS */ +} + + +void +Java_gnu_java_net_local_LocalSocketImpl_listen (JNIEnv *env, jobject this, jint backlog) +{ +#ifdef ENABLE_LOCAL_SOCKETS + jfieldID socket_fd; + jclass clazz; + int fd; + + TRACE("begin"); + + clazz = (*env)->GetObjectClass (env, this); + socket_fd = (*env)->GetFieldID (env, clazz, "socket_fd", "I"); + if (!socket_fd) + { + return; + } + fd = (int) (*env)->GetIntField (env, this, socket_fd); + if (local_listen (fd, (int) backlog)) + { + _throw (env, "java/io/IOException", local_error ()); + return; + } + + TRACE("end"); +#else + (void) this; + (void) backlog; + _throw (env, "java/lang/Error", "support for local sockets not available"); +#endif /* ENABLE_LOCAL_SOCKETS */ +} + + +void +Java_gnu_java_net_local_LocalSocketImpl_accept (JNIEnv *env, jobject this, jobject socket) +{ +#ifdef ENABLE_LOCAL_SOCKETS + jmethodID addr_init; + jfieldID socket_fd, remote_addr, local_addr; + jclass clazz1, clazz2; + jobject remote, local; + jint fd; + char path[108]; + + TRACE("begin"); + + clazz1 = (*env)->GetObjectClass (env, this); + socket_fd = (*env)->GetFieldID (env, clazz1, "socket_fd", "I"); + if (!socket_fd) + { + return; + } + fd = (*env)->GetIntField (env, this, socket_fd); + fd = (jint) local_accept ((int) fd, path); + if (fd < 0) + { + _throw (env, "java/io/IOException", local_error ()); + return; + } + + clazz2 = (*env)->FindClass (env, "gnu/java/net/local/LocalSocketAddress"); + if (!clazz2) + { + return; + } + addr_init = (*env)->GetMethodID (env, clazz2, "", "(Ljava/lang/String;)V"); + if (!addr_init) + { + return; + } + remote = (*env)->NewObject (env, clazz2, addr_init, (*env)->NewStringUTF (env, path)); + + remote_addr = (*env)->GetFieldID (env, clazz1, "remote", "Lgnu/java/net/local/LocalSocketAddress;"); + if (!remote_addr) + { + return; + } + local_addr = (*env)->GetFieldID (env, clazz1, "local", "Lgnu/java/net/local/LocalSocketAddress;"); + if (!local_addr) + { + return; + } + local = (*env)->GetObjectField (env, this, local_addr); + (*env)->SetIntField (env, socket, socket_fd, fd); + (*env)->SetObjectField (env, socket, remote_addr, remote); + (*env)->SetObjectField (env, socket, local_addr, local); + + TRACE("end"); +#else + (void) this; + (void) socket; + _throw (env, "java/lang/Error", "support for local sockets not available"); +#endif /* ENABLE_LOCAL_SOCKETS */ +} + + +jint +Java_gnu_java_net_local_LocalSocketImpl_available +(JNIEnv *env, jobject this __attribute__((unused)), jint fd) +{ +#ifdef ENABLE_LOCAL_SOCKETS + jint avail; + + TRACE("begin"); + + avail = (jint) local_available (fd); + if (avail < 0) + { + _throw (env, "java/io/IOException", local_error ()); + return 0; + } + + TRACE("end"); + + return avail; +#else + (void) this; + (void) fd; + _throw (env, "java/lang/Error", "support for local sockets not available"); + return -1; +#endif /* ENABLE_LOCAL_SOCKETS */ +} + + +void +Java_gnu_java_net_local_LocalSocketImpl_close (JNIEnv *env, jobject this) +{ +#ifdef ENABLE_LOCAL_SOCKETS + jfieldID socket_fd; + jclass clazz; + int fd; + + TRACE("begin"); + + clazz = (*env)->GetObjectClass (env, this); + socket_fd = (*env)->GetFieldID (env, clazz, "socket_fd", "I"); + if (!socket_fd) + { + return; + } + fd = (int) (*env)->GetIntField (env, this, socket_fd); + if (local_close (fd)) + { + _throw (env, "java/io/IOException", local_error ()); + } + + TRACE("end"); +#else + (void) this; + _throw (env, "java/lang/Error", "support for local sockets not available"); +#endif /* ENABLE_LOCAL_SOCKETS */ +} + + +void +Java_gnu_java_net_local_LocalSocketImpl_unlink (JNIEnv *env, jobject this) +{ +#ifdef ENABLE_LOCAL_SOCKETS + jfieldID local; + jmethodID get_path; + jclass clazz1, clazz2; + jobject local_ref, path; + char *addr_path; + + TRACE("begin"); + + clazz1 = (*env)->GetObjectClass (env, this); + local = (*env)->GetFieldID (env, clazz1, "local", "Lgnu/java/net/local/LocalSocketAddress;"); + if (!local) + { + return; + } + local_ref = (*env)->GetObjectField (env, this, local); + clazz2 = (*env)->GetObjectClass (env, local_ref); + get_path = (*env)->GetMethodID (env, clazz2, "getPath", "()Ljava/lang/String;"); + if (!get_path) + { + return; + } + path = (*env)->CallObjectMethod (env, local_ref, get_path); + addr_path = (char *) (*env)->GetStringUTFChars (env, (jstring) path, NULL); + if (local_unlink (addr_path)) + { + _throw (env, "java/io/IOException", local_error ()); + } + (*env)->ReleaseStringUTFChars (env, (jstring) path, addr_path); + + TRACE("end"); +#else + (void) this; + _throw (env, "java/lang/Error", "support for local sockets not available"); +#endif /* ENABLE_LOCAL_SOCKETS */ +} + + +void +Java_gnu_java_net_local_LocalSocketImpl_sendUrgentData (JNIEnv *env, jobject this __attribute__((unused)), jint data __attribute__((unused))) +{ + /* XXX I don't remember why I have this. Probably should just + remove. */ + (*env)->FatalError (env, "Java_gnu_java_net_local_LocalSocketImpl_shutdownInput (JNIEnv *env, jobject) not implemented"); +} + + +void +Java_gnu_java_net_local_LocalSocketImpl_shutdownInput (JNIEnv *env, jobject this) +{ +#ifdef ENABLE_LOCAL_SOCKETS + jfieldID socket_fd; + jclass clazz; + int fd; + + TRACE("begin"); + + clazz = (*env)->GetObjectClass (env, this); + socket_fd = (*env)->GetFieldID (env, clazz, "socket_fd", "I"); + if (!socket_fd) + { + return; + } + fd = (*env)->GetIntField (env, this, socket_fd); + if (local_shutdown_input (fd)) + { + _throw (env, "java/io/IOException", local_error ()); + } + + TRACE("end"); +#else + (void) this; + _throw (env, "java/lang/Error", "support for local sockets not available"); +#endif /* ENABLE_LOCAL_SOCKETS */ +} + + +void +Java_gnu_java_net_local_LocalSocketImpl_shutdownOutput (JNIEnv *env, jobject this) +{ +#ifdef ENABLE_LOCAL_SOCKETS + jfieldID socket_fd; + jclass clazz; + int fd; + + TRACE("begin"); + + clazz = (*env)->GetObjectClass (env, this); + socket_fd = (*env)->GetFieldID (env, clazz, "socket_fd", "I"); + if (!socket_fd) + { + return; + } + fd = (*env)->GetIntField (env, this, socket_fd); + if (local_shutdown_output (fd)) + { + _throw (env, "java/io/IOException", local_error ()); + } + + TRACE("end"); +#else + (void) this; + _throw (env, "java/lang/Error", "support for local sockets not available"); +#endif /* ENABLE_LOCAL_SOCKETS */ +} + + +void +Java_gnu_java_net_local_LocalSocketImpl_localBind (JNIEnv *env, jobject this, jobject address) +{ +#ifdef ENABLE_LOCAL_SOCKETS + jfieldID socket_fd; + jmethodID get_path; + jobject path; + jclass clazz1, clazz2; + const char *addr_path; + int fd; + + TRACE("begin"); + + clazz1 = (*env)->GetObjectClass (env, this); + socket_fd = (*env)->GetFieldID (env, clazz1, "socket_fd", "I"); + if (!socket_fd) + { + return; + } + fd = (int) (*env)->GetIntField (env, this, socket_fd); + clazz2 = (*env)->GetObjectClass (env, address); + get_path = (*env)->GetMethodID (env, clazz2, "getPath", "()Ljava/lang/String;"); + path = (*env)->CallObjectMethod (env, address, get_path); + addr_path = (*env)->GetStringUTFChars (env, (jstring) path, NULL); + if (local_bind (fd, addr_path)) + { + _throw (env, "java/io/IOException", local_error ()); + } + (*env)->ReleaseStringUTFChars (env, (jstring) path, addr_path); + + TRACE("end"); +#else + (void) this; + (void) address; + _throw (env, "java/lang/Error", "support for local sockets not available"); +#endif /* ENABLE_LOCAL_SOCKETS */ +} + + +void +Java_gnu_java_net_local_LocalSocketImpl_localConnect (JNIEnv *env, jobject this, jobject address) +{ +#ifdef ENABLE_LOCAL_SOCKETS + jfieldID socket_fd; + jmethodID get_path; + jobject path; + jclass clazz1, clazz2; + char *addr_path; + int fd; + + TRACE("begin"); + + clazz1 = (*env)->GetObjectClass (env, this); + socket_fd = (*env)->GetFieldID (env, clazz1, "socket_fd", "I"); + if (!socket_fd) + { + return; + } + fd = (int) (*env)->GetIntField (env, this, socket_fd); + clazz2 = (*env)->GetObjectClass (env, address); + get_path = (*env)->GetMethodID (env, clazz2, "getPath", "()Ljava/lang/String;"); + path = (*env)->CallObjectMethod (env, address, get_path); + addr_path = (char *) (*env)->GetStringUTFChars (env, (jstring) path, NULL); + if (local_connect (fd, addr_path)) + { + _throw (env, "java/io/IOException", local_error ()); + } + (*env)->ReleaseStringUTFChars (env, (jstring) path, addr_path); + + TRACE("end"); +#else + (void) this; + (void) address; + _throw (env, "java/lang/Error", "support for local sockets not available"); +#endif /* ENABLE_LOCAL_SOCKETS */ +} + + +jint +Java_gnu_java_net_local_LocalSocketImpl_read +(JNIEnv *env, jobject this __attribute__((unused)), jint fd, jbyteArray buf, + jint off, jint len) +{ +#ifdef ENABLE_LOCAL_SOCKETS + jbyte *buffer; + jint count; + + TRACE("begin"); + + if (off < 0 || len < 0 || off + len > (*env)->GetArrayLength (env, buf)) + { + _throw (env, "java/lang/ArrayIndexOutOfBoundsException", ""); + } + + buffer = (*env)->GetByteArrayElements (env, buf, NULL); + count = (jint) local_read (fd, (void *) (buffer + off), (int) len); + if (count < 0) + { + _throw (env, "java/io/IOException", local_error ()); + } + (*env)->ReleaseByteArrayElements (env, buf, buffer, 0); + + TRACE("end"); + + return count; +#else + (void) this; + (void) fd; + (void) buf; + (void) off; + (void) len; + _throw (env, "java/lang/Error", "support for local sockets not available"); + return -1; +#endif /* ENABLE_LOCAL_SOCKETS */ +} + + +void +Java_gnu_java_net_local_LocalSocketImpl_write +(JNIEnv *env, jobject this __attribute__((unused)), jint fd, jbyteArray buf, + jint off, jint len) +{ +#ifdef ENABLE_LOCAL_SOCKETS + jbyte *buffer; + + TRACE("begin"); + + if (off < 0 || len < 0 || off + len > (*env)->GetArrayLength (env, buf)) + { + _throw (env, "java/lang/ArrayIndexOutOfBoundsException", ""); + } + + buffer = (*env)->GetByteArrayElements (env, buf, NULL); + if (local_write (fd, (void *) (buffer + off), (int) len) < 0) + { + _throw (env, "java/io/IOException", local_error ()); + } + (*env)->ReleaseByteArrayElements (env, buf, buffer, JNI_ABORT); + + TRACE("end"); +#else + (void) this; + (void) fd; + (void) buf; + (void) off; + (void) len; + _throw (env, "java/lang/Error", "support for local sockets not available"); +#endif /* ENABLE_LOCAL_SOCKETS */ +} diff --git a/libjava/classpath/native/jni/java-net/java_net_VMInetAddress.c b/libjava/classpath/native/jni/java-net/java_net_VMInetAddress.c new file mode 100644 index 000000000..6ee7773b8 --- /dev/null +++ b/libjava/classpath/native/jni/java-net/java_net_VMInetAddress.c @@ -0,0 +1,395 @@ +/* VMInetAddress.c - Native methods for InetAddress class + Copyright (C) 1998, 2002, 2005, 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +/* do not move; needed here because of some macro definitions */ +#include + +#include +#include +#include + +#include +#include + +#include "cpnative.h" +#include "cpnet.h" +#include "javanet.h" + +#include "java_net_VMInetAddress.h" + +/*************************************************************************/ + +/* + * Function to return the local hostname + */ +JNIEXPORT jstring JNICALL +Java_java_net_VMInetAddress_getLocalHostname (JNIEnv * env, + jclass class + __attribute__ ((__unused__))) +{ + char hostname[256]; + int result; + jstring retval; + +#ifndef WITHOUT_NETWORK + result = cpnet_getHostname (env, hostname, sizeof (hostname)); + if (result != CPNATIVE_OK) + { + strcpy (hostname, "localhost"); + } +#else /* not WITHOUT_NETWORK */ + strcpy (hostname, "localhost"); +#endif /* not WITHOUT_NETWORK */ + + retval = (*env)->NewStringUTF (env, hostname); + + return (retval); +} + +/*************************************************************************/ + +/* + * Returns the value of the special IP address INADDR_ANY + */ +JNIEXPORT jarray JNICALL +Java_java_net_VMInetAddress_lookupInaddrAny (JNIEnv * env, + jclass class + __attribute__ ((__unused__))) +{ + jarray IParray; + cpnet_address *addr; + jbyte *octets; + + /* Allocate an array for the IP address */ + IParray = (*env)->NewByteArray (env, 4); + if (IParray == NULL) + { + JCL_ThrowException (env, UNKNOWN_HOST_EXCEPTION, "Internal Error"); + return (jarray) NULL; + } + + /* Copy in the values */ + octets = (*env)->GetByteArrayElements (env, IParray, 0); + +#ifndef WITHOUT_NETWORK + addr = cpnet_newIPV4Address (env); + cpnet_setIPV4Any (addr); + cpnet_IPV4AddressToBytes (addr, octets); + cpnet_freeAddress (env, addr); +#else /* not WITHOUT_NETWORK */ + octets[0] = 0; + octets[1] = 0; + octets[2] = 0; + octets[3] = 0; +#endif /* not WITHOUT_NETWORK */ + + (*env)->ReleaseByteArrayElements (env, IParray, octets, 0); + + return (IParray); +} + +/*************************************************************************/ + +/* + * Function to return the canonical hostname for a given IP address passed + * in as a byte array + */ +JNIEXPORT jstring JNICALL +Java_java_net_VMInetAddress_getHostByAddr (JNIEnv * env, + jclass class + __attribute__ ((__unused__)), + jarray arr) +{ +#ifndef WITHOUT_NETWORK + jbyte *octets; + jsize len; + cpnet_address *addr; + char hostname[255]; + int result; + jstring retval; + + /* Grab the byte[] array with the IP out of the input data */ + len = (*env)->GetArrayLength (env, arr); + if (len != 4 && len != 16) + { + JCL_ThrowException (env, UNKNOWN_HOST_EXCEPTION, "Bad IP Address"); + return (jstring) NULL; + } + + octets = (*env)->GetByteArrayElements (env, arr, 0); + if (!octets) + { + JCL_ThrowException (env, UNKNOWN_HOST_EXCEPTION, "Bad IP Address"); + return (jstring) NULL; + } + + switch (len) + { + case 4: + addr = cpnet_newIPV4Address(env); + cpnet_bytesToIPV4Address (addr, octets); + break; +#ifdef HAVE_INET6 + case 16: + addr = cpnet_newIPV6Address(env); + cpnet_bytesToIPV6Address (addr, octets); + break; +#endif + default: + JCL_ThrowException (env, UNKNOWN_HOST_EXCEPTION, "Bad IP Address"); + return (jstring) NULL; + + } + + /* Release some memory */ + (*env)->ReleaseByteArrayElements (env, arr, octets, 0); + + /* Resolve the address and return the name */ + result = cpnet_getHostByAddr (env, addr, hostname, sizeof (hostname)); + if (result != CPNATIVE_OK) + { + JCL_ThrowException (env, UNKNOWN_HOST_EXCEPTION, + cpnative_getErrorString (result)); + return (jstring) NULL; + } + + retval = (*env)->NewStringUTF (env, hostname); + + return (retval); +#else /* not WITHOUT_NETWORK */ + return (jstring) NULL; +#endif /* not WITHOUT_NETWORK */ +} + +/*************************************************************************/ + +JNIEXPORT jobjectArray JNICALL +Java_java_net_VMInetAddress_getHostByName (JNIEnv * env, + jclass class + __attribute__ ((__unused__)), + jstring host) +{ +#ifndef WITHOUT_NETWORK + const char *hostname; + cpnet_address **addresses; + jsize addresses_count; + int result; + jclass arr_class; + jobjectArray addrs; + jint i; + jbyte *octets; + jarray ret_octets; + + /* Grab the hostname string */ + hostname = (*env)->GetStringUTFChars (env, host, 0); + if (!hostname) + { + JCL_ThrowException (env, UNKNOWN_HOST_EXCEPTION, "Null hostname"); + return (jobjectArray) NULL; + } + + result = cpnet_getHostByName (env, hostname, &addresses, &addresses_count); + if (result != CPNATIVE_OK || addresses_count == 0) + { + JCL_ThrowException (env, UNKNOWN_HOST_EXCEPTION, hostname); + return (jobjectArray) NULL; + } + (*env)->ReleaseStringUTFChars (env, host, hostname); + + arr_class = (*env)->FindClass (env, "[B"); + if (!arr_class) + { + JCL_ThrowException (env, UNKNOWN_HOST_EXCEPTION, "Internal Error"); + return (jobjectArray) NULL; + } + + addrs = (*env)->NewObjectArray (env, addresses_count, arr_class, 0); + if (!addrs) + { + JCL_ThrowException (env, UNKNOWN_HOST_EXCEPTION, "Internal Error"); + return (jobjectArray) NULL; + } + + /* Now loop and copy in each address */ + for (i = 0; i < addresses_count; i++) + { + if (cpnet_isIPV4Address (addresses[i])) + { + ret_octets = (*env)->NewByteArray (env, 4); + + if (!ret_octets) + { + JCL_ThrowException (env, UNKNOWN_HOST_EXCEPTION, "Internal Error"); + cpnet_freeAddresses (env, addresses, addresses_count); + return (jobjectArray) NULL; + } + + octets = (*env)->GetByteArrayElements (env, ret_octets, 0); + + cpnet_IPV4AddressToBytes (addresses[i], octets); + + (*env)->ReleaseByteArrayElements (env, ret_octets, octets, 0); + + (*env)->SetObjectArrayElement (env, addrs, i, ret_octets); + } +#ifdef HAVE_INET6 + else if (cpnet_isIPV6Address (addresses[i])) + { + ret_octets = (*env)->NewByteArray (env, 16); + + if (!ret_octets) + { + JCL_ThrowException (env, UNKNOWN_HOST_EXCEPTION, "Internal Error"); + cpnet_freeAddresses (env, addresses, addresses_count); + return (jobjectArray) NULL; + } + + octets = (*env)->GetByteArrayElements (env, ret_octets, 0); + + cpnet_IPV6AddressToBytes (addresses[i], octets); + + (*env)->ReleaseByteArrayElements (env, ret_octets, octets, 0); + + (*env)->SetObjectArrayElement (env, addrs, i, ret_octets); + } +#endif + else + { + JCL_ThrowException (env, UNKNOWN_HOST_EXCEPTION, "Internal Error"); + cpnet_freeAddresses (env, addresses, addresses_count); + return (jobjectArray) NULL; + } + } + + cpnet_freeAddresses (env, addresses, addresses_count); + + return (addrs); +#else /* not WITHOUT_NETWORK */ + return (jobjectArray) NULL; +#endif /* not WITHOUT_NETWORK */ +} + +/*************************************************************************/ + +/* + * Return the IP address represented by a literal address. + * Will return null if the literal address is not valid. + */ +JNIEXPORT jbyteArray JNICALL +Java_java_net_VMInetAddress_aton (JNIEnv *env, + jclass class + __attribute__ ((__unused__)), + jstring host) +{ +#ifndef WITHOUT_NETWORK + const char *hostname; + cpnet_address *address; + int result; + jbyte *octets; + jbyteArray ret_octets; + + hostname = (*env)->GetStringUTFChars (env, host, 0); + if (!hostname) + { + JCL_ThrowException (env, UNKNOWN_HOST_EXCEPTION, "Null hostname"); + return (jbyteArray) NULL; + } + + result = cpnet_aton (env, hostname, &address); + if (result != CPNATIVE_OK) + { + JCL_ThrowException (env, UNKNOWN_HOST_EXCEPTION, "Internal Error"); + if (address) + cpnet_freeAddress (env, address); + return (jbyteArray) NULL; + } + if (!address) + return (jbyteArray) NULL; + + if (cpnet_isIPV4Address (address)) + { + ret_octets = (jbyteArray) (*env)->NewByteArray (env, 4); + + if (!ret_octets) + { + JCL_ThrowException (env, UNKNOWN_HOST_EXCEPTION, "Internal Error"); + cpnet_freeAddress (env, address); + return (jbyteArray) NULL; + } + + octets = (*env)->GetByteArrayElements (env, ret_octets, 0); + + cpnet_IPV4AddressToBytes (address, octets); + + (*env)->ReleaseByteArrayElements (env, ret_octets, octets, 0); + } +#ifdef HAVE_INET6 + else if (cpnet_isIPV6Address (address)) + { + ret_octets = (jbyteArray) (*env)->NewByteArray (env, 16); + + if (!ret_octets) + { + JCL_ThrowException (env, UNKNOWN_HOST_EXCEPTION, "Internal Error"); + cpnet_freeAddress (env, address); + return (jbyteArray) NULL; + } + + octets = (*env)->GetByteArrayElements (env, ret_octets, 0); + + cpnet_IPV6AddressToBytes (address, octets); + + (*env)->ReleaseByteArrayElements (env, ret_octets, octets, 0); + } +#endif + else + { + JCL_ThrowException (env, UNKNOWN_HOST_EXCEPTION, "Internal Error"); + cpnet_freeAddress (env, address); + return (jbyteArray) NULL; + } + + cpnet_freeAddress (env, address); + + return (ret_octets); + +#else /* not WITHOUT_NETWORK */ + return (jbyteArray) NULL; +#endif /* not WITHOUT_NETWORK */ +} + +/* end of file */ diff --git a/libjava/classpath/native/jni/java-net/java_net_VMNetworkInterface.c b/libjava/classpath/native/jni/java-net/java_net_VMNetworkInterface.c new file mode 100644 index 000000000..658299733 --- /dev/null +++ b/libjava/classpath/native/jni/java-net/java_net_VMNetworkInterface.c @@ -0,0 +1,399 @@ +/* VMNetworkInterface.c - Native methods for NetworkInterface class + Copyright (C) 2003, 2005, 2006, 2008 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#ifdef HAVE_CONFIG_H +#include +#endif /* HAVE_CONFIG_H */ + +#include +#include +#ifdef HAVE_IFADDRS_H +#include +#endif +#include +#include +#include +#include +#include + +#include +#include +/* Required on Solaris. */ +#include + +#ifdef HAVE_SYS_SOCKIO_H +# include +#endif + +#include +#include + +#include +#include + +#include "java_net_VMNetworkInterface.h" + +int iff_flags(JNIEnv *, jstring, jint *); + +static jmethodID java_net_VMNetworkInterface_init; +static jmethodID java_net_VMNetworkInterface_addAddress; + +/* + * Initialize our static method ID's. + * + * Class: java_net_VMNetworkInterface + * Method: initIds + * Signature: ()V + */ +JNIEXPORT void JNICALL +Java_java_net_VMNetworkInterface_initIds (JNIEnv *env, jclass clazz) +{ + java_net_VMNetworkInterface_init = + (*env)->GetMethodID (env, clazz, "", "(Ljava/lang/String;)V"); + if (java_net_VMNetworkInterface_init == NULL) + { + if (!(*env)->ExceptionCheck (env)) + JCL_ThrowException (env, "java/lang/NoSuchMethodError", + "VMNetworkinterface.addAddress"); + return; + } + java_net_VMNetworkInterface_addAddress = + (*env)->GetMethodID (env, clazz, "addAddress", "(Ljava/nio/ByteBuffer;)V"); + if (java_net_VMNetworkInterface_addAddress == NULL) + { + if (!(*env)->ExceptionCheck (env)) + JCL_ThrowException (env, "java/lang/NoSuchMethodError", + "VMNetworkinterface.addAddress"); + } +} + +struct netif_entry +{ + char *name; + jobject netif; + int numaddrs; + struct netif_entry *next; +}; + +#if defined (HAVE_IFADDRS_H) && defined (HAVE_GETIFADDRS) +static void +free_netif_list (JNIEnv *env, struct netif_entry *list) +{ + while (list != NULL) + { + struct netif_entry *e = list->next; + JCL_free (env, list); + list = e; + } +} +#endif + +/* + * Returns all local network interfaces as an array. + */ +JNIEXPORT jobjectArray JNICALL +Java_java_net_VMNetworkInterface_getVMInterfaces (JNIEnv * env, + jclass clazz UNUSED) +{ +#if defined (HAVE_IFADDRS_H) && defined (HAVE_GETIFADDRS) + struct ifaddrs *ifaddrs, *i; + struct netif_entry *iflist = NULL, *e; + jobjectArray netifs; + int numifs = 0; + int k; + + if (getifaddrs (&ifaddrs) == -1) + { + JCL_ThrowException (env, "java/net/SocketException", strerror (errno)); + return NULL; + } + + for (i = ifaddrs; i != NULL; i = i->ifa_next) + { + if (iflist == NULL) + { + iflist = JCL_malloc (env, sizeof (struct netif_entry)); + if (iflist == NULL) + { + freeifaddrs (ifaddrs); + return NULL; + } + iflist->name = i->ifa_name; + iflist->numaddrs = 0; + iflist->next = NULL; + iflist->netif = (*env)->NewObject (env, clazz, java_net_VMNetworkInterface_init, + (*env)->NewStringUTF (env, i->ifa_name)); + if (iflist->netif == NULL) + { + freeifaddrs (ifaddrs); + JCL_free (env, iflist); + return NULL; + } + e = iflist; + } + else + { + struct netif_entry *p = NULL; + for (e = iflist; e != NULL; e = e->next) + { + if (strcmp (e->name, i->ifa_name) == 0) + break; + p = e; + } + + if (e == NULL) + { + p->next = (struct netif_entry *) JCL_malloc (env, sizeof (struct netif_entry)); + if (p->next == NULL) + { + free_netif_list (env, iflist); + freeifaddrs (ifaddrs); + return NULL; + } + e = p->next; + e->name = i->ifa_name; + e->numaddrs = 0; + e->next = NULL; + e->netif = (*env)->NewObject (env, clazz, java_net_VMNetworkInterface_init, + (*env)->NewStringUTF (env, i->ifa_name)); + if (e->netif == NULL) + { + free_netif_list (env, iflist); + freeifaddrs (ifaddrs); + return NULL; + } + } + } + + if (i->ifa_addr == NULL) + continue; + + if (i->ifa_addr->sa_family == AF_INET) + { + struct sockaddr_in *sin = (struct sockaddr_in *) i->ifa_addr; + jobject buffer = (*env)->NewDirectByteBuffer (env, &(sin->sin_addr.s_addr), 4); + (*env)->CallVoidMethod (env, e->netif, java_net_VMNetworkInterface_addAddress, + buffer); + if ((*env)->ExceptionCheck (env)) + { + free_netif_list (env, iflist); + freeifaddrs (ifaddrs); + return NULL; + } + (*env)->DeleteLocalRef (env, buffer); + e->numaddrs++; + } +#ifdef HAVE_INET6 + else if (i->ifa_addr->sa_family == AF_INET6) + { + struct sockaddr_in6 *sin = (struct sockaddr_in6 *) i->ifa_addr; + jobject buffer = (*env)->NewDirectByteBuffer (env, &(sin->sin6_addr.s6_addr), 16); + (*env)->CallVoidMethod (env, e->netif, java_net_VMNetworkInterface_addAddress, + buffer); + if ((*env)->ExceptionCheck (env)) + { + free_netif_list (env, iflist); + freeifaddrs (ifaddrs); + return NULL; + } + (*env)->DeleteLocalRef (env, buffer); + e->numaddrs++; + } +#endif /* HAVE_INET6 */ + } + + /* Count how many interfaces we have that have addresses. */ + for (e = iflist; e != NULL; e = e->next) + { + if (e->numaddrs != 0) + numifs++; + } + + netifs = (*env)->NewObjectArray (env, numifs, clazz, NULL); + k = 0; + for (e = iflist; e != NULL && k < numifs; e = e->next) + { + if (e->numaddrs != 0) + { + (*env)->SetObjectArrayElement (env, netifs, k, e->netif); + (*env)->DeleteLocalRef (env, e->netif); + k++; + } + } + + free_netif_list (env, iflist); + freeifaddrs (ifaddrs); + return netifs; +#else + JCL_ThrowException (env, "java/net/SocketException", "getifaddrs not supported"); + return NULL; +#endif /* HAVE_IFADDRS_H && HAVE_GETIFADDRS */ +} + +int iff_flags(JNIEnv *env, jstring name, jint *flags) +{ + struct ifreq iff; + const char *iff_name; + jint socket; + int error, retval; + + if ((error = cpnet_openSocketDatagram(env, &socket, AF_INET))) + { + return error; + } + + iff_name = JCL_jstring_to_cstring(env, name); + memset(&iff, 0, sizeof(iff)); + strcpy(iff.ifr_name, iff_name); + + if (ioctl(socket, SIOCGIFFLAGS, &iff) >= 0) + { + *flags = (jint) iff.ifr_flags; + + retval = 0; + } + else + { + retval = errno; + } + + cpnet_close(env, socket); + + JCL_free_cstring(env, name, iff_name); + + return retval; +} + +JNIEXPORT jboolean JNICALL +Java_java_net_VMNetworkInterface_isUp (JNIEnv *env, jclass class UNUSED, + jstring name) +{ + jint flags; + int error; + jboolean retval; + + if ((error = iff_flags(env, name, &flags))) + { + JCL_ThrowException(env, "java/net/SocketException", + cpnative_getErrorString(error)); + + retval = JNI_FALSE; + } + else + { + retval = (flags & (IFF_UP | IFF_RUNNING)) + ? JNI_TRUE + : JNI_FALSE; + } + + return retval; +} + +JNIEXPORT jboolean JNICALL +Java_java_net_VMNetworkInterface_isPointToPoint (JNIEnv *env, + jclass class UNUSED, + jstring name) +{ + jint flags; + int error; + jboolean retval; + + if ((error = iff_flags(env, name, &flags))) + { + JCL_ThrowException(env, "java/net/SocketException", + cpnative_getErrorString(error)); + + retval = JNI_FALSE; + } + else + { + retval = (flags & IFF_POINTOPOINT) ? JNI_TRUE + : JNI_FALSE; + } + + return retval; +} + +JNIEXPORT jboolean JNICALL +Java_java_net_VMNetworkInterface_isLoopback (JNIEnv *env, + jclass class UNUSED, + jstring name) +{ + jint flags; + int error; + jboolean retval; + + if ((error = iff_flags(env, name, &flags))) + { + JCL_ThrowException(env, "java/net/SocketException", + cpnative_getErrorString(error)); + + retval = JNI_FALSE; + } + else + { + retval = (flags & IFF_LOOPBACK) ? JNI_TRUE : JNI_FALSE; + } + + return retval; +} + +JNIEXPORT jboolean JNICALL +Java_java_net_VMNetworkInterface_supportsMulticast (JNIEnv *env, + jclass class UNUSED, + jstring name) +{ + jint flags; + int error; + jboolean retval; + + if ((error = iff_flags(env, name, &flags))) + { + JCL_ThrowException(env, "java/net/SocketException", + cpnative_getErrorString(error)); + + retval = JNI_FALSE; + } + else + { + retval = (flags & IFF_MULTICAST) ? JNI_TRUE : JNI_FALSE; + } + + return retval; +} + +/* end of file */ diff --git a/libjava/classpath/native/jni/java-net/java_net_VMURLConnection.c b/libjava/classpath/native/jni/java-net/java_net_VMURLConnection.c new file mode 100644 index 000000000..52fae0ccb --- /dev/null +++ b/libjava/classpath/native/jni/java-net/java_net_VMURLConnection.c @@ -0,0 +1,102 @@ +/* VMURLConnection.c - native bits for URLConnection + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include + +#include + +#ifdef HAVE_MAGIC_H + +#include + +static magic_t cookie; + +#endif /* HAVE_MAGIC_H */ + +void +Java_java_net_VMURLConnection_init (JNIEnv *env __attribute__ ((__unused__)), + jclass klass __attribute__ ((__unused__))) +{ +#ifdef HAVE_MAGIC_H + cookie = magic_open (MAGIC_MIME); + if (cookie == (magic_t) NULL) + return; + if (magic_load (cookie, NULL) == -1) + { + magic_close (cookie); + cookie = (magic_t) NULL; + } +#endif /* HAVE_MAGIC_H */ +} + +#ifdef HAVE_MAGIC_H +jstring +Java_java_net_VMURLConnection_guessContentTypeFromBuffer (JNIEnv *env, + jclass klass + __attribute__ ((__unused__)), + jbyteArray bytes, + jint valid) +{ + jbyte *elements; + const char *result; + + if (cookie == (magic_t) NULL) + return NULL; + + elements = (*env)->GetByteArrayElements (env, bytes, NULL); + result = magic_buffer (cookie, elements, valid); + + /* The mode we use doesn't matter, since we don't change the array. */ + (*env)->ReleaseByteArrayElements (env, bytes, elements, JNI_ABORT); + + if (result == NULL) + return NULL; + return (*env)->NewStringUTF (env, result); +#else +jstring +Java_java_net_VMURLConnection_guessContentTypeFromBuffer (JNIEnv *env + __attribute__ ((__unused__)), + jclass klass + __attribute__ ((__unused__)), + jbyteArray bytes + __attribute__ ((__unused__)), + jint valid + __attribute__ ((__unused__))) +{ + return NULL; +#endif /* HAVE_MAGIC_H */ +} diff --git a/libjava/classpath/native/jni/java-net/javanet.c b/libjava/classpath/native/jni/java-net/javanet.c new file mode 100644 index 000000000..1f093f4aa --- /dev/null +++ b/libjava/classpath/native/jni/java-net/javanet.c @@ -0,0 +1,1500 @@ +/* javanet.c - Common internal functions for the java.net package + Copyright (C) 1998, 2002, 2004, 2005, 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +/* do not move; needed here because of some macro definitions */ +#include + +#include +#include +#include + +#include +#include + +#include "cpnative.h" +#include "cpnet.h" + +#include "javanet.h" + +#ifndef WITHOUT_NETWORK +/* Need to have some value for SO_TIMEOUT */ +#ifndef SO_TIMEOUT +#ifndef SO_RCVTIMEO +#warning Neither SO_TIMEOUT or SO_RCVTIMEO are defined! +#warning This will cause all get/setOption calls with that value to throw an exception +#else +#define SO_TIMEOUT SO_RCVTIMEO +#endif /* not SO_RCVTIMEO */ +#endif /* not SO_TIMEOUT */ +#endif /* WITHOUT_NETWORK */ + +/*************************************************************************/ + +/* + * Sets an integer field in the specified object. + */ +static void +_javanet_set_int_field (JNIEnv * env, jobject obj, + const char *class, const char *field, int val) +{ + jclass cls; + jfieldID fid; + + cls = (*env)->FindClass (env, class); + if (cls == NULL) + return; + + fid = (*env)->GetFieldID (env, cls, field, "I"); + if (fid == NULL) + return; + + (*env)->SetIntField (env, obj, fid, val); + + return; +} + +/*************************************************************************/ + +/* + * Returns the value of the specified integer instance variable field or + * -1 if an error occurs. + */ +int +_javanet_get_int_field (JNIEnv * env, jobject obj, const char *field) +{ + jclass cls = 0; + jfieldID fid; + int fd; + + DBG ("_javanet_get_int_field(): Entered _javanet_get_int_field\n"); + + cls = (*env)->GetObjectClass (env, obj); + if (cls == NULL) + return -1; + + fid = (*env)->GetFieldID (env, cls, field, "I"); + if (fid == NULL) + return -1; + DBG ("_javanet_get_int_field(): Found field id\n"); + + fd = (*env)->GetIntField (env, obj, fid); + + return fd; +} + +/*************************************************************************/ + +/* + * Creates a FileDescriptor object in the parent class. It is not used + * by this implementation, but the docs list it as a variable, so we + * need to include it. + */ +static void +_javanet_create_localfd (JNIEnv * env, jobject this, jboolean stream) +{ + jclass this_cls, fd_cls; + jfieldID fid; + jmethodID mid; + jobject fd_obj; + + DBG ("_javanet_create_localfd(): Entered _javanet_create_localfd\n"); + + /* Look up the fd field */ + if (stream) + this_cls = (*env)->FindClass(env, "java/net/SocketImpl"); + else + this_cls = (*env)->FindClass(env, "java/net/DatagramSocketImpl"); + if (this_cls == NULL) + return; + + fid = (*env)->GetFieldID (env, this_cls, "fd", "Ljava/io/FileDescriptor;"); + if (fid == NULL) + return; + + DBG ("_javanet_create_localfd(): Found fd variable\n"); + + /* Create a FileDescriptor */ + fd_cls = (*env)->FindClass (env, "java/io/FileDescriptor"); + if (fd_cls == NULL) + return; + + DBG ("_javanet_create_localfd(): Found FileDescriptor class\n"); + + mid = (*env)->GetMethodID (env, fd_cls, "", "()V"); + if (mid == NULL) + return; + + DBG ("_javanet_create_localfd(): Found FileDescriptor constructor\n"); + + fd_obj = (*env)->NewObject (env, fd_cls, mid); + if (fd_obj == NULL) + return; + + DBG ("_javanet_create_localfd(): Created FileDescriptor\n"); + + /* Now set the pointer to the new FileDescriptor */ + (*env)->SetObjectField (env, this, fid, fd_obj); + DBG ("_javanet_create_localfd(): Set fd field\n"); + + return; +} + +/*************************************************************************/ + +/* + * Returns a Boolean object with the specfied value + */ +static jobject +_javanet_create_boolean (JNIEnv * env, jboolean val) +{ + jclass cls; + jmethodID mid; + jobject obj; + + cls = (*env)->FindClass (env, "java/lang/Boolean"); + if (cls == NULL) + return NULL; + + mid = (*env)->GetMethodID (env, cls, "", "(Z)V"); + if (mid == NULL) + return NULL; + + obj = (*env)->NewObject (env, cls, mid, val); + if (obj == NULL) + return NULL; + + return obj; +} + +/*************************************************************************/ + +/* + * Returns an Integer object with the specfied value + */ +static jobject +_javanet_create_integer (JNIEnv * env, jint val) +{ + jclass cls; + jmethodID mid; + jobject obj; + + cls = (*env)->FindClass (env, "java/lang/Integer"); + if (cls == NULL) + return NULL; + + mid = (*env)->GetMethodID (env, cls, "", "(I)V"); + if (mid == NULL) + return NULL; + + obj = (*env)->NewObject (env, cls, mid, val); + if (obj == NULL) + return NULL; + + return obj; +} + +/*************************************************************************/ + +/* + * Builds an InetAddress object from a 32 bit address in host byte order + */ +jobject +_javanet_create_inetaddress (JNIEnv * env, cpnet_address *netaddr) +{ +#ifndef WITHOUT_NETWORK + jbyte octets[4]; + char buf[64]; + jclass ia_cls; + jmethodID mid; + jstring ip_str; + jobject ia; + + /* Build a string IP address */ + cpnet_IPV4AddressToBytes(netaddr, octets); + sprintf (buf, "%d.%d.%d.%d", (int) (unsigned char)octets[0], (int)(unsigned char)octets[1], (int)(unsigned char)octets[2], (int)(unsigned char)octets[3]); + DBG ("_javanet_create_inetaddress(): Created ip addr string\n"); + + /* Get an InetAddress object for this IP */ + ia_cls = (*env)->FindClass (env, "java/net/InetAddress"); + if (ia_cls == NULL) + { + return NULL; + } + + DBG ("_javanet_create_inetaddress(): Found InetAddress class\n"); + + mid = (*env)->GetStaticMethodID (env, ia_cls, "getByName", + "(Ljava/lang/String;)Ljava/net/InetAddress;"); + if (mid == NULL) + { + return NULL; + } + + DBG ("_javanet_create_inetaddress(): Found getByName method\n"); + + ip_str = (*env)->NewStringUTF (env, buf); + if (ip_str == NULL) + { + return NULL; + } + + ia = (*env)->CallStaticObjectMethod (env, ia_cls, mid, ip_str); + if (ia == NULL) + { + return NULL; + } + + DBG ("_javanet_create_inetaddress(): Called getByName method\n"); + + return ia; +#else /* not WITHOUT_NETWORK */ + return NULL; +#endif /* not WITHOUT_NETWORK */ +} + +/*************************************************************************/ + +static void +_javanet_set_remhost_addr (JNIEnv * env, jobject this, jobject ia) +{ + jclass this_cls; + jfieldID fid; + + /* Set the variable in the object */ + this_cls = (*env)->FindClass (env, "java/net/SocketImpl"); + if (this_cls == NULL) + return; + + fid = + (*env)->GetFieldID (env, this_cls, "address", "Ljava/net/InetAddress;"); + if (fid == NULL) + return; + + DBG ("_javanet_set_remhost_addr(): Found address field\n"); + + (*env)->SetObjectField (env, this, fid, ia); + DBG ("_javanet_set_remhost_addr(): Set field\n"); +} + +/* + * Set's the value of the "addr" field in PlainSocketImpl with a new + * InetAddress for the specified addr + */ +static void +_javanet_set_remhost (JNIEnv * env, jobject this, cpnet_address *netaddr) +{ + jobject ia; + + DBG ("_javanet_set_remhost(): Entered _javanet_set_remhost\n"); + + /* Get an InetAddress object */ + ia = _javanet_create_inetaddress (env, netaddr); + if (ia == NULL) + return; + + _javanet_set_remhost_addr (env, this, ia); +} + + +/*************************************************************************/ + +/* + * Returns an Internet address for the passed in InetAddress object + */ +cpnet_address * +_javanet_get_ip_netaddr (JNIEnv * env, jobject addr) +{ +#ifndef WITHOUT_NETWORK + jclass cls = 0; + jmethodID mid; + jarray arr = 0; + jbyte *octets; + cpnet_address *netaddr; + jint len; + + DBG ("_javanet_get_ip_netaddr(): Entered _javanet_get_ip_netaddr\n"); + + if (addr == NULL) + { + JCL_ThrowException (env, "java/lang/NullPointerException", + "Null address"); + return 0; + } + + /* Call the getAddress method on the object to retrieve the IP address */ + cls = (*env)->GetObjectClass (env, addr); + if (cls == NULL) + return 0; + + mid = (*env)->GetMethodID (env, cls, "getAddress", "()[B"); + if (mid == NULL) + return 0; + + DBG ("_javanet_get_ip_netaddr(): Got getAddress method\n"); + + arr = (*env)->CallObjectMethod (env, addr, mid); + if (arr == NULL) + return 0; + + DBG ("_javanet_get_ip_netaddr(): Got the address\n"); + + /* Turn the IP address into a system cpnet address. + * If the length is 4 then it is an IPV4 address, if it + * is 16 then it is an IPV6 address else it is an InternError. */ + len = (*env)->GetArrayLength (env, arr); + if (len != 4 && len != 16) + { + JCL_ThrowException (env, IO_EXCEPTION, "Internal Error"); + return 0; + } + DBG ("_javanet_get_ip_netaddr(): Length ok\n"); + + octets = (*env)->GetByteArrayElements (env, arr, 0); + if (octets == NULL) + return 0; + + DBG ("_javanet_get_ip_netaddr(): Grabbed bytes\n"); + + switch (len) + { + case 4: + netaddr = cpnet_newIPV4Address(env); + cpnet_bytesToIPV4Address(netaddr, octets); + break; +#ifdef HAVE_INET6 + case 16: + netaddr = cpnet_newIPV6Address(env); + cpnet_bytesToIPV6Address(netaddr, octets); + break; +#endif + default: + /* This should not happen as we have checked before. + * But that way we shut the compiler warnings */ + JCL_ThrowException (env, IO_EXCEPTION, "Internal Error"); + return 0; + + } + + (*env)->ReleaseByteArrayElements (env, arr, octets, 0); + DBG ("_javanet_get_ip_netaddr(): Done getting addr\n"); + + return netaddr; +#else /* not WITHOUT_NETWORK */ +#endif /* not WITHOUT_NETWORK */ +} + +/*************************************************************************/ + +/* + * Creates a new stream or datagram socket + */ +void +_javanet_create (JNIEnv * env, jobject this, jboolean stream) +{ +#ifndef WITHOUT_NETWORK + int fd; + int result; + + if (stream) + { + /* create a stream socket */ + result = cpnet_openSocketStream(env, &fd, AF_INET); + if (result != CPNATIVE_OK) + { + JCL_ThrowException (env, IO_EXCEPTION, + cpnative_getErrorString (result)); + return; + } + } + else + { + /* create a datagram socket, set broadcast option */ + result = cpnet_openSocketDatagram (env, &fd, AF_INET); + if (result != CPNATIVE_OK) + { + JCL_ThrowException (env, IO_EXCEPTION, + cpnative_getErrorString (result)); + return; + } + result = cpnet_setBroadcast(env, fd, 1); + if (result != CPNATIVE_OK) + { + JCL_ThrowException (env, IO_EXCEPTION, + cpnative_getErrorString (result)); + return; + } + } + + if (stream) + _javanet_set_int_field (env, this, "gnu/java/net/PlainSocketImpl", + "native_fd", fd); + else + _javanet_set_int_field (env, this, "gnu/java/net/PlainDatagramSocketImpl", + "native_fd", fd); + + if ((*env)->ExceptionOccurred (env)) + { + /* Try to make sure we close the socket since close() won't work. */ + do + { + result = cpnet_close(env, fd); + if (result != CPNATIVE_OK && result != CPNATIVE_EINTR) + return; + } + while (result != CPNATIVE_OK); + return; + } + +#else /* not WITHOUT_NETWORK */ +#endif /* not WITHOUT_NETWORK */ +} + +/*************************************************************************/ + +/* + * Close the socket. Any underlying streams will be closed by this + * action as well. + */ +void +_javanet_close (JNIEnv * env, jobject this, int stream) +{ +#ifndef WITHOUT_NETWORK + int fd; + int result; + int error = 0; + + fd = _javanet_get_int_field (env, this, "native_fd"); + if (fd == -1) + return; + + if (stream) + _javanet_set_int_field (env, this, "gnu/java/net/PlainSocketImpl", + "native_fd", -1); + else + _javanet_set_int_field (env, this, "gnu/java/net/PlainDatagramSocketImpl", + "native_fd", -1); + do + { + result = cpnet_close (env, fd); + if (result != CPNATIVE_OK) + { + /* Only throw an error when a "real" error occurs. */ + if (result != CPNATIVE_EINTR && result != ENOTCONN && result != ECONNRESET && result != EBADF) + JCL_ThrowException (env, IO_EXCEPTION, + cpnative_getErrorString (result)); + } + } + while (error == CPNATIVE_EINTR); + +#else /* not WITHOUT_NETWORK */ +#endif /* not WITHOUT_NETWORK */ +} + +/*************************************************************************/ + +/* + * Connects to the specified destination. + */ +void +_javanet_connect (JNIEnv * env, jobject this, jobject addr, jint port, + jboolean stream) +{ +#ifndef WITHOUT_NETWORK + cpnet_address *netaddr; + int fd; + int result; + cpnet_address *local_addr; + cpnet_address *remote_addr; + + DBG ("_javanet_connect(): Entered _javanet_connect\n"); + + /* Pre-process input variables */ + netaddr = _javanet_get_ip_netaddr (env, addr); + if ((*env)->ExceptionOccurred (env)) + return; + + if (port == -1) + port = 0; + + cpnet_addressSetPort(netaddr, port); + + DBG ("_javanet_connect(): Got network address\n"); + + /* Grab the real socket file descriptor */ + fd = _javanet_get_int_field (env, this, "native_fd"); + if (fd == -1) + { + JCL_ThrowException (env, IO_EXCEPTION, + "Internal error: _javanet_connect(): no native file descriptor"); + return; + } + DBG ("_javanet_connect(): Got native fd\n"); + + /* Connect up */ + do + { + result = cpnet_connect (env, fd, netaddr); + if (result != CPNATIVE_OK && result != CPNATIVE_EINTR) + { + JCL_ThrowException (env, CONNECT_EXCEPTION, + cpnative_getErrorString (result)); + return; + } + } + while (result != CPNATIVE_OK); + + DBG ("_javanet_connect(): Connected successfully\n"); + + /* Populate instance variables */ + result = cpnet_getLocalAddr (env, fd, &local_addr); + if (result != CPNATIVE_OK) + { + cpnet_freeAddress(env, netaddr); + JCL_ThrowException (env, IO_EXCEPTION, + cpnative_getErrorString (result)); + /* We don't care whether this succeeds. close() will cleanup later. */ + cpnet_close (env, fd); + return; + } + + _javanet_create_localfd (env, this, stream); + if ((*env)->ExceptionOccurred (env)) + { + /* We don't care whether this succeeds. close() will cleanup later. */ + cpnet_freeAddress(env, netaddr); + cpnet_freeAddress(env, local_addr); + cpnet_close (env, fd); + return; + } + DBG ("_javanet_connect(): Created fd\n"); + + if (stream) + _javanet_set_int_field (env, this, "java/net/SocketImpl", "localport", + cpnet_addressGetPort(local_addr)); + else + _javanet_set_int_field (env, this, "java/net/DatagramSocketImpl", + "localPort", cpnet_addressGetPort(local_addr)); + + cpnet_freeAddress (env, local_addr); + if ((*env)->ExceptionOccurred (env)) + { + /* We don't care whether this succeeds. close() will cleanup later. */ + cpnet_freeAddress(env, netaddr); + cpnet_close (env, fd); + return; + } + DBG ("_javanet_connect(): Set the local port\n"); + + result = cpnet_getRemoteAddr (env, fd, &remote_addr); + if (result != CPNATIVE_OK) + { + cpnet_freeAddress(env, netaddr); + JCL_ThrowException (env, IO_EXCEPTION, + cpnative_getErrorString (result)); + /* We don't care whether this succeeds. close() will cleanup later. */ + cpnet_close (env, fd); + return; + } + + if (stream) + { + if (cpnet_isAddressEqual(remote_addr, netaddr)) + { + _javanet_set_remhost_addr (env, this, addr); + } + else + { + _javanet_set_remhost (env, this, remote_addr); + } + cpnet_freeAddress(env, netaddr); + + if ((*env)->ExceptionOccurred (env)) + { + /* We don't care whether this succeeds. close() will cleanup later. + */ + cpnet_freeAddress (env, remote_addr); + cpnet_close (env, fd); + return; + } + DBG ("_javanet_connect(): Set the remote host\n"); + + _javanet_set_int_field (env, this, "java/net/SocketImpl", "port", + cpnet_addressGetPort(remote_addr)); + cpnet_freeAddress (env, remote_addr); + + if ((*env)->ExceptionOccurred (env)) + { + /* We don't care whether this succeeds. close() will cleanup later. + */ + cpnet_close (env, fd); + return; + } + DBG ("_javanet_connect(): Set the remote port\n"); + } +#else /* not WITHOUT_NETWORK */ +#endif /* not WITHOUT_NETWORK */ +} + +/*************************************************************************/ + +/* + * This method binds the specified address to the specified local port. + * Note that we have to set the local address and local + * port public instance variables. + */ +void +_javanet_bind (JNIEnv * env, jobject this, jobject addr, jint port, + int stream) +{ +#ifndef WITHOUT_NETWORK + jint fd; + cpnet_address *tmpaddr; + cpnet_address *local_addr; + int result; + + DBG ("_javanet_bind(): Entering native bind()\n"); + + /* Grab the real socket file descriptor */ + fd = _javanet_get_int_field (env, this, "native_fd"); + if (fd == -1) + { + JCL_ThrowException (env, IO_EXCEPTION, + "Internal error: _javanet_connect(): no native file descriptor"); + return; + } + + cpnet_setReuseAddress (env, fd, 1); + + /* Get the address to connect to */ + tmpaddr = _javanet_get_ip_netaddr (env, addr); + if ((*env)->ExceptionOccurred (env)) + return; + + cpnet_addressSetPort (tmpaddr, port); + result = cpnet_bind(env, fd, tmpaddr); + cpnet_freeAddress (env, tmpaddr); + if (result != CPNATIVE_OK) + { + JCL_ThrowException (env, BIND_EXCEPTION, + cpnative_getErrorString (result)); + return; + } + DBG ("_javanet_bind(): Past bind\n"); + + /* Update instance variables, specifically the local port number */ + result = cpnet_getLocalAddr (env, fd, &local_addr); + if (result != CPNATIVE_OK) + { + JCL_ThrowException (env, IO_EXCEPTION, + cpnative_getErrorString (result)); + return; + } + + if (stream) + _javanet_set_int_field (env, this, "java/net/SocketImpl", + "localport", cpnet_addressGetPort (local_addr)); + else + _javanet_set_int_field (env, this, "java/net/DatagramSocketImpl", + "localPort", cpnet_addressGetPort (local_addr)); + DBG ("_javanet_bind(): Past update port number\n"); + + cpnet_freeAddress (env, local_addr); + + return; +#else /* not WITHOUT_NETWORK */ +#endif /* not WITHOUT_NETWORK */ +} + +/*************************************************************************/ + +/* + * Starts listening on a socket with the specified number of pending + * connections allowed. + */ +void +_javanet_listen (JNIEnv * env, jobject this, jint queuelen) +{ +#ifndef WITHOUT_NETWORK + int fd; + int result; + + /* Get the real file descriptor */ + fd = _javanet_get_int_field (env, this, "native_fd"); + if (fd == -1) + { + JCL_ThrowException (env, IO_EXCEPTION, + "Internal error: _javanet_listen(): no native file descriptor"); + return; + } + + /* Start listening */ + result = cpnet_listen (env, fd, queuelen); + if (result != CPNATIVE_OK) + { + JCL_ThrowException (env, IO_EXCEPTION, + cpnative_getErrorString (result)); + return; + } +#else /* not WITHOUT_NETWORK */ +#endif /* not WITHOUT_NETWORK */ +} + +/*************************************************************************/ + +/* + * Accepts a new connection and assigns it to the passed in SocketImpl + * object. Note that we assume this is a PlainSocketImpl just like us + */ +void +_javanet_accept (JNIEnv * env, jobject this, jobject impl) +{ +#ifndef WITHOUT_NETWORK + int fd, newfd; + int result; + cpnet_address *remote_addr, *local_addr; + + /* Get the real file descriptor */ + fd = _javanet_get_int_field (env, this, "native_fd"); + if (fd == -1) + { + JCL_ThrowException (env, IO_EXCEPTION, + "Internal error: _javanet_accept(): no native file descriptor"); + return; + } + + /* Accept the connection */ + do + { + result = cpnet_accept (env, fd, &newfd); + if (result != CPNATIVE_OK && result != CPNATIVE_EINTR) + { + if (result == ETIMEDOUT || result == EAGAIN) + JCL_ThrowException (env, "java/net/SocketTimeoutException", + "Accept operation timed out"); + else + JCL_ThrowException (env, IO_EXCEPTION, + cpnative_getErrorString (result)); + return; + } + } + while (result != CPNATIVE_OK); + + /* Reset the inherited timeout. */ + cpnet_setSocketTimeout (env, newfd, 0); + + /* Populate instance variables */ + _javanet_set_int_field (env, impl, "gnu/java/net/PlainSocketImpl", + "native_fd", newfd); + + if ((*env)->ExceptionOccurred (env)) + { + /* Try to make sure we close the socket since close() won't work. */ + do + { + result = cpnet_close (env, newfd); + if (result != CPNATIVE_OK && result != CPNATIVE_EINTR) + return; + } + while (result != CPNATIVE_OK); + return; + } + + result = cpnet_getLocalAddr (env, newfd, &local_addr); + if (result != CPNATIVE_OK) + { + /* We don't care whether this succeeds. close() will cleanup later. */ + cpnet_close (env, newfd); + JCL_ThrowException (env, IO_EXCEPTION, + cpnative_getErrorString (result)); + return; + } + + _javanet_create_localfd (env, impl, 1); + if ((*env)->ExceptionOccurred (env)) + { + /* We don't care whether this succeeds. close() will cleanup later. */ + cpnet_freeAddress (env, local_addr); + cpnet_close (env, newfd); + return; + } + + _javanet_set_int_field (env, impl, "java/net/SocketImpl", "localport", + cpnet_addressGetPort (local_addr)); + cpnet_freeAddress (env, local_addr); + if ((*env)->ExceptionOccurred (env)) + { + /* We don't care whether this succeeds. close() will cleanup later. */ + cpnet_close (env, newfd); + return; + } + + result = cpnet_getRemoteAddr (env, newfd, &remote_addr); + if (result != CPNATIVE_OK) + { + JCL_ThrowException (env, IO_EXCEPTION, + cpnative_getErrorString (result)); + /* We don't care whether this succeeds. close() will cleanup later. */ + cpnet_close (env, newfd); + return; + } + + _javanet_set_remhost (env, impl, remote_addr); + if ((*env)->ExceptionOccurred (env)) + { + /* We don't care whether this succeeds. close() will cleanup later. */ + cpnet_close (env, newfd); + cpnet_freeAddress (env, remote_addr); + return; + } + + _javanet_set_int_field (env, impl, "java/net/SocketImpl", "port", + cpnet_addressGetPort (remote_addr)); + cpnet_freeAddress (env, remote_addr); + if ((*env)->ExceptionOccurred (env)) + { + /* We don't care whether this succeeds. close() will cleanup later. */ + cpnet_close (env, newfd); + return; + } +#else /* not WITHOUT_NETWORK */ +#endif /* not WITHOUT_NETWORK */ +} + +/*************************************************************************/ + +/* + * Receives a buffer from a remote host. The args are: + * + * buf - The byte array into which the data received will be written + * offset - Offset into the byte array to start writing + * len - The number of bytes to read. + * addr - Pointer to 32 bit net address of host to receive from. If null, + * this parm is ignored. If pointing to an address of 0, the + * actual address read is stored here + * port - Pointer to the port to receive from. If null, this parm is ignored. + * If it is 0, the actual remote port received from is stored here + * + * The actual number of bytes read is returned. + */ +int +_javanet_recvfrom (JNIEnv * env, jobject this, jarray buf, int offset, + int len, cpnet_address **addr) +{ +#ifndef WITHOUT_NETWORK + int fd; + jbyte *p; + cpnet_address *from_addr; + jint received_bytes; + int result; + + DBG ("_javanet_recvfrom(): Entered _javanet_recvfrom\n"); + + /* Get the real file descriptor */ + fd = _javanet_get_int_field (env, this, "native_fd"); + if (fd == -1) + { + JCL_ThrowException (env, IO_EXCEPTION, + "Internal error: _javanet_recvfrom(): no native file descriptor"); + return 0; + } + DBG ("_javanet_recvfrom(): Got native_fd\n"); + + /* Get a pointer to the buffer */ + p = (*env)->GetByteArrayElements (env, buf, 0); + if (p == NULL) + return 0; + + DBG ("_javanet_recvfrom(): Got buffer\n"); + + /* Read the data */ + from_addr = NULL; + do + { + if (addr != NULL) + { + result = cpnet_recvFrom (env, fd, p + offset, len, &from_addr, &received_bytes); + } + else + { + result = cpnet_recv (env, fd, p + offset, len, &received_bytes); + } + } + while (result == CPNATIVE_EINTR); + if (result != 0) + { + if (result == EAGAIN || result == ETIMEDOUT) + JCL_ThrowException (env, "java/net/SocketTimeoutException", "Receive operation timed out"); + else + JCL_ThrowException (env, IO_EXCEPTION, + cpnative_getErrorString (result)); + + /* Cleanup and return. */ + (*env)->ReleaseByteArrayElements (env, buf, p, 0); + return 0; + } + + (*env)->ReleaseByteArrayElements (env, buf, p, 0); + + /* Handle return addr case */ + if (addr != NULL) + { + (*addr) = from_addr; + } + + /* zero bytes received means recv() noticed the other side orderly + closing the connection. */ + if (received_bytes == 0) + received_bytes = -1; + + return received_bytes; +#else /* not WITHOUT_NETWORK */ +#endif /* not WITHOUT_NETWORK */ +} + +/*************************************************************************/ + +/* + * Sends a buffer to a remote host. The args are: + * + * buf - A byte array + * offset - Index into the byte array to start sendign + * len - The number of bytes to write + * addr - The 32bit address to send to (may be 0) + * port - The port number to send to (may be 0) + */ +void +_javanet_sendto (JNIEnv * env, jobject this, jarray buf, int offset, int len, + cpnet_address *addr) +{ +#ifndef WITHOUT_NETWORK + int fd; + jbyte *p; + jint bytes_sent; + int result; + + /* Get the real file descriptor */ + fd = _javanet_get_int_field (env, this, "native_fd"); + if (fd == -1) + { + JCL_ThrowException (env, IO_EXCEPTION, + "Internal error: _javanet_sendto(): no native file descriptor"); + return; + } + + /* Get a pointer to the buffer */ + p = (*env)->GetByteArrayElements (env, buf, 0); + if (p == NULL) + return; + + /* We must send all the data, so repeat till done. */ + while (len > 0) + { + /* Send the data */ + if (addr == NULL) + { + DBG ("_javanet_sendto(): Sending....\n"); + result = cpnet_send (env, fd, p + offset, len, &bytes_sent); + } + else + { + DBG ("_javanet_sendto(): Sending....\n"); + result = cpnet_sendTo (env, fd, p + offset, len, addr, &bytes_sent); + } + + if (result == EDESTADDRREQ) + { + JCL_ThrowException (env, NULL_EXCEPTION, + "Socket is not connected and no address is given"); + break; + } + + if (bytes_sent < 0) + { + if (result != CPNATIVE_EINTR) + { + JCL_ThrowException (env, IO_EXCEPTION, + cpnative_getErrorString (result)); + break; + } + } + else + { + len -= bytes_sent; + addr += bytes_sent; + } + } + + (*env)->ReleaseByteArrayElements (env, buf, p, 0); + +#else /* not WITHOUT_NETWORK */ +#endif /* not WITHOUT_NETWORK */ +} + +/*************************************************************************/ + +/* + * Sets the specified option for a socket + */ +void +_javanet_set_option (JNIEnv * env, jobject this, jint option_id, jobject val) +{ +#ifndef WITHOUT_NETWORK + int fd; + int optval; + jclass cls; + jmethodID mid; + cpnet_address * address; + int result = CPNATIVE_OK; + + /* Get the real file descriptor */ + fd = _javanet_get_int_field (env, this, "native_fd"); + if (fd == -1) + { + JCL_ThrowException (env, IO_EXCEPTION, + "Internal error: _javanet_set_option(): no native file descriptor"); + return; + } + + /* We need a class object for all cases below */ + cls = (*env)->GetObjectClass (env, val); + if (cls == NULL) + return; + + /* Process the option request */ + switch (option_id) + { + /* TCP_NODELAY case. val is a Boolean that tells us what to do */ + case SOCKOPT_TCP_NODELAY: + mid = (*env)->GetMethodID (env, cls, "booleanValue", "()Z"); + if (mid == NULL) + { + JCL_ThrowException (env, IO_EXCEPTION, + "Internal error: _javanet_set_option()"); + return; + } + + /* Should be a 0 or a 1 */ + optval = (*env)->CallBooleanMethod (env, val, mid); + if ((*env)->ExceptionOccurred (env)) + return; + + result = cpnet_setSocketTCPNoDelay (env, fd, optval); + break; + + /* SO_LINGER case. If val is a boolean, then it will always be set + to false indicating disable linger, otherwise it will be an + integer that contains the linger value */ + case SOCKOPT_SO_LINGER: + mid = (*env)->GetMethodID (env, cls, "booleanValue", "()Z"); + if (mid) + { + /* We are disabling linger */ + result = cpnet_setLinger (env, fd, JNI_FALSE, 0); + } + else + { + /* Clear exception if thrown for failure to do method lookup + above */ + if ((*env)->ExceptionOccurred (env)) + (*env)->ExceptionClear (env); + + mid = (*env)->GetMethodID (env, cls, "intValue", "()I"); + if (mid == NULL) + { + JCL_ThrowException (env, IO_EXCEPTION, + "Internal error: _javanet_set_option()"); + return; + } + + optval = (*env)->CallIntMethod (env, val, mid); + if ((*env)->ExceptionOccurred (env)) + return; + + result = cpnet_setLinger(env, fd, JNI_TRUE, optval); + } + break; + + /* SO_TIMEOUT case. Val will be an integer with the new value */ + /* Not writable on Linux */ + case SOCKOPT_SO_TIMEOUT: + mid = (*env)->GetMethodID (env, cls, "intValue", "()I"); + if (mid == NULL) + { + JCL_ThrowException (env, IO_EXCEPTION, + "Internal error: _javanet_set_option()"); + return; + } + + optval = (*env)->CallIntMethod (env, val, mid); + if ((*env)->ExceptionOccurred (env)) + return; + + result = cpnet_setSocketTimeout (env, fd, optval); + break; + + case SOCKOPT_SO_SNDBUF: + case SOCKOPT_SO_RCVBUF: + mid = (*env)->GetMethodID (env, cls, "intValue", "()I"); + if (mid == NULL) + { + JCL_ThrowException (env, IO_EXCEPTION, + "Internal error: _javanet_set_option()"); + return; + } + + + optval = (*env)->CallIntMethod (env, val, mid); + if ((*env)->ExceptionOccurred (env)) + return; + + if (option_id == SOCKOPT_SO_SNDBUF) + result = cpnet_setSendBuf (env, fd, optval); + else + result = cpnet_setRecvBuf (env, fd, optval); + break; + + /* TTL case. Val with be an Integer with the new time to live value */ + case SOCKOPT_IP_TTL: + mid = (*env)->GetMethodID (env, cls, "intValue", "()I"); + if (!mid) + { + JCL_ThrowException (env, IO_EXCEPTION, + "Internal error: _javanet_set_option()"); + return; + } + + optval = (*env)->CallIntMethod (env, val, mid); + if ((*env)->ExceptionOccurred (env)) + return; + + result = cpnet_setTTL (env, fd, optval); + break; + + /* Multicast Interface case - val is InetAddress object */ + case SOCKOPT_IP_MULTICAST_IF: + address = _javanet_get_ip_netaddr (env, val); + + if ((*env)->ExceptionOccurred (env)) + return; + + result = cpnet_setMulticastIF (env, fd, address); + cpnet_freeAddress (env, address); + break; + + case SOCKOPT_SO_REUSEADDR: + mid = (*env)->GetMethodID (env, cls, "booleanValue", "()Z"); + if (mid == NULL) + { + JCL_ThrowException (env, IO_EXCEPTION, + "Internal error: _javanet_set_option()"); + return; + } + + /* Should be a 0 or a 1 */ + optval = (*env)->CallBooleanMethod (env, val, mid); + if ((*env)->ExceptionOccurred (env)) + return; + + result = cpnet_setReuseAddress (env, fd, optval); + break; + + case SOCKOPT_SO_KEEPALIVE: + mid = (*env)->GetMethodID (env, cls, "booleanValue", "()Z"); + if (mid == NULL) + { + JCL_ThrowException (env, IO_EXCEPTION, + "Internal error: _javanet_set_option()"); + return; + } + + /* Should be a 0 or a 1 */ + optval = (*env)->CallBooleanMethod (env, val, mid); + if ((*env)->ExceptionOccurred (env)) + return; + + result = cpnet_setKeepAlive (env, fd, optval); + break; + + case SOCKOPT_SO_BINDADDR: + JCL_ThrowException (env, SOCKET_EXCEPTION, "This option cannot be set"); + break; + + default: + JCL_ThrowException (env, SOCKET_EXCEPTION, "Unrecognized option"); + return; + } + + /* Check to see if above operations succeeded */ + if (result != CPNATIVE_OK) + { + JCL_ThrowException (env, SOCKET_EXCEPTION, + cpnative_getErrorString (result)); + return; + } +#else /* not WITHOUT_NETWORK */ +#endif /* not WITHOUT_NETWORK */ +} + +/*************************************************************************/ + +/* + * Retrieves the specified option values for a socket + */ +jobject +_javanet_get_option (JNIEnv * env, jobject this, jint option_id) +{ +#ifndef WITHOUT_NETWORK + int fd; + int flag, optval; + cpnet_address *address; + int result; + jobject obj; + + /* Get the real file descriptor */ + fd = _javanet_get_int_field (env, this, "native_fd"); + if (fd == -1) + { + JCL_ThrowException (env, SOCKET_EXCEPTION, + "Internal error: _javanet_get_option(): no native file descriptor"); + return (0); + } + + /* Process the option requested */ + switch (option_id) + { + /* TCP_NODELAY case. Return a Boolean indicating on or off */ + case SOCKOPT_TCP_NODELAY: + result = cpnet_getSocketTCPNoDelay (env, fd, &optval); + if (result != CPNATIVE_OK) + { + JCL_ThrowException (env, SOCKET_EXCEPTION, + cpnative_getErrorString (result)); + return (0); + } + + if (optval) + return (_javanet_create_boolean (env, JNI_TRUE)); + else + return (_javanet_create_boolean (env, JNI_FALSE)); + + break; + + /* SO_LINGER case. If disabled, return a Boolean object that represents + false, else return an Integer that is the value of SO_LINGER */ + case SOCKOPT_SO_LINGER: + result = cpnet_getLinger (env, fd, &flag, &optval); + + if (result != CPNATIVE_OK) + { + JCL_ThrowException (env, SOCKET_EXCEPTION, + cpnative_getErrorString (result)); + return (0); + } + + if (flag) + return (_javanet_create_integer (env, optval)); + else + return (_javanet_create_boolean (env, JNI_FALSE)); + + break; + + /* SO_TIMEOUT case. Return an Integer object with the timeout value */ + case SOCKOPT_SO_TIMEOUT: + result = cpnet_getSocketTimeout (env, fd, &optval); + if (result != CPNATIVE_OK) + { + JCL_ThrowException (env, SOCKET_EXCEPTION, + cpnative_getErrorString (result)); + return (0); + } + return (_javanet_create_integer (env, optval)); + break; + + case SOCKOPT_SO_SNDBUF: + case SOCKOPT_SO_RCVBUF: + if (option_id == SOCKOPT_SO_SNDBUF) + result = cpnet_getSendBuf (env, fd, &optval); + else + result = cpnet_getRecvBuf (env, fd, &optval); + + if (result != CPNATIVE_OK) + { + JCL_ThrowException (env, SOCKET_EXCEPTION, + cpnative_getErrorString (result)); + return (0); + } + + return (_javanet_create_integer (env, optval)); + break; + + /* The TTL case. Return an Integer with the Time to Live value */ + case SOCKOPT_IP_TTL: + result = cpnet_getTTL (env, fd, &optval); + if (result != CPNATIVE_OK) + { + JCL_ThrowException (env, SOCKET_EXCEPTION, + cpnative_getErrorString (result)); + return (0); + } + + return (_javanet_create_integer (env, optval)); + break; + + /* Multicast interface case */ + case SOCKOPT_IP_MULTICAST_IF: + result = cpnet_getMulticastIF (env, fd, &address); + if (result != CPNATIVE_OK) + { + JCL_ThrowException (env, SOCKET_EXCEPTION, + cpnative_getErrorString (result)); + return (0); + } + + obj = _javanet_create_inetaddress (env, address); + cpnet_freeAddress (env, address); + + return obj; + break; + + case SOCKOPT_SO_BINDADDR: + result = cpnet_getLocalAddr (env, fd, &address); + if (result != CPNATIVE_OK) + { + JCL_ThrowException (env, SOCKET_EXCEPTION, + cpnative_getErrorString (result)); + return (0); + } + + obj = _javanet_create_inetaddress (env, address); + cpnet_freeAddress (env, address); + + return obj; + break; + + case SOCKOPT_SO_REUSEADDR: + result = cpnet_getReuseAddress (env, fd, &optval); + if (result != CPNATIVE_OK) + { + JCL_ThrowException (env, SOCKET_EXCEPTION, + cpnative_getErrorString (result)); + return (0); + } + + if (optval) + return _javanet_create_boolean (env, JNI_TRUE); + else + return _javanet_create_boolean (env, JNI_FALSE); + + break; + + case SOCKOPT_SO_KEEPALIVE: + result = cpnet_getKeepAlive (env, fd, &optval); + if (result != CPNATIVE_OK) + { + JCL_ThrowException (env, SOCKET_EXCEPTION, + cpnative_getErrorString (result)); + return (0); + } + + if (optval) + return _javanet_create_boolean (env, JNI_TRUE); + else + return _javanet_create_boolean (env, JNI_FALSE); + + break; + + default: + JCL_ThrowException (env, SOCKET_EXCEPTION, "No such option"); + return (0); + } + + return (0); +#else /* not WITHOUT_NETWORK */ +#endif /* not WITHOUT_NETWORK */ +} + +void +_javanet_shutdownInput (JNIEnv * env, jobject this) +{ + int result; + int fd; + + /* Get the real file descriptor. */ + fd = _javanet_get_int_field (env, this, "native_fd"); + if (fd == -1) + { + JCL_ThrowException (env, SOCKET_EXCEPTION, + "Internal error: _javanet_get_option(): no native file descriptor"); + return; + } + + /* Shutdown input stream of socket. */ + result = cpnet_shutdown (env, fd, CPNET_SHUTDOWN_READ); + if (result != CPNATIVE_OK) + { + JCL_ThrowException (env, SOCKET_EXCEPTION, + cpnative_getErrorString (result)); + return; + } +} + +void +_javanet_shutdownOutput (JNIEnv * env, jobject this) +{ + int fd; + int result; + + /* Get the real file descriptor. */ + fd = _javanet_get_int_field (env, this, "native_fd"); + if (fd == -1) + { + JCL_ThrowException (env, SOCKET_EXCEPTION, + "Internal error: _javanet_get_option(): no native file descriptor"); + return; + } + + /* Shutdown output stream of socket. */ + result = cpnet_shutdown (env, fd, CPNET_SHUTDOWN_WRITE); + if (result != CPNATIVE_OK) + { + JCL_ThrowException (env, SOCKET_EXCEPTION, + cpnative_getErrorString (result)); + return; + } +} + +/* end of file */ diff --git a/libjava/classpath/native/jni/java-net/javanet.h b/libjava/classpath/native/jni/java-net/javanet.h new file mode 100644 index 000000000..96dba881b --- /dev/null +++ b/libjava/classpath/native/jni/java-net/javanet.h @@ -0,0 +1,101 @@ +/* javanet.h - Declarations for common functions for the java.net package + Copyright (C) 1998, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#ifndef _JAVANET_LOADED +#define _JAVANET_LOADED + +#include +#include "jcl.h" +#include "cpnet.h" + +/*************************************************************************/ + +/* + * Defined constants + */ + +/* Exception Classes */ +#define BIND_EXCEPTION "java/net/BindException" +#define IO_EXCEPTION "java/io/IOException" +#define CONNECT_EXCEPTION "java/net/ConnectException" +#define SOCKET_EXCEPTION "java/net/SocketException" +#define UNKNOWN_HOST_EXCEPTION "java/net/UnknownHostException" +#define NULL_EXCEPTION "java/lang/NullPointerException" + +/* Socket Option Identifiers - Don't change or binary compatibility with + the JDK will be broken! These also need to + be kept compatible with java.net.SocketOptions */ +#define SOCKOPT_TCP_NODELAY 1 +#define SOCKOPT_SO_BINDADDR 15 +#define SOCKOPT_SO_LINGER 128 +#define SOCKOPT_SO_TIMEOUT 4102 +#define SOCKOPT_SO_SNDBUF 4097 +#define SOCKOPT_SO_RCVBUF 4098 +#define SOCKOPT_SO_REUSEADDR 4 +#define SOCKOPT_IP_MULTICAST_IF 16 +#define SOCKOPT_SO_KEEPALIVE 8 + +/* Internal option identifiers. Not needed for JDK compatibility */ +#define SOCKOPT_IP_TTL 7777 + +/*************************************************************************/ + +/* + * Function Prototypes + */ + +extern int _javanet_get_int_field(JNIEnv *, jobject, const char *); +extern cpnet_address *_javanet_get_ip_netaddr(JNIEnv *, jobject); +extern jobject _javanet_create_inetaddress (JNIEnv *, cpnet_address *); +extern void _javanet_create(JNIEnv *, jobject, jboolean); +extern void _javanet_close(JNIEnv *, jobject, int); +extern void _javanet_connect(JNIEnv *, jobject, jobject, jint, jboolean); +extern void _javanet_bind(JNIEnv *, jobject, jobject, jint, int); +extern void _javanet_listen(JNIEnv *, jobject, jint); +extern void _javanet_accept(JNIEnv *, jobject, jobject); +extern int _javanet_recvfrom(JNIEnv *, jobject, jarray, int, int, cpnet_address **); +extern void _javanet_sendto(JNIEnv *, jobject, jarray, int, int, cpnet_address *); +extern jobject _javanet_get_option(JNIEnv *, jobject, jint); +extern void _javanet_set_option(JNIEnv *, jobject, jint, jobject); +extern void _javanet_shutdownInput (JNIEnv *, jobject); +extern void _javanet_shutdownOutput (JNIEnv *, jobject); + +/*************************************************************************/ + +#endif /* not _JAVANET_H_LOADED */ + diff --git a/libjava/classpath/native/jni/java-net/local.c b/libjava/classpath/native/jni/java-net/local.c new file mode 100644 index 000000000..53830f371 --- /dev/null +++ b/libjava/classpath/native/jni/java-net/local.c @@ -0,0 +1,189 @@ +/* local.c -- implementation of unix-domain sockets. + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#include "config.h" + +#ifdef ENABLE_LOCAL_SOCKETS + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#if defined(HAVE_SYS_IOCTL_H) +#define BSD_COMP /* Get FIONREAD on Solaris2 */ +#include +#endif +#if defined(HAVE_SYS_FILIO_H) /* Get FIONREAD on Solaris 2.5 */ +#include +#endif + +#include "local.h" + +const char * +local_error (void) +{ + return strerror (errno); +} + +int +local_create (int stream) +{ + return socket (PF_UNIX, stream ? SOCK_STREAM : SOCK_DGRAM, 0); +} + +int +local_bind (int fd, const char *addr) +{ + struct sockaddr_un saddr; + + if (strlen (addr) >= sizeof (saddr.sun_path)) + { + errno = ENAMETOOLONG; + return -1; + } + + strcpy (saddr.sun_path, addr); + saddr.sun_family = AF_LOCAL; + + return bind (fd, (struct sockaddr *) &saddr, SUN_LEN (&saddr)); +} + +int +local_listen (int fd, int backlog) +{ + return listen (fd, backlog); +} + +int +local_accept (int fd, char *path) +{ + int newfd; + struct sockaddr_un addr; + socklen_t sz = SUN_LEN(&addr); + + newfd = accept (fd, (struct sockaddr *) &addr, &sz); + if (newfd >= 0) + { + /** sun_path is some crazy statically-sized buffer, and it's + size is different on different OSes. */ + int n = sizeof (addr.sun_path); + strncpy (path, addr.sun_path, n); + path[n] = '\0'; + } + return newfd; +} + +int +local_available (int fd) +{ + int val; + if (ioctl (fd, FIONREAD, &val)) + { + return -1; + } + return val; +} + +int +local_close (int fd) +{ + return close (fd); +} + +int +local_unlink (char *path) +{ + return unlink (path); +} + +int +local_shutdown_input (int fd) +{ + return shutdown (fd, 0); +} + +int +local_shutdown_output (int fd) +{ + return shutdown (fd, 1); +} + +int +local_connect (int fd, char *path) +{ + struct sockaddr_un saddr; + + strncpy (saddr.sun_path, path, sizeof (saddr.sun_path)); + saddr.sun_path[sizeof (saddr.sun_path) - 1] = '\0'; + saddr.sun_family = AF_UNIX; + + return connect (fd, (struct sockaddr *) &saddr, SUN_LEN(&saddr)); +} + +int +local_read (int fd, void *buf, int len) +{ + int count = -1; + do + { + count = read (fd, buf, len); + } + while (count == -1 && errno == EINTR); + return count; +} + +int +local_write (int fd, void *buf, int len) +{ + int count = -1; + do + { + count = write (fd, buf, len); + } + while (count == -1 && errno == EINTR); + return count; +} + +#endif /* ENABLE_LOCAL_SOCKETS */ diff --git a/libjava/classpath/native/jni/java-net/local.h b/libjava/classpath/native/jni/java-net/local.h new file mode 100644 index 000000000..035996a80 --- /dev/null +++ b/libjava/classpath/native/jni/java-net/local.h @@ -0,0 +1,28 @@ +#ifndef __LOCAL_H__ +#define __LOCAL_H__ + +#ifdef __cplusplus +extern "C" +{ +#endif +#define __EMACSEN__ } + +extern const char *local_error (void); +extern int local_create (int); +extern int local_bind (int, const char *); +extern int local_listen (int, int); +extern int local_accept (int, char *); +extern int local_available (int); +extern int local_close (int); +extern int local_shutdown_input (int); +extern int local_shutdown_output (int); +extern int local_connect (int, char *); +extern int local_unlink (char *); +extern int local_read (int, void *, int); +extern int local_write (int, void *, int); + +#ifdef __cplusplus +} +#endif + +#endif /* __LOCAL_H__ */ diff --git a/libjava/classpath/native/jni/java-nio/.cvsignore b/libjava/classpath/native/jni/java-nio/.cvsignore new file mode 100644 index 000000000..e9f2658a6 --- /dev/null +++ b/libjava/classpath/native/jni/java-nio/.cvsignore @@ -0,0 +1,8 @@ +*.o +*.a +*.lo +*.la +.libs +.deps +Makefile +Makefile.in diff --git a/libjava/classpath/native/jni/java-nio/Makefile.am b/libjava/classpath/native/jni/java-nio/Makefile.am new file mode 100644 index 000000000..398e6a6e7 --- /dev/null +++ b/libjava/classpath/native/jni/java-nio/Makefile.am @@ -0,0 +1,24 @@ +nativeexeclib_LTLIBRARIES = libjavanio.la + +libjavanio_la_SOURCES = gnu_java_nio_VMPipe.c \ + gnu_java_nio_VMChannel.c \ + gnu_java_nio_VMSelector.c \ + gnu_java_nio_charset_iconv_IconvDecoder.c \ + gnu_java_nio_charset_iconv_IconvEncoder.c \ + java_nio_MappedByteBufferImpl.c \ + java_nio_VMDirectByteBuffer.c \ + gnu_java_nio_EpollSelectorImpl.c \ + gnu_java_nio_KqueueSelectorImpl.c \ + javanio.h + +libjavanio_la_LIBADD = $(top_builddir)/native/jni/classpath/jcl.lo \ + $(top_builddir)/native/jni/native-lib/libclasspathnative.la \ + $(LTLIBICONV) + +# Directly included through javanio.h +EXTRA_DIST = javanio.c + +AM_LDFLAGS = @CLASSPATH_MODULE@ +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ +AM_CFLAGS = @WARNING_CFLAGS@ @STRICT_WARNING_CFLAGS@ @ERROR_CFLAGS@ \ + @EXTRA_CFLAGS@ diff --git a/libjava/classpath/native/jni/java-nio/Makefile.in b/libjava/classpath/native/jni/java-nio/Makefile.in new file mode 100644 index 000000000..427d072a1 --- /dev/null +++ b/libjava/classpath/native/jni/java-nio/Makefile.in @@ -0,0 +1,642 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +subdir = native/jni/java-nio +DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/../../config/depstand.m4 \ + $(top_srcdir)/../../config/lead-dot.m4 \ + $(top_srcdir)/../../config/lib-ld.m4 \ + $(top_srcdir)/../../config/lib-link.m4 \ + $(top_srcdir)/../../config/lib-prefix.m4 \ + $(top_srcdir)/../../config/multi.m4 \ + $(top_srcdir)/../../config/no-executables.m4 \ + $(top_srcdir)/../../config/override.m4 \ + $(top_srcdir)/../../libtool.m4 \ + $(top_srcdir)/../../ltoptions.m4 \ + $(top_srcdir)/../../ltsugar.m4 \ + $(top_srcdir)/../../ltversion.m4 \ + $(top_srcdir)/../../lt~obsolete.m4 \ + $(top_srcdir)/m4/ac_prog_antlr.m4 \ + $(top_srcdir)/m4/ac_prog_java.m4 \ + $(top_srcdir)/m4/ac_prog_java_works.m4 \ + $(top_srcdir)/m4/ac_prog_javac.m4 \ + $(top_srcdir)/m4/ac_prog_javac_works.m4 \ + $(top_srcdir)/m4/acattribute.m4 $(top_srcdir)/m4/accross.m4 \ + $(top_srcdir)/m4/acinclude.m4 \ + $(top_srcdir)/m4/ax_create_stdint_h.m4 \ + $(top_srcdir)/m4/ax_func_which_gethostbyname_r.m4 \ + $(top_srcdir)/m4/gcc_attribute.m4 $(top_srcdir)/m4/iconv.m4 \ + $(top_srcdir)/m4/pkg.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/../../mkinstalldirs +CONFIG_HEADER = $(top_builddir)/include/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__installdirs = "$(DESTDIR)$(nativeexeclibdir)" +LTLIBRARIES = $(nativeexeclib_LTLIBRARIES) +am__DEPENDENCIES_1 = +libjavanio_la_DEPENDENCIES = \ + $(top_builddir)/native/jni/classpath/jcl.lo \ + $(top_builddir)/native/jni/native-lib/libclasspathnative.la \ + $(am__DEPENDENCIES_1) +am_libjavanio_la_OBJECTS = gnu_java_nio_VMPipe.lo \ + gnu_java_nio_VMChannel.lo gnu_java_nio_VMSelector.lo \ + gnu_java_nio_charset_iconv_IconvDecoder.lo \ + gnu_java_nio_charset_iconv_IconvEncoder.lo \ + java_nio_MappedByteBufferImpl.lo \ + java_nio_VMDirectByteBuffer.lo \ + gnu_java_nio_EpollSelectorImpl.lo \ + gnu_java_nio_KqueueSelectorImpl.lo +libjavanio_la_OBJECTS = $(am_libjavanio_la_OBJECTS) +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/include +depcomp = $(SHELL) $(top_srcdir)/../../depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(libjavanio_la_SOURCES) +ETAGS = etags +CTAGS = ctags +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +ANTLR = @ANTLR@ +ANTLR_JAR = @ANTLR_JAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CAIRO_CFLAGS = @CAIRO_CFLAGS@ +CAIRO_LIBS = @CAIRO_LIBS@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CLASSPATH_CONVENIENCE = @CLASSPATH_CONVENIENCE@ +CLASSPATH_INCLUDES = @CLASSPATH_INCLUDES@ +CLASSPATH_MODULE = @CLASSPATH_MODULE@ +COLLECTIONS_PREFIX = @COLLECTIONS_PREFIX@ +CP = @CP@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DATE = @DATE@ +DEFAULT_PREFS_PEER = @DEFAULT_PREFS_PEER@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +ECJ_JAR = @ECJ_JAR@ +EGREP = @EGREP@ +ERROR_CFLAGS = @ERROR_CFLAGS@ +EXAMPLESDIR = @EXAMPLESDIR@ +EXEEXT = @EXEEXT@ +EXTRA_CFLAGS = @EXTRA_CFLAGS@ +FGREP = @FGREP@ +FIND = @FIND@ +FREETYPE2_CFLAGS = @FREETYPE2_CFLAGS@ +FREETYPE2_LIBS = @FREETYPE2_LIBS@ +GCONF_CFLAGS = @GCONF_CFLAGS@ +GCONF_LIBS = @GCONF_LIBS@ +GDK_CFLAGS = @GDK_CFLAGS@ +GDK_LIBS = @GDK_LIBS@ +GJDOC = @GJDOC@ +GLIB_CFLAGS = @GLIB_CFLAGS@ +GLIB_LIBS = @GLIB_LIBS@ +GMP_CFLAGS = @GMP_CFLAGS@ +GMP_LIBS = @GMP_LIBS@ +GREP = @GREP@ +GSTREAMER_BASE_CFLAGS = @GSTREAMER_BASE_CFLAGS@ +GSTREAMER_BASE_LIBS = @GSTREAMER_BASE_LIBS@ +GSTREAMER_CFLAGS = @GSTREAMER_CFLAGS@ +GSTREAMER_FILE_READER = @GSTREAMER_FILE_READER@ +GSTREAMER_LIBS = @GSTREAMER_LIBS@ +GSTREAMER_MIXER_PROVIDER = @GSTREAMER_MIXER_PROVIDER@ +GSTREAMER_PLUGINS_BASE_CFLAGS = @GSTREAMER_PLUGINS_BASE_CFLAGS@ +GSTREAMER_PLUGINS_BASE_LIBS = @GSTREAMER_PLUGINS_BASE_LIBS@ +GST_PLUGIN_LDFLAGS = @GST_PLUGIN_LDFLAGS@ +GTK_CFLAGS = @GTK_CFLAGS@ +GTK_LIBS = @GTK_LIBS@ +INIT_LOAD_LIBRARY = @INIT_LOAD_LIBRARY@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAR = @JAR@ +JAVA = @JAVA@ +JAVAC = @JAVAC@ +JAVAC_IS_GCJ = @JAVAC_IS_GCJ@ +JAVAC_MEM_OPT = @JAVAC_MEM_OPT@ +JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION = @JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION@ +JAY = @JAY@ +JAY_SKELETON = @JAY_SKELETON@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBDEBUG = @LIBDEBUG@ +LIBICONV = @LIBICONV@ +LIBMAGIC = @LIBMAGIC@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBVERSION = @LIBVERSION@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBICONV = @LTLIBICONV@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MKDIR = @MKDIR@ +MKDIR_P = @MKDIR_P@ +MOC = @MOC@ +MOZILLA_CFLAGS = @MOZILLA_CFLAGS@ +MOZILLA_LIBS = @MOZILLA_LIBS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PANGOFT2_CFLAGS = @PANGOFT2_CFLAGS@ +PANGOFT2_LIBS = @PANGOFT2_LIBS@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PATH_TO_ESCHER = @PATH_TO_ESCHER@ +PATH_TO_GLIBJ_ZIP = @PATH_TO_GLIBJ_ZIP@ +PERL = @PERL@ +PKG_CONFIG = @PKG_CONFIG@ +PLUGIN_DIR = @PLUGIN_DIR@ +QT_CFLAGS = @QT_CFLAGS@ +QT_LIBS = @QT_LIBS@ +RANLIB = @RANLIB@ +REMOVE = @REMOVE@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRICT_WARNING_CFLAGS = @STRICT_WARNING_CFLAGS@ +STRIP = @STRIP@ +TOOLSDIR = @TOOLSDIR@ +USER_JAVAH = @USER_JAVAH@ +VERSION = @VERSION@ +WANT_NATIVE_BIG_INTEGER = @WANT_NATIVE_BIG_INTEGER@ +WARNING_CFLAGS = @WARNING_CFLAGS@ +XMKMF = @XMKMF@ +XML_CFLAGS = @XML_CFLAGS@ +XML_LIBS = @XML_LIBS@ +XSLT_CFLAGS = @XSLT_CFLAGS@ +XSLT_LIBS = @XSLT_LIBS@ +XTEST_LIBS = @XTEST_LIBS@ +X_CFLAGS = @X_CFLAGS@ +X_EXTRA_LIBS = @X_EXTRA_LIBS@ +X_LIBS = @X_LIBS@ +X_PRE_LIBS = @X_PRE_LIBS@ +ZIP = @ZIP@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_ANTLR = @ac_ct_ANTLR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +default_toolkit = @default_toolkit@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +glibjdir = @glibjdir@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +multi_basedir = @multi_basedir@ +nativeexeclibdir = @nativeexeclibdir@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +toolexeclibdir = @toolexeclibdir@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +uudecode = @uudecode@ +vm_classes = @vm_classes@ +nativeexeclib_LTLIBRARIES = libjavanio.la +libjavanio_la_SOURCES = gnu_java_nio_VMPipe.c \ + gnu_java_nio_VMChannel.c \ + gnu_java_nio_VMSelector.c \ + gnu_java_nio_charset_iconv_IconvDecoder.c \ + gnu_java_nio_charset_iconv_IconvEncoder.c \ + java_nio_MappedByteBufferImpl.c \ + java_nio_VMDirectByteBuffer.c \ + gnu_java_nio_EpollSelectorImpl.c \ + gnu_java_nio_KqueueSelectorImpl.c \ + javanio.h + +libjavanio_la_LIBADD = $(top_builddir)/native/jni/classpath/jcl.lo \ + $(top_builddir)/native/jni/native-lib/libclasspathnative.la \ + $(LTLIBICONV) + + +# Directly included through javanio.h +EXTRA_DIST = javanio.c +AM_LDFLAGS = @CLASSPATH_MODULE@ +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ +AM_CFLAGS = @WARNING_CFLAGS@ @STRICT_WARNING_CFLAGS@ @ERROR_CFLAGS@ \ + @EXTRA_CFLAGS@ + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu native/jni/java-nio/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu native/jni/java-nio/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-nativeexeclibLTLIBRARIES: $(nativeexeclib_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(nativeexeclibdir)" || $(MKDIR_P) "$(DESTDIR)$(nativeexeclibdir)" + @list='$(nativeexeclib_LTLIBRARIES)'; test -n "$(nativeexeclibdir)" || list=; \ + list2=; for p in $$list; do \ + if test -f $$p; then \ + list2="$$list2 $$p"; \ + else :; fi; \ + done; \ + test -z "$$list2" || { \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(nativeexeclibdir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(nativeexeclibdir)"; \ + } + +uninstall-nativeexeclibLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(nativeexeclib_LTLIBRARIES)'; test -n "$(nativeexeclibdir)" || list=; \ + for p in $$list; do \ + $(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(nativeexeclibdir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(nativeexeclibdir)/$$f"; \ + done + +clean-nativeexeclibLTLIBRARIES: + -test -z "$(nativeexeclib_LTLIBRARIES)" || rm -f $(nativeexeclib_LTLIBRARIES) + @list='$(nativeexeclib_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libjavanio.la: $(libjavanio_la_OBJECTS) $(libjavanio_la_DEPENDENCIES) + $(LINK) -rpath $(nativeexeclibdir) $(libjavanio_la_OBJECTS) $(libjavanio_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_nio_EpollSelectorImpl.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_nio_KqueueSelectorImpl.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_nio_VMChannel.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_nio_VMPipe.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_nio_VMSelector.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_nio_charset_iconv_IconvDecoder.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_nio_charset_iconv_IconvEncoder.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/java_nio_MappedByteBufferImpl.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/java_nio_VMDirectByteBuffer.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) +installdirs: + for dir in "$(DESTDIR)$(nativeexeclibdir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-nativeexeclibLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-nativeexeclibLTLIBRARIES + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-nativeexeclibLTLIBRARIES + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-nativeexeclibLTLIBRARIES ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags dvi dvi-am html html-am info info-am install \ + install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-nativeexeclibLTLIBRARIES install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-nativeexeclibLTLIBRARIES + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/libjava/classpath/native/jni/java-nio/gnu_java_nio_EpollSelectorImpl.c b/libjava/classpath/native/jni/java-nio/gnu_java_nio_EpollSelectorImpl.c new file mode 100644 index 000000000..39161d68e --- /dev/null +++ b/libjava/classpath/native/jni/java-nio/gnu_java_nio_EpollSelectorImpl.c @@ -0,0 +1,416 @@ +/* gnu_java_nio_EpollSelectorImpl.c -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#ifdef HAVE_CONFIG_H +#include +#endif /* HAVE_CONFIG_H */ + +#ifdef HAVE_SYS_EPOLL_H +#include +#endif /* HAVE_SYS_EPOLL_H */ + +#include + +#include +#include +#include +#include + +#define IO_EXCEPTION "java/io/IOException" + +/* #define TRACE_EPOLL 1 */ + + +/* + * Class: gnu_java_nio_EpollSelectorImpl + * Method: epoll_supported + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL +Java_gnu_java_nio_EpollSelectorImpl_epoll_1supported (JNIEnv *e __attribute__((unused)), + jclass c __attribute__((unused))) +{ +#ifdef HAVE_EPOLL_CREATE + return JNI_TRUE; +#else + return JNI_FALSE; +#endif /* HAVE_EPOLL_CREATE */ +} + +/* + * Class: gnu_java_nio_EpollSelectorImpl + * Method: sizeof_struct + * Signature: ()I + */ +JNIEXPORT jint JNICALL +Java_gnu_java_nio_EpollSelectorImpl_sizeof_1struct (JNIEnv *env, + jclass c __attribute__((unused))) +{ +#ifdef HAVE_EPOLL_CREATE + (void) env; +#ifdef TRACE_EPOLL + fprintf (stderr, "%s: sizeof is %d\n", __FUNCTION__, sizeof (struct epoll_event)); +#endif /* TRACE_EPOLL */ + return sizeof (struct epoll_event); +#else + JCL_ThrowException (env, "java/lang/InternalError", "epoll support not available"); + return -1; +#endif /* HAVE_EPOLL_CREATE */ +} + +/* + * Class: gnu_java_nio_EpollSelectorImpl + * Method: epoll_create + * Signature: (I)I + */ +JNIEXPORT jint JNICALL +Java_gnu_java_nio_EpollSelectorImpl_epoll_1create (JNIEnv *env, + jclass c __attribute__((unused)), + jint size) +{ +#ifdef HAVE_EPOLL_CREATE + int fd = epoll_create (size); + +#ifdef TRACE_EPOLL + fprintf (stderr, "%s: epoll_create returns %d\n", __FUNCTION__, fd); +#endif /* TRACE_EPOLL */ + + if (fd == -1) + { + if (ENOSYS == errno) + JCL_ThrowException (env, "java/lang/InternalError", + strerror (errno)); + else + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); + } + return fd; +#else + (void) size; + JCL_ThrowException (env, "java/lang/InternalError", "epoll support not available"); + return -1; +#endif /* HAVE_EPOLL_CREATE */ +} + +/* + * Class: gnu_java_nio_EpollSelectorImpl + * Method: epoll_add + * Signature: (III)V + */ +JNIEXPORT void JNICALL +Java_gnu_java_nio_EpollSelectorImpl_epoll_1add (JNIEnv *env, + jclass c __attribute__((unused)), + jint efd, jint fd, jint ops) +{ +#ifdef HAVE_EPOLL_CREATE + struct epoll_event event; + + memset (&event, 0, sizeof (struct epoll_event)); + + if ((ops & gnu_java_nio_EpollSelectorImpl_OP_ACCEPT) != 0 + || (ops & gnu_java_nio_EpollSelectorImpl_OP_READ) != 0) + event.events = EPOLLIN; + + if ((ops & gnu_java_nio_EpollSelectorImpl_OP_CONNECT) != 0 + || (ops & gnu_java_nio_EpollSelectorImpl_OP_WRITE) != 0) + event.events |= EPOLLOUT; + + event.data.fd = fd; + +#ifdef TRACE_EPOLL + fprintf (stderr, "%s: adding struct epoll_event { events: %o; data.fd: %d } to %d\n", + __FUNCTION__, event.events, event.data.fd, efd); +#endif /* TRACE_EPOLL */ + + if (epoll_ctl (efd, EPOLL_CTL_ADD, fd, &event) == -1) + { + if (ENOSYS == errno) + JCL_ThrowException (env, "java/lang/InternalError", + strerror (errno)); + else + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); + } +#else + (void) efd; + (void) fd; + (void) ops; + JCL_ThrowException (env, "java/lang/InternalError", "epoll support not available"); +#endif /* HAVE_EPOLL_CREATE */ +} + + +/* + * Class: gnu_java_nio_EpollSelectorImpl + * Method: epoll_modify + * Signature: (III)V + */ +JNIEXPORT void JNICALL +Java_gnu_java_nio_EpollSelectorImpl_epoll_1modify (JNIEnv *env, + jclass c __attribute__((unused)), + jint efd, jint fd, jint ops) +{ +#ifdef HAVE_EPOLL_CREATE + struct epoll_event event; + + memset (&event, 0, sizeof (struct epoll_event)); + + if ((ops & gnu_java_nio_EpollSelectorImpl_OP_ACCEPT) != 0 + || (ops & gnu_java_nio_EpollSelectorImpl_OP_READ) != 0) + event.events = EPOLLIN; + + if ((ops & gnu_java_nio_EpollSelectorImpl_OP_CONNECT) != 0 + || (ops & gnu_java_nio_EpollSelectorImpl_OP_WRITE) != 0) + event.events |= EPOLLOUT; + + event.data.fd = fd; + +#ifdef TRACE_EPOLL + fprintf (stderr, "%s: modding struct epoll_event { events: %o; data.fd: %d } on %d\n", + __FUNCTION__, event.events, event.data.fd, efd); +#endif /* TRACE_EPOLL */ + + if (epoll_ctl (efd, EPOLL_CTL_MOD, fd, &event) == -1) + { + if (ENOSYS == errno) + JCL_ThrowException (env, "java/lang/InternalError", + strerror (errno)); + else + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); + } +#else + (void) efd; + (void) fd; + (void) ops; + JCL_ThrowException (env, "java/lang/InternalError", "epoll support not available"); +#endif /* HAVE_EPOLL_CREATE */ +} + + +/* + * Class: gnu_java_nio_EpollSelectorImpl + * Method: epoll_delete + * Signature: (II)V + */ +JNIEXPORT void JNICALL +Java_gnu_java_nio_EpollSelectorImpl_epoll_1delete (JNIEnv *env, + jclass c __attribute__((unused)), + jint efd, jint fd) +{ +#ifdef HAVE_EPOLL_CREATE + struct epoll_event event; + + memset (&event, 0, sizeof (struct epoll_event)); + event.data.fd = fd; + +#ifdef TRACE_EPOLL + fprintf (stderr, "%s: delete events on fd %d for %d\n", __FUNCTION__, fd, efd); +#endif /* TRACE_EPOLL */ + + /* Older kernel versions require a non-null `event' parameter, + * even though it is ignored by this call. + */ + if (epoll_ctl (efd, EPOLL_CTL_DEL, fd, &event) == -1) + { + if (ENOSYS == errno) + JCL_ThrowException (env, "java/lang/InternalError", + strerror (errno)); + /* XXX the docs here seem a little strange. If `fd' is closed, + epoll_ctl returns EBADF; but the docs say that this happens + only when efd is invalid. Go figure. + */ + else if (ENOENT == errno || EBADF == errno) + return; /* fd is closed; it's already removed. */ + else + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); + } +#else + (void) efd; + (void) fd; + JCL_ThrowException (env, "java/lang/InternalError", "epoll support not available"); +#endif /* HAVE_EPOLL_CREATE */ +} + +/* + * Class: gnu_java_nio_EpollSelectorImpl + * Method: epoll_wait + * Signature: (ILjava/nio/ByteBuffer;II)I + */ +JNIEXPORT jint JNICALL +Java_gnu_java_nio_EpollSelectorImpl_epoll_1wait (JNIEnv *env, + jclass c __attribute__((unused)), + jint efd, jobject nstate, + jint num_events, jint timeout) +{ +#ifdef HAVE_EPOLL_CREATE + void *p = (*env)->GetDirectBufferAddress (env, nstate); + struct epoll_event *events = (struct epoll_event *) p; + int ret; + + if (p == NULL) + { + if (!(*env)->ExceptionCheck (env)) + JCL_ThrowException (env, IO_EXCEPTION, "getting native state failed"); + return -1; + } + +#ifdef TRACE_EPOLL + fprintf (stderr, "%s: events: %p; num_events: %d; timeout: %d; efd: %d\n", + __FUNCTION__, p, num_events, timeout, efd); +#endif /* TRACE_EPOLL */ + + ret = epoll_wait (efd, events, num_events, timeout); + + if (ret == -1) + { + if (ENOSYS == errno) + JCL_ThrowException (env, "java/lang/InternalError", + strerror (errno)); + else if (EINTR == errno) + ret = 0; + else + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); + } + +#ifdef TRACE_EPOLL + fprintf (stderr, " epoll_wait returns %d\n", ret); + { + int i; + for (i = 0; i < ret; i++) + { + fprintf (stderr, " [%4i]: events: %o; data.fd: %d\n", i, events[i].events, + events[i].data.fd); + } + } + fflush (stderr); +#endif /* TRACE_EPOLL */ + + return ret; +#else + (void) efd; + (void) nstate; + (void) num_events; + (void) timeout; + JCL_ThrowException (env, "java/lang/InternalError", "epoll support not available"); + return -1; +#endif /* HAVE_EPOLL_CREATE */ +} + + +/* + * Class: gnu_java_nio_EpollSelectorImpl + * Method: selected_fd + * Signature: (Ljava/nio/ByteBuffer;)I + */ +JNIEXPORT jint JNICALL +Java_gnu_java_nio_EpollSelectorImpl_selected_1fd (JNIEnv *env, + jclass c __attribute__((unused)), + jobject value) +{ +#ifdef HAVE_EPOLL_CREATE + void *p = (*env)->GetDirectBufferAddress (env, value); + struct epoll_event *event = (struct epoll_event *) p; + +#ifdef TRACE_EPOLL + fprintf (stderr, "%s: event: %p\n", __FUNCTION__, p); +#endif /* TRACE_EPOLL */ + + if (p == NULL) + { + if (!(*env)->ExceptionCheck (env)) + JCL_ThrowException (env, "java/lang/InternalError", + "getting native state failed"); + return -1; + } + +#ifdef TRACE_EPOLL + fprintf (stderr, " data.fd: %d\n", event->data.fd); + fflush (stderr); +#endif /* TRACE_EPOLL */ + + return event->data.fd; +#else + (void) value; + JCL_ThrowException (env, "java/lang/InternalError", "epoll support not available"); + return -1; +#endif /* HAVE_EPOLL_CREATE */ +} + + +/* + * Class: gnu_java_nio_EpollSelectorImpl + * Method: selected_ops + * Signature: (Ljava/nio/ByteBuffer;)I + */ +JNIEXPORT jint JNICALL +Java_gnu_java_nio_EpollSelectorImpl_selected_1ops (JNIEnv *env, + jclass c __attribute__((unused)), + jobject value) +{ +#ifdef HAVE_EPOLL_CREATE + void *p = (*env)->GetDirectBufferAddress (env, value); + struct epoll_event *event = (struct epoll_event *) p; + int ret = 0; + +#ifdef TRACE_EPOLL + fprintf (stderr, "%s: event: %p\n", __FUNCTION__, p); +#endif /* TRACE_EPOLL */ + + if (p == NULL) + { + if (!(*env)->ExceptionCheck (env)) + JCL_ThrowException (env, "java/lang/InternalError", + "getting native state failed"); + return -1; + } + + if ((event->events & EPOLLIN) != 0) + ret |= gnu_java_nio_EpollSelectorImpl_OP_ACCEPT | gnu_java_nio_EpollSelectorImpl_OP_READ; + if ((event->events & EPOLLOUT) != 0) + ret |= gnu_java_nio_EpollSelectorImpl_OP_CONNECT | gnu_java_nio_EpollSelectorImpl_OP_WRITE; + +#ifdef TRACE_EPOLL + fprintf (stderr, " events: %o\n", event->events); + fflush (stderr); +#endif /* TRACE_EPOLL */ + + return ret; +#else + (void) value; + JCL_ThrowException (env, "java/lang/InternalError", "epoll support not available"); + return -1; +#endif /* HAVE_EPOLL_CREATE */ +} diff --git a/libjava/classpath/native/jni/java-nio/gnu_java_nio_KqueueSelectorImpl.c b/libjava/classpath/native/jni/java-nio/gnu_java_nio_KqueueSelectorImpl.c new file mode 100644 index 000000000..94e6db7f8 --- /dev/null +++ b/libjava/classpath/native/jni/java-nio/gnu_java_nio_KqueueSelectorImpl.c @@ -0,0 +1,387 @@ +/* gnu_java_nio_channel_KqueueSelectorImpl.c -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#if HAVE_CONFIG_H +#include +#endif /* HAVE_CONFIG_H */ + +#include +#if HAVE_SYS_EVENT_H +#include +#endif /* HAVE_SYS_EVENT_H */ +#include +#include +#include +#include + +#include +#include + +#include + +#define KEY_OP_ACCEPT 16 +#define KEY_OP_CONNECT 8 +#define KEY_OP_READ 1 +#define KEY_OP_WRITE 4 + +/* XXX this requires -std=gnu99 or c99 */ +/* #ifdef TRACE_KQUEUE */ +/* #define TRACE(fmt, ...) fprintf (stderr, "%s: " fmt "\n", __FUNCTION__, __VA_ARGS__); */ +/* #else */ +/* #define TRACE(fmt, ...) */ +/* #endif */ + +/* #define TRACE_KQUEUE 1 */ + + +#define throw_not_supported(env) JCL_ThrowException (env, "java/lang/UnsupportedOperationException", "kqueue/kevent support not available") + + +/* + * Class: gnu_java_nio_KqueueSelectorImpl + * Method: kqueue_supported + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL +Java_gnu_java_nio_KqueueSelectorImpl_kqueue_1supported (JNIEnv *env __attribute__((unused)), + jclass clazz __attribute__((unused))) +{ +#if defined(HAVE_KQUEUE) && defined(HAVE_KEVENT) + return JNI_TRUE; +#else + return JNI_FALSE; +#endif /* HAVE_KQUEUE && HAVE_KEVENT */ +} + + +/* + * Class: gnu_java_nio_KqueueSelectorImpl + * Method: sizeof_struct_kevent + * Signature: ()I + */ +JNIEXPORT jint JNICALL +Java_gnu_java_nio_KqueueSelectorImpl_sizeof_1struct_1kevent +(JNIEnv *env __attribute__((unused)), jclass clazz __attribute__((unused))) +{ +#if defined(HAVE_KQUEUE) && defined(HAVE_KEVENT) +/* TRACE("return sizeof %lu", sizeof (struct kevent)); */ + return sizeof (struct kevent); +#else + throw_not_supported (env); + return -1; +#endif /* HAVE_KQUEUE && HAVE_KEVENT */ +} + + +/* + * Class: gnu_java_nio_KqueueSelectorImpl + * Method: implOpen + * Signature: ()I + */ +JNIEXPORT jint JNICALL +Java_gnu_java_nio_KqueueSelectorImpl_implOpen +(JNIEnv *env, jclass clazz __attribute__((unused))) +{ +#if defined(HAVE_KQUEUE) && defined(HAVE_KEVENT) + int kq = kqueue (); +/* TRACE("kqueue returns %d", kq); */ + if (kq == -1) + JCL_ThrowException (env, "java/io/IOException", strerror (errno)); + return kq; +#else + throw_not_supported (env); + return -1; +#endif +} + + +/* + * Class: gnu_java_nio_KqueueSelectorImpl + * Method: implClose + * Signature: (I)V + */ +JNIEXPORT void JNICALL +Java_gnu_java_nio_KqueueSelectorImpl_implClose (JNIEnv *env, + jclass clazz __attribute__((unused)), + jint kq) +{ +#if defined(HAVE_KQUEUE) && defined(HAVE_KEVENT) +/* TRACE("closing %d", kq); */ + if (close (kq) != 0) + JCL_ThrowException (env, "java/io/IOException", strerror (errno)); +#else + (void) kq; + throw_not_supported (env); +#endif /* HAVE_KQUEUE && HAVE_KEVENT */ +} + + +/* + * Class: gnu_java_nio_KqueueSelectorImpl + * Method: kevent_set + * Signature: (Ljava/nio/ByteBuffer;IIIZ)V + */ +JNIEXPORT void JNICALL +Java_gnu_java_nio_KqueueSelectorImpl_kevent_1set (JNIEnv *env, + jclass clazz __attribute__((unused)), + jobject nstate, jint i, jint fd, + jint ops, jint active, jint key) +{ +#if defined(HAVE_KQUEUE) && defined(HAVE_KEVENT) + struct kevent *kev; + short ident; + + kev = (struct kevent *) (*env)->GetDirectBufferAddress (env, nstate); + +#ifdef TRACE_KQUEUE + printf ("kevent_set fd:%d p:%p i:%d ops:%x active:%x key:%x\n", + fd, (void *) kev, i, ops, active, key); +#endif /* TRACE_KQUEUE */ + + if (kev == NULL) + { + JCL_ThrowException (env, "java/lang/InternalError", + "GetDirectBufferAddress returned NULL!"); + return; + } + + ident = fd; + memset (&kev[i], 0, sizeof (struct kevent)); + + if ((ops & KEY_OP_READ) || (ops & KEY_OP_ACCEPT)) + { + /* Add event if it wasn't previously added. */ + if (!(active & KEY_OP_READ) && !(active & KEY_OP_ACCEPT)) + EV_SET(&kev[i], ident, EVFILT_READ, EV_ADD, 0, 0, (void *) key); + } + else + { + /* Delete event if it was previously added */ + if ((active & KEY_OP_READ) || (active & KEY_OP_ACCEPT)) + EV_SET(&kev[i], ident, EVFILT_READ, EV_DELETE, 0, 0, (void *) key); + } + + /* Do the same thing for the write filter. */ + if ((ops & KEY_OP_WRITE) || (ops & KEY_OP_CONNECT)) + { + if (!(active & KEY_OP_WRITE) && !(active & KEY_OP_CONNECT)) + EV_SET(&kev[i], ident, EVFILT_WRITE, EV_ADD, 0, 0, (void *) key); + } + else + { + if ((active & KEY_OP_WRITE) || (active & KEY_OP_CONNECT)) + EV_SET(&kev[i], ident, EVFILT_WRITE, EV_DELETE, 0, 0, (void *) key); + } + +#ifdef TRACE_KQUEUE + printf (" set kevent %2d: ident:%u filter:%x flags:%o fflags:%o data:%p udata:%p\n", + i, (unsigned) kev[i].ident, kev[i].filter, kev[i].flags, kev[i].fflags, + (void *) kev[i].data, kev[i].udata); +#endif /* TRACE_KQUEUE */ +#else + (void) nstate; + (void) i; + (void) fd; + (void) ops; + (void) key; + (void) active; + throw_not_supported (env); +#endif /* HAVE_KQUEUE && HAVE_KEVENT */ +} + + +/* + * Class: gnu_java_nio_KqueueSelectorImpl + * Method: kevent + * Signature: (ILjava/nio/ByteBuffer;IJ)I + */ +JNIEXPORT jint JNICALL +Java_gnu_java_nio_KqueueSelectorImpl_kevent (JNIEnv *env, + jobject this __attribute__((unused)), + jint kq, jobject nstate, jint nevents, + jint maxevents, jlong timeout) +{ +#if defined(HAVE_KQUEUE) && defined(HAVE_KEVENT) + struct timespec tv; + struct timespec *t = NULL; + struct kevent *kev = (struct kevent *) (*env)->GetDirectBufferAddress (env, nstate); + int ret; + +#ifdef TRACE_KQUEUE + int i; + + printf ("[%d] kevent nevents:%d maxevents:%d timeout:%lld\n", kq, nevents, maxevents, timeout); + printf ("[%d] addding/deleting %d events\n", kq, nevents); + for (i = 0; i < nevents; i++) + { + printf ("[%d] kevent input [%d]: ident:%u filter:%x flags:%o fflags:%o data:%p udata:%p\n", + kq, i, (unsigned) kev[i].ident, kev[i].filter, kev[i].flags, kev[i].fflags, + (void *) kev[i].data, kev[i].udata); + } +#endif + +/* TRACE("events: %p; nevents: %d; timeout: %lld", (void *) kev, nevents, timeout); */ + + if (timeout != -1) + { + tv.tv_sec = timeout / 1000; + tv.tv_nsec = (timeout % 1000) * 1000; + t = &tv; + } + + ret = kevent (kq, (const struct kevent *) kev, nevents, kev, maxevents, t); + + if (ret == -1) + { + if (errno == EINTR) + ret = 0; + else + JCL_ThrowException (env, "java/io/IOException", strerror (errno)); + } + +#ifdef TRACE_KQUEUE + for (i = 0; i < ret; i++) + { + printf ("[%d] kevent output [%d]: ident:%u filter:%x flags:%o fflags:%o data:%p udata:%p\n", + kq, i, (unsigned) kev[i].ident, kev[i].filter, kev[i].flags, kev[i].fflags, + (void *) kev[i].data, kev[i].udata); + } +#endif + + return ret; +#else + (void) kq; + (void) nstate; + (void) nevents; + (void) maxevents; + (void) timeout; + throw_not_supported (env); + return -1; +#endif /* HAVE_KQUEUE && HAVE_KEVENT */ +} + + +/* + * Class: gnu_java_nio_KqueueSelectorImpl + * Method: fetch_key + * Signature: (Ljava/nio/ByteBuffer;)I; + */ +JNIEXPORT jint JNICALL +Java_gnu_java_nio_KqueueSelectorImpl_fetch_1key (JNIEnv *env, + jclass clazz __attribute__((unused)), + jobject nstate) +{ +#if defined(HAVE_KQUEUE) && defined(HAVE_KEVENT) + struct kevent *kev = (struct kevent *) (*env)->GetDirectBufferAddress (env, nstate); +/* TRACE("return key %p\n", kev->udata); */ + return (jint) kev->udata; +#else + (void) nstate; + throw_not_supported (env); + return -1; +#endif /* HAVE_KQUEUE && HAVE_KEVENT */ +} + + +/* + * Class: gnu_java_nio_KqueueSelectorImpl + * Method: ready_ops + * Signature: (Ljava/nio/ByteBuffer;I)I + */ +JNIEXPORT jint JNICALL +Java_gnu_java_nio_KqueueSelectorImpl_ready_1ops (JNIEnv *env, + jclass clazz __attribute__((unused)), + jobject nstate, jint interest) +{ +#if defined(HAVE_KQUEUE) && defined(HAVE_KEVENT) + struct kevent *kev = (struct kevent *) (*env)->GetDirectBufferAddress (env, nstate); + jint ready = 0; + + if ((kev->flags & EV_ERROR) == EV_ERROR) + { + printf ("!!! error selecting fd %d: %s", (int) (kev->ident), strerror ((int) (kev->data))); + return 0; + } + + /* We poll for READ for OP_READ and OP_ACCEPT. */ + if (kev->filter == EVFILT_READ) + { + ready = (interest & KEY_OP_READ) | (interest & KEY_OP_ACCEPT); +/* TRACE("filter EVFILT_READ. Ready ops set to %x", ready); */ + } + + /* Poll for WRITE for OP_WRITE and OP_CONNECT; I guess we *should* + get a WRITE event if we are connected, but I don't know if we do + for real. FIXME */ + if (kev->filter == EVFILT_WRITE) + { + ready = (interest & KEY_OP_WRITE) | (interest & KEY_OP_CONNECT); +/* TRACE("filter EVFILT_WRITE. Ready ops set to %x", ready); */ + } + + return ready; +#else + (void) nstate; + (void) interest; + throw_not_supported (env); + return -1; +#endif /* HAVE_KQUEUE && HAVE_KEVENT */ +} + + +/* + * Class: gnu_java_nio_KqueueSelectorImpl + * Method: check_eof + * Signature: (Ljava/nio/ByteBuffer;)Z + */ +JNIEXPORT jboolean JNICALL +Java_gnu_java_nio_KqueueSelectorImpl_check_1eof (JNIEnv *env, + jclass clazz __attribute__((unused)), + jobject nstate) +{ +#if defined(HAVE_KQUEUE) && defined(HAVE_KEVENT) + struct kevent *kev = (struct kevent *) (*env)->GetDirectBufferAddress (env, nstate); + if ((kev->flags & EV_EOF) == EV_EOF) + return JNI_TRUE; + return JNI_FALSE; +#else + (void) nstate; + throw_not_supported (env); + return JNI_FALSE; +#endif +} diff --git a/libjava/classpath/native/jni/java-nio/gnu_java_nio_VMChannel.c b/libjava/classpath/native/jni/java-nio/gnu_java_nio_VMChannel.c new file mode 100644 index 000000000..7899f0b94 --- /dev/null +++ b/libjava/classpath/native/jni/java-nio/gnu_java_nio_VMChannel.c @@ -0,0 +1,2035 @@ +/* gnu_java_nio_VMChannel.c - + Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include +#ifdef HAVE_SYS_MMAN_H +#include +#endif +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include +#include + +#include "cpio.h" +#include "gnu_java_nio_VMChannel.h" +#include "javanio.h" + +#ifdef HAVE_FCNTL_H +#include +#endif /* HAVE_FCNTL_H */ + +#if defined(HAVE_SYS_IOCTL_H) +#define BSD_COMP /* Get FIONREAD on Solaris2 */ +#include +#endif +#if defined(HAVE_SYS_FILIO_H) /* Get FIONREAD on Solaris 2.5 */ +#include +#endif + +#define CONNECT_EXCEPTION "java/net/ConnectException" +#define IO_EXCEPTION "java/io/IOException" +#define SOCKET_EXCEPTION "java/net/SocketException" +#define INTERRUPTED_IO_EXCEPTION "java/io/InterruptedIOException" +#define NON_READABLE_CHANNEL_EXCEPTION "java/nio/channels/NonReadableChannelException" +#define NON_WRITABLE_CHANNEL_EXCEPTION "java/nio/channels/NonWritableChannelException" +#define SOCKET_TIMEOUT_EXCEPTION "java/net/SocketTimeoutException" + +/* Align a value up or down to a multiple of the pagesize. */ +#define ALIGN_DOWN(p,s) ((p) - ((p) % (s))) +#define ALIGN_UP(p,s) ((p) + ((s) - ((p) % (s)))) + +/* + * Limit to maximum of 16 buffers + */ +#define JCL_IOV_MAX 16 + +#ifdef __cplusplus +extern "C" +{ +#endif + +enum JCL_buffer_type { DIRECT, HEAP, ARRAY, UNKNOWN }; + +struct JCL_buffer +{ + enum JCL_buffer_type type; + jbyte *ptr; + jint offset; + jint position; + jint limit; + jint count; +}; + +jmethodID get_method_id(JNIEnv *, jclass, const char *, const char *); +void JCL_print_buffer(JNIEnv *, struct JCL_buffer *); +int JCL_init_buffer(JNIEnv *, struct JCL_buffer *, jobject); +void JCL_release_buffer(JNIEnv *, struct JCL_buffer *, jobject, jint); +void JCL_cleanup_buffers(JNIEnv *, struct JCL_buffer *, jint, jobjectArray, jint, jlong); +int JCL_thread_interrupted(JNIEnv *); + +static jfieldID address_fid; +static jmethodID get_position_mid; +static jmethodID set_position_mid; +static jmethodID get_limit_mid; +static jmethodID set_limit_mid; +static jmethodID has_array_mid; +static jmethodID array_mid; +static jmethodID array_offset_mid; +static jmethodID thread_interrupted_mid; +static jclass vm_channel_class; + +jmethodID +get_method_id(JNIEnv *env, jclass clazz, const char *name, + const char *sig) +{ + jmethodID mid = (*env)->GetMethodID(env, clazz, name, sig); +/* NIODBG("name: %s; sig: %s", name, sig); */ + if (mid == NULL) + { + JCL_ThrowException(env, "java/lang/InternalError", name); + return NULL; + } + + return mid; +} + +inline void +JCL_print_buffer(JNIEnv *env __attribute__((__unused__)), struct JCL_buffer *buf) +{ + fprintf (stderr, "Buffer - type: %d, ptr: %p\n", buf->type, buf->ptr); +} + + +int +JCL_init_buffer(JNIEnv *env, struct JCL_buffer *buf, jobject bbuf) +{ + void *addr = (*env)->GetDirectBufferAddress (env, bbuf); + +/* NIODBG("buf: %p; bbuf: %p; addr: %p", (void *) buf, bbuf, addr); */ + + buf->position = (*env)->CallIntMethod(env, bbuf, get_position_mid); + buf->limit = (*env)->CallIntMethod(env, bbuf, get_limit_mid); + buf->offset = 0; + buf->count = 0; + buf->type = UNKNOWN; + + if (addr != NULL) + { + buf->ptr = (jbyte *) addr; + buf->type = DIRECT; + } + else + { + jboolean has_array; + has_array = (*env)->CallBooleanMethod(env, bbuf, has_array_mid); + + if (has_array == JNI_TRUE) + { + jbyteArray arr; + buf->offset = (*env)->CallIntMethod(env, bbuf, array_offset_mid); + arr = (*env)->CallObjectMethod(env, bbuf, array_mid); + buf->ptr = (*env)->GetByteArrayElements(env, arr, 0); + buf->type = ARRAY; + (*env)->DeleteLocalRef(env, arr); + } + else + { + jobject address = (*env)->GetObjectField (env, bbuf, address_fid); + if (address == NULL) + return -1; /* XXX handle non-array, non-native buffers? */ + buf->ptr = (jbyte *) JCL_GetRawData(env, address); + buf->type = HEAP; + (*env)->DeleteLocalRef(env, address); + } + } + + return 0; +} + +void +JCL_release_buffer(JNIEnv *env, struct JCL_buffer *buf, jobject bbuf, + jint action) +{ + jbyteArray arr; + +/* NIODBG("buf: %p; bbuf: %p; action: %x", (void *) buf, bbuf, action); */ + + /* Set the position to the appropriate value */ + if (buf->count > 0) + { + jobject bbufTemp; + bbufTemp = (*env)->CallObjectMethod(env, bbuf, set_position_mid, + buf->position + buf->count); + (*env)->DeleteLocalRef(env, bbufTemp); + } + + switch (buf->type) + { + case DIRECT: + case HEAP: + break; + case ARRAY: + arr = (*env)->CallObjectMethod(env, bbuf, array_mid); + (*env)->ReleaseByteArrayElements(env, arr, buf->ptr, action); + (*env)->DeleteLocalRef(env, arr); + break; + case UNKNOWN: + /* TODO: Handle buffers that are not direct or array backed */ + break; + } +} + +void +JCL_cleanup_buffers(JNIEnv *env, + struct JCL_buffer *bi_list, + jint vec_len, + jobjectArray bbufs, + jint offset, + jlong num_bytes) +{ + jint i; + +/* NIODBG("bi_list: %p; vec_len: %d; bbufs: %p; offset: %d; num_bytes: %lld", */ +/* (void *) bi_list, vec_len, bbufs, offset, num_bytes); */ + + /* Update all of the bbufs with the approriate information */ + for (i = 0; i < vec_len; i++) + { + struct JCL_buffer* buf; + jobject bbuf; + + buf = &bi_list[i]; + bbuf = (*env)->GetObjectArrayElement(env, bbufs, offset + i); + + if (num_bytes > (buf->limit - buf->position)) + buf->count = (buf->limit - buf->position); + else + buf->count = num_bytes; + + num_bytes -= buf->count; + + JCL_release_buffer(env, buf, bbuf, JNI_ABORT); + (*env)->DeleteLocalRef(env, bbuf); + } +} + + +int +JCL_thread_interrupted(JNIEnv *env) +{ + return (int) (*env)->CallStaticBooleanMethod(env, vm_channel_class, + thread_interrupted_mid); +} + + +/* + * Class: gnu_java_nio_VMChannel + * Method: stdin_fd + * Signature: ()I + */ +JNIEXPORT jint JNICALL +Java_gnu_java_nio_VMChannel_stdin_1fd (JNIEnv *env __attribute__((unused)), + jclass c __attribute__((unused))) +{ +/* NIODBG("%d", fileno (stdin)); */ + return fileno (stdin); +} + + +/* + * Class: gnu_java_nio_VMChannel + * Method: stdout_fd + * Signature: ()I + */ +JNIEXPORT jint JNICALL +Java_gnu_java_nio_VMChannel_stdout_1fd (JNIEnv *env __attribute__((unused)), + jclass c __attribute__((unused))) +{ +/* NIODBG("%d", fileno (stdout)); */ + return fileno (stdout); +} + + +/* + * Class: gnu_java_nio_VMChannel + * Method: stderr_fd + * Signature: ()I + */ +JNIEXPORT jint JNICALL +Java_gnu_java_nio_VMChannel_stderr_1fd (JNIEnv *env __attribute__((unused)), + jclass c __attribute__((unused))) +{ +/* NIODBG("%d", fileno (stderr)); */ + return fileno (stderr); +} + + +JNIEXPORT void JNICALL +Java_gnu_java_nio_VMChannel_initIDs (JNIEnv *env, + jclass clazz) +{ + jclass bufferClass = JCL_FindClass(env, "java/nio/Buffer"); + jclass byteBufferClass = JCL_FindClass(env, "java/nio/ByteBuffer"); + +/* NIODBG("%s", "..."); */ + + address_fid = (*env)->GetFieldID(env, bufferClass, "address", + "Lgnu/classpath/Pointer;"); + if (address_fid == NULL) + { + JCL_ThrowException(env, "java/lang/InternalError", + "Unable to find internal field"); + return; + } + + get_position_mid = get_method_id(env, bufferClass, "position", "()I"); + set_position_mid = get_method_id(env, bufferClass, "position", + "(I)Ljava/nio/Buffer;"); + get_limit_mid = get_method_id(env, bufferClass, "limit", "()I"); + set_limit_mid = get_method_id(env, bufferClass, "limit", + "(I)Ljava/nio/Buffer;"); + has_array_mid = get_method_id(env, byteBufferClass, "hasArray", "()Z"); + array_mid = get_method_id(env, byteBufferClass, "array", "()[B"); + array_offset_mid = get_method_id(env, byteBufferClass, "arrayOffset", "()I"); + + vm_channel_class = clazz; + thread_interrupted_mid = (*env)->GetStaticMethodID(env, clazz, + "isThreadInterrupted", + "()Z"); +} + +JNIEXPORT void JNICALL +Java_gnu_java_nio_VMChannel_setBlocking (JNIEnv *env, + jobject o __attribute__ ((__unused__)), + jint fd, + jboolean blocking) +{ + int opts; + +/* NIODBG("fd: %d; blocking: %d", fd, blocking); */ + + opts = fcntl(fd, F_GETFL); + if (opts < 0) + { + JCL_ThrowException(env, IO_EXCEPTION, + "Failed to get flags for file desriptor"); + return; + } + + if (blocking == JNI_TRUE) + opts &= ~(O_NONBLOCK); + else + opts |= O_NONBLOCK; + + opts = fcntl(fd, F_SETFL, opts); + + if (opts < 0) + { + JCL_ThrowException(env, IO_EXCEPTION, + "Failed to set flags for file desriptor"); + return; + } +} + +/* Return true if fd is in non-blocking mode. */ +static jboolean +is_non_blocking_fd(jint fd) +{ + int opts; + opts = fcntl(fd, F_GETFL); + if (opts == -1) + { + /* Assume blocking on error. */ + return 0; + } + return (opts & O_NONBLOCK) != 0; +} + +JNIEXPORT jint JNICALL +Java_gnu_java_nio_VMChannel_read__ILjava_nio_ByteBuffer_2 (JNIEnv *env, + jobject o __attribute__ ((__unused__)), + jint fd, + jobject bbuf) +{ +#ifdef HAVE_READ + jint len; + ssize_t result; + struct JCL_buffer buf; + int tmp_errno; + +/* NIODBG("fd: %d; bbuf: %p", fd, bbuf); */ + + if (JCL_init_buffer(env, &buf, bbuf) < 0) + { + /* TODO: Rethrown exception */ + JCL_ThrowException (env, IO_EXCEPTION, "Buffer initialisation failed"); + return -1; + } + + len = buf.limit - buf.position; + + if (len == 0) + { + JCL_release_buffer (env, &buf, bbuf, JNI_ABORT); + return 0; + } + + do + { + result = cpnio_read (fd, &(buf.ptr[buf.position + buf.offset]), len); + tmp_errno = errno; + } + while (result == -1 && errno == EINTR && ! JCL_thread_interrupted(env)); + errno = tmp_errno; + + if (result == 0) + { + result = -1; + buf.count = 0; + } + else if (result == -1) + { + buf.count = 0; + if (errno == EAGAIN) + { + if (is_non_blocking_fd(fd)) + { + /* Non-blocking */ + result = 0; + } + else + { + /* Read timeout on a socket with SO_RCVTIMEO != 0. */ + JCL_release_buffer(env, &buf, bbuf, JNI_ABORT); + JCL_ThrowException(env, SOCKET_TIMEOUT_EXCEPTION, "read timed out"); + return -1; + } + } + else if (errno == EBADF) /* Bad fd */ + { + JCL_release_buffer(env, &buf, bbuf, JNI_ABORT); + JCL_ThrowException (env, NON_READABLE_CHANNEL_EXCEPTION, + strerror(errno)); + return -1; + } + else if (EINTR == errno) /* read interrupted */ + { + JCL_release_buffer(env, &buf, bbuf, JNI_ABORT); + JCL_ThrowException(env, INTERRUPTED_IO_EXCEPTION, strerror (errno)); + return -1; + } + else + { + JCL_release_buffer(env, &buf, bbuf, JNI_ABORT); + JCL_ThrowException (env, IO_EXCEPTION, strerror(errno)); + return -1; + } + } + else + buf.count = result; + + JCL_release_buffer(env, &buf, bbuf, 0); + + return result; +#else + (void) fd; + (void) bbuf; + JCL_ThrowException (env, IO_EXCEPTION, "read not supported"); + return -1; +#endif /* HAVE_READ */ +} + +JNIEXPORT jint JNICALL +Java_gnu_java_nio_VMChannel_write__ILjava_nio_ByteBuffer_2 (JNIEnv *env, + jobject o __attribute__ ((__unused__)), + jint fd, + jobject bbuf) +{ +#ifdef HAVE_WRITE + jint len; + ssize_t result; + struct JCL_buffer buf; + int tmp_errno; + +/* NIODBG("fd: %d; bbuf: %p", fd, bbuf); */ + + if (JCL_init_buffer(env, &buf, bbuf) < 0) + { + /* TODO: Rethrown exception */ + JCL_ThrowException (env, IO_EXCEPTION, "Buffer initialisation failed"); + return -1; + } + + len = buf.limit - buf.position; + + if (len == 0) + { + JCL_release_buffer (env, &buf, bbuf, JNI_ABORT); + return 0; + } + + do + { + result = cpnio_write (fd, &(buf.ptr[buf.position + buf.offset]), len); + tmp_errno = errno; + } + while (result == -1 && errno == EINTR && ! JCL_thread_interrupted(env)); + errno = tmp_errno; + + buf.count = result; + + if (result == -1) + { + if (errno == EAGAIN) /* Non-blocking */ + { + result = 0; + } + else + { + JCL_release_buffer(env, &buf, bbuf, JNI_ABORT); + JCL_ThrowException(env, IO_EXCEPTION, strerror(errno)); + return -1; + } + } + + JCL_release_buffer(env, &buf, bbuf, JNI_ABORT); + + return result; +#else + (void) fd; + (void) bbuf; + JCL_ThrowException (env, IO_EXCEPTION, "write not supported"); + return -1; +#endif /* HAVE_WRITE */ +} + + +/* + * Implementation of a scattering read. Will use the appropriate + * vector based read call (currently readv on Linux). + * + * This has a limit to the number of buffers that will be read. It + * will not make muliple readv calls. This is to ensure that operations + * are atomic. Currently it is limited to 16 buffers. This is for + * compatibiliy with Sun. + */ +JNIEXPORT jlong JNICALL +Java_gnu_java_nio_VMChannel_readScattering (JNIEnv *env, + jobject o __attribute__ ((__unused__)), + jint fd, + jobjectArray bbufs, + jint offset, + jint length) +{ + jint i; +/* jboolean is_error = JNI_FALSE; */ +/* char *error_msg; */ + struct iovec buffers[JCL_IOV_MAX]; + struct JCL_buffer bi_list[JCL_IOV_MAX]; + ssize_t result; + jint vec_len = length < JCL_IOV_MAX ? length : JCL_IOV_MAX; + jlong bytes_read = 0; + int tmp_errno; + +/* NIODBG("fd: %d; bbufs: %p; offset: %d; length: %d", */ +/* fd, bbufs, offset, length); */ + + /* Build the vector of buffers to read into */ + for (i = 0; i < vec_len; i++) + { + struct JCL_buffer* buf; + jobject bbuf; + + buf = &bi_list[i]; + bbuf = (*env)->GetObjectArrayElement(env, bbufs, offset + i); + + JCL_init_buffer(env, buf, bbuf); + +/* JCL_print_buffer (env, buf); */ + + buffers[i].iov_base = &(buf->ptr[buf->position + buf->offset]); + buffers[i].iov_len = buf->limit - buf->position; + (*env)->DeleteLocalRef(env, bbuf); + } + + /* Work the scattering magic */ + do + { + result = cpnio_readv (fd, buffers, vec_len); + tmp_errno = errno; + } + while (result == -1 && errno == EINTR && ! JCL_thread_interrupted(env)); + errno = tmp_errno; + bytes_read = (jlong) result; + + /* Handle the response */ + if (result < 0) + { + if (errno == EAGAIN) + { + if (is_non_blocking_fd(fd)) + { + /* Non-blocking */ + result = 0; + } + else + { + /* Read timeout on a socket with SO_RCVTIMEO != 0. */ + JCL_cleanup_buffers(env, bi_list, vec_len, bbufs, offset, bytes_read); + JCL_ThrowException(env, SOCKET_TIMEOUT_EXCEPTION, "read timed out"); + return -1; + } + } + else if (errno == EBADF) /* Bad fd */ + { + JCL_cleanup_buffers(env, bi_list, vec_len, bbufs, offset, bytes_read); + JCL_ThrowException (env, NON_READABLE_CHANNEL_EXCEPTION, + strerror(errno)); + return -1; + } + else + { + JCL_cleanup_buffers(env, bi_list, vec_len, bbufs, offset, bytes_read); + JCL_ThrowException (env, IO_EXCEPTION, strerror(errno)); + return -1; + } + bytes_read = 0; + } + else if (result == 0) /* EOF */ + { + result = -1; + } + + JCL_cleanup_buffers(env, bi_list, vec_len, bbufs, offset, bytes_read); + + return (jlong) result; +} + + +/* + * Implementation of a gathering write. Will use the appropriate + * vector based read call (currently readv on Linux). + * + * This has a limit to the number of buffers that will be read. It + * will not make muliple readv calls. This is to ensure that operations + * are atomic. Currently it is limited to 16 buffers. This is for + * compatibiliy with Sun. + */ +JNIEXPORT jlong JNICALL +Java_gnu_java_nio_VMChannel_writeGathering (JNIEnv *env, + jobject o __attribute__ ((__unused__)), + jint fd, + jobjectArray bbufs, + jint offset, + jint length) +{ + int i; +/* jboolean is_error = JNI_FALSE; */ +/* char *error_msg; */ + struct iovec buffers[JCL_IOV_MAX]; + struct JCL_buffer bi_list[JCL_IOV_MAX]; + ssize_t result; + jint vec_len = length < JCL_IOV_MAX ? length : JCL_IOV_MAX; + jlong bytes_written; + int tmp_errno; + +/* NIODBG("fd: %d; bbufs: %p; offset: %d; length: %d", */ +/* fd, bbufs, offset, length); */ + + /* Build the vector of buffers to read into */ + for (i = 0; i < vec_len; i++) + { + struct JCL_buffer* buf; + jobject bbuf; + + buf = &bi_list[i]; + bbuf = (*env)->GetObjectArrayElement(env, bbufs, offset + i); + + JCL_init_buffer(env, buf, bbuf); + +/* JCL_print_buffer(env, buf); */ + + buffers[i].iov_base = &(buf->ptr[buf->position + buf->offset]); + buffers[i].iov_len = buf->limit - buf->position; + (*env)->DeleteLocalRef(env, bbuf); + } + + /* Work the gathering magic */ + do + { + result = cpnio_writev (fd, buffers, vec_len); + tmp_errno = errno; + } + while (result == -1 && tmp_errno == EINTR && ! JCL_thread_interrupted(env)); + errno = tmp_errno; + + bytes_written = (jlong) result; + + if (result < 0) + { + bytes_written = 0; + if (errno == EAGAIN) /* Non blocking */ + result = 0; + else if (errno == EBADF) /* Bad fd */ + { + JCL_cleanup_buffers(env, bi_list, vec_len, bbufs, offset, + bytes_written); + JCL_ThrowException (env, NON_WRITABLE_CHANNEL_EXCEPTION, + strerror(errno)); + return -1; + } + else + { + JCL_cleanup_buffers(env, bi_list, vec_len, bbufs, offset, + bytes_written); + JCL_ThrowException (env, IO_EXCEPTION, strerror(errno)); + return -1; + } + } + else if (result == 0) /* EOF?? Does this happen on a write */ + result = -1; + + JCL_cleanup_buffers(env, bi_list, vec_len, bbufs, offset, bytes_written); + return (jlong) result; +} + + +/* + * Class: gnu_java_nio_VMChannel + * Method: receive + * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;)I + */ +JNIEXPORT jint JNICALL +Java_gnu_java_nio_VMChannel_receive (JNIEnv *env, + jclass c __attribute__((unused)), + jint fd, jobject dst, jobject addrPort) +{ +#ifdef HAVE_RECVFROM + char *addrPortPtr = (*env)->GetDirectBufferAddress (env, addrPort); + struct JCL_buffer buf; +#ifdef HAVE_INET6 + struct sockaddr_in6 sock_storage; + struct sockaddr_in6 *sock6; + socklen_t slen = sizeof (struct sockaddr_in6); +#else + struct sockaddr_in sock_storage; + socklen_t slen = sizeof (struct sockaddr_in); +#endif /* HAVE_INET6 */ + struct sockaddr *sockaddr = (struct sockaddr *) &sock_storage; + struct sockaddr_in *sock4; + int ret; + jint result = -1; + + if (JCL_init_buffer (env, &buf, dst) == -1) + JCL_ThrowException (env, IO_EXCEPTION, "loading buffer failed"); + +#ifndef HAVE_MSG_WAITALL +#define MSG_WAITALL 0 +#endif + + ret = cpnio_recvfrom (fd, &(buf.ptr[buf.position + buf.offset]), + buf.limit - buf.position, MSG_WAITALL, + sockaddr, &slen); + + if (-1 == ret) + { + JCL_release_buffer (env, &buf, dst, JNI_ABORT); + if (EINTR == errno) + JCL_ThrowException (env, "java/io/InterruptedIOException", strerror (errno)); + else if (EAGAIN == errno) + { + /* If the socket is in blocking mode, our timeout expired. */ + int val = fcntl (fd, F_GETFL, 0); + if (val == -1) + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); + else if ((val & O_NONBLOCK) == 0) + JCL_ThrowException (env, "java/net/SocketTimeoutException", + "read timed out"); + } + else + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); + return 0; + } + + if (sockaddr->sa_family == AF_INET) + { + sock4 = (struct sockaddr_in *) sockaddr; + memcpy (addrPortPtr, &(sock4->sin_addr.s_addr), 4); + ;memcpy (addrPortPtr + 4, &(sock4->sin_port), 2); + result = 4; + } +#ifdef HAVE_INET6 + else if (sockaddr->sa_family == AF_INET6) + { + sock6 = (struct sockaddr_in6 *) sockaddr; + memcpy (addrPortPtr, &(sock6->sin6_addr.s6_addr), 16); + memcpy (addrPortPtr + 16, &(sock6->sin6_port), 2); + result = 16; + } +#endif /* HAVE_INET6 */ + else if (ret == 0) + { + result = 0; + } + else + { + JCL_ThrowException (env, "java/net/SocketException", + "unsupported address type returned"); + } + + buf.count += ret; + JCL_release_buffer (env, &buf, dst, 0); + return result; +#else + (void) fd; + (void) dst; + (void) addrPort; + JCL_ThrowException (env, IO_EXCEPTION, "recvfrom not supported"); +#endif /* HAVE_RECVFROM */ +} + + +/* + * Class: gnu_java_nio_VMChannel + * Method: send + * Signature: (Ljava/nio/ByteBuffer;[BI)I + */ +JNIEXPORT jint JNICALL +Java_gnu_java_nio_VMChannel_send (JNIEnv *env, + jclass c __attribute__((unused)), + int fd, jobject src, jbyteArray addr, jint port) +{ +#ifdef HAVE_SENDTO + struct sockaddr_in sockaddr; + jbyte *elems; + struct JCL_buffer buf; + int ret; + +/* NIODBG("fd: %d; src: %p; addr: %p; port: %d", */ +/* fd, src, addr, port); */ + + if (JCL_init_buffer (env, &buf, src) == -1) + { + JCL_ThrowException (env, IO_EXCEPTION, "loading buffer failed"); + return -1; + } + +/* JCL_print_buffer (env, &buf); */ + + elems = (*env)->GetByteArrayElements (env, addr, NULL); + + sockaddr.sin_family = AF_INET; + sockaddr.sin_addr.s_addr = *((uint32_t *) elems); + sockaddr.sin_port = htons (port); + + do + { + ret = cpnio_sendto (fd, &(buf.ptr[buf.position + buf.offset]), + buf.limit - buf.position, + 0, (const struct sockaddr *) &sockaddr, + sizeof (struct sockaddr_in)); + } + while (-1 == ret && EINTR == errno); + + (*env)->ReleaseByteArrayElements (env, addr, elems, JNI_ABORT); + + if (-1 == ret) + { + if (errno != EAGAIN) + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); + JCL_release_buffer (env, &buf, src, JNI_ABORT); + return 0; + } + + buf.count += ret; + JCL_release_buffer (env, &buf, src, JNI_ABORT); + return ret; +#else + (void) fd; + (void) src; + (void) addr; + (void) port; +#endif /* HAVE_SENDTO */ +} + + +/* + * Class: gnu_java_nio_VMChannel + * Method: send6 + * Signature: (Ljava/nio/ByteBuffer;[BI)I + */ +JNIEXPORT jint JNICALL +Java_gnu_java_nio_VMChannel_send6 (JNIEnv *env, + jclass c __attribute__((unused)), + int fd, jobject src, jbyteArray addr, jint port) +{ +#if defined(HAVE_SENDTO) && defined(HAVE_INET6) + struct sockaddr_in6 sockaddr; + jbyte *elems; + struct JCL_buffer buf; + int ret; + +/* NIODBG("fd: %d; src: %p; addr: %p; port: %d", */ +/* fd, src, addr, port); */ + + if (JCL_init_buffer (env, &buf, src) == -1) + { + JCL_ThrowException (env, IO_EXCEPTION, "loading buffer failed"); + return -1; + } + +/* JCL_print_buffer (env, &buf); */ + + elems = (*env)->GetByteArrayElements (env, addr, NULL); + + sockaddr.sin6_family = AF_INET6; + memcpy (&sockaddr.sin6_addr.s6_addr, elems, 16); + sockaddr.sin6_port = htons (port); + + do + { + ret = cpnio_sendto (fd, (const void *) (buf.ptr + buf.offset), + buf.limit - buf.position, + 0, (const struct sockaddr *) &sockaddr, + sizeof (struct sockaddr_in6)); + } + while (-1 == ret && EINTR == errno); + + (*env)->ReleaseByteArrayElements (env, addr, elems, JNI_ABORT); + + if (-1 == ret) + { + if (errno != EAGAIN) + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); + JCL_release_buffer (env, &buf, src, JNI_ABORT); + return 0; + } + + buf.count += ret; + JCL_release_buffer (env, &buf, src, JNI_ABORT); + return ret; +#else + (void) fd; + (void) src; + (void) addr; + (void) port; + JCL_ThrowException (env, IO_EXCEPTION, "IPv6 sendto not supported"); + return -1; +#endif /* HAVE_SENDTO && HAVE_INET6 */ +} + + +/* + * Class: gnu_java_nio_VMChannel + * Method: read + * Signature: (I)I + */ +JNIEXPORT jint JNICALL +Java_gnu_java_nio_VMChannel_read__I (JNIEnv *env, + jclass c __attribute__((unused)), + jint fd) +{ +#ifdef HAVE_READ + char in; + int ret; + int tmp_errno; + +/* NIODBG("fd: %d", fd); */ + + do + { + ret = cpnio_read (fd, &in, 1); + tmp_errno = errno; + } + while (ret == -1 && errno == EINTR && ! JCL_thread_interrupted(env)); + errno = tmp_errno; + + if (-1 == ret) + { + if (errno == EAGAIN && !is_non_blocking_fd(fd)) + { + /* Read timeout on a socket with SO_RCVTIMEO != 0. */ + JCL_ThrowException(env, SOCKET_TIMEOUT_EXCEPTION, "read timed out"); + } + else + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); + return -1; + } + + if (0 == ret) + return -1; + + return (in & 0xFF); +#else + (void) fd; + JCL_ThrowException (env, IO_EXCEPTION, "read not supported"); +#endif /* HAVE_READ */ +} + + +/* + * Class: gnu_java_nio_VMChannel + * Method: write + * Signature: (I)V + */ +JNIEXPORT void JNICALL +Java_gnu_java_nio_VMChannel_write__II (JNIEnv *env, + jclass c __attribute__((unused)), + jint fd, jint data) +{ +#ifdef HAVE_WRITE + char out = (char) data; + int ret; + int tmp_errno; + +/* NIODBG("fd: %d; data: %d", fd, data); */ + + do + { + ret = cpnio_write (fd, &out, 1); + tmp_errno = errno; + } + while (ret == -1 && errno == EINTR && ! JCL_thread_interrupted(env)); + errno = tmp_errno; + + if (-1 == ret) + JCL_ThrowException(env, IO_EXCEPTION, strerror (errno)); +#else + (void) fd; + (void) data; + JCL_ThrowException (env, IO_EXCEPTION, "write not supported"); +#endif /* HAVE_WRITE */ +} + + +/* + * Class: gnu_java_nio_VMChannel + * Method: socket + * Signature: (Z)I + */ +JNIEXPORT jint JNICALL +Java_gnu_java_nio_VMChannel_socket (JNIEnv *env, jclass clazz __attribute__((unused)), + jboolean stream) +{ +#ifdef HAVE_SOCKET + int ret; + + do + { + ret = cpnio_socket (AF_INET, stream ? SOCK_STREAM : SOCK_DGRAM, 0); + } + while (-1 == ret && EINTR == errno); + + if (ret == -1) + JCL_ThrowException (env, "java/net/SocketException", strerror (errno)); +/* NIODBG("created socket %d", ret); */ + + return ret; +#else + (void) stream; + JCL_ThrowException (env, IO_EXCEPTION, "socket not supported"); + return -1; +#endif /* HAVE_SOCKET */ +} + + +/* + * Class: gnu_java_nio_VMChannel + * Method: connect + * Signature: (I[BI)Z + */ +JNIEXPORT jboolean JNICALL +Java_gnu_java_nio_VMChannel_connect (JNIEnv *env, jclass clazz __attribute__((unused)), + jint fd, jbyteArray addr, jint port, jint timeout) +{ +#ifdef HAVE_CONNECT + struct sockaddr_in sockaddr; + struct timeval timeo; + int origflags = 0, flags; + jbyte *addr_elems; + int ret; + int tmpErrno; + + if ((*env)->GetArrayLength (env, addr) != 4) + { + JCL_ThrowException (env, SOCKET_EXCEPTION, + "expecting 4-byte address"); + return JNI_FALSE; + } + + if (timeout > 0) + { + timeo.tv_sec = timeout / 1000; + timeo.tv_usec = (timeout % 1000) * 1000; + origflags = fcntl (fd, F_GETFL, 0); + if (origflags == -1) + { + JCL_ThrowException (env, SOCKET_EXCEPTION, strerror (errno)); + return JNI_FALSE; + } + /* Set nonblocking mode, if not already set. */ + if (!(origflags & O_NONBLOCK)) + { + flags = origflags | O_NONBLOCK; + if (fcntl (fd, F_SETFL, flags) == -1) + { + JCL_ThrowException (env, SOCKET_EXCEPTION, strerror (errno)); + return JNI_FALSE; + } + } + } + + addr_elems = (*env)->GetByteArrayElements (env, addr, NULL); + + memset (&sockaddr, 0, sizeof (struct sockaddr_in)); + sockaddr.sin_family = AF_INET; + sockaddr.sin_port = htons (port); + sockaddr.sin_addr.s_addr = *((uint32_t *) addr_elems); + + + do + { + ret = cpnio_connect (fd, (struct sockaddr *) &sockaddr, + sizeof (struct sockaddr_in)); + tmpErrno = errno; + } + while (ret == -1 && errno == EINTR && ! JCL_thread_interrupted(env)); + errno = tmpErrno; + + (*env)->ReleaseByteArrayElements (env, addr, addr_elems, JNI_ABORT); + + /* If a timeout was specified, select on the file descriptor with + the timeout. */ + if (timeout > 0 && ret == -1) + { + /* Reset the non-blocking flag, if needed. */ + if (!(origflags & O_NONBLOCK)) + { + if (fcntl (fd, F_SETFL, origflags) == -1) + { + /* oops */ + JCL_ThrowException (env, SOCKET_EXCEPTION, strerror (errno)); + return JNI_FALSE; + } + } + if (EINPROGRESS == errno) + { + fd_set wrfds; + FD_ZERO(&wrfds); + FD_SET(fd, &wrfds); + ret = cpnio_select (fd + 1, NULL, &wrfds, NULL, &timeo); + if (ret == -1) + { + JCL_ThrowException (env, SOCKET_EXCEPTION, strerror (errno)); + return JNI_FALSE; + } + if (ret == 0) /* connect timed out */ + { + JCL_ThrowException (env, SOCKET_TIMEOUT_EXCEPTION, + "connect timed out"); + return JNI_FALSE; + } + return JNI_TRUE; /* Connected! */ + } + else if (ECONNREFUSED == errno) + { + JCL_ThrowException (env, CONNECT_EXCEPTION, + strerror (errno)); + return JNI_FALSE; + } + else + { + JCL_ThrowException (env, SOCKET_EXCEPTION, strerror (errno)); + return JNI_FALSE; + } + } + + if (ret == -1) + { + if (EINPROGRESS == errno) + return JNI_FALSE; + else if (ECONNREFUSED == errno) + { + JCL_ThrowException (env, CONNECT_EXCEPTION, + strerror (errno)); + return JNI_FALSE; + } + else + { + JCL_ThrowException (env, SOCKET_EXCEPTION, strerror (errno)); + return JNI_FALSE; + } + } + + return JNI_TRUE; +#else + (void) fd; + (void) addr; + (void) port; + (void) timeout; + JCL_ThrowException (env, SOCKET_EXCEPTION, "connect not supported"); + return JNI_FALSE; +#endif /* HAVE_CONNECT */ +} + + +/* + * Class: gnu_java_nio_VMChannel + * Method: connect6 + * Signature: (I[BI)Z + */ +JNIEXPORT jboolean JNICALL +Java_gnu_java_nio_VMChannel_connect6 (JNIEnv *env, jclass clazz __attribute__((unused)), + jint fd, jbyteArray addr, jint port, int timeout) +{ +#if defined(HAVE_CONNECT) && defined(HAVE_INET6) + struct sockaddr_in6 sockaddr; + struct timeval timeo; + int flags, origflags = 0; + jbyte *addr_elems; + int ret; + + if (timeout > 0) + { + timeo.tv_sec = timeout / 1000; + timeo.tv_usec = (timeout % 1000) * 1000; + origflags = fcntl (fd, F_GETFL, 0); + if (origflags == -1) + { + JCL_ThrowException (env, SOCKET_EXCEPTION, strerror (errno)); + return JNI_FALSE; + } + /* Set nonblocking mode, if not already set. */ + if (!(origflags & O_NONBLOCK)) + { + flags = origflags | O_NONBLOCK; + if (fcntl (fd, F_SETFL, flags) == -1) + { + JCL_ThrowException (env, SOCKET_EXCEPTION, strerror (errno)); + return JNI_FALSE; + } + } + } + + addr_elems = (*env)->GetByteArrayElements (env, addr, NULL); + + memset (&sockaddr, 0, sizeof (struct sockaddr_in6)); + sockaddr.sin6_family = AF_INET6; + sockaddr.sin6_port = htons (port); + memcpy (&sockaddr.sin6_addr.s6_addr, addr_elems, 16); + + ret = cpnio_connect (fd, (struct sockaddr *) &sockaddr, + sizeof (struct sockaddr_in6)); + + (*env)->ReleaseByteArrayElements (env, addr, addr_elems, JNI_ABORT); + + /* If a timeout was specified, select on the file descriptor with + the timeout. */ + if (timeout > 0 && ret == -1) + { + /* Reset the non-blocking flag, if needed. */ + if (!(origflags & O_NONBLOCK)) + { + if (fcntl (fd, F_SETFL, origflags) == -1) + { + /* oops */ + JCL_ThrowException (env, SOCKET_EXCEPTION, strerror (errno)); + return JNI_FALSE; + } + } + if (EINPROGRESS == errno) + { + fd_set wrfds; + FD_ZERO(&wrfds); + FD_SET(fd, &wrfds); + ret = cpnio_select (fd + 1, NULL, &wrfds, NULL, &timeo); + if (ret == -1) + { + JCL_ThrowException (env, SOCKET_EXCEPTION, strerror (errno)); + return JNI_FALSE; + } + if (ret == 0) /* connect timed out */ + { + JCL_ThrowException (env, SOCKET_TIMEOUT_EXCEPTION, + "connect timed out"); + return JNI_FALSE; + } + return JNI_TRUE; /* Connected! */ + } + else if (ECONNREFUSED == errno) + { + JCL_ThrowException (env, CONNECT_EXCEPTION, + strerror (errno)); + return JNI_FALSE; + } + else + { + JCL_ThrowException (env, SOCKET_EXCEPTION, strerror (errno)); + return JNI_FALSE; + } + } + + if (ret == -1) + { + if (EAGAIN == errno) + return JNI_FALSE; + else if (ECONNREFUSED == errno) + { + JCL_ThrowException (env, CONNECT_EXCEPTION, + strerror (errno)); + return JNI_FALSE; + } + else + { + JCL_ThrowException (env, SOCKET_EXCEPTION, strerror (errno)); + return JNI_FALSE; + } + } + + return JNI_TRUE; +#else + (void) fd; + (void) addr; + (void) port; + (void) timeout; + JCL_ThrowException (env, SOCKET_EXCEPTION, "IPv6 connect not supported"); + return JNI_FALSE; +#endif /* HAVE_CONNECT && HAVE_INET6 */ +} + + +/* + * Class: gnu_java_nio_VMChannel + * Method: getsockname + * Signature: (ILjava/nio/ByteBuffer;)I + */ +JNIEXPORT jint JNICALL +Java_gnu_java_nio_VMChannel_getsockname (JNIEnv *env, jclass clazz __attribute__((unused)), + jint fd, jobject name) +{ +#ifdef HAVE_GETSOCKNAME +#ifdef HAVE_INET6 + struct sockaddr_in6 *addr6; + struct sockaddr_in6 sock_storage; + socklen_t socklen = sizeof (struct sockaddr_in6); +#else + struct sockaddr_in sock_storage; + socklen_t socklen = sizeof (struct sockaddr_in); +#endif /* HAVE_INET6 */ + + struct sockaddr *sockaddr = (struct sockaddr *) &sock_storage; + struct sockaddr_in *addr4; + int ret; + char *nameptr = (*env)->GetDirectBufferAddress (env, name); + + ret = getsockname (fd, sockaddr, &socklen); + if (ret == -1) + { + JCL_ThrowException (env, "java/net/SocketException", strerror (errno)); + return 0; + } + + if (sockaddr->sa_family == AF_INET) + { + addr4 = (struct sockaddr_in *) sockaddr; + memcpy (nameptr, &(addr4->sin_addr.s_addr), 4); + memcpy (nameptr + 4, &(addr4->sin_port), 2); + return 4; + } + +#ifdef HAVE_INET6 + /* IPv6 */ + if (sockaddr->sa_family == AF_INET6) + { + addr6 = (struct sockaddr_in6 *) sockaddr; + memcpy (nameptr, &(addr6->sin6_addr.s6_addr), 16); + memcpy (nameptr + 16, &(addr6->sin6_port), 2); + return 16; + } +#endif /* HAVE_INET6 */ + JCL_ThrowException (env, IO_EXCEPTION, "unsupported address format"); + return -1; +#else + (void) fd; + (void) name; + JCL_ThrowException (env, IO_EXCEPTION, "getsockname not supported"); + return -1; +#endif /* HAVE_GETSOCKNAME */ +} + + +/* + * Class: gnu_java_nio_VMChannel + * Method: getpeername + * Signature: (ILjava/nio/ByteBuffer;)I + */ +JNIEXPORT jint JNICALL +Java_gnu_java_nio_VMChannel_getpeername (JNIEnv *env, jclass clazz __attribute__((unused)), + jint fd, jobject name) +{ +#ifdef HAVE_GETPEERNAME +#ifdef HAVE_INET6 + struct sockaddr_in6 *addr6; + struct sockaddr_in6 sock_storage; + socklen_t socklen = sizeof (struct sockaddr_in6); +#else + struct sockaddr_in sock_storage; + socklen_t socklen = sizeof (struct sockaddr_in); +#endif /* HAVE_INET6 */ + + struct sockaddr *sockaddr = (struct sockaddr *) &sock_storage; + struct sockaddr_in *addr4; + int ret; + char *nameptr = (*env)->GetDirectBufferAddress (env, name); + + ret = getpeername (fd, sockaddr, &socklen); + if (ret == -1) + { + if (ENOTCONN != errno) + JCL_ThrowException (env, "java/net/SocketException", strerror (errno)); + return 0; + } + + if (sockaddr->sa_family == AF_INET) + { + addr4 = (struct sockaddr_in *) sockaddr; + memcpy (nameptr, &(addr4->sin_addr.s_addr), 4); + memcpy (nameptr + 4, &(addr4->sin_port), 2); + return 4; + } +#ifdef HAVE_INET6 + else if (sockaddr->sa_family == AF_INET6) + { + addr6 = (struct sockaddr_in6 *) sockaddr; + memcpy (nameptr, &(addr6->sin6_addr.s6_addr), 16); + memcpy (nameptr + 16, &(addr6->sin6_port), 2); + return 16; + } +#endif /* HAVE_INET6 */ + + JCL_ThrowException (env, "java/net/SocketException", + "unsupported address type"); + return -1; +#else + (void) fd; + (void) name; + JCL_ThrowException (env, IO_EXCEPTION, "getpeername not supported"); + return -1; +#endif /* HAVE_GETPEERNAME */ +} + + +/* + * Class: gnu_java_nio_VMChannel + * Method: accept + * Signature: (I)I + */ +JNIEXPORT jint JNICALL +Java_gnu_java_nio_VMChannel_accept (JNIEnv *env, + jclass c __attribute__((unused)), + jint fd) +{ +#ifdef HAVE_ACCEPT + int ret; + int tmp_errno = 0; + +#ifdef HAVE_INET6 + struct sockaddr_in6 addr; + socklen_t alen = sizeof (struct sockaddr_in6); +#else + struct sockaddr_in addr; + socklen_t alen = sizeof (struct sockaddr_in); +#endif /* HAVE_INET6 */ + + do + { + ret = cpnio_accept (fd, (struct sockaddr *) &addr, &alen); + tmp_errno = errno; + + if (ret == -1) + switch (tmp_errno) + { + case EINTR: + /* Check if interrupted by Thread.interrupt(). If not then some + * other unrelated signal interrupted the system function and + * we should start over again. + */ + if (JCL_thread_interrupted(env)) + { + JCL_ThrowException (env, "java/net/SocketException", strerror (tmp_errno)); + return -1; + } + break; +#if defined(EWOULDBLOCK) && defined(EAGAIN) && EWOULDBLOCK != EAGAIN + case EWOULDBLOCK: +#endif + case EAGAIN: + if (!is_non_blocking_fd(fd)) + { + JCL_ThrowException(env, SOCKET_TIMEOUT_EXCEPTION, "Accept timed out"); + } + /* Socket in non-blocking mode and no pending connection. */ + return -1; + default: + JCL_ThrowException (env, "java/net/SocketException", strerror (tmp_errno)); + return -1; + } + else + break; + } + while (1); + + cpio_closeOnExec(ret); + + return ret; +#else + (void) fd; + JCL_ThrowException (env, IO_EXCEPTION, "accept not supported"); + return -1; +#endif /* HAVE_ACCEPT */ +} + + + +/* + * Class: gnu_java_nio_VMChannel + * Method: disconnect + * Signature: (I)V + */ +JNIEXPORT void JNICALL +Java_gnu_java_nio_VMChannel_disconnect (JNIEnv *env, + jclass c __attribute__((unused)), + jint fd) +{ + struct sockaddr sockaddr; + + sockaddr.sa_family = AF_UNSPEC; + if (connect (fd, &sockaddr, sizeof (struct sockaddr)) == -1) + { + /* The expected error for a successful disconnect is EAFNOSUPPORT. */ + if (errno != EAFNOSUPPORT) + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); + } +} + + +/* + * Class: gnu_java_nio_VMChannel + * Method: close + * Signature: (I)V + */ +JNIEXPORT void JNICALL +Java_gnu_java_nio_VMChannel_close (JNIEnv *env, + jclass c __attribute__((unused)), + jint fd) +{ + if (close (fd) == -1) + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); +} + + +/* + * Class: gnu_java_nio_VMChannel + * Method: available + * Signature: (I)I + */ +JNIEXPORT jint JNICALL +Java_gnu_java_nio_VMChannel_available (JNIEnv *env, + jclass c __attribute__((unused)), + jint fd) +{ +#if defined (FIONREAD) + + jint avail = 0; + +#if defined(ENOTTY) && defined(HAVE_FSTAT) + struct stat statBuffer; + off_t n; +#endif + +/* NIODBG("fd: %d", fd); */ + if (ioctl (fd, FIONREAD, &avail) == -1) + { +#if defined(ENOTTY) && defined(HAVE_FSTAT) + if (errno == ENOTTY) + { + if ((fstat (fd, &statBuffer) == 0) && S_ISREG (statBuffer.st_mode)) + { + n = lseek (fd, 0, SEEK_CUR); + if (n != -1) + { + avail = statBuffer.st_size - n; + return avail; + } + } + } +#endif + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); + } +/* NIODBG("avail: %d", avail); */ + + return avail; + +#elif defined(HAVE_FSTAT) + + jint avail = 0; + + struct stat statBuffer; + off_t n; + + if ((fstat (fd, &statBuffer) == 0) && S_ISREG (statBuffer.st_mode)) + { + n = lseek (fd, 0, SEEK_CUR); + if (n != -1) + { + avail = statBuffer.st_size - n; + return avail; + } + } + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); + +#elif defined(HAVE_SELECT) + + jint avail = 0; + fd_set filedescriptset; + struct timeval tv; + + FD_ZERO (&filedescriptset); + FD_SET (fd,&filedescriptset); + memset (&tv, 0, sizeof(tv)); + + switch (select (fd+1, &filedescriptset, NULL, NULL, &tv)) + { + case -1: + break; + case 0: + avail = 0; + return avail; + default: + avail = 1; + return avail; + } + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); + +#else + + JCL_ThrowException (env, IO_EXCEPTION, "No native method for available"); + +#endif +} + + +enum FileChannel_mode { + CPNIO_READ = 1, + CPNIO_WRITE = 2, + CPNIO_APPEND = 4, + CPNIO_EXCL = 8, + CPNIO_SYNC = 16, + CPNIO_DSYNC = 32 +}; + + +/* + * Class: gnu_java_nio_VMChannel + * Method: open + * Signature: (Ljava/lang/String;I)I + */ +JNIEXPORT jint JNICALL +Java_gnu_java_nio_VMChannel_open (JNIEnv *env, + jclass c __attribute__((unused)), + jstring path, jint mode) +{ + int nmode = 0; + int ret; + const char *npath; + + if ((mode & CPNIO_READ) && (mode & CPNIO_WRITE)) + nmode = O_RDWR; + else if (mode & CPNIO_WRITE) + nmode = O_WRONLY; + else + nmode = O_RDONLY; + + nmode = (nmode + | ((nmode == O_RDWR || nmode == O_WRONLY) ? O_CREAT : 0) + | ((mode & CPNIO_APPEND) ? O_APPEND : + ((nmode == O_WRONLY) ? O_TRUNC : 0)) + | ((mode & CPNIO_EXCL) ? O_EXCL : 0) + | ((mode & CPNIO_SYNC) ? O_SYNC : 0)); + + npath = JCL_jstring_to_cstring (env, path); + +/* NIODBG("path: %s; mode: %x", npath, nmode); */ + + ret = open (npath, nmode, 0666); + +/* NIODBG("ret: %d\n", ret); */ + + JCL_free_cstring (env, path, npath); + + if (-1 == ret) + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); + + return ret; +} + + +/* + * Class: gnu_java_nio_VMChannel + * Method: position + * Signature: (I)J + */ +JNIEXPORT jlong JNICALL +Java_gnu_java_nio_VMChannel_position (JNIEnv *env, + jclass c __attribute__((unused)), + jint fd) +{ +#ifdef HAVE_LSEEK + off_t ret; + + ret = lseek (fd, 0, SEEK_CUR); + + if (-1 == ret) + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); + + return (jlong) ret; +#else + JCL_ThrowException (env, IO_EXCEPTION, "position not supported"); + return -1; +#endif /* HAVE_LSEEK */ +} + + +/* + * Class: gnu_java_nio_VMChannel + * Method: seek + * Signature: (IJ)V + */ +JNIEXPORT void JNICALL +Java_gnu_java_nio_VMChannel_seek (JNIEnv *env, + jclass c __attribute__((unused)), + jint fd, jlong pos) +{ +#ifdef HAVE_LSEEK + if (lseek (fd, (off_t) pos, SEEK_SET) == -1) + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); +#else + JCL_ThrowException (env, IO_EXCEPTION, "seek not supported"); +#endif /* HAVE_LSEEK */ +} + + +/* + * Class: gnu_java_nio_VMChannel + * Method: truncate + * Signature: (IJ)V + */ +JNIEXPORT void JNICALL +Java_gnu_java_nio_VMChannel_truncate (JNIEnv *env, + jclass c __attribute__((unused)), + jint fd, jlong len) +{ +#if defined(HAVE_FTRUNCATE) && defined(HAVE_LSEEK) + off_t pos = lseek (fd, 0, SEEK_CUR); + if (pos == -1) + { + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); + return; + } + if (ftruncate (fd, (off_t) len) == -1) + { + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); + return; + } + if (pos > len) + { + if (lseek (fd, len, SEEK_SET) == -1) + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); + } +#else + JCL_ThrowException (env, IO_EXCEPTION, "truncate not supported"); +#endif /* HAVE_FTRUNCATE && HAVE_LSEEK */ +} + + +/* + * Class: gnu_java_nio_VMChannel + * Method: lock + * Signature: (IJJZZ)Z + */ +JNIEXPORT jboolean JNICALL +Java_gnu_java_nio_VMChannel_lock (JNIEnv *env, + jclass c __attribute__((unused)), + jint fd, jlong pos, jlong len, + jboolean shared, jboolean wait) +{ +#if HAVE_FCNTL + struct flock fl; + + fl.l_start = (off_t) pos; + /* Long.MAX_VALUE means lock everything possible starting at pos. */ + if (len == 9223372036854775807LL) + fl.l_len = 0; + else + fl.l_len = (off_t) len; + fl.l_pid = getpid (); + fl.l_type = (shared ? F_RDLCK : F_WRLCK); + fl.l_whence = SEEK_SET; + + if (cpnio_fcntl (fd, (wait ? F_SETLKW : F_SETLK), (long) &fl) == -1) + { + if (errno != EAGAIN) + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); + return JNI_FALSE; + } + + return JNI_TRUE; +#else + JCL_ThrowException (env, IO_EXCEPTION, "lock not supported"); + return JNI_FALSE; +#endif /* HAVE_FCNTL */ +} + +/* + * Class: gnu_java_nio_VMChannel + * Method: unlock + * Signature: (IJJ)V + */ +JNIEXPORT void JNICALL +Java_gnu_java_nio_VMChannel_unlock (JNIEnv *env, + jclass c __attribute__((unused)), + jint fd, jlong pos, jlong len) +{ +#if HAVE_FCNTL + struct flock fl; + + fl.l_start = (off_t) pos; + fl.l_len = (off_t) len; + fl.l_pid = getpid (); + fl.l_type = F_UNLCK; + fl.l_whence = SEEK_SET; + + if (cpnio_fcntl (fd, F_SETLK, (long) &fl) == -1) + { + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); + } +#else + JCL_ThrowException (env, IO_EXCEPTION, "unlock not supported"); +#endif /* HAVE_FCNTL */ +} + +/* + * Class: gnu_java_nio_VMChannel + * Method: size + * Signature: (I)J + */ +JNIEXPORT jlong JNICALL +Java_gnu_java_nio_VMChannel_size (JNIEnv *env, + jclass c __attribute__((unused)), + jint fd) +{ +#ifdef HAVE_FSTAT + struct stat st; + + if (fstat (fd, &st) == -1) + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); + + return (jlong) st.st_size; +#else + JCL_ThrowException (env, IO_EXCEPTION, "size not supported"); + return 0; +#endif +} + +/* + * Class: gnu_java_nio_VMChannel + * Method: map + * Signature: (ICJI)Lgnu/classpath/Pointer; + */ +JNIEXPORT jobject JNICALL +Java_gnu_java_nio_VMChannel_map (JNIEnv *env, + jclass clazz __attribute__((unused)), + jint fd, jchar mode, jlong position, jint size) +{ +#ifdef HAVE_MMAP + jclass MappedByteBufferImpl_class; + jmethodID MappedByteBufferImpl_init = NULL; + jobject Pointer_instance; + volatile jobject buffer; + long pagesize; + int prot, flags; + void *p; + void *address; + +/* NIODBG("fd: %d; mode: %x; position: %lld; size: %d", */ +/* fd, mode, position, size); */ + + /* FIXME: should we just assume we're on an OS modern enough to + have 'sysconf'? And not check for 'getpagesize'? */ +#if defined(HAVE_GETPAGESIZE) + pagesize = getpagesize (); +#elif defined(HAVE_SYSCONF) + pagesize = sysconf (_SC_PAGESIZE); +#else + JCL_ThrowException (env, IO_EXCEPTION, + "can't determine memory page size"); + return NULL; +#endif /* HAVE_GETPAGESIZE/HAVE_SYSCONF */ + + if ((*env)->ExceptionOccurred (env)) + { + return NULL; + } + + prot = PROT_READ; + if (mode == '+' || mode == 'c') + { + /* When writing we need to make sure the file is big enough, + otherwise the result of mmap is undefined. */ + struct stat st; + if (fstat (fd, &st) == -1) + { + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); + return NULL; + } + if (position + size > st.st_size) + { + if (ftruncate(fd, position + size) == -1) + { + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); + return NULL; + } + } + prot |= PROT_WRITE; + } + + flags = (mode == 'c' ? MAP_PRIVATE : MAP_SHARED); + p = mmap (NULL, (size_t) ALIGN_UP (size, pagesize), prot, flags, + fd, ALIGN_DOWN (position, pagesize)); + if (p == MAP_FAILED) + { + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); + return NULL; + } + + /* Unalign the mapped value back up, since we aligned offset + down to a multiple of the page size. */ + address = (void *) ((char *) p + (position % pagesize)); + + Pointer_instance = JCL_NewRawDataObject(env, address); + + MappedByteBufferImpl_class = (*env)->FindClass (env, + "java/nio/MappedByteBufferImpl"); + if (MappedByteBufferImpl_class != NULL) + { + MappedByteBufferImpl_init = + (*env)->GetMethodID (env, MappedByteBufferImpl_class, + "", "(Lgnu/classpath/Pointer;IZ)V"); + } + + if ((*env)->ExceptionOccurred (env)) + { + munmap (p, ALIGN_UP (size, pagesize)); + return NULL; + } + if (MappedByteBufferImpl_init == NULL) + { + JCL_ThrowException (env, "java/lang/InternalError", + "could not get MappedByteBufferImpl constructor"); + munmap (p, ALIGN_UP (size, pagesize)); + return NULL; + } + + buffer = (*env)->NewObject (env, MappedByteBufferImpl_class, + MappedByteBufferImpl_init, Pointer_instance, + (jint) size, mode == 'r'); + return buffer; +#else + (void) fd; + (void) mode; + (void) position; + (void) size; + JCL_ThrowException (env, IO_EXCEPTION, + "memory-mapped files not implemented"); + return 0; +#endif /* HAVE_MMAP */ +} + +/* + * Class: gnu_java_nio_VMChannel + * Method: flush + * Signature: (IZ)Z + */ +JNIEXPORT jboolean JNICALL +Java_gnu_java_nio_VMChannel_flush (JNIEnv *env, + jclass c __attribute__((unused)), + jint fd, jboolean metadata __attribute__((unused))) +{ +#ifdef HAVE_FSYNC + /* XXX blocking? */ + if (fsync (fd) == -1) + { + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); + return JNI_FALSE; + } + return JNI_TRUE; +#else + JCL_ThrowException (env, IO_EXCEPTION, "flush not implemented"); + return JNI_TRUE; +#endif /* HAVE_FSYNC */ +} + + +#ifdef __cplusplus +} +#endif diff --git a/libjava/classpath/native/jni/java-nio/gnu_java_nio_VMPipe.c b/libjava/classpath/native/jni/java-nio/gnu_java_nio_VMPipe.c new file mode 100644 index 000000000..cbaaa0834 --- /dev/null +++ b/libjava/classpath/native/jni/java-nio/gnu_java_nio_VMPipe.c @@ -0,0 +1,83 @@ +/* gnu_java_nio_VMPipe.c - Native methods for PipeImpl class + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#ifdef HAVE_CONFIG_H +#include +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include + +#include +#include + +#include "gnu_java_nio_VMPipe.h" + +#define IO_EXCEPTION "java/io/IOException" + +/* + * Class: gnu_java_nio_VMPipe + * Method: pipe0 + * Signature: ()[I + */ +JNIEXPORT jintArray JNICALL +Java_gnu_java_nio_VMPipe_pipe0 (JNIEnv *env, + jclass c __attribute__((unused))) +{ + int fd[2]; + jintArray array; + jint* elem; + int ret; + + /* FIXME: autoconf this? */ + ret = pipe (fd); + + if (ret == -1) + { + JCL_ThrowException (env, "java/io/IOException", strerror (errno)); + return NULL; + } + + array = (*env)->NewIntArray (env, 2); + elem = (*env)->GetIntArrayElements (env, array, NULL); + elem[0] = fd[0]; + elem[1] = fd[1]; + (*env)->ReleaseIntArrayElements (env, array, elem, 0); + return array; +} diff --git a/libjava/classpath/native/jni/java-nio/gnu_java_nio_VMSelector.c b/libjava/classpath/native/jni/java-nio/gnu_java_nio_VMSelector.c new file mode 100644 index 000000000..19a6f244d --- /dev/null +++ b/libjava/classpath/native/jni/java-nio/gnu_java_nio_VMSelector.c @@ -0,0 +1,303 @@ +/* gnu_java_nio_VMSelector.c - Native methods for SelectorImpl class + Copyright (C) 2004, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include "config.h" + +/* needs to be included on OSX before */ +#if defined(HAVE_SYS_TYPES_H) +#include +#endif +#if defined(HAVE_SYS_SELECT_H) +#include +#endif +#include + +#include + +#include + +#include +#include + +#include "gnu_java_nio_VMSelector.h" + +/* Amount of characters in the error message buffer for strerror_r. */ +#define BUF_SIZE 250 + +void helper_put_filedescriptors (JNIEnv *, jintArray, fd_set *, int *); + +void helper_get_filedescriptors (JNIEnv *, jintArray *, fd_set *); + +void helper_reset (JNIEnv *, jintArray *); + +int +helper_select (JNIEnv *, jclass, jmethodID, + int, fd_set *, fd_set *, fd_set *, struct timeval *); + +void +helper_put_filedescriptors (JNIEnv * env, jintArray fdArray, fd_set * fds, + int *max_fd) +{ + jint *tmpFDArray = (*env)->GetIntArrayElements (env, fdArray, 0); + int size = (*env)->GetArrayLength (env, fdArray); + int index, fd; + + for (index = 0; index < size; index++) + { + fd = tmpFDArray[index]; + + if (fd > 0) + { + FD_SET (tmpFDArray[index], fds); + + if (tmpFDArray[index] > (*max_fd)) + (*max_fd) = tmpFDArray[index]; + } + } +} + +void +helper_get_filedescriptors (JNIEnv * env, jintArray * fdArray, fd_set * fds) +{ + jint *tmpFDArray = (*env)->GetIntArrayElements (env, fdArray, 0); + int size = (*env)->GetArrayLength (env, fdArray); + int index, fd; + + for (index = 0; index < size; index++) + { + fd = tmpFDArray[index]; + if (fd < 0 || !FD_ISSET (fd, fds)) + tmpFDArray[index] = 0; + } +} + +void +helper_reset (JNIEnv * env, jintArray * fdArray) +{ + jint *tmpFDArray = (*env)->GetIntArrayElements (env, fdArray, 0); + int size = (*env)->GetArrayLength (env, fdArray); + int index; + + for (index = 0; index < size; index++) + tmpFDArray[index] = 0; +} + +/* A wrapper for select() which ignores EINTR. + * Taken from gclib's posix.cc + */ +int +helper_select (JNIEnv * env, jclass thread_class, + jmethodID thread_interrupted, int n, fd_set * readfds, + fd_set * writefds, fd_set * exceptfds, struct timeval *timeout) +{ +#ifdef HAVE_SYS_SELECT_H + /* If we have a timeout, compute the absolute ending time. */ + struct timeval end, delay, after; + int r; + + if (timeout) + { + gettimeofday (&end, NULL); + + end.tv_usec += timeout->tv_usec; + + if (end.tv_usec >= 1000000) + { + ++end.tv_sec; + end.tv_usec -= 1000000; + } + + end.tv_sec += timeout->tv_sec; + delay = *timeout; + } + else + { + /* Placate compiler. */ + delay.tv_sec = delay.tv_usec = 0; + } + + while (1) + { + r = select (n, readfds, writefds, exceptfds, timeout ? &delay : NULL); + + if (r < 0 && errno != EINTR) + return -errno; + else if (r >= 0) + return r; + + /* Here we know we got EINTR. */ + if ((*env)-> + CallStaticBooleanMethod (env, thread_class, thread_interrupted)) + { + return -EINTR; + } + + if (timeout) + { + gettimeofday (&after, NULL); + + /* Now compute new timeout argument. */ + delay.tv_usec = end.tv_usec - after.tv_usec; + delay.tv_sec = end.tv_sec - after.tv_sec; + + if (delay.tv_usec < 0) + { + --delay.tv_sec; + delay.tv_usec += 1000000; + } + + if (delay.tv_sec < 0) + { + /* We assume that the user wants a valid select() call + * more than precise timing. So if we get a series of + * EINTR we just keep trying with delay 0 until we get a + * valid result. + */ + delay.tv_sec = 0; + } + } + } +#else /* HAVE_SYS_SELECT_H */ + return 0; +#endif + +} + +JNIEXPORT jint JNICALL +Java_gnu_java_nio_VMSelector_select (JNIEnv * env, + jclass obj __attribute__ ((__unused__)), + jintArray read, + jintArray write, + jintArray except, jlong timeout) +{ + jint result; + jclass thread_class = (*env)->FindClass (env, "java/lang/Thread"); + jmethodID thread_current_thread = + (*env)->GetStaticMethodID (env, thread_class, "currentThread", + "()Ljava/lang/Thread;"); + jmethodID thread_interrupt = + (*env)->GetMethodID (env, thread_class, "interrupt", "()V"); + jmethodID thread_interrupted = + (*env)->GetStaticMethodID (env, thread_class, "interrupted", "()Z"); + jobject current_thread; + int max_fd = 0; + fd_set read_fds; + fd_set write_fds; + fd_set except_fds; + struct timeval real_time_data; + struct timeval *time_data = NULL; + char *message; + + /* If a legal timeout value isn't given, use NULL. + * This means an infinite timeout. The specification + * also says that a zero timeout should be treated + * as infinite. Otherwise (if the timeout value is legal), + * fill our timeval struct and use it for the select. + */ + if (timeout > 0) + { + real_time_data.tv_sec = timeout / 1000; + real_time_data.tv_usec = (timeout % 1000) * 1000; + time_data = &real_time_data; + } + + /* Reset all fd_set structures */ + FD_ZERO (&read_fds); + FD_ZERO (&write_fds); + FD_ZERO (&except_fds); + + /* Fill the fd_set data structures for the _Jv_select() call. */ + helper_put_filedescriptors (env, read, &read_fds, &max_fd); + helper_put_filedescriptors (env, write, &write_fds, &max_fd); + helper_put_filedescriptors (env, except, &except_fds, &max_fd); + + /* Actually do the select */ + result = + helper_select (env, thread_class, thread_interrupted, max_fd + 1, + &read_fds, &write_fds, &except_fds, time_data); + + if (result == -EINTR) + { + /* The behavior of JRE 1.4.1 is that no exception is thrown + * when the thread is interrupted, but the thread's interrupt + * status is set. Clear all of our select sets and return 0, + * indicating that nothing was selected. + */ + current_thread = + (*env)->CallStaticObjectMethod (env, thread_class, + thread_current_thread); + (*env)->CallVoidMethod (env, current_thread, thread_interrupt); + + helper_reset (env, read); + helper_reset (env, write); + helper_reset (env, except); + + return 0; + } + + if (result < 0) + { +#if defined(HAVE_STRERROR_R) + char message_buf[BUF_SIZE+1]; + int errorcode = -result; + + if (strerror_r (errorcode, message_buf, BUF_SIZE)) + { + /* This would mean that message_buf was to small + * to hold the error message. + */ + JCL_ThrowException (env, "java/lang/InternalError", + "Not enough space in message buffer."); + return 0; + } + + message = message_buf; +#else + message = strerror(errno); +#endif + + JCL_ThrowException (env, "java/io/IOException", message); + return 0; + } + + /* Set the file descriptors according to the values returned from select(). */ + helper_get_filedescriptors (env, read, &read_fds); + helper_get_filedescriptors (env, write, &write_fds); + helper_get_filedescriptors (env, except, &except_fds); + + return result; +} diff --git a/libjava/classpath/native/jni/java-nio/gnu_java_nio_charset_iconv_IconvDecoder.c b/libjava/classpath/native/jni/java-nio/gnu_java_nio_charset_iconv_IconvDecoder.c new file mode 100644 index 000000000..248a948c3 --- /dev/null +++ b/libjava/classpath/native/jni/java-nio/gnu_java_nio_charset_iconv_IconvDecoder.c @@ -0,0 +1,208 @@ +/* gnu_java_nio_charset_iconv_IconvDecoder.c -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include + +#include +#include +#include + +#if defined(HAVE_ICONV) +#include +#endif + +#include "gnu_java_nio_charset_iconv_IconvDecoder.h" + +#if defined(HAVE_ICONV) +static void createRawData (JNIEnv * env, jobject obj, void *ptr); +static void *getData (JNIEnv * env, jobject obj); + +static jfieldID infid = NULL; +static jfieldID outfid = NULL; +#endif + +/* Union used for type punning. */ +union char_union +{ + jbyte **jb; + jchar **jc; + char **c; +}; + +JNIEXPORT void JNICALL +Java_gnu_java_nio_charset_iconv_IconvDecoder_openIconv (JNIEnv * env UNUSED, + jobject obj UNUSED, + jstring jname UNUSED) +{ +#if defined(HAVE_ICONV) + iconv_t iconv_object; + jclass cls; + + const char *name = JCL_jstring_to_cstring (env, jname); + if (name == NULL) + return; + + /* Cache fieldIDs for use in decode function. */ + if (infid == NULL || outfid == NULL) + { + cls = (*env)->GetObjectClass (env, obj); + infid = (*env)->GetFieldID (env, cls, "inremaining", "I"); + assert (infid != 0); + outfid = (*env)->GetFieldID (env, cls, "outremaining", "I"); + assert (outfid != 0); + } + + /* to java from "name", native java format depends on endianness */ +#ifdef WORDS_BIGENDIAN + iconv_object = iconv_open ("UTF-16BE", name); +#else + iconv_object = iconv_open ("UTF-16LE", name); +#endif + + JCL_free_cstring (env, jname, name); + if ((long) iconv_object == -1L) + { + JCL_ThrowException (env, "java/lang/IllegalArgumentException", + "Charset not available"); + return; + } + createRawData (env, obj, (void *) iconv_object); +#else + JCL_ThrowException (env, "java/lang/IllegalArgumentException", + "iconv not available"); +#endif +} + +JNIEXPORT jint JNICALL +Java_gnu_java_nio_charset_iconv_IconvDecoder_decode (JNIEnv * env UNUSED, + jobject obj UNUSED, + jbyteArray inArr UNUSED, + jcharArray outArr UNUSED, + jint posIn UNUSED, + jint remIn UNUSED, + jint posOut UNUSED, + jint remOut UNUSED) +{ +#if defined(HAVE_ICONV) + iconv_t iconv_object = getData (env, obj); + size_t retval; + union char_union in, out; + jbyte *input, *inputcopy; + jchar *output, *outputcopy; + size_t lenIn = (size_t) remIn; + size_t lenOut = (size_t) remOut * 2; + + inputcopy = input = (*env)->GetByteArrayElements (env, inArr, 0); + outputcopy = output = (*env)->GetCharArrayElements (env, outArr, 0); + + input += posIn; + output += posOut; + + in.jb = &input; + out.jc = &output; + retval = iconv (iconv_object, (ICONV_CONST char **) in.c, &lenIn, + out.c, &lenOut); + + /* XXX: Do we need to relase the input array? It's not modified. */ + (*env)->ReleaseByteArrayElements (env, inArr, inputcopy, 0); + (*env)->ReleaseCharArrayElements (env, outArr, outputcopy, 0); + + if (retval == (size_t) (-1)) + { + if (errno == EILSEQ) + retval = 1; + else + retval = 0; + } + else + retval = 0; + + (*env)->SetIntField (env, obj, infid, (jint) lenIn); + (*env)->SetIntField (env, obj, outfid, (jint) (lenOut >> 1)); + + return (jint) retval; +#else + return -1; +#endif +} + +JNIEXPORT void JNICALL +Java_gnu_java_nio_charset_iconv_IconvDecoder_closeIconv (JNIEnv * env UNUSED, + jobject obj UNUSED) +{ +#if defined(HAVE_ICONV) + iconv_t iconv_object; + iconv_object = getData (env, obj); + iconv_close (iconv_object); +#endif +} + + +#if defined(HAVE_ICONV) +static void +createRawData (JNIEnv * env, jobject obj, void *ptr) +{ + jclass cls; + jobject data; + jfieldID data_fid; + + cls = (*env)->GetObjectClass (env, obj); + data_fid = (*env)->GetFieldID (env, cls, "data", "Lgnu/classpath/Pointer;"); + assert (data_fid != 0); + + data = JCL_NewRawDataObject(env, ptr); + + (*env)->SetObjectField (env, obj, data_fid, data); +} + +static void * +getData (JNIEnv * env, jobject obj) +{ + jclass cls; + jfieldID data_fid; + jobject data; + + cls = (*env)->GetObjectClass (env, obj); + data_fid = (*env)->GetFieldID (env, cls, "data", "Lgnu/classpath/Pointer;"); + assert (data_fid != 0); + data = (*env)->GetObjectField (env, obj, data_fid); + + return JCL_GetRawData(env, data); +} +#endif + diff --git a/libjava/classpath/native/jni/java-nio/gnu_java_nio_charset_iconv_IconvEncoder.c b/libjava/classpath/native/jni/java-nio/gnu_java_nio_charset_iconv_IconvEncoder.c new file mode 100644 index 000000000..54fd17286 --- /dev/null +++ b/libjava/classpath/native/jni/java-nio/gnu_java_nio_charset_iconv_IconvEncoder.c @@ -0,0 +1,208 @@ +/* gnu_java_nio_charset_iconv_IconvEncoder.c -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include + +#include +#include +#include + +#if defined(HAVE_ICONV) +#include +#endif + +#include "gnu_java_nio_charset_iconv_IconvEncoder.h" + + +#if defined(HAVE_ICONV) +static void createRawData (JNIEnv * env, jobject obj, void *ptr); +static void *getData (JNIEnv * env, jobject obj); + +static jfieldID infid = NULL; +static jfieldID outfid = NULL; +#endif + +/* Union used for type punning. */ +union char_union +{ + jbyte **jb; + jchar **jc; + char **c; +}; + +JNIEXPORT void JNICALL +Java_gnu_java_nio_charset_iconv_IconvEncoder_openIconv (JNIEnv * env UNUSED, + jobject obj UNUSED, + jstring jname UNUSED) +{ +#if defined(HAVE_ICONV) + iconv_t iconv_object; + jclass cls; + + const char *name = JCL_jstring_to_cstring (env, jname); + if (name == NULL) + return; + + /* Cache fieldIDs for use in encode function. */ + if (infid == NULL || outfid == NULL) + { + cls = (*env)->GetObjectClass (env, obj); + infid = (*env)->GetFieldID (env, cls, "inremaining", "I"); + assert (infid != 0); + outfid = (*env)->GetFieldID (env, cls, "outremaining", "I"); + assert (outfid != 0); + } + + /* to "name" from java, native java format depends on endianness */ +#ifdef WORDS_BIGENDIAN + iconv_object = iconv_open (name, "UTF-16BE"); +#else + iconv_object = iconv_open (name, "UTF-16LE"); +#endif + + JCL_free_cstring (env, jname, name); + if ((long) iconv_object == -1L) + { + JCL_ThrowException (env, "java/lang/IllegalArgumentException", + "Charset not available"); + return; + } + createRawData (env, obj, (void *) iconv_object); +#else + JCL_ThrowException (env, "java/lang/IllegalArgumentException", + "iconv not available"); +#endif +} + +JNIEXPORT jint JNICALL +Java_gnu_java_nio_charset_iconv_IconvEncoder_encode (JNIEnv * env UNUSED, + jobject obj UNUSED, + jcharArray inArr UNUSED, + jbyteArray outArr UNUSED, + jint posIn UNUSED, + jint remIn UNUSED, + jint posOut UNUSED, + jint remOut UNUSED) +{ +#if defined(HAVE_ICONV) + iconv_t iconv_object = getData (env, obj); + size_t retval; + union char_union in, out; + jchar *input, *inputcopy; + jbyte *output, *outputcopy; + size_t lenIn = (size_t) remIn * 2; + size_t lenOut = (size_t) remOut; + + inputcopy = input = (*env)->GetCharArrayElements (env, inArr, 0); + outputcopy = output = (*env)->GetByteArrayElements (env, outArr, 0); + + input += posIn; + output += posOut; + + in.jc = &input; + out.jb = &output; + retval = iconv (iconv_object, (ICONV_CONST char **) in.c, &lenIn, + out.c, &lenOut); + + /* XXX: Do we need to relase the input array? It's not modified. */ + (*env)->ReleaseCharArrayElements (env, inArr, inputcopy, 0); + (*env)->ReleaseByteArrayElements (env, outArr, outputcopy, 0); + + if (retval == (size_t) (-1)) + { + if (errno == EILSEQ || errno == EINVAL) + retval = 1; + else + retval = 0; + } + else + retval = 0; + + (*env)->SetIntField (env, obj, infid, (jint) (lenIn >> 1)); + (*env)->SetIntField (env, obj, outfid, (jint) lenOut); + + return (jint) retval; +#else + return -1; +#endif +} + +JNIEXPORT void JNICALL +Java_gnu_java_nio_charset_iconv_IconvEncoder_closeIconv (JNIEnv * env UNUSED, + jobject obj UNUSED) +{ +#if defined(HAVE_ICONV) + iconv_t iconv_object; + iconv_object = getData (env, obj); + iconv_close (iconv_object); +#endif +} + + +#if defined(HAVE_ICONV) +static void +createRawData (JNIEnv * env, jobject obj, void *ptr) +{ + jclass cls; + jobject data; + jfieldID data_fid; + + cls = (*env)->GetObjectClass (env, obj); + data_fid = (*env)->GetFieldID (env, cls, "data", "Lgnu/classpath/Pointer;"); + assert (data_fid != 0); + + data = JCL_NewRawDataObject (env, ptr); + + (*env)->SetObjectField (env, obj, data_fid, data); +} + +static void * +getData (JNIEnv * env, jobject obj) +{ + jclass cls; + jfieldID data_fid; + jobject data; + + cls = (*env)->GetObjectClass (env, obj); + data_fid = (*env)->GetFieldID (env, cls, "data", "Lgnu/classpath/Pointer;"); + assert (data_fid != 0); + data = (*env)->GetObjectField (env, obj, data_fid); + + return JCL_GetRawData(env, data); +} +#endif diff --git a/libjava/classpath/native/jni/java-nio/java_nio_MappedByteBufferImpl.c b/libjava/classpath/native/jni/java-nio/java_nio_MappedByteBufferImpl.c new file mode 100644 index 000000000..2a87d2950 --- /dev/null +++ b/libjava/classpath/native/jni/java-nio/java_nio_MappedByteBufferImpl.c @@ -0,0 +1,241 @@ +/* java_nio_MappedByteBufferImpl.c - Native methods for MappedByteBufferImpl + Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include + +#include +#include + +#include "java_nio_MappedByteBufferImpl.h" + +#include +#include +#ifdef HAVE_UNISTD_H +#include +#endif /* HAVE_UNISTD_H */ +#ifdef HAVE_SYS_MMAN_H +#include +#endif /* HAVE_SYS_MMAN_H */ + +#define IO_EXCEPTION "java/io/IOException" + +/* FIXME these are defined in gnu_java_nio_channels_FileChannelImpl + too; should be someplace common. */ +#define ALIGN_DOWN(p,s) ((jpointer)(p) - ((jpointer)(p) % (s))) +#define ALIGN_UP(p,s) ((jpointer)(p) + ((s) - ((jpointer)(p) % (s)))) + +/** + * Returns the memory page size of this platform. + * + * \return The page size. + */ +static long +get_pagesize (void) +{ + /* FIXME can we just try HAVE_SYSCONF? */ +#if defined(HAVE_GETPAGESIZE) + return getpagesize (); +#elif defined (HAVE_SYSCONF) + return sysconf (_SC_PAGESIZE); +#endif /* HAVE_GETPAGESIZE / HAVE_SYSCONF */ +} + +/** + * Retrieve the 'address' and 'cap' (the mapped size) fields of this + * buffer. + * + * This function will align the address down to the nearest page + * boundary, and the size up to the nearest page boundary. Thus, it is + * safe to use these values in 'mman' functions. + * + * \param env The JNI environment pointer. + * \param this The MappedByteBufferImpl instance. + * \param address A pointer to where the actual pointer should be + * stored. + * \param size A pointer to where the mapped region's size should be + * stored + */ +static void +get_raw_values (JNIEnv *env, jobject this, void **address, size_t *size) +{ + const long pagesize = get_pagesize (); + jfieldID MappedByteBufferImpl_address; + jfieldID MappedByteBufferImpl_size; + jobject MappedByteBufferImpl_address_value = NULL; + + *address = NULL; + /* 'address' is declared in java.nio.Buffer */ + MappedByteBufferImpl_address + = (*env)->GetFieldID (env, (*env)->GetObjectClass (env, this), + "address", "Lgnu/classpath/Pointer;"); + /* 'cap' -- likewise, the capacity */ + MappedByteBufferImpl_size + = (*env)->GetFieldID (env, (*env)->GetObjectClass (env, this), + "cap", "I"); + if (MappedByteBufferImpl_address != NULL) + { + MappedByteBufferImpl_address_value = + (*env)->GetObjectField (env, this, MappedByteBufferImpl_address); + } + if ((*env)->ExceptionOccurred (env)) + return; + if (MappedByteBufferImpl_address_value == NULL) + { + JCL_ThrowException (env, "java/lang/NullPointerException", + "mapped address is NULL"); + return; + } + + *address = (void *) + ALIGN_DOWN (JCL_GetRawData (env, MappedByteBufferImpl_address_value), pagesize); + *size = (size_t) + ALIGN_UP ((*env)->GetIntField (env, this, MappedByteBufferImpl_size), + pagesize); +} + +JNIEXPORT void JNICALL +Java_java_nio_MappedByteBufferImpl_unmapImpl (JNIEnv *env, jobject this) +{ +#ifdef HAVE_MUNMAP + void *address; + size_t size; + + get_raw_values (env, this, &address, &size); + + if (address == NULL) + return; + + if (munmap (address, size) != 0) + { + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); + return; + } +#else + JCL_ThrowException (env, IO_EXCEPTION, + "unmapping files not implemented"); +#endif /* HAVE_MUNMAP */ +} + +JNIEXPORT jboolean JNICALL +Java_java_nio_MappedByteBufferImpl_isLoadedImpl (JNIEnv * env, jobject this) +{ +#ifdef HAVE_MINCORE + void *address; + size_t size; + char *vec; + size_t count, i; + const long pagesize = get_pagesize (); + + /* + * FIXME on Darwin this does not work if the mapped region is + * exactly one page long; i.e., 'mincore' tells us it isn't loaded. + */ + get_raw_values (env, this, &address, &size); + if (address == NULL) + return JNI_FALSE; + count = (size_t) ((size + pagesize - 1) / pagesize); + vec = (char *) malloc (count * sizeof (unsigned char)); + + /* + * Darwin (and BSD?) define argument 3 of 'mincore' to be 'char *', + * while GNU libc defines it to be 'unsigned char *'. Casting the + * argument to 'void *' fixes this, but not with C++. So you might + * be SOL if you compile this with g++ (!) on GNU with -Werror. + */ +#ifdef __cplusplus + if (mincore (address, size, vec) != 0) +#else + if (mincore (address, size, (void *) vec) != 0) +#endif /* __cplusplus */ + { + free (vec); + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); + return JNI_FALSE; + } + + for (i = 0; i < count; i++) + { + if ((vec[i] & 1) == 0) + return JNI_FALSE; + } + return JNI_TRUE; +#else + return JNI_FALSE; +#endif +} + +JNIEXPORT void JNICALL +Java_java_nio_MappedByteBufferImpl_loadImpl (JNIEnv *env, jobject this) +{ +#ifdef HAVE_MADVISE + void *address; + size_t size; + + get_raw_values (env, this, &address, &size); + if (address == NULL) + return; + + madvise (address, size, MADV_WILLNEED); +#else + JCL_ThrowException (env, IO_EXCEPTION, + "forcing mapped files into core not implemented"); +#endif /* HAVE_MADVISE */ +} + +JNIEXPORT void JNICALL +Java_java_nio_MappedByteBufferImpl_forceImpl (JNIEnv *env, jobject this) +{ +#ifdef HAVE_MSYNC + void *address; + size_t size; + + get_raw_values (env, this, &address, &size); + + if (address == NULL) + return; + + /* FIXME: is using MS_SYNC ok? Should we use MS_INVALIDATE? */ + if (msync (address, size, MS_SYNC) != 0) + { + JCL_ThrowException (env, IO_EXCEPTION, strerror (errno)); + } +#else + JCL_ThrowException (env, IO_EXCEPTION, + "forcing mapped files to disk not implemented"); +#endif /* HAVE_MSYNC */ +} diff --git a/libjava/classpath/native/jni/java-nio/java_nio_VMDirectByteBuffer.c b/libjava/classpath/native/jni/java-nio/java_nio_VMDirectByteBuffer.c new file mode 100644 index 000000000..bfee7e9dc --- /dev/null +++ b/libjava/classpath/native/jni/java-nio/java_nio_VMDirectByteBuffer.c @@ -0,0 +1,130 @@ +/* java_nio_VMDirectByteBuffer.c - Native methods for VMDirectByteBuffer + Copyright (C) 2004, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include + +#include +#include + +#include "java_nio_VMDirectByteBuffer.h" + +JNIEXPORT jobject JNICALL +Java_java_nio_VMDirectByteBuffer_allocate + (JNIEnv * env, jclass clazz __attribute__ ((__unused__)), jint capacity) +{ + void *buffer; + + buffer = malloc (capacity); + + if (buffer == NULL) + { + JCL_ThrowException (env, "java/lang/OutOfMemoryError", + "unable to allocate memory for direct byte buffer"); + return 0; + } + + memset (buffer, 0, capacity); + + return JCL_NewRawDataObject (env, buffer); +} + +JNIEXPORT void JNICALL +Java_java_nio_VMDirectByteBuffer_free + (JNIEnv * env, jclass clazz __attribute__ ((__unused__)), jobject address) +{ + free (JCL_GetRawData (env, address)); +} + +JNIEXPORT jbyte JNICALL +Java_java_nio_VMDirectByteBuffer_get__Lgnu_classpath_Pointer_2I + (JNIEnv * env, jclass clazz __attribute__ ((__unused__)), + jobject address, jint index) +{ + return ((jbyte *) JCL_GetRawData (env, address))[index]; +} + +JNIEXPORT void JNICALL +Java_java_nio_VMDirectByteBuffer_put__Lgnu_classpath_Pointer_2IB + (JNIEnv * env, jclass clazz __attribute__ ((__unused__)), + jobject address, jint index, jbyte value) +{ + jbyte *pointer = (jbyte *) JCL_GetRawData (env, address) + index; + *pointer = value; +} + +JNIEXPORT void JNICALL +Java_java_nio_VMDirectByteBuffer_get__Lgnu_classpath_Pointer_2I_3BII + (JNIEnv * env, jclass clazz __attribute__ ((__unused__)), + jobject address, jint index, jbyteArray dst, jint dst_offset, jint dst_len) +{ + jbyte *src = (jbyte *) JCL_GetRawData (env, address) + index; + jbyte *_dst = (*env)->GetByteArrayElements (env, dst, NULL); + memcpy (_dst + dst_offset, src, dst_len); + (*env)->ReleaseByteArrayElements (env, dst, _dst, 0); +} + +JNIEXPORT void JNICALL +Java_java_nio_VMDirectByteBuffer_put__Lgnu_classpath_Pointer_2I_3BII + (JNIEnv *env, jclass clazz __attribute__ ((__unused__)), + jobject address, jint index, jbyteArray src, jint src_offset, jint src_len) +{ + jbyte *_src = (*env)->GetByteArrayElements (env, src, NULL); + jbyte *dst = (jbyte *)JCL_GetRawData (env, address); + memcpy (dst + index, _src + src_offset, src_len); + (*env)->ReleaseByteArrayElements (env, src, _src, 0); +} + +JNIEXPORT void JNICALL +Java_java_nio_VMDirectByteBuffer_shiftDown + (JNIEnv * env, jclass clazz __attribute__ ((__unused__)), + jobject address, jint dst_offset, jint src_offset, jint count) +{ + jbyte *dst = (jbyte *) JCL_GetRawData (env, address) + dst_offset; + jbyte *src = (jbyte *) JCL_GetRawData (env, address) + src_offset; + memmove (dst, src, count); +} + +JNIEXPORT jobject JNICALL +Java_java_nio_VMDirectByteBuffer_adjustAddress + (JNIEnv * env, jclass clazz __attribute__ ((__unused__)), + jobject address, jint offset) +{ + return JCL_NewRawDataObject (env, (jbyte *) JCL_GetRawData (env, address) + offset); +} diff --git a/libjava/classpath/native/jni/java-nio/javanio.c b/libjava/classpath/native/jni/java-nio/javanio.c new file mode 100644 index 000000000..a7018b347 --- /dev/null +++ b/libjava/classpath/native/jni/java-nio/javanio.c @@ -0,0 +1,144 @@ +/* javanio.c -- implementations of functions in javanio.h. + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +/* + * Note, because these functions are trivial, and should be inlined, + * we include this file in the header, and do not compile it. + */ + +#include +#include +#include +#include +#ifdef HAVE_SYS_SELECT_H +#include +#endif +#include + +CPNIO_EXPORT ssize_t +cpnio_read (int fd, void *buf, size_t nbytes) +{ + return read (fd, buf, nbytes); +} + +CPNIO_EXPORT ssize_t +cpnio_readv (int fd, const struct iovec *iov, int iovcnt) +{ + return readv (fd, iov, iovcnt); +} + +CPNIO_EXPORT ssize_t +cpnio_write (int fd, const void *buf, size_t nbytes) +{ + return write (fd, buf, nbytes); +} + +CPNIO_EXPORT ssize_t +cpnio_writev (int fd, const struct iovec *iov, size_t iovcnt) +{ + return writev (fd, iov, iovcnt); +} + +CPNIO_EXPORT int +cpnio_socket (int domain, int type, int protocol) +{ + return socket (domain, type, protocol); +} + +CPNIO_EXPORT int +cpnio_connect (int fd, const struct sockaddr *addr, socklen_t addrlen) +{ + return connect (fd, addr, addrlen); +} + +CPNIO_EXPORT int +cpnio_accept (int fd, struct sockaddr *addr, socklen_t *addrlen) +{ + fd_set rset; + struct timeval tv; + socklen_t tvlen = sizeof(tv); + int ret; + + tv.tv_sec = 0; + tv.tv_usec = 0; + getsockopt (fd, SOL_SOCKET, SO_RCVTIMEO, &tv, &tvlen); + if (tv.tv_sec > 0 || tv.tv_usec > 0) + { + FD_ZERO(&rset); + FD_SET(fd,&rset); + ret = select (fd+1,&rset,NULL,NULL,&tv); + if (ret == 0) + { + errno = EAGAIN; + return -1; + } + } + return accept (fd, addr, addrlen); +} + +CPNIO_EXPORT ssize_t +cpnio_sendto (int fd, const void *msg, size_t len, int flags, + const struct sockaddr *to, socklen_t tolen) +{ + return sendto (fd, msg, len, flags, to, tolen); +} + +CPNIO_EXPORT ssize_t +cpnio_recvfrom (int fd, void *buf, size_t len, int flags, + struct sockaddr *from, socklen_t *fromlen) +{ + return recvfrom (fd, buf, len, flags, from, fromlen); +} + +CPNIO_EXPORT int +cpnio_fcntl (int fd, int cmd, long arg) +{ +#ifdef HAVE_FCNTL + return fcntl (fd, cmd, arg); +#else + errno = ENOSUP; + return -1; +#endif /* HAVE_FCNTL */ +} + +CPNIO_EXPORT int +cpnio_select (int nfds, fd_set *readfds, fd_set *writefds, + fd_set *excepfds, struct timeval *timeo) +{ + return select (nfds, readfds, writefds, excepfds, timeo); +} diff --git a/libjava/classpath/native/jni/java-nio/javanio.h b/libjava/classpath/native/jni/java-nio/javanio.h new file mode 100644 index 000000000..cc31cf3c1 --- /dev/null +++ b/libjava/classpath/native/jni/java-nio/javanio.h @@ -0,0 +1,334 @@ +/* javanio.h -- reference implementation of native functions. + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#ifndef __JAVANIO_H__ +#define __JAVANIO_H__ + +#include + +/** + * This header defines functions that are called by our JNI reference + * implementation of java.nio.*. In our reference implementation, these + * functions map exactly to their counterparts in POSIX; in implementations + * that can't use these functions directly (such as systems that use user-land + * threads, and thus can't call blocking system calls directly) can provide + * their own implementations suitable for their system. + */ + +/** + * This macro is used in all function prototypes below; if any additional + * keywords need to be added to a prototype, declare them in this macro. + */ +#define CPNIO_EXPORT static inline + +/** + * Read bytes from the given file descriptor into the given memory address, which + * has sufficient space for NBYTES bytes. + * + * \param fd The file descriptor to read from. + * \param buf The memory address to read bytes into. + * \param nbytes The number of bytes available to store in BUF. + * \return The number of bytes read, possibly zero, on success; return -1 on failure, + * and set ERRNO to an appropriate value. + * \see read(2) + * + * Allowed errno values: + * [EBADF] If FD is not a valid file descriptor, or is not open for reading. + * [EFAULT] If BUF points outside the process's address space. + * [EIO] An I/O error occurrs. + * [EINTR] If the read is interrupted by a signal. + * [EINVAL] If FD is negative. + * [EAGAIN] If FD was marked for non-blocking I/O, and no data were ready to + * be read. + */ +CPNIO_EXPORT ssize_t cpnio_read (int fd, void *buf, size_t nbytes); + +/* + * Read bytes from a file descriptor into a sequence of IO buffers. + * + * The iovec structure is defined as: + * + * struct iovec { + * char *iov_base; + * size_t iov_len; + * }; + * + * The call to _cp_readv should do a scattering read, where for each struct iovec + * in the supplied list, up to IOV_LEN bytes are read into IOV_BASE. The function + * returns the total number of bytes read into all supplied buffers. + * + * \param fd The file descriptor. + * \param iov A pointer to the head of a list of iovec structures. + * \param iovcnt The number of iovec structures pointed to by IOV. + * \return The total number of bytes read accross all buffers, possibly zero. On + * error, -1 is returned and ERRNO is set. + * \see readv(2) + * + * Allowed ERRNO values include all of those listed for _cp_read, as well as the + * following: + * [EINVAL] If IOVCNT overflows the maximum number of iovec structures + * this platform supports (usually 16), if any IOV_LEN value + * is negative, or if the sum of all IOV_LEN values is too + * large to be stored in a ssize_t (usually a 32-bit integer). + * [EFAULT] If part of IOV points outside the process's address space. + */ +CPNIO_EXPORT ssize_t cpnio_readv (int fd, const struct iovec *iov, int iovcnt); + +/* + * Write NBYTES bytes from BUF to the file descriptor FD, returning the number + * of bytes successfully written. + * + * \param fd The file descriptor. + * \param buf A pointer to the bytes to write. + * \param nbytes The maximum number of bytes to write. + * \return The number of bytes written to the file descriptor, possibly zero. -1 + * is returned if an error is encountered, and ERRNO will be set. + * \see write(2) + * + * Allowed ERRNO values: + * [EBADF] If FD is not a valid file descriptor or is not open for writing. + * [EPIPE] If FD is a pipe, when the other side is disconnected; if FD is a + * socket, when the peer is not connected. + * [EFBIG] When FD is a file, and writing to it overflows the process's + * or the system's maximim file size. + * [EFAULT] If the buffer to write points outside the process's address + * space. + * [EINVAL] If the descriptor FD is negative. + * [ENOSPC] If FD is a file, and there is insufficient space on the + * filesystem. + * [EDQUOT] If FD is a file, and the user's disk quota has been exceeded. + * [EIO] If an I/O error occurs. + * [EINTR] If the call is interrupted by a signal. + * [EAGAIN] If FD is in non-blocking mode, and no bytes could be immediately + * written. + */ +CPNIO_EXPORT ssize_t cpnio_write (int fd, const void *buf, size_t nbytes); + +/* + * Write data from a sequence of IOVCNT buffers IOV to a file descriptor FD. + * + * \param fd The file descriptor. + * \param iov The list of buffers to write. + * \param iovcnt The number of iovec structures pointed to by IOV. + * \return The total number of bytes written from the given buffers, possibly + * zero. -1 if an error occurs, and ERRNO will be set. + * \see writev(2) + * + * Allowed ERRNO values include those mentioned in _cp_write, as well as: + * [EDESTADDRREQ] If the descriptor is a datagram socket, and the peer is + * no longer available. + * [EINVAL] If IOVCNT is out of range, if any IOV_LEN value is + * negative, or if the sum of all IOVCNT IOV_LEN values + * will overflow a ssize_t. + * [ENOBUFS] If the mbuf pool is exhausted (???). + */ +CPNIO_EXPORT ssize_t cpnio_writev (int fd, const struct iovec *iov, size_t iovcnt); + +/** + * Open a new, unbound and unconnected socket. + * + * \param domain The socket domain. Implementations need only handle AF_INET. + * \param type The socket type; implementations need only handle types + * SOCK_STREAM (for streaming sockets) and SOCK_DGRAM (for datagram sockets). + * \param protocol This should always be 0. It can be ignored. + * \return A new file descriptor pointing to a newly created socket, or -1 on + * error, and ERRNO set. + * + * Allowed ERRNO values: + * [EPROTONOSUPPORT] If TYPE is unrecognized. + * [EMFILE] If a new file descriptor cannot be allocated, because + * the process's descriptor table is full. + * [ENFILE] Likewise, but when the system table is full. + * [EACCES] If this operation is not allowed. + * [ENOBUFS] If there is not enough buffer space available for the + * new socket. + */ +CPNIO_EXPORT int cpnio_socket (int domain, int type, int protocol); + +/** + * Connect a socket to a remote address. + * + * \param fd The file descriptor of the socket to connect. + * \param addr The address to connect to. In practice, this should be + * either a `struct sockaddr_in' or a `struct sockaddr_in6'. + * \param addrlen The size of the address structure passed by ADDR. + * \return Zero if the connect succeeds. -1 on error, and ERRNO should be set. + * + * Allowed ERRNO values: + * [EBADF] If FD is not a valid file descriptor. + * [ENOTSOCK] If FD is not a socket descriptor. + * [EADDRNOTAVAIL] If ADDR is not available for use to this process. + * [EAFNOSUPPORT] If the address family of ADDR is not supported. + * [EISCONN] If the socket is already connected. + * [ETIMEDOUT] If the connection could not be made in a reasonable + * amount of time. + * [ECONNREFUSED] If the connection attempt was rejected. + * [ENETUNREACH] If the network ADDR is on is unreachable. + * [EADDRINUSE] If the address is already in use. + * [EFAULT] If ADDR points outside the addressable space. + * [EINPROGRESS] If FD is in non-blocking mode, and the connection could + * not be completed immediately. + * [EALREADY] If FD is in non-blocking mode, and a connection attempt + * is still pending. + * [EACCESS] If ADDR is the broadcast address, and the socket option + * SO_BROADCAST is not set. + */ +CPNIO_EXPORT int cpnio_connect (int fd, const struct sockaddr *addr, socklen_t addrlen); + +/** + * Accept an incoming connection on a socket, returning a new socket for + * the connection, and storing the peer address in ADDR. + * + * \param fd The socket file descriptor. + * \param addr The structure to store the peer address in. + * \param addrlen The size of the data available in ADDR; upon return, the + * number of bytes stored in ADDR will be placed here. + * \return The new socket file descriptor, or -1 on error, and ERRNO set. + * + * Allowed ERRNO values: + * [EBADF] If FD is not a valid file descriptor. + * [ENOTSOCK] If FD in not a socket descriptor. + * [EOPNOTSUPP] If the socket is not a SOCK_STREAM socket. + * [EFAULT] If ADDR points outside the process's addressable space. + * [EWOULDBLOCK] If the socket is in non-blocking mode, and no connection + * attempt is currently ready. + * [EMFILE] If the process's descriptor table is full. + * [ENFILE] If the system's descriptor table is full. + */ +CPNIO_EXPORT int cpnio_accept (int fd, struct sockaddr *addr, socklen_t *addrlen); + +/** + * Send a datagram to the given address. + * + * \param fd The socket file descriptor. + * \param msg A pointer to the message to send. + * \param len The size of the message to send. + * \param flags Flags for sending. + * \param to The remote address to send the message to. + * \param tolen The size of the TO address structure. + * \return The number of bytes written, possibly zero, on success. Returns + * -1 on failure, and sets ERRNO. + * \see sendto(2) + * + * Allowed ERRNO values: + * [EBADF] + * [ENOTSOCK] + * [EFAULT] + * [EMSGSIZE] + * [EAGAIN] + * [ENOBUFS] + * [EACCES] + * [EHOSTUNREACH] + */ +CPNIO_EXPORT ssize_t cpnio_sendto (int fd, const void *msg, size_t len, int flags, + const struct sockaddr *to, socklen_t tolen); + +/** + * Receive a message on a socket, storing the remote host's address in + * FROM. + * + * \param fd The socket file descriptor. + * \param buf The buffer to store received bytes in. + * \param flags Flags to control the receive. + * \param from Where to store the remote address. + * \param fromlen Pointer to the size of FROM; on return, it will contain the + * size of the structure placed in FROM. + * \return The number of bytes received on success. -1 on error, and ERRNO will + * be set. + * \see recvfrom(2) + * + * Allewed ERRNO values: + * [EBADF] FD is not a valid file descriptor. + * [ENOTCONN] If the socket is stream-oriented, and no prior call to + * connect(2) was made. + * [ENOTSOCK] FD is not a socket. + * [EAGAIN] FD is in non-blocking mode, and no message was + * immediately available. + * [EINTR] The system call was interrupted by a signal. + * [EFAULT] BUF, FROM, or FROMLEN lie outside the process's address + * space. + */ +CPNIO_EXPORT ssize_t cpnio_recvfrom (int fd, void *buf, size_t len, int flags, + struct sockaddr *from, socklen_t *fromlen); + + +/** + * Control file descriptor properties. + * + * \param fd The file descriptor to control. + * \param cmd The command to execute. + * \param arg The command argument. + * \return A value other than -1, specific to CMD. On error, -1 is + * returned, and ERRNO is set. + * + * Allowed ERRNO values: + * FIXME + */ +CPNIO_EXPORT int cpnio_fcntl (int fd, int cmd, long arg); + + +/** + * Select from one of the given file descriptor sets a descriptor that + * is ready for the given operation (read, write, etc.). + * + * \param nfds A value one larger than the largest file + * descriptor. + * \param readfds A set of file descriptors to select for + * readability. + * \param writefds A set of file descriptors to select for + * writability. + * \param exceptfds A set of file descriptors to select for + * exceptional conditions. + * \param tm The selection timeout. + * \return The number of file descriptors selected, possibly zero, or + * -1 on error (and with ERRNO set). + */ +CPNIO_EXPORT int cpnio_select (int nfds, fd_set *readfds, fd_set *writefds, + fd_set *exceptfds, struct timeval *tm); + +/* + * We include the implementation file here, because our reference + * implementation is trivial, and the functions are declared extern + * inline. + * + * Implementations that need different implementations of these functions + * SHOULD remove this line, and compile javanio.c as a separate unit. + */ +#include "javanio.c" + +#endif /* __JAVANIO_H__ */ diff --git a/libjava/classpath/native/jni/java-util/.cvsignore b/libjava/classpath/native/jni/java-util/.cvsignore new file mode 100644 index 000000000..e9f2658a6 --- /dev/null +++ b/libjava/classpath/native/jni/java-util/.cvsignore @@ -0,0 +1,8 @@ +*.o +*.a +*.lo +*.la +.libs +.deps +Makefile +Makefile.in diff --git a/libjava/classpath/native/jni/java-util/Makefile.am b/libjava/classpath/native/jni/java-util/Makefile.am new file mode 100644 index 000000000..59ddc74e2 --- /dev/null +++ b/libjava/classpath/native/jni/java-util/Makefile.am @@ -0,0 +1,9 @@ +nativeexeclib_LTLIBRARIES = libjavautil.la + +libjavautil_la_SOURCES = java_util_VMTimeZone.c + +AM_LDFLAGS = @CLASSPATH_MODULE@ +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ +AM_CFLAGS = @WARNING_CFLAGS@ @STRICT_WARNING_CFLAGS@ @ERROR_CFLAGS@ \ + @EXTRA_CFLAGS@ + diff --git a/libjava/classpath/native/jni/java-util/Makefile.in b/libjava/classpath/native/jni/java-util/Makefile.in new file mode 100644 index 000000000..7d0655112 --- /dev/null +++ b/libjava/classpath/native/jni/java-util/Makefile.in @@ -0,0 +1,606 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +subdir = native/jni/java-util +DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/../../config/depstand.m4 \ + $(top_srcdir)/../../config/lead-dot.m4 \ + $(top_srcdir)/../../config/lib-ld.m4 \ + $(top_srcdir)/../../config/lib-link.m4 \ + $(top_srcdir)/../../config/lib-prefix.m4 \ + $(top_srcdir)/../../config/multi.m4 \ + $(top_srcdir)/../../config/no-executables.m4 \ + $(top_srcdir)/../../config/override.m4 \ + $(top_srcdir)/../../libtool.m4 \ + $(top_srcdir)/../../ltoptions.m4 \ + $(top_srcdir)/../../ltsugar.m4 \ + $(top_srcdir)/../../ltversion.m4 \ + $(top_srcdir)/../../lt~obsolete.m4 \ + $(top_srcdir)/m4/ac_prog_antlr.m4 \ + $(top_srcdir)/m4/ac_prog_java.m4 \ + $(top_srcdir)/m4/ac_prog_java_works.m4 \ + $(top_srcdir)/m4/ac_prog_javac.m4 \ + $(top_srcdir)/m4/ac_prog_javac_works.m4 \ + $(top_srcdir)/m4/acattribute.m4 $(top_srcdir)/m4/accross.m4 \ + $(top_srcdir)/m4/acinclude.m4 \ + $(top_srcdir)/m4/ax_create_stdint_h.m4 \ + $(top_srcdir)/m4/ax_func_which_gethostbyname_r.m4 \ + $(top_srcdir)/m4/gcc_attribute.m4 $(top_srcdir)/m4/iconv.m4 \ + $(top_srcdir)/m4/pkg.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/../../mkinstalldirs +CONFIG_HEADER = $(top_builddir)/include/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__installdirs = "$(DESTDIR)$(nativeexeclibdir)" +LTLIBRARIES = $(nativeexeclib_LTLIBRARIES) +libjavautil_la_LIBADD = +am_libjavautil_la_OBJECTS = java_util_VMTimeZone.lo +libjavautil_la_OBJECTS = $(am_libjavautil_la_OBJECTS) +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/include +depcomp = $(SHELL) $(top_srcdir)/../../depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(libjavautil_la_SOURCES) +ETAGS = etags +CTAGS = ctags +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +ANTLR = @ANTLR@ +ANTLR_JAR = @ANTLR_JAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CAIRO_CFLAGS = @CAIRO_CFLAGS@ +CAIRO_LIBS = @CAIRO_LIBS@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CLASSPATH_CONVENIENCE = @CLASSPATH_CONVENIENCE@ +CLASSPATH_INCLUDES = @CLASSPATH_INCLUDES@ +CLASSPATH_MODULE = @CLASSPATH_MODULE@ +COLLECTIONS_PREFIX = @COLLECTIONS_PREFIX@ +CP = @CP@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DATE = @DATE@ +DEFAULT_PREFS_PEER = @DEFAULT_PREFS_PEER@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +ECJ_JAR = @ECJ_JAR@ +EGREP = @EGREP@ +ERROR_CFLAGS = @ERROR_CFLAGS@ +EXAMPLESDIR = @EXAMPLESDIR@ +EXEEXT = @EXEEXT@ +EXTRA_CFLAGS = @EXTRA_CFLAGS@ +FGREP = @FGREP@ +FIND = @FIND@ +FREETYPE2_CFLAGS = @FREETYPE2_CFLAGS@ +FREETYPE2_LIBS = @FREETYPE2_LIBS@ +GCONF_CFLAGS = @GCONF_CFLAGS@ +GCONF_LIBS = @GCONF_LIBS@ +GDK_CFLAGS = @GDK_CFLAGS@ +GDK_LIBS = @GDK_LIBS@ +GJDOC = @GJDOC@ +GLIB_CFLAGS = @GLIB_CFLAGS@ +GLIB_LIBS = @GLIB_LIBS@ +GMP_CFLAGS = @GMP_CFLAGS@ +GMP_LIBS = @GMP_LIBS@ +GREP = @GREP@ +GSTREAMER_BASE_CFLAGS = @GSTREAMER_BASE_CFLAGS@ +GSTREAMER_BASE_LIBS = @GSTREAMER_BASE_LIBS@ +GSTREAMER_CFLAGS = @GSTREAMER_CFLAGS@ +GSTREAMER_FILE_READER = @GSTREAMER_FILE_READER@ +GSTREAMER_LIBS = @GSTREAMER_LIBS@ +GSTREAMER_MIXER_PROVIDER = @GSTREAMER_MIXER_PROVIDER@ +GSTREAMER_PLUGINS_BASE_CFLAGS = @GSTREAMER_PLUGINS_BASE_CFLAGS@ +GSTREAMER_PLUGINS_BASE_LIBS = @GSTREAMER_PLUGINS_BASE_LIBS@ +GST_PLUGIN_LDFLAGS = @GST_PLUGIN_LDFLAGS@ +GTK_CFLAGS = @GTK_CFLAGS@ +GTK_LIBS = @GTK_LIBS@ +INIT_LOAD_LIBRARY = @INIT_LOAD_LIBRARY@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAR = @JAR@ +JAVA = @JAVA@ +JAVAC = @JAVAC@ +JAVAC_IS_GCJ = @JAVAC_IS_GCJ@ +JAVAC_MEM_OPT = @JAVAC_MEM_OPT@ +JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION = @JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION@ +JAY = @JAY@ +JAY_SKELETON = @JAY_SKELETON@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBDEBUG = @LIBDEBUG@ +LIBICONV = @LIBICONV@ +LIBMAGIC = @LIBMAGIC@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBVERSION = @LIBVERSION@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBICONV = @LTLIBICONV@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MKDIR = @MKDIR@ +MKDIR_P = @MKDIR_P@ +MOC = @MOC@ +MOZILLA_CFLAGS = @MOZILLA_CFLAGS@ +MOZILLA_LIBS = @MOZILLA_LIBS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PANGOFT2_CFLAGS = @PANGOFT2_CFLAGS@ +PANGOFT2_LIBS = @PANGOFT2_LIBS@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PATH_TO_ESCHER = @PATH_TO_ESCHER@ +PATH_TO_GLIBJ_ZIP = @PATH_TO_GLIBJ_ZIP@ +PERL = @PERL@ +PKG_CONFIG = @PKG_CONFIG@ +PLUGIN_DIR = @PLUGIN_DIR@ +QT_CFLAGS = @QT_CFLAGS@ +QT_LIBS = @QT_LIBS@ +RANLIB = @RANLIB@ +REMOVE = @REMOVE@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRICT_WARNING_CFLAGS = @STRICT_WARNING_CFLAGS@ +STRIP = @STRIP@ +TOOLSDIR = @TOOLSDIR@ +USER_JAVAH = @USER_JAVAH@ +VERSION = @VERSION@ +WANT_NATIVE_BIG_INTEGER = @WANT_NATIVE_BIG_INTEGER@ +WARNING_CFLAGS = @WARNING_CFLAGS@ +XMKMF = @XMKMF@ +XML_CFLAGS = @XML_CFLAGS@ +XML_LIBS = @XML_LIBS@ +XSLT_CFLAGS = @XSLT_CFLAGS@ +XSLT_LIBS = @XSLT_LIBS@ +XTEST_LIBS = @XTEST_LIBS@ +X_CFLAGS = @X_CFLAGS@ +X_EXTRA_LIBS = @X_EXTRA_LIBS@ +X_LIBS = @X_LIBS@ +X_PRE_LIBS = @X_PRE_LIBS@ +ZIP = @ZIP@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_ANTLR = @ac_ct_ANTLR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +default_toolkit = @default_toolkit@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +glibjdir = @glibjdir@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +multi_basedir = @multi_basedir@ +nativeexeclibdir = @nativeexeclibdir@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +toolexeclibdir = @toolexeclibdir@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +uudecode = @uudecode@ +vm_classes = @vm_classes@ +nativeexeclib_LTLIBRARIES = libjavautil.la +libjavautil_la_SOURCES = java_util_VMTimeZone.c +AM_LDFLAGS = @CLASSPATH_MODULE@ +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ +AM_CFLAGS = @WARNING_CFLAGS@ @STRICT_WARNING_CFLAGS@ @ERROR_CFLAGS@ \ + @EXTRA_CFLAGS@ + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu native/jni/java-util/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu native/jni/java-util/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-nativeexeclibLTLIBRARIES: $(nativeexeclib_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(nativeexeclibdir)" || $(MKDIR_P) "$(DESTDIR)$(nativeexeclibdir)" + @list='$(nativeexeclib_LTLIBRARIES)'; test -n "$(nativeexeclibdir)" || list=; \ + list2=; for p in $$list; do \ + if test -f $$p; then \ + list2="$$list2 $$p"; \ + else :; fi; \ + done; \ + test -z "$$list2" || { \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(nativeexeclibdir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(nativeexeclibdir)"; \ + } + +uninstall-nativeexeclibLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(nativeexeclib_LTLIBRARIES)'; test -n "$(nativeexeclibdir)" || list=; \ + for p in $$list; do \ + $(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(nativeexeclibdir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(nativeexeclibdir)/$$f"; \ + done + +clean-nativeexeclibLTLIBRARIES: + -test -z "$(nativeexeclib_LTLIBRARIES)" || rm -f $(nativeexeclib_LTLIBRARIES) + @list='$(nativeexeclib_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libjavautil.la: $(libjavautil_la_OBJECTS) $(libjavautil_la_DEPENDENCIES) + $(LINK) -rpath $(nativeexeclibdir) $(libjavautil_la_OBJECTS) $(libjavautil_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/java_util_VMTimeZone.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) +installdirs: + for dir in "$(DESTDIR)$(nativeexeclibdir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-nativeexeclibLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-nativeexeclibLTLIBRARIES + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-nativeexeclibLTLIBRARIES + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-nativeexeclibLTLIBRARIES ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags dvi dvi-am html html-am info info-am install \ + install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-nativeexeclibLTLIBRARIES install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-nativeexeclibLTLIBRARIES + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/libjava/classpath/native/jni/java-util/java_util_VMTimeZone.c b/libjava/classpath/native/jni/java-util/java_util_VMTimeZone.c new file mode 100644 index 000000000..a3a986d36 --- /dev/null +++ b/libjava/classpath/native/jni/java-util/java_util_VMTimeZone.c @@ -0,0 +1,223 @@ +/* VMTimeZone.c - Native method for java.util.VMTimeZone + Copyright (C) 1999, 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include "config.h" + +#if TIME_WITH_SYS_TIME +# include +# include +#else +# if HAVE_SYS_TIME_H +# include +# else +# include +# endif +#endif + +#include +#include +#include + +#include + +#include "java_util_VMTimeZone.h" + +static size_t jint_to_charbuf (char *bufend, jint num); + +/** + * This method returns a time zone id string which is in the form + * (standard zone name) or (standard zone name)(GMT offset) or + * (standard zone name)(GMT offset)(daylight time zone name). The + * GMT offset can be in seconds, or where it is evenly divisible by + * 3600, then it can be in hours. The offset must be the time to + * add to the local time to get GMT. If a offset is given and the + * time zone observes daylight saving then the (daylight time zone + * name) must also be given (otherwise it is assumed the time zone + * does not observe any daylight savings). + *

+ * The result of this method is given to getDefaultTimeZone(String) + * which tries to map the time zone id to a known TimeZone. See + * that method on how the returned String is mapped to a real + * TimeZone object. + */ +JNIEXPORT jstring JNICALL +Java_java_util_VMTimeZone_getSystemTimeZoneId (JNIEnv * env, + jclass clazz + __attribute__ ((__unused__))) +{ + struct tm tim; +#ifndef HAVE_LOCALTIME_R + struct tm *lt_tim; +#endif +#ifdef HAVE_TM_ZONE + int month; +#endif + time_t current_time; + long tzoffset; + const char *tz1, *tz2; + char tzoff[11]; + size_t tz1_len, tz2_len, tzoff_len; + char *tzid; + jstring retval; + + time (¤t_time); +#ifdef HAVE_LOCALTIME_R + localtime_r (¤t_time, &tim); +#else + /* Fall back on non-thread safe localtime. */ + lt_tim = localtime (¤t_time); + memcpy (&tim, lt_tim, sizeof (struct tm)); +#endif + mktime (&tim); + +#ifdef HAVE_STRUCT_TM_TM_ZONE + /* We will cycle through the months to make sure we hit dst. */ + month = tim.tm_mon; + tz1 = tz2 = NULL; + while (tz1 == NULL || tz2 == NULL) + { + if (tim.tm_isdst > 0) + tz2 = tim.tm_zone; + else if (tz1 == NULL) + { + tz1 = tim.tm_zone; + month = tim.tm_mon; + } + + if (tz1 == NULL || tz2 == NULL) + { + tim.tm_mon++; + tim.tm_mon %= 12; + } + + if (tim.tm_mon == month && tz2 == NULL) + tz2 = ""; + else + mktime (&tim); + } + /* We want to make sure the tm struct we use later on is not dst. */ + tim.tm_mon = month; + mktime (&tim); +#elif defined (HAVE_TZNAME) + /* If dst is never used, tzname[1] is the empty string. */ + tzset (); + tz1 = tzname[0]; + tz2 = tzname[1]; +#else + /* Some targets have no concept of timezones. Assume GMT without dst. */ + tz1 = "GMT"; + tz2 = ""; +#endif + +#ifdef STRUCT_TM_HAS_GMTOFF + /* tm_gmtoff is the number of seconds that you must add to GMT to get + local time, we need the number of seconds to add to the local time + to get GMT. */ + tzoffset = -1L * tim.tm_gmtoff; +#elif HAVE_UNDERSCORE_TIMEZONE + /* On some systems _timezone is actually defined as time_t. */ + tzoffset = (long) _timezone; +#elif HAVE_TIMEZONE + /* timezone is secs WEST of UTC. */ + tzoffset = timezone; +#else + /* FIXME: there must be another global if neither tm_gmtoff nor timezone + is available, esp. if tzname is valid. + Richard Earnshaw has suggested using difftime to + calculate between gmtime and localtime (and accounting for possible + daylight savings time) as an alternative. */ + tzoffset = 0L; +#endif + + if ((tzoffset % 3600) == 0) + tzoffset = tzoffset / 3600; + + tz1_len = strlen (tz1); + tz2_len = strlen (tz2); + tzoff_len = jint_to_charbuf (tzoff + 11, tzoffset); + tzid = (char *) malloc (tz1_len + tz2_len + tzoff_len + 1); /* FIXME alloc */ + memcpy (tzid, tz1, tz1_len); + memcpy (tzid + tz1_len, tzoff + 11 - tzoff_len, tzoff_len); + memcpy (tzid + tz1_len + tzoff_len, tz2, tz2_len); + tzid[tz1_len + tzoff_len + tz2_len] = '\0'; + + retval = (*env)->NewStringUTF (env, tzid); + free (tzid); + + return retval; +} + +/* Put printed (decimal) representation of NUM in a buffer. + BUFEND marks the end of the buffer, which must be at least 11 chars long. + Returns the COUNT of chars written. The result is in + (BUFEND - COUNT) (inclusive) upto (BUFEND) (exclusive). + + Note that libgcj has a slightly different version called _Jv_FormatInt + that works on jchar buffers. +*/ + +static size_t +jint_to_charbuf (char *bufend, jint num) +{ + register char *ptr = bufend; + jboolean isNeg; + if (num < 0) + { + isNeg = JNI_TRUE; + num = -(num); + if (num < 0) + { + /* Must be MIN_VALUE, so handle this special case. + FIXME use 'unsigned jint' for num. */ + *--ptr = '8'; + num = 214748364; + } + } + else + isNeg = JNI_FALSE; + + do + { + *--ptr = (char) ((int) '0' + (num % 10)); + num /= 10; + } + while (num > 0); + + if (isNeg) + *--ptr = '-'; + return bufend - ptr; +} diff --git a/libjava/classpath/native/jni/midi-alsa/.cvsignore b/libjava/classpath/native/jni/midi-alsa/.cvsignore new file mode 100644 index 000000000..483b27744 --- /dev/null +++ b/libjava/classpath/native/jni/midi-alsa/.cvsignore @@ -0,0 +1,9 @@ +*.o +*.a +*.lo +*.la +.libs +.depsMakefile +Makefile.in +Makefile +.deps diff --git a/libjava/classpath/native/jni/midi-alsa/Makefile.am b/libjava/classpath/native/jni/midi-alsa/Makefile.am new file mode 100644 index 000000000..5ea89f306 --- /dev/null +++ b/libjava/classpath/native/jni/midi-alsa/Makefile.am @@ -0,0 +1,13 @@ +nativeexeclib_LTLIBRARIES = libgjsmalsa.la + +libgjsmalsa_la_SOURCES = gnu_javax_sound_midi_alsa_AlsaMidiSequencerDevice.c \ +gnu_javax_sound_midi_alsa_AlsaPortDevice.c \ +gnu_javax_sound_midi_alsa_AlsaMidiDeviceProvider.c + +libgjsmalsa_la_LIBADD = -lasound +libgjsmalsa_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version + +AM_LDFLAGS = @CLASSPATH_MODULE@ +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ `pkg-config --cflags-only-I alsa` +AM_CFLAGS = @WARNING_CFLAGS@ @STRICT_WARNING_CFLAGS@ @ERROR_CFLAGS@ `pkg-config --cflags-only-other alsa` \ + @EXTRA_CFLAGS@ diff --git a/libjava/classpath/native/jni/midi-alsa/Makefile.in b/libjava/classpath/native/jni/midi-alsa/Makefile.in new file mode 100644 index 000000000..eb46acbfe --- /dev/null +++ b/libjava/classpath/native/jni/midi-alsa/Makefile.in @@ -0,0 +1,619 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +subdir = native/jni/midi-alsa +DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/../../config/depstand.m4 \ + $(top_srcdir)/../../config/lead-dot.m4 \ + $(top_srcdir)/../../config/lib-ld.m4 \ + $(top_srcdir)/../../config/lib-link.m4 \ + $(top_srcdir)/../../config/lib-prefix.m4 \ + $(top_srcdir)/../../config/multi.m4 \ + $(top_srcdir)/../../config/no-executables.m4 \ + $(top_srcdir)/../../config/override.m4 \ + $(top_srcdir)/../../libtool.m4 \ + $(top_srcdir)/../../ltoptions.m4 \ + $(top_srcdir)/../../ltsugar.m4 \ + $(top_srcdir)/../../ltversion.m4 \ + $(top_srcdir)/../../lt~obsolete.m4 \ + $(top_srcdir)/m4/ac_prog_antlr.m4 \ + $(top_srcdir)/m4/ac_prog_java.m4 \ + $(top_srcdir)/m4/ac_prog_java_works.m4 \ + $(top_srcdir)/m4/ac_prog_javac.m4 \ + $(top_srcdir)/m4/ac_prog_javac_works.m4 \ + $(top_srcdir)/m4/acattribute.m4 $(top_srcdir)/m4/accross.m4 \ + $(top_srcdir)/m4/acinclude.m4 \ + $(top_srcdir)/m4/ax_create_stdint_h.m4 \ + $(top_srcdir)/m4/ax_func_which_gethostbyname_r.m4 \ + $(top_srcdir)/m4/gcc_attribute.m4 $(top_srcdir)/m4/iconv.m4 \ + $(top_srcdir)/m4/pkg.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/../../mkinstalldirs +CONFIG_HEADER = $(top_builddir)/include/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__installdirs = "$(DESTDIR)$(nativeexeclibdir)" +LTLIBRARIES = $(nativeexeclib_LTLIBRARIES) +libgjsmalsa_la_DEPENDENCIES = +am_libgjsmalsa_la_OBJECTS = \ + gnu_javax_sound_midi_alsa_AlsaMidiSequencerDevice.lo \ + gnu_javax_sound_midi_alsa_AlsaPortDevice.lo \ + gnu_javax_sound_midi_alsa_AlsaMidiDeviceProvider.lo +libgjsmalsa_la_OBJECTS = $(am_libgjsmalsa_la_OBJECTS) +libgjsmalsa_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(libgjsmalsa_la_LDFLAGS) $(LDFLAGS) -o $@ +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/include +depcomp = $(SHELL) $(top_srcdir)/../../depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(libgjsmalsa_la_SOURCES) +ETAGS = etags +CTAGS = ctags +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +ANTLR = @ANTLR@ +ANTLR_JAR = @ANTLR_JAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CAIRO_CFLAGS = @CAIRO_CFLAGS@ +CAIRO_LIBS = @CAIRO_LIBS@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CLASSPATH_CONVENIENCE = @CLASSPATH_CONVENIENCE@ +CLASSPATH_INCLUDES = @CLASSPATH_INCLUDES@ +CLASSPATH_MODULE = @CLASSPATH_MODULE@ +COLLECTIONS_PREFIX = @COLLECTIONS_PREFIX@ +CP = @CP@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DATE = @DATE@ +DEFAULT_PREFS_PEER = @DEFAULT_PREFS_PEER@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +ECJ_JAR = @ECJ_JAR@ +EGREP = @EGREP@ +ERROR_CFLAGS = @ERROR_CFLAGS@ +EXAMPLESDIR = @EXAMPLESDIR@ +EXEEXT = @EXEEXT@ +EXTRA_CFLAGS = @EXTRA_CFLAGS@ +FGREP = @FGREP@ +FIND = @FIND@ +FREETYPE2_CFLAGS = @FREETYPE2_CFLAGS@ +FREETYPE2_LIBS = @FREETYPE2_LIBS@ +GCONF_CFLAGS = @GCONF_CFLAGS@ +GCONF_LIBS = @GCONF_LIBS@ +GDK_CFLAGS = @GDK_CFLAGS@ +GDK_LIBS = @GDK_LIBS@ +GJDOC = @GJDOC@ +GLIB_CFLAGS = @GLIB_CFLAGS@ +GLIB_LIBS = @GLIB_LIBS@ +GMP_CFLAGS = @GMP_CFLAGS@ +GMP_LIBS = @GMP_LIBS@ +GREP = @GREP@ +GSTREAMER_BASE_CFLAGS = @GSTREAMER_BASE_CFLAGS@ +GSTREAMER_BASE_LIBS = @GSTREAMER_BASE_LIBS@ +GSTREAMER_CFLAGS = @GSTREAMER_CFLAGS@ +GSTREAMER_FILE_READER = @GSTREAMER_FILE_READER@ +GSTREAMER_LIBS = @GSTREAMER_LIBS@ +GSTREAMER_MIXER_PROVIDER = @GSTREAMER_MIXER_PROVIDER@ +GSTREAMER_PLUGINS_BASE_CFLAGS = @GSTREAMER_PLUGINS_BASE_CFLAGS@ +GSTREAMER_PLUGINS_BASE_LIBS = @GSTREAMER_PLUGINS_BASE_LIBS@ +GST_PLUGIN_LDFLAGS = @GST_PLUGIN_LDFLAGS@ +GTK_CFLAGS = @GTK_CFLAGS@ +GTK_LIBS = @GTK_LIBS@ +INIT_LOAD_LIBRARY = @INIT_LOAD_LIBRARY@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAR = @JAR@ +JAVA = @JAVA@ +JAVAC = @JAVAC@ +JAVAC_IS_GCJ = @JAVAC_IS_GCJ@ +JAVAC_MEM_OPT = @JAVAC_MEM_OPT@ +JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION = @JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION@ +JAY = @JAY@ +JAY_SKELETON = @JAY_SKELETON@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBDEBUG = @LIBDEBUG@ +LIBICONV = @LIBICONV@ +LIBMAGIC = @LIBMAGIC@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBVERSION = @LIBVERSION@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBICONV = @LTLIBICONV@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MKDIR = @MKDIR@ +MKDIR_P = @MKDIR_P@ +MOC = @MOC@ +MOZILLA_CFLAGS = @MOZILLA_CFLAGS@ +MOZILLA_LIBS = @MOZILLA_LIBS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PANGOFT2_CFLAGS = @PANGOFT2_CFLAGS@ +PANGOFT2_LIBS = @PANGOFT2_LIBS@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PATH_TO_ESCHER = @PATH_TO_ESCHER@ +PATH_TO_GLIBJ_ZIP = @PATH_TO_GLIBJ_ZIP@ +PERL = @PERL@ +PKG_CONFIG = @PKG_CONFIG@ +PLUGIN_DIR = @PLUGIN_DIR@ +QT_CFLAGS = @QT_CFLAGS@ +QT_LIBS = @QT_LIBS@ +RANLIB = @RANLIB@ +REMOVE = @REMOVE@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRICT_WARNING_CFLAGS = @STRICT_WARNING_CFLAGS@ +STRIP = @STRIP@ +TOOLSDIR = @TOOLSDIR@ +USER_JAVAH = @USER_JAVAH@ +VERSION = @VERSION@ +WANT_NATIVE_BIG_INTEGER = @WANT_NATIVE_BIG_INTEGER@ +WARNING_CFLAGS = @WARNING_CFLAGS@ +XMKMF = @XMKMF@ +XML_CFLAGS = @XML_CFLAGS@ +XML_LIBS = @XML_LIBS@ +XSLT_CFLAGS = @XSLT_CFLAGS@ +XSLT_LIBS = @XSLT_LIBS@ +XTEST_LIBS = @XTEST_LIBS@ +X_CFLAGS = @X_CFLAGS@ +X_EXTRA_LIBS = @X_EXTRA_LIBS@ +X_LIBS = @X_LIBS@ +X_PRE_LIBS = @X_PRE_LIBS@ +ZIP = @ZIP@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_ANTLR = @ac_ct_ANTLR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +default_toolkit = @default_toolkit@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +glibjdir = @glibjdir@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +multi_basedir = @multi_basedir@ +nativeexeclibdir = @nativeexeclibdir@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +toolexeclibdir = @toolexeclibdir@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +uudecode = @uudecode@ +vm_classes = @vm_classes@ +nativeexeclib_LTLIBRARIES = libgjsmalsa.la +libgjsmalsa_la_SOURCES = gnu_javax_sound_midi_alsa_AlsaMidiSequencerDevice.c \ +gnu_javax_sound_midi_alsa_AlsaPortDevice.c \ +gnu_javax_sound_midi_alsa_AlsaMidiDeviceProvider.c + +libgjsmalsa_la_LIBADD = -lasound +libgjsmalsa_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version +AM_LDFLAGS = @CLASSPATH_MODULE@ +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ `pkg-config --cflags-only-I alsa` +AM_CFLAGS = @WARNING_CFLAGS@ @STRICT_WARNING_CFLAGS@ @ERROR_CFLAGS@ `pkg-config --cflags-only-other alsa` \ + @EXTRA_CFLAGS@ + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu native/jni/midi-alsa/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu native/jni/midi-alsa/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-nativeexeclibLTLIBRARIES: $(nativeexeclib_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(nativeexeclibdir)" || $(MKDIR_P) "$(DESTDIR)$(nativeexeclibdir)" + @list='$(nativeexeclib_LTLIBRARIES)'; test -n "$(nativeexeclibdir)" || list=; \ + list2=; for p in $$list; do \ + if test -f $$p; then \ + list2="$$list2 $$p"; \ + else :; fi; \ + done; \ + test -z "$$list2" || { \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(nativeexeclibdir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(nativeexeclibdir)"; \ + } + +uninstall-nativeexeclibLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(nativeexeclib_LTLIBRARIES)'; test -n "$(nativeexeclibdir)" || list=; \ + for p in $$list; do \ + $(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(nativeexeclibdir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(nativeexeclibdir)/$$f"; \ + done + +clean-nativeexeclibLTLIBRARIES: + -test -z "$(nativeexeclib_LTLIBRARIES)" || rm -f $(nativeexeclib_LTLIBRARIES) + @list='$(nativeexeclib_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libgjsmalsa.la: $(libgjsmalsa_la_OBJECTS) $(libgjsmalsa_la_DEPENDENCIES) + $(libgjsmalsa_la_LINK) -rpath $(nativeexeclibdir) $(libgjsmalsa_la_OBJECTS) $(libgjsmalsa_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_javax_sound_midi_alsa_AlsaMidiDeviceProvider.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_javax_sound_midi_alsa_AlsaMidiSequencerDevice.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_javax_sound_midi_alsa_AlsaPortDevice.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) +installdirs: + for dir in "$(DESTDIR)$(nativeexeclibdir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-nativeexeclibLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-nativeexeclibLTLIBRARIES + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-nativeexeclibLTLIBRARIES + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-nativeexeclibLTLIBRARIES ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags dvi dvi-am html html-am info info-am install \ + install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-nativeexeclibLTLIBRARIES install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-nativeexeclibLTLIBRARIES + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/libjava/classpath/native/jni/midi-alsa/gnu_javax_sound_midi_alsa_AlsaMidiDeviceProvider.c b/libjava/classpath/native/jni/midi-alsa/gnu_javax_sound_midi_alsa_AlsaMidiDeviceProvider.c new file mode 100644 index 000000000..f740b276a --- /dev/null +++ b/libjava/classpath/native/jni/midi-alsa/gnu_javax_sound_midi_alsa_AlsaMidiDeviceProvider.c @@ -0,0 +1,148 @@ +/* gnu_javax_sound_midi_alsa_AlsaMidiDeviceProvider.c + Copyright (C) 2005 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + +#include +#include + +#include + +static snd_seq_t *seq; + +JNIEXPORT void JNICALL +Java_gnu_javax_sound_midi_alsa_AlsaMidiDeviceProvider_init_1 +(JNIEnv *env __attribute__((unused)), jobject this __attribute__((unused))) +{ + int rc = snd_seq_open (&seq, "default", SND_SEQ_OPEN_DUPLEX, SND_SEQ_NONBLOCK); + if (rc < 0) + abort (); + snd_seq_set_client_name(seq, "gnu.javax.sound.midi.alsa"); +} + +/** + * Return a CLAZZ[] filled with ports matching TYPE. + */ +static jobjectArray +getPortDeviceInfo (JNIEnv *env, unsigned type, const char *clazz) +{ + jobjectArray rarray; + snd_seq_client_info_t *cinfo; + snd_seq_port_info_t *pinfo; + int client; + int count = 0; + jclass icls; + jmethodID mid; + + snd_seq_client_info_alloca(&cinfo); + snd_seq_port_info_alloca(&pinfo); + + /* First, count the number of input devices. */ + snd_seq_client_info_set_client (cinfo, -1); + while (snd_seq_query_next_client (seq, cinfo) >= 0) + { + client = snd_seq_client_info_get_client (cinfo); + if (client == 0) + continue; + snd_seq_port_info_set_client (pinfo, client); + snd_seq_port_info_set_port (pinfo, -1); + while (snd_seq_query_next_port (seq, pinfo) >= 0) + { + if ((snd_seq_port_info_get_capability (pinfo) & type) != type) + continue; + count++; + } + } + + icls = (*env)->FindClass(env, clazz); + mid = (*env)->GetMethodID(env, icls, "", + "(Ljava/lang/String;Ljava/lang/String;JJ)V"); + + rarray = (jobjectArray) (*env)->NewObjectArray(env, count, icls, NULL); + + /* Now, populate our array. */ + count = 0; + snd_seq_client_info_set_client (cinfo, -1); + while (snd_seq_query_next_client (seq, cinfo) >= 0) + { + const char *client_name; + client = snd_seq_client_info_get_client (cinfo); + if (client == 0) + continue; + snd_seq_port_info_set_client (pinfo, client); + snd_seq_port_info_set_port (pinfo, -1); + + client_name = snd_seq_client_info_get_name (cinfo); + + while (snd_seq_query_next_port (seq, pinfo) >= 0) + { + const char *port_name; + + if ((snd_seq_port_info_get_capability (pinfo) & type) != type) + continue; + + port_name = snd_seq_port_info_get_name (pinfo); + + (*env)->SetObjectArrayElement(env, rarray, count, + (*env)->NewObject (env, icls, mid, + (*env)->NewStringUTF (env, client_name), + (*env)->NewStringUTF (env, port_name), + (jlong) snd_seq_port_info_get_client(pinfo), + (jlong) snd_seq_port_info_get_port(pinfo))); + count++; + } + } + + return rarray; +} + +JNIEXPORT jobjectArray JNICALL +Java_gnu_javax_sound_midi_alsa_AlsaMidiDeviceProvider_getInputDeviceInfo_1 + (JNIEnv *env, jobject this __attribute__((unused))) +{ + return getPortDeviceInfo (env, + (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ), + "gnu/javax/sound/midi/alsa/AlsaMidiDeviceProvider$AlsaInputPortInfo"); +} + +JNIEXPORT jobjectArray JNICALL +Java_gnu_javax_sound_midi_alsa_AlsaMidiDeviceProvider_getOutputDeviceInfo_1 + (JNIEnv *env, jobject this __attribute__((unused))) +{ + return getPortDeviceInfo (env, + (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE), + "gnu/javax/sound/midi/alsa/AlsaMidiDeviceProvider$AlsaOutputPortInfo"); +} + diff --git a/libjava/classpath/native/jni/midi-alsa/gnu_javax_sound_midi_alsa_AlsaMidiSequencerDevice.c b/libjava/classpath/native/jni/midi-alsa/gnu_javax_sound_midi_alsa_AlsaMidiSequencerDevice.c new file mode 100644 index 000000000..6e079d36c --- /dev/null +++ b/libjava/classpath/native/jni/midi-alsa/gnu_javax_sound_midi_alsa_AlsaMidiSequencerDevice.c @@ -0,0 +1,59 @@ +/* gnu_javax_sound_midi_alsa_AlsaMidiSequencerDevice.c + Copyright (C) 2005 + Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#include +#include + +JNIEXPORT jlong JNICALL +Java_gnu_javax_sound_midi_alsa_AlsaMidiSequencerDevice_open_1 + (JNIEnv *env __attribute__((unused)), jobject this __attribute__((unused))) +{ + /* Nothing yet. */ + return 555; +} + +JNIEXPORT void JNICALL +Java_gnu_javax_sound_midi_alsa_AlsaMidiSequencerDevice_close_1 + (JNIEnv *env __attribute__((unused)), + jobject this __attribute__((unused)), jlong s __attribute__((unused))) +{ + /* Nothing. */ +} + + diff --git a/libjava/classpath/native/jni/midi-alsa/gnu_javax_sound_midi_alsa_AlsaPortDevice.c b/libjava/classpath/native/jni/midi-alsa/gnu_javax_sound_midi_alsa_AlsaPortDevice.c new file mode 100644 index 000000000..d3e4f2b45 --- /dev/null +++ b/libjava/classpath/native/jni/midi-alsa/gnu_javax_sound_midi_alsa_AlsaPortDevice.c @@ -0,0 +1,149 @@ +/* gnu_javax_sound_midi_alsa_AlsaPortDevice.c - Native support + Copyright (C) 2005, 2010 + Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +#include +#include +#include + +#include + +JNIEXPORT void JNICALL +Java_gnu_javax_sound_midi_alsa_AlsaPortDevice_run_1receiver_1thread_1 + (JNIEnv *env, jobject this __attribute__((unused)), + jlong client, jlong port, jobject receiver) +{ + snd_seq_port_info_t *pinfo, *sinfo; + snd_seq_port_subscribe_t *subs; + snd_seq_addr_t sender, dest; + snd_seq_t *seq; + + snd_seq_port_info_alloca (&pinfo); + snd_seq_port_info_alloca (&sinfo); + snd_seq_port_subscribe_alloca (&subs); + + snd_seq_open (&seq, "default", SND_SEQ_OPEN_DUPLEX, SND_SEQ_NONBLOCK); + + snd_seq_port_info_set_capability (pinfo, SND_SEQ_PORT_CAP_WRITE); + snd_seq_port_info_set_type (pinfo, SND_SEQ_PORT_TYPE_MIDI_GENERIC); + + snd_seq_create_port (seq, pinfo); + + sender.client = (int) client; + sender.port = (int) port; + dest.client = snd_seq_port_info_get_client(pinfo); + dest.port = snd_seq_port_info_get_port(pinfo); + + snd_seq_port_subscribe_set_sender (subs, &sender); + snd_seq_port_subscribe_set_dest (subs, &dest); + snd_seq_subscribe_port(seq, subs); + + { + int npfd; + struct pollfd *pfd; + jclass smcls, rcls; + jmethodID sminit, rsend; + jbyteArray mba; + jbyte *ba; + jobject msg; + jlong jtimestamp; + + npfd = snd_seq_poll_descriptors_count (seq, POLLIN); + pfd = (struct pollfd *) alloca (npfd * sizeof (struct pollfd)); + snd_seq_poll_descriptors (seq, pfd, npfd, POLLIN); + + smcls = (*env)->FindClass(env, "javax/sound/midi/ShortMessage"); + sminit = (*env)->GetMethodID(env, smcls, "", "([B)V"); + + rcls = (*env)->FindClass(env, "javax/sound/midi/Receiver"); + rsend = (*env)->GetMethodID(env, rcls, "send", "(Ljavax/sound/midi/MidiMessage;J)V"); + + while (1) + { + if (poll (pfd, npfd, 100000) > 0) + { + snd_seq_event_t *ev; + + do + { + snd_seq_event_input (seq, &ev); + + if ((ev->flags & SND_SEQ_TIME_STAMP_MASK) == SND_SEQ_TIME_STAMP_TICK) + jtimestamp = (jlong) ev->time.tick; + else + jtimestamp = (jlong) ev->time.time.tv_sec * (jlong) 1000000000 + + (jlong) ev->time.time.tv_nsec; + + switch (ev->type) + { + case SND_SEQ_EVENT_NOTEON: + mba = (*env)->NewByteArray (env, 3); + ba = (*env)->GetByteArrayElements (env, mba, 0); + ba[0] = 0x90 + ev->data.control.channel; + ba[1] = ev->data.note.note; + ba[2] = ev->data.note.velocity; + (*env)->ReleaseByteArrayElements (env, mba, ba, 0); + msg = (*env)->NewObject(env, smcls, sminit, mba); + (*env)->CallObjectMethod(env, receiver, + rsend, msg, jtimestamp); + break; + + case SND_SEQ_EVENT_CONTROLLER: + mba = (*env)->NewByteArray (env, 3); + ba = (*env)->GetByteArrayElements (env, mba, 0); + ba[0] = 0xB0 + ev->data.control.channel; + ba[1] = ev->data.control.param; + ba[2] = ev->data.control.value; + (*env)->ReleaseByteArrayElements (env, mba, ba, 0); + msg = (*env)->NewObject(env, smcls, sminit, mba); + (*env)->CallObjectMethod(env, receiver, + rsend, msg, jtimestamp); + break; + + default: + printf ("UNKNOWN EVENT 0x%x\n", ev->type); + break; + } + + snd_seq_free_event(ev); + } + while (snd_seq_event_input_pending (seq, 0) > 0); + } + } + } +} diff --git a/libjava/classpath/native/jni/midi-dssi/.cvsignore b/libjava/classpath/native/jni/midi-dssi/.cvsignore new file mode 100644 index 000000000..ac18ca272 --- /dev/null +++ b/libjava/classpath/native/jni/midi-dssi/.cvsignore @@ -0,0 +1,9 @@ +*.o +*.a +*.lo +*.la +.libs +.depsMakefile +Makefile.in +.deps +Makefile diff --git a/libjava/classpath/native/jni/midi-dssi/Makefile.am b/libjava/classpath/native/jni/midi-dssi/Makefile.am new file mode 100644 index 000000000..ee12bf2e9 --- /dev/null +++ b/libjava/classpath/native/jni/midi-dssi/Makefile.am @@ -0,0 +1,15 @@ +nativeexeclib_LTLIBRARIES = libgjsmdssi.la + +libgjsmdssi_la_SOURCES = gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider.c \ + gnu_javax_sound_midi_dssi_DSSISynthesizer.c \ + dssi_data.h + +libgjsmdssi_la_LIBADD = $(top_builddir)/native/jni/classpath/jcl.lo -ljack +libgjsmdssi_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version + +AM_LDFLAGS = @CLASSPATH_MODULE@ +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ +# No STRICT_WARNING_CFLAGS here as we use dlsym to load the address of +# a function,and ISO C prohibits casting void pointers, like those returned +# by dlsym, to function pointers. +AM_CFLAGS = @WARNING_CFLAGS@ @ERROR_CFLAGS@ @EXTRA_CFLAGS@ diff --git a/libjava/classpath/native/jni/midi-dssi/Makefile.in b/libjava/classpath/native/jni/midi-dssi/Makefile.in new file mode 100644 index 000000000..7eed5df96 --- /dev/null +++ b/libjava/classpath/native/jni/midi-dssi/Makefile.in @@ -0,0 +1,619 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +subdir = native/jni/midi-dssi +DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/../../config/depstand.m4 \ + $(top_srcdir)/../../config/lead-dot.m4 \ + $(top_srcdir)/../../config/lib-ld.m4 \ + $(top_srcdir)/../../config/lib-link.m4 \ + $(top_srcdir)/../../config/lib-prefix.m4 \ + $(top_srcdir)/../../config/multi.m4 \ + $(top_srcdir)/../../config/no-executables.m4 \ + $(top_srcdir)/../../config/override.m4 \ + $(top_srcdir)/../../libtool.m4 \ + $(top_srcdir)/../../ltoptions.m4 \ + $(top_srcdir)/../../ltsugar.m4 \ + $(top_srcdir)/../../ltversion.m4 \ + $(top_srcdir)/../../lt~obsolete.m4 \ + $(top_srcdir)/m4/ac_prog_antlr.m4 \ + $(top_srcdir)/m4/ac_prog_java.m4 \ + $(top_srcdir)/m4/ac_prog_java_works.m4 \ + $(top_srcdir)/m4/ac_prog_javac.m4 \ + $(top_srcdir)/m4/ac_prog_javac_works.m4 \ + $(top_srcdir)/m4/acattribute.m4 $(top_srcdir)/m4/accross.m4 \ + $(top_srcdir)/m4/acinclude.m4 \ + $(top_srcdir)/m4/ax_create_stdint_h.m4 \ + $(top_srcdir)/m4/ax_func_which_gethostbyname_r.m4 \ + $(top_srcdir)/m4/gcc_attribute.m4 $(top_srcdir)/m4/iconv.m4 \ + $(top_srcdir)/m4/pkg.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/../../mkinstalldirs +CONFIG_HEADER = $(top_builddir)/include/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__installdirs = "$(DESTDIR)$(nativeexeclibdir)" +LTLIBRARIES = $(nativeexeclib_LTLIBRARIES) +libgjsmdssi_la_DEPENDENCIES = \ + $(top_builddir)/native/jni/classpath/jcl.lo +am_libgjsmdssi_la_OBJECTS = \ + gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider.lo \ + gnu_javax_sound_midi_dssi_DSSISynthesizer.lo +libgjsmdssi_la_OBJECTS = $(am_libgjsmdssi_la_OBJECTS) +libgjsmdssi_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(libgjsmdssi_la_LDFLAGS) $(LDFLAGS) -o $@ +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/include +depcomp = $(SHELL) $(top_srcdir)/../../depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(libgjsmdssi_la_SOURCES) +ETAGS = etags +CTAGS = ctags +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +ANTLR = @ANTLR@ +ANTLR_JAR = @ANTLR_JAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CAIRO_CFLAGS = @CAIRO_CFLAGS@ +CAIRO_LIBS = @CAIRO_LIBS@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CLASSPATH_CONVENIENCE = @CLASSPATH_CONVENIENCE@ +CLASSPATH_INCLUDES = @CLASSPATH_INCLUDES@ +CLASSPATH_MODULE = @CLASSPATH_MODULE@ +COLLECTIONS_PREFIX = @COLLECTIONS_PREFIX@ +CP = @CP@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DATE = @DATE@ +DEFAULT_PREFS_PEER = @DEFAULT_PREFS_PEER@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +ECJ_JAR = @ECJ_JAR@ +EGREP = @EGREP@ +ERROR_CFLAGS = @ERROR_CFLAGS@ +EXAMPLESDIR = @EXAMPLESDIR@ +EXEEXT = @EXEEXT@ +EXTRA_CFLAGS = @EXTRA_CFLAGS@ +FGREP = @FGREP@ +FIND = @FIND@ +FREETYPE2_CFLAGS = @FREETYPE2_CFLAGS@ +FREETYPE2_LIBS = @FREETYPE2_LIBS@ +GCONF_CFLAGS = @GCONF_CFLAGS@ +GCONF_LIBS = @GCONF_LIBS@ +GDK_CFLAGS = @GDK_CFLAGS@ +GDK_LIBS = @GDK_LIBS@ +GJDOC = @GJDOC@ +GLIB_CFLAGS = @GLIB_CFLAGS@ +GLIB_LIBS = @GLIB_LIBS@ +GMP_CFLAGS = @GMP_CFLAGS@ +GMP_LIBS = @GMP_LIBS@ +GREP = @GREP@ +GSTREAMER_BASE_CFLAGS = @GSTREAMER_BASE_CFLAGS@ +GSTREAMER_BASE_LIBS = @GSTREAMER_BASE_LIBS@ +GSTREAMER_CFLAGS = @GSTREAMER_CFLAGS@ +GSTREAMER_FILE_READER = @GSTREAMER_FILE_READER@ +GSTREAMER_LIBS = @GSTREAMER_LIBS@ +GSTREAMER_MIXER_PROVIDER = @GSTREAMER_MIXER_PROVIDER@ +GSTREAMER_PLUGINS_BASE_CFLAGS = @GSTREAMER_PLUGINS_BASE_CFLAGS@ +GSTREAMER_PLUGINS_BASE_LIBS = @GSTREAMER_PLUGINS_BASE_LIBS@ +GST_PLUGIN_LDFLAGS = @GST_PLUGIN_LDFLAGS@ +GTK_CFLAGS = @GTK_CFLAGS@ +GTK_LIBS = @GTK_LIBS@ +INIT_LOAD_LIBRARY = @INIT_LOAD_LIBRARY@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAR = @JAR@ +JAVA = @JAVA@ +JAVAC = @JAVAC@ +JAVAC_IS_GCJ = @JAVAC_IS_GCJ@ +JAVAC_MEM_OPT = @JAVAC_MEM_OPT@ +JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION = @JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION@ +JAY = @JAY@ +JAY_SKELETON = @JAY_SKELETON@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBDEBUG = @LIBDEBUG@ +LIBICONV = @LIBICONV@ +LIBMAGIC = @LIBMAGIC@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBVERSION = @LIBVERSION@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBICONV = @LTLIBICONV@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MKDIR = @MKDIR@ +MKDIR_P = @MKDIR_P@ +MOC = @MOC@ +MOZILLA_CFLAGS = @MOZILLA_CFLAGS@ +MOZILLA_LIBS = @MOZILLA_LIBS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PANGOFT2_CFLAGS = @PANGOFT2_CFLAGS@ +PANGOFT2_LIBS = @PANGOFT2_LIBS@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PATH_TO_ESCHER = @PATH_TO_ESCHER@ +PATH_TO_GLIBJ_ZIP = @PATH_TO_GLIBJ_ZIP@ +PERL = @PERL@ +PKG_CONFIG = @PKG_CONFIG@ +PLUGIN_DIR = @PLUGIN_DIR@ +QT_CFLAGS = @QT_CFLAGS@ +QT_LIBS = @QT_LIBS@ +RANLIB = @RANLIB@ +REMOVE = @REMOVE@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRICT_WARNING_CFLAGS = @STRICT_WARNING_CFLAGS@ +STRIP = @STRIP@ +TOOLSDIR = @TOOLSDIR@ +USER_JAVAH = @USER_JAVAH@ +VERSION = @VERSION@ +WANT_NATIVE_BIG_INTEGER = @WANT_NATIVE_BIG_INTEGER@ +WARNING_CFLAGS = @WARNING_CFLAGS@ +XMKMF = @XMKMF@ +XML_CFLAGS = @XML_CFLAGS@ +XML_LIBS = @XML_LIBS@ +XSLT_CFLAGS = @XSLT_CFLAGS@ +XSLT_LIBS = @XSLT_LIBS@ +XTEST_LIBS = @XTEST_LIBS@ +X_CFLAGS = @X_CFLAGS@ +X_EXTRA_LIBS = @X_EXTRA_LIBS@ +X_LIBS = @X_LIBS@ +X_PRE_LIBS = @X_PRE_LIBS@ +ZIP = @ZIP@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_ANTLR = @ac_ct_ANTLR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +default_toolkit = @default_toolkit@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +glibjdir = @glibjdir@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +multi_basedir = @multi_basedir@ +nativeexeclibdir = @nativeexeclibdir@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +toolexeclibdir = @toolexeclibdir@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +uudecode = @uudecode@ +vm_classes = @vm_classes@ +nativeexeclib_LTLIBRARIES = libgjsmdssi.la +libgjsmdssi_la_SOURCES = gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider.c \ + gnu_javax_sound_midi_dssi_DSSISynthesizer.c \ + dssi_data.h + +libgjsmdssi_la_LIBADD = $(top_builddir)/native/jni/classpath/jcl.lo -ljack +libgjsmdssi_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version +AM_LDFLAGS = @CLASSPATH_MODULE@ +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ +# No STRICT_WARNING_CFLAGS here as we use dlsym to load the address of +# a function,and ISO C prohibits casting void pointers, like those returned +# by dlsym, to function pointers. +AM_CFLAGS = @WARNING_CFLAGS@ @ERROR_CFLAGS@ @EXTRA_CFLAGS@ +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu native/jni/midi-dssi/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu native/jni/midi-dssi/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-nativeexeclibLTLIBRARIES: $(nativeexeclib_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(nativeexeclibdir)" || $(MKDIR_P) "$(DESTDIR)$(nativeexeclibdir)" + @list='$(nativeexeclib_LTLIBRARIES)'; test -n "$(nativeexeclibdir)" || list=; \ + list2=; for p in $$list; do \ + if test -f $$p; then \ + list2="$$list2 $$p"; \ + else :; fi; \ + done; \ + test -z "$$list2" || { \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(nativeexeclibdir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(nativeexeclibdir)"; \ + } + +uninstall-nativeexeclibLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(nativeexeclib_LTLIBRARIES)'; test -n "$(nativeexeclibdir)" || list=; \ + for p in $$list; do \ + $(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(nativeexeclibdir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(nativeexeclibdir)/$$f"; \ + done + +clean-nativeexeclibLTLIBRARIES: + -test -z "$(nativeexeclib_LTLIBRARIES)" || rm -f $(nativeexeclib_LTLIBRARIES) + @list='$(nativeexeclib_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libgjsmdssi.la: $(libgjsmdssi_la_OBJECTS) $(libgjsmdssi_la_DEPENDENCIES) + $(libgjsmdssi_la_LINK) -rpath $(nativeexeclibdir) $(libgjsmdssi_la_OBJECTS) $(libgjsmdssi_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_javax_sound_midi_dssi_DSSISynthesizer.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) +installdirs: + for dir in "$(DESTDIR)$(nativeexeclibdir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-nativeexeclibLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-nativeexeclibLTLIBRARIES + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-nativeexeclibLTLIBRARIES + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-nativeexeclibLTLIBRARIES ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags dvi dvi-am html html-am info info-am install \ + install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-nativeexeclibLTLIBRARIES install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-nativeexeclibLTLIBRARIES + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/libjava/classpath/native/jni/midi-dssi/README b/libjava/classpath/native/jni/midi-dssi/README new file mode 100644 index 000000000..6913414ff --- /dev/null +++ b/libjava/classpath/native/jni/midi-dssi/README @@ -0,0 +1,134 @@ +The file native/jni/midi-dssi/gnu_javax_sound_midi_dssi_DSSISynthesizer.c +contains two functions (get_port_default and set_control) derived from +example code in the DSSI distribution (http://dssi.sourceforge.net). +The original DSSI example code is distributed under the following +terms: + + Copyright 2004 Chris Cannam, Steve Harris and Sean Bolton. + + Permission to use, copy, modify, distribute, and sell this software + for any purpose is hereby granted without fee, provided that the + above copyright notice and this permission notice are included in + all copies or substantial portions of the software. + + +The rest of this file contain the original versions of these +functions. + + +LADSPA_Data get_port_default(const LADSPA_Descriptor *plugin, int port) +{ + LADSPA_PortRangeHint hint = plugin->PortRangeHints[port]; + float lower = hint.LowerBound * + (LADSPA_IS_HINT_SAMPLE_RATE(hint.HintDescriptor) ? sample_rate : 1.0f); + float upper = hint.UpperBound * + (LADSPA_IS_HINT_SAMPLE_RATE(hint.HintDescriptor) ? sample_rate : 1.0f); + + if (!LADSPA_IS_HINT_HAS_DEFAULT(hint.HintDescriptor)) { + if (!LADSPA_IS_HINT_BOUNDED_BELOW(hint.HintDescriptor) || + !LADSPA_IS_HINT_BOUNDED_ABOVE(hint.HintDescriptor)) { + /* No hint, its not bounded, wild guess */ + return 0.0f; + } + + if (lower <= 0.0f && upper >= 0.0f) { + /* It spans 0.0, 0.0 is often a good guess */ + return 0.0f; + } + + /* No clues, return minimum */ + return lower; + } + + /* Try all the easy ones */ + + if (LADSPA_IS_HINT_DEFAULT_0(hint.HintDescriptor)) { + return 0.0f; + } else if (LADSPA_IS_HINT_DEFAULT_1(hint.HintDescriptor)) { + return 1.0f; + } else if (LADSPA_IS_HINT_DEFAULT_100(hint.HintDescriptor)) { + return 100.0f; + } else if (LADSPA_IS_HINT_DEFAULT_440(hint.HintDescriptor)) { + return 440.0f; + } + + /* All the others require some bounds */ + + if (LADSPA_IS_HINT_BOUNDED_BELOW(hint.HintDescriptor)) { + if (LADSPA_IS_HINT_DEFAULT_MINIMUM(hint.HintDescriptor)) { + return lower; + } + } + if (LADSPA_IS_HINT_BOUNDED_ABOVE(hint.HintDescriptor)) { + if (LADSPA_IS_HINT_DEFAULT_MAXIMUM(hint.HintDescriptor)) { + return upper; + } + if (LADSPA_IS_HINT_BOUNDED_BELOW(hint.HintDescriptor)) { + if (LADSPA_IS_HINT_DEFAULT_LOW(hint.HintDescriptor)) { + return lower * 0.75f + upper * 0.25f; + } else if (LADSPA_IS_HINT_DEFAULT_MIDDLE(hint.HintDescriptor)) { + return lower * 0.5f + upper * 0.5f; + } else if (LADSPA_IS_HINT_DEFAULT_HIGH(hint.HintDescriptor)) { + return lower * 0.25f + upper * 0.75f; + } + } + } + + /* fallback */ + return 0.0f; +} + + +void +setControl(d3h_instance_t *instance, long controlIn, snd_seq_event_t *event) +{ + long port = pluginControlInPortNumbers[controlIn]; + + const LADSPA_Descriptor *p = instance->plugin->descriptor->LADSPA_Plugin; + + LADSPA_PortRangeHintDescriptor d = p->PortRangeHints[port].HintDescriptor; + + LADSPA_Data lb = p->PortRangeHints[port].LowerBound * + (LADSPA_IS_HINT_SAMPLE_RATE(p->PortRangeHints[port].HintDescriptor) ? + sample_rate : 1.0f); + + LADSPA_Data ub = p->PortRangeHints[port].UpperBound * + (LADSPA_IS_HINT_SAMPLE_RATE(p->PortRangeHints[port].HintDescriptor) ? + sample_rate : 1.0f); + + float value = (float)event->data.control.value; + + if (!LADSPA_IS_HINT_BOUNDED_BELOW(d)) { + if (!LADSPA_IS_HINT_BOUNDED_ABOVE(d)) { + /* unbounded: might as well leave the value alone. */ + } else { + /* bounded above only. just shift the range. */ + value = ub - 127.0f + value; + } + } else { + if (!LADSPA_IS_HINT_BOUNDED_ABOVE(d)) { + /* bounded below only. just shift the range. */ + value = lb + value; + } else { + /* bounded both ends. more interesting. */ + if (LADSPA_IS_HINT_LOGARITHMIC(d)) { + const float llb = logf(lb); + const float lub = logf(ub); + + value = expf(llb + ((lub - llb) * value / 127.0f)); + } else { + value = lb + ((ub - lb) * value / 127.0f); + } + } + } + + if (verbose) { + printf("%s: %s MIDI controller %d=%d -> control in %ld=%f\n", myName, + instance->friendly_name, event->data.control.param, + event->data.control.value, controlIn, value); + } + + pluginControlIns[controlIn] = value; + pluginPortUpdated[controlIn] = 1; +} + diff --git a/libjava/classpath/native/jni/midi-dssi/dssi_data.h b/libjava/classpath/native/jni/midi-dssi/dssi_data.h new file mode 100644 index 000000000..f8243f29b --- /dev/null +++ b/libjava/classpath/native/jni/midi-dssi/dssi_data.h @@ -0,0 +1,114 @@ +/* dssi_data.h - DSSI data + Copyright (C) 2005, 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "../classpath/jcl.h" + +/* Specify the size of the circular buffer. It only needs to be big + enough to hold the events that happen between jack callbacks (~ + 1/40th of a second). */ +#define EVENT_BUFFER_SIZE 1024 + +/* Every DSSI Synthesizer has one of these associated with it. The + Java class sees it as a "long" handle. */ + +typedef struct +{ + /* This is a handle to the dlopen'ed .so file containing the DSSI + synthesizer. */ + void *dlhandle; + + /* The function to call to get the DSS_Descriptor. */ + DSSI_Descriptor_Function fn; + + /* The descriptor for this synthesizer. See the dssi.h system + header. */ + const DSSI_Descriptor *desc; + + /* We currently open a jack client connection for every + synthesizer. */ + jack_client_t *jack_client; + + /* We currently only handle stereo jack connections. Output from + mono synthesizers is sent to both left and right ports. */ + jack_port_t *jack_left_output_port; + jack_port_t *jack_right_output_port; + + /* We use a circular buffer to hold MIDI events before processing + them in the jack audio processing callback function. */ + snd_seq_event_t midiEventBuffer[EVENT_BUFFER_SIZE]; + int midiEventReadIndex; + int midiEventWriteIndex; + + /* This is a handle the synthesizers underlying LADSPA structure. + See the ladspa.h system header for details. */ + LADSPA_Handle plugin_handle; + + /* These are buffers we pass to the DSSI Synthesizer for + filling. */ + float *left_buffer; + float *right_buffer; + + /* The number of input controls for this synth. */ + unsigned control_count; + + /* An array of control values, control_count in length. */ + LADSPA_Data *control_values; + + /* A mapping of MIDI controllers to control values. There are a + maximum of 128 MIDI controllers. */ + unsigned control_value_map[128]; + + /* A mapping of MIDI controllers to LADSPA ports. There are a + maximum of 128 MIDI controllers. */ + unsigned control_port_map[128]; + + /* The sample rate. */ + jack_nframes_t sample_rate; + +} dssi_data; + diff --git a/libjava/classpath/native/jni/midi-dssi/gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider.c b/libjava/classpath/native/jni/midi-dssi/gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider.c new file mode 100644 index 000000000..3cad45931 --- /dev/null +++ b/libjava/classpath/native/jni/midi-dssi/gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider.c @@ -0,0 +1,139 @@ +/* gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider.c - DSSI Provider + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include + +#include "dssi_data.h" + +void +Java_gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider_dlclose_1 + (JNIEnv *env, jclass clazz __attribute__((unused)), jlong sohandle) +{ + dssi_data *data = (dssi_data *) (long) sohandle; + dlclose (data->dlhandle); + JCL_free (env, data); +} + +jlong +Java_gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider_dlopen_1 + (JNIEnv *env, jclass clazz __attribute__((unused)), jstring name) +{ + const char *filename; + void *handle; + DSSI_Descriptor_Function fn; + dssi_data *data = 0; + + filename = JCL_jstring_to_cstring (env, name); + if (filename == NULL) + return (0); + + handle = dlopen(filename, RTLD_NOW); + + if (handle == 0) + goto done; + + fn = (DSSI_Descriptor_Function) dlsym(handle, "dssi_descriptor"); + + if (fn == 0) + { + dlclose(handle); + goto done; + } + + data = (dssi_data *) JCL_malloc(env, sizeof(dssi_data)); + data->dlhandle = handle; + data->fn = fn; + data->midiEventReadIndex = 0; + data->midiEventWriteIndex = 0; + + done: + JCL_free_cstring (env, name, filename); + return PTR_TO_JLONG(data); +} + +jlong +Java_gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider_getDSSIHandle_1 + (JNIEnv *env __attribute__((unused)), + jclass clazz __attribute__((unused)), jlong handle, jlong index) +{ + dssi_data *data = JLONG_TO_PTR(dssi_data,handle); + data->desc = (data->fn)(index); + return PTR_TO_JLONG(data->desc); +} + +jstring +Java_gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider_getDSSIName_1 + (JNIEnv *env, jclass clazz __attribute__((unused)), jlong handle) +{ + DSSI_Descriptor *desc = JLONG_TO_PTR(DSSI_Descriptor,handle); + const char *str = desc->LADSPA_Plugin->Name; + + return (*env)->NewStringUTF (env, str); +} + +jstring +Java_gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider_getDSSICopyright_1 + (JNIEnv *env, jclass clazz __attribute__((unused)), jlong handle) +{ + DSSI_Descriptor *desc = JLONG_TO_PTR(DSSI_Descriptor,handle); + const char *str = desc->LADSPA_Plugin->Copyright; + + return (*env)->NewStringUTF (env, str); +} + +jstring +Java_gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider_getDSSIVendor_1 + (JNIEnv *env, jclass clazz __attribute__((unused)), jlong handle) +{ + DSSI_Descriptor *desc = JLONG_TO_PTR(DSSI_Descriptor,handle); + const char *str = desc->LADSPA_Plugin->Maker; + + return (*env)->NewStringUTF (env, str); +} + +jstring +Java_gnu_javax_sound_midi_dssi_DSSIMidiDeviceProvider_getDSSILabel_1 + (JNIEnv *env, jclass clazz __attribute__((unused)), jlong handle) +{ + DSSI_Descriptor *desc = JLONG_TO_PTR(DSSI_Descriptor,handle); + const char *str = desc->LADSPA_Plugin->Label; + + return (*env)->NewStringUTF (env, str); +} + + diff --git a/libjava/classpath/native/jni/midi-dssi/gnu_javax_sound_midi_dssi_DSSISynthesizer.c b/libjava/classpath/native/jni/midi-dssi/gnu_javax_sound_midi_dssi_DSSISynthesizer.c new file mode 100644 index 000000000..ec1477ec8 --- /dev/null +++ b/libjava/classpath/native/jni/midi-dssi/gnu_javax_sound_midi_dssi_DSSISynthesizer.c @@ -0,0 +1,584 @@ +/* gnu_javax_sound_midi_dssi_DSSISynthesizer.c - DSSI Synth + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +/* The original get_port_default() and set_control() routines were + * copied from the DSSI source distribution and are covered by the + * following copyright and license... + * + * Copyright 2004 Chris Cannam, Steve Harris and Sean Bolton. + * + * Permission to use, copy, modify, distribute, and sell this software + * for any purpose is hereby granted without fee, provided that the + * above copyright notice and this permission notice are included in + * all copies or substantial portions of the software. + */ + +#include +#include +#include + +#include "dssi_data.h" + +/* Define this for debug output. */ +#undef DEBUG_DSSI_PROVIDER + +static void set_control (dssi_data *data, snd_seq_event_t *event); + + +/** + * The jack callback routine. + * + * This function is called by the jack audio system in its own thread + * whenever it needs new audio data. + * + */ +static int +process (jack_nframes_t nframes, void *arg) +{ + dssi_data *data = (dssi_data *) arg; + int index; + jack_default_audio_sample_t *buffer; + + /* Look through the event buffer to see if any control values + need changing. */ + for ( index = data->midiEventReadIndex; + index != data->midiEventWriteIndex; + index = (index + 1) % EVENT_BUFFER_SIZE) + { + if (data->midiEventBuffer[index].type == SND_SEQ_EVENT_CONTROLLER) + set_control (data, & data->midiEventBuffer[index]); + } + + if (data->desc->run_synth) + { + /* Call the synth audio processing routine. */ + data->desc->run_synth + (data->plugin_handle, + nframes, + &data->midiEventBuffer[data->midiEventReadIndex], + data->midiEventWriteIndex - data->midiEventReadIndex); + } + else + if (data->desc->run_multiple_synths) + { + snd_seq_event_t *events = + &data->midiEventBuffer[data->midiEventReadIndex]; + unsigned long event_count = + data->midiEventWriteIndex - data->midiEventReadIndex; + + /* Call the synth audio processing routine. */ + data->desc->run_multiple_synths + (1, + & (data->plugin_handle), + nframes, + &events, + &event_count); + } + + /* Update the read index on our circular buffer. */ + data->midiEventReadIndex = data->midiEventWriteIndex; + + /* Copy output from the synth to jack. + + FIXME: This is hack that only gets one channel from the synth and + send that to both jack ports (until we handle stero synths + properly). + + FIXME: Can we avoid this copying? */ + buffer = jack_port_get_buffer(data->jack_left_output_port, nframes); + memcpy (buffer, data->left_buffer, nframes * sizeof(LADSPA_Data)); + buffer = jack_port_get_buffer(data->jack_right_output_port, nframes); + memcpy (buffer, data->left_buffer, nframes * sizeof(LADSPA_Data)); + + return 0; +} + + +/** + * Calculate a reasonable default value for a specific control port. + * This is mostly copied from the DSSI example code. Copyright info + * is found at the top of this file. + * + */ +static LADSPA_Data +get_port_default (const LADSPA_Descriptor *plugin, + int port, jack_nframes_t sample_rate) +{ + LADSPA_PortRangeHint hint = plugin->PortRangeHints[port]; + float lower = hint.LowerBound * + (LADSPA_IS_HINT_SAMPLE_RATE(hint.HintDescriptor) ? sample_rate : 1.0f); + float upper = hint.UpperBound * + (LADSPA_IS_HINT_SAMPLE_RATE(hint.HintDescriptor) ? sample_rate : 1.0f); + + if (!LADSPA_IS_HINT_HAS_DEFAULT(hint.HintDescriptor)) + { + if (!LADSPA_IS_HINT_BOUNDED_BELOW(hint.HintDescriptor) || + !LADSPA_IS_HINT_BOUNDED_ABOVE(hint.HintDescriptor)) + { + /* No hint, its not bounded, wild guess */ + return 0.0f; + } + + if (lower <= 0.0f && upper >= 0.0f) + { + /* It spans 0.0, 0.0 is often a good guess */ + return 0.0f; + } + + /* No clues, return minimum */ + return lower; + } + + /* Try all the easy ones */ + + if (LADSPA_IS_HINT_DEFAULT_0(hint.HintDescriptor)) + return 0.0f; + else if (LADSPA_IS_HINT_DEFAULT_1(hint.HintDescriptor)) + return 1.0f; + else if (LADSPA_IS_HINT_DEFAULT_100(hint.HintDescriptor)) + return 100.0f; + else if (LADSPA_IS_HINT_DEFAULT_440(hint.HintDescriptor)) + return 440.0f; + + /* All the others require some bounds */ + + if (LADSPA_IS_HINT_BOUNDED_BELOW(hint.HintDescriptor) + && (LADSPA_IS_HINT_DEFAULT_MINIMUM(hint.HintDescriptor))) + return lower; + + if (LADSPA_IS_HINT_BOUNDED_ABOVE(hint.HintDescriptor)) + { + if (LADSPA_IS_HINT_DEFAULT_MAXIMUM(hint.HintDescriptor)) + return upper; + + if (LADSPA_IS_HINT_BOUNDED_BELOW(hint.HintDescriptor)) + { + if (LADSPA_IS_HINT_DEFAULT_LOW(hint.HintDescriptor)) + return lower * 0.75f + upper * 0.25f; + else if (LADSPA_IS_HINT_DEFAULT_MIDDLE(hint.HintDescriptor)) + return lower * 0.5f + upper * 0.5f; + else if (LADSPA_IS_HINT_DEFAULT_HIGH(hint.HintDescriptor)) + return lower * 0.25f + upper * 0.75f; + } + } + + /* fallback */ + return 0.0f; +} + +/** + * Set a control value by mapping the MIDI event to a suitable value + * for this control. + * This is mostly copied from the DSSI example code. Copyright info + * is found at the top of this file. + * + */ +static void +set_control(dssi_data *data, snd_seq_event_t *event) +{ + unsigned control = event->data.control.param; + unsigned port = data->control_port_map[control]; + + const LADSPA_Descriptor *p = data->desc->LADSPA_Plugin; + + LADSPA_PortRangeHintDescriptor d = p->PortRangeHints[port].HintDescriptor; + + LADSPA_Data lb = p->PortRangeHints[port].LowerBound * + (LADSPA_IS_HINT_SAMPLE_RATE(p->PortRangeHints[port].HintDescriptor) ? + data->sample_rate : 1.0f); + + LADSPA_Data ub = p->PortRangeHints[port].UpperBound * + (LADSPA_IS_HINT_SAMPLE_RATE(p->PortRangeHints[port].HintDescriptor) ? + data->sample_rate : 1.0f); + + float value = (float)event->data.control.value; + + if (!LADSPA_IS_HINT_BOUNDED_BELOW(d)) + { + if (!LADSPA_IS_HINT_BOUNDED_ABOVE(d)) + { + /* unbounded: might as well leave the value alone. */ + } + else + { + /* bounded above only. just shift the range. */ + value = ub - 127.0f + value; + } + } + else + { + if (!LADSPA_IS_HINT_BOUNDED_ABOVE(d)) + { + /* bounded below only. just shift the range. */ + value = lb + value; + } + else + { + /* bounded both ends. more interesting. */ + if (LADSPA_IS_HINT_LOGARITHMIC(d)) + { + const float llb = logf(lb); + const float lub = logf(ub); + + value = expf(llb + ((lub - llb) * value / 127.0f)); + } + else + { + value = lb + ((ub - lb) * value / 127.0f); + } + } + } + +#ifdef DEBUG_DSSI_PROVIDER + printf("MIDI controller %d=%d -> control in %u=%f\n", + event->data.control.param, + event->data.control.value, + data->control_value_map[control], value); +#endif + + data->control_values[data->control_value_map[control]] = value; +} + +/** + * Open a new synthesizer. This currently involves instantiating a + * new synth, creating a new jack client connection, and activating + * both. + * + */ +JNIEXPORT void JNICALL +Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_open_1 + (JNIEnv *env, jclass clazz __attribute__((unused)), jlong handle) +{ + unsigned int port_count, j, cindex; + const char **ports; + int controller = 0; + dssi_data *data = (dssi_data *) (long) handle; + if ((data->jack_client = jack_client_new (data->desc->LADSPA_Plugin->Label)) == 0) + { + /* JCL_ThrowException (env, "javax/sound/midi/MidiUnavailableException", */ + JCL_ThrowException (env, "java/io/IOException", + "can't create jack client"); + return; + } + + /* Get the jack sample rate, which may be used in default control port + value calculations. */ + data->sample_rate = jack_get_sample_rate (data->jack_client); + + data->plugin_handle = + (data->desc->LADSPA_Plugin->instantiate)(data->desc->LADSPA_Plugin, + data->sample_rate); + + if (jack_set_process_callback (data->jack_client, process, data) != 0) + { + JCL_ThrowException (env, "java/io/IOException", + "can't set jack process callback"); + return; + } + + data->jack_left_output_port = + jack_port_register (data->jack_client, "output_left", + JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); + data->jack_right_output_port = + jack_port_register (data->jack_client, "output_right", + JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); + + /* Count the number of controls and audio ouput ports. */ + port_count = data->control_count = 0; + for (j = 0; j < data->desc->LADSPA_Plugin->PortCount; j++) + { + LADSPA_PortDescriptor pod = + data->desc->LADSPA_Plugin->PortDescriptors[j]; + + if (LADSPA_IS_PORT_AUDIO(pod) && LADSPA_IS_PORT_OUTPUT(pod)) + port_count++; + else if (LADSPA_IS_PORT_CONTROL(pod) && LADSPA_IS_PORT_INPUT(pod)) + data->control_count++; + } + + /* Allocate the array of control values. */ + data->control_values = + (LADSPA_Data *) JCL_malloc (env, + data->control_count * sizeof (LADSPA_Data)); + + /* Initialize the MIDI control map. */ + memset (data->control_value_map, 0, data->control_count * sizeof(unsigned)); + + /* Create buffers for each port. */ + for (cindex = 0, j = 0; j < data->desc->LADSPA_Plugin->PortCount; j++) + { + LADSPA_PortDescriptor pod = + data->desc->LADSPA_Plugin->PortDescriptors[j]; + if (LADSPA_IS_PORT_AUDIO(pod) && LADSPA_IS_PORT_OUTPUT(pod)) + { + data->left_buffer = + (float *) calloc(jack_get_buffer_size(data->jack_client), + sizeof(float)); + (data->desc->LADSPA_Plugin->connect_port)(data->plugin_handle, j, + data->left_buffer); + } + else + if (LADSPA_IS_PORT_CONTROL(pod) && LADSPA_IS_PORT_INPUT(pod)) + { + /* This is an input control port. Connect it to a properly + initialized value in our controller value array. */ + (data->desc->LADSPA_Plugin->connect_port) + (data->plugin_handle, j, &(data->control_values[cindex])); + data->control_values[cindex] = + get_port_default (data->desc->LADSPA_Plugin, + j, data->sample_rate); + + /* Set up the mapping between MIDI controllers and this + contoller value. */ + if (data->desc->get_midi_controller_for_port) + { + controller = data->desc-> + get_midi_controller_for_port(data->plugin_handle, j); + + if ((controller != DSSI_NONE) && DSSI_IS_CC(controller)) + { + data->control_value_map[DSSI_CC_NUMBER(controller)] = cindex; + data->control_port_map[DSSI_CC_NUMBER(controller)] = j; + +#ifdef DEBUG_DSSI_PROVIDER + printf ("MIDI Controller 0x%x [%s] = %g\n", + DSSI_CC_NUMBER(controller), + data->desc->LADSPA_Plugin->PortNames[j], + data->control_values[cindex]); +#endif + } + } + + cindex++; + } + } + + (data->desc->LADSPA_Plugin->activate)(data->plugin_handle); + + if (jack_activate (data->jack_client)) + JCL_ThrowException (env, "java/io/IOException", + "can't activate jack client"); + + /* Try to connect the synth output to hardware audio ports. */ + ports = jack_get_ports (data->jack_client, NULL, NULL, + JackPortIsPhysical | JackPortIsInput); + if (ports) + { + if (ports[0] && ports[1]) + { + /* Don't bother checking return values. Failing is OK. */ + jack_connect (data->jack_client, + jack_port_name (data->jack_left_output_port), + ports[0]); + jack_connect (data->jack_client, + jack_port_name (data->jack_right_output_port), + ports[1]); + } + free(ports); + } +} + +/** + * This is called when we receive a new MIDI CONTROL CHANGE message. + * Simply stick an appropriate event in the event buffer. This will + * get processed in the jack callback function. + */ +JNIEXPORT void JNICALL +Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_controlChange_1 + (JNIEnv *env __attribute__((unused)), jclass clazz __attribute__((unused)), + jlong handle, jint channel, jint control, jint value) +{ + dssi_data *data = JLONG_TO_PTR(dssi_data,handle); + + /* Insert this event in the event buffer. */ + snd_seq_event_t *ev = & data->midiEventBuffer[data->midiEventWriteIndex]; + + /* Set the event value. */ + snd_seq_ev_set_controller (ev, channel, control, value); + + data->midiEventWriteIndex = + (data->midiEventWriteIndex + 1) % EVENT_BUFFER_SIZE; +} + +/** + * This is called when we receive a new MIDI NOTE ON message. Simply + * stick an appropriate event in the event buffer. This will get + * processed in the jack callback function. + */ +JNIEXPORT void JNICALL +Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_noteOn_1 + (JNIEnv *env __attribute__((unused)), jclass clazz __attribute__((unused)), + jlong handle, jint channel, jint note, jint velocity) +{ + dssi_data *data = JLONG_TO_PTR(dssi_data,handle); + + /* Insert this event in the event buffer. */ + snd_seq_event_t *ev = & data->midiEventBuffer[data->midiEventWriteIndex]; + + ev->type = SND_SEQ_EVENT_NOTEON; + ev->data.control.channel = channel; + ev->data.note.note = note; + ev->data.note.velocity = velocity; + + data->midiEventWriteIndex = + (data->midiEventWriteIndex + 1) % EVENT_BUFFER_SIZE; +} + +/** + * This is called when we receive a new MIDI NOTE OFF message. Simply + * stick an appropriate event in the event buffer. This will get + * processed in the jack callback function. + */ +JNIEXPORT void JNICALL +Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_noteOff_1 + (JNIEnv *env __attribute__((unused)), + jclass clazz __attribute__((unused)), + jlong handle, jint channel, jint note, jint velocity) +{ + dssi_data *data = JLONG_TO_PTR(dssi_data,handle); + + /* Insert this event in the event buffer. */ + snd_seq_event_t *ev = & data->midiEventBuffer[data->midiEventWriteIndex]; + + ev->type = SND_SEQ_EVENT_NOTEOFF; + ev->data.control.channel = channel; + ev->data.note.note = note; + ev->data.note.velocity = velocity; + + data->midiEventWriteIndex = + (data->midiEventWriteIndex + 1) % EVENT_BUFFER_SIZE; +} + +JNIEXPORT void JNICALL +Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_setPolyPressure_1 + (JNIEnv *env __attribute__((unused)), jclass clazz __attribute__((unused)), + jlong handle __attribute__((unused)), jint channel __attribute__((unused)), + jint note __attribute__((unused)), jint velocity __attribute__((unused))) +{ +} + +JNIEXPORT jint JNICALL +Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_getPolyPressure_1 + (JNIEnv *env __attribute__((unused)), jclass clazz __attribute__((unused)), + jlong handle __attribute__((unused)), jint channel __attribute__((unused)), + jint note __attribute__((unused))) +{ + return 0; +} + +JNIEXPORT void JNICALL +Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_close_1 + (JNIEnv *env __attribute__((unused)), jclass clazz __attribute__((unused)), + jlong handle __attribute__((unused))) +{ +} + +/* FIXME: These next three functions are really inefficient because + we're instantiating and cleaning up plugin instances just to query + values. */ + +JNIEXPORT jstring JNICALL +Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_getProgramName_1 + (JNIEnv *env, jclass clazz __attribute__((unused)), + jlong handle, jint index) +{ + LADSPA_Handle lhandle; + jstring name = (jstring) NULL; + dssi_data *data = JLONG_TO_PTR(dssi_data, handle); + if (data->desc->get_program == NULL) + return NULL; + lhandle = + (data->desc->LADSPA_Plugin->instantiate)(data->desc->LADSPA_Plugin, + 48000); + const DSSI_Program_Descriptor *program = + (data->desc->get_program)(lhandle, (unsigned long) index); + if (program) + name = (*env)->NewStringUTF (env, program->Name); + (data->desc->LADSPA_Plugin->cleanup)(lhandle); + + return name; +} + +JNIEXPORT jint JNICALL +Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_getProgramBank_1 + (JNIEnv *env __attribute__((unused)), jclass clazz __attribute__((unused)), + jlong handle, jint index) +{ + LADSPA_Handle lhandle; + jint result = -1; + dssi_data *data = JLONG_TO_PTR(dssi_data, handle); + lhandle = + (data->desc->LADSPA_Plugin->instantiate)(data->desc->LADSPA_Plugin, + 48000); + const DSSI_Program_Descriptor *program = + (data->desc->get_program)(lhandle, (unsigned long) index); + if (program) + result = (jint) program->Bank; + (data->desc->LADSPA_Plugin->cleanup)(lhandle); + return result; +} + +JNIEXPORT jint JNICALL +Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_getProgramProgram_1 + (JNIEnv *env __attribute__((unused)), jclass clazz __attribute__((unused)), + jlong handle, jint index) +{ + LADSPA_Handle lhandle; + jint result = -1; + dssi_data *data = JLONG_TO_PTR(dssi_data, handle); + lhandle = + (data->desc->LADSPA_Plugin->instantiate)(data->desc->LADSPA_Plugin, + 48000); + const DSSI_Program_Descriptor *program = + (data->desc->get_program)(lhandle, (unsigned long) index); + if (program) + result = (jint) program->Program; + (data->desc->LADSPA_Plugin->cleanup)(lhandle); + return result; +} + + +JNIEXPORT void JNICALL +Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_selectProgram_1 + (JNIEnv *env __attribute__((unused)), jclass clazz __attribute__((unused)), + jlong handle, jint bank, jint program) +{ + dssi_data *data = JLONG_TO_PTR(dssi_data, handle); + + (data->desc->select_program)(data->plugin_handle, + (unsigned) bank, (unsigned) program); +} diff --git a/libjava/classpath/native/jni/native-lib/.cvsignore b/libjava/classpath/native/jni/native-lib/.cvsignore new file mode 100644 index 000000000..e9f2658a6 --- /dev/null +++ b/libjava/classpath/native/jni/native-lib/.cvsignore @@ -0,0 +1,8 @@ +*.o +*.a +*.lo +*.la +.libs +.deps +Makefile +Makefile.in diff --git a/libjava/classpath/native/jni/native-lib/Makefile.am b/libjava/classpath/native/jni/native-lib/Makefile.am new file mode 100644 index 000000000..0de723eb1 --- /dev/null +++ b/libjava/classpath/native/jni/native-lib/Makefile.am @@ -0,0 +1,13 @@ +noinst_LTLIBRARIES = libclasspathnative.la +libclasspathnative_la_SOURCES = cpnet.c \ + cpnet.h \ + cpio.c \ + cpio.h \ + cpnative.h \ + cpproc.h \ + cpproc.c + +AM_LDFLAGS = @CLASSPATH_CONVENIENCE@ +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ +AM_CFLAGS = @WARNING_CFLAGS@ @STRICT_WARNING_CFLAGS@ @ERROR_CFLAGS@ \ + @EXTRA_CFLAGS@ diff --git a/libjava/classpath/native/jni/native-lib/Makefile.in b/libjava/classpath/native/jni/native-lib/Makefile.in new file mode 100644 index 000000000..4f58dedaa --- /dev/null +++ b/libjava/classpath/native/jni/native-lib/Makefile.in @@ -0,0 +1,567 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +subdir = native/jni/native-lib +DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/../../config/depstand.m4 \ + $(top_srcdir)/../../config/lead-dot.m4 \ + $(top_srcdir)/../../config/lib-ld.m4 \ + $(top_srcdir)/../../config/lib-link.m4 \ + $(top_srcdir)/../../config/lib-prefix.m4 \ + $(top_srcdir)/../../config/multi.m4 \ + $(top_srcdir)/../../config/no-executables.m4 \ + $(top_srcdir)/../../config/override.m4 \ + $(top_srcdir)/../../libtool.m4 \ + $(top_srcdir)/../../ltoptions.m4 \ + $(top_srcdir)/../../ltsugar.m4 \ + $(top_srcdir)/../../ltversion.m4 \ + $(top_srcdir)/../../lt~obsolete.m4 \ + $(top_srcdir)/m4/ac_prog_antlr.m4 \ + $(top_srcdir)/m4/ac_prog_java.m4 \ + $(top_srcdir)/m4/ac_prog_java_works.m4 \ + $(top_srcdir)/m4/ac_prog_javac.m4 \ + $(top_srcdir)/m4/ac_prog_javac_works.m4 \ + $(top_srcdir)/m4/acattribute.m4 $(top_srcdir)/m4/accross.m4 \ + $(top_srcdir)/m4/acinclude.m4 \ + $(top_srcdir)/m4/ax_create_stdint_h.m4 \ + $(top_srcdir)/m4/ax_func_which_gethostbyname_r.m4 \ + $(top_srcdir)/m4/gcc_attribute.m4 $(top_srcdir)/m4/iconv.m4 \ + $(top_srcdir)/m4/pkg.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/../../mkinstalldirs +CONFIG_HEADER = $(top_builddir)/include/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +LTLIBRARIES = $(noinst_LTLIBRARIES) +libclasspathnative_la_LIBADD = +am_libclasspathnative_la_OBJECTS = cpnet.lo cpio.lo cpproc.lo +libclasspathnative_la_OBJECTS = $(am_libclasspathnative_la_OBJECTS) +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/include +depcomp = $(SHELL) $(top_srcdir)/../../depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(libclasspathnative_la_SOURCES) +ETAGS = etags +CTAGS = ctags +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +ANTLR = @ANTLR@ +ANTLR_JAR = @ANTLR_JAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CAIRO_CFLAGS = @CAIRO_CFLAGS@ +CAIRO_LIBS = @CAIRO_LIBS@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CLASSPATH_CONVENIENCE = @CLASSPATH_CONVENIENCE@ +CLASSPATH_INCLUDES = @CLASSPATH_INCLUDES@ +CLASSPATH_MODULE = @CLASSPATH_MODULE@ +COLLECTIONS_PREFIX = @COLLECTIONS_PREFIX@ +CP = @CP@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DATE = @DATE@ +DEFAULT_PREFS_PEER = @DEFAULT_PREFS_PEER@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +ECJ_JAR = @ECJ_JAR@ +EGREP = @EGREP@ +ERROR_CFLAGS = @ERROR_CFLAGS@ +EXAMPLESDIR = @EXAMPLESDIR@ +EXEEXT = @EXEEXT@ +EXTRA_CFLAGS = @EXTRA_CFLAGS@ +FGREP = @FGREP@ +FIND = @FIND@ +FREETYPE2_CFLAGS = @FREETYPE2_CFLAGS@ +FREETYPE2_LIBS = @FREETYPE2_LIBS@ +GCONF_CFLAGS = @GCONF_CFLAGS@ +GCONF_LIBS = @GCONF_LIBS@ +GDK_CFLAGS = @GDK_CFLAGS@ +GDK_LIBS = @GDK_LIBS@ +GJDOC = @GJDOC@ +GLIB_CFLAGS = @GLIB_CFLAGS@ +GLIB_LIBS = @GLIB_LIBS@ +GMP_CFLAGS = @GMP_CFLAGS@ +GMP_LIBS = @GMP_LIBS@ +GREP = @GREP@ +GSTREAMER_BASE_CFLAGS = @GSTREAMER_BASE_CFLAGS@ +GSTREAMER_BASE_LIBS = @GSTREAMER_BASE_LIBS@ +GSTREAMER_CFLAGS = @GSTREAMER_CFLAGS@ +GSTREAMER_FILE_READER = @GSTREAMER_FILE_READER@ +GSTREAMER_LIBS = @GSTREAMER_LIBS@ +GSTREAMER_MIXER_PROVIDER = @GSTREAMER_MIXER_PROVIDER@ +GSTREAMER_PLUGINS_BASE_CFLAGS = @GSTREAMER_PLUGINS_BASE_CFLAGS@ +GSTREAMER_PLUGINS_BASE_LIBS = @GSTREAMER_PLUGINS_BASE_LIBS@ +GST_PLUGIN_LDFLAGS = @GST_PLUGIN_LDFLAGS@ +GTK_CFLAGS = @GTK_CFLAGS@ +GTK_LIBS = @GTK_LIBS@ +INIT_LOAD_LIBRARY = @INIT_LOAD_LIBRARY@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAR = @JAR@ +JAVA = @JAVA@ +JAVAC = @JAVAC@ +JAVAC_IS_GCJ = @JAVAC_IS_GCJ@ +JAVAC_MEM_OPT = @JAVAC_MEM_OPT@ +JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION = @JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION@ +JAY = @JAY@ +JAY_SKELETON = @JAY_SKELETON@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBDEBUG = @LIBDEBUG@ +LIBICONV = @LIBICONV@ +LIBMAGIC = @LIBMAGIC@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBVERSION = @LIBVERSION@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBICONV = @LTLIBICONV@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MKDIR = @MKDIR@ +MKDIR_P = @MKDIR_P@ +MOC = @MOC@ +MOZILLA_CFLAGS = @MOZILLA_CFLAGS@ +MOZILLA_LIBS = @MOZILLA_LIBS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PANGOFT2_CFLAGS = @PANGOFT2_CFLAGS@ +PANGOFT2_LIBS = @PANGOFT2_LIBS@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PATH_TO_ESCHER = @PATH_TO_ESCHER@ +PATH_TO_GLIBJ_ZIP = @PATH_TO_GLIBJ_ZIP@ +PERL = @PERL@ +PKG_CONFIG = @PKG_CONFIG@ +PLUGIN_DIR = @PLUGIN_DIR@ +QT_CFLAGS = @QT_CFLAGS@ +QT_LIBS = @QT_LIBS@ +RANLIB = @RANLIB@ +REMOVE = @REMOVE@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRICT_WARNING_CFLAGS = @STRICT_WARNING_CFLAGS@ +STRIP = @STRIP@ +TOOLSDIR = @TOOLSDIR@ +USER_JAVAH = @USER_JAVAH@ +VERSION = @VERSION@ +WANT_NATIVE_BIG_INTEGER = @WANT_NATIVE_BIG_INTEGER@ +WARNING_CFLAGS = @WARNING_CFLAGS@ +XMKMF = @XMKMF@ +XML_CFLAGS = @XML_CFLAGS@ +XML_LIBS = @XML_LIBS@ +XSLT_CFLAGS = @XSLT_CFLAGS@ +XSLT_LIBS = @XSLT_LIBS@ +XTEST_LIBS = @XTEST_LIBS@ +X_CFLAGS = @X_CFLAGS@ +X_EXTRA_LIBS = @X_EXTRA_LIBS@ +X_LIBS = @X_LIBS@ +X_PRE_LIBS = @X_PRE_LIBS@ +ZIP = @ZIP@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_ANTLR = @ac_ct_ANTLR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +default_toolkit = @default_toolkit@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +glibjdir = @glibjdir@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +multi_basedir = @multi_basedir@ +nativeexeclibdir = @nativeexeclibdir@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +toolexeclibdir = @toolexeclibdir@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +uudecode = @uudecode@ +vm_classes = @vm_classes@ +noinst_LTLIBRARIES = libclasspathnative.la +libclasspathnative_la_SOURCES = cpnet.c \ + cpnet.h \ + cpio.c \ + cpio.h \ + cpnative.h \ + cpproc.h \ + cpproc.c + +AM_LDFLAGS = @CLASSPATH_CONVENIENCE@ +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ +AM_CFLAGS = @WARNING_CFLAGS@ @STRICT_WARNING_CFLAGS@ @ERROR_CFLAGS@ \ + @EXTRA_CFLAGS@ + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu native/jni/native-lib/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu native/jni/native-lib/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +clean-noinstLTLIBRARIES: + -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES) + @list='$(noinst_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libclasspathnative.la: $(libclasspathnative_la_OBJECTS) $(libclasspathnative_la_DEPENDENCIES) + $(LINK) $(libclasspathnative_la_OBJECTS) $(libclasspathnative_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpio.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpnet.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpproc.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-noinstLTLIBRARIES ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags dvi dvi-am html html-am info info-am install \ + install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-pdf install-pdf-am install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ + pdf pdf-am ps ps-am tags uninstall uninstall-am + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/libjava/classpath/native/jni/native-lib/cpio.c b/libjava/classpath/native/jni/native-lib/cpio.c new file mode 100644 index 000000000..d8523680a --- /dev/null +++ b/libjava/classpath/native/jni/native-lib/cpio.c @@ -0,0 +1,592 @@ +/* cpio.c - Common java file IO native functions + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +/* do not move; needed here because of some macro definitions */ +#include + +#include +#include +#include +#include +#include +#include + +#include + +#if defined(HAVE_SYS_IOCTL_H) +#define BSD_COMP /* Get FIONREAD on Solaris2 */ +#include +#endif +#if defined(HAVE_SYS_FILIO_H) /* Get FIONREAD on Solaris 2.5 */ +#include +#endif + +#if defined(HAVE_SYS_STAT_H) +#include +#endif + +#if defined(HAVE_FCNTL_H) +#include +#endif + +#if defined(HAVE_UNISTD_H) +#include +#endif + +#if defined(HAVE_SYS_SELECT_H) +#include +#endif + +#if defined(HAVE_STATVFS) +#include +#endif + +#include + +#include "cpnative.h" +#include "cpio.h" + +/* Some POSIX systems don't have O_SYNC and O_DYSNC so we define them here. */ +#if !defined (O_SYNC) && defined (O_FSYNC) +#define O_SYNC O_FSYNC +#endif +#if !defined (O_DSYNC) && defined (O_FSYNC) +#define O_DSYNC O_FSYNC +#endif +/* If O_DSYNC is still not defined, use O_SYNC (needed for newlib). */ +#if !defined (O_DSYNC) +#define O_DSYNC O_SYNC +#endif + +JNIEXPORT int cpio_openFile (const char *filename, int *fd, int flags, int permissions) +{ + int sflags = 0; + int rwflags = flags & CPFILE_FLAG_READWRITE; + int perms; + + if (flags & CPFILE_FLAG_CREATE) + sflags |= O_CREAT; + if (flags & CPFILE_FLAG_APPEND) + sflags |= O_APPEND; + if (flags & CPFILE_FLAG_TRUNCATE) + sflags |= O_TRUNC; + if (flags & CPFILE_FLAG_SYNC) + sflags |= O_SYNC; + if (flags & CPFILE_FLAG_DSYNC) + sflags |= O_DSYNC; +#if defined(O_BINARY) + if (flags & CPFILE_FLAG_BINARY) + sflags |= O_BINARY; +#endif + + switch (rwflags) + { + case CPFILE_FLAG_READ: + sflags |= O_RDONLY; + break; + case CPFILE_FLAG_WRITE: + sflags |= O_WRONLY; + break; + case CPFILE_FLAG_READWRITE: + sflags |= O_RDWR; + break; + } + + if (permissions == CPFILE_PERMISSION_NORMAL) + perms = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); + else + perms = 0; + + *fd = open (filename, sflags, perms); + + if (*fd < 0) + return errno; + + return CPNATIVE_OK; +} + +JNIEXPORT int cpio_closeFile (int fd) +{ + if (close (fd) < 0) + return errno; + + return CPNATIVE_OK; +} + +JNIEXPORT int cpio_availableBytes (int fd, jlong *bytes_available) +{ +#if defined (FIONREAD) + ssize_t n; + + if (ioctl (fd, FIONREAD, (char *)&n) != 0) + return errno; + + *bytes_available = n; + return CPNATIVE_OK; +#elif defined(HAVE_FSTAT) + struct stat statBuffer; + off_t n; + int result; + + *bytes_available = 0; + if ((fstat (fd, &statBuffer) == 0) && S_ISREG (statBuffer.st_mode)) + { + n = lseek (fd, 0, SEEK_CUR); + if (n != -1) + { + *bytes_available = statBuffer.st_size - n; + result = CPNATIVE_OK; + } + else + { + result = errno; + } + } + else + { + result = errno; + } + + return result; +#elif defined(HAVE_SELECT) + fd_set filedescriptset; + struct timeval tv; + int result; + + *bytes_available = 0; + + FD_ZERO (&filedescriptset); + FD_SET (fd,&filedescriptset); + memset (&tv, 0, sizeof(tv)); + + switch (select (fd+1, &filedescriptset, NULL, NULL, &tv)) + { + case -1: + result=errno; + break; + case 0: + *bytes_available = 0; + result = CPNATIVE_OK; + break; + default: + *bytes_available = 1; + result = CPNATIVE_OK; + break; + } + return result; + +#else + *bytes_available = 0; + return ENOTSUP; +#endif +} + +JNIEXPORT int cpio_getFileSize (int fd, jlong *filesize) +{ + struct stat statBuffer; + + if (fstat(fd, &statBuffer) < 0) + return errno; + + *filesize = statBuffer.st_size; + return CPNATIVE_OK; +} + +JNIEXPORT int cpio_getFilePosition (int fd, jlong *offset) +{ + *offset = lseek (fd, 0, SEEK_CUR); + if (*offset < 0) + return errno; + + return CPNATIVE_OK; +} + +JNIEXPORT int cpio_setFilePosition (int fd, jlong position) +{ + if (lseek (fd, position, SEEK_SET) < 0) + return errno; + + return CPNATIVE_OK; +} + +JNIEXPORT int cpio_read (int fd, void *buffer, jint length, jint *bytes_read) +{ + *bytes_read = read (fd, buffer, length); + + if (*bytes_read < 0) + { + return errno; + } + + return CPNATIVE_OK; +} + +JNIEXPORT int cpio_write (int fd, const void *buffer, jint length, jint *bytes_written) +{ + *bytes_written = write (fd, buffer, length); + + if (*bytes_written < 0) + return errno; + + return CPNATIVE_OK; +} + +JNIEXPORT int cpio_fsync (int fd) +{ + if (fsync (fd) < 0) + return errno; + + return CPNATIVE_OK; +} + +JNIEXPORT int cpio_truncate (int fd, jlong size) +{ + if (ftruncate (fd, size) < 0) + return errno; + + return CPNATIVE_OK; +} + +JNIEXPORT int cpio_setFileSize (int native_fd, jlong new_size) +{ + jlong file_size; + jlong save_offset; + int result; + char data; + jint bytes_written; + + result = cpio_getFileSize (native_fd, &file_size); + if (result != CPNATIVE_OK) + return result; + + /* Save off current position */ + result = cpio_getFilePosition (native_fd, &save_offset); + if (result != CPNATIVE_OK) + return result; + + if (file_size < new_size) + { + /* File is too short -- seek to one byte short of where we want, + * then write a byte */ + + /* move to position n-1 */ + result = cpio_setFilePosition (native_fd, new_size-1); + if (result != CPNATIVE_OK) + return result; + + /* write a byte + Note: This will fail if we somehow get here in read only mode + * That shouldn't happen */ + data = '\0'; + result = cpio_write (native_fd, &data, 1, &bytes_written); + if (result != CPNATIVE_OK) + return result; + + /* Reposition file pointer to where we started if not beyond new len. */ + if (save_offset < new_size) + { + result = cpio_setFilePosition (native_fd, save_offset); + if (result != CPNATIVE_OK) + return result; + } + } + else if (new_size < file_size) + { + /* File is too long - use ftruncate if available */ + result = cpio_truncate (native_fd, new_size); + if (result != CPNATIVE_OK) + return result; + + /* Reposition file pointer when it now is beyond the end of file. */ + if (new_size < save_offset) + { + result = cpio_setFilePosition (native_fd, new_size); + if (result != CPNATIVE_OK) + return result; + } + } + + return CPNATIVE_OK; +} + +int cpio_setFileReadonly (const char *filename) +{ + struct stat statbuf; + + if (stat(filename, &statbuf) < 0) + return errno; + +#ifdef S_IWRITE + if (chmod(filename, statbuf.st_mode & ~(S_IWRITE | S_IWGRP | S_IWOTH)) < 0) + return errno; +#endif + + return 0; +} + +int cpio_chmod (const char *filename, int permissions) +{ + struct stat statbuf; + int perms = 0; + + if (stat(filename, &statbuf) < 0) + return errno; + + /* check for permission flags */ + if (permissions & CPFILE_FLAG_USR) + { + if (permissions & CPFILE_FLAG_READ) + perms |= S_IRUSR; + + if (permissions & CPFILE_FLAG_WRITE) + perms |= S_IWUSR; + + if (permissions & CPFILE_FLAG_EXEC) + perms |= S_IXUSR; + } + else + { + if (permissions & CPFILE_FLAG_READ) + perms |= (S_IRUSR | S_IRGRP | S_IROTH); + + if (permissions & CPFILE_FLAG_WRITE) + perms |= (S_IWUSR | S_IWGRP | S_IWOTH); + + if (permissions & CPFILE_FLAG_EXEC) + perms |= (S_IXUSR | S_IXGRP | S_IXOTH); + } + + if (permissions & CPFILE_FLAG_OFF) + perms = statbuf.st_mode & ~perms; + else + perms = statbuf.st_mode | perms; + + if (chmod(filename, perms) < 0) + return errno; + + return 0; +} + +JNIEXPORT long long +cpio_df (__attribute__((unused)) const char *path, + __attribute__((unused)) CPFILE_DF_TYPE type) +{ + long long result = 0L; + +#if defined(HAVE_STATVFS) + + long long scale_factor = 0L; + struct statvfs buf; + + if (statvfs (path, &buf) < 0) + return 0L; + + /* f_blocks, f_bfree and f_bavail are defined in terms of f_frsize */ + scale_factor = (long long) (buf.f_frsize); + + switch (type) + { + case TOTAL: + result = (long long) (buf.f_blocks * scale_factor); + break; + case FREE: + result = (long long) (buf.f_bfree * scale_factor); + break; + case USABLE: + result = (long long) (buf.f_bavail * scale_factor); + break; + default: + result = 0L; + break; + } + +#endif + + return result; +} + +int cpio_checkAccess (const char *filename, unsigned int flag) +{ + struct stat statbuf; + unsigned int perms = 0; + + if (stat(filename, &statbuf) < 0) + return errno; + + switch (flag) + { + case CPFILE_FLAG_READ: + perms = R_OK; + break; + + case CPFILE_FLAG_WRITE: + perms = W_OK; + break; + + case CPFILE_FLAG_EXEC: + default: + perms = X_OK; + break; + } + + return (access (filename, perms)); +} + +int cpio_isFileExists (const char *filename) +{ + struct stat statbuf; + + if (stat(filename, &statbuf) < 0) + { + return errno; + } + + return 0; +} + +int cpio_checkType (const char *filename, jint *entryType) +{ + struct stat statbuf; + + if (stat(filename, &statbuf) < 0) + return errno; + + if (S_ISDIR(statbuf.st_mode)) + *entryType = CPFILE_DIRECTORY; + else + *entryType = CPFILE_FILE; + + return 0; +} + +int cpio_getModificationTime (const char *filename, jlong *mtime) +{ + struct stat statbuf; + + if (stat(filename, &statbuf) < 0) + return errno; + + *mtime = (jlong)statbuf.st_mtime * (jlong)1000; + + return 0; +} + +int cpio_setModificationTime (const char *filename, jlong mtime) +{ + struct stat statbuf; + struct utimbuf buf; + + if (stat(filename, &statbuf) < 0) + return errno; + + buf.actime = statbuf.st_atime; + buf.modtime = mtime / 1000; + + if (utime(filename, &buf) < 0) + return errno; + + return 0; +} + +int cpio_removeFile (const char *filename) +{ + if (unlink(filename) < 0 && rmdir(filename) < 0) + return errno; + + return 0; +} + +int cpio_mkdir (const char *path) +{ + if (mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO) < 0) + return errno; + + return 0; +} + +int cpio_rename (const char *old_name, const char *new_name) +{ + if (rename(old_name, new_name) < 0) + return errno; + + return 0; +} + +int cpio_openDir (const char *dirname, void **handle) +{ + *handle = (void *)opendir(dirname); + if (*handle == NULL) + return errno; + + return 0; +} + +int cpio_closeDir (void *handle) +{ + closedir((DIR *)handle); + return 0; +} + + +int cpio_readDir (void *handle, char *filename) +{ + struct dirent *dBuf; + + errno = 0; + dBuf = readdir((DIR *)handle); + + if (dBuf == NULL) + { + /* Some OS's (OS X) return NULL on end-of-dir, but + don't set errno to anything. */ + if (errno == 0) + return ENOENT; /* Whatever. */ + return errno; + } + + strncpy (filename, dBuf->d_name, FILENAME_MAX - 1); + return 0; +} + +int +cpio_closeOnExec(int fd) +{ + if (fcntl (fd, F_SETFD, FD_CLOEXEC) == -1) + return errno; + + return 0; +} diff --git a/libjava/classpath/native/jni/native-lib/cpio.h b/libjava/classpath/native/jni/native-lib/cpio.h new file mode 100644 index 000000000..a42fe62db --- /dev/null +++ b/libjava/classpath/native/jni/native-lib/cpio.h @@ -0,0 +1,99 @@ +/* cpio.h - + Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#ifndef _CLASSPATH_IO_H_INCLUDED +#define _CLASSPATH_IO_H_INCLUDED + +#include + +#define CPFILE_FLAG_CREATE 0x0001 +#define CPFILE_FLAG_APPEND 0x0002 +#define CPFILE_FLAG_TRUNCATE 0x0004 +#define CPFILE_FLAG_SYNC 0x0008 +#define CPFILE_FLAG_DSYNC 0x0010 +#define CPFILE_FLAG_BINARY 0x0020 +#define CPFILE_FLAG_READ 0x0040 +#define CPFILE_FLAG_WRITE 0x0080 +#define CPFILE_FLAG_EXEC 0x0100 +#define CPFILE_FLAG_USR 0x0400 +#define CPFILE_FLAG_OFF 0x0800 + +#define CPFILE_PERMISSION_NORMAL 1 + +#define CPFILE_FLAG_READWRITE (CPFILE_FLAG_READ|CPFILE_FLAG_WRITE) + +JNIEXPORT int cpio_openFile (const char *filename, int *fd, int flags, int permissions); +JNIEXPORT int cpio_closeFile (int fd); +JNIEXPORT int cpio_availableBytes (int fd, jlong *avail); +JNIEXPORT int cpio_getFileSize (int fd, jlong *filesize); +JNIEXPORT int cpio_setFileSize (int fd, jlong filesize); +JNIEXPORT int cpio_getFilePosition (int fd, jlong *position); +JNIEXPORT int cpio_setFilePosition (int fd, jlong position); +JNIEXPORT int cpio_read (int fd, void *data, jint len, jint *bytes_read); +JNIEXPORT int cpio_write (int fd, const void *data, jint len, jint *bytes_written); +JNIEXPORT int cpio_fsync (int fd); +JNIEXPORT int cpio_truncate (int fd, jlong size); +JNIEXPORT int cpio_closeOnExec(int fd); + +#define CPFILE_FILE 0 +#define CPFILE_DIRECTORY 1 + +JNIEXPORT int cpio_setFileReadonly (const char *filename); +JNIEXPORT int cpio_chmod (const char *filename, int permissions); +JNIEXPORT int cpio_checkAccess (const char *filename, unsigned int flag); +JNIEXPORT int cpio_isFileExists (const char *filename); +JNIEXPORT int cpio_checkType (const char *filename, jint *entryType); +JNIEXPORT int cpio_getModificationTime (const char *filename, jlong *mtime); +JNIEXPORT int cpio_setModificationTime (const char *filename, jlong mtime); +JNIEXPORT int cpio_removeFile (const char *filename); +JNIEXPORT int cpio_mkdir (const char *filename); +JNIEXPORT int cpio_rename (const char *old_name, const char *new_name); + +/* to be used with cpio_df */ +typedef enum { + TOTAL = 0, + FREE, + USABLE +} CPFILE_DF_TYPE; + +JNIEXPORT long long cpio_df (const char *path, CPFILE_DF_TYPE type); + +JNIEXPORT int cpio_openDir (const char *dirname, void **handle); +JNIEXPORT int cpio_closeDir (void *handle); +JNIEXPORT int cpio_readDir (void *handle, char *filename); + +#endif diff --git a/libjava/classpath/native/jni/native-lib/cpnative.h b/libjava/classpath/native/jni/native-lib/cpnative.h new file mode 100644 index 000000000..4ba772603 --- /dev/null +++ b/libjava/classpath/native/jni/native-lib/cpnative.h @@ -0,0 +1,49 @@ +/* cpnative.h - + Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#ifndef _CLASSPATH_NATIVE_H_INCLUDED +#define _CLASSPATH_NATIVE_H_INCLUDED + +#include +#include + +#define CPNATIVE_OK 0 +#define CPNATIVE_EINTR EINTR + +#define cpnative_getErrorString strerror + +#endif diff --git a/libjava/classpath/native/jni/native-lib/cpnet.c b/libjava/classpath/native/jni/native-lib/cpnet.c new file mode 100644 index 000000000..154a7dd7d --- /dev/null +++ b/libjava/classpath/native/jni/native-lib/cpnet.c @@ -0,0 +1,818 @@ +/* cpnet.c - + Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include "config.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined(HAVE_SYS_IOCTL_H) +#define BSD_COMP /* Get FIONREAD on Solaris2 */ +#include +#endif +#if defined(HAVE_SYS_FILIO_H) /* Get FIONREAD on Solaris 2.5 */ +#include +#endif + +#include "cpnet.h" + +#define SOCKET_DEFAULT_TIMEOUT -1 /* milliseconds */ + +static int socketTimeouts[FD_SETSIZE]; + +static jint waitForWritable(jint fd) +{ + struct timeval tv; + fd_set writeset; + int ret; + + + FD_ZERO(&writeset); + FD_SET(fd, &writeset); + if (socketTimeouts[fd] > 0) + { + tv.tv_sec = socketTimeouts[fd] / 1000; + tv.tv_usec = (socketTimeouts[fd] % 1000) * 1000; + ret = select(fd+1, NULL, &writeset, NULL, &tv); + } + else + ret = select(fd+1, NULL, &writeset, NULL, NULL); + + return (ret <= 0) ? -1 : 0; +} + +static jint waitForReadable(jint fd) +{ + struct timeval tv; + fd_set readset; + int ret; + + + FD_ZERO(&readset); + FD_SET(fd, &readset); + if (socketTimeouts[fd] > 0) + { + tv.tv_sec = socketTimeouts[fd] / 1000; + tv.tv_usec = (socketTimeouts[fd] % 1000) * 1000; + ret = select(fd+1, &readset, NULL, NULL, &tv); + } + else + ret = select(fd+1, &readset, NULL, NULL, NULL); + + return (ret <= 0) ? -1 : 0; +} + +jint cpnet_openSocketStream(JNIEnv *env UNUSED, jint *fd, jint family) +{ + *fd = socket(family, SOCK_STREAM, 0); + if (*fd == -1) + return errno; + + fcntl(*fd, F_SETFD, FD_CLOEXEC); + assert(*fd < FD_SETSIZE); + socketTimeouts[*fd] = SOCKET_DEFAULT_TIMEOUT; + return 0; +} + +jint cpnet_openSocketDatagram(JNIEnv *env UNUSED, jint *fd, jint family) +{ + *fd = socket(family, SOCK_DGRAM, 0); + if (*fd == -1) + return errno; + + fcntl(*fd, F_SETFD, FD_CLOEXEC); + assert(*fd < FD_SETSIZE); + socketTimeouts[*fd] = SOCKET_DEFAULT_TIMEOUT; + return 0; +} + +jint cpnet_shutdown (JNIEnv *env UNUSED, jint fd, jbyte flag) +{ + int ret; + int shut_flag = 0; + + if (flag == CPNET_SHUTDOWN_READ) + shut_flag = SHUT_RD; + else if (flag == CPNET_SHUTDOWN_WRITE) + shut_flag = SHUT_WR; + + ret = shutdown (fd, shut_flag); + if (ret != 0) + return errno; + return 0; +} + +jint cpnet_close(JNIEnv *env UNUSED, jint fd) +{ + if (close (fd) != 0) + return errno; + return 0; +} + +jint cpnet_listen(JNIEnv *env UNUSED, jint fd, jint queuelen) +{ + if (listen (fd, queuelen) != 0) + return errno; + return 0; +} + +jint cpnet_accept(JNIEnv *env UNUSED, jint fd, jint *newfd) +{ + if (waitForReadable (fd) < 0) + return ETIMEDOUT; + + *newfd = accept(fd, NULL, 0); + if (*newfd != 0) + return errno; + + return 0; +} + +jint cpnet_bind(JNIEnv *env UNUSED, jint fd, cpnet_address *addr) +{ + int ret; + + ret = bind(fd, (struct sockaddr *)addr->data, addr->len); + if (ret != 0) + return errno; + + return 0; +} + +jint cpnet_connect(JNIEnv *env UNUSED, jint fd, cpnet_address *addr) +{ + int ret; + + /* TODO: implement socket time out */ + ret = connect(fd, (struct sockaddr *)addr->data, addr->len); + if (ret != 0) + return errno; + + return 0; +} + +jint cpnet_getLocalAddr(JNIEnv *env, jint fd, cpnet_address **addr) +{ + socklen_t slen = 1024; + int ret; + + *addr = JCL_malloc(env, slen); + + slen -= sizeof(jint); + ret = getsockname(fd, (struct sockaddr *)(*addr)->data, &slen ); + if (ret != 0) + { + int err = errno; + JCL_free(env, *addr); + return err; + } + + (*addr)->len = slen; + + return 0; +} + +jint cpnet_getRemoteAddr(JNIEnv *env, jint fd, cpnet_address **addr) +{ + socklen_t slen = 1024; + int ret; + + *addr = JCL_malloc(env, slen); + + slen -= sizeof(jint); + ret = getpeername(fd, (struct sockaddr *)(*addr)->data, &slen ); + if (ret != 0) + { + int err = errno; + JCL_free(env, *addr); + return err; + } + + (*addr)->len = slen; + + return 0; +} + +jint cpnet_setBroadcast(JNIEnv *env UNUSED, jint fd, jint flag) +{ + int ret; + + ret = setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &flag, sizeof(flag)); + if (ret != 0) + return errno; + + return 0; +} + +#if defined (HAVE_MSG_NOSIGNAL) +#elif defined (HAVE_SO_NOSIGPIPE) +static int setsockopt_NOSIGPIPE (int fd) +{ + int setToTrue = 1; + return setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &setToTrue, sizeof(setToTrue)); +} +#endif + +jint cpnet_send (JNIEnv *env UNUSED, jint fd, jbyte *data, jint len, jint *bytes_sent) +{ + ssize_t ret; + + if (waitForWritable(fd) < 0) + return ETIMEDOUT; + +#if defined (HAVE_MSG_NOSIGNAL) + ret = send(fd, data, len, MSG_NOSIGNAL); +#elif defined (HAVE_SO_NOSIGPIPE) + ret = setsockopt_NOSIGPIPE(fd); + if (ret == 0) ret = send(fd, data, len, 0); +#else + /* We want SIGPIPE to be omitted. But this configuration does not have an + * option for that. + */ + ret = send(fd, data, len, 0); +#endif + if (ret < 0) + return errno; + + *bytes_sent = ret; + + return 0; +} + +jint cpnet_sendTo (JNIEnv *env UNUSED, jint fd, jbyte *data, jint len, cpnet_address *addr, jint *bytes_sent) +{ + ssize_t ret; + + if (waitForWritable(fd) < 0) + return ETIMEDOUT; + +#if defined (HAVE_MSG_NOSIGNAL) + ret = sendto(fd, data, len, MSG_NOSIGNAL, (struct sockaddr *)addr->data, + addr->len); +#elif defined (HAVE_SO_NOSIGPIPE) + ret = setsockopt_NOSIGPIPE(fd); + if (ret == 0) + { + ret = sendto(fd, data, len, 0, (struct sockaddr *)addr->data, + addr->len); + } +#else + /* We want SIGPIPE to be omitted. But this configuration does not have an + * option for that. + */ + ret = sendto(fd, data, len, 0, (struct sockaddr *)addr->data, + addr->len); +#endif + + if (ret < 0) + return errno; + + *bytes_sent = ret; + return 0; +} + +jint cpnet_recv (JNIEnv *env UNUSED, jint fd, jbyte *data, jint len, jint *bytes_recv) +{ + ssize_t ret; + + if (waitForReadable(fd) < 0) + return ETIMEDOUT; + + ret = recv(fd, data, len, 0); + if (ret < 0) + return errno; + + *bytes_recv = ret; + + return 0; +} + +jint cpnet_recvFrom (JNIEnv *env, jint fd, jbyte *data, jint len, cpnet_address **addr, jint *bytes_recv) +{ + socklen_t slen = 1024; + ssize_t ret; + + if (waitForReadable(fd) < 0) + return ETIMEDOUT; + + *addr = JCL_malloc(env, slen); + + slen -= sizeof(jint); + ret = recvfrom(fd, data, len, 0, (struct sockaddr *) (*addr)->data, &slen); + if (ret < 0) + { + int err = errno; + JCL_free(env, *addr); + return err; + } + + (*addr)->len = slen; + *bytes_recv = ret; + + return 0; +} + +jint cpnet_setSocketTCPNoDelay (JNIEnv *env UNUSED, jint fd, jint nodelay) +{ + socklen_t len = sizeof(jint); + int ret; + + ret = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &nodelay, len); + if (ret < 0) + return errno; + + return 0; +} + +jint cpnet_getSocketTCPNoDelay (JNIEnv *env UNUSED, jint fd, jint *nodelay) +{ + socklen_t len = sizeof(jint); + int ret; + + ret = getsockopt(fd, IPPROTO_TCP, TCP_NODELAY, nodelay, &len); + if (ret < 0) + return errno; + + return 0; +} + +jint cpnet_setLinger (JNIEnv *env UNUSED, jint fd, jint flag, jint value) +{ + socklen_t len = sizeof(struct linger); + int ret; + struct linger __linger; + + if (flag) + { + __linger.l_onoff = 0; + } + else + { + __linger.l_linger = value; + __linger.l_onoff = 1; + } + + ret = setsockopt(fd, SOL_SOCKET, SO_LINGER, &__linger, len); + if (ret < 0) + return errno; + + return 0; +} + +jint cpnet_getLinger (JNIEnv *env UNUSED, jint fd, jint *flag, jint *value) +{ + socklen_t slen = sizeof(struct linger); + struct linger __linger; + int ret; + + ret = getsockopt(fd, SOL_SOCKET, SO_LINGER, &__linger, &slen); + if (ret != 0) + return errno; + + *flag = __linger.l_onoff; + *value = __linger.l_linger; + + return ret; +} + +jint cpnet_setSocketTimeout (JNIEnv *env UNUSED, jint fd, jint value) +{ + socketTimeouts[fd] = value; + return 0; +} + +jint cpnet_getSocketTimeout (JNIEnv *env UNUSED, jint fd, jint *value) +{ + *value = socketTimeouts[fd]; + return 0; +} + +jint cpnet_setSendBuf (JNIEnv *env UNUSED, jint fd, jint value) +{ + int ret; + + ret = setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &value, sizeof(value)); + if (ret != 0) + return errno; + + return 0; +} + +jint cpnet_getSendBuf (JNIEnv *env UNUSED, jint fd, jint *value) +{ + int ret; + socklen_t slen = sizeof(*value); + + ret = getsockopt(fd, SOL_SOCKET, SO_SNDBUF, value, &slen); + if (ret != 0) + return errno; + + return 0; +} + +jint cpnet_setRecvBuf (JNIEnv *env UNUSED, jint fd, jint value) +{ + int ret; + + ret = setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &value, sizeof(value)); + if (ret != 0) + return errno; + + return 0; +} + +jint cpnet_getRecvBuf (JNIEnv *env UNUSED, jint fd, jint *value) +{ + int ret; + socklen_t slen = sizeof(*value); + + ret = getsockopt(fd, SOL_SOCKET, SO_RCVBUF, value, &slen); + if (ret != 0) + return errno; + + return 0; +} + +jint cpnet_setTTL (JNIEnv *env UNUSED, jint fd, jint value) +{ + int ret; + + ret = setsockopt(fd, IPPROTO_IP, IP_TTL, &value, sizeof(value)); + if (ret != 0) + return errno; + + return 0; +} + +jint cpnet_getTTL (JNIEnv *env UNUSED, jint fd, jint *value) +{ + int ret; + socklen_t slen = sizeof(*value); + + ret = getsockopt(fd, IPPROTO_IP, IP_TTL, value, &slen); + if (ret != 0) + return errno; + + return 0; +} + +jint cpnet_setMulticastIF (JNIEnv *env UNUSED, jint fd, cpnet_address *addr) +{ + int ret; + + ret = setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, (struct sockaddr *)addr->data, addr->len); + if (ret != 0) + return errno; + + return 0; +} + +jint cpnet_getMulticastIF (JNIEnv *env, jint fd, cpnet_address **addr) +{ + socklen_t slen = 1024; + int ret; + + *addr = JCL_malloc(env, slen); + + slen -= sizeof(jint); + ret = getsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, (struct sockaddr *)(*addr)->data, &slen); + (*addr)->len = slen; + + if (ret != 0) + return errno; + + return 0; +} + +jint cpnet_setReuseAddress (JNIEnv *env UNUSED, jint fd, jint reuse) +{ + int ret; + + ret = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)); + if (ret != 0) + return errno; + + return 0; +} + +jint cpnet_getReuseAddress (JNIEnv *env UNUSED, jint fd, jint *reuse) +{ + int ret; + socklen_t slen = sizeof(*reuse); + + ret = getsockopt(fd, SOL_SOCKET, SO_REUSEADDR, reuse, &slen); + if (ret != 0) + return errno; + + return 0; +} + +jint cpnet_setKeepAlive (JNIEnv *env UNUSED, jint fd, jint keep) +{ + int ret; + + ret = setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &keep, sizeof(keep)); + if (ret != 0) + return errno; + + return 0; +} + +jint cpnet_getKeepAlive (JNIEnv *env UNUSED, jint fd, jint *keep) +{ + int ret; + socklen_t slen = sizeof(*keep); + + ret = getsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, keep, &slen); + if (ret != 0) + return errno; + + return 0; +} + +jint cpnet_addMembership (JNIEnv *env UNUSED, jint fd, cpnet_address *addr) +{ + struct ip_mreq req; + int ret; + struct sockaddr_in *sockaddr = (struct sockaddr_in *)addr->data; + + memset(&req, 0, sizeof(req)); + req.imr_multiaddr = sockaddr->sin_addr; + req.imr_interface.s_addr = INADDR_ANY; + ret = setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &req, sizeof(req)); + if (ret != 0) + return errno; + + return 0; +} + +jint cpnet_dropMembership (JNIEnv *env UNUSED, jint fd, cpnet_address *addr) +{ + struct ip_mreq req; + int ret; + struct sockaddr_in *sockaddr = (struct sockaddr_in *)addr->data; + + memset(&req, 0, sizeof(req)); + req.imr_multiaddr = sockaddr->sin_addr; + req.imr_interface.s_addr = INADDR_ANY; + ret = setsockopt(fd, IPPROTO_IP, IP_DROP_MEMBERSHIP, &req, sizeof(req)); + if (ret != 0) + return errno; + + return 0; +} + +jint cpnet_getAvailableBytes (JNIEnv *env UNUSED, jint fd, jint *availableBytes) +{ + int ret; + + ret = ioctl(fd, FIONREAD, availableBytes); + if (ret != 0) + return errno; + + return 0; +} + +jint cpnet_getHostname (JNIEnv *env UNUSED, char *hostname, jint hostname_len) +{ + int ret; + + ret = gethostname(hostname, hostname_len); + if (ret != 0) + return errno; + + hostname[hostname_len-1] = 0; + return 0; +} + +jint cpnet_getHostByName (JNIEnv *env, const char *hostname, cpnet_address ***addresses, jint *addresses_count) +{ + struct hostent hret; + struct hostent *result; + jint buflen = 1024; + int herr = 0; + int ret = 0; + int counter = 0; + cpnet_address **addr_arr; + int i; + char *buf; + + do + { + buf = (char *)JCL_malloc(env, buflen); + +#ifdef HAVE_GETHOSTBYNAME_R +# if defined(HAVE_FUNC_GETHOSTBYNAME_R_6) + ret = gethostbyname_r (hostname, &hret, buf, buflen, &result, &herr); +# elif defined(HAVE_FUNC_GETHOSTBYNAME_R_5) + result = gethostbyname_r(hostname, &hret, buf, buflen, &herr); +# elif defined(HAVE_FUNC_GETHOSTBYNAME_R_3) +# error IMPLEMENT ME! +# else +# error unknown number of arguments for gethostbyname_r +# endif +#else + hret.h_addr_list = NULL; + hret.h_addrtype = 0; + + result = gethostbyname (hostname); + if (result == NULL) + return -errno; + memcpy (&hret, result, sizeof (struct hostent)); +#endif + if (ret != 0 || result == NULL) + { + if (herr == ERANGE) + { + buflen *= 2; + JCL_free(env, buf); + continue; + } + JCL_free(env, buf); + + return -herr; + } + + break; + } + while (1); + + while (hret.h_addr_list[counter] != NULL) + counter++; + + *addresses_count = counter; + addr_arr = *addresses = JCL_malloc(env, sizeof(cpnet_address *) * counter); + switch (hret.h_addrtype) + { + case AF_INET: + for (i = 0; i < counter; i++) + { + addr_arr[i] = cpnet_newIPV4Address(env); + cpnet_bytesToIPV4Address(addr_arr[i], (jbyte *)hret.h_addr_list[i]); + } + break; +#ifdef HAVE_INET6 + case AF_INET6: + for (i = 0; i < counter; i++) + { + addr_arr[i] = cpnet_newIPV6Address(env); + cpnet_bytesToIPV6Address(addr_arr[i], (jbyte *)hret.h_addr_list[i]); + } + break; +#endif + default: + *addresses_count = 0; + JCL_free(env, addr_arr); + break; + } + + JCL_free(env, buf); + + return 0; +} + +jint cpnet_getHostByAddr (JNIEnv *env UNUSED, cpnet_address *addr, char *hostname, jint hostname_len) +{ + union + { + struct sockaddr_in *addr_v4; + struct sockaddr_in6 *addr_v6; + char *data; + } haddr; + void *raw_addr; + int addr_type; + struct hostent *ret; + int addr_len; + + haddr.data = addr->data; + + if (haddr.addr_v4->sin_family == AF_INET) + { + raw_addr = &haddr.addr_v4->sin_addr; + addr_len = sizeof(haddr.addr_v4->sin_addr); + addr_type = AF_INET; + } +#ifdef HAVE_INET6 + else if (haddr.addr_v6->sin6_family == AF_INET6) + { + raw_addr = &haddr.addr_v6->sin6_addr; + addr_type = AF_INET6; + addr_len = sizeof(haddr.addr_v6->sin6_addr); + } +#endif + else + return EINVAL; + + /* Here we do not have any thread safe call. VM implementors will have to + * do a big lock. Or it should be put on the Classpath VM interface. + */ + ret = gethostbyaddr(raw_addr, addr_len, addr_type); + if (ret == NULL) + { + /* The trouble here is how to distinguish the two cases ? */ + if (h_errno != 0) + return h_errno; + else + return errno; + + } + strncpy(hostname, ret->h_name, hostname_len); + + return 0; +} + +jint cpnet_aton (JNIEnv *env, const char *hostname, cpnet_address **addr) +{ + jbyte *bytes = NULL; + +#if defined(HAVE_INET_PTON) && defined(HAVE_INET6) + jbyte inet6_addr[16]; +#endif + +#ifdef HAVE_INET_ATON + struct in_addr laddr; + if (inet_aton (hostname, &laddr)) + { + bytes = (jbyte *) &laddr; + } +#elif defined(HAVE_INET_ADDR) +#if ! HAVE_IN_ADDR_T + typedef jint in_addr_t; +#endif + in_addr_t laddr = inet_addr (hostname); + if (laddr != (in_addr_t)(-1)) + { + bytes = (jbyte *) &laddr; + } +#endif + if (bytes) + { + *addr = cpnet_newIPV4Address(env); + cpnet_bytesToIPV4Address(*addr, bytes); + return 0; + } + +#if defined(HAVE_INET_PTON) && defined(HAVE_INET6) + if (inet_pton (AF_INET6, hostname, inet6_addr) > 0) + { + *addr = cpnet_newIPV6Address(env); + cpnet_bytesToIPV6Address(*addr, inet6_addr); + return 0; + } +#endif + + *addr = NULL; + return 0; +} + +void cpnet_freeAddresses(JNIEnv * env, cpnet_address **addr, jint addresses_count) +{ + jint i; + + for (i = 0; i < addresses_count; i++) + cpnet_freeAddress(env, addr[i]); +} diff --git a/libjava/classpath/native/jni/native-lib/cpnet.h b/libjava/classpath/native/jni/native-lib/cpnet.h new file mode 100644 index 000000000..979c363c2 --- /dev/null +++ b/libjava/classpath/native/jni/native-lib/cpnet.h @@ -0,0 +1,221 @@ +/* cpnet.h - + Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#ifndef _CLASSPATH_NET_H_INCLUDED +#define _CLASSPATH_NET_H_INCLUDED + +#include +#include +#include + +#include +#include +#ifdef HAVE_NETINET_IN_SYSTM_H +#include +#endif /* HAVE_NETINET_IN_SYSTM_H */ +#include +#ifdef HAVE_NETINET_IP_H +#include +#endif /* HAVE_NETINET_IP_H */ + +typedef struct { + jint len; + char data[1]; +} cpnet_address; + +#define CPNET_SHUTDOWN_READ 1 +#define CPNET_SHUTDOWN_WRITE 2 + +JNIEXPORT jint cpnet_openSocketStream(JNIEnv *env, jint *fd, jint family); +JNIEXPORT jint cpnet_openSocketDatagram(JNIEnv *env, jint *fd, jint family); +JNIEXPORT jint cpnet_shutdown (JNIEnv *env, jint fd, jbyte flag); +JNIEXPORT jint cpnet_close(JNIEnv *env, jint fd); +JNIEXPORT jint cpnet_listen(JNIEnv *env, jint fd, jint queuelen); +JNIEXPORT jint cpnet_accept(JNIEnv *env, jint fd, jint *newfd); +JNIEXPORT jint cpnet_bind(JNIEnv *env, jint fd, cpnet_address *addr); +JNIEXPORT jint cpnet_connect(JNIEnv *env, jint fd, cpnet_address *addr); +JNIEXPORT jint cpnet_getLocalAddr(JNIEnv *env, jint fd, cpnet_address **addr); +JNIEXPORT jint cpnet_getRemoteAddr(JNIEnv *env, jint fd, cpnet_address **addr); +JNIEXPORT jint cpnet_setBroadcast(JNIEnv *env, jint fd, jint flag); +JNIEXPORT jint cpnet_send (JNIEnv *env, jint fd, jbyte *data, jint len, jint *bytes_sent); +JNIEXPORT jint cpnet_sendTo (JNIEnv *env, jint fd, jbyte *data, jint len, cpnet_address *addr, jint *bytes_sent); +JNIEXPORT jint cpnet_recv (JNIEnv *env, jint fd, jbyte *data, jint len, jint *bytes_recv); +JNIEXPORT jint cpnet_recvFrom (JNIEnv *env, jint fd, jbyte *data, jint len, cpnet_address **addr, jint *bytes_recv); +JNIEXPORT jint cpnet_setSocketTCPNoDelay (JNIEnv *env, jint fd, jint nodelay); +JNIEXPORT jint cpnet_getSocketTCPNoDelay (JNIEnv *env, jint fd, jint *nodelay); +JNIEXPORT jint cpnet_setLinger (JNIEnv *env, jint fd, jint flag, jint value); +JNIEXPORT jint cpnet_getLinger (JNIEnv *env, jint fd, jint *flag, jint *value); +JNIEXPORT jint cpnet_setSocketTimeout (JNIEnv *env, jint fd, jint value); +JNIEXPORT jint cpnet_getSocketTimeout (JNIEnv *env, jint fd, jint *value); +JNIEXPORT jint cpnet_setSendBuf (JNIEnv *env, jint fd, jint value); +JNIEXPORT jint cpnet_getSendBuf (JNIEnv *env, jint fd, jint *value); +JNIEXPORT jint cpnet_setRecvBuf (JNIEnv *env, jint fd, jint value); +JNIEXPORT jint cpnet_getRecvBuf (JNIEnv *env, jint fd, jint *value); +JNIEXPORT jint cpnet_setTTL (JNIEnv *env, jint fd, jint value); +JNIEXPORT jint cpnet_getTTL (JNIEnv *env, jint fd, jint *value); +JNIEXPORT jint cpnet_setMulticastIF (JNIEnv *env, jint fd, cpnet_address *addr); +JNIEXPORT jint cpnet_getMulticastIF (JNIEnv *env, jint fd, cpnet_address **addr); +JNIEXPORT jint cpnet_setReuseAddress (JNIEnv *env, jint fd, jint reuse); +JNIEXPORT jint cpnet_getReuseAddress (JNIEnv *env, jint fd, jint *reuse); +JNIEXPORT jint cpnet_setKeepAlive (JNIEnv *env, jint fd, jint keep); +JNIEXPORT jint cpnet_getKeepAlive (JNIEnv *env, jint fd, jint *keep); +JNIEXPORT jint cpnet_getBindAddress (JNIEnv *env, jint fd, cpnet_address **addr); +JNIEXPORT jint cpnet_addMembership (JNIEnv *env, jint fd, cpnet_address *addr); +JNIEXPORT jint cpnet_dropMembership (JNIEnv *env, jint fd, cpnet_address *addr); +JNIEXPORT jint cpnet_getAvailableBytes (JNIEnv *env, jint fd, jint *availableBytes); +JNIEXPORT jint cpnet_getHostname (JNIEnv *env, char *hostname, jint hostname_len); +JNIEXPORT jint cpnet_getHostByName (JNIEnv *env, const char *hostname, cpnet_address ***adresses, jint *addresses_count); +JNIEXPORT jint cpnet_getHostByAddr (JNIEnv *env, cpnet_address *addr, char *hostname, jint hostname_len); +JNIEXPORT jint cpnet_aton (JNIEnv *env, const char *hostname, cpnet_address **addr); +JNIEXPORT void cpnet_freeAddresses(JNIEnv * env, cpnet_address **addr, jint addresses_count); + +static inline cpnet_address *cpnet_newIPV4Address(JNIEnv * env) +{ + cpnet_address *addr = (cpnet_address *)JCL_malloc(env, sizeof(cpnet_address) + sizeof(struct sockaddr_in)); + struct sockaddr_in *netaddr = (struct sockaddr_in *)&(addr->data[0]); + + addr->len = sizeof(struct sockaddr_in); + memset(netaddr, 0, addr->len); + netaddr->sin_family = AF_INET; + return addr; +} + +static inline void cpnet_setIPV4Any(cpnet_address *addr) +{ + struct sockaddr_in *netaddr = (struct sockaddr_in *)&(addr->data[0]); + + netaddr->sin_addr.s_addr = INADDR_ANY; +} + +#ifdef HAVE_INET6 +static inline cpnet_address *cpnet_newIPV6Address(JNIEnv * env) +{ + cpnet_address * addr = (cpnet_address *)JCL_malloc(env, sizeof(cpnet_address) + sizeof(struct sockaddr_in6)); + struct sockaddr_in6 *netaddr = (struct sockaddr_in6 *)&(addr->data[0]); + + addr->len = sizeof(struct sockaddr_in6); + memset(netaddr, 0, addr->len); + netaddr->sin6_family = AF_INET6; + + return addr; +} +#endif + +static inline void cpnet_freeAddress(JNIEnv * env, cpnet_address *addr) +{ + JCL_free(env, addr); +} + +static inline void cpnet_addressSetPort(cpnet_address *addr, jint port) +{ + struct sockaddr_in *ipaddr = (struct sockaddr_in *)&(addr->data[0]); + + ipaddr->sin_port = htons(port); +} + +static inline jint cpnet_addressGetPort(cpnet_address *addr) +{ + struct sockaddr_in *ipaddr = (struct sockaddr_in *)&(addr->data[0]); + + return ntohs(ipaddr->sin_port); +} + +static inline jboolean cpnet_isAddressEqual(cpnet_address *addr1, cpnet_address *addr2) +{ + if (addr1->len != addr2->len) + return JNI_FALSE; + + return memcmp(addr1->data, addr2->data, addr1->len) == 0; +} + +#ifdef HAVE_INET6 +static inline jboolean cpnet_isIPV6Address(cpnet_address *addr) +{ + struct sockaddr_in *ipaddr = (struct sockaddr_in *)&(addr->data[0]); + + return ipaddr->sin_family == AF_INET6; +} +#endif + +static inline jboolean cpnet_isIPV4Address(cpnet_address *addr) +{ + struct sockaddr_in *ipaddr = (struct sockaddr_in *)&(addr->data[0]); + + return ipaddr->sin_family == AF_INET; +} + +static inline void cpnet_IPV4AddressToBytes(cpnet_address *netaddr, jbyte *octets) +{ + struct sockaddr_in *ipaddr = (struct sockaddr_in *)&(netaddr->data[0]); + unsigned long sysaddr = ntohl(ipaddr->sin_addr.s_addr); + + octets[0] = ((sysaddr >> 24) & 0xff); + octets[1] = ((sysaddr >> 16) & 0xff); + octets[2] = ((sysaddr >> 8) & 0xff); + octets[3] = (sysaddr & 0xff); +} + +static inline void cpnet_bytesToIPV4Address(cpnet_address *netaddr, jbyte *octets) +{ + jint sysaddr; + struct sockaddr_in *ipaddr = (struct sockaddr_in *)&(netaddr->data[0]); + + sysaddr = ((jint)(unsigned char)octets[0]) << 24; + sysaddr |= ((jint)(unsigned char)octets[1]) << 16; + sysaddr |= ((jint)(unsigned char)octets[2]) << 8; + sysaddr |= ((jint)(unsigned char)octets[3]); + + ipaddr->sin_addr.s_addr = htonl(sysaddr); +} + +#ifdef HAVE_INET6 +static inline void cpnet_IPV6AddressToBytes(cpnet_address *netaddr, jbyte *octets) +{ + struct sockaddr_in6 *ipaddr = (struct sockaddr_in6 *)&(netaddr->data[0]); + + memcpy(octets, &ipaddr->sin6_addr, 16); +} + +static inline void cpnet_bytesToIPV6Address(cpnet_address *netaddr, jbyte *octets) +{ + struct sockaddr_in6 *ipaddr = (struct sockaddr_in6 *)&(netaddr->data[0]); + + memcpy(&ipaddr->sin6_addr, octets, 16); +} +#endif + +#endif diff --git a/libjava/classpath/native/jni/native-lib/cpproc.c b/libjava/classpath/native/jni/native-lib/cpproc.c new file mode 100644 index 000000000..0c80703d6 --- /dev/null +++ b/libjava/classpath/native/jni/native-lib/cpproc.c @@ -0,0 +1,141 @@ +/* cpproc.c - + Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include "config.h" +#include +#include "cpproc.h" +#include +#include +#include +#include +#include +#include + +static void close_all_fds(int *fds, int numFds) +{ + int i; + + for (i = 0; i < numFds; i++) + close(fds[i]); +} + +int cpproc_forkAndExec (char * const *commandLine, char * const * newEnviron, + int *fds, int pipe_count, pid_t *out_pid, const char *wd) +{ + int local_fds[6]; + int i; + pid_t pid; + + for (i = 0; i < (pipe_count * 2); i += 2) + { + if (pipe(&local_fds[i]) < 0) + { + int err = errno; + + close_all_fds(local_fds, i); + + return err; + } + } + + pid = fork(); + + switch (pid) + { + case 0: + dup2(local_fds[0], 0); + dup2(local_fds[3], 1); + if (pipe_count == 3) + dup2(local_fds[5], 2); + else + dup2(1, 2); + + close_all_fds(local_fds, pipe_count * 2); + + i = chdir(wd); + /* FIXME: Handle the return value */ + if (newEnviron == NULL) + execvp(commandLine[0], commandLine); + else + execve(commandLine[0], commandLine, newEnviron); + + abort(); + + break; + case -1: + { + int err = errno; + + close_all_fds(local_fds, pipe_count * 2); + return err; + } + default: + close(local_fds[0]); + close(local_fds[3]); + if (pipe_count == 3) + close(local_fds[5]); + + fds[0] = local_fds[1]; + fds[1] = local_fds[2]; + fds[2] = local_fds[4]; + *out_pid = pid; + return 0; + } + + /* keep compiler happy */ + + return 0; +} + +int cpproc_waitpid (pid_t pid, int *status, pid_t *outpid, int options) +{ + pid_t wp = waitpid(pid, status, options); + + if (wp < 0) + return errno; + + *outpid = wp; + return 0; +} + +int cpproc_kill (pid_t pid, int signal) +{ + if (kill(pid, signal) < 0) + return errno; + + return 0; +} diff --git a/libjava/classpath/native/jni/native-lib/cpproc.h b/libjava/classpath/native/jni/native-lib/cpproc.h new file mode 100644 index 000000000..5e8db5800 --- /dev/null +++ b/libjava/classpath/native/jni/native-lib/cpproc.h @@ -0,0 +1,52 @@ +/* cpproc.h - + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ +#ifndef _CLASSPATH_PROC_H_INCLUDED +#define _CLASSPATH_PROC_H_INCLUDED + +#include + +#define CPIO_EXEC_STDIN 0 +#define CPIO_EXEC_STDOUT 1 +#define CPIO_EXEC_STDERR 2 +#define CPIO_EXEC_NUM_PIPES 3 + +JNIEXPORT int cpproc_forkAndExec (char * const *commandLine, char * const * newEnviron, + int *fds, int pipe_count, pid_t *pid, const char *wd); +JNIEXPORT int cpproc_waitpid (pid_t pid, int *status, pid_t *outpid, int options); +JNIEXPORT int cpproc_kill (pid_t pid, int signal); + +#endif diff --git a/libjava/classpath/native/jni/qt-peer/.cvsignore b/libjava/classpath/native/jni/qt-peer/.cvsignore new file mode 100644 index 000000000..369a52a2a --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/.cvsignore @@ -0,0 +1,9 @@ +*.o +*.a +*.lo +*.la +.libs +.deps +Makefile +Makefile.in +slotcallbacks.moc.h diff --git a/libjava/classpath/native/jni/qt-peer/Makefile.am b/libjava/classpath/native/jni/qt-peer/Makefile.am new file mode 100644 index 000000000..03dcd9629 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/Makefile.am @@ -0,0 +1,85 @@ +# Qt AWT backend for Classpath +# + +## GCJ LOCAL: don't install this library +noinst_LTLIBRARIES = libqtpeer.la + +AM_LDFLAGS = @CLASSPATH_MODULE@ @QT_LIBS@ +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ + +## GCJ LOCAL: add libstdc++-v3 include directories +AM_CXXFLAGS = @QT_CFLAGS@ \ + -I$(top_builddir)/../../libstdc++-v3/include/$(target_alias) \ + -I$(top_builddir)/../../libstdc++-v3/include \ + -I$(top_srcdir)/../../libstdc++-v3/include \ + -I$(top_srcdir)/../../libstdc++-v3/libsupc++ + +libqtpeer_la_MOC = \ + slotcallbacks.moc.h + +slotcallbacks.moc.h: slotcallbacks.cpp + $(MOC) -o slotcallbacks.moc.h $(srcdir)/slotcallbacks.cpp + +nodist_libqtpeer_la_SOURCES = \ + $(libqtpeer_la_MOC) + +libqtpeer_la_SOURCES = \ + buttonevent.h \ + componentevent.cpp \ + componentevent.h \ + containers.h \ + eventmethods.h \ + keybindings.cpp \ + keybindings.h \ + mainqtthread.cpp \ + mainthreadinterface.cpp \ + mainthreadinterface.h \ + nativewrapper.cpp \ + nativewrapper.h \ + qmatrix.cpp \ + qpainterpath.cpp \ + qpen.cpp \ + qtaudioclip.cpp \ + qtbuttonpeer.cpp \ + qtcanvaspeer.cpp \ + qtcheckboxpeer.cpp \ + qtchoicepeer.cpp \ + qtcomponent.cpp \ + qtcomponent.h \ + qtcomponentpeer.cpp \ + qtdialogpeer.cpp \ + qtembeddedwindowpeer.cpp \ + qtfiledialogpeer.cpp \ + qtfont.h \ + qtfontmetrics.cpp \ + qtfontpeer.cpp \ + qtframepeer.cpp \ + qtgraphics.cpp \ + qtgraphics.h \ + qtimage.cpp \ + qtimage.h \ + qtlabelpeer.cpp \ + qtlistpeer.cpp \ + qtmenubarpeer.cpp \ + qtmenucomponentpeer.cpp \ + qtmenuitempeer.cpp \ + qtmenupeer.cpp \ + qtpanelpeer.cpp \ + qtpopupmenupeer.cpp \ + qtscreendevice.cpp \ + qtscrollbarpeer.cpp \ + qtscrollpanepeer.cpp \ + qtstrings.cpp \ + qtstrings.h \ + qttextareapeer.cpp \ + qttextfieldpeer.cpp \ + qttoolkit.cpp \ + qtvolatileimage.cpp \ + qtwindowpeer.cpp \ + slotcallbacks.cpp \ + slotcallbacks.h +libqtpeer_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version + +BUILT_SOURCES = $(libqtpeer_la_MOC) + +CLEANFILES = so_locations $(BUILT_SOURCES) diff --git a/libjava/classpath/native/jni/qt-peer/Makefile.in b/libjava/classpath/native/jni/qt-peer/Makefile.in new file mode 100644 index 000000000..d65474e7b --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/Makefile.in @@ -0,0 +1,703 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +# Qt AWT backend for Classpath +# + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +subdir = native/jni/qt-peer +DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/../../config/depstand.m4 \ + $(top_srcdir)/../../config/lead-dot.m4 \ + $(top_srcdir)/../../config/lib-ld.m4 \ + $(top_srcdir)/../../config/lib-link.m4 \ + $(top_srcdir)/../../config/lib-prefix.m4 \ + $(top_srcdir)/../../config/multi.m4 \ + $(top_srcdir)/../../config/no-executables.m4 \ + $(top_srcdir)/../../config/override.m4 \ + $(top_srcdir)/../../libtool.m4 \ + $(top_srcdir)/../../ltoptions.m4 \ + $(top_srcdir)/../../ltsugar.m4 \ + $(top_srcdir)/../../ltversion.m4 \ + $(top_srcdir)/../../lt~obsolete.m4 \ + $(top_srcdir)/m4/ac_prog_antlr.m4 \ + $(top_srcdir)/m4/ac_prog_java.m4 \ + $(top_srcdir)/m4/ac_prog_java_works.m4 \ + $(top_srcdir)/m4/ac_prog_javac.m4 \ + $(top_srcdir)/m4/ac_prog_javac_works.m4 \ + $(top_srcdir)/m4/acattribute.m4 $(top_srcdir)/m4/accross.m4 \ + $(top_srcdir)/m4/acinclude.m4 \ + $(top_srcdir)/m4/ax_create_stdint_h.m4 \ + $(top_srcdir)/m4/ax_func_which_gethostbyname_r.m4 \ + $(top_srcdir)/m4/gcc_attribute.m4 $(top_srcdir)/m4/iconv.m4 \ + $(top_srcdir)/m4/pkg.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/../../mkinstalldirs +CONFIG_HEADER = $(top_builddir)/include/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +LTLIBRARIES = $(noinst_LTLIBRARIES) +libqtpeer_la_LIBADD = +am_libqtpeer_la_OBJECTS = componentevent.lo keybindings.lo \ + mainqtthread.lo mainthreadinterface.lo nativewrapper.lo \ + qmatrix.lo qpainterpath.lo qpen.lo qtaudioclip.lo \ + qtbuttonpeer.lo qtcanvaspeer.lo qtcheckboxpeer.lo \ + qtchoicepeer.lo qtcomponent.lo qtcomponentpeer.lo \ + qtdialogpeer.lo qtembeddedwindowpeer.lo qtfiledialogpeer.lo \ + qtfontmetrics.lo qtfontpeer.lo qtframepeer.lo qtgraphics.lo \ + qtimage.lo qtlabelpeer.lo qtlistpeer.lo qtmenubarpeer.lo \ + qtmenucomponentpeer.lo qtmenuitempeer.lo qtmenupeer.lo \ + qtpanelpeer.lo qtpopupmenupeer.lo qtscreendevice.lo \ + qtscrollbarpeer.lo qtscrollpanepeer.lo qtstrings.lo \ + qttextareapeer.lo qttextfieldpeer.lo qttoolkit.lo \ + qtvolatileimage.lo qtwindowpeer.lo slotcallbacks.lo +am__objects_1 = +nodist_libqtpeer_la_OBJECTS = $(am__objects_1) +libqtpeer_la_OBJECTS = $(am_libqtpeer_la_OBJECTS) \ + $(nodist_libqtpeer_la_OBJECTS) +libqtpeer_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \ + $(CXXFLAGS) $(libqtpeer_la_LDFLAGS) $(LDFLAGS) -o $@ +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/include +depcomp = $(SHELL) $(top_srcdir)/../../depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +LTCXXCOMPILE = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +CXXLD = $(CXX) +CXXLINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(libqtpeer_la_SOURCES) $(nodist_libqtpeer_la_SOURCES) +ETAGS = etags +CTAGS = ctags +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +ANTLR = @ANTLR@ +ANTLR_JAR = @ANTLR_JAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CAIRO_CFLAGS = @CAIRO_CFLAGS@ +CAIRO_LIBS = @CAIRO_LIBS@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CLASSPATH_CONVENIENCE = @CLASSPATH_CONVENIENCE@ +CLASSPATH_INCLUDES = @CLASSPATH_INCLUDES@ +CLASSPATH_MODULE = @CLASSPATH_MODULE@ +COLLECTIONS_PREFIX = @COLLECTIONS_PREFIX@ +CP = @CP@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DATE = @DATE@ +DEFAULT_PREFS_PEER = @DEFAULT_PREFS_PEER@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +ECJ_JAR = @ECJ_JAR@ +EGREP = @EGREP@ +ERROR_CFLAGS = @ERROR_CFLAGS@ +EXAMPLESDIR = @EXAMPLESDIR@ +EXEEXT = @EXEEXT@ +EXTRA_CFLAGS = @EXTRA_CFLAGS@ +FGREP = @FGREP@ +FIND = @FIND@ +FREETYPE2_CFLAGS = @FREETYPE2_CFLAGS@ +FREETYPE2_LIBS = @FREETYPE2_LIBS@ +GCONF_CFLAGS = @GCONF_CFLAGS@ +GCONF_LIBS = @GCONF_LIBS@ +GDK_CFLAGS = @GDK_CFLAGS@ +GDK_LIBS = @GDK_LIBS@ +GJDOC = @GJDOC@ +GLIB_CFLAGS = @GLIB_CFLAGS@ +GLIB_LIBS = @GLIB_LIBS@ +GMP_CFLAGS = @GMP_CFLAGS@ +GMP_LIBS = @GMP_LIBS@ +GREP = @GREP@ +GSTREAMER_BASE_CFLAGS = @GSTREAMER_BASE_CFLAGS@ +GSTREAMER_BASE_LIBS = @GSTREAMER_BASE_LIBS@ +GSTREAMER_CFLAGS = @GSTREAMER_CFLAGS@ +GSTREAMER_FILE_READER = @GSTREAMER_FILE_READER@ +GSTREAMER_LIBS = @GSTREAMER_LIBS@ +GSTREAMER_MIXER_PROVIDER = @GSTREAMER_MIXER_PROVIDER@ +GSTREAMER_PLUGINS_BASE_CFLAGS = @GSTREAMER_PLUGINS_BASE_CFLAGS@ +GSTREAMER_PLUGINS_BASE_LIBS = @GSTREAMER_PLUGINS_BASE_LIBS@ +GST_PLUGIN_LDFLAGS = @GST_PLUGIN_LDFLAGS@ +GTK_CFLAGS = @GTK_CFLAGS@ +GTK_LIBS = @GTK_LIBS@ +INIT_LOAD_LIBRARY = @INIT_LOAD_LIBRARY@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAR = @JAR@ +JAVA = @JAVA@ +JAVAC = @JAVAC@ +JAVAC_IS_GCJ = @JAVAC_IS_GCJ@ +JAVAC_MEM_OPT = @JAVAC_MEM_OPT@ +JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION = @JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION@ +JAY = @JAY@ +JAY_SKELETON = @JAY_SKELETON@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBDEBUG = @LIBDEBUG@ +LIBICONV = @LIBICONV@ +LIBMAGIC = @LIBMAGIC@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBVERSION = @LIBVERSION@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBICONV = @LTLIBICONV@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MKDIR = @MKDIR@ +MKDIR_P = @MKDIR_P@ +MOC = @MOC@ +MOZILLA_CFLAGS = @MOZILLA_CFLAGS@ +MOZILLA_LIBS = @MOZILLA_LIBS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PANGOFT2_CFLAGS = @PANGOFT2_CFLAGS@ +PANGOFT2_LIBS = @PANGOFT2_LIBS@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PATH_TO_ESCHER = @PATH_TO_ESCHER@ +PATH_TO_GLIBJ_ZIP = @PATH_TO_GLIBJ_ZIP@ +PERL = @PERL@ +PKG_CONFIG = @PKG_CONFIG@ +PLUGIN_DIR = @PLUGIN_DIR@ +QT_CFLAGS = @QT_CFLAGS@ +QT_LIBS = @QT_LIBS@ +RANLIB = @RANLIB@ +REMOVE = @REMOVE@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRICT_WARNING_CFLAGS = @STRICT_WARNING_CFLAGS@ +STRIP = @STRIP@ +TOOLSDIR = @TOOLSDIR@ +USER_JAVAH = @USER_JAVAH@ +VERSION = @VERSION@ +WANT_NATIVE_BIG_INTEGER = @WANT_NATIVE_BIG_INTEGER@ +WARNING_CFLAGS = @WARNING_CFLAGS@ +XMKMF = @XMKMF@ +XML_CFLAGS = @XML_CFLAGS@ +XML_LIBS = @XML_LIBS@ +XSLT_CFLAGS = @XSLT_CFLAGS@ +XSLT_LIBS = @XSLT_LIBS@ +XTEST_LIBS = @XTEST_LIBS@ +X_CFLAGS = @X_CFLAGS@ +X_EXTRA_LIBS = @X_EXTRA_LIBS@ +X_LIBS = @X_LIBS@ +X_PRE_LIBS = @X_PRE_LIBS@ +ZIP = @ZIP@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_ANTLR = @ac_ct_ANTLR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +default_toolkit = @default_toolkit@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +glibjdir = @glibjdir@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +multi_basedir = @multi_basedir@ +nativeexeclibdir = @nativeexeclibdir@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +toolexeclibdir = @toolexeclibdir@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +uudecode = @uudecode@ +vm_classes = @vm_classes@ +noinst_LTLIBRARIES = libqtpeer.la +AM_LDFLAGS = @CLASSPATH_MODULE@ @QT_LIBS@ +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ +AM_CXXFLAGS = @QT_CFLAGS@ \ + -I$(top_builddir)/../../libstdc++-v3/include/$(target_alias) \ + -I$(top_builddir)/../../libstdc++-v3/include \ + -I$(top_srcdir)/../../libstdc++-v3/include \ + -I$(top_srcdir)/../../libstdc++-v3/libsupc++ + +libqtpeer_la_MOC = \ + slotcallbacks.moc.h + +nodist_libqtpeer_la_SOURCES = \ + $(libqtpeer_la_MOC) + +libqtpeer_la_SOURCES = \ + buttonevent.h \ + componentevent.cpp \ + componentevent.h \ + containers.h \ + eventmethods.h \ + keybindings.cpp \ + keybindings.h \ + mainqtthread.cpp \ + mainthreadinterface.cpp \ + mainthreadinterface.h \ + nativewrapper.cpp \ + nativewrapper.h \ + qmatrix.cpp \ + qpainterpath.cpp \ + qpen.cpp \ + qtaudioclip.cpp \ + qtbuttonpeer.cpp \ + qtcanvaspeer.cpp \ + qtcheckboxpeer.cpp \ + qtchoicepeer.cpp \ + qtcomponent.cpp \ + qtcomponent.h \ + qtcomponentpeer.cpp \ + qtdialogpeer.cpp \ + qtembeddedwindowpeer.cpp \ + qtfiledialogpeer.cpp \ + qtfont.h \ + qtfontmetrics.cpp \ + qtfontpeer.cpp \ + qtframepeer.cpp \ + qtgraphics.cpp \ + qtgraphics.h \ + qtimage.cpp \ + qtimage.h \ + qtlabelpeer.cpp \ + qtlistpeer.cpp \ + qtmenubarpeer.cpp \ + qtmenucomponentpeer.cpp \ + qtmenuitempeer.cpp \ + qtmenupeer.cpp \ + qtpanelpeer.cpp \ + qtpopupmenupeer.cpp \ + qtscreendevice.cpp \ + qtscrollbarpeer.cpp \ + qtscrollpanepeer.cpp \ + qtstrings.cpp \ + qtstrings.h \ + qttextareapeer.cpp \ + qttextfieldpeer.cpp \ + qttoolkit.cpp \ + qtvolatileimage.cpp \ + qtwindowpeer.cpp \ + slotcallbacks.cpp \ + slotcallbacks.h + +libqtpeer_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version +BUILT_SOURCES = $(libqtpeer_la_MOC) +CLEANFILES = so_locations $(BUILT_SOURCES) +all: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) all-am + +.SUFFIXES: +.SUFFIXES: .cpp .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu native/jni/qt-peer/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu native/jni/qt-peer/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +clean-noinstLTLIBRARIES: + -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES) + @list='$(noinst_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libqtpeer.la: $(libqtpeer_la_OBJECTS) $(libqtpeer_la_DEPENDENCIES) + $(libqtpeer_la_LINK) $(libqtpeer_la_OBJECTS) $(libqtpeer_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/componentevent.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/keybindings.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mainqtthread.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mainthreadinterface.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nativewrapper.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qmatrix.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qpainterpath.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qpen.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qtaudioclip.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qtbuttonpeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qtcanvaspeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qtcheckboxpeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qtchoicepeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qtcomponent.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qtcomponentpeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qtdialogpeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qtembeddedwindowpeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qtfiledialogpeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qtfontmetrics.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qtfontpeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qtframepeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qtgraphics.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qtimage.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qtlabelpeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qtlistpeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qtmenubarpeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qtmenucomponentpeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qtmenuitempeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qtmenupeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qtpanelpeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qtpopupmenupeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qtscreendevice.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qtscrollbarpeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qtscrollpanepeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qtstrings.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qttextareapeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qttextfieldpeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qttoolkit.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qtvolatileimage.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qtwindowpeer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/slotcallbacks.Plo@am__quote@ + +.cpp.o: +@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $< + +.cpp.obj: +@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.cpp.lo: +@am__fastdepCXX_TRUE@ $(LTCXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(LTCXXCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags +check-am: all-am +check: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) check-am +all-am: Makefile $(LTLIBRARIES) +installdirs: +install: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." + -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES) +clean: clean-am + +clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: + +.MAKE: all check install install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-noinstLTLIBRARIES ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags dvi dvi-am html html-am info info-am install \ + install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-pdf install-pdf-am install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ + pdf pdf-am ps ps-am tags uninstall uninstall-am + + +slotcallbacks.moc.h: slotcallbacks.cpp + $(MOC) -o slotcallbacks.moc.h $(srcdir)/slotcallbacks.cpp + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/libjava/classpath/native/jni/qt-peer/buttonevent.h b/libjava/classpath/native/jni/qt-peer/buttonevent.h new file mode 100644 index 000000000..aab11dd03 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/buttonevent.h @@ -0,0 +1,27 @@ +#ifndef BUTTONEVENT_H +#define BUTTONEVENT_H + +#include +#include "mainthreadinterface.h" + +class AWTLabelEvent : public AWTEvent { + + private: + QAbstractButton *widget; + QString *string; + + public: + AWTLabelEvent(QAbstractButton *w, QString *s) : AWTEvent() + { + widget = w; + string = s; + } + + void runEvent() + { + widget->setText( *string ); + delete string; + } +}; + +#endif diff --git a/libjava/classpath/native/jni/qt-peer/componentevent.cpp b/libjava/classpath/native/jni/qt-peer/componentevent.cpp new file mode 100644 index 000000000..ae88af019 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/componentevent.cpp @@ -0,0 +1,223 @@ +/* componentevent.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include + +#include "componentevent.h" + +AWTInitEvent::AWTInitEvent(JNIEnv *env, jobject obj) : AWTEvent() +{ + env->GetJavaVM( &vm ); + target = env->NewGlobalRef( obj ); +} + +void AWTInitEvent::runEvent() +{ + JNIEnv *env; + vm->GetEnv((void **)&env, JNI_VERSION_1_1); + jclass targetCls = env->GetObjectClass( target ); + // call init() + jmethodID mID = env->GetMethodID( targetCls, + "init", + "()V" ); + env->CallVoidMethod( target, mID ); + + // call notify() + mID = env->GetMethodID( targetCls, + "notify", + "()V" ); + assert(mID != NULL); + env->MonitorEnter( target ); + env->CallVoidMethod( target, mID ); + env->MonitorExit( target ); + + env->DeleteGlobalRef( target ); +} + +AWTShowEvent::AWTShowEvent(QWidget *w, bool v) : AWTEvent() +{ + widget = w; + visible = v; +} + +void AWTShowEvent::runEvent() +{ + widget->setVisible( visible ); +} + +AWTEnableEvent::AWTEnableEvent(QWidget *w, bool v) : AWTEvent() +{ + widget = w; + enabled = v; +} + +void AWTEnableEvent::runEvent() +{ + widget->setEnabled( enabled ); +} + +AWTCursorEvent::AWTCursorEvent(QWidget *w, Qt::CursorShape s) : AWTEvent() +{ + widget = w; + shape = s; +} + +void AWTCursorEvent::runEvent() +{ + QCursor *s = new QCursor(shape); + widget->setCursor( *s ); +} + +AWTResizeEvent::AWTResizeEvent(QWidget *wid, int x0, int y0, int w0, int h0) +{ + widget = wid; + x = x0; y = y0; + w = w0; h = h0; + if(w == 0 && h == 0) w = h = 10; +} + +void AWTResizeEvent::runEvent() +{ + QRect g = widget->geometry(); + if(g.x() != x || g.y() != y || g.width() != w || g.height() != h) + widget->setGeometry( x, y, w, h ); +} + +AWTBackgroundEvent::AWTBackgroundEvent(QWidget *wid, bool fg, QColor *clr) +{ + widget = wid; + foreground = fg; + color = clr; +} + +void AWTBackgroundEvent::runEvent() +{ + QPalette p = widget->palette(); + if (foreground) + { + p.setColor(QPalette::Active, QPalette::Foreground, *color); + p.setColor(QPalette::Active, QPalette::Text, *color); + } + else + { + p.setColor(QPalette::Active, QPalette::Background, *color); + p.setColor(QPalette::Active, QPalette::Button, *color); + p.setColor(QPalette::Active, QPalette::Base, *color); + p.setColor(QPalette::Active, QPalette::AlternateBase, *color); + } + widget->setPalette(p); + widget->repaint(); + delete color; +} + +AWTGetOriginEvent::AWTGetOriginEvent(QWidget *w, JNIEnv *env, jobject obj) : AWTEvent() +{ + widget = w; + env->GetJavaVM( &vm ); + target = env->NewGlobalRef( obj ); +} + +void AWTGetOriginEvent::runEvent() +{ + JNIEnv *env; + vm->GetEnv((void **)&env, JNI_VERSION_1_1); + jclass targetCls = env->GetObjectClass( target ); + + QPoint *p = new QPoint( widget->mapToGlobal( QPoint(0, 0) ) ); + // call init() + jmethodID mID = env->GetMethodID( targetCls, + "setLocation", + "(II)V" ); + env->CallVoidMethod( target, mID, p->x(), p->y() ); + delete p; + + // call notify() + mID = env->GetMethodID( targetCls, + "notify", + "()V" ); + assert(mID != NULL); + env->MonitorEnter( target ); + env->CallVoidMethod( target, mID ); + env->MonitorExit( target ); + + env->DeleteGlobalRef( target ); +} + +GetSizeEvent::GetSizeEvent(QWidget *w, JNIEnv *env, jobject obj, bool p) : AWTEvent() +{ + widget = w; + env->GetJavaVM( &vm ); + target = env->NewGlobalRef( obj ); + pref = p; +} + +void GetSizeEvent::runEvent() +{ + JNIEnv *env; + vm->GetEnv((void **)&env, JNI_VERSION_1_1); + jclass targetCls = env->GetObjectClass( target ); + + QPoint *p = new QPoint( widget->mapToGlobal( QPoint(0, 0) ) ); + QSize s; + if( pref ) + s = widget->sizeHint(); + else + s = widget->minimumSizeHint(); + + // call init() + jmethodID mID = env->GetMethodID( targetCls, + "setSize", + "(II)V" ); + env->CallVoidMethod( target, mID, s.width(), s.height() ); + + // call notify() + mID = env->GetMethodID( targetCls, + "notify", + "()V" ); + assert(mID != NULL); + env->MonitorEnter( target ); + env->CallVoidMethod( target, mID ); + env->MonitorExit( target ); + + env->DeleteGlobalRef( target ); +} + + + + diff --git a/libjava/classpath/native/jni/qt-peer/componentevent.h b/libjava/classpath/native/jni/qt-peer/componentevent.h new file mode 100644 index 000000000..7cf2f2eac --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/componentevent.h @@ -0,0 +1,203 @@ +#ifndef CALLBACKEVENT_H +#define CALLBACKEVENT_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mainthreadinterface.h" + +class AWTInitEvent : public AWTEvent { + + private: + JavaVM* vm; + jobject target; + + public: + AWTInitEvent(JNIEnv *env, jobject obj); + void runEvent(); +}; + +class AWTDestroyEvent : public AWTEvent { + + private: + QWidget *widget; + + public: + AWTDestroyEvent(QWidget *w) + { + widget = w; + } + + void runEvent() + { + if( widget != NULL ) + delete widget; + } +}; + +class AWTFontEvent : public AWTEvent { + + private: + QWidget *widget; + QFont *font; + + public: + AWTFontEvent(QWidget *w, QFont *f) + { + widget = w; + font = f; + } + + void runEvent() + { + widget->setFont( *font ); + } +}; + +class AWTUpdateEvent : public AWTEvent { + + private: + QWidget *widget; + int x,y,w,h; + bool updateAll; + + public: + AWTUpdateEvent(QWidget *src, bool all, int x0, int y0, int w0, int h0) + { + widget = src; + updateAll = all; + x = x0; y = y0; w = w0; h = h0; + } + + void runEvent() + { + if(updateAll) + widget->update(); + else + widget->update(x,y,w,h); + } +}; + +class AWTShowEvent : public AWTEvent { + + private: + QWidget *widget; + bool visible; + + public: + AWTShowEvent(QWidget *w, bool v); + void runEvent(); +}; + +class AWTEnableEvent : public AWTEvent { + + private: + QWidget *widget; + bool enabled; + + public: + AWTEnableEvent(QWidget *w, bool v); + void runEvent(); +}; + +class AWTCursorEvent : public AWTEvent { + + private: + QWidget *widget; + Qt::CursorShape shape; + + public: + AWTCursorEvent(QWidget *w, Qt::CursorShape s); + void runEvent(); +}; + +class AWTResizeEvent : public AWTEvent { + + private: + QWidget *widget; + int x, y, w, h; + + public: + AWTResizeEvent(QWidget *wid, int x0, int y0, int w0, int h0); + void runEvent(); +}; + +class AWTBackgroundEvent : public AWTEvent { + + private: + QWidget *widget; + bool foreground; + QColor *color; + + public: + AWTBackgroundEvent(QWidget *wid, bool fg, QColor *clr); + void runEvent(); +}; + +class AWTReqFocusEvent : public AWTEvent { + + private: + QWidget *widget; + + public: + AWTReqFocusEvent(QWidget *w) : AWTEvent() + { + widget = w; + } + void runEvent() + { + widget->setFocus(); + } +}; + +class AWTGetOriginEvent : public AWTEvent { + + private: + JavaVM* vm; + jobject target; + QWidget *widget; + + public: + AWTGetOriginEvent(QWidget *w, JNIEnv *env, jobject obj); + void runEvent(); +}; + +class GetSizeEvent : public AWTEvent { + + private: + JavaVM* vm; + jobject target; + QWidget *widget; + bool pref; + + public: + GetSizeEvent(QWidget *w, JNIEnv *env, jobject obj, bool p); + void runEvent(); +}; + +class AWTReparent : public AWTEvent { + + private: + QWidget *widget; + QWidget *parent; + + public: + AWTReparent(QWidget *w, QWidget *p) : AWTEvent() + { + widget = w; + parent = p; + } + void runEvent() + { + widget->setParent( parent ); + } +}; + +#endif diff --git a/libjava/classpath/native/jni/qt-peer/containers.h b/libjava/classpath/native/jni/qt-peer/containers.h new file mode 100644 index 000000000..a2ae76af0 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/containers.h @@ -0,0 +1,10 @@ +#ifndef QTFRAME_H +#define QTFRAME_H + +#include +#include + +QWidget *frameChildWidget( JNIEnv *env, jobject component ); +QWidget *scrollPaneChildWidget( JNIEnv *env, jobject component); + +#endif diff --git a/libjava/classpath/native/jni/qt-peer/eventmethods.h b/libjava/classpath/native/jni/qt-peer/eventmethods.h new file mode 100644 index 000000000..ae56da8e7 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/eventmethods.h @@ -0,0 +1,245 @@ +/* eventmethods.cpp -- + Copyright (C) 2005, 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#ifdef I_KNOW_WHAT_IM_DOING + +bool draw; + +private: + JavaVM* vm; + jobject target; + jclass componentCls; + + void setup(JNIEnv *env, jobject obj) + { + env->GetJavaVM(&vm); + componentCls = NULL; + target = env->NewGlobalRef(obj); + componentCls = (jclass)env->NewGlobalRef(env->GetObjectClass( target )); + setMouseTracking( true ); + draw = true; + } + + void destroy() + { + JNIEnv *env; + vm->GetEnv((void **)&env, JNI_VERSION_1_1); + env->DeleteGlobalRef(target); + env->DeleteGlobalRef(componentCls); + } + + void callVoidMethod(const char *methodName) + { + JNIEnv *env; + vm->GetEnv((void **)&env, JNI_VERSION_1_1); + jmethodID fireEventID = env->GetMethodID( componentCls, + methodName, + "()V" ); + env->CallVoidMethod( target, fireEventID ); + } + + void callMouseMethod(const char *methodName, + int modifiers, int x, int y, int clickCount) + { + JNIEnv *env; + vm->GetEnv((void **)&env, JNI_VERSION_1_1); + jmethodID fireEventID = env->GetMethodID( componentCls, + methodName, + "(IIII)V" ); + env->CallVoidMethod( target, fireEventID, modifiers, x, y, clickCount ); + } + +protected: + + void closeEvent( QCloseEvent *e ) + { + PARENT::closeEvent(e); + callVoidMethod("closeEvent"); + } + + void focusInEvent( QFocusEvent *e ) + { + PARENT::focusInEvent(e); + callVoidMethod("focusInEvent"); + } + + void focusOutEvent( QFocusEvent *e ) + { + PARENT::focusOutEvent(e); + callVoidMethod("focusOutEvent"); + } + + void enterEvent( QEvent *e ) + { + PARENT::enterEvent(e); + QPoint p = mapFromGlobal( QCursor::pos() ); + int modifiers = getKeyModifiers( QApplication::keyboardModifiers() ); + callMouseMethod("enterEvent", modifiers, p.x(), p.y(), 0); + } + + void keyPressEvent( QKeyEvent *e ) + { + PARENT::keyPressEvent(e); + int modifiers, x, y; + modifiers = getKeyModifiers(e->modifiers()); + x = mapKeyCode(e); + y = getUnicode(e); + callMouseMethod("keyPressEvent", modifiers, x, y, 0); + } + + void keyReleaseEvent( QKeyEvent *e ) + { + PARENT::keyReleaseEvent(e); + int modifiers, x, y; + modifiers = getKeyModifiers(e->modifiers()); + x = mapKeyCode(e); + y = getUnicode(e); + callMouseMethod("keyReleaseEvent", modifiers, x, y, 0); + } + + void leaveEvent( QEvent *e ) + { + PARENT::leaveEvent(e); + QPoint p = mapFromGlobal( QCursor::pos() ); + int modifiers = getKeyModifiers( QApplication::keyboardModifiers() ); + callMouseMethod("leaveEvent", modifiers, p.x(), p.y(), 0); + } + + void mouseDoubleClickEvent( QMouseEvent *e ) + { + PARENT::mouseDoubleClickEvent(e); + int modifiers, x, y, clickCount; + clickCount = 2; + modifiers = getMouseModifiers(e); + x = e->x(); + y = e->y(); + callMouseMethod("mouseDoubleClickEvent", modifiers, x, y, clickCount); + } + + void mouseMoveEvent( QMouseEvent *e ) + { + PARENT::mouseMoveEvent(e); + int modifiers, x, y, clickCount; + clickCount = 0; + modifiers = getMouseModifiers(e); + x = e->x(); + y = e->y(); + callMouseMethod("mouseMoveEvent", modifiers, x, y, clickCount); + } + + void mousePressEvent( QMouseEvent *e ) + { + PARENT::mousePressEvent(e); + int modifiers, x, y, clickCount; + clickCount = 0; + modifiers = getMouseModifiers(e); + x = e->x(); + y = e->y(); + callMouseMethod("mousePressEvent", modifiers, x, y, clickCount); + } + + void mouseReleaseEvent( QMouseEvent *e ) + { + PARENT::mouseReleaseEvent(e); + int modifiers, x, y, clickCount; + modifiers = 0; + + modifiers |= getReleaseModifiers( e ); + x = e->x(); + y = e->y(); + callMouseMethod("mouseReleaseEvent", modifiers, x, y, 0); + } + + void moveEvent( QMoveEvent *e ) + { + PARENT::moveEvent(e); + callMouseMethod("moveEvent", e->pos().x(), e->pos().y(), + e->oldPos().x(), e->oldPos().y()); + } + + void resizeEvent( QResizeEvent *e ) + { + PARENT::resizeEvent(e); + callMouseMethod("resizeEvent", + e->oldSize().width(), e->oldSize().height(), + e->size().width(), e->size().height()); + } + + void hideEvent( QHideEvent *e ) + { + PARENT::hideEvent(e); + callVoidMethod("hideEvent"); + } + + void showEvent( QShowEvent *e ) + { + PARENT::showEvent(e); + callVoidMethod("showEvent"); + } + + void paintEvent ( QPaintEvent * e ) + { + PARENT::paintEvent( e ); + if ( draw ) + { + // Create a QPainter + GraphicsPainter painter( this ); + int x, y, w, h; + e->rect().getRect ( &x, &y, &w, &h ); + + // Get the environment. + JNIEnv *env; + vm->GetEnv((void **)&env, JNI_VERSION_1_1); + + // create a QtGraphics wrapper for the QPainter + jclass cls = env->FindClass( "gnu/java/awt/peer/qt/QtComponentGraphics" ); + jmethodID mid = env->GetMethodID(cls, "", "(JLgnu/java/awt/peer/qt/QtComponentPeer;IIII)V"); + jobject graphics = env->NewObject(cls, mid, (jlong)&painter, target, + (jint)x, (jint)y, (jint)w, (jint)h); + + // call QtComponentPeer.paintEvent() + jmethodID paintEventID = env->GetMethodID( componentCls, + "paint", + "(Ljava/awt/Graphics;)V" ); + env->CallVoidMethod( target, paintEventID, graphics ); + env->DeleteLocalRef( cls ); + env->DeleteLocalRef( graphics ); + painter.end(); + } + } + +#endif diff --git a/libjava/classpath/native/jni/qt-peer/keybindings.cpp b/libjava/classpath/native/jni/qt-peer/keybindings.cpp new file mode 100644 index 000000000..f18616689 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/keybindings.cpp @@ -0,0 +1,600 @@ +/* keybindings.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include "keybindings.h" + +/* InputEvent key modifiers */ +#define SHIFT_MASK 1 +#define CTRL_MASK 2 +#define META_MASK 4 +#define ALT_MASK 8 +#define ALT_GRAPH_MASK 0x20 +#define BUTTON1_MASK 0x10 +#define BUTTON2_MASK 8 +#define BUTTON3_MASK 4 + +#define SHIFT_DOWN_MASK 0x0040 +#define CTRL_DOWN_MASK 0x0080 +#define META_DOWN_MASK 0x0100 +#define ALT_DOWN_MASK 0x0200 +#define BUTTON1_DOWN_MASK 0x0400 +#define BUTTON2_DOWN_MASK 0x0800 +#define BUTTON3_DOWN_MASK 0x1000 +#define ALT_GRAPH_DOWN_MASK 0x2000 + +/* Virtual Keys */ +/* This list should be kept in the same order as the VK_ field + declarations in KeyEvent.java. */ +#define VK_ENTER '\n' +#define VK_BACK_SPACE '\b' +#define VK_TAB '\t' +#define VK_CANCEL 3 +#define VK_CLEAR 12 +#define VK_SHIFT 16 +#define VK_CONTROL 17 +#define VK_ALT 18 +#define VK_PAUSE 19 +#define VK_CAPS_LOCK 20 +#define VK_ESCAPE 27 +#define VK_SPACE ' ' +#define VK_PAGE_UP 33 +#define VK_PAGE_DOWN 34 +#define VK_END 35 +#define VK_HOME 36 +#define VK_LEFT 37 +#define VK_UP 38 +#define VK_RIGHT 39 +#define VK_DOWN 40 +#define VK_COMMA ',' +#define VK_MINUS '-' +#define VK_PERIOD '.' +#define VK_SLASH '/' +#define VK_0 '0' +#define VK_1 '1' +#define VK_2 '2' +#define VK_3 '3' +#define VK_4 '4' +#define VK_5 '5' +#define VK_6 '6' +#define VK_7 '7' +#define VK_8 '8' +#define VK_9 '9' +#define VK_SEMICOLON ';' +#define VK_EQUALS '=' +#define VK_A 'A' +#define VK_B 'B' +#define VK_C 'C' +#define VK_D 'D' +#define VK_E 'E' +#define VK_F 'F' +#define VK_G 'G' +#define VK_H 'H' +#define VK_I 'I' +#define VK_J 'J' +#define VK_K 'K' +#define VK_L 'L' +#define VK_M 'M' +#define VK_N 'N' +#define VK_O 'O' +#define VK_P 'P' +#define VK_Q 'Q' +#define VK_R 'R' +#define VK_S 'S' +#define VK_T 'T' +#define VK_U 'U' +#define VK_V 'V' +#define VK_W 'W' +#define VK_X 'X' +#define VK_Y 'Y' +#define VK_Z 'Z' +#define VK_OPEN_BRACKET '[' +#define VK_BACK_SLASH '\\' +#define VK_CLOSE_BRACKET ']' +#define VK_NUMPAD0 96 +#define VK_NUMPAD1 97 +#define VK_NUMPAD2 98 +#define VK_NUMPAD3 99 +#define VK_NUMPAD4 100 +#define VK_NUMPAD5 101 +#define VK_NUMPAD6 102 +#define VK_NUMPAD7 103 +#define VK_NUMPAD8 104 +#define VK_NUMPAD9 105 +#define VK_MULTIPLY 106 +#define VK_ADD 107 +#define VK_SEPARATER 108 +#define VK_SEPARATOR 108 +#define VK_SUBTRACT 109 +#define VK_DECIMAL 110 +#define VK_DIVIDE 111 +#define VK_DELETE 127 +#define VK_NUM_LOCK 144 +#define VK_SCROLL_LOCK 145 +#define VK_F1 112 +#define VK_F2 113 +#define VK_F3 114 +#define VK_F4 115 +#define VK_F5 116 +#define VK_F6 117 +#define VK_F7 118 +#define VK_F8 119 +#define VK_F9 120 +#define VK_F10 121 +#define VK_F11 122 +#define VK_F12 123 +#define VK_F13 61440 +#define VK_F14 61441 +#define VK_F15 61442 +#define VK_F16 61443 +#define VK_F17 61444 +#define VK_F18 61445 +#define VK_F19 61446 +#define VK_F20 61447 +#define VK_F21 61448 +#define VK_F22 61449 +#define VK_F23 61450 +#define VK_F24 61451 +#define VK_PRINTSCREEN 154 +#define VK_INSERT 155 +#define VK_HELP 156 +#define VK_META 157 +#define VK_BACK_QUOTE 192 +#define VK_QUOTE 222 +#define VK_KP_UP 224 +#define VK_KP_DOWN 225 +#define VK_KP_LEFT 226 +#define VK_KP_RIGHT 227 +#define VK_DEAD_GRAVE 128 +#define VK_DEAD_ACUTE 129 +#define VK_DEAD_CIRCUMFLEX 130 +#define VK_DEAD_TILDE 131 +#define VK_DEAD_MACRON 132 +#define VK_DEAD_BREVE 133 +#define VK_DEAD_ABOVEDOT 134 +#define VK_DEAD_DIAERESIS 135 +#define VK_DEAD_ABOVERING 136 +#define VK_DEAD_DOUBLEACUTE 137 +#define VK_DEAD_CARON 138 +#define VK_DEAD_CEDILLA 139 +#define VK_DEAD_OGONEK 140 +#define VK_DEAD_IOTA 141 +#define VK_DEAD_VOICED_SOUND 142 +#define VK_DEAD_SEMIVOICED_SOUND 143 +#define VK_AMPERSAND 150 +#define VK_ASTERISK 151 +#define VK_QUOTEDBL 152 +#define VK_LESS 153 +#define VK_GREATER 160 +#define VK_BRACELEFT 161 +#define VK_BRACERIGHT 162 +#define VK_AT 512 +#define VK_COLON 513 +#define VK_CIRCUMFLEX 514 +#define VK_DOLLAR 515 +#define VK_EURO_SIGN 516 +#define VK_EXCLAMATION_MARK 517 +#define VK_INVERTED_EXCLAMATION_MARK 518 +#define VK_LEFT_PARENTHESIS 519 +#define VK_NUMBER_SIGN 520 +#define VK_PLUS 521 +#define VK_RIGHT_PARENTHESIS 522 +#define VK_UNDERSCORE 523 +#define VK_FINAL 24 +#define VK_CONVERT 28 +#define VK_NONCONVERT 29 +#define VK_ACCEPT 30 +#define VK_MODECHANGE 31 +#define VK_KANA 21 +#define VK_KANJI 25 +#define VK_ALPHANUMERIC 240 +#define VK_KATAKANA 241 +#define VK_HIRAGANA 242 +#define VK_FULL_WIDTH 243 +#define VK_HALF_WIDTH 244 +#define VK_ROMAN_CHARACTERS 245 +#define VK_ALL_CANDIDATES 256 +#define VK_PREVIOUS_CANDIDATE 257 +#define VK_CODE_INPUT 258 +#define VK_JAPANESE_KATAKANA 259 +#define VK_JAPANESE_HIRAGANA 260 +#define VK_JAPANESE_ROMAN 261 +#define VK_KANA_LOCK 262 +#define VK_INPUT_METHOD_ON_OFF 263 +#define VK_CUT 65489 +#define VK_COPY 65485 +#define VK_PASTE 65487 +#define VK_UNDO 65483 +#define VK_AGAIN 65481 +#define VK_FIND 65488 +#define VK_PROPS 65482 +#define VK_STOP 65480 +#define VK_COMPOSE 65312 +#define VK_ALT_GRAPH 65406 +#define VK_UNDEFINED 0 + + +int mapKeyCode(QKeyEvent *key) +{ + switch(key->key()) + { + case Qt::Key_Escape: + return VK_ESCAPE; + case Qt::Key_Tab: + return VK_TAB; + case Qt::Key_Backspace: + return VK_BACK_SPACE; + case Qt::Key_Return: + case Qt::Key_Enter: + return VK_ENTER; + case Qt::Key_Insert: + return VK_INSERT; + case Qt::Key_Delete: + return VK_DELETE; + case Qt::Key_Pause: + return VK_PAUSE; + case Qt::Key_Print: + case Qt::Key_SysReq: + return VK_PRINTSCREEN; + case Qt::Key_Home: + return VK_HOME; + case Qt::Key_End: + return VK_END; + case Qt::Key_Left: + return VK_LEFT; + case Qt::Key_Up: + return VK_UP; + case Qt::Key_Right: + return VK_RIGHT; + case Qt::Key_Down: + return VK_DOWN; + case Qt::Key_PageUp: + return VK_PAGE_UP; + case Qt::Key_PageDown: + return VK_PAGE_DOWN; + case Qt::Key_Shift: + return VK_SHIFT; + case Qt::Key_Control: + return VK_CONTROL; + case Qt::Key_Meta: + return VK_META; + case Qt::Key_Alt: + return VK_ALT; + case Qt::Key_CapsLock: + return VK_CAPS_LOCK; + case Qt::Key_NumLock: + return VK_NUM_LOCK; + case Qt::Key_ScrollLock: + return VK_SCROLL_LOCK; + case Qt::Key_Clear: + return VK_CLEAR; + case Qt::Key_F1: + return VK_F1; + case Qt::Key_F2: + return VK_F2; + case Qt::Key_F3: + return VK_F3; + case Qt::Key_F4: + return VK_F4; + case Qt::Key_F5: + return VK_F5; + case Qt::Key_F6: + return VK_F6; + case Qt::Key_F7: + return VK_F7; + case Qt::Key_F8: + return VK_F8; + case Qt::Key_F9: + return VK_F9; + case Qt::Key_F10: + return VK_F10; + case Qt::Key_F11: + return VK_F11; + case Qt::Key_F12: + return VK_F12; + case Qt::Key_F13: + return VK_F13; + case Qt::Key_F14: + return VK_F14; + case Qt::Key_F15: + return VK_F15; + case Qt::Key_F16: + return VK_F16; + case Qt::Key_F17: + return VK_F17; + case Qt::Key_F18: + return VK_F18; + case Qt::Key_F19: + return VK_F19; + case Qt::Key_F20: + return VK_F20; + case Qt::Key_F21: + return VK_F21; + case Qt::Key_F22: + return VK_F22; + case Qt::Key_F23: + return VK_F23; + case Qt::Key_F24: + return VK_F24; + case Qt::Key_Help: + return VK_HELP; + + case Qt::Key_Space: + return VK_SPACE; + + case Qt::Key_Exclam: + return VK_EXCLAMATION_MARK; + case Qt::Key_QuoteDbl: + return VK_QUOTEDBL; + case Qt::Key_NumberSign: + return VK_NUMBER_SIGN; + + case Qt::Key_Dollar: + return VK_DOLLAR; + + + case Qt::Key_Ampersand: + return VK_AMPERSAND; + + case Qt::Key_ParenLeft: + return VK_LEFT_PARENTHESIS; + case Qt::Key_ParenRight: + return VK_RIGHT_PARENTHESIS; + case Qt::Key_Asterisk: + return VK_ASTERISK; + case Qt::Key_Plus: + return VK_PLUS; + case Qt::Key_Comma: + return VK_COMMA; + case Qt::Key_Minus: + return VK_MINUS; + case Qt::Key_Period: + return VK_PERIOD; + case Qt::Key_Slash: + return VK_SLASH; + + case Qt::Key_0: + return VK_0; + case Qt::Key_1: + return VK_1; + case Qt::Key_2: + return VK_2; + case Qt::Key_3: + return VK_3; + case Qt::Key_4: + return VK_4; + case Qt::Key_5: + return VK_5 ; + case Qt::Key_6: + return VK_6; + case Qt::Key_7: + return VK_7; + case Qt::Key_8: + return VK_8; + case Qt::Key_9: + return VK_9; + + case Qt::Key_Colon: + return VK_COLON; + case Qt::Key_Semicolon: + return VK_SEMICOLON; + case Qt::Key_Less: + return VK_LESS; + case Qt::Key_Equal: + return VK_EQUALS; + case Qt::Key_Greater: + return VK_GREATER; + case Qt::Key_Question: + case Qt::Key_At: + + case Qt::Key_A: + return VK_A; + case Qt::Key_B: + return VK_B; + case Qt::Key_C: + return VK_C; + case Qt::Key_D: + return VK_D; + case Qt::Key_E: + return VK_E; + case Qt::Key_F: + return VK_F; + case Qt::Key_G: + return VK_G; + case Qt::Key_H: + return VK_H; + case Qt::Key_I: + return VK_I; + case Qt::Key_J: + return VK_J; + case Qt::Key_K: + return VK_K; + case Qt::Key_L: + return VK_L; + case Qt::Key_M: + return VK_M; + case Qt::Key_N: + return VK_N; + case Qt::Key_O: + return VK_O; + case Qt::Key_P: + return VK_P; + case Qt::Key_Q: + return VK_Q; + case Qt::Key_R: + return VK_R; + case Qt::Key_S: + return VK_S; + case Qt::Key_T: + return VK_T; + case Qt::Key_U: + return VK_U; + case Qt::Key_V: + return VK_V; + case Qt::Key_W: + return VK_W; + case Qt::Key_X: + return VK_X; + case Qt::Key_Y: + return VK_Y; + case Qt::Key_Z: + return VK_Z; + case Qt::Key_division: + return VK_DIVIDE; + case Qt::Key_BracketLeft: + return VK_OPEN_BRACKET; + case Qt::Key_Backslash: + return VK_BACK_SLASH; + case Qt::Key_BracketRight: + return VK_CLOSE_BRACKET; + case Qt::Key_BraceLeft: + return VK_BRACELEFT; + case Qt::Key_BraceRight: + return VK_BRACERIGHT; + case Qt::Key_brokenbar: + return VK_SEPARATOR; // correct? + + default: + return VK_UNDEFINED; + } +} + +int getUnicode(QKeyEvent *key) +{ + QString s = key->text(); + if(s.isEmpty()) + return 0; // CHAR_UNDEFINED + QChar c = s.at(0); + return (int)c.unicode(); +} + +/** + * Returns the key modifiers in KeyEvent format + */ +int getKeyModifiers(Qt::KeyboardModifiers state) +{ + int modifier = 0; + if( state & Qt::ShiftModifier ) + modifier |= SHIFT_DOWN_MASK; + if( state & Qt::ControlModifier ) + modifier |= CTRL_DOWN_MASK; + if( state & Qt::AltModifier ) + modifier |= ALT_DOWN_MASK; + if( state & Qt::MetaModifier ) + modifier |= META_DOWN_MASK; + + return modifier; +} + +/** + * Returns the key modifiers in ActionEvent format + */ +int getAEKeyModifiers(Qt::KeyboardModifiers state) +{ + int modifier = 0; + if( state & Qt::ShiftModifier ) + modifier |= SHIFT_MASK; + if( state & Qt::ControlModifier ) + modifier |= CTRL_MASK; + if( state & Qt::AltModifier ) + modifier |= ALT_MASK; + if( state & Qt::MetaModifier ) + modifier |= META_MASK; + + return modifier; +} + +/** + * Returns the mouse modifiers in InputEvent format + */ +int getMouseModifiers(QMouseEvent *e) +{ + int modifier = 0; + int buttons = e->buttons(); + int state = e->modifiers(); + + if( buttons & Qt::LeftButton ) + modifier |= BUTTON1_DOWN_MASK; + if( buttons & Qt::MidButton ) + modifier |= BUTTON2_DOWN_MASK; + if( buttons & Qt::RightButton ) + modifier |= BUTTON3_DOWN_MASK; + + if( state & Qt::ShiftModifier ) + modifier |= SHIFT_DOWN_MASK; + if( state & Qt::ControlModifier ) + modifier |= CTRL_DOWN_MASK; + if( state & Qt::AltModifier ) + modifier |= ALT_DOWN_MASK; + if( state & Qt::MetaModifier ) + modifier |= META_DOWN_MASK; + + // FIXME: Alt Gr? + return modifier; +} + +/** + * Returns the mouse modifiers in InputEvent format + * We need a different method here because e->buttons() doesn't work for, + * mouseReleased events. (But strangely enough it does for pressed ones) + */ +int getReleaseModifiers(QMouseEvent *e) +{ + int modifier = 0; + int button = e->button(); + int state = e->modifiers(); + + if( button & Qt::LeftButton ) + modifier |= BUTTON1_DOWN_MASK; + if( button & Qt::MidButton ) + modifier |= BUTTON2_DOWN_MASK; + if( button & Qt::RightButton ) + modifier |= BUTTON3_DOWN_MASK; + + if( state & Qt::ShiftModifier ) + modifier |= SHIFT_DOWN_MASK; + if( state & Qt::ControlModifier ) + modifier |= CTRL_DOWN_MASK; + if( state & Qt::AltModifier ) + modifier |= ALT_DOWN_MASK; + if( state & Qt::MetaModifier ) + modifier |= META_DOWN_MASK; + + // FIXME: Alt Gr? + return modifier; +} + + diff --git a/libjava/classpath/native/jni/qt-peer/keybindings.h b/libjava/classpath/native/jni/qt-peer/keybindings.h new file mode 100644 index 000000000..cdf761f61 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/keybindings.h @@ -0,0 +1,20 @@ +#ifndef KEYBINDINGS_H +#define KEYBINDINGS_H + +#include +#include +#include +#include +#include +#include +#include +#include "qtgraphics.h" + +int mapKeyCode(QKeyEvent *key); +int getUnicode(QKeyEvent *key); +int getKeyModifiers(Qt::KeyboardModifiers state); +int getAEKeyModifiers(Qt::KeyboardModifiers state); +int getMouseModifiers(QMouseEvent *event); +int getReleaseModifiers(QMouseEvent *e); + +#endif diff --git a/libjava/classpath/native/jni/qt-peer/mainqtthread.cpp b/libjava/classpath/native/jni/qt-peer/mainqtthread.cpp new file mode 100644 index 000000000..19566c63b --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/mainqtthread.cpp @@ -0,0 +1,104 @@ +/* mainqtthread.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include +#include +#include "mainthreadinterface.h" + +MainThreadInterface *mainThread; +QApplication *qApplication; + + +/** + * Starts up a QApplication + */ +JNIEXPORT jlong JNICALL Java_gnu_java_awt_peer_qt_MainQtThread_init +(JNIEnv *env, jobject obj, jstring theme, jboolean doublebuffer) +{ + int *argc; + char **argv; + + if(theme != NULL) + { + argc = (int*)malloc(sizeof(int)); + *argc = 3; + argv = (char **)malloc( 3 * sizeof(char *) ); + argv[0] = (char *)malloc(10 * sizeof(char)); + argv[1] = (char *)malloc(10 * sizeof(char)); + argv[2] = (char *)malloc(100 * sizeof(char)); + strncpy(argv[0], "\0", 2); + strncpy(argv[1], "-style\0", 8); + strncpy(argv[2], (char *)env->GetStringUTFChars( theme, NULL ), 100); + } + else + { + argc = (int*)malloc(sizeof(int)); + *argc = 1; + argv = (char **)malloc( 3 * sizeof(char *) ); + argv[0] = (char *)malloc(10 * sizeof(char)); + strncpy(argv[0], " \0", 3); + } + QApplication *qtApp = new QApplication( *argc, argv ); + assert( qtApp ); + + qApplication = qtApp; + + if( theme != NULL) + env->ReleaseStringUTFChars( theme, argv[1] ); + + mainThread = new MainThreadInterface( qtApp ); + + jclass cls = env->GetObjectClass(obj); + jfieldID nofid = env->GetFieldID( cls, "mainThreadInterface", "J" ); + env->SetLongField( obj, nofid, (jlong)mainThread ); + + return (jlong)qtApp; +} + +/* + * Calls QApplication::exec() + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_MainQtThread_exec +(JNIEnv *env, jobject obj, jlong ptr) +{ + QApplication *app = (QApplication *)ptr; + if(app) + app->exec(); +} diff --git a/libjava/classpath/native/jni/qt-peer/mainthreadinterface.cpp b/libjava/classpath/native/jni/qt-peer/mainthreadinterface.cpp new file mode 100644 index 000000000..3c197ad19 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/mainthreadinterface.cpp @@ -0,0 +1,69 @@ +/* mainthreadinterface.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include "mainthreadinterface.h" + +MainThreadInterface::MainThreadInterface(QApplication *parent) : QObject( parent ) +{ + mainApp = parent; +} + +/** + * This is called from the main Qt event loop, and delegates the work to + * the AWTEvent runEvent method. + */ +bool MainThreadInterface::event ( QEvent * e ) +{ + QObject::event( e ); + if( e->type() == QEvent::User) + { + AWTEvent *fe = (AWTEvent *)e; + fe->runEvent(); + } + return true; +} + +/** + * Posts the event to the main Qt event loop for execution. + */ +void MainThreadInterface::postEventToMain(AWTEvent *event) +{ + mainApp->postEvent(this, event); +} + diff --git a/libjava/classpath/native/jni/qt-peer/mainthreadinterface.h b/libjava/classpath/native/jni/qt-peer/mainthreadinterface.h new file mode 100644 index 000000000..e17b78652 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/mainthreadinterface.h @@ -0,0 +1,36 @@ +#ifndef MAINTHREADINTERFACE_H +#define MAINTHREADINTERFACE_H + +#include +#include +#include +#include +#include + +class AWTEvent : public QEvent { + + public: + AWTEvent() : QEvent( QEvent::User ) + { + } + + virtual void runEvent() + { + } + +}; + +class MainThreadInterface : public QObject { + + private: + QApplication *mainApp; + + public: + MainThreadInterface(QApplication *parent); + bool event ( QEvent * e ); + void postEventToMain(AWTEvent *event); +}; + +extern MainThreadInterface *mainThread; + +#endif diff --git a/libjava/classpath/native/jni/qt-peer/nativewrapper.cpp b/libjava/classpath/native/jni/qt-peer/nativewrapper.cpp new file mode 100644 index 000000000..0dec02c96 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/nativewrapper.cpp @@ -0,0 +1,64 @@ +/* nativewrapper.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include "nativewrapper.h" + +#define WRAPPER_CLASS "gnu/java/awt/peer/qt/NativeWrapper" + +/* + * Sets the native object field. + */ +void setNativeObject( JNIEnv *env, jobject qtcomponent, void *ptr ) +{ + jclass cls = env->GetObjectClass( qtcomponent ); + jlong value = (jlong) ptr; + jfieldID nofid = env->GetFieldID( cls, "nativeObject", "J" ); + env->SetLongField( qtcomponent, nofid, value ); + env->DeleteLocalRef( cls ); +} + +/** + * Gets the native object field. + */ +void *getNativeObject( JNIEnv *env, jobject qtcomponent ) +{ + jclass cls = env->GetObjectClass( qtcomponent ); + jfieldID nofid = env->GetFieldID( cls, "nativeObject", "J" ); + jlong value = env->GetLongField( qtcomponent, nofid ); + env->DeleteLocalRef( cls ); + return (void *) value; +} diff --git a/libjava/classpath/native/jni/qt-peer/nativewrapper.h b/libjava/classpath/native/jni/qt-peer/nativewrapper.h new file mode 100644 index 000000000..1207aa1d3 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/nativewrapper.h @@ -0,0 +1,10 @@ +#ifndef NATIVEWRAPPER_H +#define NATIVEWRAPPER_H + +#include + +void *getNativeObject( JNIEnv *env, jobject qtcomponent ); + +void setNativeObject( JNIEnv *env, jobject qtcomponent, void *ptr ); + +#endif diff --git a/libjava/classpath/native/jni/qt-peer/qmatrix.cpp b/libjava/classpath/native/jni/qt-peer/qmatrix.cpp new file mode 100644 index 000000000..4b99ae7ab --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qmatrix.cpp @@ -0,0 +1,96 @@ +/* qmatrix.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include "nativewrapper.h" + +/* + * Creates a QMatrix + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QMatrix_init +(JNIEnv *env, jobject obj, jdouble m00, jdouble m10, jdouble m01, jdouble m11, + jdouble m02, jdouble m12 ) +{ + QMatrix *matrix = new QMatrix( (qreal) m00, (qreal) m10, + (qreal) m01, (qreal) m11, + (qreal) m02, (qreal) m12 ); + assert( matrix ); + setNativeObject(env, obj, matrix); +} + +/* + * Returns the matrix a java array of doubles, + * in m00, m10, m01, m11, m02, m12 (java notation) format. + * Note that qt has different notations for the array elements. + */ +JNIEXPORT jdoubleArray JNICALL Java_gnu_java_awt_peer_qt_QMatrix_getMatrix +(JNIEnv *env, jobject obj) +{ + QMatrix *matrix = (QMatrix *)getNativeObject(env, obj); + assert( matrix ); + + jdoubleArray result_array; + jdouble *dst; + + result_array = env->NewDoubleArray( 6 ); + dst = env->GetDoubleArrayElements(result_array, NULL); + + dst[0] = (jdouble)matrix->m11(); // qt m11 = java m00 + dst[1] = (jdouble)matrix->m12(); // qt m12 = java m10 + dst[2] = (jdouble)matrix->m21(); // qt m21 = java m01 + dst[3] = (jdouble)matrix->m22(); // qt m22 = java m11 + dst[4] = (jdouble)matrix->dx(); // qt dx = java m02 + dst[5] = (jdouble)matrix->dy(); // qt dy = java m12 + + env->ReleaseDoubleArrayElements (result_array, dst, 0); + return result_array; +} + +/* + * Dispose of the thing. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QMatrix_dispose +(JNIEnv *env, jobject obj) +{ + QMatrix *matrix = (QMatrix *)getNativeObject(env, obj); + if( matrix ) + delete matrix; + setNativeObject(env, obj, NULL); +} + diff --git a/libjava/classpath/native/jni/qt-peer/qpainterpath.cpp b/libjava/classpath/native/jni/qt-peer/qpainterpath.cpp new file mode 100644 index 000000000..cfe9eeae9 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qpainterpath.cpp @@ -0,0 +1,239 @@ +/* qpainterpath.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include "nativewrapper.h" + +// java.awt.geom.PathIterator constants. +#define WIND_EVEN_ODD 0 +#define WIND_NON_ZERO 1 + + +/* + * Creates an empty QPainterPath. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QPainterPath_init +(JNIEnv *env, jobject obj, jint windingRule) +{ + QPainterPath *path = new QPainterPath(); + assert( path ); + path->setFillRule( (windingRule == WIND_EVEN_ODD) ? + Qt::OddEvenFill : Qt::WindingFill ); + setNativeObject(env, obj, path); +} + +/* + * MoveTo + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QPainterPath_moveTo +(JNIEnv *env, jobject obj, jdouble x, jdouble y) +{ + QPainterPath *path = (QPainterPath *)getNativeObject(env, obj); + assert( path ); + path->moveTo( (qreal)x, (qreal)y ); +} + +/* + * Closes the subpath. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QPainterPath_close +(JNIEnv *env, jobject obj) +{ + QPainterPath *path = (QPainterPath *)getNativeObject(env, obj); + assert( path ); + path->closeSubpath(); +} + +/* + * LineTo + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QPainterPath_lineTo +(JNIEnv *env, jobject obj, jdouble x, jdouble y) +{ + QPainterPath *path = (QPainterPath *)getNativeObject(env, obj); + assert( path ); + path->lineTo( (qreal)x, (qreal)y ); +} + +/* + * QuadraticTo + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QPainterPath_quadTo +(JNIEnv *env, jobject obj, jdouble x, jdouble y, jdouble x2, jdouble y2) +{ + QPainterPath *path = (QPainterPath *)getNativeObject(env, obj); + assert( path ); + path->quadTo( (qreal)x, (qreal)y, (qreal)x2, (qreal)y2 ); +} + +/* + * CubicTo + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QPainterPath_cubicTo +(JNIEnv *env, jobject obj, jdouble x, jdouble y, jdouble x2, jdouble y2, + jdouble x3, jdouble y3) +{ + QPainterPath *path = (QPainterPath *)getNativeObject(env, obj); + assert( path ); + path->cubicTo( (qreal)x, (qreal)y, + (qreal)x2, (qreal)y2, + (qreal)x3, (qreal)y3 ); +} + +/* + * Delete the native object + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QPainterPath_dispose + (JNIEnv *env, jobject obj) +{ + QPainterPath *path = (QPainterPath *)getNativeObject(env, obj); + if ( path ) + delete path; +} + +/********* GeneralPath functions *****************************/ + +// FIXME : Cache method ids. + +static void gp_moveTo( JNIEnv *env, + jobject gp, + jclass cls, + double x1, + double y1 ) +{ + jmethodID method; + jvalue values[2]; + + values[0].f = (jfloat) x1; + values[1].f = (jfloat) y1; + + method = env->GetMethodID(cls, "moveTo", "(FF)V"); + env->CallVoidMethodA( gp, method, values ); +} + +static void gp_lineTo( JNIEnv *env, + jobject gp, + jclass cls, + double x1, + double y1 ) +{ + jmethodID method; + jvalue values[2]; + + values[0].f = (jfloat) x1; + values[1].f = (jfloat) y1; + + method = env->GetMethodID(cls, "lineTo", "(FF)V"); + env->CallVoidMethodA( gp, method, values ); +} + +static void gp_curveTo( JNIEnv *env, + jobject gp, + jclass cls, + double x1, + double y1, + double x2, + double y2, + double x3, + double y3 ) +{ + jmethodID method; + jvalue values[6]; + + values[0].f = (jfloat) x1; + values[1].f = (jfloat) y1; + values[2].f = (jfloat) x2; + values[3].f = (jfloat) y2; + values[4].f = (jfloat) x3; + values[5].f = (jfloat) y3; + + method = env->GetMethodID(cls, "curveTo", "(FFFFFF)V"); + env->CallVoidMethodA( gp, method, values ); +} + +/** + * Returns the QPainterPath obj as a java.awt.geom.GeneralPath. + */ +JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QPainterPath_getPath +(JNIEnv *env, jobject obj) +{ + jclass cls; + jmethodID method; + jobject gp; + QPainterPath::Element currElement; + int windingRule; + + QPainterPath *path = new QPainterPath(); + assert( path ); + + windingRule = (path->fillRule() == Qt::OddEvenFill) ? + WIND_EVEN_ODD : WIND_NON_ZERO; + + cls = env->FindClass("java/awt/geom/GeneralPath"); + method = env->GetMethodID(cls, "", "(I)V"); + gp = env->NewObject(cls, method, windingRule); + + for( int i = 0; i < path->elementCount(); i++) + { + currElement = path->elementAt( i ); + switch(currElement.type) + { + case QPainterPath::MoveToElement: + gp_moveTo(env, gp, cls, currElement.x, currElement.y); + break; + case QPainterPath::LineToElement: + gp_lineTo(env, gp, cls, currElement.x, currElement.y); + break; + case QPainterPath::CurveToElement: + if( i + 2 >= path->elementCount() ) + break; + if(path->elementAt(i + 1).type != QPainterPath::CurveToDataElement || + path->elementAt(i + 2).type != QPainterPath::CurveToDataElement) + break; + gp_curveTo(env, gp, cls, currElement.x, currElement.y, + path->elementAt(i + 1).x, path->elementAt(i + 1).y, + path->elementAt(i + 2).x, path->elementAt(i + 2).y ); + i += 2; + break; + } + } + env->DeleteLocalRef( cls ); + return gp; +} + diff --git a/libjava/classpath/native/jni/qt-peer/qpen.cpp b/libjava/classpath/native/jni/qt-peer/qpen.cpp new file mode 100644 index 000000000..353826f6b --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qpen.cpp @@ -0,0 +1,108 @@ +/* qpen.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include +#include "nativewrapper.h" + +/* + * java.awt.geom.BasicStroke constants. + */ +#define JOIN_MITER 0 +#define JOIN_ROUND 1 +#define JOIN_BEVEL 2 +#define CAP_BUTT 0 +#define CAP_ROUND 1 +#define CAP_SQUARE 2 + +/** + * Create a QPen object + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QPen_init +(JNIEnv *env, jobject obj , jdouble width, jint cap, jint join, jdouble miterlimit) +{ + Qt::PenCapStyle qtCap; + Qt::PenJoinStyle qtJoin; + + switch(cap) + { + case CAP_BUTT: + qtCap = Qt::FlatCap; + break; + case CAP_ROUND: + qtCap = Qt::RoundCap; + break; + case CAP_SQUARE: + qtCap = Qt::SquareCap; + break; + } + + switch(join) + { + case JOIN_MITER: + qtJoin = Qt::MiterJoin; + break; + case JOIN_ROUND: + qtJoin = Qt::RoundJoin; + break; + case JOIN_BEVEL: + qtJoin = Qt::BevelJoin; + break; + } + + QPen *pen = new QPen(); + assert( pen ); + pen->setWidthF( (qreal)width ); + pen->setCapStyle( qtCap ); + pen->setJoinStyle( qtJoin ); + + setNativeObject(env, obj, pen); +} + +/** + * Dispose of the QPen object + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QPen_dispose +(JNIEnv *env, jobject obj) +{ + QPen *pen = (QPen *)getNativeObject(env, obj); + if ( pen ) + delete pen; +} + diff --git a/libjava/classpath/native/jni/qt-peer/qtaudioclip.cpp b/libjava/classpath/native/jni/qt-peer/qtaudioclip.cpp new file mode 100644 index 000000000..d5689b26d --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qtaudioclip.cpp @@ -0,0 +1,114 @@ +/* qtaudioclip.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include +#include +#include "qtstrings.h" +#include "nativewrapper.h" + +/* + * Loads an audio clip. Returns JNI_TRUE if the load succeded, + * JNI_FALSE otherwise. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtAudioClip_loadClip +(JNIEnv *env, jobject obj, jstring filename) +{ + QString *qStr = getQString(env, filename); + + QSound *sound = new QSound( *qStr ); + + delete qStr; + + setNativeObject( env, obj, sound ); +} + +/* + * Plays the audio clip, plays looped if loop equals JNI_TRUE. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtAudioClip_play +(JNIEnv *env, jobject obj, jboolean loop) +{ + QSound *sound = (QSound *)getNativeObject(env, obj); + if( sound != NULL ) + { + sound->setLoops( (loop == JNI_TRUE) ? -1 : 1 ); + sound->play(); + } +} + +/* + * Stops the audio playback. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtAudioClip_stop +(JNIEnv *env, jobject obj) +{ + QSound *sound = (QSound *)getNativeObject(env, obj); + if( sound != NULL ) + sound->stop(); +} + +/** + * Disposes the audio clip + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtAudioClip_dispose +(JNIEnv *env, jobject obj) +{ + QSound *sound = (QSound *)getNativeObject(env, obj); + if( sound != NULL ) + { + setNativeObject( env, obj, NULL ); + if( !sound->isFinished() ) + sound->stop(); + delete sound; + } +} + +/** + * Returns whether sound is available. + */ +JNIEXPORT jboolean JNICALL Java_gnu_java_awt_peer_qt_QtAudioClip_isAvailable +(JNIEnv *env, jobject obj) +{ + if( QSound::isAvailable() ) + return JNI_TRUE; + else + return JNI_FALSE; +} + diff --git a/libjava/classpath/native/jni/qt-peer/qtbuttonpeer.cpp b/libjava/classpath/native/jni/qt-peer/qtbuttonpeer.cpp new file mode 100644 index 000000000..b807ed466 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qtbuttonpeer.cpp @@ -0,0 +1,94 @@ +/* qtbuttonpeer.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include +#include +#include "qtcomponent.h" +#include "qtstrings.h" +#include "keybindings.h" +#include "buttonevent.h" +#include "slotcallbacks.h" + + +class MyButton : public QPushButton +{ +public: + MyButton(JNIEnv *env, jobject obj, QWidget *parent) : QPushButton(parent) + { + setup(env, obj); + } + + ~MyButton() + { + destroy(); + } +#define I_KNOW_WHAT_IM_DOING +#define PARENT QPushButton +#include "eventmethods.h" +}; + +/** + * Init method + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtButtonPeer_init +(JNIEnv *env, jobject obj) +{ + + QWidget *parentWidget = (QWidget *) getParentWidget( env, obj ); + MyButton *button = new MyButton( env, obj, parentWidget ); + assert( button ); + setNativeObject( env, obj, button ); + connectButton(button, env, obj); // connect the fireClick method. +} + +/** + * Sets the button label. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtButtonPeer_setLabel +(JNIEnv *env, jobject obj, jstring str) +{ + QPushButton *button = (QPushButton *) getNativeObject( env, obj ); + assert( button ); + + QString *qStr = getQString(env, str); // AWTLabelEvent takes care of disposal. + mainThread->postEventToMain( new AWTLabelEvent( button, qStr ) ); +} + + diff --git a/libjava/classpath/native/jni/qt-peer/qtcanvaspeer.cpp b/libjava/classpath/native/jni/qt-peer/qtcanvaspeer.cpp new file mode 100644 index 000000000..9cdbaef8a --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qtcanvaspeer.cpp @@ -0,0 +1,75 @@ +/* qtcanvaspeer.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include +#include "qtcomponent.h" +#include "keybindings.h" + +class MyCanvas : public QWidget +{ +public: + MyCanvas(JNIEnv *env, jobject obj, QWidget *parent) : QWidget( parent ) + { + setup(env, obj); + } + + ~MyCanvas() + { + destroy(); + } + +#define I_KNOW_WHAT_IM_DOING +#define PARENT QWidget +#include "eventmethods.h" +}; + +/* + * Construct a QWidget object + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtCanvasPeer_init +(JNIEnv *env, jobject obj) +{ + QWidget *parentWidget = (QWidget *)getParentWidget(env, obj); + // QWidget *canvas = new QWidget( parentWidget ); + QWidget *canvas = new MyCanvas( env, obj, parentWidget ); + assert( canvas ); + + setNativeObject( env, obj, canvas ); +} diff --git a/libjava/classpath/native/jni/qt-peer/qtcheckboxpeer.cpp b/libjava/classpath/native/jni/qt-peer/qtcheckboxpeer.cpp new file mode 100644 index 000000000..c7bbe5511 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qtcheckboxpeer.cpp @@ -0,0 +1,164 @@ +/* qtcheckboxpeer.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include +#include +#include "qtstrings.h" +#include "qtcomponent.h" +#include "keybindings.h" +#include "buttonevent.h" +#include "slotcallbacks.h" + +class CheckboxCheckEvent : public AWTEvent { + + private: + QAbstractButton *widget; + bool checked; + + public: + CheckboxCheckEvent(QAbstractButton *w, bool c) + { + widget = w; + checked = c; + } + + void runEvent() + { + if (checked != widget->isChecked()) + widget->setChecked( checked ); + } +}; + +class MyCheckBox : public QCheckBox +{ +public: + MyCheckBox(JNIEnv *env, jobject obj, QWidget *parent) : QCheckBox( parent ) + { + setup(env, obj); + } + + ~MyCheckBox() + { + destroy(); + } + +#define I_KNOW_WHAT_IM_DOING +#define PARENT QCheckBox +#include "eventmethods.h" +}; + +/** + * Determines whether the darn native object should be a radio button or not + */ +static bool isRadioButton( JNIEnv *env, jobject obj ) +{ + jclass cls = env->FindClass( "gnu/java/awt/peer/qt/QtCheckboxPeer" ); + jfieldID field = env->GetFieldID( cls, "group", "Ljava/awt/CheckboxGroup;" ); + if (env->GetObjectField( obj, field ) != NULL) + return true; + return false; +} + +/** + * Construct the native object. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtCheckboxPeer_init +(JNIEnv *env, jobject obj) +{ + QWidget *parentWidget = (QWidget *)getParentWidget(env, obj); + + QAbstractButton *cb = (QAbstractButton *) getNativeObject( env, obj ); + if (cb) + delete cb; + + bool radioButton; + { + jclass cls = env->GetObjectClass( obj ); + jfieldID field = env->GetFieldID( cls, "owner", "Ljava/awt/Component;" ); + assert(field != NULL); + jobject owner = env->GetObjectField( obj, field ); + assert(owner != NULL); + cls = env->GetObjectClass( owner ); + jmethodID method = env->GetMethodID( cls, + "getCheckboxGroup", + "()Ljava/awt/CheckboxGroup;" ); + assert(method != NULL); + jobject group = env->CallObjectMethod( owner, method, 0); + radioButton = (group != NULL); + } + + if(radioButton) + cb = new QRadioButton( parentWidget ); + else + cb = new QCheckBox( parentWidget ); + // cb = new MyCheckBox( env, obj, parentWidget ); + assert( cb ); + + connectToggle(cb, env, obj); // connect the native event. + + setNativeObject( env, obj, cb ); +} + +/* + * Sets the checkbox label. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtCheckboxPeer_setLabel +(JNIEnv *env, jobject obj, jstring label) +{ + /* Both QCheckbox and QRadioButton inherit QAbstractButton */ + QAbstractButton *cb = (QAbstractButton *) getNativeObject( env, obj ); + assert( cb ); + + QString *qStr = getQString(env, label); + mainThread->postEventToMain( new AWTLabelEvent( cb, qStr ) ); + // AWTLabelEvent takes care of disposal of qStr +} + +/* + * Sets the checkbox state. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtCheckboxPeer_setState +(JNIEnv *env, jobject obj, jboolean state) +{ + QAbstractButton *cb = (QAbstractButton *) getNativeObject( env, obj ); + assert( cb ); + mainThread->postEventToMain( new CheckboxCheckEvent( cb, (state == JNI_TRUE) ) ); +} + diff --git a/libjava/classpath/native/jni/qt-peer/qtchoicepeer.cpp b/libjava/classpath/native/jni/qt-peer/qtchoicepeer.cpp new file mode 100644 index 000000000..f77d3a0cf --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qtchoicepeer.cpp @@ -0,0 +1,142 @@ +/* qtchoicepeer.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include "qtcomponent.h" +#include "qtstrings.h" +#include "mainthreadinterface.h" +#include "slotcallbacks.h" + +class InsertEvent : public AWTEvent { + + private: + QComboBox *widget; + QString *string; + int index; + + public: + InsertEvent(QComboBox *w, QString *s, int i) : AWTEvent() + { + widget = w; + string = s; + index = i; + } + + void runEvent() + { + widget->insertItem( index, *string ); + delete string; + } +}; + +class RemoveSelectEvent : public AWTEvent { + + private: + QComboBox *widget; + int index; + bool remove; + + public: + RemoveSelectEvent(QComboBox *w, int i, bool r) : AWTEvent() + { + widget = w; + index = i; + remove = r; + } + + void runEvent() + { + if (remove) + widget->removeItem( index ); + else + widget->setCurrentIndex( index ); + } +}; + +/* + * Constructs tha QComboBox object + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtChoicePeer_init +(JNIEnv *env, jobject obj) +{ + QWidget *parentWidget = (QWidget *)getParentWidget(env, obj); + + QComboBox *box = new QComboBox( parentWidget ); + assert( box ); + + setNativeObject( env, obj, box ); + + connectChoice(box, env, obj); // connect the fireChoice method. +} + +/* + * Inserts a choice box item at index. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtChoicePeer_add +(JNIEnv *env, jobject obj, jstring itemLabel, jint index) +{ + QComboBox *box = (QComboBox *) getNativeObject( env, obj ); + assert( box ); + + QString *qStr = getQString( env, itemLabel ); + mainThread->postEventToMain( new InsertEvent( box, qStr, index ) ); +} + +/* + * Removes a choice box item at index. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtChoicePeer_remove +(JNIEnv *env, jobject obj, jint index) +{ + QComboBox *box = (QComboBox *) getNativeObject( env, obj ); + assert( box ); + mainThread->postEventToMain( new RemoveSelectEvent( box, index, true ) ); +} + +/** + * Selects a choice box item. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtChoicePeer_select +(JNIEnv *env, jobject obj, jint index) +{ + QComboBox *box = (QComboBox *) getNativeObject( env, obj ); + assert( box ); + mainThread->postEventToMain( new RemoveSelectEvent( box, index, false ) ); +} + diff --git a/libjava/classpath/native/jni/qt-peer/qtcomponent.cpp b/libjava/classpath/native/jni/qt-peer/qtcomponent.cpp new file mode 100644 index 000000000..fc7480091 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qtcomponent.cpp @@ -0,0 +1,122 @@ +/* qtcomponent.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include +#include "qtcomponent.h" +#include "containers.h" + +#define COMPONENT_CLASS "gnu/java/awt/peer/qt/QtComponentPeer" + +/* + * Returns the parent widget for a QtComponentPeer + */ +void *getParentWidget( JNIEnv *env, jobject qtcomponentpeer ) +{ + jclass componentCls = env->GetObjectClass( qtcomponentpeer ); + jfieldID ownerField = env->GetFieldID( componentCls, + "owner", "Ljava/awt/Component;" ); + assert( ownerField ); + jobject owner = env->GetObjectField( qtcomponentpeer, ownerField ); + if (owner == NULL) + return NULL; + + jclass ownerCls = env->GetObjectClass( owner ); + jmethodID getParentMID = env->GetMethodID( ownerCls, + "getParent", + "()Ljava/awt/Container;" ); + assert(getParentMID); + + jobject parent = env->CallObjectMethod( owner, getParentMID, 0); + assert(parent); + + // Get the parents peer + jclass parentCls = env->GetObjectClass( parent ); + { + jclass frameCls = env->FindClass( "java/awt/Frame" ); + if(env->IsInstanceOf( parent, frameCls ) == JNI_TRUE) + return frameChildWidget( env, parent ); + } + { + jclass scrollpaneCls = env->FindClass( "java/awt/ScrollPane" ); + if(env->IsInstanceOf( parent, scrollpaneCls ) == JNI_TRUE) + return scrollPaneChildWidget( env, parent ); + } + + jmethodID getPeerMID = env->GetMethodID( parentCls, + "getPeer", + "()Ljava/awt/peer/ComponentPeer;" ); + assert(getPeerMID); + return getNativeObject(env, env->CallObjectMethod( parent, getPeerMID, 0)); +} + +/* + * Creates a java.awt.Dimension object from a QSize. + */ +jobject makeDimension(JNIEnv *env, QSize *size) +{ + if( size == NULL ) + return NULL; + if( size->isNull() || !size->isValid() ) + return NULL; + jclass cls = env->FindClass("java/awt/Dimension"); + jmethodID mid = env->GetMethodID(cls, "", "(II)V"); + jvalue values[2]; + + values[0].i = (jint) size->width(); + values[1].i = (jint) size->height(); + + return env->NewObjectA(cls, mid, values); +} + +/* + * Creates a java.awt.Point object from a QPoint. + */ +jobject makePoint(JNIEnv *env, QPoint &p) +{ + jclass cls = env->FindClass("java/awt/Point"); + jmethodID mid = env->GetMethodID(cls, "", "(II)V"); + jvalue values[2]; + + values[0].i = (jint) p.x(); + values[1].i = (jint) p.y(); + + return env->NewObjectA(cls, mid, values); +} + diff --git a/libjava/classpath/native/jni/qt-peer/qtcomponent.h b/libjava/classpath/native/jni/qt-peer/qtcomponent.h new file mode 100644 index 000000000..3188f03f5 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qtcomponent.h @@ -0,0 +1,16 @@ +#ifndef QTCOMPONENT_H +#define QTCOMPONENT_H + +#include +#include +//#include +#include +#include "nativewrapper.h" + +void *getParentWidget( JNIEnv *env, jobject qtcomponentpeer ); + +jobject makeDimension(JNIEnv *env, QSize *size); + +jobject makePoint(JNIEnv *env, QPoint &p); + +#endif diff --git a/libjava/classpath/native/jni/qt-peer/qtcomponentpeer.cpp b/libjava/classpath/native/jni/qt-peer/qtcomponentpeer.cpp new file mode 100644 index 000000000..0399dd8fd --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qtcomponentpeer.cpp @@ -0,0 +1,384 @@ +/* qtcomponentpeer.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "qtcomponent.h" +#include "componentevent.h" +#include "qtfont.h" + +extern QApplication *qApplication; + +// Java Cursor types. +#define DEFAULT_CURSOR 0 +#define CROSSHAIR_CURSOR 1 +#define TEXT_CURSOR 2 +#define WAIT_CURSOR 3 +#define SW_RESIZE_CURSOR 4 +#define SE_RESIZE_CURSOR 5 +#define NW_RESIZE_CURSOR 6 +#define NE_RESIZE_CURSOR 7 +#define N_RESIZE_CURSOR 8 +#define S_RESIZE_CURSOR 9 +#define W_RESIZE_CURSOR 10 +#define E_RESIZE_CURSOR 11 +#define HAND_CURSOR 12 +#define MOVE_CURSOR 13 + +/** + * Call back the init() method from the main thread. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_callInit +(JNIEnv *env, jobject obj) +{ + mainThread->postEventToMain( new AWTInitEvent( env, obj ) ); +} + +/* + * Generic disposal. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_disposeNative +(JNIEnv *env, jobject obj) +{ + QWidget *widget = (QWidget *) getNativeObject( env, obj ); + setNativeObject(env, obj, NULL); + mainThread->postEventToMain( new AWTDestroyEvent( widget ) ); +} + +/** + * Returns the on-screen location of the component. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_getLocationOnScreenNative +(JNIEnv *env, jobject obj, jobject point) +{ + QWidget *widget = (QWidget *) getNativeObject( env, obj ); + assert( widget ); + mainThread->postEventToMain( new AWTGetOriginEvent( widget, env, point) ); +} + +/* + * Get the preferred/minimum size of the widget + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_getSizeNative +(JNIEnv *env, jobject obj, jobject size, jboolean preferred) +{ + QWidget *widget = (QWidget *) getNativeObject( env, obj ); + assert( widget ); + + mainThread->postEventToMain + (new GetSizeEvent( widget, env, size, (preferred == JNI_TRUE))); +} + +/* + */ +JNIEXPORT jboolean JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_isObscured +(JNIEnv *env, jobject obj) +{ + jboolean retVal; + + QWidget *widget = (QWidget *) getNativeObject( env, obj ); + assert( widget ); + + retVal = (widget->isVisible() == TRUE) ? JNI_TRUE : JNI_FALSE; + + return retVal; +} + +/* + * Returns whether the widget is focusable or not. + */ +JNIEXPORT jboolean JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_isFocusable +(JNIEnv *env, jobject obj) +{ + jboolean retVal; + + QWidget *widget = (QWidget *) getNativeObject( env, obj ); + assert( widget ); + + retVal = (widget->focusPolicy() != Qt::NoFocus) ? JNI_TRUE : JNI_FALSE; + + return retVal; +} + +/** + * Requests the focus + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_requestFocus + (JNIEnv *env, jobject obj) +{ + QWidget *widget = (QWidget *) getNativeObject( env, obj ); + assert( widget ); + mainThread->postEventToMain( new AWTReqFocusEvent( widget ) ); +} + +/* + * Sets the size and position. Important. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_setBoundsNative +(JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height) +{ + QWidget *widget = (QWidget *) getNativeObject( env, obj ); + assert( widget ); + mainThread->postEventToMain + (new AWTResizeEvent( widget, x, y, width, height ) ); +} + +/* + * Sets the mouse cursor + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_setCursor + (JNIEnv *env, jobject obj, jint cursortype) +{ + QWidget *widget = (QWidget *) getNativeObject( env, obj ); + assert( widget ); + + Qt::CursorShape shape; + switch(cursortype) + { + case CROSSHAIR_CURSOR: + shape = Qt::CrossCursor; + break; + + case W_RESIZE_CURSOR: + case E_RESIZE_CURSOR: + shape = Qt::SizeHorCursor; + break; + case N_RESIZE_CURSOR: + case S_RESIZE_CURSOR: + shape = Qt::SizeVerCursor; + break; + case HAND_CURSOR: + shape = Qt::PointingHandCursor; + break; + case MOVE_CURSOR: + shape = Qt::SizeAllCursor; + break; + + case NE_RESIZE_CURSOR: + case SW_RESIZE_CURSOR: + shape = Qt::SizeBDiagCursor; + break; + case NW_RESIZE_CURSOR: + case SE_RESIZE_CURSOR: + shape = Qt::SizeFDiagCursor; + break; + case TEXT_CURSOR: + shape = Qt::IBeamCursor; + break; + case WAIT_CURSOR: + shape = Qt::WaitCursor; + break; + + case DEFAULT_CURSOR: + default: + shape = Qt::ArrowCursor; + break; + } + + mainThread->postEventToMain( new AWTCursorEvent( widget, shape ) ); +} + +/* + * Enable, disable. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_setEnabled +(JNIEnv *env, jobject obj, jboolean state) +{ + QWidget *widget = (QWidget *) getNativeObject( env, obj ); + assert(widget != NULL); + + mainThread->postEventToMain( new AWTEnableEvent( widget, (state == JNI_TRUE) ) ); +} + +/** + * Set the font + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_setFontNative +(JNIEnv *env, jobject obj, jobject fontpeer) +{ + QWidget *widget = (QWidget *) getNativeObject( env, obj ); + assert( widget ); + QFont *font = (QFont *) getFont( env, fontpeer ); + assert( font ); + + mainThread->postEventToMain( new AWTFontEvent(widget, font) ); +} + +/* + * Sets the back- or foreground color. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_setGround +(JNIEnv *env, jobject obj, jint r, jint g, jint b, jboolean isForeground) +{ + QColor *color = new QColor(r, g, b); + + QWidget *widget = (QWidget *) getNativeObject( env, obj ); + assert(widget); + mainThread->postEventToMain( new AWTBackgroundEvent(widget, + (isForeground == JNI_TRUE), + color) ); +} + +/* + * Sets the visibility. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_setVisible +(JNIEnv *env, jobject obj, jboolean state) +{ + QWidget *widget = (QWidget *) getNativeObject( env, obj ); + assert(widget != NULL); + mainThread->postEventToMain( new AWTShowEvent( widget, (state == JNI_TRUE) ) ); +} + +/* + * Returns whether the widget handles wheel scrolling. + */ +JNIEXPORT jboolean JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_handlesWheelScrolling +(JNIEnv *env, jobject obj) +{ + jboolean handles = JNI_FALSE; + + QWidget *cb = (QWidget *) getNativeObject( env, obj ); + if( cb ) + if( cb->focusPolicy() & Qt::WheelFocus ) + handles = JNI_TRUE; + + return handles; +} + +/** + * calls qwidget::update on the compnent. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_QtUpdateArea +(JNIEnv *env, jobject obj, jint x, jint y, jint w, jint h) +{ + QWidget *cb = (QWidget *) getNativeObject( env, obj ); + if( cb ) + mainThread->postEventToMain( new AWTUpdateEvent + (cb, false, x, y, w, h ) ); +} + +/* + * calls qwidget::update on the compnent. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_QtUpdate +(JNIEnv *env, jobject obj) +{ + QWidget *cb = (QWidget *) getNativeObject( env, obj ); + if( cb ) + mainThread->postEventToMain( new AWTUpdateEvent + ( cb, true, 0, 0, 0, 0 ) ); +} + +/* + * Returns the native background color. + */ +JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_getNativeBackground +(JNIEnv *env, jobject obj) +{ + QWidget *cb = (QWidget *) getNativeObject( env, obj ); + assert(cb); + QColor c = cb->palette().background().color().toRgb(); + + jclass cls = env->FindClass("java/awt/Color"); + jmethodID mid = env->GetMethodID(cls, "", "(III)V"); + jvalue values[3]; + + values[0].i = (jint) c.red(); + values[1].i = (jint) c.green(); + values[2].i = (jint) c.blue(); + + return env->NewObjectA(cls, mid, values); +} + +/* + * Returns which screen the component is on. + */ +JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_whichScreen +(JNIEnv *env, jobject obj) +{ + QWidget *widget = (QWidget *) getNativeObject( env, obj ); + assert( widget ); + return (jint) qApplication->desktop()->screenNumber( widget ); +} + +/* + * Reparents the widget. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_reparentNative +(JNIEnv *env, jobject obj, jobject newparent) +{ + QWidget *widget = (QWidget *) getNativeObject( env, obj ); + assert( widget ); + QWidget *parentWidget = (QWidget *) getNativeObject( env, newparent ); + assert( parentWidget ); + mainThread->postEventToMain( new AWTReparent(widget, parentWidget ) ); +} + +/* + * Get the preferred size of the widget + */ +JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_getBounds + +(JNIEnv *env, jobject obj) +{ + QWidget *widget = (QWidget *) getNativeObject( env, obj ); + assert( widget ); + + int x, y, w, h; + widget->geometry().getRect(&x, &y, &w, &h); + + jclass cls = env->FindClass("java/awt/Rectangle"); + assert( cls != NULL); + jmethodID mid = env->GetMethodID(cls, "", "(IIII)V"); + assert( mid != NULL); + jvalue values[4]; + + values[0].i = (jint) x; + values[1].i = (jint) y; + values[2].i = (jint) w; + values[3].i = (jint) h; + + return env->NewObjectA(cls, mid, values); +} diff --git a/libjava/classpath/native/jni/qt-peer/qtdialogpeer.cpp b/libjava/classpath/native/jni/qt-peer/qtdialogpeer.cpp new file mode 100644 index 000000000..0eb709443 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qtdialogpeer.cpp @@ -0,0 +1,164 @@ +/* qtdialogpeer.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include "qtcomponent.h" +#include "containers.h" +#include "qtstrings.h" +#include "keybindings.h" +#include "mainthreadinterface.h" + +class MyDialog : public QDialog +{ +public: + MyDialog(JNIEnv *env, jobject obj, QWidget *parent) : QDialog(parent) + { + setup(env, obj); + } + + ~MyDialog() + { + destroy(); + } + +#define I_KNOW_WHAT_IM_DOING +#define PARENT QDialog +#include "eventmethods.h" +}; + +class DialogSettingsEvent : public AWTEvent { + + private: + QDialog *widget; + bool modal; + bool value; + + public: + DialogSettingsEvent(QDialog *w, bool m, bool v) : AWTEvent() + { + widget = w; + modal = m; + value = v; + } + + void runEvent() + { + if( modal ) + widget->setModal( value ); + else + widget->setSizeGripEnabled( value ); + } +}; + +class DialogResizeEvent : public AWTEvent { + + private: + QWidget *widget; + bool fixed; + int x, y, w, h; + + public: + DialogResizeEvent(QWidget *wid, int x0, int y0, int w0, int h0, bool f) + { + widget = wid; + fixed = f; + x = x0; y = y0; + w = w0; h = h0; + if(w == 0 && h == 0) w = h = 10; + } + + void runEvent() + { + if( fixed ) + widget->setFixedSize( w, h ); + widget->setGeometry( x, y, w, h ); + } +}; + +/* + * Constructs a QDialog native object. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtDialogPeer_init +(JNIEnv *env, jobject obj) +{ + QWidget *parentWidget = (QWidget *) getParentWidget( env, obj ); + // QDialog *dialog = new QDialog(parentWidget); + MyDialog *dialog = new MyDialog(env, obj, parentWidget); + assert( dialog ); + setNativeObject( env, obj, dialog ); +} + + +/* + * Sets the modality of the dialog. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtDialogPeer_setModal +(JNIEnv *env, jobject obj, jboolean flag) +{ + QDialog *dialog = (QDialog *) getNativeObject( env, obj ); + assert( dialog ); + mainThread->postEventToMain( new DialogSettingsEvent(dialog, true, (flag == JNI_TRUE))); +} + + +/* + * Set resizeable. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtDialogPeer_setResizable +(JNIEnv *env, jobject obj, jboolean flag) +{ + QDialog *dialog = (QDialog *) getNativeObject( env, obj ); + assert( dialog ); + mainThread->postEventToMain( new DialogSettingsEvent(dialog, false, (flag == JNI_TRUE))); +} + +/* + * Overloaded to allow for size locking. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtDialogPeer_setBoundsNative +(JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height, jboolean fixed) +{ + QWidget *widget = (QWidget *) getNativeObject( env, obj ); + assert( widget ); + + QRect g = widget->geometry(); + if(g.x() != x || g.y() != y || + g.width() != width || g.height() != height) + mainThread->postEventToMain( new DialogResizeEvent( widget, x, y, width, height, (fixed == JNI_TRUE) ) ); +} diff --git a/libjava/classpath/native/jni/qt-peer/qtembeddedwindowpeer.cpp b/libjava/classpath/native/jni/qt-peer/qtembeddedwindowpeer.cpp new file mode 100644 index 000000000..dbbf87ea4 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qtembeddedwindowpeer.cpp @@ -0,0 +1,113 @@ +/* qtembeddedwindowpeer.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include +#include "qtcomponent.h" +#include "keybindings.h" +#include "mainthreadinterface.h" + +/** + * Event wrapper for embedding. + */ +class EmbedEvent : public AWTEvent { + + private: + QX11EmbedWidget *widget; + WId id; + + public: + EmbedEvent(QX11EmbedWidget *w, WId i) : AWTEvent() + { + widget = w; + id = i; + } + + void runEvent() + { + widget->embedInto( id ); + } +}; + + +class MyEmbeddedPanel : public QX11EmbedWidget +{ +public: + MyEmbeddedPanel(JNIEnv *env, jobject obj, QWidget *parent) : QX11EmbedWidget( parent ) + { + setup(env, obj); + } + + ~MyEmbeddedPanel() + { + destroy(); + } + +#define I_KNOW_WHAT_IM_DOING +#define PARENT QX11EmbedWidget +#include "eventmethods.h" +#undef I_KNOW_WHAT_IM_DOING +#undef PARENT +}; + +/** + * Init + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtEmbeddedWindowPeer_init +(JNIEnv *env, jobject obj) +{ + QWidget *parentWidget = (QWidget *) getParentWidget( env, obj ); + QWidget *panel = new MyEmbeddedPanel( env, obj, parentWidget ); + assert( panel ); + + setNativeObject( env, obj, panel ); +} + +/** + * Embed the thing. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtEmbeddedWindowPeer_embed +(JNIEnv *env, jobject obj, jlong wid) +{ + MyEmbeddedPanel *panel = (MyEmbeddedPanel *)getNativeObject( env, obj ); + assert( panel ); + + mainThread->postEventToMain( new EmbedEvent( panel, (WId)wid ) ); +} + diff --git a/libjava/classpath/native/jni/qt-peer/qtfiledialogpeer.cpp b/libjava/classpath/native/jni/qt-peer/qtfiledialogpeer.cpp new file mode 100644 index 000000000..bd6ab3f08 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qtfiledialogpeer.cpp @@ -0,0 +1,101 @@ +/* qtfiledialogpeer.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include +#include "qtcomponent.h" +#include "qtstrings.h" +#include "mainthreadinterface.h" + +// Constants from FileDialog +#define LOAD 0 +#define SAVE 1 + +class FileDialogMode : public AWTEvent { + + private: + QFileDialog *widget; + bool open; + + public: + FileDialogMode(QFileDialog *w, bool o) : AWTEvent() + { + widget = w; + open = o; + } + + void runEvent() + { + if( open ) + { + widget->setAcceptMode( QFileDialog::AcceptOpen ); + widget->setFileMode( QFileDialog::ExistingFile ); + } + else + { + widget->setAcceptMode( QFileDialog::AcceptSave ); + widget->setFileMode( QFileDialog::AnyFile ); + } + } +}; + + +/* + * Constructs a QDialog native object. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtFileDialogPeer_init +(JNIEnv *env, jobject obj) +{ + QWidget *parentWidget = (QWidget *) getParentWidget( env, obj ); + QFileDialog *dialog = new QFileDialog(parentWidget); + assert( dialog ); + setNativeObject( env, obj, dialog ); +} + +/** + * Sets the mode (LOAD or SAVE) + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtFileDialogPeer_setMode +(JNIEnv *env, jobject obj, jint mode) +{ + QFileDialog *filedialog = (QFileDialog *) getNativeObject( env, obj ); + assert( filedialog ); + + mainThread->postEventToMain( new FileDialogMode( filedialog, (mode != SAVE) ) ); +} diff --git a/libjava/classpath/native/jni/qt-peer/qtfont.h b/libjava/classpath/native/jni/qt-peer/qtfont.h new file mode 100644 index 000000000..d13b8e098 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qtfont.h @@ -0,0 +1,8 @@ +#ifndef QTFONT_H +#define QTFONT_H + +#include + +QFont *getFont( JNIEnv *env, jobject obj ); + +#endif diff --git a/libjava/classpath/native/jni/qt-peer/qtfontmetrics.cpp b/libjava/classpath/native/jni/qt-peer/qtfontmetrics.cpp new file mode 100644 index 000000000..f2f61822d --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qtfontmetrics.cpp @@ -0,0 +1,233 @@ +/* qtfontmetrics.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "qtfont.h" +#include "qtstrings.h" +#include "qtgraphics.h" + +QFontMetrics *getFontMetrics( JNIEnv *env, jobject obj ) +{ + jclass cls = env->GetObjectClass( obj ); + jfieldID field = env->GetFieldID( cls, "nativeObject", "J" ); + return (QFontMetrics *)env->GetLongField( obj, field ); +} + +static void setNativePtr( JNIEnv *env, jobject obj, void *value ) +{ + jlong longValue = (jlong) value; + jclass cls = env->GetObjectClass( obj ); + jfieldID field = env->GetFieldID( cls, "nativeObject", "J" ); + env->SetLongField( obj, field, longValue ); +} + +static jobject makeRectangle(JNIEnv *env, QRect *rect) +{ + if( rect == NULL ) + return NULL; + if( rect->isNull() || !rect->isValid() ) + return NULL; + jclass cls = env->FindClass("java/awt/Rectangle"); + jmethodID mid = env->GetMethodID(cls, "", "(IIII)V"); + jvalue values[4]; + + int x,y,w,h; + rect->getRect(&x, &y, &w, &h); + values[0].i = (jint) x; + values[1].i = (jint) y; + values[2].i = (jint) w; + values[3].i = (jint) h; + + return env->NewObjectA(cls, mid, values); +} + +/* + * Create font metrics from a font. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtFontMetrics_init +(JNIEnv *env, jobject obj, jobject fontPeer) +{ + QFont *f = getFont(env, fontPeer); + assert( f ); + QFontMetrics *fm = new QFontMetrics( *f ); + assert( fm ); + setNativePtr( env, obj, fm ); +} + +/* + * Create font metrics from a font. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtFontMetrics_initGraphics +(JNIEnv *env, jobject obj, jobject fontPeer, jobject graphics) +{ + QFont *f = getFont(env, fontPeer); + assert( f ); + QPainter *painter = getPainter( env, graphics ); + assert( painter ); + QFontMetrics *fm = new QFontMetrics( *f , painter->device()); + assert( fm ); + setNativePtr( env, obj, fm ); +} + +/* + * Dispose + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtFontMetrics_dispose +(JNIEnv *env, jobject obj) +{ + QFontMetrics *fm = getFontMetrics( env, obj ); + if ( fm ) + delete fm; + setNativePtr( env, obj, NULL ); +} + +/* + * Returns JNI_TRUE if a character is displayable. + */ +JNIEXPORT jboolean JNICALL Java_gnu_java_awt_peer_qt_QtFontMetrics_canDisplay +(JNIEnv *env, jobject obj, jint c) +{ + QFontMetrics *fm = getFontMetrics( env, obj ); + assert( fm ); + bool result = fm->inFont( QChar( (unsigned int) c ) ); + return (result ? JNI_TRUE : JNI_FALSE); +} + +/* + * Returns the ascent. + */ +JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtFontMetrics_getAscent +(JNIEnv *env, jobject obj) +{ + QFontMetrics *fm = getFontMetrics( env, obj ); + assert( fm ); + return fm->ascent(); +} + +/* + * Returns the descent + */ +JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtFontMetrics_getDescent +(JNIEnv *env, jobject obj) +{ + QFontMetrics *fm = getFontMetrics( env, obj ); + assert( fm ); + return fm->descent(); +} + +/* + * Returns the height. + */ +JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtFontMetrics_getHeight +(JNIEnv *env, jobject obj) +{ + QFontMetrics *fm = getFontMetrics( env, obj ); + assert( fm ); + return fm->height(); +} + +/* + */ +JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtFontMetrics_getLeading +(JNIEnv *env, jobject obj) +{ + QFontMetrics *fm = getFontMetrics( env, obj ); + assert( fm ); + return fm->leading(); +} + +/* + * getStringBounds + */ +JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QtFontMetrics_getStringBounds +(JNIEnv *env, jobject obj, jstring str) +{ + QFontMetrics *fm = getFontMetrics( env, obj ); + assert( fm ); + QString *qStr = getQString(env, str); + QRect r = fm->boundingRect( *qStr ); + delete qStr; + + return makeRectangle( env, &r ); +} + +/* + * Returns the width of the widest character. + */ +JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtFontMetrics_getMaxAdvance +(JNIEnv *env, jobject obj) +{ + QFontMetrics *fm = getFontMetrics( env, obj ); + assert( fm ); + return fm->maxWidth(); +} + +/* + * Returns the width of a given character. + */ +JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtFontMetrics_charWidth +(JNIEnv *env, jobject obj, jchar c) +{ + QFontMetrics *fm = getFontMetrics( env, obj ); + assert( fm ); + return fm->width( QChar( (unsigned short)c ) ); +} + +/* + * Returns the width of a string. + */ +JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtFontMetrics_stringWidth +(JNIEnv *env, jobject obj, jstring str) +{ + QFontMetrics *fm = getFontMetrics( env, obj ); + assert( fm ); + QString *qStr = getQString(env, str); + int width = fm->width( *qStr ); + delete qStr; + return width; +} + + + diff --git a/libjava/classpath/native/jni/qt-peer/qtfontpeer.cpp b/libjava/classpath/native/jni/qt-peer/qtfontpeer.cpp new file mode 100644 index 000000000..7859f6234 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qtfontpeer.cpp @@ -0,0 +1,92 @@ +/* qtfontpeer.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include +#include "qtfont.h" +#include "qtstrings.h" + +// java.awt.Font constants +#define PLAIN 0 +#define BOLD 1 +#define ITALIC 2 + +QFont *getFont( JNIEnv *env, jobject obj ) +{ + jclass cls = env->GetObjectClass( obj ); + jfieldID field = env->GetFieldID( cls, "nativeObject", "J" ); + return (QFont *)env->GetLongField( obj, field ); +} + +static void setNativePtr( JNIEnv *env, jobject obj, void *value ) +{ + jlong longValue = (jlong) value; + jclass cls = env->GetObjectClass( obj ); + jfieldID field = env->GetFieldID( cls, "nativeObject", "J" ); + env->SetLongField( obj, field, longValue ); +} + +/* + * Creates a font. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtFontPeer_create +(JNIEnv *env, jobject obj, jstring name, jint style, jint size) +{ + QString *str = getQString(env, name); + QFont *font = NULL; + font = new QFont( *str, size, + ((style & BOLD) != 0) ? QFont::Bold : QFont::Normal, + ((style & ITALIC) != 0) ); + assert( font ); + delete str; + setNativePtr( env, obj, font ); +} + +/* + * Destroys a font. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtFontPeer_dispose +(JNIEnv *env, jobject obj) +{ + QFont *font = getFont( env, obj ); + if( font ) + delete font; + setNativePtr( env, obj, NULL ); +} + diff --git a/libjava/classpath/native/jni/qt-peer/qtframepeer.cpp b/libjava/classpath/native/jni/qt-peer/qtframepeer.cpp new file mode 100644 index 000000000..85059ab1a --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qtframepeer.cpp @@ -0,0 +1,205 @@ +/* qtframepeer.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "qtcomponent.h" +#include "qtstrings.h" +#include "qtimage.h" +#include "containers.h" +#include "keybindings.h" +#include "mainthreadinterface.h" + +#define MenuSizeDefault 5 + +/* + * Our QMainWindow subclass + */ +class MyFrame : public QMainWindow +{ +public: + MyFrame(JNIEnv *env, jobject obj) : QMainWindow(0, Qt::Window ) + { + setup(env, obj); + } + + ~MyFrame() + { + destroy(); + } + +#define I_KNOW_WHAT_IM_DOING +#define PARENT QMainWindow +#include "eventmethods.h" +}; + +/** + * Event wrapper for adding a menu bar to the frame + * if the QMenuBar pointer is NULL, the current menu bar is removed. + */ +class FrameMenuEvent : public AWTEvent { + + private: + QMainWindow *widget; + QMenuBar *menu; + + public: + FrameMenuEvent(QMainWindow *w, QMenuBar *mb) : AWTEvent() + { + widget = w; + menu = mb; + } + + void runEvent() + { + if( menu != NULL) + widget->setMenuBar( menu ); + else + delete widget->menuBar(); + } +}; + +/** + * Returns the child widget for the frame (the centralWidget in qt terms) + */ +QWidget *frameChildWidget( JNIEnv *env, jobject component ) +{ + jclass frameCls = env->FindClass( "java/awt/Frame" ); + assert( frameCls ); + jmethodID getPeerMID = env->GetMethodID( frameCls, + "getPeer", + "()Ljava/awt/peer/ComponentPeer;" ); + assert(getPeerMID); + + jobject framepeerobj = env->CallObjectMethod( component, getPeerMID, 0); + if( framepeerobj == NULL ) + return (QWidget *)NULL; + + MyFrame *window = (MyFrame *)getNativeObject(env, framepeerobj); + assert( window ); + return window; +} + +/* + * Constructs a QMainWindow native object. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtFramePeer_init +(JNIEnv *env, jobject obj) +{ + MyFrame *frame = new MyFrame(env, obj); + assert( frame ); + frame->addToolBarBreak ( Qt::BottomToolBarArea ); + setNativeObject( env, obj, frame ); +} + +/** + * Sets the icon image. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtFramePeer_setIcon +(JNIEnv *env, jobject obj, jobject image) +{ + QMainWindow *frame = (QMainWindow *) getNativeObject( env, obj ); + assert( frame ); + + QIcon *i; + if( image == NULL ) + { + // remove icon + i = new QIcon(); + } + else + { + // set icon + QImage *img = getQtImage( env, image ); + assert( img ); + i = new QIcon( QPixmap::fromImage( *img ) ); + } + frame->setWindowIcon( *i ); + delete i; +} + +/** + * Returns the menu bar height for insets. + */ +JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtFramePeer_menuBarHeight +(JNIEnv *env, jobject obj) +{ + QMainWindow *frame = (QMainWindow *) getNativeObject( env, obj ); + assert( frame ); + + QMenuBar *mb = frame->menuBar(); + + return ( mb != NULL ) ? mb->sizeHint().height() : 0 ; +} + +/* + * set Menu bar. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtFramePeer_setMenu +(JNIEnv *env, jobject obj, jobject mbPeer) +{ + QMainWindow *frame = (QMainWindow *) getNativeObject( env, obj ); + assert( frame ); + + QMenuBar *menubar = NULL; + + if( mbPeer != NULL ) + { + menubar = (QMenuBar *) getNativeObject( env, mbPeer ); + assert( menubar ); + } + + mainThread->postEventToMain( new FrameMenuEvent( frame, menubar ) ); +} + +/** + * Set the bounds of the maximized frame + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtFramePeer_setMaximizedBounds (JNIEnv *env, jobject obj, jint w, jint h) +{ + QMainWindow *frame = (QMainWindow *) getNativeObject( env, obj ); + assert( frame ); + // FIXME +} + diff --git a/libjava/classpath/native/jni/qt-peer/qtgraphics.cpp b/libjava/classpath/native/jni/qt-peer/qtgraphics.cpp new file mode 100644 index 000000000..efd334292 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qtgraphics.cpp @@ -0,0 +1,475 @@ +/* qtgraphics.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "nativewrapper.h" +#include "qtimage.h" +#include "qtstrings.h" +#include "qtcomponent.h" +#include "qtgraphics.h" +#include "qtfont.h" + +// Constants from java.awt.AlphaComposite +#define CLEAR 1 +#define SRC 2 +#define DST 9 +#define SRC_OVER 3 +#define DST_OVER 4 +#define SRC_IN 5 +#define DST_IN 6 +#define SRC_OUT 7 +#define DST_OUT 8 +#define SRC_ATOP 10 +#define DST_ATOP 11 +#define XOR 12 + +GraphicsPainter *getPainter( JNIEnv *env, jobject obj ) +{ + jclass cls = env->GetObjectClass( obj ); + jfieldID field = env->GetFieldID( cls, "nativeObject", "J" ); + return (GraphicsPainter *)env->GetLongField( obj, field ); +} + +static void setNativePtr( JNIEnv *env, jobject obj, void *value ) +{ + jlong longValue = (jlong) value; + jclass cls = env->GetObjectClass( obj ); + jfieldID field = env->GetFieldID( cls, "nativeObject", "J" ); + env->SetLongField( obj, field, longValue ); +} + +static jobject getToolkit( JNIEnv *env, jobject obj ) +{ + jclass cls = env->FindClass( "gnu/java/awt/peer/qt/QtGraphics" ); + + jfieldID field = env->GetFieldID( cls, "toolkit", + "Lgnu/java/awt/peer/qt/QtToolkit;" ); + return env->GetObjectField( obj, field ); +} + +///////////////////////// JNI methods //////////////////////////////// + +/** + * Clones the parent QPainter object. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_cloneNativeContext +(JNIEnv *env, jobject obj, jobject parent) +{ + GraphicsPainter *painter = (GraphicsPainter *)getPainter( env, parent ); + assert( painter ); + QPainter *newPainter = new GraphicsPainter( painter->device() ); + assert( newPainter ); + setNativePtr(env, obj, newPainter); +} + +/* + * Start of JNI methods + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_initImage +(JNIEnv *env, jobject obj, jobject image) +{ + QImage *im = getQtImage( env, image ); + assert( im ); + QPainter *painter = new GraphicsPainter( im ); + assert( painter ); + setNativePtr(env, obj, painter); + painter->setRenderHint(QPainter::TextAntialiasing); + painter->setRenderHint(QPainter::Antialiasing); + painter->setRenderHint(QPainter::SmoothPixmapTransform); +} + +/* + * Start of JNI methods + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_initVolatileImage +(JNIEnv *env, jobject obj, jobject image) +{ + QPixmap *im = getQtVolatileImage( env, image ); + assert( im ); + QPainter *painter = new GraphicsPainter( im ); + assert( painter ); + setNativePtr(env, obj, painter); + painter->setRenderHint(QPainter::TextAntialiasing); + painter->setRenderHint(QPainter::Antialiasing); + painter->setRenderHint(QPainter::SmoothPixmapTransform); +} + +/** + * Deletes the QPainter + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_delete +(JNIEnv *env, jobject obj) +{ + GraphicsPainter *painter = (GraphicsPainter *)getPainter( env, obj ); + setNativePtr( env, obj, NULL ); + if( painter ) + { + if( painter->isActive() ) + painter->end(); + delete painter; + } +} + +/////////////////////////////////////////////////////////// +/* + * Sets the clip to a path. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_setClipNative +(JNIEnv *env, jobject obj, jobject path) +{ + QPainter *painter = getPainter( env, obj ); + assert( painter ); + QPainterPath *pp = (QPainterPath *)getNativeObject( env, path ); + assert( pp ); + painter->setClipPath( *pp ); +} + +/* + * Sets the clip to a rectangle. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_setClipRectNative +(JNIEnv *env, jobject obj, jint x, jint y, jint w, jint h) +{ + QPainter *painter = getPainter( env, obj ); + assert( painter ); + painter->setClipRect( x, y, w, h ); +} + +/* + * Intersects a shape with the current clip. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_intersectClipNative +(JNIEnv *env, jobject obj, jobject path) +{ + QPainter *painter = getPainter( env, obj ); + assert( painter ); + QPainterPath *pp = (QPainterPath *)getNativeObject( env, path ); + assert( pp ); + painter->setClipPath( *pp, Qt::IntersectClip ); +} + +/* + * Intersect a rectangle with the current clip. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_intersectClipRectNative +(JNIEnv *env, jobject obj, jint x, jint y, jint w, jint h) +{ + QPainter *painter = getPainter( env, obj ); + assert( painter ); + painter->setClipRect( x, y, w, h, Qt::IntersectClip ); +} + +/* + * Returns a QPainterPath object with the clip path of this painter. + */ +JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_getClipNative +(JNIEnv *env, jobject obj) +{ + QPainter *painter = getPainter( env, obj ); + assert( painter ); + jclass cls = env->FindClass("gnu/java/awt/peer/qt/QPainterPath"); + jmethodID method = env->GetMethodID(cls, "", "()V"); + + jobject ppo = env->NewObject(cls, method); + QPainterPath qpp = painter->clipPath(); + setNativeObject(env, ppo, &qpp); + + env->DeleteLocalRef( cls ); + return ppo; +} + +/* + * Returns a Rectangle with the bounds of this painters clip path. + */ +JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_getClipBounds +(JNIEnv *env, jobject obj) +{ + QPainter *painter = getPainter( env, obj ); + assert( painter ); + qreal x, y, w, h; + painter->clipPath().boundingRect().getRect(&x, &y, &w, &h); + + jclass cls = env->FindClass("java/awt/Rectangle"); + assert( cls != NULL); + jmethodID mid = env->GetMethodID(cls, "", "(IIII)V"); + assert( mid != NULL); + jvalue values[4]; + + values[0].i = (jint) x; + values[1].i = (jint) y; + values[2].i = (jint) w; + values[3].i = (jint) h; + + return env->NewObjectA(cls, mid, values); +} + +///////////////////////// Color stuff //////////////////////// +/** + * + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_setColor +(JNIEnv *env, jobject obj, jint r, jint g, jint b, jint alpha) +{ + GraphicsPainter *painter = (GraphicsPainter *)getPainter( env, obj ); + assert( painter ); + painter->currentPen->setColor( QColor(r, g, b, alpha) ); + painter->setPen( *painter->currentPen ); + painter->currentBrush = new QBrush( QColor(r, g, b, alpha) ); + painter->setBrush( *painter->currentBrush ); + painter->currentColor = new QColor(r, g, b, alpha); +} + +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_setAlphaNative + (JNIEnv *env, jobject obj, jdouble alpha) +{ + GraphicsPainter *painter = (GraphicsPainter *)getPainter( env, obj ); + assert( painter ); + + QColor c = painter->currentPen->color(); + c.setAlphaF( (qreal)alpha ); + painter->currentPen->setColor(c); + + c = painter->currentBrush->color(); + c.setAlphaF( (qreal)alpha ); + painter->currentBrush->setColor( c ); +} + +/* + * Class: gnu_java_awt_peer_qt_QtGraphics + * Method: drawNative + * Signature: (Lgnu/java/awt/peer/qt/QPainterPath;)V + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_drawNative +(JNIEnv *env, jobject obj, jobject path) +{ + GraphicsPainter *painter = (GraphicsPainter *)getPainter( env, obj ); + assert( painter ); + QPainterPath *pp = (QPainterPath *)getNativeObject( env, path ); + assert( pp ); + painter->setPen( *painter->currentPen ); + painter->setBrush( Qt::NoBrush ); + painter->drawPath( *pp ); +} + +/* + * Class: gnu_java_awt_peer_qt_QtGraphics + * Method: fillNative + * Signature: (Lgnu/java/awt/peer/qt/QPainterPath;)V + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_fillNative +(JNIEnv *env, jobject obj, jobject path) +{ + GraphicsPainter *painter = (GraphicsPainter *)getPainter( env, obj ); + assert( painter ); + QPainterPath *pp = (QPainterPath *)getNativeObject( env, path ); + assert( pp ); + + painter->setPen(Qt::NoPen); + painter->setBrush( *painter->currentBrush ); + painter->drawPath( *pp ); +} + +/** + * Draws a string. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_drawStringNative +(JNIEnv *env, jobject obj, jstring str, jdouble x, jdouble y) +{ + GraphicsPainter *painter = getPainter( env, obj ); + assert( painter ); + QString *qStr = getQString(env, str); + painter->setBrush( Qt::NoBrush ); + painter->setPen( *painter->currentPen ); + painter->drawText(QPointF( (qreal)x, (qreal)y ), *qStr); + delete qStr; +} + +/* + * Sets the native stroke + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_setNativeStroke +(JNIEnv *env, jobject obj, jobject stroke) +{ + GraphicsPainter *painter = (GraphicsPainter *)getPainter( env, obj ); + assert( painter ); + QPen *pen = (QPen *)getNativeObject(env, stroke); + assert( pen ); + painter->currentPen = new QPen( *pen ); + painter->setPen( *painter->currentPen ); +} + +/* + * Sets the transform + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_setQtTransform +(JNIEnv *env, jobject obj, jobject matrix) +{ + QPainter *painter = getPainter( env, obj ); + assert( painter ); + QMatrix *m = (QMatrix *)getNativeObject( env, matrix ); + assert( m ); + painter->setMatrix( *m ); +} + +/** + * Set the font + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_setFontNative +(JNIEnv *env, jobject obj, jobject fontpeer) +{ + QPainter *painter = getPainter( env, obj ); + assert( painter ); + QFont *font = (QFont *) getFont( env, fontpeer ); + assert( font ); + painter->setFont( *font ); +} + +/* + * Sets Porter-Duff compositing. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_setNativeComposite +(JNIEnv *env, jobject obj, jint compositeMode) +{ + QPainter *painter = getPainter( env, obj ); + assert( painter ); + QPainter::CompositionMode mode; + + switch( compositeMode ) + { + case CLEAR: + mode = QPainter::CompositionMode_Clear; + break; + case SRC: + mode = QPainter::CompositionMode_Source; + break; + case DST: + mode = QPainter::CompositionMode_Destination; + break; + case SRC_OVER: + mode = QPainter::CompositionMode_SourceOver; + break; + case DST_OVER: + mode = QPainter::CompositionMode_DestinationOver; + break; + case SRC_IN: + mode = QPainter::CompositionMode_SourceIn; + break; + case DST_IN: + mode = QPainter::CompositionMode_DestinationIn; + break; + case SRC_OUT: + mode = QPainter::CompositionMode_SourceOut; + break; + case DST_OUT: + mode = QPainter::CompositionMode_DestinationOut; + break; + case SRC_ATOP: + mode = QPainter::CompositionMode_SourceAtop; + break; + case DST_ATOP: + mode = QPainter::CompositionMode_DestinationAtop; + break; + case XOR: + mode = QPainter::CompositionMode_Xor; + break; + } + painter->setCompositionMode( mode ); +} + +/** + * Sets the current brush to a linear gradient. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_setLinearGradient +(JNIEnv *env, jobject obj, jint r1, jint g1, jint b1, jint r2, jint g2, +jint b2, jdouble x1, jdouble y1, jdouble x2, jdouble y2, jboolean cyclic) +{ + GraphicsPainter *painter = getPainter( env, obj ); + assert( painter ); + QLinearGradient *lg = new QLinearGradient(QPointF( (qreal)x1, (qreal)y1 ), + QPointF( (qreal)x2, (qreal)y2 ) ); + lg->setColorAt( (qreal)0.0, QColor(r1, g1, b1) ); + lg->setColorAt( (qreal)1.0, QColor(r2, g2, b2) ); + if( cyclic == JNI_TRUE ) + lg->setSpread( QGradient::ReflectSpread ); + else + lg->setSpread( QGradient::PadSpread ); + painter->currentBrush = new QBrush( *lg ); + delete lg; +} + +/* + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_fill3DRect +(JNIEnv *env, jobject obj, jint x, jint y, jint w, jint h, jboolean raised) +{ + GraphicsPainter *painter = getPainter( env, obj ); + assert( painter ); + // FIXME: Adjust colors + painter->fillRect ( x, y, w, h, QBrush( *painter->currentColor) ); + QPen *p = new QPen( *painter->currentColor ); + p->setWidth( 1 ); + painter->setPen( *p ); + painter->drawLine( x + w, y, x + w, y + h); + painter->drawLine( x, y + h, x + w, y + h); +} + +/* + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_draw3DRect +(JNIEnv *env, jobject obj, jint x, jint y, jint w, jint h, jboolean raised) +{ + GraphicsPainter *painter = getPainter( env, obj ); + assert( painter ); + // FIXME: Adjust colors + QPen *p = new QPen( *painter->currentColor ); + p->setWidth( 1 ); + painter->setPen( *p ); + painter->drawLine( x, y, x + w, y ); + painter->drawLine( x, y, x, y + h); + painter->drawLine( x + w, y, x + w, y + h); + painter->drawLine( x, y + h, x + w, y + h); +} diff --git a/libjava/classpath/native/jni/qt-peer/qtgraphics.h b/libjava/classpath/native/jni/qt-peer/qtgraphics.h new file mode 100644 index 000000000..5252897db --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qtgraphics.h @@ -0,0 +1,26 @@ +#ifndef QTGRAPHICS_H +#define QTGRAPHICS_H + +#include +#include +#include +#include +#include + +class GraphicsPainter : public QPainter +{ +public: + QPen *currentPen; + QBrush *currentBrush; + QColor *currentColor; + GraphicsPainter(QPaintDevice *dev) : QPainter( dev ) + { + currentPen = new QPen(); + currentBrush = new QBrush(); + currentColor = new QColor(); + } +}; + +GraphicsPainter *getPainter( JNIEnv *env, jobject obj ); + +#endif diff --git a/libjava/classpath/native/jni/qt-peer/qtimage.cpp b/libjava/classpath/native/jni/qt-peer/qtimage.cpp new file mode 100644 index 000000000..4d2b5b90a --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qtimage.cpp @@ -0,0 +1,401 @@ +/* qtimage.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include +#include +#include +#include "qtimage.h" +#include "qtstrings.h" +#include "qtgraphics.h" +#include "nativewrapper.h" + +/* The constant fields in java.awt.Image */ +#define SCALE_DEFAULT 1 +#define SCALE_FAST 2 +#define SCALE_SMOOTH 4 +#define SCALE_REPLICATE 8 +#define SCALE_AREA_AVERAGING 16 + +QImage *getQtImage( JNIEnv *env, jobject obj ) +{ + jclass cls = env->GetObjectClass( obj ); + jfieldID field = env->GetFieldID( cls, "nativeObject", "J" ); + return (QImage *)env->GetLongField( obj, field ); +} + +static void setNativePtr( JNIEnv *env, jobject obj, void *value ) +{ + jlong longValue = (jlong) value; + jclass cls = env->GetObjectClass( obj ); + jfieldID field = env->GetFieldID( cls, "nativeObject", "J" ); + env->SetLongField( obj, field, longValue ); +} + +/* + * Creates a QImage. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtImage_createImage +(JNIEnv *env, jobject obj) +{ + int width, height; + jclass cls; + jfieldID field; + + cls = env->GetObjectClass( obj ); + field = env->GetFieldID (cls, "width", "I"); + assert (field != 0); + width = env->GetIntField(obj, field); + + field = env->GetFieldID(cls, "height", "I"); + assert (field != 0); + height = env->GetIntField(obj, field); + + QImage *image = new QImage ( width, height, + QImage::Format_ARGB32_Premultiplied ); + setNativePtr(env, obj, image); +} + +/* + * Frees the image data. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtImage_freeImage +(JNIEnv *env, jobject obj) +{ + QImage *image = getQtImage(env, obj); + setNativePtr(env, obj, NULL); + if ( image ) + delete image; +} + +/* + * Clears the image to zero. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtImage_clear +(JNIEnv *env, jobject obj) +{ + QImage *image = getQtImage(env, obj); + assert( image ); + image->fill(0); +} + +/* + * Returns the pixel data in an int array. + */ +JNIEXPORT jintArray JNICALL Java_gnu_java_awt_peer_qt_QtImage_getPixels +(JNIEnv *env, jobject obj) +{ + QImage *image = getQtImage(env, obj); + jintArray result_array; + jint *result_array_ptr, *dst; + int x, y; + jint pixel; + QRgb current; + + assert( image ); + + result_array = env->NewIntArray (image->width() * image->height()); + dst = result_array_ptr = + env->GetIntArrayElements(result_array, NULL); + + // A bit inefficient. + for ( y = 0; y < image->height(); y++) + for ( x = 0; x < image->width(); x++) + { + current = image->pixel(x, y); + pixel = 0; + pixel = (qAlpha(current) & 0xFF) << 24 | + (qRed(current) & 0xFF) << 16 | + (qGreen(current) & 0xFF) << 8 | + (qBlue(current) & 0xFF); + *dst = pixel; + dst++; + } + + env->ReleaseIntArrayElements (result_array, result_array_ptr, 0); + return result_array; +} + +/* + * Sets the pixel data. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtImage_setPixels +(JNIEnv *env, jobject obj, jintArray pixels) +{ + QImage *image = getQtImage(env, obj); + assert( image ); + + int width, height; + jint *src_array, *src; + + width = image->width(); + height = image->height(); + + src = src_array = + env->GetIntArrayElements(pixels, NULL); + + for(int i = 0 ; i < height; i++) + { + uchar *scanline = image->scanLine( i ); + memcpy((void *)scanline, (void *)src, width * 4); + src += width; + } + + env->ReleaseIntArrayElements(pixels, src_array, 0); +} + + +/* + * Loads an image from a file, + * returns true on success, false on failure. + */ +JNIEXPORT jboolean JNICALL Java_gnu_java_awt_peer_qt_QtImage_loadImage +(JNIEnv *env, jobject obj, jstring fn) +{ + QString *filename = getQString(env, fn); + + QImage *image = new QImage(); + bool retVal = image->load( *filename ); + delete filename; + + if(image->isNull() && !retVal) + { + setNativePtr(env, obj, NULL); + return JNI_FALSE; + } + + setNativePtr(env, obj, image); + + jclass cls = env->GetObjectClass( obj ); + jfieldID field = env->GetFieldID( cls, "width", "I" ); + env->SetIntField( obj, field, image->width() ); + field = env->GetFieldID( cls, "height", "I" ); + env->SetIntField( obj, field, image->height() ); + + return JNI_TRUE; +} + +/* + * Creates the image from an array of java bytes. + */ +JNIEXPORT jboolean JNICALL Java_gnu_java_awt_peer_qt_QtImage_loadImageFromData +(JNIEnv *env, jobject obj, jbyteArray data) +{ + jbyte *src_array, *src; + bool retVal; + + src = env->GetByteArrayElements(data, NULL); + int len = env->GetArrayLength( data ); + + QImage *image = new QImage(); + retVal = image->loadFromData( (uchar *) src, len); + env->ReleaseByteArrayElements(data, src, 0); + + if(image->isNull() || retVal == false) + { + setNativePtr(env, obj, NULL); + return JNI_FALSE; + } + + setNativePtr(env, obj, image); + + jclass cls = env->GetObjectClass( obj ); + jfieldID field = env->GetFieldID( cls, "width", "I" ); + env->SetIntField( obj, field, image->width() ); + field = env->GetFieldID( cls, "height", "I" ); + env->SetIntField( obj, field, image->height() ); + + return JNI_TRUE; +} + + +/* + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtImage_createScaledImage +(JNIEnv *env, jobject obj, jobject src, jint hints) +{ + int w,h; + jclass cls; + jfieldID field; + + cls = env->GetObjectClass( obj ); + field = env->GetFieldID(cls, "width", "I"); + assert (field != 0); + w = env->GetIntField(obj, field); + + field = env->GetFieldID(cls, "height", "I"); + assert (field != 0); + h = env->GetIntField(obj, field); + + QImage *image = getQtImage(env, src); + assert( image ); + QImage imageScaled; + + if (hints == SCALE_SMOOTH || hints == SCALE_AREA_AVERAGING) + imageScaled = image->scaled(w, h, + Qt::IgnoreAspectRatio, + Qt::SmoothTransformation); + else + imageScaled = image->scaled(w, h, + Qt::IgnoreAspectRatio, + Qt::FastTransformation); + QImage *scaledPtr = new QImage( imageScaled ); + + // create new QtImage object + setNativePtr( env, obj, scaledPtr ); +} + +/* + * Simple draw without scaling. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtImage_drawPixels +(JNIEnv *env, jobject obj, jobject graphics, jint bg_red, jint bg_green, + jint bg_blue, jint x, jint y, jboolean composite) +{ + QImage *image = getQtImage(env, obj); + assert( image ); + QPainter *painter = getPainter( env, graphics ); + assert( painter ); + if(composite == JNI_TRUE) + painter->fillRect ( x, y, image->width(), image->height(), + QColor(bg_red, bg_green, bg_blue ) ); + painter->drawImage ( QPoint(x, y), *image ); +} + +/* + * Draw the image with scaling. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtImage_drawPixelsScaled +(JNIEnv *env, jobject obj, jobject graphics, + jint bg_red, jint bg_green, jint bg_blue, + jint x, jint y, jint w, jint h, jboolean composite) +{ + QImage *image = getQtImage(env, obj); + assert( image ); + QPainter *painter = getPainter( env, graphics ); + assert( painter ); + + if(composite == JNI_TRUE) + painter->fillRect ( x, y, w, h, QColor(bg_red, bg_green, bg_blue ) ); + + QRectF *srcRect = new QRectF((qreal)0, (qreal)0, + (qreal)image->width(), (qreal)image->height()); + QRectF *dstRect = new QRectF((qreal)x, (qreal)y, + (qreal)w, (qreal)h); + + if(composite == JNI_TRUE) + painter->fillRect( *dstRect, QColor(bg_red, bg_green, bg_blue ) ); + + painter->drawImage( *dstRect, *image, *srcRect); + + delete srcRect; + delete dstRect; +} + +/* + * Draws a transformed image. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtImage_drawPixelsTransformed +(JNIEnv *env, jobject obj, jobject graphics, jobject transform) +{ + QImage *originalImage = getQtImage(env, obj); + assert( originalImage ); + QPainter *painter = getPainter( env, graphics ); + assert( painter ); + QMatrix *matrix = (QMatrix *)getNativeObject(env, transform); + assert( matrix ); + + // FIXME : Add rendering hint support here. + QPoint p = matrix->map( QPoint(0,0) ); + QImage image = originalImage->transformed ( *matrix, Qt::FastTransformation ); + painter->drawImage(p, image); +} + +/** + * Draws the pixbuf at x, y, scaled to width and height and + * optionally composited and/or flipped with a given background color. + */ +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_qt_QtImage_drawPixelsScaledFlipped +(JNIEnv *env, jobject obj, jobject graphics, + jint bg_red, jint bg_green, jint bg_blue, + jboolean flipx, jboolean flipy, + jint srcx, jint srcy, jint srcwidth, jint srcheight, + jint dstx, jint dsty, jint dstwidth, jint dstheight, + jboolean composite) +{ + QImage *originalImage = getQtImage(env, obj); + assert( originalImage ); + QPainter *painter = getPainter( env, graphics ); + assert( painter ); + + QRectF *srcRect = new QRectF((qreal)srcx, (qreal)srcy, + (qreal)srcwidth, (qreal)srcheight); + QRectF *dstRect = new QRectF((qreal)dstx, (qreal)dsty, + (qreal)dstwidth, (qreal)dstheight); + + QImage image; + if( flipx == JNI_TRUE || flipy == JNI_TRUE) + image = originalImage->mirrored ( (flipx == JNI_TRUE), + (flipy == JNI_TRUE) ); + else + image = *originalImage; + + if(composite == JNI_TRUE) + painter->fillRect( *dstRect, QColor(bg_red, bg_green, bg_blue ) ); + + painter->drawImage( *dstRect, image, *srcRect); + + delete srcRect; + delete dstRect; +} + +/** + * Copies an area of the image (used by Graphics) + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtImage_copyArea +(JNIEnv *env, jobject obj , jint x, jint y, jint w, jint h, jint dx, jint dy) +{ + QImage *image = getQtImage(env, obj); + assert( image ); + QImage area = image->copy(x, y, w, h); + QPainter *p = new QPainter( image ); + p->drawImage( x + dx, y + dy, area ); + delete p; +} diff --git a/libjava/classpath/native/jni/qt-peer/qtimage.h b/libjava/classpath/native/jni/qt-peer/qtimage.h new file mode 100644 index 000000000..8772086ce --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qtimage.h @@ -0,0 +1,10 @@ +#ifndef QTIMAGE_H +#define QTIMAGE_H + +#include +#include + +QImage *getQtImage( JNIEnv *env, jobject obj ); +QPixmap *getQtVolatileImage( JNIEnv *env, jobject obj ); + +#endif diff --git a/libjava/classpath/native/jni/qt-peer/qtlabelpeer.cpp b/libjava/classpath/native/jni/qt-peer/qtlabelpeer.cpp new file mode 100644 index 000000000..6cbadece6 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qtlabelpeer.cpp @@ -0,0 +1,151 @@ +/* qtlabelpeer.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include +#include "qtcomponent.h" +#include "qtstrings.h" +#include "mainthreadinterface.h" +#include "keybindings.h" + +// java.awt.Label justification fields +#define LEFT 0 +#define CENTER 1 +#define RIGHT 2 + +class MyLabel : public QLabel +{ +public: + MyLabel(JNIEnv *env, jobject obj, QWidget *parent) : QLabel( parent ) + { + setup(env, obj); + } + + ~MyLabel() + { + destroy(); + } + +#define I_KNOW_WHAT_IM_DOING +#define PARENT QLabel +#include "eventmethods.h" +}; + +class LabelTitle : public AWTEvent { + + private: + QLabel *widget; + QString *string; + Qt::Alignment alignment; + + public: + LabelTitle(QLabel *w, QString *s, Qt::Alignment a) : AWTEvent() + { + widget = w; + string = s; + alignment = a; + } + + void runEvent() + { + if( string != NULL) + { + widget->setText( *string ); + delete string; + } + else + { + widget->setAlignment( alignment ); + } + } +}; + +/* + * Init a QLabel + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtLabelPeer_init +(JNIEnv *env, jobject obj) +{ + QWidget *parentWidget = (QWidget *) getParentWidget( env, obj ); + QLabel *label = new MyLabel( env, obj, parentWidget ); + assert( label ); + setNativeObject( env, obj, label ); +} + +/* + * Sets the text + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtLabelPeer_setText +(JNIEnv *env, jobject obj, jstring str) +{ + QLabel *label = (QLabel *) getNativeObject( env, obj ); + assert( label ); + + QString *qStr = getQString(env, str); + mainThread->postEventToMain( new LabelTitle( label, qStr, 0 ) ); +} + +/* + * Sets the alignment + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtLabelPeer_setAlignment +(JNIEnv *env, jobject obj, jint align) +{ + Qt::Alignment alignment = Qt::AlignVCenter; + + QLabel *label = (QLabel *) getNativeObject( env, obj ); + assert( label ); + + switch(align) + { + case LEFT: + alignment |= Qt::AlignLeft; + break; + + case RIGHT: + alignment |= Qt::AlignRight; + break; + + default: + case CENTER: + alignment |= Qt::AlignHCenter; + break; + } + mainThread->postEventToMain( new LabelTitle( label, NULL, alignment ) ); +} diff --git a/libjava/classpath/native/jni/qt-peer/qtlistpeer.cpp b/libjava/classpath/native/jni/qt-peer/qtlistpeer.cpp new file mode 100644 index 000000000..027d47880 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qtlistpeer.cpp @@ -0,0 +1,210 @@ +/* qtlistpeer.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include +#include "qtcomponent.h" +#include "qtstrings.h" +#include "mainthreadinterface.h" +#include "slotcallbacks.h" + +class ListInsert : public AWTEvent { + + private: + QListWidget *widget; + QString *string; + int index; + + public: + ListInsert(QListWidget *w, QString *s, int i) : AWTEvent() + { + widget = w; + string = s; + index = i; + } + + void runEvent() + { + widget->insertItem( index, *string ); + delete string; + } +}; + +class SelectEvent : public AWTEvent { + + private: + QListWidget *widget; + int index; + bool selected; + + public: + SelectEvent(QListWidget *w, int i, bool s) : AWTEvent() + { + widget = w; + index = i; + selected = s; + } + + void runEvent() + { + widget->setItemSelected ( widget->item(index), selected ); + } +}; + +class ListDelete : public AWTEvent { + + private: + QListWidget *widget; + int startIndex, endIndex; + + public: + ListDelete(QListWidget *w, int starti, int endi) : AWTEvent() + { + widget = w; + startIndex = starti; + endIndex = endi; + } + + void runEvent() + { + for (int i = endIndex; i >= startIndex; i--) + delete widget->takeItem(i); + } +}; + +/* + * Construct a QListWidget object + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtListPeer_init +(JNIEnv *env, jobject obj) +{ + QWidget *parentWidget = (QWidget *)getParentWidget(env, obj); + assert( parentWidget ); + QListWidget *list = new QListWidget( parentWidget ); + assert( list ); + + setNativeObject( env, obj, list ); + connectList(list, env, obj); +} + +/* + * Adds an element. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtListPeer_add +(JNIEnv *env, jobject obj, jstring str, jint index) +{ + QListWidget *list = (QListWidget *) getNativeObject( env, obj ); + assert( list ); + QString *qStr = getQString(env, str); + mainThread->postEventToMain( new ListInsert(list, qStr, index) ); +} + +/* + * Delete items + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtListPeer_delItems +(JNIEnv *env, jobject obj, jint startindex, jint endindex) +{ + QListWidget *list = (QListWidget *) getNativeObject( env, obj ); + assert( list ); + mainThread->postEventToMain( new ListDelete(list, startindex, endindex) ); +} + +/* + * (De)select an element. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtListPeer_select +(JNIEnv *env, jobject obj, jint index, jboolean sel) +{ + QListWidget *list = (QListWidget *) getNativeObject( env, obj ); + assert( list ); + + mainThread->postEventToMain( new SelectEvent(list, index, + (sel == JNI_TRUE)) ); +} + +/** + * Returns the indices of the selected items. + */ +JNIEXPORT jintArray JNICALL Java_gnu_java_awt_peer_qt_QtListPeer_getSelectedIndexes + (JNIEnv *env, jobject obj) +{ + jintArray retArray; + jint *arr; + + QListWidget *list = (QListWidget *) getNativeObject( env, obj ); + assert( list ); + + QList items = list->selectedItems(); + retArray = env->NewIntArray( items.count() ); + arr = env->GetIntArrayElements( retArray, NULL ); + + for(int i = 0; i < items.count(); i++) + arr[i] = list->row(items.at(i)); + + env->ReleaseIntArrayElements( retArray, arr, 0 ); + return retArray; +} + +/* + * Sets the current item and makes it visible. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtListPeer_makeVisible + (JNIEnv *env, jobject obj, jint index) +{ + + QListWidget *list = (QListWidget *) getNativeObject( env, obj ); + assert( list ); + + list->scrollToItem( list->item(index) ); +} + +/* + * Set multiple selection mode. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtListPeer_setMultipleMode +(JNIEnv *env, jobject obj, jboolean allow) +{ + QListWidget *list = (QListWidget *) getNativeObject( env, obj ); + assert( list ); + + // FIXME: Multiple selection is buggy in Qt4. Workaround needed. + list->setSelectionMode( ((allow == JNI_TRUE) ? QAbstractItemView::MultiSelection : QAbstractItemView::SingleSelection) ); +} + diff --git a/libjava/classpath/native/jni/qt-peer/qtmenubarpeer.cpp b/libjava/classpath/native/jni/qt-peer/qtmenubarpeer.cpp new file mode 100644 index 000000000..2c855773e --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qtmenubarpeer.cpp @@ -0,0 +1,150 @@ +/* qtmenubarpeer.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include +#include +#include +#include +#include "nativewrapper.h" +#include "qtstrings.h" +#include "mainthreadinterface.h" + +/* + * Event wrapper to add a menu to a menu bar + */ +class MenuBarAdd : public AWTEvent { + + private: + QMenuBar *widget; + QMenu *menu; + bool isHelp; + + public: + MenuBarAdd(QMenuBar *w, QMenu *m, bool help) : AWTEvent() + { + widget = w; + menu = m; + isHelp = help; + } + + void runEvent() + { + if ( isHelp ) + widget->addSeparator(); + QAction *ptr = widget->addMenu( menu ); + } +}; + +/** + * Event wrapper to remove a menu from a menu bar. + */ +class MenuBarRemove : public AWTEvent { + + private: + QMenuBar *widget; + QMenu *menu; + + public: + MenuBarRemove(QMenuBar *w, QMenu *m) : AWTEvent() + { + widget = w; + menu = m; + } + + void runEvent() + { + // FIXME + } +}; + + +/* + * Constructs a QMenuBar object. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuBarPeer_init + (JNIEnv *env, jobject obj) +{ + QMenuBar *menubar = new QMenuBar(); + assert( menubar ); + setNativeObject( env, obj, menubar ); +} + +/* + * Adds a menu item. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuBarPeer_addMenu +(JNIEnv *env, jobject obj, jobject menuPeer) +{ + QMenuBar *menubar = (QMenuBar *)getNativeObject(env, obj); + assert( menubar ); + QMenu *menu = (QMenu *)getNativeObject(env, menuPeer); + assert( menu ); + mainThread->postEventToMain( new MenuBarAdd( menubar, menu, false ) ); +} + +/* + * Add a help menu. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuBarPeer_addHelpMenu +(JNIEnv *env, jobject obj, jobject menuPeer) +{ + QMenuBar *menubar = (QMenuBar *)getNativeObject(env, obj); + assert( menubar ); + QMenu *menu = (QMenu *)getNativeObject(env, menuPeer); + assert( menu ); + + mainThread->postEventToMain( new MenuBarAdd( menubar, menu, true ) ); +} + +/* + * Delete a menu. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuBarPeer_delMenu +(JNIEnv *env, jobject obj, jobject menuPeer) +{ + QMenuBar *menubar = (QMenuBar *)getNativeObject(env, obj); + assert( menubar ); + QMenu *menu = (QMenu *)getNativeObject(env, menuPeer); + assert( menu ); + + // FIXME + +} + diff --git a/libjava/classpath/native/jni/qt-peer/qtmenucomponentpeer.cpp b/libjava/classpath/native/jni/qt-peer/qtmenucomponentpeer.cpp new file mode 100644 index 000000000..c924bcc91 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qtmenucomponentpeer.cpp @@ -0,0 +1,66 @@ +/* qtmenucomponentpeer.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include "nativewrapper.h" +#include "componentevent.h" + + +/** + * Calls back init() from the main thread. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuComponentPeer_callInit +(JNIEnv *env, jobject obj) +{ + mainThread->postEventToMain( new AWTInitEvent( env, obj ) ); + // wait for the thing to be created. +} + +/* + * Generic disposal. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuComponentPeer_dispose +(JNIEnv *env, jobject obj) +{ + QWidget *widget = (QWidget *) getNativeObject( env, obj ); + assert( widget ); + + setNativeObject(env, obj, NULL); + mainThread->postEventToMain( new AWTDestroyEvent( widget ) ); +} diff --git a/libjava/classpath/native/jni/qt-peer/qtmenuitempeer.cpp b/libjava/classpath/native/jni/qt-peer/qtmenuitempeer.cpp new file mode 100644 index 000000000..0d0b92e19 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qtmenuitempeer.cpp @@ -0,0 +1,182 @@ +/* qtmenuitempeer.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include +#include +#include "nativewrapper.h" +#include "qtstrings.h" +#include "mainthreadinterface.h" + +class MenuItemDestroyEvent : public AWTEvent { + + private: + QAction *widget; + + public: + MenuItemDestroyEvent(QAction *w) + { + widget = w; + } + + void runEvent() + { + delete widget; + } +}; + +class MenuItemLabelEvent : public AWTEvent { + + private: + QAction *widget; + QString *string; + + public: + MenuItemLabelEvent(QAction *w, QString *s) : AWTEvent() + { + widget = w; + string = s; + } + + void runEvent() + { + widget->setText( *string ); + delete string; + } +}; + +class MenuItemStatusEvent : public AWTEvent { + + private: + QAction *widget; + bool enabled; + bool value; + + public: + MenuItemStatusEvent(QAction *w, bool e, bool v) : AWTEvent() + { + widget = w; + enabled = e; + value = v; + } + + void runEvent() + { + if( enabled ) + widget->setEnabled( value ); + else + widget->setChecked( value ); + } +}; + +/* + * Creates a QAction object + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuItemPeer_create +(JNIEnv *env, jobject obj, jstring label, jboolean isSeperator, jboolean isCheckable) +{ + QAction *action; + if(label == NULL || isSeperator == JNI_TRUE) + { + action = new QAction(NULL); + action->setSeparator(true); + assert( action ); + } + else + { + QString *qStr = getQString(env, label); + action = new QAction(*qStr, NULL); + delete qStr; + assert( action ); + action->setCheckable( (isCheckable == JNI_TRUE) ); + } + + setNativeObject( env, obj, action ); +} + +/** + * Disposal. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuItemPeer_dispose +(JNIEnv *env, jobject obj) +{ + QAction *action = (QAction *)getNativeObject( env, obj ); + assert( action ); + mainThread->postEventToMain( new MenuItemDestroyEvent( action ) ); +} + +/* + * Enables/disables the item + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuItemPeer_setEnabled +(JNIEnv *env, jobject obj, jboolean enabled) +{ + QAction *action = (QAction *)getNativeObject( env, obj ); + assert( action ); + mainThread->postEventToMain(new MenuItemStatusEvent(action, true, + (enabled == JNI_TRUE))); +} + +/* + * Sets the item label. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuItemPeer_setLabel +(JNIEnv *env, jobject obj, jstring label) +{ + QAction *action = (QAction *)getNativeObject( env, obj ); + assert( action ); + + QString *qStr = getQString(env, label); + mainThread->postEventToMain( new MenuItemLabelEvent( action, qStr ) ); +} + +/* + * Sets the checkbox state. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuItemPeer_setState +(JNIEnv *env, jobject obj, jboolean state) +{ + QAction *action = (QAction *)getNativeObject( env, obj ); + assert( action ); + mainThread->postEventToMain(new MenuItemStatusEvent(action, false, + (state == JNI_TRUE))); +} + + + diff --git a/libjava/classpath/native/jni/qt-peer/qtmenupeer.cpp b/libjava/classpath/native/jni/qt-peer/qtmenupeer.cpp new file mode 100644 index 000000000..6f35c89b9 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qtmenupeer.cpp @@ -0,0 +1,254 @@ +/* qtmenupeer.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include "nativewrapper.h" +#include "qtstrings.h" +#include "mainthreadinterface.h" +#include "slotcallbacks.h" +#include "componentevent.h" + +typedef enum ActionType { + ActionMenu, + ActionItem, + ActionSeparator +} ActionType; + +// Sets the title, but also tear-off. +class MenuTitleEvent : public AWTEvent { + + private: + QMenu *widget; + QString *string; + bool tearOff; + + public: + MenuTitleEvent(QMenu *w, QString *s, bool tear) : AWTEvent() + { + widget = w; + string = s; + tearOff = tear; + } + + void runEvent() + { + if (tearOff) + widget->setTearOffEnabled( true ); + else + { + widget->setTitle( *string ); + delete string; + } + } +}; + +class MenuAction : public AWTEvent { + + private: + QMenu *menu; + QAction *action; + ActionType actionType; // type of action to add + JavaVM *vm; + jobject menuPeer; + jobject itemPeer; + +public: + MenuAction(JNIEnv *env, jobject mp, jobject ip, QMenu *m, QAction *a, + ActionType actionType) : AWTEvent() + { + menu = m; + action = a; + this->actionType = actionType; + env->GetJavaVM( &vm ); + menuPeer = env->NewGlobalRef( mp ); + if( ip != NULL ) + itemPeer = env->NewGlobalRef( ip ); + else + itemPeer = NULL; + } + + void runEvent() + { + JNIEnv *env; + vm->GetEnv((void **)&env, JNI_VERSION_1_1); + if (actionType == ActionMenu) + menu->addMenu ((QMenu *) action); + else + menu->addAction (action); + + jclass menuCls = env->GetObjectClass( menuPeer ); + jmethodID mid = env->GetMethodID(menuCls, "add", "(J)V"); + env->DeleteLocalRef(menuCls); + env->CallVoidMethod( menuPeer, mid, (jlong)action ); + + env->DeleteGlobalRef( menuPeer ); + if( itemPeer != NULL ) + { + setNativeObject( env, itemPeer, action ); + connectAction(action, env, itemPeer); + env->DeleteGlobalRef( itemPeer ); + } + } +}; + +class MenuRemoveAction : public AWTEvent { + + private: + QMenu *menu; + QAction *action; + +public: + MenuRemoveAction(QMenu *m, QAction *a) : AWTEvent() + { + menu = m; + action = a; + } + + void runEvent() + { + if (action) + menu->removeAction(action); + } +}; + +/* + * Constructs a QMenu item + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuPeer_init +(JNIEnv *env, jobject obj) +{ + QMenu *menu = new QMenu(); + assert( menu ); + + setNativeObject( env, obj, menu ); +} + +/** + * Allows tear-off: Only called once, if ever. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuPeer_allowTearOff +(JNIEnv *env, jobject obj) +{ + QMenu *menu = (QMenu *)getNativeObject( env, obj ); + assert( menu ); + mainThread->postEventToMain( new MenuTitleEvent( menu, NULL, true ) ); +} + +/* + * Inserts a seperator. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuPeer_insertSeperator +(JNIEnv *env, jobject obj) +{ + QMenu *menu = (QMenu *)getNativeObject( env, obj ); + assert( menu ); + mainThread->postEventToMain( new MenuAction( env, obj, NULL, + menu, NULL, ActionSeparator ) ); +} + +/* + * Inserts an item. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuPeer_insertItem +(JNIEnv *env, jobject obj, jobject item) +{ + QMenu *menu = (QMenu *)getNativeObject( env, obj ); + assert( menu ); + + QAction *action = (QAction *)getNativeObject( env, item ); + assert( action ); + + mainThread->postEventToMain( new MenuAction( env, obj, item, menu, action, ActionItem )); +} + +/* + * Inserts a sub-menu + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuPeer_insertMenu +(JNIEnv *env, jobject obj, jobject menu) +{ + assert( menu ); + QMenu *thisMenu = (QMenu *)getNativeObject( env, obj ); + assert( thisMenu ); + QMenu *insMenu = (QMenu *)getNativeObject(env, menu); + assert( insMenu ); + + mainThread->postEventToMain( new MenuAction( env, obj, menu, thisMenu, (QAction *)insMenu, ActionMenu ) ); +} + +/* + * Removes an item at index. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuPeer_delItem +(JNIEnv *env, jobject obj, jlong ptr) +{ + QMenu *menu = (QMenu *)getNativeObject( env, obj ); + assert( menu ); + QAction *action = (QAction *)ptr; + + mainThread->postEventToMain( new MenuRemoveAction( menu, action ) ); +} + +/* + * Enables/Disables the menu. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuPeer_setEnabled +(JNIEnv *env, jobject obj, jboolean enabled) +{ + QMenu *menu = (QMenu *)getNativeObject( env, obj ); + assert( menu ); + + mainThread->postEventToMain(new AWTEnableEvent(menu, (enabled == JNI_TRUE))); +} + +/* + * Sets the menu title. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuPeer_setLabel +(JNIEnv *env, jobject obj, jstring label) +{ + if(label == NULL) + return; + + QMenu *menu = (QMenu *)getNativeObject( env, obj ); + assert( menu ); + QString *qStr = getQString(env, label); + mainThread->postEventToMain( new MenuTitleEvent( menu, qStr, false ) ); +} + diff --git a/libjava/classpath/native/jni/qt-peer/qtpanelpeer.cpp b/libjava/classpath/native/jni/qt-peer/qtpanelpeer.cpp new file mode 100644 index 000000000..68aef4864 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qtpanelpeer.cpp @@ -0,0 +1,77 @@ +/* qtpanelpeer.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include "qtcomponent.h" +#include "keybindings.h" + +class MyPanel : public QWidget +{ +public: + MyPanel(JNIEnv *env, jobject obj, QWidget *parent) : QWidget( parent ) + { + setup(env, obj); + } + + ~MyPanel() + { + destroy(); + } + +#define I_KNOW_WHAT_IM_DOING +#define PARENT QWidget +#include "eventmethods.h" +#undef I_KNOW_WHAT_IM_DOING +#undef PARENT +}; + +/** + * Init + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtPanelPeer_init +(JNIEnv *env, jobject obj) +{ + QWidget *parentWidget = (QWidget *) getParentWidget( env, obj ); + QWidget *canvas = new MyPanel( env, obj, parentWidget ); + assert( canvas ); + + setNativeObject( env, obj, canvas ); +} + + diff --git a/libjava/classpath/native/jni/qt-peer/qtpopupmenupeer.cpp b/libjava/classpath/native/jni/qt-peer/qtpopupmenupeer.cpp new file mode 100644 index 000000000..56784a591 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qtpopupmenupeer.cpp @@ -0,0 +1,76 @@ +/* qtpopupmenupeer.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include +#include +#include "nativewrapper.h" +#include "qtstrings.h" +#include "mainthreadinterface.h" + +class PopupMenuShowEvent : public AWTEvent { + + private: + QMenu *menu; + int x, y; + + public: + PopupMenuShowEvent(QMenu *m, int x0, int y0) : AWTEvent() + { + menu = m; + x = x0; + y = y0; + } + + void runEvent() + { + menu->exec( QPoint( x, y ) ); + } +}; + +/* + * Shows the menu. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtPopupMenuPeer_showNative +(JNIEnv *env, jobject obj, jint x, jint y) +{ + QMenu *menu = (QMenu *)getNativeObject( env, obj ); + assert( menu ); + mainThread->postEventToMain( new PopupMenuShowEvent(menu, x, y ) ); +} diff --git a/libjava/classpath/native/jni/qt-peer/qtscreendevice.cpp b/libjava/classpath/native/jni/qt-peer/qtscreendevice.cpp new file mode 100644 index 000000000..c5cc2fe37 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qtscreendevice.cpp @@ -0,0 +1,123 @@ +/* qtscreendevice.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include +#include "nativewrapper.h" + +extern QApplication *qApplication; + +/* + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtScreenDevice_init +(JNIEnv *env, jobject obj, jint id) +{ + QWidget *widget = qApplication->desktop()->screen( id ); + assert( widget ); + setNativeObject(env, obj, widget); +} + +/* + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtScreenDevice_dispose +(JNIEnv *env, jobject obj) +{ + QWidget *widget = (QWidget *)getNativeObject(env, obj); + setNativeObject(env, obj, NULL); + if( widget ) + delete widget; +} + +/* + * Returns the bounds + */ +JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QtScreenDevice_getBounds +(JNIEnv *env, jobject obj) +{ + QWidget *widget = (QWidget *)getNativeObject(env, obj); + assert( widget ); + + jclass cls = env->FindClass("java/awt/Rectangle"); + jmethodID mid = env->GetMethodID(cls, "", "(IIII)V"); + jvalue values[4]; + + int x,y,w,h; + widget->geometry().getRect( &x, &y, &w, &h ); + + values[0].i = (jint) x; + values[1].i = (jint) y; + values[2].i = (jint) w; + values[3].i = (jint) h; + + return env->NewObjectA(cls, mid, values); +} + +/* + * Returns the X DPI + */ +JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtScreenDevice_getDpiX +(JNIEnv *env, jobject obj) +{ + QWidget *widget = (QWidget *)getNativeObject(env, obj); + assert( widget ); + return widget->logicalDpiX(); +} + +/* + * Returns the Y DPI + */ +JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtScreenDevice_getDpiY +(JNIEnv *env, jobject obj) +{ + QWidget *widget = (QWidget *)getNativeObject(env, obj); + assert( widget ); + return widget->logicalDpiY(); +} + +/* + * Returns the bitplane depth + */ +JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtScreenDevice_depth +(JNIEnv *env, jobject obj) +{ + QWidget *widget = (QWidget *)getNativeObject(env, obj); + assert( widget ); + return widget->depth(); +} + diff --git a/libjava/classpath/native/jni/qt-peer/qtscrollbarpeer.cpp b/libjava/classpath/native/jni/qt-peer/qtscrollbarpeer.cpp new file mode 100644 index 000000000..0649ebd17 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qtscrollbarpeer.cpp @@ -0,0 +1,142 @@ +/* qtscrollbarpeer.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include "keybindings.h" +#include "slotcallbacks.h" +#include "qtcomponent.h" + +// Constant fields from java.awt.Scrollbar +#define HORIZONTAL 0 +#define VERTICAL 1 + +class MyScrollBar : public QScrollBar +{ +public: + MyScrollBar(JNIEnv *env, jobject obj, QWidget *parent) : QScrollBar( parent ) + { + setup(env, obj); + } + + ~MyScrollBar() + { + destroy(); + } + +#define I_KNOW_WHAT_IM_DOING +#define PARENT QScrollBar +#include "eventmethods.h" +}; + +/* + * Construct a QScrollbar object + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtScrollbarPeer_init +(JNIEnv *env, jobject obj) +{ + QWidget *parentWidget = (QWidget *)getParentWidget( env, obj ); + assert( parentWidget ); + // QScrollBar *scrollbar = new QScrollBar( parentWidget ); + MyScrollBar *scrollbar = new MyScrollBar( env, obj, parentWidget ); + assert( scrollbar ); + + setNativeObject( env, obj, scrollbar ); + connectScrollBar(scrollbar, env, obj); +} + +/* + * Set the line increment. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtScrollbarPeer_setLineIncrement +(JNIEnv *env, jobject obj, jint inc) +{ + QScrollBar *bar = (QScrollBar *) getNativeObject( env, obj ); + assert( bar ); + + bar->setSingleStep(inc); +} + +/** + * Sets the orientation of the scrollbar + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtScrollbarPeer_setOrientation +(JNIEnv *env, jobject obj, jint orientation) +{ + QScrollBar *bar = (QScrollBar *) getNativeObject( env, obj ); + assert( bar ); + + switch(orientation) + { + case HORIZONTAL: + bar->setOrientation ( Qt::Horizontal ); + break; + + default: + case VERTICAL: + bar->setOrientation ( Qt::Vertical ); + break; + } +} + +/** + * Sets the page increment (equivalent to slider size) + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtScrollbarPeer_setPageIncrement +(JNIEnv *env, jobject obj, jint inc) +{ + QScrollBar *bar = (QScrollBar *) getNativeObject( env, obj ); + assert( bar ); + + bar->setPageStep( inc ); +} + +/* + * Setvalues. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtScrollbarPeer_setValues +(JNIEnv *env, jobject obj, jint value, jint visible, jint min, jint max) +{ + QScrollBar *bar = (QScrollBar *) getNativeObject( env, obj ); + assert( bar ); + + bar->setValue(value); + bar->setPageStep( visible ); // page step and slider size are the same in Qt + bar->setRange( min , max ); +} + diff --git a/libjava/classpath/native/jni/qt-peer/qtscrollpanepeer.cpp b/libjava/classpath/native/jni/qt-peer/qtscrollpanepeer.cpp new file mode 100644 index 000000000..b7bf64a90 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qtscrollpanepeer.cpp @@ -0,0 +1,214 @@ +/* qtscrollpanepeer.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include +#include "qtcomponent.h" +#include "containers.h" +#include "mainthreadinterface.h" +#include "componentevent.h" +#include "keybindings.h" + +// Constants in java.awt.ScrollPane +#define SCROLLBARS_AS_NEEDED 0 +#define SCROLLBARS_ALWAYS 1 +#define SCROLLBARS_NEVER 2 + + +class MyScrollArea : public QScrollArea +{ +public: + MyScrollArea(JNIEnv *env, jobject obj, QWidget *parent) : QScrollArea( parent ) + { + setup(env, obj); + } + + ~MyScrollArea() + { + destroy(); + } + +#define I_KNOW_WHAT_IM_DOING +#define PARENT QScrollArea +#include "eventmethods.h" +}; + + +class ScrollPanePolicy : public AWTEvent { + + private: + QScrollArea *widget; + Qt::ScrollBarPolicy policy; + + public: + ScrollPanePolicy(QScrollArea *w, Qt::ScrollBarPolicy p) : AWTEvent() + { + widget = w; + policy = p; + } + + void runEvent() + { + widget->setHorizontalScrollBarPolicy(policy); + widget->setVerticalScrollBarPolicy(policy); + } +}; + +/** + * Returns the child widget, given the owner Component. + */ +QWidget *scrollPaneChildWidget( JNIEnv *env, jobject component ) +{ + jclass scrollpaneCls = env->FindClass( "java/awt/ScrollPane" ); + jmethodID getPeerMID = env->GetMethodID( scrollpaneCls, + "getPeer", + "()Ljava/awt/peer/ComponentPeer;"); + assert(getPeerMID != 0); + jobject scrollpanepeerobj = env->CallObjectMethod( component, getPeerMID, NULL ); + QScrollArea *view = (QScrollArea *) getNativeObject( env, scrollpanepeerobj ); + assert(view != 0); + return view->viewport(); +} + +/* + * Creates a QScrollArea object. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtScrollPanePeer_init +(JNIEnv *env, jobject obj) +{ + QWidget *parentWidget = (QWidget *) getParentWidget( env, obj ); + assert( parentWidget ); + // QScrollArea *pane = new MyScrollArea( env, obj, parentWidget ); + QScrollArea *pane = new QScrollArea( parentWidget ); + assert( pane ); + setNativeObject( env, obj, pane ); +} + +/* + * Resize the child. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtScrollPanePeer_childResized +(JNIEnv *env, jobject obj, jint w, jint h) +{ + QScrollArea *view = (QScrollArea *) getNativeObject( env, obj ); + assert( view ); + + QWidget *child = view->viewport(); + assert( child ); + // child->setGeometry( 0, 0, w, h ); +// child->update(); + mainThread->postEventToMain( new AWTResizeEvent(child, 0, 0, w, h) ); +} + +/* + * Returns the horizontal scrollbar height. + */ +JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtScrollPanePeer_getHScrollbarHeight +(JNIEnv *env, jobject obj) +{ + QScrollArea *pane = (QScrollArea *) getNativeObject( env, obj ); + assert( pane ); + QScrollBar *hbar = pane->horizontalScrollBar(); + if(hbar == NULL) + return 0; + if(!hbar->isVisible()) + return 0; + int height = hbar->height(); + + return height; +} + +/* + * Returns the vertical scrollbar width. + */ +JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtScrollPanePeer_getVScrollbarWidth +(JNIEnv *env, jobject obj) +{ + QScrollArea *pane = (QScrollArea *) getNativeObject( env, obj ); + assert( pane ); + QScrollBar *vbar = pane->verticalScrollBar(); + if(vbar == NULL) + return 0; + if(!vbar->isVisible()) + return 0; + int width = vbar->width(); + + return width; +} + +/* + * Sets the current upper-left corner to x, y. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtScrollPanePeer_setScrollPosition +(JNIEnv *env, jobject obj, jint x, jint y) +{ + QScrollArea *pane = (QScrollArea *) getNativeObject( env, obj ); + assert( pane ); + // pane->scrollContentsBy( x, y ); +} + +/* + * Sets the scrollbar policy + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtScrollPanePeer_setPolicy +(JNIEnv *env, jobject obj, jint policy) +{ + QScrollArea *pane = (QScrollArea *) getNativeObject( env, obj ); + assert( pane ); + + Qt::ScrollBarPolicy qtpolicy; + switch( policy ) + { + case SCROLLBARS_ALWAYS: + qtpolicy = Qt::ScrollBarAlwaysOn; + break; + + case SCROLLBARS_NEVER: + qtpolicy = Qt::ScrollBarAlwaysOff; + break; + + default: + case SCROLLBARS_AS_NEEDED: + qtpolicy = Qt::ScrollBarAsNeeded; + break; + } + + mainThread->postEventToMain( new ScrollPanePolicy( pane, qtpolicy ) ); +} + diff --git a/libjava/classpath/native/jni/qt-peer/qtstrings.cpp b/libjava/classpath/native/jni/qt-peer/qtstrings.cpp new file mode 100644 index 000000000..c343c6331 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qtstrings.cpp @@ -0,0 +1,54 @@ +/* qtstrings.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include "qtstrings.h" + +QString *getQString(JNIEnv *env, jstring str) +{ + QString qStr; + { + const char *chars = env->GetStringUTFChars( str, NULL ); + qStr = QString::fromUtf8( chars, env->GetStringLength( str ) ); + env->ReleaseStringUTFChars( str, chars ); + } + return new QString(qStr); +} + +jstring getJavaString(JNIEnv *env, QString *qstring) +{ + return env->NewStringUTF(qstring->toUtf8()); +} diff --git a/libjava/classpath/native/jni/qt-peer/qtstrings.h b/libjava/classpath/native/jni/qt-peer/qtstrings.h new file mode 100644 index 000000000..ba5ab8c99 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qtstrings.h @@ -0,0 +1,10 @@ +#ifndef QTSTRINGS_H +#define QTSTRINGS_H + +#include +#include + +QString *getQString(JNIEnv *env, jstring str); +jstring getJavaString(JNIEnv *env, QString *qstring); + +#endif diff --git a/libjava/classpath/native/jni/qt-peer/qttextareapeer.cpp b/libjava/classpath/native/jni/qt-peer/qttextareapeer.cpp new file mode 100644 index 000000000..50f85b861 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qttextareapeer.cpp @@ -0,0 +1,197 @@ +/* qttextareapeer.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include +#include +#include "mainthreadinterface.h" +#include "componentevent.h" +#include "slotcallbacks.h" +#include "qtcomponent.h" +#include "qtstrings.h" + +class TASetText : public AWTEvent { + private: + QTextEdit *area; + QString *text; + + public: + TASetText(QTextEdit *w, QString *t) : AWTEvent() + { + area = w; + text = t; + } + + void runEvent() + { + area->setPlainText( *text ); + delete text; + } +}; + +/* + * Construct a QTextEdit object + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_init +(JNIEnv *env, jobject obj) +{ + QWidget *parentWidget = (QWidget *)getParentWidget( env, obj ); + assert( parentWidget ); + QTextEdit *editor = new QTextEdit( parentWidget ); + editor->setGeometry( 0, 0, 400, 400 ); + assert( editor ); + + // setLineWrapColumnOrWidth ( int w ); + setNativeObject( env, obj, editor ); + + // Connect TextChanged events. + connectTextEdit(editor, env, obj); +} + +/* + * Returns the cursor position. + */ +JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_getCaretPosition +(JNIEnv *env, jobject obj) +{ + int index; + + QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj ); + assert( editor ); + + index = editor->textCursor().position();; + + return (jint)index; +} + +/* + * Returns the char index at a given screen point + */ +JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_getIndexAtPoint +(JNIEnv *env, jobject obj, jint x, jint y) +{ + QPoint *p = new QPoint(x,y); + + QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj ); + assert( editor ); + QTextCursor curs = editor->cursorForPosition( *p ); + delete p; + + return curs.position(); +} + +/* + * Returns the start (start = true) or end (start = false) of the selection. + */ +JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_getSelection +(JNIEnv *env, jobject obj, jboolean isStart) +{ + int start, end; + + QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj ); + assert( editor ); + start = editor->textCursor().selectionStart(); + end = editor->textCursor().selectionEnd(); + + return ((isStart == JNI_TRUE) ? start : end); +} + +/* + * Returns the text. + */ +JNIEXPORT jstring JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_getText +(JNIEnv *env, jobject obj) +{ + QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj ); + assert( editor ); + QString text = editor->toPlainText(); + + return getJavaString(env, &text); +} + +/* + * Sets the editor text. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_setText +(JNIEnv *env, jobject obj, jstring str) +{ + QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj ); + assert( editor ); + + QString *qStr = getQString(env, str); + mainThread->postEventToMain( new TASetText( editor, qStr ) ); +} + +/* + * Sets the selection. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_select +(JNIEnv *env, jobject obj, jint startpos, jint endpos) +{ + QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj ); + assert( editor ); + + QTextCursor curs(editor->document()); + curs.setPosition(startpos); + curs.setPosition(endpos, QTextCursor::KeepAnchor); + editor->setTextCursor( curs ); +} + +/* + * Allow or disallow editing. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_setEditable +(JNIEnv *env, jobject obj, jboolean editable) +{ + QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj ); + assert( editor ); + editor->setReadOnly( (editable != JNI_TRUE) ); +} + +/* + * Sets the cursor position + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_setCaretPosition +(JNIEnv *env, jobject obj, jint index) +{ + QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj ); + assert( editor ); + + editor->textCursor().setPosition( index ); +} diff --git a/libjava/classpath/native/jni/qt-peer/qttextfieldpeer.cpp b/libjava/classpath/native/jni/qt-peer/qttextfieldpeer.cpp new file mode 100644 index 000000000..5c7113379 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qttextfieldpeer.cpp @@ -0,0 +1,290 @@ +/* qttextfieldpeer.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include +#include "qtcomponent.h" +#include "qtstrings.h" +#include "slotcallbacks.h" +#include "mainthreadinterface.h" + +class TFEchoChar : public AWTEvent { + private: + QLineEdit *line; + jchar c; + + public: + TFEchoChar(QLineEdit *w, jchar ch) : AWTEvent() + { + line = w; + c = ch; + } + + void runEvent() + { + line->setEchoMode( (c) ? QLineEdit::Password : QLineEdit::Normal ); + } +}; + +class TFEditable : public AWTEvent { + private: + QLineEdit *line; + bool editable; + + public: + TFEditable(QLineEdit *w, bool e) : AWTEvent() + { + line = w; + editable = e; + } + + void runEvent() + { + line->setReadOnly( editable ); + } +}; + +class TFSetText : public AWTEvent { + private: + QLineEdit *line; + QString *text; + + public: + TFSetText(QLineEdit *w, QString *t) : AWTEvent() + { + line = w; + text = t; + } + + void runEvent() + { + line->setText( *text ); + delete text; + } +}; + +class TFSetCursorPos : public AWTEvent { + private: + QLineEdit *line; + int pos; + + public: + TFSetCursorPos(QLineEdit *w, int p) : AWTEvent() + { + line = w; + pos = p; + } + + void runEvent() + { + line->setCursorPosition(pos); + } +}; + +class TFSelect : public AWTEvent { + private: + QLineEdit *line; + int start,end; + + public: + TFSelect(QLineEdit *w, int s, int e) : AWTEvent() + { + line = w; + start = s; + end = e; + } + + void runEvent() + { + line->setSelection(start, end - start); + } +}; + + +/* + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_init +(JNIEnv *env, jobject obj) +{ + QWidget *parentWidget = (QWidget *)getParentWidget(env, obj); + assert( parentWidget ); + QLineEdit *line = new QLineEdit( parentWidget ); + assert( line ); + + setNativeObject( env, obj, line ); + connectLineEdit(line, env, obj); +} + + +/* + * Sets the echo char. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_setEchoChar +(JNIEnv *env, jobject obj, jchar echo) +{ + QLineEdit *line = (QLineEdit *) getNativeObject( env, obj ); + assert( line ); + mainThread->postEventToMain( new TFEchoChar( line, echo ) ); +} + +/* + */ +JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_getMinimumSizeNative +(JNIEnv *env, jobject obj, jint columns) +{ + QLineEdit *line = (QLineEdit *) getNativeObject( env, obj ); + assert( line ); + + // FIXME does this work? + int old = line->maxLength(); + line->setMaxLength(columns); + QSize size = line->minimumSizeHint(); + line->setMaxLength(old); + + return makeDimension(env, &size); +} + +/* + */ +JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_getPreferredSizeNative +(JNIEnv *env, jobject obj, jint columns) +{ + QLineEdit *line = (QLineEdit *) getNativeObject( env, obj ); + assert( line ); + + int old = line->maxLength(); + line->setMaxLength(columns); + QSize size = line->sizeHint(); + line->setMaxLength(old); + + return makeDimension(env, &size); +} + +/* + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_setEditable +(JNIEnv *env, jobject obj, jboolean edit) +{ + QLineEdit *line = (QLineEdit *) getNativeObject( env, obj ); + assert( line ); + + mainThread->postEventToMain( new TFEditable( line, (edit != JNI_TRUE) ) ); +} + +/* + * Gets the text. + */ +JNIEXPORT jstring JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_getText +(JNIEnv *env, jobject obj) +{ + QLineEdit *line = (QLineEdit *) getNativeObject( env, obj ); + assert( line ); + QString text = line->text(); + + return getJavaString(env, &text); +} + +/* + * Sets the text + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_setText +(JNIEnv *env, jobject obj, jstring text) +{ + QLineEdit *line = (QLineEdit *) getNativeObject( env, obj ); + assert( line ); + + QString *qStr = getQString(env, text); + mainThread->postEventToMain( new TFSetText( line, qStr ) ); +} + +/* + * Returns the start (start = true) or end (start = false) of the selection. + */ +JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_getSelection +(JNIEnv *env, jobject obj, jboolean start) +{ + int index, length; + + QLineEdit *line = (QLineEdit *) getNativeObject( env, obj ); + assert( line ); + index = line->selectionStart(); + + if(start == JNI_TRUE) + return index; + + length = (line->selectedText()).length(); + + return index + length; +} + +/* + * Sets the selection. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_select +(JNIEnv *env, jobject obj, jint start, jint end) +{ + QLineEdit *line = (QLineEdit *) getNativeObject( env, obj ); + assert( line ); + + mainThread->postEventToMain( new TFSelect( line, start, end ) ); +} + +/* + * Sets the cursor position. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_setCaretPosition +(JNIEnv *env, jobject obj, jint pos) +{ + QLineEdit *line = (QLineEdit *) getNativeObject( env, obj ); + assert( line ); + mainThread->postEventToMain( new TFSetCursorPos( line, (int)pos ) ); +} + +/* + * Returns the caret position. + */ +JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_getCaretPosition +(JNIEnv *env, jobject obj) +{ + QLineEdit *line = (QLineEdit *) getNativeObject( env, obj ); + assert( line ); + + return line->cursorPosition(); +} + diff --git a/libjava/classpath/native/jni/qt-peer/qttoolkit.cpp b/libjava/classpath/native/jni/qt-peer/qttoolkit.cpp new file mode 100644 index 000000000..222b32344 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qttoolkit.cpp @@ -0,0 +1,156 @@ +/* qttoolkit.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include +#include +#include +#include "qtcomponent.h" +#include "mainthreadinterface.h" +#include "qtstrings.h" + +extern QApplication *qApplication; + +/** + * Calls syncX(); + */ +class AWTSyncEvent : public AWTEvent { + + private: + QApplication *application; + + public: + AWTSyncEvent(QApplication *app) : AWTEvent() + { + application = app; + } + + void runEvent() + { + application->syncX(); + } +}; + +/* + * Causes your machine to beep. Wow. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtToolkit_beep +(JNIEnv *env, jobject obj) +{ + qApplication->beep(); +} + +/** + * Returns the # of the default screen. + */ +JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtToolkit_defaultScreen +(JNIEnv *env, jobject obj) +{ + return (jint) qApplication->desktop()->primaryScreen(); +} + +/** + * Returns the # of screens. + */ +JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtToolkit_numScreens +(JNIEnv *env, jobject obj) +{ + return (jint) qApplication->desktop()->numScreens(); +} + +/* + * Returns the screen size. + */ +JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QtToolkit_getScreenSize +(JNIEnv *env, jobject obj) +{ + QDesktopWidget *d = QApplication::desktop(); + QSize s = d->size(); + return makeDimension( env, &s ); +} + +/* + * Returns the available fonts + */ +JNIEXPORT jobjectArray JNICALL Java_gnu_java_awt_peer_qt_QtToolkit_nativeFontFamilies +(JNIEnv *env, jobject obj) +{ + jobjectArray result_array; + jobject *result_array_ptr; + QFontDatabase db; + QStringList fonts = db.families(); + + result_array = env->NewObjectArray(fonts.size(), + env->FindClass("java/lang/String"), + env->NewStringUTF("")); + for (int i = 0; i < fonts.size(); i++) + { + QString qstr = fonts.at(i); + jstring jstr = getJavaString(env, &qstr); + env->SetObjectArrayElement( result_array, i, jstr ); + } + return result_array; +} + + +/* + * Returns the screen resolution + */ +JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtToolkit_getScreenResolution +(JNIEnv *env, jobject obj) +{ + QDesktopWidget *d = qApplication->desktop(); + + // Java assumes square pixels. Qt, more intelligently, does not. + // What to do? Well.. Average them? + // FIXME: Weird values? + int dpi = (d->logicalDpiX() + d->logicalDpiY()) >> 1; + + return (jint)dpi; +} + +/* + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtToolkit_sync +(JNIEnv *env, jobject obj) +{ + // SyncX needs to be called from the main thread. + mainThread->postEventToMain( new AWTSyncEvent( qApplication ) ); +} + diff --git a/libjava/classpath/native/jni/qt-peer/qtvolatileimage.cpp b/libjava/classpath/native/jni/qt-peer/qtvolatileimage.cpp new file mode 100644 index 000000000..9c28db6d1 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qtvolatileimage.cpp @@ -0,0 +1,347 @@ +/* qtvolatileimage.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include +#include +#include +#include +#include "qtimage.h" +#include "qtstrings.h" +#include "qtgraphics.h" +#include "nativewrapper.h" + +/* The constant fields in java.awt.Image */ +#define SCALE_DEFAULT 1 +#define SCALE_FAST 2 +#define SCALE_SMOOTH 4 +#define SCALE_REPLICATE 8 +#define SCALE_AREA_AVERAGING 16 + +QPixmap *getQtVolatileImage( JNIEnv *env, jobject obj ) +{ + jclass cls = env->GetObjectClass( obj ); + jfieldID field = env->GetFieldID( cls, "nativeObject", "J" ); + return (QPixmap *)env->GetLongField( obj, field ); +} + +static void setNativePtr( JNIEnv *env, jobject obj, void *value ) +{ + jlong longValue = (jlong) value; + jclass cls = env->GetObjectClass( obj ); + jfieldID field = env->GetFieldID( cls, "nativeObject", "J" ); + env->SetLongField( obj, field, longValue ); +} + +/* + * Clears the image to zero. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtVolatileImage_clear +(JNIEnv *env, jobject obj) +{ + QPixmap *image = getQtVolatileImage(env, obj); + assert( image ); + image->fill(); +} + +/* + * Returns the pixel data in an int array. + */ +JNIEXPORT jintArray JNICALL Java_gnu_java_awt_peer_qt_QtVolatileImage_getPixels +(JNIEnv *env, jobject obj) +{ + QPixmap *image = getQtVolatileImage(env, obj); + jintArray result_array; + jint *result_array_ptr, *dst; + int x, y; + jint pixel; + QRgb current; + + assert( image ); + QImage im = image->toImage(); + + result_array = env->NewIntArray (image->width() * image->height()); + dst = result_array_ptr = + env->GetIntArrayElements(result_array, NULL); + + // A bit inefficient. + for ( y = 0; y < image->height(); y++) + for ( x = 0; x < image->width(); x++) + { + current = im.pixel(x, y); + pixel = 0; + pixel = (qAlpha(current) & 0xFF) << 24 | + (qRed(current) & 0xFF) << 16 | + (qGreen(current) & 0xFF) << 8 | + (qBlue(current) & 0xFF); + *dst = pixel; + dst++; + } + + env->ReleaseIntArrayElements (result_array, result_array_ptr, 0); + return result_array; +} + +/* + * Creates a QImage. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtVolatileImage_createImage +(JNIEnv *env, jobject obj) +{ + int width, height; + jclass cls; + jfieldID field; + + cls = env->GetObjectClass( obj ); + field = env->GetFieldID (cls, "width", "I"); + assert (field != 0); + width = env->GetIntField(obj, field); + + field = env->GetFieldID(cls, "height", "I"); + assert (field != 0); + height = env->GetIntField(obj, field); + + QPixmap *image = new QPixmap ( width, height ); + setNativePtr(env, obj, image); +} + +/* + * Frees the image data. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtVolatileImage_freeImage +(JNIEnv *env, jobject obj) +{ + QPixmap *image = getQtVolatileImage(env, obj); + if ( image ) + delete image; + setNativePtr(env, obj, NULL); +} + +/* + * Blits a QImage + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtVolatileImage_blit__Lgnu_java_awt_peer_qt_QtImage_2 +(JNIEnv *env, jobject obj, jobject i2) +{ + QPixmap *image = getQtVolatileImage(env, obj); + assert( image ); + + QImage *blit = getQtImage(env, i2); + assert( blit ); + + QPainter *p = new QPainter( image ); + assert( p ); + p->drawImage( 0, 0, *blit ); + + delete p; +} + +/* + * Blits a QImage + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtVolatileImage_blit__Lgnu_java_awt_peer_qt_QtImage_2IIII +(JNIEnv *env, jobject obj, jobject i2, jint x, jint y, jint w, jint h) +{ + QPixmap *image = getQtVolatileImage(env, obj); + assert( image ); + + QImage *blit = getQtImage(env, i2); + assert( blit ); + + QPainter *p = new QPainter( image ); + assert( p ); + p->drawImage( x, y, *blit, x, y, w, h); + + delete p; +} + +/* + * Creates a scaled version. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtVolatileImage_createScaledImage +(JNIEnv *env, jobject obj, jobject src, jint hints) +{ + int w,h; + jclass cls; + jfieldID field; + + cls = env->GetObjectClass( obj ); + field = env->GetFieldID(cls, "width", "I"); + assert (field != 0); + w = env->GetIntField(obj, field); + + field = env->GetFieldID(cls, "height", "I"); + assert (field != 0); + h = env->GetIntField(obj, field); + + QPixmap *ip = getQtVolatileImage(env, src); + assert( ip ); + QImage image = ip->toImage(); + QImage imageScaled; + + if (hints == SCALE_SMOOTH || hints == SCALE_AREA_AVERAGING) + imageScaled = image.scaled(w, h, + Qt::IgnoreAspectRatio, + Qt::SmoothTransformation); + else + imageScaled = image.scaled(w, h, + Qt::IgnoreAspectRatio, + Qt::FastTransformation); + QImage *scaledPtr = new QImage( imageScaled ); + + // create new QtImage object + setNativePtr( env, obj, scaledPtr ); +} + +/* + * DrawPixels. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtVolatileImage_drawPixels +(JNIEnv *env, jobject obj, jobject graphics, jint bg_red, jint bg_green, + jint bg_blue, jint x, jint y, jboolean composite) +{ + QPixmap *image = getQtVolatileImage(env, obj); + assert( image ); + QPainter *painter = getPainter( env, graphics ); + assert( painter ); + + if(composite == JNI_TRUE) + painter->fillRect ( x, y, image->width(), image->height(), + QColor(bg_red, bg_green, bg_blue ) ); + painter->drawPixmap ( QPoint(x, y), *image ); +} + +/* + * DrawPixels scaled. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtVolatileImage_drawPixelsScaled +(JNIEnv *env, jobject obj, jobject graphics, + jint bg_red, jint bg_green, jint bg_blue, + jint x, jint y, jint w, jint h, jboolean composite) +{ + QPixmap *image = getQtVolatileImage(env, obj); + assert( image ); + QPainter *painter = getPainter( env, graphics ); + assert( painter ); + + if(composite == JNI_TRUE) + painter->fillRect ( x, y, w, h, QColor(bg_red, bg_green, bg_blue ) ); + + QRectF *srcRect = new QRectF((qreal)0, (qreal)0, + (qreal)image->width(), (qreal)image->height()); + QRectF *dstRect = new QRectF((qreal)x, (qreal)y, + (qreal)w, (qreal)h); + + if(composite == JNI_TRUE) + painter->fillRect( *dstRect, QColor(bg_red, bg_green, bg_blue ) ); + + painter->drawPixmap( *dstRect, *image, *srcRect); + + delete srcRect; + delete dstRect; +} + +/* + * Draw pixels transformed. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtVolatileImage_drawPixelsTransformed +(JNIEnv *env, jobject obj, jobject graphics, jobject transform) +{ + QPixmap *originalImage = getQtVolatileImage(env, obj); + assert( originalImage ); + QPainter *painter = getPainter( env, graphics ); + assert( painter ); + QMatrix *matrix = (QMatrix *)getNativeObject(env, transform); + assert( matrix ); + + // FIXME : Add rendering hint support here. + QPoint p = matrix->map( QPoint(0,0) ); + QImage image = originalImage->toImage().transformed ( *matrix, Qt::FastTransformation ); + painter->drawImage(p, image); +} + + +/** + * Draw pixels scaled and flipped + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtVolatileImage_drawPixelsScaledFlipped +(JNIEnv *env, jobject obj, jobject graphics, + jint bg_red, jint bg_green, jint bg_blue, + jboolean flipx, jboolean flipy, + jint srcx, jint srcy, jint srcwidth, jint srcheight, + jint dstx, jint dsty, jint dstwidth, jint dstheight, + jboolean composite) +{ + QPixmap *originalImage = getQtVolatileImage(env, obj); + assert( originalImage ); + QPainter *painter = getPainter( env, graphics ); + assert( painter ); + + QRectF *srcRect = new QRectF((qreal)srcx, (qreal)srcy, + (qreal)srcwidth, (qreal)srcheight); + QRectF *dstRect = new QRectF((qreal)dstx, (qreal)dsty, + (qreal)dstwidth, (qreal)dstheight); + + if(composite == JNI_TRUE) + painter->fillRect( *dstRect, QColor(bg_red, bg_green, bg_blue ) ); + + if( flipx == JNI_TRUE || flipy == JNI_TRUE ) + { + QImage im = originalImage->toImage().mirrored ( (flipx == JNI_TRUE), + (flipy == JNI_TRUE) ); + painter->drawImage ( *dstRect, im, *srcRect); + } + else + painter->drawPixmap ( *dstRect, *originalImage, *srcRect); + + delete srcRect; + delete dstRect; +} + +/** + * Copies an area of the image (used by Graphics) + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtVolatileImage_copyArea +(JNIEnv *env, jobject obj , jint x, jint y, jint w, jint h, jint dx, jint dy) +{ + QPixmap *image = getQtVolatileImage(env, obj); + assert( image ); + + // FIXME +} diff --git a/libjava/classpath/native/jni/qt-peer/qtwindowpeer.cpp b/libjava/classpath/native/jni/qt-peer/qtwindowpeer.cpp new file mode 100644 index 000000000..decb64f9a --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/qtwindowpeer.cpp @@ -0,0 +1,157 @@ +/* qtwindowpeer.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include +#include "qtcomponent.h" +#include "keybindings.h" +#include "qtstrings.h" +#include "containers.h" +#include "mainthreadinterface.h" + +/* + * Our QMainWindow subclass + */ +class MyWindow : public QWidget +{ +public: + MyWindow(JNIEnv *env, jobject obj) : QWidget(0, (Qt::Window | Qt::FramelessWindowHint)) + { + setup(env, obj); + } + + ~MyWindow() + { + destroy(); + } + +#define I_KNOW_WHAT_IM_DOING +#define PARENT QWidget +#include "eventmethods.h" +}; + + +class RaiseLower : public AWTEvent { + + private: + QWidget *widget; + bool raise; + + public: + RaiseLower(QWidget *w, bool r) : AWTEvent() + { + widget = w; + raise = r; + } + + void runEvent() + { + if (raise) + widget->raise(); + else + widget->lower(); + } +}; + +class FrameTitleEvent : public AWTEvent { + + private: + QWidget *widget; + QString *string; + + public: + FrameTitleEvent(QWidget *w, QString *s) : AWTEvent() + { + widget = w; + string = s; + } + + void runEvent() + { + widget->setWindowTitle( *string ); + delete string; + } +}; + +/* + * Constructs a top-level QWidget native object. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtWindowPeer_init +(JNIEnv *env, jobject obj) +{ + QWidget *window = new MyWindow(env, obj); + assert( window ); + // Qt::WStyle_StaysOnTop + setNativeObject( env, obj, window ); +} + +/* + * Lower the window. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtWindowPeer_toBack +(JNIEnv *env, jobject obj) +{ + QWidget *window = (QWidget *) getNativeObject( env, obj ); + assert( window ); + mainThread->postEventToMain( new RaiseLower( window, false ) ); +} + +/* + * Raise the window. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtWindowPeer_toFront +(JNIEnv *env, jobject obj) +{ + QWidget *window = (QWidget *) getNativeObject( env, obj ); + assert( window ); + mainThread->postEventToMain( new RaiseLower( window, true ) ); +} + +/* + * Title. + */ +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtWindowPeer_setTitle +(JNIEnv *env, jobject obj, jstring string) +{ + QWidget *frame = (QWidget *) getNativeObject( env, obj ); + assert( frame ); + QString *qStr = getQString(env, string); + mainThread->postEventToMain( new FrameTitleEvent( frame, qStr ) ); +} + diff --git a/libjava/classpath/native/jni/qt-peer/slotcallbacks.cpp b/libjava/classpath/native/jni/qt-peer/slotcallbacks.cpp new file mode 100644 index 000000000..3e0820477 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/slotcallbacks.cpp @@ -0,0 +1,256 @@ +/* slotcallbacks.cpp -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "qtcomponent.h" +#include "qtstrings.h" +#include "keybindings.h" +#include "buttonevent.h" +#include "slotcallbacks.h" + +// AdjustmentEvent constants +#define UNIT_INCREMENT 1 +#define UNIT_DECREMENT 2 +#define BLOCK_DECREMENT 3 +#define BLOCK_INCREMENT 4 +#define TRACK 5 + + +class SlotCallback : public QObject { + Q_OBJECT; + +private: + JavaVM* vm; + jobject target; + jclass componentCls; + jmethodID fireEventID; + +public: + QScrollBar *sb; // used only by the scrollbar method. + QListWidget *lw; // used only by the listitemclicked method + + SlotCallback(JNIEnv *env, jobject t) + { + env->GetJavaVM(&vm); + target = t; + target = env->NewGlobalRef(t); + } + + ~SlotCallback() + { + JNIEnv *env; + vm->GetEnv((void **)&env, JNI_VERSION_1_1); + env->DeleteGlobalRef(target); + } + + public slots: + + void buttonClicked() + { + JNIEnv *env; + vm->GetEnv((void **)&env, JNI_VERSION_1_1); + componentCls = env->GetObjectClass( target ); + fireEventID = env->GetMethodID( componentCls, + "fireClick", + "(I)V" ); + int modifiers = getAEKeyModifiers( QApplication::keyboardModifiers() ); + env->CallVoidMethod( target, fireEventID, modifiers ); + env->DeleteLocalRef( componentCls ); + } + + void buttonToggled(bool checked) + { + JNIEnv *env; + vm->GetEnv((void **)&env, JNI_VERSION_1_1); + componentCls = env->GetObjectClass( target ); + fireEventID = env->GetMethodID( componentCls, + "fireToggle", + "(Z)V" ); + if(checked) + env->CallVoidMethod( target, fireEventID, JNI_TRUE ); + else + env->CallVoidMethod( target, fireEventID, JNI_FALSE ); + env->DeleteLocalRef( componentCls ); + } + + // Used for List and Choice + void choiceActivated( int index ) + { + JNIEnv *env; + vm->GetEnv((void **)&env, JNI_VERSION_1_1); + componentCls = env->GetObjectClass( target ); + fireEventID = env->GetMethodID( componentCls, + "fireChoice", + "(I)V" ); + env->CallVoidMethod( target, fireEventID, (jint)index ); + env->DeleteLocalRef( componentCls ); + } + + void textChanged() + { + JNIEnv *env; + vm->GetEnv((void **)&env, JNI_VERSION_1_1); + componentCls = env->GetObjectClass( target ); + fireEventID = env->GetMethodID( componentCls, + "textChanged", + "()V" ); + env->CallVoidMethod( target, fireEventID ); + env->DeleteLocalRef( componentCls ); + } + + void scrollBarAction( int action ) + { + JNIEnv *env; + int type; + int index; + switch(action) + { + case QAbstractSlider::SliderNoAction: + return; + case QAbstractSlider::SliderSingleStepAdd: + type = UNIT_INCREMENT; + break; + case QAbstractSlider::SliderSingleStepSub: + type = UNIT_DECREMENT; + break; + case QAbstractSlider::SliderPageStepAdd: + type = BLOCK_INCREMENT; + break; + case QAbstractSlider::SliderPageStepSub: + type = BLOCK_DECREMENT; + break; + case QAbstractSlider::SliderToMinimum: + type = TRACK; + break; + case QAbstractSlider::SliderToMaximum: + type = TRACK; + break; + case QAbstractSlider::SliderMove: + type = TRACK; + break; + } + index = sb->value(); + vm->GetEnv((void **)&env, JNI_VERSION_1_1); + componentCls = env->GetObjectClass( target ); + fireEventID = env->GetMethodID( componentCls, + "fireMoved", + "(II)V" ); + env->CallVoidMethod( target, fireEventID, (jint)type, (jint)index ); + env->DeleteLocalRef( componentCls ); + } + + void listItemClicked( QListWidgetItem * item ) + { + int index = lw->row( item ); + JNIEnv *env; + vm->GetEnv((void **)&env, JNI_VERSION_1_1); + componentCls = env->GetObjectClass( target ); + fireEventID = env->GetMethodID( componentCls, + "itemDoubleClicked", + "(II)V" ); + int modifiers = getAEKeyModifiers( QApplication::keyboardModifiers() ); + env->CallVoidMethod( target, fireEventID, index, modifiers ); + env->DeleteLocalRef( componentCls ); + } +}; + +#include "slotcallbacks.moc.h" + +void connectButton(QPushButton *button, JNIEnv *env, jobject buttonobj) +{ + SlotCallback *scb = new SlotCallback(env, buttonobj); + QObject::connect( button, SIGNAL( clicked() ), scb, SLOT( buttonClicked() ) ); +} + +void connectChoice(QComboBox *choice, JNIEnv *env, jobject choiceobj) +{ + SlotCallback *scb = new SlotCallback(env, choiceobj); + QObject::connect( choice, SIGNAL( activated(int) ), scb, SLOT( choiceActivated(int) ) ); +} + +void connectList(QListWidget *list, JNIEnv *env, jobject listobj) +{ + SlotCallback *scb = new SlotCallback(env, listobj); + scb->lw = list; + QObject::connect( list, SIGNAL( currentRowChanged(int) ), + scb, SLOT( choiceActivated(int) ) ); + QObject::connect( list, SIGNAL( itemDoubleClicked( QListWidgetItem * )), + scb, SLOT( listItemClicked( QListWidgetItem * ))); +} + +void connectAction(QAction *action, JNIEnv *env, jobject obj) +{ + SlotCallback *scb = new SlotCallback(env, obj); + QObject::connect( action, SIGNAL( triggered() ), scb, SLOT( buttonClicked() ) ); +} + +void connectToggle(QAbstractButton *action, JNIEnv *env, jobject obj) +{ + SlotCallback *scb = new SlotCallback(env, obj); + QObject::connect( action, SIGNAL( toggled(bool) ), scb, SLOT( buttonToggled(bool) ) ); +} + +void connectScrollBar(QScrollBar *scroll, JNIEnv *env, jobject obj) +{ + SlotCallback *scb = new SlotCallback(env, obj); + scb->sb = scroll; + QObject::connect( scroll, SIGNAL( actionTriggered(int) ), scb, SLOT( scrollBarAction(int) ) ); +} + +void connectTextEdit(QTextEdit *edit, JNIEnv *env, jobject obj) +{ + SlotCallback *scb = new SlotCallback(env, obj); + QObject::connect( edit, SIGNAL( textChanged() ), + scb, SLOT( textChanged() ) ); +} + +void connectLineEdit(QLineEdit *edit, JNIEnv *env, jobject obj) +{ + SlotCallback *scb = new SlotCallback(env, obj); + QObject::connect( edit, SIGNAL(textChanged( QString ) ), + scb, SLOT( textChanged() ) ); +} + diff --git a/libjava/classpath/native/jni/qt-peer/slotcallbacks.h b/libjava/classpath/native/jni/qt-peer/slotcallbacks.h new file mode 100644 index 000000000..88c292ce7 --- /dev/null +++ b/libjava/classpath/native/jni/qt-peer/slotcallbacks.h @@ -0,0 +1,24 @@ +#ifndef SLOTCALLBACKS_H +#define SLOTCALLBACKS_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void connectButton(QPushButton *button, JNIEnv *env, jobject buttonobj); +void connectChoice(QComboBox *choice, JNIEnv *env, jobject choiceobj); +void connectAction(QAction *action, JNIEnv *env, jobject obj); +void connectToggle(QAbstractButton *action, JNIEnv *env, jobject obj); +void connectScrollBar(QScrollBar *scroll, JNIEnv *env, jobject obj); +void connectList(QListWidget *list, JNIEnv *env, jobject choiceobj); +void connectTextEdit(QTextEdit *edit, JNIEnv *env, jobject obj); +void connectLineEdit(QLineEdit *edit, JNIEnv *env, jobject obj); + +#endif diff --git a/libjava/classpath/native/jni/xmlj/.cvsignore b/libjava/classpath/native/jni/xmlj/.cvsignore new file mode 100644 index 000000000..e9f2658a6 --- /dev/null +++ b/libjava/classpath/native/jni/xmlj/.cvsignore @@ -0,0 +1,8 @@ +*.o +*.a +*.lo +*.la +.libs +.deps +Makefile +Makefile.in diff --git a/libjava/classpath/native/jni/xmlj/BUGS b/libjava/classpath/native/jni/xmlj/BUGS new file mode 100644 index 000000000..801700cf1 --- /dev/null +++ b/libjava/classpath/native/jni/xmlj/BUGS @@ -0,0 +1,35 @@ +GNU Jaxp +------------------------------------------------------------------------ + +These bugs are for the gnu.xml.libxmlj package. + +CAVEAT: LibxmlJ's current incarnation is incomplete and partly +incorrect. Highly experimental. + +- Thread-safe, but effectively runs single-threaded. + +- Native code passes incorrect URIs to URIResolver.resolve. + +- Default output properties accessible through JAXP always assume XML + output (in violation of the XSLT 1.0 specification, section 16) + Correction: LibxmlJ always assumes XML output. + +- OutputProperties are not properly implemented, compare code and API + documentation. + +- TransformerFactory.getAttribute() and + TransformerFactory.setAttribute() not implemented, i.e. low-level + libxslt settings can currently not be accessed from Java. + +- TransformerFactory.getFeature() not implemented, i.e. currently no + low-level features of libxslt are advertised. + +FIXME: + +- Make LRU caching configurable. + +- Check whether headers are honored. + +- DefaultURIResolver uses naive approach. + +- TransformerFactory.getAssociatedStyleSheet() unfinished. diff --git a/libjava/classpath/native/jni/xmlj/Makefile.am b/libjava/classpath/native/jni/xmlj/Makefile.am new file mode 100644 index 000000000..4f66ac827 --- /dev/null +++ b/libjava/classpath/native/jni/xmlj/Makefile.am @@ -0,0 +1,28 @@ +nativeexeclib_LTLIBRARIES = libxmlj.la + +libxmlj_la_SOURCES = \ +xmlj_dom.c \ +xmlj_dom.h \ +xmlj_error.c \ +xmlj_error.h \ +xmlj_io.c \ +xmlj_io.h \ +xmlj_node.c \ +xmlj_node.h \ +xmlj_sax.c \ +xmlj_sax.h \ +xmlj_transform.c \ +xmlj_util.c \ +xmlj_util.h \ +xmlj_xpath.c + +libxmlj_la_LIBADD = $(top_builddir)/native/jni/classpath/jcl.lo + +AM_LDFLAGS = @CLASSPATH_MODULE@ @XML_LIBS@ @XSLT_LIBS@ +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ + +# Don't enable ERROR flags. Code isn't warning free yet. +AM_CFLAGS = @WARNING_CFLAGS@ @STRICT_WARNING_CFLAGS@ @XML_CFLAGS@ \ + @XSLT_CFLAGS@ @EXTRA_CFLAGS@ + +EXTRA_DIST = BUGS diff --git a/libjava/classpath/native/jni/xmlj/Makefile.in b/libjava/classpath/native/jni/xmlj/Makefile.in new file mode 100644 index 000000000..2fe972ab6 --- /dev/null +++ b/libjava/classpath/native/jni/xmlj/Makefile.in @@ -0,0 +1,634 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +subdir = native/jni/xmlj +DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/../../config/depstand.m4 \ + $(top_srcdir)/../../config/lead-dot.m4 \ + $(top_srcdir)/../../config/lib-ld.m4 \ + $(top_srcdir)/../../config/lib-link.m4 \ + $(top_srcdir)/../../config/lib-prefix.m4 \ + $(top_srcdir)/../../config/multi.m4 \ + $(top_srcdir)/../../config/no-executables.m4 \ + $(top_srcdir)/../../config/override.m4 \ + $(top_srcdir)/../../libtool.m4 \ + $(top_srcdir)/../../ltoptions.m4 \ + $(top_srcdir)/../../ltsugar.m4 \ + $(top_srcdir)/../../ltversion.m4 \ + $(top_srcdir)/../../lt~obsolete.m4 \ + $(top_srcdir)/m4/ac_prog_antlr.m4 \ + $(top_srcdir)/m4/ac_prog_java.m4 \ + $(top_srcdir)/m4/ac_prog_java_works.m4 \ + $(top_srcdir)/m4/ac_prog_javac.m4 \ + $(top_srcdir)/m4/ac_prog_javac_works.m4 \ + $(top_srcdir)/m4/acattribute.m4 $(top_srcdir)/m4/accross.m4 \ + $(top_srcdir)/m4/acinclude.m4 \ + $(top_srcdir)/m4/ax_create_stdint_h.m4 \ + $(top_srcdir)/m4/ax_func_which_gethostbyname_r.m4 \ + $(top_srcdir)/m4/gcc_attribute.m4 $(top_srcdir)/m4/iconv.m4 \ + $(top_srcdir)/m4/pkg.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/../../mkinstalldirs +CONFIG_HEADER = $(top_builddir)/include/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__installdirs = "$(DESTDIR)$(nativeexeclibdir)" +LTLIBRARIES = $(nativeexeclib_LTLIBRARIES) +libxmlj_la_DEPENDENCIES = $(top_builddir)/native/jni/classpath/jcl.lo +am_libxmlj_la_OBJECTS = xmlj_dom.lo xmlj_error.lo xmlj_io.lo \ + xmlj_node.lo xmlj_sax.lo xmlj_transform.lo xmlj_util.lo \ + xmlj_xpath.lo +libxmlj_la_OBJECTS = $(am_libxmlj_la_OBJECTS) +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/include +depcomp = $(SHELL) $(top_srcdir)/../../depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(libxmlj_la_SOURCES) +ETAGS = etags +CTAGS = ctags +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +ANTLR = @ANTLR@ +ANTLR_JAR = @ANTLR_JAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CAIRO_CFLAGS = @CAIRO_CFLAGS@ +CAIRO_LIBS = @CAIRO_LIBS@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CLASSPATH_CONVENIENCE = @CLASSPATH_CONVENIENCE@ +CLASSPATH_INCLUDES = @CLASSPATH_INCLUDES@ +CLASSPATH_MODULE = @CLASSPATH_MODULE@ +COLLECTIONS_PREFIX = @COLLECTIONS_PREFIX@ +CP = @CP@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DATE = @DATE@ +DEFAULT_PREFS_PEER = @DEFAULT_PREFS_PEER@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +ECJ_JAR = @ECJ_JAR@ +EGREP = @EGREP@ +ERROR_CFLAGS = @ERROR_CFLAGS@ +EXAMPLESDIR = @EXAMPLESDIR@ +EXEEXT = @EXEEXT@ +EXTRA_CFLAGS = @EXTRA_CFLAGS@ +FGREP = @FGREP@ +FIND = @FIND@ +FREETYPE2_CFLAGS = @FREETYPE2_CFLAGS@ +FREETYPE2_LIBS = @FREETYPE2_LIBS@ +GCONF_CFLAGS = @GCONF_CFLAGS@ +GCONF_LIBS = @GCONF_LIBS@ +GDK_CFLAGS = @GDK_CFLAGS@ +GDK_LIBS = @GDK_LIBS@ +GJDOC = @GJDOC@ +GLIB_CFLAGS = @GLIB_CFLAGS@ +GLIB_LIBS = @GLIB_LIBS@ +GMP_CFLAGS = @GMP_CFLAGS@ +GMP_LIBS = @GMP_LIBS@ +GREP = @GREP@ +GSTREAMER_BASE_CFLAGS = @GSTREAMER_BASE_CFLAGS@ +GSTREAMER_BASE_LIBS = @GSTREAMER_BASE_LIBS@ +GSTREAMER_CFLAGS = @GSTREAMER_CFLAGS@ +GSTREAMER_FILE_READER = @GSTREAMER_FILE_READER@ +GSTREAMER_LIBS = @GSTREAMER_LIBS@ +GSTREAMER_MIXER_PROVIDER = @GSTREAMER_MIXER_PROVIDER@ +GSTREAMER_PLUGINS_BASE_CFLAGS = @GSTREAMER_PLUGINS_BASE_CFLAGS@ +GSTREAMER_PLUGINS_BASE_LIBS = @GSTREAMER_PLUGINS_BASE_LIBS@ +GST_PLUGIN_LDFLAGS = @GST_PLUGIN_LDFLAGS@ +GTK_CFLAGS = @GTK_CFLAGS@ +GTK_LIBS = @GTK_LIBS@ +INIT_LOAD_LIBRARY = @INIT_LOAD_LIBRARY@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAR = @JAR@ +JAVA = @JAVA@ +JAVAC = @JAVAC@ +JAVAC_IS_GCJ = @JAVAC_IS_GCJ@ +JAVAC_MEM_OPT = @JAVAC_MEM_OPT@ +JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION = @JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION@ +JAY = @JAY@ +JAY_SKELETON = @JAY_SKELETON@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBDEBUG = @LIBDEBUG@ +LIBICONV = @LIBICONV@ +LIBMAGIC = @LIBMAGIC@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBVERSION = @LIBVERSION@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBICONV = @LTLIBICONV@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MKDIR = @MKDIR@ +MKDIR_P = @MKDIR_P@ +MOC = @MOC@ +MOZILLA_CFLAGS = @MOZILLA_CFLAGS@ +MOZILLA_LIBS = @MOZILLA_LIBS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PANGOFT2_CFLAGS = @PANGOFT2_CFLAGS@ +PANGOFT2_LIBS = @PANGOFT2_LIBS@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PATH_TO_ESCHER = @PATH_TO_ESCHER@ +PATH_TO_GLIBJ_ZIP = @PATH_TO_GLIBJ_ZIP@ +PERL = @PERL@ +PKG_CONFIG = @PKG_CONFIG@ +PLUGIN_DIR = @PLUGIN_DIR@ +QT_CFLAGS = @QT_CFLAGS@ +QT_LIBS = @QT_LIBS@ +RANLIB = @RANLIB@ +REMOVE = @REMOVE@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRICT_WARNING_CFLAGS = @STRICT_WARNING_CFLAGS@ +STRIP = @STRIP@ +TOOLSDIR = @TOOLSDIR@ +USER_JAVAH = @USER_JAVAH@ +VERSION = @VERSION@ +WANT_NATIVE_BIG_INTEGER = @WANT_NATIVE_BIG_INTEGER@ +WARNING_CFLAGS = @WARNING_CFLAGS@ +XMKMF = @XMKMF@ +XML_CFLAGS = @XML_CFLAGS@ +XML_LIBS = @XML_LIBS@ +XSLT_CFLAGS = @XSLT_CFLAGS@ +XSLT_LIBS = @XSLT_LIBS@ +XTEST_LIBS = @XTEST_LIBS@ +X_CFLAGS = @X_CFLAGS@ +X_EXTRA_LIBS = @X_EXTRA_LIBS@ +X_LIBS = @X_LIBS@ +X_PRE_LIBS = @X_PRE_LIBS@ +ZIP = @ZIP@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_ANTLR = @ac_ct_ANTLR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +default_toolkit = @default_toolkit@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +glibjdir = @glibjdir@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +multi_basedir = @multi_basedir@ +nativeexeclibdir = @nativeexeclibdir@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +toolexeclibdir = @toolexeclibdir@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +uudecode = @uudecode@ +vm_classes = @vm_classes@ +nativeexeclib_LTLIBRARIES = libxmlj.la +libxmlj_la_SOURCES = \ +xmlj_dom.c \ +xmlj_dom.h \ +xmlj_error.c \ +xmlj_error.h \ +xmlj_io.c \ +xmlj_io.h \ +xmlj_node.c \ +xmlj_node.h \ +xmlj_sax.c \ +xmlj_sax.h \ +xmlj_transform.c \ +xmlj_util.c \ +xmlj_util.h \ +xmlj_xpath.c + +libxmlj_la_LIBADD = $(top_builddir)/native/jni/classpath/jcl.lo +AM_LDFLAGS = @CLASSPATH_MODULE@ @XML_LIBS@ @XSLT_LIBS@ +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ + +# Don't enable ERROR flags. Code isn't warning free yet. +AM_CFLAGS = @WARNING_CFLAGS@ @STRICT_WARNING_CFLAGS@ @XML_CFLAGS@ \ + @XSLT_CFLAGS@ @EXTRA_CFLAGS@ + +EXTRA_DIST = BUGS +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu native/jni/xmlj/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu native/jni/xmlj/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-nativeexeclibLTLIBRARIES: $(nativeexeclib_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(nativeexeclibdir)" || $(MKDIR_P) "$(DESTDIR)$(nativeexeclibdir)" + @list='$(nativeexeclib_LTLIBRARIES)'; test -n "$(nativeexeclibdir)" || list=; \ + list2=; for p in $$list; do \ + if test -f $$p; then \ + list2="$$list2 $$p"; \ + else :; fi; \ + done; \ + test -z "$$list2" || { \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(nativeexeclibdir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(nativeexeclibdir)"; \ + } + +uninstall-nativeexeclibLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(nativeexeclib_LTLIBRARIES)'; test -n "$(nativeexeclibdir)" || list=; \ + for p in $$list; do \ + $(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(nativeexeclibdir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(nativeexeclibdir)/$$f"; \ + done + +clean-nativeexeclibLTLIBRARIES: + -test -z "$(nativeexeclib_LTLIBRARIES)" || rm -f $(nativeexeclib_LTLIBRARIES) + @list='$(nativeexeclib_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libxmlj.la: $(libxmlj_la_OBJECTS) $(libxmlj_la_DEPENDENCIES) + $(LINK) -rpath $(nativeexeclibdir) $(libxmlj_la_OBJECTS) $(libxmlj_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xmlj_dom.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xmlj_error.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xmlj_io.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xmlj_node.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xmlj_sax.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xmlj_transform.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xmlj_util.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xmlj_xpath.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) +installdirs: + for dir in "$(DESTDIR)$(nativeexeclibdir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-nativeexeclibLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-nativeexeclibLTLIBRARIES + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-nativeexeclibLTLIBRARIES + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-nativeexeclibLTLIBRARIES ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags dvi dvi-am html html-am info info-am install \ + install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-nativeexeclibLTLIBRARIES install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-nativeexeclibLTLIBRARIES + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/libjava/classpath/native/jni/xmlj/xmlj_dom.c b/libjava/classpath/native/jni/xmlj/xmlj_dom.c new file mode 100644 index 000000000..b9bd372b1 --- /dev/null +++ b/libjava/classpath/native/jni/xmlj/xmlj_dom.c @@ -0,0 +1,2617 @@ +/* xmlj_dom.c - + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include "xmlj_dom.h" +#include "xmlj_error.h" +#include "xmlj_io.h" +#include "xmlj_node.h" +#include "xmlj_sax.h" +#include "xmlj_util.h" + +#include +#include +#include +#include + +JNIEnv *dom_cb_env; +jobject dom_cb_obj; + +typedef struct +{ + int index; + int count; + xmlNodePtr node; +} +xmljHashScanData; + +/* Prototypes for local functions */ + +void +xmljAddAttribute (xmlNodePtr node, xmlAttrPtr attr); + +void +xmljHashScanner (void *payload, void *vdata, xmlChar *name); + +xmlChar * +xmljGetNodeValue (xmlNodePtr node); + +/* + * Determines whether a child node is suitable for insertion in the list of + * children for a given parent node. + * Returns 0 on success, a DOMException code otherwise. + */ +void +xmljValidateChildNode (JNIEnv *env, xmlNodePtr parent, xmlNodePtr child) +{ + xmlNodePtr cur; + + if (child == NULL || parent == NULL) + { + xmljThrowDOMException (env, 8, NULL); /* NOT_FOUND_ERR */ + return; + } + if (child->doc != parent->doc) + { + xmljThrowDOMException (env, 4, NULL); /* WRONG_DOCUMENT_ERR */ + return; + } + /* Check that new parent is of an allowed type */ + switch (parent->type) + { + case XML_CDATA_SECTION_NODE: + case XML_COMMENT_NODE: + case XML_TEXT_NODE: + case XML_ENTITY_NODE: + case XML_ENTITY_REF_NODE: + case XML_NOTATION_NODE: + case XML_PI_NODE: + /* these can't have any children */ + /* HIERARCHY_REQUEST_ERR */ + xmljThrowDOMException (env, 3, "parent type does not allow children"); + return; + case XML_ATTRIBUTE_NODE: + if (child->type != XML_TEXT_NODE && + child->type != XML_ENTITY_REF_NODE) + { + /* HIERARCHY_REQUEST_ERR */ + xmljThrowDOMException (env, 3, "attributes may only contain text or entity reference nodes"); + return; + } + break; + case XML_DOCUMENT_FRAG_NODE: + case XML_ELEMENT_NODE: + if (child->type == XML_DTD_NODE || + child->type == XML_DOCUMENT_TYPE_NODE || + child->type == XML_ENTITY_NODE || + child->type == XML_NOTATION_NODE || + child->type == XML_PI_NODE) + { + /* HIERARCHY_REQUEST_ERR */ + xmljThrowDOMException (env, 3, "parent type does not allow child of this type"); + return; + } + /* fall through */ + default: + if (child->type == XML_ATTRIBUTE_NODE || + child->type == XML_DOCUMENT_NODE || + child->type == XML_DOCUMENT_FRAG_NODE) + { + /* HIERARCHY_REQUEST_ERR */ + xmljThrowDOMException (env, 3, "node type may not be a child"); + return; + } + /* TODO others? */ + } + /* Check that new parent is not self or an ancestor */ + for (cur = parent; cur != NULL; cur = cur->parent) + { + if (cur == child) + { + /* HIERARCHY_REQUEST_ERR */ + xmljThrowDOMException (env, 3, "child cannot be an ancestor of itself"); + return; + } + } + /* Check that new parent does not add a second doctype or root element + * to a document parent */ + if (parent->type == XML_DOCUMENT_NODE) + { + cur = parent->children; + while (cur != NULL) + { + if (cur->type == XML_DTD_NODE || + cur->type == XML_DOCUMENT_TYPE_NODE || + (cur->type == XML_ELEMENT_NODE && + parent->type == XML_DOCUMENT_NODE)) + { + if (child->type == cur->type && child != cur) + { + /* HIERARCHY_REQUEST_ERR */ + xmljThrowDOMException (env, 3, "cannot add a second doctype or root element"); + return; + } + } + cur = cur->next; + } + } +} + +/* + * Adds the specified attribute node to the list of attributes for the given + * element. + */ +void +xmljAddAttribute (xmlNodePtr node, xmlAttrPtr attr) +{ + xmlAttrPtr cur = node->properties; + + if (cur == NULL) + { + node->properties = attr; + attr->prev = NULL; + attr->next = NULL; + attr->parent = node; + attr->doc = node->doc; + } + else + { + while (cur->next != NULL) + { + cur = cur->next; + } + cur->next = attr; + attr->prev = cur; + attr->next = NULL; + attr->parent = node; + attr->doc = node->doc; + } +} + +/* -- GnomeAttr -- */ + +JNIEXPORT jboolean JNICALL +Java_gnu_xml_libxmlj_dom_GnomeAttr_getSpecified (JNIEnv * env, jobject self) +{ + xmlAttrPtr attr; + + attr = (xmlAttrPtr) xmljGetNodeID (env, self); + return (attr->atype != 0); +} + +JNIEXPORT jstring JNICALL +Java_gnu_xml_libxmlj_dom_GnomeAttr_getValue (JNIEnv * env, jobject self) +{ + xmlNodePtr node; + xmlChar *text; + jstring ret; + + node = xmljGetNodeID (env, self); + text = xmlNodeGetContent (node); + ret = xmljNewString (env, (const xmlChar *) text); + if (text != NULL) + { + xmlFree (text); + } + return ret; +} + +JNIEXPORT void JNICALL +Java_gnu_xml_libxmlj_dom_GnomeAttr_setValue (JNIEnv * env, + jobject self, jstring value) +{ + xmlNodePtr node; + const xmlChar *s_value; + + node = xmljGetNodeID (env, self); + s_value = xmljGetStringChars (env, value); + xmlNodeSetContent (node, s_value); +} + +JNIEXPORT jboolean JNICALL +Java_gnu_xml_libxmlj_dom_GnomeAttr_xmljIsId (JNIEnv * env, jobject self) +{ + xmlAttrPtr attr; + + attr = (xmlAttrPtr) xmljGetNodeID (env, self); + return (attr->atype == XML_ATTRIBUTE_ID); +} + +/* -- GnomeDocument -- */ + +JNIEXPORT void JNICALL +Java_gnu_xml_libxmlj_dom_GnomeDocument_free (JNIEnv * env, + jobject self + __attribute__ ((__unused__)), + jobject id) +{ + xmlDocPtr doc; + + doc = (xmlDocPtr) xmljAsPointer (env, id); + xmljFreeDoc (env, doc); + xmlFree (doc); +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeDocument_getDoctype (JNIEnv * env, jobject self) +{ + xmlDocPtr doc; + xmlDtdPtr dtd; + + doc = (xmlDocPtr) xmljGetNodeID (env, self); + dtd = doc->extSubset; + if (dtd == NULL) + { + dtd = doc->intSubset; + } + return xmljGetNodeInstance (env, (xmlNodePtr) dtd); +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeDocument_getDocumentElement (JNIEnv * env, + jobject self) +{ + xmlDocPtr doc; + + doc = (xmlDocPtr) xmljGetNodeID (env, self); + return xmljGetNodeInstance (env, xmlDocGetRootElement (doc)); +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeDocument_createDocumentType (JNIEnv * env, + jobject self, + jstring name, + jstring publicId, + jstring systemId) +{ + xmlDocPtr doc; + xmlDtdPtr dtd; + + doc = (xmlDocPtr) xmljGetNodeID (env, self); + dtd = xmlNewDtd (doc, + xmljGetStringChars (env, name), + xmljGetStringChars (env, publicId), + xmljGetStringChars (env, systemId)); + return xmljGetNodeInstance (env, (xmlNodePtr) dtd); +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeDocument_createDocumentFragment (JNIEnv * env, + jobject self) +{ + xmlDocPtr doc; + + doc = (xmlDocPtr) xmljGetNodeID (env, self); + return xmljGetNodeInstance (env, xmlNewDocFragment (doc)); +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeDocument_createTextNode (JNIEnv * env, + jobject self, + jstring data) +{ + xmlDocPtr doc; + xmlNodePtr text; + const xmlChar *s_data; + + doc = (xmlDocPtr) xmljGetNodeID (env, self); + s_data = xmljGetStringChars (env, data); + text = xmlNewDocText (doc, s_data); + return xmljGetNodeInstance (env, text); +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeDocument_createComment (JNIEnv * env, + jobject self, + jstring data) +{ + xmlDocPtr doc; + xmlNodePtr comment; + const xmlChar *s_data; + + doc = (xmlDocPtr) xmljGetNodeID (env, self); + s_data = xmljGetStringChars (env, data); + comment = xmlNewDocComment (doc, s_data); + return xmljGetNodeInstance (env, comment); +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeDocument_createCDATASection (JNIEnv * env, + jobject self, + jstring data) +{ + xmlDocPtr doc; + xmlNodePtr cdata; + const xmlChar *s_data; + int len; + + doc = (xmlDocPtr) xmljGetNodeID (env, self); + s_data = xmljGetStringChars (env, data); + len = xmlStrlen (s_data); + cdata = xmlNewCDataBlock (doc, s_data, len); + return xmljGetNodeInstance (env, cdata); +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeDocument_createProcessingInstruction (JNIEnv * + env, + jobject + self, + jstring + target, + jstring + data) +{ + xmlDocPtr doc; + xmlNodePtr pi; + const xmlChar *s_target; + const xmlChar *s_data; + + doc = (xmlDocPtr) xmljGetNodeID (env, self); + s_target = xmljGetStringChars (env, target); + s_data = xmljGetStringChars (env, data); + pi = xmlNewPI (s_target, s_data); + pi->doc = doc; + return xmljGetNodeInstance (env, pi); +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeDocument_createEntityReference (JNIEnv * env, + jobject self, + jstring name) +{ + xmlDocPtr doc; + xmlNodePtr ref; + const xmlChar *s_name; + + doc = (xmlDocPtr) xmljGetNodeID (env, self); + s_name = xmljGetStringChars (env, name); + ref = xmlNewReference (doc, s_name); + return xmljGetNodeInstance (env, ref); +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeDocument_xmljImportNode (JNIEnv * env, + jobject self, + jobject importedNode, + jboolean deep) +{ + xmlDocPtr doc; + xmlNodePtr node; + + doc = (xmlDocPtr) xmljGetNodeID (env, self); + node = xmljGetNodeID (env, importedNode); + if (node == NULL) + { + xmljThrowDOMException (env, 8, NULL); /* NOT_FOUND_ERR */ + return NULL; + } + if (node->type == XML_DOCUMENT_NODE || + node->type == XML_DOCUMENT_TYPE_NODE) + { + xmljThrowDOMException (env, 9, NULL); /* NOT_SUPPORTED_ERR */ + return NULL; + } + node = xmlDocCopyNode (node, doc, deep); + return xmljGetNodeInstance (env, node); +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeDocument_createElementNS (JNIEnv * env, + jobject self, + jstring uri, + jstring qName) +{ + xmlDocPtr doc; + xmlNodePtr element; + xmlNsPtr ns = NULL; + const xmlChar *s_uri; + const xmlChar *s_qName; + const xmlChar *s_prefix; + const xmlChar *s_localName; + + doc = (xmlDocPtr) xmljGetNodeID (env, self); + s_qName = xmljGetStringChars (env, qName); + if (xmlValidateQName (s_qName, 0)) + { + xmljThrowDOMException (env, 5, NULL); /* INVALID_CHARACTER_ERR */ + return NULL; + } + if (uri != NULL) + { + s_uri = xmljGetStringChars (env, uri); + s_prefix = xmljGetPrefix (s_qName); + s_localName = xmljGetLocalName (s_qName); + ns = xmlNewNs ((xmlNodePtr) doc, s_uri, s_prefix); + } + element = xmlNewDocNode (doc, ns, s_qName, NULL); + return xmljGetNodeInstance (env, element); +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeDocument_createAttributeNS (JNIEnv * env, + jobject self, + jstring uri, + jstring qName) +{ + xmlDocPtr doc; + xmlNodePtr attr; + xmlNsPtr ns = NULL; + const xmlChar *s_uri; + const xmlChar *s_qName; + const xmlChar *s_prefix; + const xmlChar *s_localName; + + doc = (xmlDocPtr) xmljGetNodeID (env, self); + s_qName = xmljGetStringChars (env, qName); + if (xmlValidateQName (s_qName, 0)) + { + xmljThrowDOMException (env, 5, NULL); /* INVALID_CHARACTER_ERR */ + return NULL; + } + if (uri != NULL) + { + s_uri = xmljGetStringChars (env, uri); + s_prefix = xmljGetPrefix (s_qName); + s_localName = xmljGetLocalName (s_qName); + ns = xmlNewNs ((xmlNodePtr) doc, s_uri, s_prefix); + } + attr = (xmlNodePtr) xmlNewNsProp ((xmlNodePtr) doc, ns, s_qName, NULL); + attr->parent = NULL; + return xmljGetNodeInstance (env, attr); +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeDocument_xmljGetElementById (JNIEnv * env, + jobject self, + jstring elementId) +{ + xmlDocPtr doc; + xmlNodePtr ctx, tmp; + xmlAttrPtr attr; + const xmlChar *id; + const xmlChar *val; + + doc = (xmlDocPtr) xmljGetNodeID (env, self); + id = xmljGetStringChars (env, elementId); + + ctx = xmlDocGetRootElement (doc); + while (ctx && ctx != (xmlNodePtr) doc) + { + if (ctx->type == XML_ELEMENT_NODE) + { + for (attr = ctx->properties; attr; + attr = (xmlAttrPtr) attr->next) + { + if (xmlIsID (doc, ctx, attr)) + { + val = xmlGetProp (ctx, attr->name); + if (val && xmlStrEqual (id, val)) + { + return xmljGetNodeInstance (env, ctx); + } + } + } + } + if (ctx->children) + { + ctx = ctx->children; + } + else + { + tmp = ctx->next; + if (tmp) + { + ctx = tmp; + } + else + { + do + { + tmp = ctx->parent; + if (!tmp) + { + return NULL; + } + ctx = tmp; + tmp = ctx->next; + } + while (!tmp); + ctx = tmp; + } + } + } + return NULL; +} + +JNIEXPORT jstring JNICALL +Java_gnu_xml_libxmlj_dom_GnomeDocument_getInputEncoding (JNIEnv * env, + jobject self) +{ + xmlDocPtr doc; + + doc = (xmlDocPtr) xmljGetNodeID (env, self); + if (doc->encoding) + { + return xmljNewString (env, doc->encoding); + } + switch (doc->charset) + { + case XML_CHAR_ENCODING_ASCII: + return xmljNewString (env, BAD_CAST "US-ASCII"); + case XML_CHAR_ENCODING_UTF16LE: + return xmljNewString (env, BAD_CAST "UTF-16LE"); + case XML_CHAR_ENCODING_UTF16BE: + return xmljNewString (env, BAD_CAST "UTF-16BE"); + case XML_CHAR_ENCODING_8859_1: + return xmljNewString (env, BAD_CAST "ISO-8859-1"); + /* TODO others */ + default: + return xmljNewString (env, BAD_CAST "UTF-8"); + } +} + +JNIEXPORT jstring JNICALL +Java_gnu_xml_libxmlj_dom_GnomeDocument_getXmlEncoding (JNIEnv * env, + jobject self) +{ + xmlDocPtr doc; + + doc = (xmlDocPtr) xmljGetNodeID (env, self); + return (doc->encoding == NULL) ? + xmljNewString (env, BAD_CAST "UTF-8") : + xmljNewString (env, doc->encoding); +} + +JNIEXPORT jboolean JNICALL +Java_gnu_xml_libxmlj_dom_GnomeDocument_getXmlStandalone (JNIEnv * env, + jobject self) +{ + xmlDocPtr doc; + + doc = (xmlDocPtr) xmljGetNodeID (env, self); + return doc->standalone; +} + +JNIEXPORT void JNICALL +Java_gnu_xml_libxmlj_dom_GnomeDocument_setXmlStandalone (JNIEnv * env, + jobject self, + jboolean xmlStandalone) +{ + xmlDocPtr doc; + + doc = (xmlDocPtr) xmljGetNodeID (env, self); + doc->standalone = xmlStandalone; +} + +JNIEXPORT jstring JNICALL +Java_gnu_xml_libxmlj_dom_GnomeDocument_getXmlVersion (JNIEnv * env, + jobject self) +{ + xmlDocPtr doc; + + doc = (xmlDocPtr) xmljGetNodeID (env, self); + return (doc->version == NULL) ? + xmljNewString (env, BAD_CAST "1.0") : + xmljNewString (env, doc->version); +} + +JNIEXPORT void JNICALL +Java_gnu_xml_libxmlj_dom_GnomeDocument_setXmlVersion (JNIEnv * env, + jobject self, + jstring xmlVersion) +{ + xmlDocPtr doc; + + doc = (xmlDocPtr) xmljGetNodeID (env, self); + if (xmlVersion == NULL) + { + doc->version = NULL; + } + else + { + const xmlChar *version = xmljGetStringChars (env, xmlVersion); + if (!xmlStrEqual (version, BAD_CAST "1.0") && + !xmlStrEqual (version, BAD_CAST "1.1")) + { + xmljThrowDOMException (env, 9, NULL); /* NOT_SUPPORTED_ERR */ + return; + } + doc->version = version; + } +} + +JNIEXPORT jstring JNICALL +Java_gnu_xml_libxmlj_dom_GnomeDocument_getDocumentURI (JNIEnv * env, + jobject self) +{ + xmlDocPtr doc; + + doc = (xmlDocPtr) xmljGetNodeID (env, self); + return (doc->name == NULL) ? NULL : + xmljNewString (env, (const xmlChar *) doc->URL); +} + +JNIEXPORT void JNICALL +Java_gnu_xml_libxmlj_dom_GnomeDocument_setDocumentURI (JNIEnv * env, + jobject self, + jstring documentURI) +{ + xmlDocPtr doc; + + doc = (xmlDocPtr) xmljGetNodeID (env, self); + if (documentURI == NULL) + { + doc->URL = NULL; + } + else + { + doc->URL = xmljGetStringChars (env, documentURI); + } +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeDocument_xmljAdoptNode (JNIEnv *env, + jobject self, + jobject jnode) +{ + xmlDocPtr doc; + xmlNodePtr node; + + doc = (xmlDocPtr) xmljGetNodeID (env, self); + node = xmljGetNodeID (env, jnode); + + if (node == NULL) + { + xmljThrowDOMException (env, 8, NULL); /* NOT_FOUND_ERR */ + return NULL; + } + if (node->type == XML_DOCUMENT_NODE || + node->type == XML_DOCUMENT_TYPE_NODE || + node->type == XML_ENTITY_NODE || + node->type == XML_NOTATION_NODE) + { + xmljThrowDOMException (env, 9, NULL); /* NOT_SUPPORTED_ERR */ + return NULL; + } + xmlUnlinkNode (node); + node = xmlDocCopyNode (node, doc, 1); + return xmljGetNodeInstance (env, node); +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeDocument_renameNode (JNIEnv * env, + jobject self + __attribute__ ((__unused__)), + jobject n + __attribute__ ((__unused__)), + jstring namespaceURI + __attribute__ ((__unused__)), + jstring qName + __attribute__ ((__unused__))) +{ + xmlNodePtr node; + xmlNsPtr ns; + const xmlChar *s_qName; + const xmlChar *href; + const xmlChar *prefix; + int *len; + + node = xmljGetNodeID (env, n); + if (node == NULL) + { + xmljThrowDOMException (env, 8, NULL); /* NOT_FOUND_ERR */ + return NULL; + } + s_qName = xmljGetStringChars (env, qName); + if (xmlValidateQName (s_qName, 0)) + { + xmljThrowDOMException (env, 5, NULL); /* INVALID_CHARACTER_ERR */ + return NULL; + } + xmlNodeSetName (node, s_qName); + + href = xmljGetStringChars (env, namespaceURI); + len = (int *) malloc (sizeof (int)); + prefix = xmlSplitQName3 (s_qName, len); + ns = node->ns; + if (ns == NULL) + { + if (href != NULL) + { + ns = xmlNewNs (node, href, prefix); + xmlSetNs (node, ns); + } + } + else + { + node->ns = NULL; + /*xmlFreeNs (ns); FIXME this can segfault (?) */ + if (href != NULL) + { + ns = xmlNewNs (node, href, prefix); + xmlSetNs (node, ns); + } + } + free (len); + return n; +} + +/* -- GnomeDocumentBuilder -- */ + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeDocumentBuilder_parseStream (JNIEnv * env, + jobject self, + jobject in, + jbyteArray + detectBuffer, + jstring publicId, + jstring systemId, + jstring base, + jboolean validate, + jboolean coalesce, + jboolean + expandEntities, + jboolean + entityResolver, + jboolean + errorHandler) +{ + xmlDocPtr doc; + + doc = xmljParseDocument(env, + self, + in, + detectBuffer, + publicId, + systemId, + base, + validate, + coalesce, + expandEntities, + 0, + 0, + entityResolver, + errorHandler, + 0, + 0, + 1); + return xmljCreateDocument (env, self, doc); +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeDocumentBuilder_createDocument +(JNIEnv * env, + jobject self, + jstring namespaceURI, + jstring qualifiedName, + jobject doctype) +{ + xmlDocPtr doc; + xmlNodePtr root; + xmlNsPtr ns; + const xmlChar *href; + const xmlChar *prefix; + const xmlChar *qName; + + qName = xmljGetStringChars (env, qualifiedName); + href = xmljGetStringChars (env, namespaceURI); + if (qName == NULL) + { + prefix = NULL; + } + else + { + int *len; + + len = (int *) malloc (sizeof (int)); + prefix = xmlSplitQName3 (qName, len); + free (len); + } + + /* Create the document node */ + doc = xmlNewDoc (BAD_CAST "1.0"); + + /* doctype */ + if (doctype != NULL) + { + jclass cls; + jmethodID method; + jstring ret; + const xmlChar *name; + const xmlChar *publicId; + const xmlChar *systemId; + const xmlChar *internalSubset; + xmlDtdPtr dtd; + + cls = (*env)->FindClass (env, "org/w3c/dom/DocumentType"); + if (cls == NULL) + { + return NULL; + } + /* name */ + method = (*env)->GetMethodID (env, cls, "getName", + "()Ljava/lang/String;"); + if (method == NULL) + { + return NULL; + } + ret = (jstring) (*env)->CallObjectMethod (env, doctype, method); + name = xmljGetStringChars (env, ret); + + /* publicId */ + method = (*env)->GetMethodID (env, cls, "getPublicId", + "()Ljava/lang/String;"); + if (method == NULL) + { + return NULL; + } + ret = (jstring) (*env)->CallObjectMethod (env, doctype, method); + publicId = xmljGetStringChars (env, ret); + + /* systemId */ + method = (*env)->GetMethodID (env, cls, "getSystemId", + "()Ljava/lang/String;"); + if (method == NULL) + { + return NULL; + } + ret = (jstring) (*env)->CallObjectMethod (env, doctype, method); + systemId = xmljGetStringChars (env, ret); + + /* internalSubset */ + method = (*env)->GetMethodID (env, cls, "getInternalSubset", + "()Ljava/lang/String;"); + if (method == NULL) + { + return NULL; + } + ret = (jstring) (*env)->CallObjectMethod (env, doctype, method); + internalSubset = xmljGetStringChars (env, ret); + + /* TODO notations */ + /* TODO entities */ + if (internalSubset == NULL) + { + dtd = xmlNewDtd (doc, name, publicId, systemId); + } + else + { + dtd = xmlCreateIntSubset (doc, name, publicId, systemId); + /* TODO parse internal subset? */ + xmljThrowDOMException (env, 9, NULL); /* NOT_SUPPORTED_ERR */ + return NULL; + } + } + + /* Create the root element */ + root = xmlNewNode (NULL, qName); + xmlDocSetRootElement (doc, root); + ns = xmlNewNs (root, href, prefix); + xmlSetNs (root, ns); + + return xmljCreateDocument (env, self, doc); +} + +/* -- GnomeDocumentType -- */ + +JNIEXPORT jstring JNICALL +Java_gnu_xml_libxmlj_dom_GnomeDocumentType_getPublicId (JNIEnv * env, + jobject self) +{ + xmlDtdPtr dtd; + + dtd = (xmlDtdPtr) xmljGetNodeID (env, self); + return xmljNewString (env, dtd->ExternalID); +} + +JNIEXPORT jstring JNICALL +Java_gnu_xml_libxmlj_dom_GnomeDocumentType_getSystemId (JNIEnv * env, + jobject self) +{ + xmlDtdPtr dtd; + + dtd = (xmlDtdPtr) xmljGetNodeID (env, self); + return xmljNewString (env, dtd->SystemID); +} + +JNIEXPORT jstring JNICALL +Java_gnu_xml_libxmlj_dom_GnomeDocumentType_getInternalSubset (JNIEnv * env, + jobject self + __attribute__ ((__unused__))) +{ + /* TODO */ + xmljThrowDOMException (env, 9, NULL); /* NOT_SUPPORTED_ERR */ + return NULL; +} + +/* -- GnomeElement -- */ + +JNIEXPORT jstring JNICALL +Java_gnu_xml_libxmlj_dom_GnomeElement_getAttribute (JNIEnv * env, + jobject self, + jstring name) +{ + xmlNodePtr node; + const xmlChar *s_name; + const xmlChar *s_value; + + node = xmljGetNodeID (env, self); + s_name = xmljGetStringChars (env, name); + s_value = xmlGetProp (node, s_name); + xmlFree ((xmlChar *) s_name); + return (s_value == NULL) ? + xmljNewString (env, BAD_CAST "") : + xmljNewString (env, s_value); +} + +JNIEXPORT void JNICALL +Java_gnu_xml_libxmlj_dom_GnomeElement_setAttribute (JNIEnv * env, + jobject self, + jstring name, + jstring value) +{ + xmlNodePtr node; + const xmlChar *s_name; + const xmlChar *s_value; + + node = xmljGetNodeID (env, self); + s_name = xmljGetStringChars (env, name); + if (xmlValidateName (s_name, 0)) + { + xmljThrowDOMException (env, 5, NULL); /* INVALID_CHARACTER_ERR */ + return; + } + s_value = xmljGetStringChars (env, value); + xmlSetProp (node, s_name, s_value); +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeElement_getAttributeNode (JNIEnv * env, + jobject self, + jstring name) +{ + xmlNodePtr node; + const xmlChar *s_name; + xmlAttrPtr attr; + + node = xmljGetNodeID (env, self); + s_name = xmljGetStringChars (env, name); + attr = xmlHasProp (node, s_name); + if (attr == NULL) + { + return NULL; + } + xmlFree ((xmlChar *) s_name); + return xmljGetNodeInstance (env, (xmlNodePtr) attr); +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeElement_setAttributeNode (JNIEnv * env, + jobject self, + jobject newAttr) +{ + xmlNodePtr node; + xmlAttrPtr new_attr; + xmlAttrPtr old_attr; + + node = xmljGetNodeID (env, self); + new_attr = (xmlAttrPtr) xmljGetNodeID (env, newAttr); + if (new_attr->parent != NULL) + { + xmljThrowDOMException (env, 10, NULL); /* INUSE_ATTRIBUTE_ERR */ + return NULL; + } + if (new_attr->doc != node->doc) + { + xmljThrowDOMException (env, 4, NULL); /* WRONG_DOCUMENT_ERR */ + return NULL; + } + old_attr = xmlHasProp (node, new_attr->name); + if (old_attr) + { + xmlUnlinkNode ((xmlNodePtr) old_attr); + } + xmljAddAttribute (node, new_attr); + return xmljGetNodeInstance (env, (xmlNodePtr) old_attr); +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeElement_removeAttributeNode (JNIEnv * env, + jobject self + __attribute__ ((__unused__)), + jobject oldAttr) +{ + xmlNodePtr attr; + + attr = xmljGetNodeID (env, oldAttr); + xmlUnlinkNode (attr); + return oldAttr; +} + +JNIEXPORT jstring JNICALL +Java_gnu_xml_libxmlj_dom_GnomeElement_getAttributeNS (JNIEnv * env, + jobject self, + jstring uri, + jstring localName) +{ + xmlNodePtr node; + const xmlChar *s_uri; + const xmlChar *s_localName; + const xmlChar *s_value; + + node = xmljGetNodeID (env, self); + s_localName = xmljGetStringChars (env, localName); + if (uri == NULL) + { + s_value = xmlGetNoNsProp (node, s_localName); + } + else + { + s_uri = xmljGetStringChars (env, uri); + s_value = xmlGetNsProp (node, s_localName, s_uri); + xmlFree ((xmlChar *) s_uri); + } + xmlFree ((xmlChar *) s_localName); + return (s_value == NULL) ? + xmljNewString (env, BAD_CAST "") : + xmljNewString (env, s_value); +} + +JNIEXPORT void JNICALL +Java_gnu_xml_libxmlj_dom_GnomeElement_setAttributeNS (JNIEnv * env, + jobject self, + jstring uri, + jstring qName, + jstring value) +{ + xmlNodePtr node; + xmlNsPtr ns; + const xmlChar *s_uri; + const xmlChar *s_qName; + const xmlChar *s_prefix; + const xmlChar *s_localName; + const xmlChar *s_value; + + node = xmljGetNodeID (env, self); + s_qName = xmljGetStringChars (env, qName); + if (xmlValidateQName (s_qName, 0)) + { + xmljThrowDOMException (env, 5, NULL); /* INVALID_CHARACTER_ERR */ + return; + } + s_value = xmljGetStringChars (env, value); + if (uri == NULL) + { + xmlSetProp (node, s_qName, s_value); + } + else + { + s_prefix = xmljGetPrefix (s_qName); + s_localName = xmljGetLocalName (s_qName); + s_uri = xmljGetStringChars (env, uri); + ns = xmlNewNs (node, s_uri, s_prefix); + xmlSetNsProp (node, ns, s_localName, s_value); + } +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeElement_getAttributeNodeNS (JNIEnv * env, + jobject self, + jstring uri, + jstring localName) +{ + xmlNodePtr node; + xmlAttrPtr attr; + const xmlChar *s_uri; + const xmlChar *s_localName; + + node = xmljGetNodeID (env, self); + attr = node->properties; + s_uri = xmljGetStringChars (env, uri); + s_localName = xmljGetStringChars (env, localName); + while (attr != NULL) + { + if (uri == NULL) + { + if (xmljMatch (s_localName, (xmlNodePtr) attr)) + break; + } + else + { + if (xmljMatchNS (s_uri, s_localName, (xmlNodePtr) attr)) + break; + } + attr = attr->next; + } + xmlFree ((xmlChar *) s_uri); + xmlFree ((xmlChar *) s_localName); + return xmljGetNodeInstance (env, (xmlNodePtr) attr); +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeElement_setAttributeNodeNS (JNIEnv * env, + jobject self, + jobject newAttr) +{ + xmlNodePtr node; + xmlAttrPtr new_attr; + xmlAttrPtr old_attr; + const xmlChar *uri; + + node = xmljGetNodeID (env, self); + new_attr = (xmlAttrPtr) xmljGetNodeID (env, newAttr); + if (new_attr->parent != NULL) + { + xmljThrowDOMException (env, 10, NULL); /* INUSE_ATTRIBUTE_ERR */ + return NULL; + } + if (new_attr->doc != node->doc) + { + xmljThrowDOMException (env, 4, NULL); /* WRONG_DOCUMENT_ERR */ + return NULL; + } + uri = (new_attr->ns != NULL) ? new_attr->ns->href : NULL; + old_attr = xmlHasNsProp (node, new_attr->name, uri); + if (old_attr) + { + xmlUnlinkNode ((xmlNodePtr) old_attr); + } + xmljAddAttribute (node, new_attr); + return xmljGetNodeInstance (env, (xmlNodePtr) old_attr); +} + +JNIEXPORT jboolean JNICALL +Java_gnu_xml_libxmlj_dom_GnomeElement_hasAttribute (JNIEnv * env, + jobject self, + jstring name) +{ + xmlNodePtr node; + const xmlChar *s_name; + const xmlChar *s_value; + + node = xmljGetNodeID (env, self); + s_name = xmljGetStringChars (env, name); + s_value = xmlGetProp (node, s_name); + xmlFree ((xmlChar *) s_name); + return (s_value != NULL); +} + +JNIEXPORT jboolean JNICALL +Java_gnu_xml_libxmlj_dom_GnomeElement_hasAttributeNS (JNIEnv * env, + jobject self, + jstring uri, + jstring localName) +{ + xmlNodePtr node; + const xmlChar *s_uri; + const xmlChar *s_localName; + const xmlChar *s_value; + + node = xmljGetNodeID (env, self); + s_localName = xmljGetStringChars (env, localName); + if (uri == NULL) + { + s_value = xmlGetNoNsProp (node, s_localName); + } + else + { + s_uri = xmljGetStringChars (env, uri); + s_value = xmlGetNsProp (node, s_localName, s_uri); + xmlFree ((xmlChar *) s_uri); + } + xmlFree ((xmlChar *) s_localName); + return (s_value != NULL); +} + +/* -- GnomeEntity -- */ + +JNIEXPORT jstring JNICALL +Java_gnu_xml_libxmlj_dom_GnomeEntity_getPublicId (JNIEnv * env, jobject self) +{ + xmlEntityPtr entity; + + entity = (xmlEntityPtr) xmljGetNodeID (env, self); + return xmljNewString (env, entity->ExternalID); +} + +JNIEXPORT jstring JNICALL +Java_gnu_xml_libxmlj_dom_GnomeEntity_getSystemId (JNIEnv * env, jobject self) +{ + xmlEntityPtr entity; + + entity = (xmlEntityPtr) xmljGetNodeID (env, self); + return xmljNewString (env, entity->SystemID); +} + +JNIEXPORT jstring JNICALL +Java_gnu_xml_libxmlj_dom_GnomeEntity_getNotationName (JNIEnv * env, + jobject self + __attribute__ ((__unused__))) +{ + /* TODO */ + xmljThrowDOMException (env, 9, NULL); /* NOT_SUPPORTED_ERR */ + return NULL; +} + +/* -- GnomeNamedNodeMap -- */ + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNamedNodeMap_getNamedItem (JNIEnv * env, + jobject self, + jstring name) +{ + jclass cls; + jfieldID field; + jint type; + + cls = (*env)->GetObjectClass (env, self); + field = (*env)->GetFieldID (env, cls, "type", "I"); + type = (*env)->GetIntField (env, self, field); + + if (type == 0) + { + xmlAttrPtr attr; + + attr = xmljGetNamedItem (env, self, name); + return xmljGetNodeInstance (env, (xmlNodePtr) attr); + } + else + { + xmlDtdPtr dtd; + xmlHashTablePtr hash; + const xmlChar *s_name; + xmlNodePtr ret; + + dtd = (xmlDtdPtr) xmljGetNodeID (env, self); + hash = (xmlHashTablePtr) ((type == 1) ? dtd->entities : dtd->notations); + if (hash == NULL) + { + return NULL; + } + s_name = xmljGetStringChars (env, name); + ret = (xmlNodePtr) xmlHashLookup (hash, s_name); + xmlFree ((xmlChar *) s_name); + return xmljGetNodeInstance (env, ret); + } +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNamedNodeMap_setNamedItem (JNIEnv * env, + jobject self, + jobject arg) +{ + jclass cls; + jfieldID field; + jint type; + xmlNodePtr node; + xmlNodePtr argNode; + + cls = (*env)->GetObjectClass (env, self); + field = (*env)->GetFieldID (env, cls, "type", "I"); + type = (*env)->GetIntField (env, self, field); + + node = xmljGetNodeID (env, self); + argNode = xmljGetNodeID (env, arg); + + if (argNode->doc != node->doc) + { + xmljThrowDOMException (env, 4, NULL); /* WRONG_DOCUMENT_ERR */ + } + xmljValidateChildNode (env, node, argNode); + if ((*env)->ExceptionOccurred (env)) + { + return NULL; + } + if (type == 0) + { + if (argNode->parent != NULL) + { + xmljThrowDOMException (env, 10, NULL); /* INUSE_ATTRIBUTE_ERR */ + return NULL; + } + xmlAddChild (node, argNode); + } + else + { + xmlDtdPtr dtd; + xmlHashTablePtr hash; + + dtd = (xmlDtdPtr) xmljGetNodeID (env, self); + hash = (xmlHashTablePtr) ((type == 1) ? dtd->entities : dtd->notations); + if (hash == NULL) + { + hash = xmlHashCreate (10); + if (type == 1) + { + dtd->entities = hash; + } + else + { + dtd->notations = hash; + } + } + xmlHashAddEntry (hash, argNode->name, argNode); + } + return arg; +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNamedNodeMap_removeNamedItem (JNIEnv * env, + jobject self, + jstring name) +{ + jclass cls; + jfieldID field; + jint type; + + cls = (*env)->GetObjectClass (env, self); + field = (*env)->GetFieldID (env, cls, "type", "I"); + type = (*env)->GetIntField (env, self, field); + + if (type == 0) + { + xmlAttrPtr attr; + + attr = xmljGetNamedItem (env, self, name); + if (attr == NULL) + { + xmljThrowDOMException (env, 8, NULL); /* NOT_FOUND_ERR */ + return NULL; + } + xmlUnlinkNode ((xmlNodePtr) attr); + return xmljGetNodeInstance (env, (xmlNodePtr) attr); + } + else + { + xmlDtdPtr dtd; + xmlHashTablePtr hash; + const xmlChar *s_name; + xmlNodePtr ret; + + dtd = (xmlDtdPtr) xmljGetNodeID (env, self); + hash = (xmlHashTablePtr) ((type == 1) ? dtd->entities : dtd->notations); + if (hash == NULL) + { + return NULL; + } + s_name = xmljGetStringChars (env, name); + ret = (xmlNodePtr) xmlHashLookup (hash, s_name); + if (ret != NULL) + { + xmlHashRemoveEntry (hash, s_name, NULL); + } + xmlFree ((xmlChar *) s_name); + return xmljGetNodeInstance (env, ret); + } +} + +void +xmljHashScanner (void *payload, void *vdata, xmlChar *name) +{ + xmljHashScanData *data; + + data = (xmljHashScanData *) vdata; + if (data->count <= data->index) + { + data->node = (xmlNodePtr) payload; + } + data->count++; +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNamedNodeMap_item (JNIEnv * env, + jobject self, jint index) +{ + jclass cls; + jfieldID field; + jint type; + + cls = (*env)->GetObjectClass (env, self); + field = (*env)->GetFieldID (env, cls, "type", "I"); + type = (*env)->GetIntField (env, self, field); + + if (type == 0) + { + xmlNodePtr node; + xmlAttrPtr attr; + jint count; + + node = xmljGetNodeID (env, self); + switch (node->type) + { + case XML_ELEMENT_NODE: + attr = node->properties; + for (count = 0; attr != NULL && count < index; count++) + { + attr = attr->next; + } + if (attr == NULL) + { + char msg[1024]; + sprintf (msg, "No attribute at index %d\n", (int) index); + xmljThrowException (env, "java/lang/NullPointerException", msg); + return NULL; + } + return xmljGetNodeInstance (env, (xmlNodePtr) attr); + default: + return NULL; + } + } + else + { + xmlDtdPtr dtd; + xmlHashTablePtr hash; + xmljHashScanData *data; + xmlNodePtr ret; + + dtd = (xmlDtdPtr) xmljGetNodeID (env, self); + hash = (xmlHashTablePtr) ((type == 1) ? dtd->entities : dtd->notations); + if (hash == NULL) + { + return NULL; + } + data = (xmljHashScanData *) malloc (sizeof (xmljHashScanData)); + if (data == NULL) + { + return NULL; + } + data->index = index; + data->count = 0; + data->node = NULL; + xmlHashScan (hash, xmljHashScanner, data); + ret = data->node; + free (data); + return xmljGetNodeInstance (env, ret); + } +} + +JNIEXPORT jint JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNamedNodeMap_getLength (JNIEnv * env, + jobject self) +{ + jclass cls; + jfieldID field; + jint type; + + cls = (*env)->GetObjectClass (env, self); + field = (*env)->GetFieldID (env, cls, "type", "I"); + type = (*env)->GetIntField (env, self, field); + + if (type == 0) + { + xmlNodePtr node; + xmlAttrPtr attr; + jint count; + + node = xmljGetNodeID (env, self); + switch (node->type) + { + case XML_ELEMENT_NODE: + count = 0; + attr = node->properties; + while (attr != NULL) + { + count++; + attr = attr->next; + } + return count; + default: + return -1; + } + } + else + { + xmlDtdPtr dtd; + xmlHashTablePtr hash; + xmljHashScanData *data; + jint ret; + + dtd = (xmlDtdPtr) xmljGetNodeID (env, self); + hash = (xmlHashTablePtr) ((type == 1) ? dtd->entities : dtd->notations); + if (hash == NULL) + { + return 0; + } + data = (xmljHashScanData *) malloc (sizeof (xmljHashScanData)); + if (data == NULL) + { + return 0; + } + data->index = -1; + data->count = 0; + data->node = NULL; + xmlHashScan (hash, xmljHashScanner, data); + ret = data->count; + free (data); + return ret; + } +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNamedNodeMap_getNamedItemNS (JNIEnv * env, + jobject self, + jstring uri, + jstring localName) +{ + jclass cls; + jfieldID field; + jint type; + + cls = (*env)->GetObjectClass (env, self); + field = (*env)->GetFieldID (env, cls, "type", "I"); + type = (*env)->GetIntField (env, self, field); + + if (type == 0) + { + xmlAttrPtr attr; + + attr = xmljGetNamedItemNS (env, self, uri, localName); + return xmljGetNodeInstance (env, (xmlNodePtr) attr); + } + else + { + return NULL; + } +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNamedNodeMap_setNamedItemNS (JNIEnv * env, + jobject self, + jobject arg) +{ + return Java_gnu_xml_libxmlj_dom_GnomeNamedNodeMap_setNamedItem (env, self, + arg); +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNamedNodeMap_removeNamedItemNS (JNIEnv * env, + jobject self, + jstring uri, + jstring + localName) +{ + jclass cls; + jfieldID field; + jint type; + + cls = (*env)->GetObjectClass (env, self); + field = (*env)->GetFieldID (env, cls, "type", "I"); + type = (*env)->GetIntField (env, self, field); + + if (type == 0) + { + xmlAttrPtr attr; + + attr = xmljGetNamedItemNS (env, self, uri, localName); + if (attr == NULL) + { + xmljThrowDOMException (env, 8, NULL); /* NOT_FOUND_ERR */ + return NULL; + } + else + { + xmlUnlinkNode ((xmlNodePtr) attr); + return xmljGetNodeInstance (env, (xmlNodePtr) attr); + } + } + else + { + return NULL; + } +} + +/* -- GnomeNode -- */ + +JNIEXPORT jstring JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNode_getNodeName (JNIEnv * env, jobject self) +{ + xmlNodePtr node; + + node = xmljGetNodeID (env, self); + if (node == NULL) + { + return NULL; + } + return xmljNewString (env, node->name); +} + +xmlChar * +xmljGetNodeValue (xmlNodePtr node) +{ + /* If not character data, return null */ + switch (node->type) + { + case XML_TEXT_NODE: + case XML_CDATA_SECTION_NODE: + case XML_COMMENT_NODE: + case XML_ATTRIBUTE_NODE: + return xmlNodeGetContent (node); + default: + return NULL; + } +} + +JNIEXPORT jstring JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNode_getNodeValue (JNIEnv * env, jobject self) +{ + xmlNodePtr node; + xmlChar *text; + jstring ret; + + node = xmljGetNodeID (env, self); + text = xmljGetNodeValue (node); + ret = xmljNewString (env, (const xmlChar *) text); + if (text != NULL) + { + xmlFree (text); + } + return ret; +} + +JNIEXPORT void JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNode_setNodeValue (JNIEnv * env, + jobject self, + jstring nodeValue) +{ + xmlNodePtr node; + const xmlChar *s_nodeValue; + + node = xmljGetNodeID (env, self); + + /* If not character data, return */ + if (node->type != XML_TEXT_NODE && + node->type != XML_CDATA_SECTION_NODE && node->type != XML_COMMENT_NODE) + return; + + s_nodeValue = xmljGetStringChars (env, nodeValue); + xmlNodeSetContent (node, s_nodeValue); +} + +JNIEXPORT jshort JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNode_getNodeType (JNIEnv * env, jobject self) +{ + xmlNodePtr node; + + node = xmljGetNodeID (env, self); + switch (node->type) + { + case XML_DTD_NODE: + return XML_DOCUMENT_TYPE_NODE; + case XML_ATTRIBUTE_DECL: + return XML_ATTRIBUTE_NODE; + case XML_ENTITY_DECL: + return XML_ENTITY_NODE; + default: + return node->type; + } +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNode_getParentNode (JNIEnv * env, jobject self) +{ + xmlNodePtr node; + + node = xmljGetNodeID (env, self); + return xmljGetNodeInstance (env, node->parent); +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNode_getFirstChild (JNIEnv * env, jobject self) +{ + xmlNodePtr node; + + node = xmljGetNodeID (env, self); + return xmljGetNodeInstance (env, node->children); +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNode_getLastChild (JNIEnv * env, jobject self) +{ + xmlNodePtr node; + + node = xmljGetNodeID (env, self); + return xmljGetNodeInstance (env, node->last); +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNode_getPreviousSibling (JNIEnv * env, + jobject self) +{ + xmlNodePtr node; + + node = xmljGetNodeID (env, self); + return xmljGetNodeInstance (env, node->prev); +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNode_getNextSibling (JNIEnv * env, jobject self) +{ + xmlNodePtr node; + + node = xmljGetNodeID (env, self); + return xmljGetNodeInstance (env, node->next); +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNode_getOwnerDocument (JNIEnv * env, + jobject self) +{ + xmlNodePtr node; + + node = xmljGetNodeID (env, self); + return xmljGetNodeInstance (env, (xmlNodePtr) node->doc); +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNode_xmljInsertBefore (JNIEnv * env, + jobject self, + jobject newChild, + jobject refChild) +{ + xmlNodePtr node; + xmlNodePtr newChildNode; + xmlNodePtr refChildNode; + + node = xmljGetNodeID (env, self); + newChildNode = xmljGetNodeID (env, newChild); + refChildNode = xmljGetNodeID (env, refChild); + + /* Is refChildNode a child of this node? */ + if (refChildNode == NULL || + refChildNode->parent == NULL || + refChildNode->parent != node) + { + xmljThrowDOMException (env, 8, NULL); /* NOT_FOUND_ERR */ + return NULL; + } + /* Check new child */ + xmljValidateChildNode (env, node, newChildNode); + if ((*env)->ExceptionOccurred (env)) + { + return NULL; + } + + newChildNode = xmlAddPrevSibling (refChildNode, newChildNode); + return xmljGetNodeInstance (env, newChildNode); +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNode_xmljReplaceChild (JNIEnv * env, + jobject self, + jobject newChild, + jobject oldChild) +{ + xmlNodePtr node; + xmlNodePtr newChildNode; + xmlNodePtr oldChildNode; + + node = xmljGetNodeID (env, self); + newChildNode = xmljGetNodeID (env, newChild); + oldChildNode = xmljGetNodeID (env, oldChild); + + /* Is oldChildNode a child of this node? */ + if (oldChildNode == NULL || + oldChildNode->parent == NULL || + oldChildNode->parent != node) + { + xmljThrowDOMException (env, 8, NULL); /* NOT_FOUND_ERR */ + return NULL; + } + /* Check new child */ + xmljValidateChildNode (env, node, newChildNode); + if ((*env)->ExceptionOccurred (env)) + { + return NULL; + } + + newChildNode = xmlReplaceNode (oldChildNode, newChildNode); + return xmljGetNodeInstance (env, newChildNode); +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNode_xmljRemoveChild (JNIEnv * env, + jobject self, + jobject oldChild) +{ + xmlNodePtr node; + xmlNodePtr oldChildNode; + + node = xmljGetNodeID (env, self); + oldChildNode = xmljGetNodeID (env, oldChild); + + if (oldChildNode == NULL || + oldChildNode->parent == NULL || + oldChildNode->parent != node) + { + xmljThrowDOMException (env, 8, NULL); /* NOT_FOUND_ERR */ + return NULL; + } + xmlUnlinkNode (oldChildNode); + return oldChild; +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNode_xmljAppendChild (JNIEnv * env, + jobject self, + jobject newChild) +{ + xmlNodePtr node; + xmlNodePtr newChildNode; + + node = xmljGetNodeID (env, self); + newChildNode = xmljGetNodeID (env, newChild); + + /* Check new child */ + xmljValidateChildNode (env, node, newChildNode); + if ((*env)->ExceptionOccurred (env)) + { + return NULL; + } + + newChildNode = xmlAddChild (node, newChildNode); + return xmljGetNodeInstance (env, newChildNode); +} + +JNIEXPORT jboolean JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNode_hasChildNodes (JNIEnv * env, jobject self) +{ + xmlNodePtr node; + + node = xmljGetNodeID (env, self); + return (node->children != NULL); +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNode_xmljCloneNode (JNIEnv * env, + jobject self, jboolean deep) +{ + xmlNodePtr node; + xmlNodePtr clone; + + node = xmljGetNodeID (env, self); + clone = xmlCopyNode (node, deep); + clone->parent = NULL; + clone->doc = node->doc; + return xmljGetNodeInstance (env, clone); +} + +JNIEXPORT void JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNode_normalize (JNIEnv * env, jobject self) +{ + xmlNodePtr node; + + node = xmljGetNodeID (env, self); + xmljNormalizeNode (node); +} + +void +xmljNormalizeNode (xmlNodePtr node) +{ + xmlNodePtr cur; + xmlNodePtr last = NULL; + + cur = node->children; + while (cur != NULL) + { + switch (cur->type) + { + case XML_CDATA_SECTION_NODE: + case XML_TEXT_NODE: + if (xmlIsBlankNode (cur)) + { + xmlNodePtr next = cur->next; + xmlUnlinkNode (cur); + xmlFreeNode (cur); + cur = next; + continue; + } + if (last != NULL) + { + last = xmlTextMerge (last, cur); + xmlUnlinkNode (cur); + xmlFreeNode (cur); + cur = last; + } + else + { + last = cur; + } + break; + default: + last = NULL; + xmljNormalizeNode (cur); + } + cur = cur->next; + } +} + +JNIEXPORT jstring JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNode_getNamespaceURI (JNIEnv * env, + jobject self) +{ + xmlNodePtr node; + + node = xmljGetNodeID (env, self); + if (node->type != XML_ELEMENT_NODE && + node->type != XML_ATTRIBUTE_NODE) + { + return NULL; + } + if (node->ns == NULL) + { + return NULL; + } + return xmljNewString (env, node->ns->href); +} + +JNIEXPORT jstring JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNode_getPrefix (JNIEnv * env, jobject self) +{ + xmlNodePtr node; + + node = xmljGetNodeID (env, self); + if (node->type != XML_ELEMENT_NODE && + node->type != XML_ATTRIBUTE_NODE) + { + return NULL; + } + if (node->ns == NULL) + { + return NULL; + } + return xmljNewString (env, node->ns->prefix); +} + +JNIEXPORT void JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNode_setPrefix (JNIEnv * env, + jobject self, jstring prefix) +{ + xmlNodePtr node; + const xmlChar *s_prefix; + + s_prefix = xmljGetStringChars (env, prefix); + if (xmlValidateName (s_prefix, 0)) + { + xmljThrowDOMException (env, 5, NULL); /* INVALID_CHARACTER_ERR */ + } + node = xmljGetNodeID (env, self); + if (node->type != XML_ELEMENT_NODE && + node->type != XML_ATTRIBUTE_NODE) + { + xmljThrowDOMException (env, 3, NULL); /* HIERARCHY_REQUEST_ERR */ + return; + } + if (node->ns == NULL) + { + xmljThrowDOMException (env, 14, NULL); /* NAMESPACE_ERR */ + return; + } + node->ns->prefix = s_prefix; +} + +JNIEXPORT jstring JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNode_getLocalName (JNIEnv * env, jobject self) +{ + xmlNodePtr node; + int *len; + jstring ret; + + node = xmljGetNodeID (env, self); + if (node->name == NULL) + { + return NULL; + } + len = (int *) malloc (sizeof (int)); + if (xmlSplitQName3 (node->name, len) != NULL) + { + ret = xmljNewString (env, node->name + (*len)); + } + else + { + ret = xmljNewString (env, node->name); + } + free (len); + return ret; +} + +JNIEXPORT jboolean JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNode_hasAttributes (JNIEnv * env, jobject self) +{ + xmlNodePtr node; + + node = xmljGetNodeID (env, self); + return (node->properties != NULL); +} + +JNIEXPORT jstring JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNode_getBaseURI (JNIEnv * env, jobject self) +{ + xmlNodePtr node; + xmlChar *baseURI; + jstring ret; + + node = xmljGetNodeID (env, self); + baseURI = xmlNodeGetBase (node->doc, node); + ret = xmljNewString (env, (const xmlChar *) baseURI); + if (baseURI != NULL) + { + xmlFree (baseURI); + } + return ret; +} + +JNIEXPORT jstring JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNode_lookupPrefix (JNIEnv * env, jobject self, + jstring namespaceURI) +{ + xmlNodePtr node; + xmlNsPtr ns; + xmlDocPtr doc; + const xmlChar *s_uri; + + node = xmljGetNodeID (env, self); + doc = node->doc; + /* If this is a document node, search from the root element */ + if (node->type == XML_DOCUMENT_NODE) + { + doc = (xmlDocPtr) node; + node = xmlDocGetRootElement (doc); + } + s_uri = xmljGetStringChars (env, namespaceURI); + ns = xmlSearchNsByHref (doc, node, s_uri); + xmlFree ((xmlChar *) s_uri); + if (ns == NULL) + { + return NULL; + } + return xmljNewString (env, ns->prefix); +} + +JNIEXPORT jboolean JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNode_isDefaultNamespace (JNIEnv * env, + jobject self, + jstring namespaceURI) +{ + xmlNodePtr node; + xmlNsPtr ns; + const xmlChar *s_uri; + + node = xmljGetNodeID (env, self); + s_uri = xmljGetStringChars (env, namespaceURI); + ns = xmlSearchNsByHref (node->doc, node, s_uri); + xmlFree ((xmlChar *) s_uri); + if (ns == NULL) + { + return 0; + } + return (ns->prefix == NULL || xmlStrlen (ns->prefix) == 0); +} + +JNIEXPORT jstring JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNode_lookupNamespaceURI (JNIEnv * env, + jobject self, + jstring prefix) +{ + xmlNodePtr node; + xmlDocPtr doc; + xmlNsPtr ns; + const xmlChar *s_prefix; + + node = xmljGetNodeID (env, self); + doc = node->doc; + /* If this is a document node, search from the root element */ + if (node->type == XML_DOCUMENT_NODE) + { + doc = (xmlDocPtr) node; + node = xmlDocGetRootElement (doc); + } + s_prefix = xmljGetStringChars (env, prefix); + ns = xmlSearchNs (doc, node, s_prefix); + xmlFree ((xmlChar *) s_prefix); + if (ns == NULL) + { + return NULL; + } + return xmljNewString (env, ns->href); +} + +JNIEXPORT jint JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNode_xmljCompareTo (JNIEnv * env, + jobject self, + jobject other) +{ + xmlNodePtr n1, n2, x; + int d1, d2, delta, c; + + n1 = xmljGetNodeID (env, self); + n2 = xmljGetNodeID (env, other); + if (n1->doc != n2->doc) + { + return 0; + } + if (n1->type == XML_ATTRIBUTE_NODE || n2->type == XML_ATTRIBUTE_NODE) + { + return 0; + } + d1 = 0; + for (x = n1->parent; x && x->type != XML_DOCUMENT_NODE; x = x->parent) + { + d1++; + } + d2 = 0; + for (x = n2->parent; x && x->type != XML_DOCUMENT_NODE; x = x->parent) + { + d2++; + } + delta = d1 - d2; + while (d1 > d2) + { + n1 = n1->parent; + d1--; + } + while (d2 > d1) + { + n2 = n2->parent; + d2--; + } + c = xmljCompare (n1, n2); + return (c != 0) ? c : delta; +} + +/* Compare at same level */ +int +xmljCompare (xmlNodePtr n1, xmlNodePtr n2) +{ + int c, i1, i2; + + if (n1->parent == NULL || n1->type == XML_DOCUMENT_NODE || + n2->parent == NULL || n2->type == XML_DOCUMENT_NODE || + n1 == n2) + { + return 0; + } + c = xmljCompare (n1->parent, n2->parent); + if (c != 0) + { + return c; + } + i1 = 0; + for (n1 = n1->prev; n1; n1 = n1->prev) + { + i1++; + } + i2 = 0; + for (n2 = n2->prev; n2; n2 = n2->prev) + { + i2++; + } + return i1 - i2; +} + +int +xmljIsEqualNodeList (xmlNodePtr node1, xmlNodePtr node2) +{ + while (node1 != NULL) + { + if (!xmljIsEqualNode (node1, node2)) + { + return 0; + } + node1 = node1->next; + node2 = node2->next; + } + return 1; +} + +int +xmljIsEqualNode (xmlNodePtr node1, xmlNodePtr node2) +{ + const xmlChar *val1; + const xmlChar *val2; + + if (node1 == node2) + { + return 1; + } + if (node1 == NULL || node2 == NULL) + { + return 0; + } + /* Check node type */ + if (node1->type != node2->type) + { + return 0; + } + /* Check node name */ + if (!xmlStrEqual (node1->name, node2->name)) + { + return 0; + } + /* Check node namespace */ + if (node1->type == XML_ELEMENT_NODE || + node1->type == XML_ATTRIBUTE_NODE) + { + xmlNsPtr ns1, ns2; + + ns1 = node1->ns; + if (ns1 != NULL) + { + ns2 = node2->ns; + if (ns2 == NULL) + { + return 0; + } + val1 = ns1->href; + val2 = ns2->href; + if (!xmlStrEqual (val1, val2)) + { + return 0; + } + } + } + /* Check node value */ + val1 = xmljGetNodeValue (node1); + val2 = xmljGetNodeValue (node2); + if (!xmlStrEqual (val1, val2)) + { + return 0; + } + /* Check attributes */ + if (node1->type == XML_ELEMENT_NODE && + !xmljIsEqualNodeList ((xmlNodePtr) node1->properties, + (xmlNodePtr) node2->properties)) + { + return 0; + } + /* Check doctype */ + if (node1->type == XML_DOCUMENT_NODE) + { + xmlDocPtr doc1 = (xmlDocPtr) node1; + xmlDocPtr doc2 = (xmlDocPtr) node2; + + if (!xmljIsEqualNode ((xmlNodePtr) doc1->intSubset, + (xmlNodePtr) doc2->intSubset) || + !xmljIsEqualNode ((xmlNodePtr) doc1->extSubset, + (xmlNodePtr) doc2->extSubset)) + { + return 0; + } + } + /* Check child nodes */ + if (!xmljIsEqualNodeList (node1->children, node2->children)) + { + return 0; + } + return 1; +} + +JNIEXPORT jboolean JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNode_isEqualNode (JNIEnv * env, + jobject self, + jobject arg) +{ + xmlNodePtr node1; + xmlNodePtr node2; + + node1 = xmljGetNodeID (env, self); + node2 = xmljGetNodeID (env, arg); + return xmljIsEqualNode (node1, node2); +} + +/* -- GnomeNodeList -- */ + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNodeList_item (JNIEnv * env, + jobject self, jint index) +{ + xmlNodePtr node; + jint count; + + node = xmljGetNodeID (env, self); + node = node->children; + count = 0; + for (count = 0; node != NULL && count < index; count++) + { + node = node->next; + } + return xmljGetNodeInstance (env, node); +} + +JNIEXPORT jint JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNodeList_getLength (JNIEnv * env, jobject self) +{ + xmlNodePtr node; + jint count; + + node = xmljGetNodeID (env, self); + count = 0; + node = node->children; + while (node != NULL) + { + count++; + node = node->next; + } + return count; +} + +/* -- GnomeNotation -- */ + +JNIEXPORT jstring JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNotation_getPublicId (JNIEnv * env, + jobject self) +{ + xmlNotationPtr notation; + + notation = (xmlNotationPtr) xmljGetNodeID (env, self); + if (notation->PublicID == NULL) + { + return NULL; + } + return xmljNewString (env, notation->PublicID); +} + +JNIEXPORT jstring JNICALL +Java_gnu_xml_libxmlj_dom_GnomeNotation_getSystemId (JNIEnv * env, + jobject self) +{ + xmlNotationPtr notation; + + notation = (xmlNotationPtr) xmljGetNodeID (env, self); + if (notation->SystemID == NULL) + { + return NULL; + } + return xmljNewString (env, notation->SystemID); +} + +/* -- GnomeProcessingInstruction -- */ + +JNIEXPORT jstring JNICALL +Java_gnu_xml_libxmlj_dom_GnomeProcessingInstruction_getData (JNIEnv * env, + jobject self) +{ + xmlNodePtr node; + xmlChar *text; + jstring ret; + + node = xmljGetNodeID (env, self); + text = xmlNodeGetContent (node); + ret = xmljNewString (env, (const xmlChar *) text); + if (text != NULL) + { + xmlFree (text); + } + return ret; +} + +JNIEXPORT void JNICALL +Java_gnu_xml_libxmlj_dom_GnomeProcessingInstruction_setData (JNIEnv * env, + jobject self, + jstring data) +{ + xmlNodePtr node; + const xmlChar *s_data; + + node = xmljGetNodeID (env, self); + s_data = xmljGetStringChars (env, data); + xmlNodeSetContent (node, s_data); +} + +/* -- GnomeTypeInfo -- */ + +xmlDtdPtr xmljGetDtd (xmlDocPtr doc) +{ + xmlNodePtr ctx; + + for (ctx = doc->children; ctx; ctx = ctx->next) + { + if (ctx->type == XML_DOCUMENT_TYPE_NODE) + { + return (xmlDtdPtr) ctx; + } + } + return NULL; +} + +JNIEXPORT jstring JNICALL +Java_gnu_xml_libxmlj_dom_GnomeTypeInfo_getTypeName (JNIEnv *env, jobject self) +{ + xmlNodePtr node; + xmlDtdPtr dtd; + xmlAttributePtr attribute; + + node = xmljGetNodeID (env, self); + dtd = xmljGetDtd (node->doc); + if (dtd) + { + switch (node->type) + { + case XML_ATTRIBUTE_NODE: + attribute = xmlGetDtdAttrDesc (dtd, node->parent->name, node->name); + if (attribute) + { + switch (attribute->type) + { + case XML_ATTRIBUTE_CDATA: + return xmljNewString (env, BAD_CAST "CDATA"); + case XML_ATTRIBUTE_ID: + return xmljNewString (env, BAD_CAST "ID"); + case XML_ATTRIBUTE_IDREF: + return xmljNewString (env, BAD_CAST "IDREF"); + case XML_ATTRIBUTE_IDREFS: + return xmljNewString (env, BAD_CAST "IDREFS"); + case XML_ATTRIBUTE_ENTITY: + return xmljNewString (env, BAD_CAST "ENTITY"); + case XML_ATTRIBUTE_ENTITIES: + return xmljNewString (env, BAD_CAST "ENTITIES"); + case XML_ATTRIBUTE_NMTOKEN: + return xmljNewString (env, BAD_CAST "NMTOKEN"); + case XML_ATTRIBUTE_NMTOKENS: + return xmljNewString (env, BAD_CAST "NMTOKENS"); + default: + return NULL; + } + } + return NULL; + default: + return NULL; + } + } + /* TODO when XML Schema support is available */ + return NULL; +} + +JNIEXPORT jstring JNICALL +Java_gnu_xml_libxmlj_dom_GnomeTypeInfo_getTypeNamespace (JNIEnv *env, + jobject self) +{ + xmlNodePtr node; + xmlDtdPtr dtd; + xmlAttributePtr attribute; + + node = xmljGetNodeID (env, self); + dtd = xmljGetDtd (node->doc); + if (dtd) + { + switch (node->type) + { + case XML_ATTRIBUTE_NODE: + attribute = xmlGetDtdAttrDesc (dtd, node->parent->name, node->name); + if (attribute) + { + return xmljNewString (env, + BAD_CAST "http://www.w3.org/TR/REC-xml"); + } + return NULL; + default: + return NULL; + } + } + /* TODO when XML Schema support is available */ + return NULL; +} + +JNIEXPORT jboolean JNICALL +Java_gnu_xml_libxmlj_dom_GnomeTypeInfo_isDerivedFrom (JNIEnv *env + __attribute__ ((__unused__)), + jobject self + __attribute__ ((__unused__)), + jstring typeNS + __attribute__ ((__unused__)), + jstring typeName + __attribute__ ((__unused__)), + jint method + __attribute__ ((__unused__))) +{ + /* TODO when XML Schema support is available */ + return 0; +} + +/* -- Utility -- */ + +/* + * Create GnomeDocument object from the given xmlDocPtr + */ +jobject +xmljCreateDocument (JNIEnv * env, jobject self, xmlDocPtr doc) +{ + jclass cls; + jfieldID field; + jobject ret; + + if (!doc) + { + return NULL; + } + + /* Get document object */ + ret = xmljGetNodeInstance (env, (xmlNodePtr) doc); + + /* Set DOM implementation field */ + cls = (*env)->FindClass (env, "gnu/xml/libxmlj/dom/GnomeDocument"); + field = (*env)->GetFieldID (env, cls, "dom", + "Lorg/w3c/dom/DOMImplementation;"); + (*env)->SetObjectField (env, ret, field, self); + return ret; +} + +xmlAttrPtr +xmljGetNamedItem (JNIEnv * env, jobject self, jstring name) +{ + xmlNodePtr node; + xmlAttrPtr attr; + const xmlChar *s_name; + + s_name = xmljGetStringChars (env, name); + + node = xmljGetNodeID (env, self); + attr = node->properties; + while (attr != NULL) + { + if (xmljMatch (s_name, (xmlNodePtr) attr)) + break; + attr = attr->next; + } + xmlFree ((xmlChar *) s_name); + + return attr; +} + +xmlAttrPtr +xmljGetNamedItemNS (JNIEnv * env, jobject self, jstring uri, jstring localName) +{ + xmlNodePtr node; + xmlAttrPtr attr; + const xmlChar *s_uri; + const xmlChar *s_localName; + + s_uri = xmljGetStringChars (env, uri); + s_localName = xmljGetStringChars (env, localName); + + node = xmljGetNodeID (env, self); + attr = node->properties; + while (attr != NULL) + { + if (xmljMatchNS (s_uri, s_localName, (xmlNodePtr) attr)) + break; + attr = attr->next; + } + xmlFree ((xmlChar *) s_uri); + xmlFree ((xmlChar *) s_localName); + + return attr; +} diff --git a/libjava/classpath/native/jni/xmlj/xmlj_dom.h b/libjava/classpath/native/jni/xmlj/xmlj_dom.h new file mode 100644 index 000000000..d4a1dff42 --- /dev/null +++ b/libjava/classpath/native/jni/xmlj/xmlj_dom.h @@ -0,0 +1,70 @@ +/* xmlj_dom.h - + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#ifndef XMLJ_DOM_H +#define XMLJ_DOM_H + +#include "gnu_xml_libxmlj_dom_GnomeAttr.h" +#include "gnu_xml_libxmlj_dom_GnomeDocument.h" +#include "gnu_xml_libxmlj_dom_GnomeDocumentBuilder.h" +#include "gnu_xml_libxmlj_dom_GnomeDocumentType.h" +#include "gnu_xml_libxmlj_dom_GnomeElement.h" +#include "gnu_xml_libxmlj_dom_GnomeEntity.h" +#include "gnu_xml_libxmlj_dom_GnomeNamedNodeMap.h" +#include "gnu_xml_libxmlj_dom_GnomeNode.h" +#include "gnu_xml_libxmlj_dom_GnomeNodeList.h" +#include "gnu_xml_libxmlj_dom_GnomeNotation.h" +#include "gnu_xml_libxmlj_dom_GnomeProcessingInstruction.h" +#include "gnu_xml_libxmlj_dom_GnomeTypeInfo.h" + +#include +#include + +void xmljValidateChildNode (JNIEnv *env, xmlNodePtr parent, xmlNodePtr child); +int xmljIsEqualNode (xmlNodePtr node1, xmlNodePtr node2); +int xmljIsEqualNodeList (xmlNodePtr node1, xmlNodePtr node2); +void xmljNormalizeNode (xmlNodePtr node); +xmlDtdPtr xmljGetDtd (xmlDocPtr doc); +int xmljCompare (xmlNodePtr n1, xmlNodePtr n2); + +/* Utility */ +jobject xmljCreateDocument (JNIEnv * env, jobject self, xmlDocPtr doc); +xmlAttrPtr xmljGetNamedItem (JNIEnv * env, jobject self, jstring name); +xmlAttrPtr xmljGetNamedItemNS (JNIEnv * env, jobject self, jstring uri, + jstring localName); + +#endif /* !defined XMLJ_DOM_H */ diff --git a/libjava/classpath/native/jni/xmlj/xmlj_error.c b/libjava/classpath/native/jni/xmlj/xmlj_error.c new file mode 100644 index 000000000..5dd90552c --- /dev/null +++ b/libjava/classpath/native/jni/xmlj/xmlj_error.c @@ -0,0 +1,169 @@ +/* xmlj_error.c - + Copyright (C) 2003, 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include "xmlj_error.h" +#include "xmlj_io.h" +#include "xmlj_util.h" + +void +xmljXsltErrorFunc (void *ctx, const char *msg, ...) +{ + if (NULL != ctx) + { + SAXParseContext *sax = ((SAXParseContext *) ctx); + + if (NULL != sax) + { + JNIEnv *env = sax->env; + + if (!(*env)->ExceptionOccurred (env)) + { + jobject target = sax->obj; + xmlChar *x_msg; + jstring j_msg; + va_list args; + + if (sax->error == NULL) + { + sax->error = + xmljGetMethodID (env, + target, + "error", + "(Ljava/lang/String;IILjava/lang/String;Ljava/lang/String;)V"); + if (sax->error == NULL) + { + return; + } + } + + va_start (args, msg); + x_msg = (msg == NULL) ? NULL : xmlCharStrdup (msg); + va_end (args); + j_msg = xmljNewString (env, x_msg); + + (*env)->CallVoidMethod (env, + target, + sax->error, + j_msg, + -1, + -1, + NULL, + NULL); + } + } + } + else + { + va_list va; + va_start (va, msg); + fprintf (stderr, "libxslt error: "); + vfprintf (stderr, msg, va); + fflush (stderr); + va_end (va); + } +} + +void +xmljThrowException (JNIEnv *env, + const char *classname, + const char *message) +{ + jclass cls; + jmethodID method; + jthrowable ex; + jstring jmsg; + + /*fprintf(stderr, "Throwing exception %s %s\n", classname, message);*/ + cls = (*env)->FindClass (env, classname); + if (cls == NULL) + { + fprintf (stderr, "Can't find class %s\n", classname); + fflush (stderr); + return; + } + method = (*env)->GetMethodID (env, cls, "", "(Ljava/lang/String;)V"); + if (method == NULL) + { + fprintf (stderr, "Can't find method %s.\n", classname); + fflush (stderr); + return; + } + jmsg = (message == NULL) ? NULL : (*env)->NewStringUTF (env, message); + ex = (jthrowable) (*env)->NewObject (env, cls, method, jmsg); + if (ex == NULL) + { + fprintf (stderr, "Can't instantiate new %s\n", classname); + fflush (stderr); + return; + } + (*env)->Throw (env, ex); +} + +void +xmljThrowDOMException (JNIEnv *env, + int code, + const char *message) +{ + jclass cls; + jmethodID method; + jthrowable ex; + jstring jmsg; + + if ((*env)->ExceptionOccurred (env)) + { + return; + } + + cls = (*env)->FindClass (env, "gnu/xml/libxmlj/dom/GnomeDOMException"); + if (cls == NULL) + { + fprintf (stderr, "Can't find DOMException class!\n"); + fflush (stderr); + return; + } + method = (*env)->GetMethodID (env, cls, "", "(SLjava/lang/String;)V"); + if (method == NULL) + { + fprintf (stderr, "Can't find DOMException constructor!\n"); + fflush (stderr); + return; + } + jmsg = (message == NULL) ? NULL : (*env)->NewStringUTF (env, message); + ex = (jthrowable) (*env)->NewObject (env, cls, method, code, jmsg); + (*env)->Throw (env, ex); +} + diff --git a/libjava/classpath/native/jni/xmlj/xmlj_error.h b/libjava/classpath/native/jni/xmlj/xmlj_error.h new file mode 100644 index 000000000..a0c9fcc80 --- /dev/null +++ b/libjava/classpath/native/jni/xmlj/xmlj_error.h @@ -0,0 +1,85 @@ +/* xmlj_error.h - + Copyright (C) 2003, 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#ifndef XMLJ_ERROR_H +#define XMLJ_ERROR_H + +#include +#include + +/* +typedef struct SaxErrorContext_ +{ + JNIEnv * env; + jobject saxErrorAdapter; + jmethodID saxCommentMethodID; + jmethodID saxWarningMethodID; + jmethodID saxErrorMethodID; + jmethodID saxFatalErrorMethodID; + jclass sourceLocatorClass; + jmethodID sourceLocatorConstructor; + xmlSAXLocatorPtr locator; + jstring publicId; + jstring systemId; + const char *publicIdCstr; + const char *systemIdCstr; + jmethodID resolveURIMethodID; + jmethodID resolveURIAndOpenMethodID; + jmethodID getInputStreamMethodID; + jmethodID xsltGenericErrorMethodID; + jobject theTransformerException; + jmethodID getNativeHandleMethodID; +} SaxErrorContext; + +SaxErrorContext * xmljCreateSaxErrorContext (JNIEnv * env, + jobject errorContext, + jstring systemId, + jstring publicId); + +void xmljFreeSaxErrorContext (SaxErrorContext * errorContext); + +void xmljInitErrorHandling (xmlSAXHandler * saxHandler); +*/ + +void xmljXsltErrorFunc (void *ctx, const char *msg, ...); + +void xmljThrowException (JNIEnv *, const char *classname, const char *message); + +void xmljThrowDOMException (JNIEnv *, int code, const char *message); + +#endif /* !defined XMLJ_ERROR_H */ + diff --git a/libjava/classpath/native/jni/xmlj/xmlj_io.c b/libjava/classpath/native/jni/xmlj/xmlj_io.c new file mode 100644 index 000000000..aa2964dc3 --- /dev/null +++ b/libjava/classpath/native/jni/xmlj/xmlj_io.c @@ -0,0 +1,799 @@ +/* xmlj_io.c - + Copyright (C) 2003, 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include "xmlj_io.h" +#include "xmlj_error.h" +#include "xmlj_node.h" +#include "xmlj_sax.h" +#include "xmlj_util.h" + +#include +#include +#include +#include + +#include +#include + +#include + +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) +#define UNSIGN(a) (((a) < 0) ? ((a) + 0x100) : (a)) + +#define DETECT_BUFFER_SIZE 50 + +typedef struct _OutputStreamContext +{ + + JNIEnv *env; + jobject outputStream; + jmethodID outputStreamWriteFunc; + jmethodID outputStreamCloseFunc; + +} +OutputStreamContext; + +typedef struct _InputStreamContext +{ + + JNIEnv *env; + jobject inputStream; + jmethodID inputStreamReadFunc; + jmethodID inputStreamCloseFunc; + jobject bufferByteArray; + jint bufferLength; + +} +InputStreamContext; + +InputStreamContext *xmljNewInputStreamContext (JNIEnv * env, + jobject inputStream); + +void xmljFreeInputStreamContext (InputStreamContext * inContext); + +int xmljInputReadCallback (void *context, char *buffer, int len); + +int xmljInputCloseCallback (void *context); + +int xmljOutputWriteCallback (void *context, const char *buffer, int len); + +int xmljOutputCloseCallback (void *context); + +OutputStreamContext *xmljNewOutputStreamContext (JNIEnv * env, + jobject outputStream); + +void +xmljFreeOutputStreamContext (OutputStreamContext * outContext); + +xmlCharEncoding +xmljDetectCharEncoding (JNIEnv * env, jbyteArray buffer); + +int +xmljOutputWriteCallback (void *context, const char *buffer, int len) +{ + OutputStreamContext *outContext; + JNIEnv *env; + jbyteArray byteArray; + + outContext = (OutputStreamContext *) context; + env = outContext->env; + byteArray = (*env)->NewByteArray (env, len); + + if (0 != byteArray) + { + (*env)->SetByteArrayRegion (env, byteArray, 0, len, (jbyte *) buffer); + + (*env)->CallVoidMethod (env, + outContext->outputStream, + outContext->outputStreamWriteFunc, byteArray); + + (*env)->DeleteLocalRef (env, byteArray); + + return (*env)->ExceptionOccurred (env) ? -1 : len; + } + else + { + /* Out of memory, signal error */ + return -1; + } +} + +int +xmljOutputCloseCallback (void *context) +{ + OutputStreamContext *outContext; + JNIEnv *env; + + outContext = (OutputStreamContext *) context; + env = outContext->env; + (*env)->CallVoidMethod (env, + outContext->outputStream, + outContext->outputStreamCloseFunc); + + return (*env)->ExceptionOccurred (env) ? -1 : 0; +} + +int +xmljInputReadCallback (void *context, char *buffer, int len) +{ + InputStreamContext *inContext; + JNIEnv *env; + jint nread; + int offset; + + inContext = (InputStreamContext *) context; + env = inContext->env; + nread = 0; + + for (offset = 0; offset < len && nread >= 0;) + { + nread = (*env)->CallIntMethod (env, + inContext->inputStream, + inContext->inputStreamReadFunc, + inContext->bufferByteArray, + 0, MIN (len - offset, + inContext->bufferLength)); + + if (nread > 0) + { + (*env)->GetByteArrayRegion (env, + inContext->bufferByteArray, + 0, nread, ((jbyte *) buffer) + offset); + + offset += nread; + } + } + + return (*env)->ExceptionOccurred (env) ? -1 : offset; +} + +int +xmljInputCloseCallback (void *context) +{ + InputStreamContext *inContext; + JNIEnv *env; + + inContext = (InputStreamContext *) context; + env = inContext->env; + (*env)->CallVoidMethod (env, inContext->inputStream, + inContext->inputStreamCloseFunc); + + return (*env)->ExceptionOccurred (env) ? -1 : 0; +} + +InputStreamContext * +xmljNewInputStreamContext (JNIEnv * env, jobject inputStream) +{ + jclass inputStreamClass; + InputStreamContext *result; + + inputStreamClass = (*env)->FindClass (env, "java/io/InputStream"); + if (inputStreamClass == NULL) + { + return NULL; + } + result = (InputStreamContext *) malloc (sizeof (InputStreamContext)); + if (result == NULL) + { + return NULL; + } + + result->env = env; + result->inputStream = inputStream; + result->inputStreamReadFunc = + (*env)->GetMethodID (env, inputStreamClass, "read", "([BII)I"); + result->inputStreamCloseFunc = + (*env)->GetMethodID (env, inputStreamClass, "close", "()V"); + result->bufferLength = 4096; + result->bufferByteArray = (*env)->NewByteArray (env, result->bufferLength); + return result; +} + +void +xmljFreeInputStreamContext (InputStreamContext * inContext) +{ + JNIEnv *env; + + env = inContext->env; + (*env)->DeleteLocalRef (env, inContext->bufferByteArray); + free (inContext); +} + +OutputStreamContext * +xmljNewOutputStreamContext (JNIEnv * env, jobject outputStream) +{ + jclass outputStreamClass; + OutputStreamContext *result; + + outputStreamClass = (*env)->FindClass (env, "java/io/OutputStream"); + if (outputStreamClass == NULL) + { + return NULL; + } + result = (OutputStreamContext *) malloc (sizeof (OutputStreamContext)); + if (result == NULL) + { + return NULL; + } + + result->env = env; + result->outputStream = outputStream; + result->outputStreamWriteFunc = + (*env)->GetMethodID (env, outputStreamClass, "write", "([B)V"); + result->outputStreamCloseFunc = + (*env)->GetMethodID (env, outputStreamClass, "close", "()V"); + return result; +} + + +void +xmljFreeOutputStreamContext (OutputStreamContext * outContext) +{ + free (outContext); +} + +SAXParseContext * +xmljNewSAXParseContext (JNIEnv * env, jobject obj, xmlParserCtxtPtr ctx, + jstring publicId, jstring systemId) +{ + SAXParseContext *ret; + + ret = (SAXParseContext *) malloc (sizeof (SAXParseContext)); + ret->env = env; + ret->obj = obj; + ret->ctx = ctx; + ret->sax = ctx->sax; + ret->loc = NULL; + ret->publicId = publicId; + ret->systemId = systemId; + + ret->startDTD = NULL; + ret->externalEntityDecl = NULL; + ret->internalEntityDecl = NULL; + ret->resolveEntity = NULL; + ret->notationDecl = NULL; + ret->attributeDecl = NULL; + ret->elementDecl = NULL; + ret->unparsedEntityDecl = NULL; + ret->setDocumentLocator = NULL; + ret->startDocument = NULL; + ret->endDocument = NULL; + ret->startElement = NULL; + ret->endElement = NULL; + ret->characters = NULL; + ret->ignorableWhitespace = NULL; + ret->processingInstruction = NULL; + ret->comment = NULL; + ret->cdataBlock = NULL; + ret->warning = NULL; + ret->error = NULL; + ret->fatalError = NULL; + + ret->resolveURIAndOpen = NULL; + ret->stringClass = NULL; + return ret; +} + +void +xmljFreeSAXParseContext (SAXParseContext * saxCtx) +{ + free (saxCtx); +} + +xmlCharEncoding +xmljDetectCharEncoding (JNIEnv * env, jbyteArray buffer) +{ + xmlCharEncoding ret; + jint nread; + + if (buffer == NULL) + { + return XML_CHAR_ENCODING_ERROR; + } + nread = (*env)->GetArrayLength (env, buffer); + if (nread >= 5) + { + jbyte nativeBuffer[DETECT_BUFFER_SIZE + 1]; + unsigned char converted[DETECT_BUFFER_SIZE + 1]; + int i; + + memset (nativeBuffer, 0, DETECT_BUFFER_SIZE + 1); + (*env)->GetByteArrayRegion (env, buffer, 0, nread, nativeBuffer); + /* Convert from signed to unsigned */ + for (i = 0; i < DETECT_BUFFER_SIZE + 1; i++) + { + converted[i] = UNSIGN (nativeBuffer[i]); + } + ret = xmlDetectCharEncoding (converted, nread); + } + else + { + ret = XML_CHAR_ENCODING_NONE; + } + return ret; +} + +xmlParserCtxtPtr +xmljNewParserContext (JNIEnv * env, + jobject inputStream, + jbyteArray detectBuffer, + jstring publicId, + jstring systemId, + jstring base, + jboolean validate, + jboolean coalesce, + jboolean expandEntities, + jboolean loadEntities) +{ + InputStreamContext *inputContext; + xmlCharEncoding encoding; + xmlParserCtxtPtr ctx; + int options; + + encoding = xmljDetectCharEncoding (env, detectBuffer); + if (encoding != XML_CHAR_ENCODING_ERROR) + { + inputContext = xmljNewInputStreamContext (env, inputStream); + if (NULL != inputContext) + { + /* NOTE: userdata must be NULL for DOM to work */ + ctx = xmlCreateIOParserCtxt (NULL, + NULL, + xmljInputReadCallback, + xmljInputCloseCallback, + inputContext, + encoding); + if (NULL != ctx) + { + ctx->userData = ctx; + + /* Set parsing options */ + options = 0; + if (validate) + { + options |= XML_PARSE_DTDVALID; + } + if (coalesce) + { + options |= XML_PARSE_NOCDATA; + } + if (expandEntities) + { + options |= XML_PARSE_NOENT; + } + if (loadEntities) + { + options |= XML_PARSE_DTDLOAD; + } + if (xmlCtxtUseOptions (ctx, options)) + { + xmljThrowException (env, + "java/lang/RuntimeException", + "Unable to set xmlParserCtxtPtr options"); + } + if (base != NULL) + { + ctx->input->directory = + (*env)->GetStringUTFChars (env, base, 0); + } + return ctx; + } + xmljFreeInputStreamContext (inputContext); + } + } + return NULL; +} + +void +xmljFreeParserContext (xmlParserCtxtPtr ctx) +{ + InputStreamContext *inputStreamContext = NULL; + + if (ctx->input != NULL && ctx->input->buf != NULL) + { + inputStreamContext + = (InputStreamContext *) ctx->input->buf->context; + + } + xmlFreeParserCtxt (ctx); + if (inputStreamContext != NULL) + { + xmljFreeInputStreamContext (inputStreamContext); + } +} + +xmlDocPtr +xmljParseDocument (JNIEnv * env, + jobject self, + jobject in, + jbyteArray detectBuffer, + jstring publicId, + jstring systemId, + jstring base, + jboolean validate, + jboolean coalesce, + jboolean expandEntities, + jboolean contentHandler, + jboolean dtdHandler, + jboolean entityResolver, + jboolean errorHandler, + jboolean declarationHandler, + jboolean lexicalHandler, + int mode) +{ + xmlParserCtxtPtr ctx; + SAXParseContext *saxCtx; + xmlSAXHandlerPtr sax; + + ctx = xmljNewParserContext (env, in, detectBuffer, publicId, systemId, base, + validate, coalesce, expandEntities, + entityResolver); + if (ctx != NULL) + { + saxCtx = xmljNewSAXParseContext (env, self, ctx, publicId, systemId); + if (saxCtx != NULL) + { + sax = xmljNewSAXHandler (contentHandler, + dtdHandler, + entityResolver, + errorHandler, + declarationHandler, + lexicalHandler); + if (sax != NULL) + { + return xmljParseDocument2 (env, + ctx, + saxCtx, + sax, + mode); + } + xmljFreeSAXParseContext (saxCtx); + } + xmljFreeParserContext (ctx); + } + if (!(*env)->ExceptionOccurred (env)) + { + xmljThrowException (env, "java/io/IOException", + "Unable to create parser context"); + } + return NULL; +} + +xmlDocPtr +xmljParseDocument2 (JNIEnv * env, + xmlParserCtxtPtr ctx, + SAXParseContext *saxCtx, + xmlSAXHandlerPtr sax, + int mode) +{ + xmlSAXHandlerPtr orig; + xmlDocPtr doc; + int ret; + + ctx->_private = saxCtx; + ctx->userData = ctx; + orig = ctx->sax; + ctx->sax = sax; + + xmljSetThreadContext (saxCtx); + + ret = xmlParseDocument (ctx); + doc = ctx->myDoc; + if (ret || !doc) + { + const char *msg = ctx->lastError.message; + switch (mode) + { + case 0: + xmljSAXFatalError (ctx, msg); + break; + case 1: + xmljThrowDOMException (env, ret, msg); + break; + case 2: + xmljThrowException (env, + "javax/xml/transform/TransformerException", + msg); + } + } + + xmljClearThreadContext (); + + ctx->sax = orig; + free(sax); + xmljFreeSAXParseContext (saxCtx); + xmljFreeParserContext (ctx); + xmljClearStringCache (); + return doc; +} + +xmlParserInputPtr +xmljNewParserInput (JNIEnv * env, + jobject inputStream, + jbyteArray detectBuffer, + xmlParserCtxtPtr parserContext) +{ + xmlParserInputPtr ret; + xmlParserInputBufferPtr input; + xmlCharEncoding encoding; + + encoding = xmljDetectCharEncoding (env, detectBuffer); + if (encoding != XML_CHAR_ENCODING_ERROR) + { + input = xmljNewParserInputBuffer (env, inputStream, encoding); + if (input != NULL) + { + ret = xmlNewIOInputStream (parserContext, input, encoding); + return ret; + } + xmlFreeParserInputBuffer (input); + } + return NULL; +} + +xmlParserInputBufferPtr +xmljNewParserInputBuffer (JNIEnv * env, + jobject inputStream, xmlCharEncoding encoding) +{ + xmlParserInputBufferPtr ret; + InputStreamContext *inputContext; + + inputContext = xmljNewInputStreamContext (env, inputStream); + if (NULL != inputContext) + { + ret = xmlParserInputBufferCreateIO (&xmljInputReadCallback, + &xmljInputCloseCallback, + inputContext, encoding); + if (ret != NULL) + return ret; + xmljFreeInputStreamContext (inputContext); + } + return NULL; +} + +void +xmljSaveFileToJavaOutputStream (JNIEnv * env, jobject outputStream, + xmlDocPtr tree, + const char *outputEncodingName) +{ + OutputStreamContext *outputContext = + xmljNewOutputStreamContext (env, outputStream); + + xmlCharEncoding outputEncoding = xmlParseCharEncoding (outputEncodingName); + + xmlOutputBufferPtr outputBuffer = + xmlOutputBufferCreateIO (xmljOutputWriteCallback, + xmljOutputCloseCallback, + outputContext, + xmlGetCharEncodingHandler (outputEncoding)); + + /* Write result to output stream */ + + xmlSaveFileTo (outputBuffer, tree, outputEncodingName); + + xmljFreeOutputStreamContext (outputContext); +} + +/* +jobject +xmljResolveURI (SaxErrorContext * saxErrorContext, + const char *URL, const char *ID) +{ + JNIEnv *env = saxErrorContext->env; + + jstring hrefString = (*env)->NewStringUTF (env, URL); + jstring baseString = saxErrorContext->systemId; + + jobject sourceWrapper = (*env)->CallObjectMethod (env, + saxErrorContext-> + saxErrorAdapter, + saxErrorContext-> + resolveURIMethodID, + hrefString, + baseString); + (*env)->DeleteLocalRef (env, hrefString); + + if (NULL == sourceWrapper) + { + return NULL; + } + else + { + jobject sourceInputStream = (*env)->CallObjectMethod (env, + sourceWrapper, + saxErrorContext-> + getInputStreamMethodID); + + (*env)->DeleteLocalRef (env, sourceWrapper); + + if ((*env)->ExceptionOccurred (env)) + { + -* Report to ErrorAdapter here? *- + return NULL; + } + + return sourceInputStream; + } +}*/ + +xmlDocPtr +xmljResolveURIAndOpen (SAXParseContext *saxContext, + const char *URL, + const char *ID) +{ + jobject libxmlDocument; + xmlDocPtr doc; + JNIEnv *env = saxContext->env; + + jstring hrefString = (*env)->NewStringUTF (env, URL); + jstring baseString = saxContext->systemId; + + if (saxContext->resolveURIAndOpen == NULL) + { + jclass cls = (*env)->GetObjectClass (env, saxContext->obj); + saxContext->resolveURIAndOpen = + (*env)->GetMethodID (env, cls, "resolveURIAndOpen", + "Ljava/lang/String;Ljava/lang/String)Lgnu/xml/libxmlj/transform/LibxmlDocument;"); + } + libxmlDocument = + (*env)->CallObjectMethod (env, + saxContext->obj, + saxContext->resolveURIAndOpen, + hrefString, + baseString); + + doc = (xmlDocPtr) xmljGetNodeID (env, libxmlDocument); + + (*env)->DeleteLocalRef (env, libxmlDocument); + + if ((*env)->ExceptionOccurred (env)) + { + /* Report to ErrorAdapter here? */ + return NULL; + } + else + { + return doc; + } +} + +/*xmlParserInputPtr +xmljLoadExternalEntity (const char *URL, const char *ID, + xmlParserCtxtPtr ctxt) +{ + SaxErrorContext *saxErrorContext = xmljGetThreadContext (); + + JNIEnv *env = saxErrorContext->env; + + jstring hrefString = (*env)->NewStringUTF (env, URL); + jstring baseString = saxErrorContext->systemId; + + jobject sourceWrapper = (*env)->CallObjectMethod (env, + saxErrorContext-> + saxErrorAdapter, + saxErrorContext-> + resolveURIMethodID, + hrefString, + baseString); + + (*env)->DeleteLocalRef (env, hrefString); + + if (NULL == sourceWrapper) + { + return NULL; + } + else + { + InputStreamContext *inputContext; + xmlParserInputBufferPtr inputBuffer; + xmlParserInputPtr inputStream; + + jobject sourceInputStream = (*env)->CallObjectMethod (env, + sourceWrapper, + saxErrorContext-> + getInputStreamMethodID); + + (*env)->DeleteLocalRef (env, sourceWrapper); + + if ((*env)->ExceptionOccurred (env)) + { + -* Report to ErrorAdapter *- + return NULL; + } + + inputContext = xmljNewInputStreamContext (env, sourceInputStream); + + inputBuffer + = xmlParserInputBufferCreateIO (xmljInputReadCallback, + xmljInputCloseCallback, + inputContext, XML_CHAR_ENCODING_NONE); + + inputStream = xmlNewInputStream (ctxt); + if (inputStream == NULL) + { + return (NULL); + } + + inputStream->filename = NULL; + inputStream->directory = NULL; + inputStream->buf = inputBuffer; + + inputStream->base = inputStream->buf->buffer->content; + inputStream->cur = inputStream->buf->buffer->content; + inputStream->end = &inputStream->base[inputStream->buf->buffer->use]; + if ((ctxt->directory == NULL) && (inputStream->directory != NULL)) + ctxt->directory = + (char *) xmlStrdup ((const xmlChar *) inputStream->directory); + return (inputStream); + } +}*/ + +/* Key for the thread-specific buffer */ +static pthread_key_t thread_context_key; + +/* Once-only initialisation of the key */ +static pthread_once_t thread_context_once = PTHREAD_ONCE_INIT; + +static void +thread_context_key_alloc (void); + +/* Allocate the key */ +static void +thread_context_key_alloc () +{ + pthread_key_create (&thread_context_key, NULL); +} + +void +xmljSetThreadContext (SAXParseContext * context) +{ + pthread_once (&thread_context_once, thread_context_key_alloc); + pthread_setspecific (thread_context_key, context); +} + +void +xmljClearThreadContext (void) +{ + pthread_setspecific (thread_context_key, NULL); +} + +/* Return the thread-specific buffer */ +SAXParseContext * +xmljGetThreadContext (void) +{ + return (SAXParseContext *) pthread_getspecific (thread_context_key); +} diff --git a/libjava/classpath/native/jni/xmlj/xmlj_io.h b/libjava/classpath/native/jni/xmlj/xmlj_io.h new file mode 100644 index 000000000..871859aca --- /dev/null +++ b/libjava/classpath/native/jni/xmlj/xmlj_io.h @@ -0,0 +1,170 @@ +/* xmlj_io.h - + Copyright (C) 2003, 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#ifndef XMLJ_IO_H +#define XMLJ_IO_H + +#include +#include +#include "xmlj_error.h" + +typedef struct _SAXParseContext +{ + + JNIEnv *env; /* Current JNI environment */ + jobject obj; /* The gnu.xml.libxmlj.sax.GnomeXmlReader instance */ + xmlParserCtxtPtr ctx; /* libxml2 parser context */ + xmlSAXLocatorPtr loc; /* libxml2 SAX locator */ + xmlSAXHandlerPtr sax; /* pristine SAX handler */ + jstring publicId; + jstring systemId; + + jmethodID startDTD; + jmethodID externalEntityDecl; + jmethodID internalEntityDecl; + jmethodID resolveEntity; + jmethodID notationDecl; + jmethodID attributeDecl; + jmethodID elementDecl; + jmethodID unparsedEntityDecl; + jmethodID setDocumentLocator; + jmethodID startDocument; + jmethodID endDocument; + jmethodID startElement; + jmethodID endElement; + jmethodID characters; + jmethodID ignorableWhitespace; + jmethodID processingInstruction; + jmethodID comment; + jmethodID cdataBlock; + jmethodID warning; + jmethodID error; + jmethodID fatalError; + + jmethodID resolveURIAndOpen; /* JavaProxy */ + jclass stringClass; +} +SAXParseContext; + +SAXParseContext * +xmljNewSAXParseContext (JNIEnv * env, jobject obj, xmlParserCtxtPtr ctx, + jstring publicId, jstring systemId); + +void +xmljFreeSAXParseContext (SAXParseContext * saxCtx); + +xmlParserCtxtPtr +xmljNewParserContext (JNIEnv * env, + jobject inputStream, + jbyteArray detectBuffer, + jstring publicId, + jstring systemId, + jstring base, + jboolean validate, + jboolean coalesce, + jboolean expandEntities, + jboolean loadEntities); + +void +xmljFreeParserContext (xmlParserCtxtPtr parserContext); + +xmlDocPtr +xmljParseDocument (JNIEnv * env, + jobject self, + jobject in, + jbyteArray detectBuffer, + jstring publicId, + jstring systemId, + jstring base, + jboolean validate, + jboolean coalesce, + jboolean expandEntities, + jboolean contentHandler, + jboolean dtdHandler, + jboolean entityResolver, + jboolean errorHandler, + jboolean declarationHandler, + jboolean lexicalHandler, + int saxMode); + +xmlDocPtr +xmljParseDocument2 (JNIEnv * env, + xmlParserCtxtPtr ctx, + SAXParseContext *saxCtx, + xmlSAXHandlerPtr sax, + int saxMode); + +xmlParserInputPtr +xmljNewParserInput (JNIEnv * env, + jobject inputStream, + jbyteArray detectBuffer, + xmlParserCtxtPtr parserContext); + +xmlParserInputBufferPtr +xmljNewParserInputBuffer (JNIEnv * env, + jobject inputStream, + xmlCharEncoding encoding); + +void +xmljSaveFileToJavaOutputStream (JNIEnv * env, jobject outputStream, + xmlDocPtr tree, + const char *outputEncoding); + +/* +xmlParserInputPtr +xmljLoadExternalEntity (const char *URL, const char *ID, + xmlParserCtxtPtr ctxt); + +jobject +xmljResolveURI (SaxErrorContext * saxErrorContext, const char *URL, + const char *ID); +*/ +xmlDocPtr +xmljResolveURIAndOpen (SAXParseContext *saxContext, + const char *URL, const char *ID); + + +void +xmljSetThreadContext (SAXParseContext * ctxt); + +SAXParseContext * +xmljGetThreadContext (void); + +void +xmljClearThreadContext (void); + +#endif /* !defined XMLJ_IO_H */ diff --git a/libjava/classpath/native/jni/xmlj/xmlj_node.c b/libjava/classpath/native/jni/xmlj/xmlj_node.c new file mode 100644 index 000000000..20832678a --- /dev/null +++ b/libjava/classpath/native/jni/xmlj/xmlj_node.c @@ -0,0 +1,203 @@ +/* xmlj_node.c - + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include "xmlj_error.h" +#include "xmlj_node.h" +#include "xmlj_util.h" +#include + +/* + * Returns the node ID for the given GnomeNode object. + */ +xmlNodePtr +xmljGetNodeID (JNIEnv * env, jobject self) +{ + jclass cls; + jfieldID field; + jobject id; + xmlNodePtr node; + + if (self == NULL) + { + xmljThrowDOMException (env, 8, NULL); /* NOT_FOUND_ERR */ + return NULL; + } + cls = (*env)->GetObjectClass (env, self); + if (cls == NULL) + { + return NULL; + } + field = (*env)->GetFieldID (env, cls, "id", "Ljava/lang/Object;"); + if (field == NULL) + { + return NULL; + } + id = (*env)->GetObjectField (env, self, field); + node = (xmlNodePtr) xmljAsPointer (env, id); + if (node == NULL) + { + xmljThrowDOMException (env, 8, NULL); /* NOT_FOUND_ERR */ + } + return node; +} + +/* + * Returns the Java node instanced corresponding to the specified node ID. + */ +jobject +xmljGetNodeInstance (JNIEnv * env, xmlNodePtr node) +{ + jclass cls; + jmethodID method; + xmlElementType type; + + if (node == NULL) + return NULL; + + /* Invoke the GnomeNode.newInstance class method */ + cls = (*env)->FindClass (env, "gnu/xml/libxmlj/dom/GnomeNode"); + if (cls == NULL) + { + return NULL; + } + method = (*env)->GetStaticMethodID (env, cls, "newInstance", + "(Ljava/lang/Object;Ljava/lang/Object;I)Lgnu/xml/libxmlj/dom/GnomeNode;"); + + if (method == NULL) + { + return NULL; + } + type = node->type; + switch (type) + { + case XML_DTD_NODE: + type = XML_DOCUMENT_TYPE_NODE; + break; + case XML_ATTRIBUTE_DECL: + type = XML_ATTRIBUTE_NODE; + break; + case XML_ENTITY_DECL: + type = XML_ENTITY_NODE; + break; + default: + break; + } + return (*env)->CallStaticObjectMethod (env, cls, method, + xmljAsField (env, node->doc), + xmljAsField (env, node), + type); +} + +void +xmljFreeDoc (JNIEnv * env, xmlDocPtr doc) +{ + jclass cls; + jmethodID method; + + /* Invoke the GnomeNode.freeDocument class method */ + cls = (*env)->FindClass (env, "gnu/xml/libxmlj/dom/GnomeNode"); + if (cls == NULL) + { + return; + } + method = (*env)->GetStaticMethodID (env, cls, "freeDocument", + "(Ljava/lang/Object;)V"); + if (method == NULL) + { + return; + } + (*env)->CallStaticVoidMethod (env, cls, method, xmljAsField (env, doc)); +} + +int +xmljMatch (const xmlChar * name, xmlNodePtr node) +{ + switch (node->type) + { + case XML_ELEMENT_NODE: + case XML_ATTRIBUTE_NODE: + return xmlStrcmp (node->name, name); + default: + return 1; + } +} + +int +xmljMatchNS (const xmlChar * uri, const xmlChar * localName, xmlNodePtr node) +{ + xmlNsPtr ns; + const xmlChar *nodeLocalName; + int *len; + int ret; + + switch (node->type) + { + case XML_ELEMENT_NODE: + case XML_ATTRIBUTE_NODE: + len = (int *) malloc (sizeof (int)); + if (xmlSplitQName3 (node->name, len) != NULL) + { + nodeLocalName = node->name + (*len); + } + else + { + nodeLocalName = node->name; + } + free (len); + ns = node->ns; + if (ns == NULL || ns->href == NULL) + { + if (uri != NULL) + { + return 0; + } + ret = xmlStrcmp (localName, nodeLocalName); + } + else + { + if (uri == NULL) + { + return 0; + } + ret = (xmlStrcmp (localName, nodeLocalName) && + xmlStrcmp (uri, ns->href)); + } + return ret; + default: + return 1; + } +} diff --git a/libjava/classpath/native/jni/xmlj/xmlj_node.h b/libjava/classpath/native/jni/xmlj/xmlj_node.h new file mode 100644 index 000000000..11f5e308b --- /dev/null +++ b/libjava/classpath/native/jni/xmlj/xmlj_node.h @@ -0,0 +1,72 @@ +/* xmlj_node.h - + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#ifndef XMLJ_NODE_H +#define XMLJ_NODE_H + +#include +#include + +/* -- Utility method definitions -- */ + +/* + * Returns the node for the given Java node instance + */ +xmlNodePtr xmljGetNodeID (JNIEnv *, jobject); + +/* + * Returns the Java node instance for the given node + */ +jobject xmljGetNodeInstance (JNIEnv *, xmlNodePtr); + +/* + * Frees the specified document pointer, + * releasing all its nodes from the cache. + */ +void xmljFreeDoc (JNIEnv *, xmlDocPtr); + +/* + * Match a node name + */ +int xmljMatch (const xmlChar *, xmlNodePtr); + +/* + * Match a node name and namespace + */ +int xmljMatchNS (const xmlChar *, const xmlChar *, xmlNodePtr); + +#endif /* !defined XMLJ_NODE_H */ diff --git a/libjava/classpath/native/jni/xmlj/xmlj_sax.c b/libjava/classpath/native/jni/xmlj/xmlj_sax.c new file mode 100644 index 000000000..78991bdad --- /dev/null +++ b/libjava/classpath/native/jni/xmlj/xmlj_sax.c @@ -0,0 +1,1445 @@ +/* xmlj_sax.c - + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include "xmlj_sax.h" +#include "xmlj_io.h" +#include "xmlj_util.h" +#include +#include + +xmlExternalEntityLoader defaultLoader = NULL; + +void +xmljDispatchError (xmlParserCtxtPtr ctx, + xmlSAXLocatorPtr loc, + JNIEnv *env, + jobject target, + jmethodID method, + const char *msg, + va_list args); + +/* -- GnomeLocator -- */ + +JNIEXPORT jstring JNICALL +Java_gnu_xml_libxmlj_sax_GnomeLocator_publicId (JNIEnv * env, + jobject self + __attribute__((__unused__)), + jobject j_ctx, + jobject j_loc) +{ + xmlParserCtxtPtr ctx; + xmlSAXLocatorPtr loc; + SAXParseContext *sax; + + ctx = (xmlParserCtxtPtr) xmljAsPointer (env, j_ctx); + loc = (xmlSAXLocatorPtr) xmljAsPointer (env, j_loc); + sax = (SAXParseContext *) ctx->_private; + + return sax->publicId; +} + +JNIEXPORT jstring JNICALL +Java_gnu_xml_libxmlj_sax_GnomeLocator_systemId (JNIEnv * env, + jobject self + __attribute__((__unused__)), + jobject j_ctx, + jobject j_loc) +{ + xmlParserCtxtPtr ctx; + xmlSAXLocatorPtr loc; + SAXParseContext *sax; + + ctx = (xmlParserCtxtPtr) xmljAsPointer (env, j_ctx); + loc = (xmlSAXLocatorPtr) xmljAsPointer (env, j_loc); + sax = (SAXParseContext *) ctx->_private; + + return sax->systemId; +} + +JNIEXPORT jint JNICALL +Java_gnu_xml_libxmlj_sax_GnomeLocator_lineNumber (JNIEnv * env, + jobject self + __attribute__((__unused__)), + jobject j_ctx, + jobject j_loc) +{ + xmlParserCtxtPtr ctx; + xmlSAXLocatorPtr loc; + + ctx = (xmlParserCtxtPtr) xmljAsPointer (env, j_ctx); + loc = (xmlSAXLocatorPtr) xmljAsPointer (env, j_loc); + if (ctx == NULL || ctx->input == NULL) + { + return -1; + } + return ctx->input->line; +} + +JNIEXPORT jint JNICALL +Java_gnu_xml_libxmlj_sax_GnomeLocator_columnNumber (JNIEnv * env, + jobject self + __attribute__((__unused__)), + jobject j_ctx, + jobject j_loc) +{ + xmlParserCtxtPtr ctx; + xmlSAXLocatorPtr loc; + + ctx = (xmlParserCtxtPtr) xmljAsPointer (env, j_ctx); + loc = (xmlSAXLocatorPtr) xmljAsPointer (env, j_loc); + if (ctx == NULL || ctx->input == NULL) + { + return -1; + } + return ctx->input->col; +} + +/* -- GnomeXMLReader -- */ + +/* + * Entry point for SAX parsing. + */ +JNIEXPORT void JNICALL +Java_gnu_xml_libxmlj_sax_GnomeXMLReader_parseStream (JNIEnv * env, + jobject self, + jobject in, + jbyteArray detectBuffer, + jstring publicId, + jstring systemId, + jstring base, + jboolean validate, + jboolean contentHandler, + jboolean dtdHandler, + jboolean entityResolver, + jboolean errorHandler, + jboolean + declarationHandler, + jboolean lexicalHandler) +{ + xmljParseDocument (env, + self, + in, + detectBuffer, + publicId, + systemId, + base, + validate, + 0, + 0, + contentHandler, + dtdHandler, + entityResolver, + errorHandler, + declarationHandler, + lexicalHandler, + 0); +} + +xmlParserInputPtr +xmljExternalEntityLoader (const char *url, const char *id, + xmlParserCtxtPtr ctx) +{ + const xmlChar *systemId; + const xmlChar *publicId; + xmlParserInputPtr ret; + + systemId = xmlCharStrdup (url); + publicId = xmlCharStrdup (id); + /* TODO convert systemId to absolute URI */ + ret = xmljSAXResolveEntity (ctx, publicId, systemId); + if (ret == NULL) + { + ret = defaultLoader (url, id, ctx); + } + return ret; +} + +/* + * Allocates and configures a SAX handler that can report the various + * classes of callback. + */ +xmlSAXHandlerPtr +xmljNewSAXHandler (jboolean contentHandler, + jboolean dtdHandler, + jboolean entityResolver, + jboolean errorHandler, + jboolean declarationHandler, + jboolean lexicalHandler) +{ + xmlSAXHandlerPtr sax; + + sax = (xmlSAXHandlerPtr) malloc (sizeof (xmlSAXHandler)); + if (sax == NULL) + { + return NULL; + } + memset (sax, 0, sizeof (xmlSAXHandler)); + xmlSAXVersion (sax, 1); /* TODO SAX2 */ + + if (dtdHandler) + { + sax->internalSubset = &xmljSAXInternalSubset; + } + if (defaultLoader == NULL) + { + defaultLoader = xmlGetExternalEntityLoader (); + xmlSetExternalEntityLoader (xmljExternalEntityLoader); + } + if (entityResolver) + { + sax->resolveEntity = &xmljSAXResolveEntity; + } + + if (declarationHandler) + { + sax->entityDecl = &xmljSAXEntityDecl; + sax->notationDecl = &xmljSAXNotationDecl; + sax->attributeDecl = &xmljSAXAttributeDecl; + sax->elementDecl = &xmljSAXElementDecl; + sax->unparsedEntityDecl = &xmljSAXUnparsedEntityDecl; + } + + /* We always listen for the locator callback */ + sax->setDocumentLocator = &xmljSAXSetDocumentLocator; + if (contentHandler) + { + sax->startDocument = &xmljSAXStartDocument; + sax->endDocument = &xmljSAXEndDocument; + sax->startElement = &xmljSAXStartElement; + sax->endElement = &xmljSAXEndElement; + sax->characters = &xmljSAXCharacters; + sax->ignorableWhitespace = &xmljSAXIgnorableWhitespace; + sax->processingInstruction = &xmljSAXProcessingInstruction; + } + + /* We always intercept getEntity */ + /* TODO this should only be if lexicalHandler */ + sax->getEntity = &xmljSAXGetEntity; + if (lexicalHandler) + { + sax->getEntity = &xmljSAXGetEntity; + sax->reference = &xmljSAXReference; + sax->comment = &xmljSAXComment; + sax->cdataBlock = &xmljSAXCDataBlock; + } + else if (contentHandler) + { + sax->cdataBlock = &xmljSAXCharacters; + } + + if (errorHandler) + { + sax->warning = &xmljSAXWarning; + sax->error = &xmljSAXError; + sax->fatalError = &xmljSAXFatalError; + } + + return sax; +} + +/* -- Callback functions -- */ + +void +xmljSAXInternalSubset (void *vctx, + const xmlChar * name, + const xmlChar * publicId, const xmlChar * systemId) +{ + xmlParserCtxtPtr ctx; + SAXParseContext *sax; + JNIEnv *env; + jobject target; + jstring j_name; + jstring j_publicId; + jstring j_systemId; + + xmlSAX2InternalSubset (vctx, name, publicId, systemId); + + ctx = (xmlParserCtxtPtr) vctx; + sax = (SAXParseContext *) ctx->_private; + env = sax->env; + target = sax->obj; + + xmljCheckWellFormed (ctx); + if ((*env)->ExceptionOccurred (env)) + { + return; + } + + if (sax->startDTD == NULL) + { + sax->startDTD = + xmljGetMethodID (env, + target, + "startDTD", + "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); + if (sax->startDTD == NULL) + { + return; + } + } + + j_name = xmljNewString (env, name); + j_publicId = xmljNewString (env, publicId); + j_systemId = xmljNewString (env, systemId); + + (*env)->CallVoidMethod (env, + target, + sax->startDTD, + j_name, + j_publicId, + j_systemId); +} + +xmlParserInputPtr +xmljSAXResolveEntity (void *vctx, + const xmlChar * publicId, const xmlChar * systemId) +{ + xmlParserCtxtPtr ctx; + SAXParseContext *sax; + JNIEnv *env; + jobject target; + jstring j_publicId; + jstring j_systemId; + jobject inputStream; + + /* xmlSAX2ResolveEntity (vctx, publicId, systemId); */ + + ctx = (xmlParserCtxtPtr) vctx; + if (ctx->_private == NULL) + { + /* Not in Kansas */ + return NULL; + } + sax = (SAXParseContext *) ctx->_private; + env = sax->env; + target = sax->obj; + + if ((*env)->ExceptionOccurred (env)) + { + return NULL; + } + + if (sax->resolveEntity == NULL) + { + sax->resolveEntity = + xmljGetMethodID (env, + target, + "resolveEntity", + "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/io/InputStream;"); + if (sax->resolveEntity == NULL) + { + return NULL; + } + } + + j_publicId = xmljNewString (env, publicId); + j_systemId = xmljNewString (env, systemId); + + inputStream = (*env)->CallObjectMethod (env, + target, + sax->resolveEntity, + j_publicId, + j_systemId, + sax->systemId); + + /* Return an xmlParserInputPtr corresponding to the input stream */ + if (inputStream != NULL) + { + jbyteArray detectBuffer; + jmethodID getDetectBuffer; + + /* Get the detect buffer from the NamedInputStream */ + getDetectBuffer = xmljGetMethodID (env, inputStream, "getDetectBuffer", + "()[B"); + if (getDetectBuffer == NULL) + { + return NULL; + } + detectBuffer = (*env)->CallObjectMethod (env, inputStream, + getDetectBuffer); + + return xmljNewParserInput (env, inputStream, detectBuffer, ctx); + } + else + { + return NULL; + } +} + +xmlEntityPtr +xmljSAXGetEntity (void *vctx __attribute__((__unused__)), const xmlChar * name) +{ + xmlEntityPtr ret; + + /* TODO */ + /* ret = xmlSAX2GetEntity (vctx, name); */ + ret = NULL; + return ret; +} + +void +xmljSAXEntityDecl (void *vctx, + const xmlChar * name, + int type, + const xmlChar * publicId, + const xmlChar * systemId, + xmlChar * content) +{ + xmlParserCtxtPtr ctx; + SAXParseContext *sax; + JNIEnv *env; + jobject target; + jstring j_name; + jstring j_publicId; + jstring j_systemId; + jstring j_value; + + xmlSAX2EntityDecl (vctx, name, type, publicId, systemId, content); + + ctx = (xmlParserCtxtPtr) vctx; + sax = (SAXParseContext *) ctx->_private; + env = sax->env; + target = sax->obj; + + xmljCheckWellFormed (ctx); + if ((*env)->ExceptionOccurred (env)) + { + return; + } + + j_name = xmljNewString (env, name); + switch (type) + { + case XML_INTERNAL_GENERAL_ENTITY: + case XML_INTERNAL_PARAMETER_ENTITY: + case XML_INTERNAL_PREDEFINED_ENTITY: + if (sax->internalEntityDecl == NULL) + { + sax->internalEntityDecl = + xmljGetMethodID (env, + target, + "internalEntityDecl", + "(Ljava/lang/String;Ljava/lang/String;)V"); + if (sax->internalEntityDecl == NULL) + { + return; + } + } + j_value = xmljNewString (env, content); + (*env)->CallVoidMethod (env, + target, + sax->internalEntityDecl, + j_name, + j_value); + break; + default: + if (sax->externalEntityDecl == NULL) + { + sax->externalEntityDecl = + xmljGetMethodID (env, + target, + "externalEntityDecl", + "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); + if (sax->externalEntityDecl == NULL) + { + return; + } + } + j_publicId = xmljNewString (env, publicId); + j_systemId = xmljNewString (env, systemId); + (*env)->CallVoidMethod (env, + target, + sax->externalEntityDecl, + j_name, + j_publicId, + j_systemId); + } +} + +void +xmljSAXNotationDecl (void *vctx, + const xmlChar * name, + const xmlChar * publicId, + const xmlChar * systemId) +{ + xmlParserCtxtPtr ctx; + SAXParseContext *sax; + JNIEnv *env; + jobject target; + jstring j_name; + jstring j_publicId; + jstring j_systemId; + + xmlSAX2NotationDecl (vctx, name, publicId, systemId); + + ctx = (xmlParserCtxtPtr) vctx; + sax = (SAXParseContext *) ctx->_private; + env = sax->env; + target = sax->obj; + + xmljCheckWellFormed (ctx); + if ((*env)->ExceptionOccurred (env)) + { + return; + } + + if (sax->notationDecl == NULL) + { + sax->notationDecl = + xmljGetMethodID (env, + target, + "notationDecl", + "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); + if (sax->notationDecl == NULL) + { + return; + } + } + + j_name = xmljNewString (env, name); + j_publicId = xmljNewString (env, publicId); + j_systemId = xmljNewString (env, systemId); + + /* Invoke the method */ + (*env)->CallVoidMethod (env, + target, + sax->notationDecl, + j_name, + j_publicId, + j_systemId); +} + +void +xmljSAXAttributeDecl (void *vctx, + const xmlChar * elem, + const xmlChar * fullName, + int type, + int def, + const xmlChar * defaultValue, + xmlEnumerationPtr tree) +{ + xmlParserCtxtPtr ctx; + SAXParseContext *sax; + JNIEnv *env; + jobject target; + jstring j_eName; + jstring j_aName; + jstring j_type; + jstring j_mode; + jstring j_value; + + xmlSAX2AttributeDecl (vctx, elem, fullName, type, def, defaultValue, tree); + + ctx = (xmlParserCtxtPtr) vctx; + sax = (SAXParseContext *) ctx->_private; + env = sax->env; + target = sax->obj; + + xmljCheckWellFormed (ctx); + if ((*env)->ExceptionOccurred (env)) + { + return; + } + + if (sax->attributeDecl == NULL) + { + sax->attributeDecl = + xmljGetMethodID (env, + target, + "attributeDecl", + "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); + if (sax->attributeDecl == NULL) + { + return; + } + } + + j_eName = xmljNewString (env, elem); + j_aName = xmljNewString (env, fullName); + j_type = xmljAttributeTypeName (env, type); + j_mode = xmljAttributeModeName (env, def); + j_value = xmljNewString (env, defaultValue); + + (*env)->CallVoidMethod (env, + target, + sax->attributeDecl, + j_eName, + j_aName, + j_type, + j_mode, + j_value); +} + +void +xmljSAXElementDecl (void *vctx, + const xmlChar * name, + int type, + xmlElementContentPtr content) +{ + xmlParserCtxtPtr ctx; + SAXParseContext *sax; + JNIEnv *env; + jobject target; + jstring j_name; + jstring j_model; + + xmlSAX2ElementDecl (vctx, name, type, content); + + ctx = (xmlParserCtxtPtr) vctx; + sax = (SAXParseContext *) ctx->_private; + env = sax->env; + target = sax->obj; + + xmljCheckWellFormed (ctx); + if ((*env)->ExceptionOccurred (env)) + { + return; + } + + if (sax->elementDecl == NULL) + { + sax->elementDecl = + xmljGetMethodID (env, + target, + "elementDecl", + "(Ljava/lang/String;Ljava/lang/String;)V"); + if (sax->elementDecl == NULL) + { + return; + } + } + + j_name = xmljNewString (env, name); + j_model = NULL; /* TODO */ + + (*env)->CallVoidMethod (env, + target, + sax->elementDecl, + j_name, + j_model); +} + +void +xmljSAXUnparsedEntityDecl (void *vctx, + const xmlChar * name, + const xmlChar * publicId, + const xmlChar * systemId, + const xmlChar * notationName) +{ + xmlParserCtxtPtr ctx; + SAXParseContext *sax; + JNIEnv *env; + jobject target; + jstring j_name; + jstring j_publicId; + jstring j_systemId; + jstring j_notationName; + + xmlSAX2UnparsedEntityDecl (vctx, name, publicId, systemId, notationName); + + ctx = (xmlParserCtxtPtr) vctx; + sax = (SAXParseContext *) ctx->_private; + env = sax->env; + target = sax->obj; + + xmljCheckWellFormed (ctx); + if ((*env)->ExceptionOccurred (env)) + { + return; + } + + if (sax->unparsedEntityDecl == NULL) + { + sax->unparsedEntityDecl = + xmljGetMethodID (env, + target, + "unparsedEntityDecl", + "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); + if (sax->unparsedEntityDecl == NULL) + { + return; + } + } + + j_name = xmljNewString (env, name); + j_publicId = xmljNewString (env, publicId); + j_systemId = xmljNewString (env, systemId); + j_notationName = xmljNewString (env, notationName); + + (*env)->CallVoidMethod (env, + target, + sax->unparsedEntityDecl, + j_name, + j_publicId, + j_systemId, + j_notationName); +} + +void +xmljSAXSetDocumentLocator (void *vctx, xmlSAXLocatorPtr loc) +{ + xmlParserCtxtPtr ctx; + SAXParseContext *sax; + JNIEnv *env; + jobject target; + + xmlSAX2SetDocumentLocator (vctx, loc); + + ctx = (xmlParserCtxtPtr) vctx; + sax = (SAXParseContext *) ctx->_private; + env = sax->env; + target = sax->obj; + + if (target == NULL) + { + /* No Java parse context */ + return; + } + + /* Update locator on sax context */ + sax->loc = loc; + if ((*env)->ExceptionOccurred (env)) + { + return; + } + + if (sax->setDocumentLocator == NULL) + { + sax->setDocumentLocator = xmljGetMethodID (env, + target, + "setDocumentLocator", + "(Ljava/lang/Object;Ljava/lang/Object;)V"); + if (sax->setDocumentLocator == NULL) + { + return; + } + } + + (*env)->CallVoidMethod (env, + target, + sax->setDocumentLocator, + xmljAsField (env, ctx), + xmljAsField (env, loc)); +} + +void +xmljSAXStartDocument (void *vctx) +{ + xmlParserCtxtPtr ctx; + SAXParseContext *sax; + JNIEnv *env; + jobject target; + + xmlSAX2StartDocument (vctx); + + ctx = (xmlParserCtxtPtr) vctx; + sax = (SAXParseContext *) ctx->_private; + env = sax->env; + target = sax->obj; + + xmljCheckWellFormed (ctx); + if ((*env)->ExceptionOccurred (env)) + { + return; + } + + if (sax->startDocument == NULL) + { + sax->startDocument = xmljGetMethodID (env, + target, + "startDocument", + "(Z)V"); + if (sax->startDocument == NULL) + { + return; + } + } + + (*env)->CallVoidMethod (env, + target, + sax->startDocument, + ctx->standalone); +} + +void +xmljSAXEndDocument (void *vctx) +{ + xmlParserCtxtPtr ctx; + SAXParseContext *sax; + JNIEnv *env; + jobject target; + + xmlSAX2EndDocument (vctx); + + ctx = (xmlParserCtxtPtr) vctx; + sax = (SAXParseContext *) ctx->_private; + env = sax->env; + target = sax->obj; + + xmljCheckWellFormed (ctx); + if ((*env)->ExceptionOccurred (env)) + { + return; + } + + if (sax->endDocument == NULL) + { + sax->endDocument = xmljGetMethodID (env, + target, + "endDocument", + "()V"); + if (sax->endDocument == NULL) + { + return; + } + } + + (*env)->CallVoidMethod (env, + target, + sax->endDocument); +} + +void +xmljSAXStartElement (void *vctx, + const xmlChar * name, + const xmlChar ** attrs) +{ + xmlParserCtxtPtr ctx; + SAXParseContext *sax; + JNIEnv *env; + jobject target; + jstring j_name; + jobjectArray j_attrs; + jstring j_attr; + jsize len; + + xmlSAX2StartElement (vctx, name, attrs); + + ctx = (xmlParserCtxtPtr) vctx; + sax = (SAXParseContext *) ctx->_private; + env = sax->env; + target = sax->obj; + + xmljCheckWellFormed (ctx); + if ((*env)->ExceptionOccurred (env)) + { + return; + } + + if (sax->startElement == NULL) + { + sax->startElement = + xmljGetMethodID (env, + target, + "startElement", + "(Ljava/lang/String;[Ljava/lang/String;)V"); + if (sax->startElement == NULL) + { + return; + } + } + + j_name = xmljNewString (env, name); + /* build attributes array */ + len = 0; + for (len = 0; attrs && attrs[len]; len++) + { + } + if (len) + { + if (sax->stringClass == NULL) + { + sax->stringClass = (*env)->FindClass (env, "java/lang/String"); + if (sax->stringClass == NULL) + { + fprintf (stderr, "Can't find java.lang.String class!\n"); + return; + } + } + j_attrs = (*env)->NewObjectArray (env, len, sax->stringClass, NULL); + if (j_attrs == NULL) + { + fprintf (stderr, "Can't allocate attributes array!\n"); + return; + } + len = 0; + for (len = 0; attrs && attrs[len]; len++) + { + j_attr = xmljNewString (env, attrs[len]); + (*env)->SetObjectArrayElement (env, j_attrs, len, j_attr); + } + + (*env)->CallVoidMethod (env, + target, + sax->startElement, + j_name, + j_attrs); + (*env)->DeleteLocalRef (env, j_attrs); + } + else + { + (*env)->CallVoidMethod (env, + target, + sax->startElement, + j_name, + NULL); + + } +} + +void +xmljSAXEndElement (void *vctx, + const xmlChar * name) +{ + xmlParserCtxtPtr ctx; + SAXParseContext *sax; + JNIEnv *env; + jobject target; + jstring j_name; + + xmlSAX2EndElement (vctx, name); + + ctx = (xmlParserCtxtPtr) vctx; + sax = (SAXParseContext *) ctx->_private; + env = sax->env; + target = sax->obj; + + xmljCheckWellFormed (ctx); + if ((*env)->ExceptionOccurred (env)) + { + return; + } + + if (sax->endElement == NULL) + { + sax->endElement = xmljGetMethodID (env, + target, + "endElement", + "(Ljava/lang/String;)V"); + if (sax->endElement == NULL) + { + return; + } + } + + j_name = xmljNewString (env, name); + + (*env)->CallVoidMethod (env, + target, + sax->endElement, + j_name); +} + +void +xmljSAXReference (void *vctx, + const xmlChar * name) +{ + xmlSAX2Reference (vctx, name); +} + +void +xmljSAXCharacters (void *vctx, + const xmlChar * ch, + int len) +{ + xmlParserCtxtPtr ctx; + SAXParseContext *sax; + JNIEnv *env; + jobject target; + jstring j_ch; + xmlChar *dup; + + xmlSAX2Characters (vctx, ch, len); + + ctx = (xmlParserCtxtPtr) vctx; + sax = (SAXParseContext *) ctx->_private; + env = sax->env; + target = sax->obj; + + xmljCheckWellFormed (ctx); + if ((*env)->ExceptionOccurred (env)) + { + return; + } + + if (sax->characters == NULL) + { + sax->characters = xmljGetMethodID (env, + target, + "characters", + "(Ljava/lang/String;)V"); + if (sax->characters == NULL) + { + return; + } + } + + dup = xmlStrndup (ch, len); + j_ch = xmljNewString (env, dup); + + (*env)->CallVoidMethod (env, + target, + sax->characters, + j_ch); + xmlFree (dup); +} + +void +xmljSAXIgnorableWhitespace (void *vctx, + const xmlChar * ch, + int len) +{ + xmlParserCtxtPtr ctx; + SAXParseContext *sax; + JNIEnv *env; + jobject target; + jstring j_ch; + xmlChar *dup; + + xmlSAX2IgnorableWhitespace (vctx, ch, len); + + ctx = (xmlParserCtxtPtr) vctx; + sax = (SAXParseContext *) ctx->_private; + env = sax->env; + target = sax->obj; + + xmljCheckWellFormed (ctx); + if ((*env)->ExceptionOccurred (env)) + { + return; + } + + if (sax->ignorableWhitespace == NULL) + { + sax->ignorableWhitespace = xmljGetMethodID (env, + target, + "ignorableWhitespace", + "(Ljava/lang/String;)V"); + if (sax->ignorableWhitespace == NULL) + { + return; + } + } + + dup = xmlStrndup (ch, len); + j_ch = xmljNewString (env, dup); + + (*env)->CallVoidMethod (env, + target, + sax->ignorableWhitespace, + j_ch); + xmlFree (dup); +} + +void +xmljSAXProcessingInstruction (void *vctx, + const xmlChar * targ, + const xmlChar * data) +{ + xmlParserCtxtPtr ctx; + SAXParseContext *sax; + JNIEnv *env; + jobject target; + jstring j_targ; + jstring j_data; + + xmlSAX2ProcessingInstruction (vctx, targ, data); + + ctx = (xmlParserCtxtPtr) vctx; + sax = (SAXParseContext *) ctx->_private; + env = sax->env; + target = sax->obj; + + xmljCheckWellFormed (ctx); + if ((*env)->ExceptionOccurred (env)) + { + return; + } + + if (sax->processingInstruction == NULL) + { + sax->processingInstruction = + xmljGetMethodID (env, + target, + "processingInstruction", + "(Ljava/lang/String;Ljava/lang/String;)V"); + if (sax->processingInstruction == NULL) + { + return; + } + } + + j_targ = xmljNewString (env, targ); + j_data = xmljNewString (env, data); + + (*env)->CallVoidMethod (env, + target, + sax->processingInstruction, + j_targ, + j_data); +} + +void +xmljSAXComment (void *vctx, + const xmlChar * value) +{ + xmlParserCtxtPtr ctx; + SAXParseContext *sax; + JNIEnv *env; + jobject target; + jstring j_text; + + xmlSAX2Comment (vctx, value); + + ctx = (xmlParserCtxtPtr) vctx; + sax = (SAXParseContext *) ctx->_private; + env = sax->env; + target = sax->obj; + + xmljCheckWellFormed (ctx); + if ((*env)->ExceptionOccurred (env)) + { + return; + } + + if (sax->comment == NULL) + { + sax->comment = + xmljGetMethodID (env, + target, + "comment", + "(Ljava/lang/String;)V"); + if (sax->comment == NULL) + { + return; + } + } + + j_text = xmljNewString (env, value); + + (*env)->CallVoidMethod (env, + target, + sax->comment, + j_text); +} + +void +xmljSAXCDataBlock (void *vctx, + const xmlChar * ch, + int len) +{ + xmlParserCtxtPtr ctx; + SAXParseContext *sax; + JNIEnv *env; + jobject target; + jstring j_ch; + xmlChar *dup; + + xmlSAX2CDataBlock (vctx, ch, len); + + ctx = (xmlParserCtxtPtr) vctx; + sax = (SAXParseContext *) ctx->_private; + env = sax->env; + target = sax->obj; + + xmljCheckWellFormed (ctx); + if ((*env)->ExceptionOccurred (env)) + { + return; + } + + if (sax->cdataBlock == NULL) + { + sax->cdataBlock = + xmljGetMethodID (env, + target, + "cdataBlock", + "(Ljava/lang/String;)V"); + if (sax->cdataBlock == NULL) + { + return; + } + } + + dup = xmlStrndup (ch, len); + j_ch = xmljNewString (env, dup); + + (*env)->CallVoidMethod (env, + target, + sax->cdataBlock, + j_ch); + xmlFree (dup); +} + +void +xmljDispatchError (xmlParserCtxtPtr ctx, + xmlSAXLocatorPtr loc, + JNIEnv *env, + jobject target, + jmethodID method, + const char *msg, + va_list args) +{ + jint lineNumber; + jint columnNumber; + jstring publicId; + jstring systemId; + char buffer[2048] = ""; + + if (msg != NULL) + { + vsnprintf (buffer, sizeof buffer, msg, args); + } + lineNumber = loc->getLineNumber (ctx); + columnNumber = loc->getColumnNumber (ctx); + publicId = xmljNewString (env, loc->getPublicId (ctx)); + systemId = xmljNewString (env, loc->getSystemId (ctx)); + (*env)->CallVoidMethod (env, + target, + method, + (*env)->NewStringUTF (env, buffer), + lineNumber, + columnNumber, + publicId, + systemId); +} + +void +xmljSAXWarning (void *vctx, + const char *msg, + ...) +{ + va_list args; + + xmlParserCtxtPtr ctx; + SAXParseContext *sax; + xmlSAXLocatorPtr loc; + JNIEnv *env; + jobject target; + + ctx = (xmlParserCtxtPtr) vctx; + sax = (SAXParseContext *) ctx->_private; + loc = (xmlSAXLocatorPtr) sax->loc; + env = sax->env; + target = sax->obj; + + if ((*env)->ExceptionOccurred (env)) + { + return; + } + if (sax->warning == NULL) + { + sax->warning = + xmljGetMethodID (env, + target, + "warning", + "(Ljava/lang/String;IILjava/lang/String;Ljava/lang/String;)V"); + if (sax->warning == NULL) + { + return; + } + } + + va_start (args, msg); + /* xmlParserWarning (vctx, msg, args); */ + xmljDispatchError (ctx, loc, env, target, sax->warning, msg, args); + va_end (args); +} + +void +xmljSAXError (void *vctx, + const char *msg, + ...) +{ + va_list args; + + xmlParserCtxtPtr ctx; + SAXParseContext *sax; + xmlSAXLocatorPtr loc; + JNIEnv *env; + jobject target; + + ctx = (xmlParserCtxtPtr) vctx; + sax = (SAXParseContext *) ctx->_private; + loc = (xmlSAXLocatorPtr) sax->loc; + env = sax->env; + target = sax->obj; + + if ((*env)->ExceptionOccurred (env)) + { + return; + } + if (sax->error == NULL) + { + sax->error = + xmljGetMethodID (env, + target, + "error", + "(Ljava/lang/String;IILjava/lang/String;Ljava/lang/String;)V"); + if (sax->error == NULL) + { + return; + } + } + + va_start (args, msg); + /* xmlParserError (vctx, msg, args); */ + xmljDispatchError (ctx, loc, env, target, sax->error, msg, args); + va_end (args); +} + +void +xmljSAXFatalError (void *vctx, + const char *msg, + ...) +{ + va_list args; + + xmlParserCtxtPtr ctx; + SAXParseContext *sax; + xmlSAXLocatorPtr loc; + JNIEnv *env; + jobject target; + + ctx = (xmlParserCtxtPtr) vctx; + sax = (SAXParseContext *) ctx->_private; + loc = (xmlSAXLocatorPtr) sax->loc; + env = sax->env; + target = sax->obj; + + if ((*env)->ExceptionOccurred (env)) + { + return; + } + if (sax->fatalError == NULL) + { + sax->fatalError = + xmljGetMethodID (env, + target, + "fatalError", + "(Ljava/lang/String;IILjava/lang/String;Ljava/lang/String;)V"); + if (sax->fatalError == NULL) + { + return; + } + } + + va_start (args, msg); + /* xmlParserError (vctx, msg, args); */ + xmljDispatchError (ctx, loc, env, target, sax->fatalError, msg, args); + va_end (args); +} + +void +xmljCheckWellFormed (xmlParserCtxtPtr ctx) +{ + if (!ctx->wellFormed) + { + xmljSAXFatalError (ctx, "document is not well-formed"); + } + if (ctx->validate && !ctx->valid) + { + xmljSAXFatalError (ctx, "document is not valid"); + } +} + +/* + * Convert a libxml2 attribute type to a string. + */ +jstring +xmljAttributeTypeName (JNIEnv * env, int type) +{ + const char *text; + + switch (type) + { + case XML_ATTRIBUTE_CDATA: + text = "CDATA"; + break; + case XML_ATTRIBUTE_ID: + text = "ID"; + break; + case XML_ATTRIBUTE_IDREF: + text = "IDREF"; + break; + case XML_ATTRIBUTE_IDREFS: + text = "IDREFS"; + break; + case XML_ATTRIBUTE_NMTOKEN: + text = "NMTOKEN"; + break; + case XML_ATTRIBUTE_NMTOKENS: + text = "NMTOKENS"; + break; + case XML_ATTRIBUTE_ENTITY: + text = "ID"; + break; + case XML_ATTRIBUTE_ENTITIES: + text = "ID"; + break; + default: + return NULL; + } + + return (*env)->NewStringUTF (env, text); +} + +/* + * Convert a libxml2 attribute default value type to a string. + */ +jstring +xmljAttributeModeName (JNIEnv * env, int type) +{ + const char *text; + + switch (type) + { + case XML_ATTRIBUTE_IMPLIED: + text = "#IMPLIED"; + break; + case XML_ATTRIBUTE_REQUIRED: + text = "#REQUIRED"; + break; + case XML_ATTRIBUTE_FIXED: + text = "#FIXED"; + break; + default: + return NULL; + } + + return (*env)->NewStringUTF (env, text); +} diff --git a/libjava/classpath/native/jni/xmlj/xmlj_sax.h b/libjava/classpath/native/jni/xmlj/xmlj_sax.h new file mode 100644 index 000000000..249929ce0 --- /dev/null +++ b/libjava/classpath/native/jni/xmlj/xmlj_sax.h @@ -0,0 +1,160 @@ +/* xmlj_sax.h - + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#ifndef XMLJ_SAX_H +#define XMLJ_SAX_H + +#include "gnu_xml_libxmlj_sax_GnomeLocator.h" +#include "gnu_xml_libxmlj_sax_GnomeXMLReader.h" + +#include +#include + +xmlSAXHandlerPtr +xmljNewSAXHandler (jboolean contentHandler, + jboolean dtdHandler, + jboolean entityResolver, + jboolean errorHandler, + jboolean declarationHandler, + jboolean lexicalHandler); + +xmlParserInputPtr +xmljExternalEntityLoader (const char *systemId, const char *publicId, + xmlParserCtxtPtr context); + +/* -- Function declarations for callback functions -- */ + +void xmljSAXInternalSubset(void *ctx, + const xmlChar *name, + const xmlChar *publicId, + const xmlChar *systemId); + +xmlParserInputPtr xmljSAXResolveEntity(void *ctx, + const xmlChar *publicId, + const xmlChar *systemId); + +xmlEntityPtr xmljSAXGetEntity(void *ctx, + const xmlChar *name); + +void xmljSAXEntityDecl(void *ctx, + const xmlChar *name, + int type, + const xmlChar *publicId, + const xmlChar *systemId, + xmlChar *content); + +void xmljSAXNotationDecl(void *ctx, + const xmlChar *name, + const xmlChar *publicId, + const xmlChar *systemId); + +void xmljSAXAttributeDecl(void *ctx, + const xmlChar *elem, + const xmlChar *fullName, + int type, + int def, + const xmlChar *defaultValue, + xmlEnumerationPtr tree); + +void xmljSAXElementDecl(void *ctx, + const xmlChar *name, + int type, + xmlElementContentPtr content); + +void xmljSAXUnparsedEntityDecl(void *ctx, + const xmlChar *name, + const xmlChar *publicId, + const xmlChar *systemId, + const xmlChar *notationName); + +void xmljSAXSetDocumentLocator(void *ctx, + xmlSAXLocatorPtr loc); + +void xmljSAXStartDocument(void *ctx); + +void xmljSAXEndDocument(void *ctx); + +void xmljSAXStartElement(void *ctx, + const xmlChar *name, + const xmlChar **atts); + +void xmljSAXEndElement(void *ctx, + const xmlChar *name); + +void xmljSAXReference(void *ctx, + const xmlChar *name); + +void xmljSAXCharacters(void *ctx, + const xmlChar *ch, + int len); + +void xmljSAXIgnorableWhitespace(void *ctx, + const xmlChar *ch, + int len); + +void xmljSAXProcessingInstruction(void *ctx, + const xmlChar *target, + const xmlChar *data); + +void xmljSAXComment(void *ctx, + const xmlChar *value); + +void xmljSAXCDataBlock(void *ctx, + const xmlChar *ch, + int len); + +void xmljSAXWarning(void *ctx, + const char *msg, + ...); + +void xmljSAXError(void *ctx, + const char *msg, + ...); + +void xmljSAXFatalError(void *ctx, + const char *msg, + ...); + +void xmljCheckWellFormed(xmlParserCtxtPtr ctx); + +jstring xmljAttributeTypeName (JNIEnv *env, + int type); + +jstring xmljAttributeModeName (JNIEnv *env, + int type); + +#endif /* !defined XMLJ_SAX_H */ diff --git a/libjava/classpath/native/jni/xmlj/xmlj_transform.c b/libjava/classpath/native/jni/xmlj/xmlj_transform.c new file mode 100644 index 000000000..075409ad1 --- /dev/null +++ b/libjava/classpath/native/jni/xmlj/xmlj_transform.c @@ -0,0 +1,868 @@ +/* xmlj_transform.c - + Copyright (C) 2003, 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include "gnu_xml_libxmlj_transform_GnomeTransformerFactory.h" +#include "gnu_xml_libxmlj_transform_GnomeTransformer.h" + +#include "xmlj_dom.h" +#include "xmlj_io.h" +#include "xmlj_error.h" +#include "xmlj_node.h" +#include "xmlj_sax.h" +#include "xmlj_util.h" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Local function prototypes */ + +void +xmljDocumentFunction (xmlXPathParserContextPtr ctxt, int nargs); + +xsltStylesheetPtr +xmljGetStylesheetID (JNIEnv * env, jobject transformer); + +jobject +xmljGetTransformerProperties (JNIEnv *env, jobject transformer); + +const xmlChar * +xmljBooleanToString (int value); + +void +xmljSetOutputProperties (JNIEnv *env, jobject transformer, + xsltStylesheetPtr stylesheet); + +jobjectArray +xmljGetParameterArray (JNIEnv *env, jobject transformer); + +const char ** +xmljGetParameters (JNIEnv *env, jobjectArray pa); + +void +xmljFreeParameters (JNIEnv *env, jobjectArray pa, const char **parameters); + +xmlDocPtr +xmljTransform (JNIEnv *env, jobject transformer, xmlDocPtr source); + +void +xmljTransformToSAX (JNIEnv *env, jobject transformer, xmlDocPtr source, + jobject callback); + +xmlDocPtr +xmljDocLoader (const xmlChar *uri, xmlDictPtr dict, int options, + void *ctxt, xsltLoadType type); + +/* HACK: store stylesheet URL as context for resolving URIs in xmljDocLoader */ +static jstring stylesheetURL = NULL; + +/* + * -------------------------------------------------------------------------- + * + * Native implementation for class + * gnu.xml.libxmlj.transform.GnomeTransformer follows. + */ + +static void +xmljSetProperty (JNIEnv * env, jobject outputProperties, + jmethodID setPropertyMethodID, const char *name, + const xmlChar * value) +{ + if (NULL != value) + { + jstring nameString = (*env)->NewStringUTF (env, name); + jstring valueString = (*env)->NewStringUTF (env, (const char *) value); + + jobject prevValue = (*env)->CallObjectMethod (env, outputProperties, + setPropertyMethodID, + nameString, valueString); + if (NULL != prevValue) + { + (*env)->DeleteLocalRef (env, prevValue); + } + + (*env)->DeleteLocalRef (env, nameString); + (*env)->DeleteLocalRef (env, valueString); + } +} + +typedef struct CdataSectionScannerInfo_ +{ + JNIEnv *env; + jobject stringBuffer; + jmethodID appendMethodID; + int isFirst; +} CdataSectionScannerInfo; + +static void +cdataSectionScanner (void *payload, void *data, xmlChar * name) +{ + CdataSectionScannerInfo *info = (CdataSectionScannerInfo *) data; + JNIEnv *env = info->env; + jstring nameString = (*env)->NewStringUTF (env, (const char *) name); + jstring blankString = (*env)->NewStringUTF (env, " "); + jobject stringBuffer; + if (!info->isFirst) + { + stringBuffer + = (*env)->CallObjectMethod (env, + info->stringBuffer, + info->appendMethodID, blankString); + (*env)->DeleteLocalRef (env, stringBuffer); + } + info->isFirst = 0; + stringBuffer + = (*env)->CallObjectMethod (env, + info->stringBuffer, + info->appendMethodID, nameString); + (*env)->DeleteLocalRef (env, stringBuffer); + (*env)->DeleteLocalRef (env, blankString); + (*env)->DeleteLocalRef (env, nameString); +} + +void +xmljDocumentFunction (xmlXPathParserContextPtr ctxt, int nargs) +{ + xmlXPathObjectPtr obj, obj2 = NULL; + + if ((nargs < 1) || (nargs > 2)) + { + xsltTransformError (xsltXPathGetTransformContext (ctxt), NULL, NULL, + "document() : invalid number of args %d\n", nargs); + ctxt->error = XPATH_INVALID_ARITY; + return; + } + if (ctxt->value == NULL) + { + xsltTransformError (xsltXPathGetTransformContext (ctxt), NULL, NULL, + "document() : invalid arg value\n"); + ctxt->error = XPATH_INVALID_TYPE; + return; + } + + if (nargs == 2) + { + if (ctxt->value->type != XPATH_NODESET) + { + xsltTransformError (xsltXPathGetTransformContext (ctxt), NULL, NULL, + "document() : invalid arg expecting a nodeset\n"); + ctxt->error = XPATH_INVALID_TYPE; + return; + } + + obj2 = valuePop (ctxt); + } + + if (ctxt->value->type == XPATH_NODESET) + { + int i; + xmlXPathObjectPtr newobj, ret; + + obj = valuePop (ctxt); + ret = xmlXPathNewNodeSet (NULL); + + if (obj->nodesetval) + { + for (i = 0; i < obj->nodesetval->nodeNr; i++) + { + valuePush (ctxt, + xmlXPathNewNodeSet (obj->nodesetval->nodeTab[i])); + xmlXPathStringFunction (ctxt, 1); + if (nargs == 2) + { + valuePush (ctxt, xmlXPathObjectCopy (obj2)); + } + else + { + valuePush (ctxt, + xmlXPathNewNodeSet (obj->nodesetval-> + nodeTab[i])); + } + xsltDocumentFunction (ctxt, 2); + newobj = valuePop (ctxt); + ret->nodesetval = xmlXPathNodeSetMerge (ret->nodesetval, + newobj->nodesetval); + xmlXPathFreeObject (newobj); + } + } + + xmlXPathFreeObject (obj); + if (obj2 != NULL) + { + xmlXPathFreeObject (obj2); + } + valuePush (ctxt, ret); + return; + } + /* + * Make sure it's converted to a string + */ + xmlXPathStringFunction (ctxt, 1); + if (ctxt->value->type != XPATH_STRING) + { + xsltTransformError (xsltXPathGetTransformContext (ctxt), NULL, NULL, + "document() : invalid arg expecting a string\n"); + ctxt->error = XPATH_INVALID_TYPE; + if (obj2 != NULL) + xmlXPathFreeObject (obj2); + return; + } + obj = valuePop (ctxt); + if (obj->stringval == NULL) + { + valuePush (ctxt, xmlXPathNewNodeSet (NULL)); + } + else + { + + xsltTransformContextPtr tctxt; + + tctxt = xsltXPathGetTransformContext (ctxt); + + { + SAXParseContext *saxContext = + (SAXParseContext *) tctxt->style->_private; + + xmlDocPtr tree = xmljResolveURIAndOpen (saxContext, + (const char*)obj->stringval, + NULL); + + xsltNewDocument (tctxt, tree); /* FIXME - free at a later point */ + + valuePush (ctxt, xmlXPathNewNodeSet ((xmlNodePtr) tree)); + } + } + xmlXPathFreeObject (obj); + if (obj2 != NULL) { + xmlXPathFreeObject (obj2); + } +} + +/* + * Returns the stylesheet pointer for the given GnomeTransformer. + */ +xsltStylesheetPtr +xmljGetStylesheetID (JNIEnv * env, jobject transformer) +{ + jclass cls; + jfieldID field; + jobject id; + xsltStylesheetPtr stylesheet; + + if (transformer == NULL) + { + xmljThrowException (env, "javax/xml/transform/TransformerException", + "Transformer is null"); + return NULL; + } + cls = (*env)->GetObjectClass (env, transformer); + if (cls == NULL) + { + return NULL; + } + field = (*env)->GetFieldID (env, cls, "stylesheet", "Ljava/lang/Object;"); + if (field == NULL) + { + return NULL; + } + id = (*env)->GetObjectField (env, transformer, field); + stylesheet = (xsltStylesheetPtr) xmljAsPointer (env, id); + if (stylesheet == NULL) + { + xmljThrowException (env, "javax/xml/transform/TransformerException", + "Stylesheet is null"); + return NULL; + } + return stylesheet; +} + +jobject +xmljGetTransformerProperties (JNIEnv *env, jobject transformer) +{ + jclass cls; + jfieldID field; + + cls = (*env)->GetObjectClass (env, transformer); + if (cls == NULL) + { + return NULL; + } + field = (*env)->GetFieldID (env, cls, "outputProperties", + "Ljava/util/Properties;"); + if (field == NULL) + { + return NULL; + } + return (*env)->GetObjectField (env, transformer, field); +} + +const xmlChar * +xmljBooleanToString (int value) +{ + return value ? BAD_CAST "yes" : BAD_CAST "no"; +} + +/* + * Sets the output properties for the given transformer, + * based on its stylesheet. + */ +void +xmljSetOutputProperties (JNIEnv *env, jobject transformer, + xsltStylesheetPtr stylesheet) +{ + jobject outputProperties; + jclass propertiesClass; + jmethodID setPropertyMethod; + + outputProperties = xmljGetTransformerProperties (env, transformer); + if (outputProperties == NULL) + { + return; + } + propertiesClass = (*env)->FindClass (env, "java/util/Properties"); + if (propertiesClass == NULL) + { + return; + } + setPropertyMethod = + (*env)->GetMethodID (env, propertiesClass, "setProperty", + "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;"); + if (setPropertyMethod == NULL) + { + return; + } + + xmljSetProperty (env, outputProperties, setPropertyMethod, + "encoding", stylesheet->encoding); + + xmljSetProperty (env, outputProperties, setPropertyMethod, + "media-type", stylesheet->mediaType); + + xmljSetProperty (env, outputProperties, setPropertyMethod, + "doctype-public", stylesheet->doctypePublic); + + xmljSetProperty (env, outputProperties, setPropertyMethod, + "doctype-system", stylesheet->doctypeSystem); + + xmljSetProperty (env, outputProperties, setPropertyMethod, + "indent", xmljBooleanToString (stylesheet->indent)); + + xmljSetProperty (env, outputProperties, setPropertyMethod, + "method", stylesheet->method); + + xmljSetProperty (env, outputProperties, setPropertyMethod, + "standalone", xmljBooleanToString (stylesheet->standalone)); + + xmljSetProperty (env, outputProperties, setPropertyMethod, + "version", stylesheet->version); + + xmljSetProperty (env, outputProperties, setPropertyMethod, + "omit-xml-declaration", + xmljBooleanToString (stylesheet->omitXmlDeclaration)); + + { + CdataSectionScannerInfo info; + jclass stringBufferClass + = + (*env)->FindClass (env, + "java/lang/StringBuffer"); + jmethodID stringBufferConstructorID = + (*env)->GetMethodID (env, stringBufferClass, + "", "()V"); + jmethodID toStringMethodID = + (*env)->GetMethodID (env, stringBufferClass, + "toString", + "()Ljava/lang/String;"); + info.env = env; + info.isFirst = 1; + info.stringBuffer + = (*env)->AllocObject (env, stringBufferClass); + (*env)->CallVoidMethod (env, info.stringBuffer, + stringBufferConstructorID); + info.appendMethodID = + (*env)->GetMethodID (env, stringBufferClass, + "append", + "(Ljava/lang/String;)Ljava/lang/StringBuffer;"); + + xmlHashScan (stylesheet->cdataSection, + cdataSectionScanner, &info); + + { + jstring result = (jstring) + (*env)->CallObjectMethod (env, + info.stringBuffer, + toStringMethodID); + + jstring nameString = + (*env)->NewStringUTF (env, + "cdata-section-elements"); + + jobject prevValue + = + (*env)->CallObjectMethod (env, + outputProperties, + setPropertyMethod, + nameString, result); + if (NULL != prevValue) + { + (*env)->DeleteLocalRef (env, prevValue); + } + (*env)->DeleteLocalRef (env, nameString); + } + + (*env)->DeleteLocalRef (env, info.stringBuffer); + } +} + +/* + * Returns the parameter array for the given GnomeTransformer. + */ +jobjectArray +xmljGetParameterArray (JNIEnv *env, jobject transformer) +{ + jclass cls; + jmethodID method; + + cls = (*env)->GetObjectClass (env, transformer); + if (cls == NULL) + { + return NULL; + } + method = (*env)->GetMethodID (env, cls, "getParameterArray", + "()[Ljava/lang/String;"); + if (method == NULL) + { + return NULL; + } + return (jobjectArray) (*env)->CallObjectMethod (env, transformer, method); +} + +/* Convert parameter array to xmlChar ** */ +const char ** +xmljGetParameters (JNIEnv *env, jobjectArray pa) +{ + int i, len; + const char **parameters; + + len = (*env)->GetArrayLength (env, pa); + parameters = (const char **) malloc ((len + 2) * sizeof (const char *)); + if (parameters == NULL) + { + return NULL; + } + + for (i = 0; i < len; i++) + { + jstring string = (jstring) (*env)->GetObjectArrayElement (env, pa, i); + + if (string != NULL) + { + parameters[i] = (*env)->GetStringUTFChars (env, string, NULL); + } + else + { + parameters[i] = NULL; + } + } + + parameters[len] = 0; + parameters[len + 1] = 0; + return parameters; +} + +/* Release parameter strings */ +void +xmljFreeParameters (JNIEnv *env, jobjectArray pa, const char **parameters) +{ + int i, len; + + len = (*env)->GetArrayLength (env, pa); + for (i = 0; i < len; i++) + { + jstring string = (jstring) (*env)->GetObjectArrayElement (env, pa, i); + if (string != NULL) + { + (*env)->ReleaseStringUTFChars (env, string, parameters[i]); + } + } + + free (parameters); +} + +xmlDocPtr +xmljTransform (JNIEnv *env, jobject transformer, xmlDocPtr source) +{ + xsltStylesheetPtr stylesheet; + xmlDocPtr result; + jobjectArray pa; + const char **parameters; + + stylesheet = xmljGetStylesheetID (env, transformer); + pa = xmljGetParameterArray (env, transformer); + parameters = xmljGetParameters (env, pa); + if (parameters == NULL) + { + xmljThrowException (env, "javax/xml/transform/TransformerException", + "Couldn't allocate memory for parameters"); + return NULL; + } + result = xsltApplyStylesheet (stylesheet, source, parameters); + xmljFreeParameters (env, pa, parameters); + if (result == NULL) + { + xmljThrowException (env, "javax/xml/transform/TransformerException", + "XSLT transformation failed"); + } + return result; +} + +void +xmljTransformToSAX (JNIEnv *env, jobject transformer, xmlDocPtr source, + jobject callback) +{ + xsltStylesheetPtr stylesheet; + int ret; + jobjectArray pa; + const char **parameters; + xmlSAXHandlerPtr sax; + + stylesheet = xmljGetStylesheetID (env, transformer); + pa = xmljGetParameterArray (env, transformer); + parameters = xmljGetParameters (env, pa); + if (parameters == NULL) + { + xmljThrowException (env, "javax/xml/transform/TransformerException", + "Couldn't allocate memory for parameters"); + return; + } + sax = NULL; /* TODO link up sax and callback */ + ret = xsltRunStylesheet (stylesheet, source, parameters, NULL, sax, NULL); + xmljFreeParameters (env, pa, parameters); + if (ret == -1) + { + xmljThrowException (env, "javax/xml/transform/TransformerException", + "XSLT transformation failed"); + } +} + +xmlDocPtr +xmljDocLoader (const xmlChar *uri, xmlDictPtr dict, int options, + void *ctxt, xsltLoadType type) +{ + JNIEnv *env; + jclass xmljClass; + jclass inputStreamClass; + jmethodID getInputStream; + jmethodID getDetectBuffer; + jstring systemId; + jobject inputStream; + jbyteArray detectBuffer; + + fflush(stdout); + env = xmljGetJNIEnv (); + if (!env) + { + return NULL; + } + xmljClass = (*env)->FindClass (env, "gnu/xml/libxmlj/util/XMLJ"); + if (!xmljClass) + { + return NULL; + } + getInputStream = + (*env)->GetStaticMethodID (env, xmljClass, "xmljGetInputStream", + "(Ljava/lang/String;Ljava/lang/String;)Lgnu/xml/libxmlj/util/NamedInputStream;"); + if (!getInputStream) + { + return NULL; + } + systemId = xmljNewString (env, uri); + inputStream = (*env)->CallStaticObjectMethod (env, xmljClass, getInputStream, + stylesheetURL, systemId); + if (!inputStream) + { + return NULL; + } + inputStreamClass = (*env)->GetObjectClass (env, inputStream); + if (!inputStreamClass) + { + return NULL; + } + getDetectBuffer = (*env)->GetMethodID (env, inputStreamClass, + "getDetectBuffer", "()[B"); + if (!getDetectBuffer) + { + return NULL; + } + detectBuffer = (*env)->CallObjectMethod (env, inputStream, getDetectBuffer); + if (!detectBuffer) + { + return NULL; + } + return xmljParseDocument (env, NULL, inputStream, detectBuffer, + NULL, systemId, stylesheetURL, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 2); +} + +/* GnomeTransformer.newStylesheet */ +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_transform_GnomeTransformer_newStylesheet (JNIEnv *env, + jobject self) +{ + xsltStylesheetPtr stylesheet; + jobject ret; + + stylesheetURL = NULL; + xsltSetLoaderFunc (xmljDocLoader); + stylesheet = xsltNewStylesheet (); + xmljSetOutputProperties (env, self, stylesheet); + ret = xmljAsField (env, stylesheet); + if (ret == NULL) + { + xmljThrowException (env, + "javax/xml/transform/TransformerConfigurationException", + "Can't create Java object for stylesheet"); + } + return ret; +} + +/* GnomeTransformer.newStylesheetFromStream */ +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_transform_GnomeTransformer_newStylesheetFromStream +(JNIEnv *env, jobject self, jobject in, jbyteArray detectBuffer, + jstring publicId, jstring systemId, jstring base, + jboolean entityResolver, jboolean errorHandler) +{ + xmlDocPtr doc; + xsltStylesheetPtr stylesheet; + jobject ret; + + doc = xmljParseDocument (env, self, in, detectBuffer, publicId, systemId, + base, 0, 0, 0, 0, 0, + entityResolver, errorHandler, 0, 0, 2); + if (doc == NULL) + { + return NULL; + } + stylesheetURL = systemId; + xsltSetLoaderFunc (xmljDocLoader); + stylesheet = xsltParseStylesheetDoc (doc); + if (stylesheet == NULL) + { + xmljThrowException (env, + "javax/xml/transform/TransformerConfigurationException", + "Error parsing XSLT stylesheet"); + return NULL; + } + xmljSetOutputProperties (env, self, stylesheet); + ret = xmljAsField (env, stylesheet); + if (ret == NULL) + { + xmljThrowException (env, + "javax/xml/transform/TransformerConfigurationException", + "Can't create Java object for stylesheet"); + } + return ret; +} + +/* GnomeTransformer.newStylesheetFromDoc */ +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_transform_GnomeTransformer_newStylesheetFromDoc +(JNIEnv *env, jobject self, jobject in) +{ + xmlDocPtr doc; + xsltStylesheetPtr stylesheet; + jobject ret; + + doc = (xmlDocPtr) xmljGetNodeID (env, in); + if (doc == NULL) + { + return NULL; + } + stylesheetURL = xmljNewString (env, doc->URL); + xsltSetLoaderFunc (xmljDocLoader); + stylesheet = xsltParseStylesheetDoc (doc); + if (stylesheet == NULL) + { + xmljThrowException (env, + "javax/xml/transform/TransformerConfigurationException", + "Error parsing XSLT stylesheet"); + } + xmljSetOutputProperties (env, self, stylesheet); + ret = xmljAsField (env, stylesheet); + if (ret == NULL) + { + xmljThrowException (env, + "javax/xml/transform/TransformerConfigurationException", + "Can't create Java object for stylesheet"); + } + return ret; +} + +/* GnomeTransformer.transformStreamToStream */ +JNIEXPORT void JNICALL +Java_gnu_xml_libxmlj_transform_GnomeTransformer_transformStreamToStream +(JNIEnv *env, jobject self, jobject in, jbyteArray detectBuffer, + jstring publicId, jstring systemId, jstring base, + jboolean entityResolver, jboolean errorHandler, jobject out) +{ + xmlDocPtr source; + xmlDocPtr result; + + source = xmljParseDocument (env, self, in, detectBuffer, publicId, systemId, + base, 0, 0, 0, 0, 0, + entityResolver, errorHandler, 0, 0, 2); + result = xmljTransform (env, self, source); + xmljSaveFileToJavaOutputStream (env, out, result, + (const char*) result->encoding); + xmlFreeDoc (result); +} + +/* GnomeTransformer.transformStreamToDoc */ +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_transform_GnomeTransformer_transformStreamToDoc +(JNIEnv *env, jobject self, jobject in, jbyteArray detectBuffer, + jstring publicId, jstring systemId, jstring base, + jboolean entityResolver, jboolean errorHandler) +{ + xmlDocPtr source; + xmlDocPtr result; + + source = xmljParseDocument (env, self, in, detectBuffer, publicId, systemId, + base, 0, 0, 0, 0, 0, + entityResolver, errorHandler, 0, 0, 2); + result = xmljTransform (env, self, source); + return xmljGetNodeInstance (env, (xmlNodePtr) result); +} + +/* GnomeTransformer.transformStreamToSAX */ +JNIEXPORT void JNICALL +Java_gnu_xml_libxmlj_transform_GnomeTransformer_transformStreamToSAX +(JNIEnv *env, jobject self, jobject in, jbyteArray detectBuffer, + jstring publicId, jstring systemId, jstring base, + jboolean entityResolver, jboolean errorHandler, jobject callback) +{ + xmlDocPtr source; + + source = xmljParseDocument (env, self, in, detectBuffer, publicId, systemId, + base, 0, 0, 0, 0, 0, + entityResolver, errorHandler, 0, 0, 2); + xmljTransformToSAX (env, self, source, callback); +} + +/* GnomeTransformer.transformDocToStream */ +JNIEXPORT void JNICALL +Java_gnu_xml_libxmlj_transform_GnomeTransformer_transformDocToStream +(JNIEnv *env, jobject self, jobject doc, jobject out) +{ + xmlDocPtr source; + xmlDocPtr result; + + source = (xmlDocPtr) xmljGetNodeID (env, doc); + result = xmljTransform (env, self, source); + xmljSaveFileToJavaOutputStream (env, out, result, + (const char*) result->encoding); + xmlFreeDoc (result); +} + +/* GnomeTransformer.transformDocToDoc */ +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_transform_GnomeTransformer_transformDocToDoc +(JNIEnv *env, jobject self, jobject doc) +{ + xmlDocPtr source; + xmlDocPtr result; + + source = (xmlDocPtr) xmljGetNodeID (env, doc); + result = xmljTransform (env, self, source); + return xmljGetNodeInstance (env, (xmlNodePtr) result); +} + +/* GnomeTransformer.transformDocToSAX */ +JNIEXPORT void JNICALL +Java_gnu_xml_libxmlj_transform_GnomeTransformer_transformDocToSAX +(JNIEnv *env, jobject self, jobject doc, jobject callback) +{ + xmlDocPtr source; + + source = (xmlDocPtr) xmljGetNodeID (env, doc); + xmljTransformToSAX (env, self, source, callback); +} + +/* GnomeTransformer.free */ +JNIEXPORT void JNICALL +Java_gnu_xml_libxmlj_transform_GnomeTransformer_free (JNIEnv *env, + jobject self) +{ + xsltStylesheetPtr stylesheet; + + stylesheet = xmljGetStylesheetID (env, self); + xsltFreeStylesheet (stylesheet); +} + +/* + * -------------------------------------------------------------------------- + * Native implementation for class + * gnu.xml.libxmlj.transform.GnomeTransformerFactory follows. + */ + +/* GnomeTransformerFactory.freeLibxsltGlobal */ +JNIEXPORT void JNICALL +Java_gnu_xml_libxmlj_transform_GnomeTransformerFactory_freeLibxsltGlobal ( + JNIEnv *env __attribute__((__unused__)), + jclass clazz __attribute__((__unused__))) +{ + xsltCleanupGlobals (); + xmlCleanupParser (); +} + diff --git a/libjava/classpath/native/jni/xmlj/xmlj_util.c b/libjava/classpath/native/jni/xmlj/xmlj_util.c new file mode 100644 index 000000000..409eb6e75 --- /dev/null +++ b/libjava/classpath/native/jni/xmlj/xmlj_util.c @@ -0,0 +1,280 @@ +/* xmlj_util.c + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include "xmlj_util.h" +#include "xmlj_error.h" +#include +#include +#include + +/* xmlChar->jstring cache */ +#ifdef XMLJ_STRING_CACHE +#define XMLJ_STRING_CACHE_SIZE 1024 +xmlHashTablePtr xmljStringCache = NULL; + +void +xmljHashDeallocate (void *data, xmlChar *name); + +void +xmljHashDeallocate (void *data, xmlChar *name) +{ + /* NOOP */ +} +#endif /* XMLJ_STRING_CACHE */ + +jstring +xmljNewString (JNIEnv * env, const xmlChar * text) +{ + jstring ret; + + if (text == NULL || (*env)->ExceptionOccurred (env)) + { + return NULL; + } +#ifdef XMLJ_STRING_CACHE + if (xmljStringCache == NULL) /* Init cache */ + { + xmljStringCache = xmlHashCreate (XMLJ_STRING_CACHE_SIZE); + } + ret = (jstring) xmlHashLookup (xmljStringCache, text); + if (ret == NULL) + { + ret = (*env)->NewStringUTF (env, (char *) text); + if (ret == NULL) /* Why? */ + { + fprintf(stderr, "xmljNewString: ERROR: NewStringUTF returned null for \"%s\"\n", text); + fflush (stderr); + } + else + { + xmlHashAddEntry (xmljStringCache, text, ret); + } + } +#else + ret = (*env)->NewStringUTF (env, (char *) text); + if (ret == NULL) /* Why? */ + { + printf("xmljNewString: ERROR: NewStringUTF returned null for \"%s\"\n", text); + } +#endif /* XMLJ_STRING_CACHE */ + return ret; +} + +void +xmljClearStringCache () +{ +#ifdef XMLJ_STRING_CACHE + if (xmljStringCache != NULL) + { + xmlHashFree (xmljStringCache, &xmljHashDeallocate); + } +#endif /* XMLJ_STRING_CACHE */ +} + +const xmlChar * +xmljGetStringChars (JNIEnv * env, jstring text) +{ + const char *s_text; + xmlChar *x_text; + + if (text == NULL) + { + return NULL; + } + + s_text = (*env)->GetStringUTFChars (env, text, 0); + x_text = (s_text == NULL) ? NULL : xmlCharStrdup (s_text); + if (s_text != NULL && x_text == NULL) + { + /* TODO raise exception */ + } + (*env)->ReleaseStringUTFChars (env, text, s_text); + return x_text; +} + +const xmlChar * +xmljGetPrefix (const xmlChar * qName) +{ + const xmlChar *localName; + const xmlChar *ret; + xmlChar **prefix; + + prefix = (xmlChar **) malloc (sizeof (xmlChar *)); + localName = xmlSplitQName2 (qName, prefix); + if (localName == NULL) + { + return NULL; + } + ret = *prefix; + free (prefix); + return ret; +} + +const xmlChar * +xmljGetLocalName (const xmlChar * qName) +{ + const xmlChar *localName; + xmlChar **prefix; + + prefix = (xmlChar **) malloc (sizeof (xmlChar *)); + localName = xmlSplitQName2 (qName, prefix); + if (localName == NULL) + { + return qName; + } + free (prefix); + return localName; +} + +jmethodID xmljGetMethodID (JNIEnv *env, + jobject target, + const char *name, + const char *signature) +{ + jclass cls; + jmethodID ret; + + cls = (*env)->GetObjectClass (env, target); + if (cls == NULL) + { + xmljThrowException (env, + "java/lang/ClassNotFoundException", + NULL); + return NULL; + } + ret = (*env)->GetMethodID (env, + cls, + name, + signature); + if (ret == NULL) + { + jclass clscls; + jmethodID nm; + jstring clsname; + const char *c_clsName; + char cat[512] = "[method signature too long]"; + + clscls = (*env)->FindClass (env, "java/lang/Class"); + if (clscls == NULL) + { + return NULL; + } + nm = (*env)->GetMethodID (env, clscls, "getName", + "()Ljava/lang/String;"); + if (nm == NULL) + { + return NULL; + } + clsname = (jstring) (*env)->CallObjectMethod (env, + (jobject)cls, + nm); + if (clsname == NULL) + { + return NULL; + } + c_clsName = (*env)->GetStringUTFChars (env, clsname, 0); + sprintf (cat, "%s.%s %s", c_clsName, name, signature); + xmljThrowException (env, + "java/lang/NoSuchMethodException", + cat); + (*env)->ReleaseStringUTFChars (env, clsname, c_clsName); + } + return ret; +} + +void * +xmljAsPointer (JNIEnv *env, jobject ptr) +{ + return JCL_GetRawData(env, ptr); +} + +jobject +xmljAsField (JNIEnv *env, void * ptr) +{ + return JCL_NewRawDataObject(env, ptr); +} + +JNIEnv * +xmljGetJNIEnv () +{ + JavaVM **jvms; + jsize *jvm_count; + JavaVM *jvm; + JNIEnv **envs; + JNIEnv *env; + + jvms = (JavaVM **) malloc (sizeof (JavaVM *)); + if (!jvms) + { + return NULL; + } + jvm_count = (jsize *) malloc (sizeof (jsize)); + if (!jvm_count) + { + free (jvms); + return NULL; + } + if (JNI_GetCreatedJavaVMs (jvms, 1, jvm_count)) + { + free (jvms); + free (jvm_count); + return NULL; + } + jvm = *jvms; + envs = (JNIEnv **) malloc (sizeof (JNIEnv *)); + if (!envs) + { + free (jvms); + free (jvm_count); + return NULL; + } + (*jvm)->AttachCurrentThread (jvm, (void **) envs, NULL); + (*jvm)->GetEnv (jvm, (void **) envs, JNI_VERSION_1_2); + if (envs) + { + env = *envs; + free (envs); + } + else + { + env = NULL; + } + free (jvms); + free (jvm_count); + return env; +} + diff --git a/libjava/classpath/native/jni/xmlj/xmlj_util.h b/libjava/classpath/native/jni/xmlj/xmlj_util.h new file mode 100644 index 000000000..72601ae9f --- /dev/null +++ b/libjava/classpath/native/jni/xmlj/xmlj_util.h @@ -0,0 +1,65 @@ +/* xmlj_util.h - + Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#ifndef XMLJ_UTIL_H +#define XMLJ_UTIL_H + +#include +#include + +jstring xmljNewString (JNIEnv *, const xmlChar *); + +void xmljClearStringCache (void); + +const xmlChar *xmljGetStringChars (JNIEnv *, jstring); + +const xmlChar *xmljGetPrefix (const xmlChar * qName); + +const xmlChar *xmljGetLocalName (const xmlChar * qName); + +jmethodID xmljGetMethodID (JNIEnv *env, + jobject target, + const char *name, + const char *signature); + +void * xmljAsPointer (JNIEnv *env, jobject field); + +jobject xmljAsField (JNIEnv *env, void * ptr); + +JNIEnv * xmljGetJNIEnv (void); + +#endif /* !defined XMLJ_UTIL_H */ diff --git a/libjava/classpath/native/jni/xmlj/xmlj_xpath.c b/libjava/classpath/native/jni/xmlj/xmlj_xpath.c new file mode 100644 index 000000000..6aabaad23 --- /dev/null +++ b/libjava/classpath/native/jni/xmlj/xmlj_xpath.c @@ -0,0 +1,624 @@ +/* xmlj_xpath.c - + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include "gnu_xml_libxmlj_dom_GnomeDocument.h" +#include "gnu_xml_libxmlj_dom_GnomeElement.h" +#include "gnu_xml_libxmlj_dom_GnomeXPathExpression.h" +#include "gnu_xml_libxmlj_dom_GnomeXPathNodeList.h" +#include "gnu_xml_libxmlj_dom_GnomeXPathResult.h" +#include "xmlj_node.h" +#include "xmlj_util.h" +#include + +/* Local function prototypes */ + +xmlXPathContextPtr +xmljCreateXPathContextPtr (xmlNodePtr node); + +jobject +xmljGetXPathResult (JNIEnv *env, xmlXPathObjectPtr obj); + +jobject +xmljGetXPathNodeList (JNIEnv *env, xmlXPathObjectPtr obj); + +xmlXPathObjectPtr +xmljGetXPathObjectID (JNIEnv *env, jobject obj); + +/** + * Creates an XPath context for the given node. + */ +xmlXPathContextPtr +xmljCreateXPathContextPtr (xmlNodePtr node) +{ + xmlXPathContextPtr ctx; + + ctx = xmlXPathNewContext (node->doc); + ctx->node = node; + return ctx; +} + +/** + * Converts an xmlXPathObjectPtr to a Java XPathResult. + */ +jobject +xmljGetXPathResult (JNIEnv *env, xmlXPathObjectPtr obj) +{ + jclass cls; + jmethodID method; + jobject ret; + jobject val; + + if (obj == NULL) + { + return NULL; + } + cls = (*env)->FindClass (env, "gnu/xml/libxmlj/dom/GnomeXPathResult"); + if (cls == NULL) + { + return NULL; + } + method = (*env)->GetMethodID (env, cls, "", "(Ljava/lang/Object;)V"); + if (method == NULL) + { + return NULL; + } + val = xmljAsField (env, obj); + ret = (*env)->NewObject (env, cls, method, val); + + return ret; +} + +/** + * Converts an xmlXPathObjectPtr to a Java XPathNodeList. + */ +jobject +xmljGetXPathNodeList (JNIEnv *env, xmlXPathObjectPtr obj) +{ + jclass cls; + jmethodID method; + jobject ret; + jobject val; + + if (obj == NULL) + { + return NULL; + } + cls = (*env)->FindClass (env, "gnu/xml/libxmlj/dom/GnomeXPathNodeList"); + if (cls == NULL) + { + return NULL; + } + method = (*env)->GetMethodID (env, cls, "", "(Ljava/lang/Object;)V"); + if (method == NULL) + { + return NULL; + } + val = xmljAsField (env, obj); + ret = (*env)->NewObject (env, cls, method, val); + + return ret; +} + +xmlXPathObjectPtr +xmljGetXPathObjectID (JNIEnv *env, jobject obj) +{ + jclass cls; + jfieldID field; + jobject val; + xmlXPathObjectPtr ret; + + cls = (*env)->GetObjectClass (env, obj); + if (cls == NULL) + { + return NULL; + } + field = (*env)->GetFieldID (env, cls, "obj", "Ljava/lang/Object;"); + if (field == NULL) + { + return NULL; + } + val = (*env)->GetObjectField (env, obj, field); + ret = (xmlXPathObjectPtr) xmljAsPointer (env, val); + + return ret; +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeDocument_evaluate (JNIEnv *env, + jobject self + __attribute__((__unused__)), + jstring expression, + jobject contextNode, + jobject resolver, + jshort type, + jobject result) +{ + const xmlChar *str; + xmlNodePtr node; + xmlXPathContextPtr ctx; + xmlXPathObjectPtr eval = NULL; + + str = xmljGetStringChars (env, expression); + node = xmljGetNodeID (env, contextNode); + if (node == NULL) + { + return NULL; + } + ctx = xmljCreateXPathContextPtr (node); + if (ctx != NULL) + { + eval = xmlXPathEval (str, ctx); + xmlXPathFreeContext (ctx); + } + xmlFree ((xmlChar *) str); + return xmljGetXPathResult (env, eval); +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeXPathExpression_init (JNIEnv *env, + jobject self + __attribute__((__unused__)), + jstring expression) +{ + const xmlChar *str; + xmlXPathCompExprPtr ptr; + + str = xmljGetStringChars (env, expression); + ptr = xmlXPathCompile (str); + xmlFree ((xmlChar *) str); + return xmljAsField (env, ptr); +} + +JNIEXPORT void JNICALL +Java_gnu_xml_libxmlj_dom_GnomeXPathExpression_free (JNIEnv *env, + jobject self + __attribute__((__unused__)), + jobject ptr) +{ + xmlXPathCompExprPtr expr; + + expr = (xmlXPathCompExprPtr) xmljAsPointer (env, ptr); + xmlXPathFreeCompExpr (expr); +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeXPathExpression_doEvaluate (JNIEnv *env, + jobject self + __attribute__((__unused__)), + jobject ptr, + jobject contextNode, + jshort type, + jobject result) +{ + xmlXPathCompExprPtr expr; + xmlNodePtr node; + xmlXPathContextPtr ctx; + xmlXPathObjectPtr eval = NULL; + + expr = (xmlXPathCompExprPtr) xmljAsPointer (env, ptr); + node = xmljGetNodeID (env, contextNode); + if (node == NULL) + { + return NULL; + } + ctx = xmljCreateXPathContextPtr (node); + if (ctx != NULL) + { + eval = xmlXPathCompiledEval (expr, ctx); + xmlXPathFreeContext (ctx); + } + return xmljGetXPathResult (env, eval); +} + +JNIEXPORT void JNICALL +Java_gnu_xml_libxmlj_dom_GnomeXPathResult_free (JNIEnv *env, + jobject self + __attribute__((__unused__)), + jobject obj) +{ + xmlXPathFreeObject ((xmlXPathObjectPtr) xmljAsPointer (env, obj)); +} + +JNIEXPORT jshort JNICALL +Java_gnu_xml_libxmlj_dom_GnomeXPathResult_getResultType (JNIEnv *env, + jobject self) +{ + xmlXPathObjectPtr obj; + + obj = xmljGetXPathObjectID (env, self); + switch (obj->type) + { + case XPATH_UNDEFINED: + return 0; /* ANY_TYPE */ + case XPATH_NUMBER: + return 1; /* NUMBER_TYPE */ + case XPATH_STRING: + return 2; /* STRING_TYPE */ + case XPATH_BOOLEAN: + return 3; /* BOOLEAN_TYPE */ + case XPATH_NODESET: + return 6; /* UNORDERED_NODE_SNAPSHOT_TYPE */ + case XPATH_POINT: + case XPATH_RANGE: + case XPATH_LOCATIONSET: + case XPATH_USERS: + case XPATH_XSLT_TREE: + /* TODO */ + default: + return -1; /* TODO */ + } +} + +JNIEXPORT jdouble JNICALL +Java_gnu_xml_libxmlj_dom_GnomeXPathResult_getNumberValue (JNIEnv *env, + jobject self) +{ + xmlXPathObjectPtr obj; + + obj = xmljGetXPathObjectID (env, self); + if (obj == NULL) + { + return 0.0; + } + return obj->floatval; +} + +JNIEXPORT jstring JNICALL +Java_gnu_xml_libxmlj_dom_GnomeXPathResult_getStringValue (JNIEnv *env, + jobject self) +{ + xmlXPathObjectPtr obj; + + obj = xmljGetXPathObjectID (env, self); + if (obj == NULL) + { + return NULL; + } + return xmljNewString (env, obj->stringval); +} + +JNIEXPORT jboolean JNICALL +Java_gnu_xml_libxmlj_dom_GnomeXPathResult_getBooleanValue (JNIEnv *env, + jobject self) +{ + xmlXPathObjectPtr obj; + + obj = xmljGetXPathObjectID (env, self); + return obj->boolval; +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeXPathResult_getSingleNodeValue (JNIEnv *env, + jobject self) +{ + xmlXPathObjectPtr obj; + + obj = xmljGetXPathObjectID (env, self); + if (obj == NULL) + { + return NULL; + } + if (obj->nodesetval == NULL) + { + return NULL; + } + if (obj->nodesetval->nodeNr > 0) + { + return xmljGetNodeInstance (env, obj->nodesetval->nodeTab[0]); + } + else + { + return NULL; + } +} + +JNIEXPORT jboolean JNICALL +Java_gnu_xml_libxmlj_dom_GnomeXPathResult_getInvalidIteratorState (JNIEnv *env, + jobject self) +{ + xmlXPathObjectPtr obj; + + obj = xmljGetXPathObjectID (env, self); + return 0; /* TODO */ +} + +JNIEXPORT jint JNICALL +Java_gnu_xml_libxmlj_dom_GnomeXPathResult_getSnapshotLength (JNIEnv *env, + jobject self) +{ + xmlXPathObjectPtr obj; + + obj = xmljGetXPathObjectID (env, self); + if (obj == NULL) + { + return -1; + } + if (obj->nodesetval == NULL) + { + return -1; + } + return obj->nodesetval->nodeNr; +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeXPathResult_iterateNext (JNIEnv *env, + jobject self) +{ + xmlXPathObjectPtr obj; + + obj = xmljGetXPathObjectID (env, self); + return NULL; /* TODO */ +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeXPathResult_snapshotItem (JNIEnv *env, + jobject self, + jint index) +{ + xmlXPathObjectPtr obj; + + obj = xmljGetXPathObjectID (env, self); + if (obj == NULL) + { + return NULL; + } + if (obj->nodesetval == NULL) + { + return NULL; + } + if (obj->nodesetval->nodeNr > 0) + { + return xmljGetNodeInstance (env, obj->nodesetval->nodeTab[index]); + } + else + { + return NULL; + } +} + +/* -- GnomeXPathNodeList -- */ + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeDocument_getElementsByTagName (JNIEnv *env, + jobject self, + jstring name) +{ + return Java_gnu_xml_libxmlj_dom_GnomeElement_getElementsByTagName (env, + self, + name); +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeElement_getElementsByTagName (JNIEnv *env, + jobject self, + jstring name) +{ + const xmlChar *s_name; + const xmlChar *format; + xmlChar expr[256]; + xmlNodePtr node; + xmlXPathContextPtr ctx; + xmlXPathObjectPtr eval = NULL; + + node = xmljGetNodeID (env, self); + if (node == NULL) + { + return NULL; + } + s_name = xmljGetStringChars (env, name); + if (xmlStrEqual (s_name, BAD_CAST "*")) + { + format = xmlCharStrdup ("descendant-or-self::*[node-type()=1]"); + if (xmlStrPrintf (expr, 256, format) == -1) + { + return NULL; + } + } + else + { + format = xmlCharStrdup ("descendant-or-self::*[name()='%s']"); + if (xmlStrPrintf (expr, 256, format, s_name) == -1) + { + return NULL; + } + } + xmlFree ((xmlChar *) s_name); + ctx = xmljCreateXPathContextPtr (node); + if (ctx != NULL) + { + eval = xmlXPathEval (expr, ctx); + xmlXPathFreeContext (ctx); + } + return xmljGetXPathNodeList (env, eval); +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeDocument_getElementsByTagNameNS (JNIEnv *env, + jobject self, + jstring uri, + jstring localName) +{ + return Java_gnu_xml_libxmlj_dom_GnomeElement_getElementsByTagNameNS (env, + self, + uri, + localName); +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeElement_getElementsByTagNameNS (JNIEnv *env, + jobject self, + jstring uri, + jstring localName) +{ + const xmlChar *s_uri; + const xmlChar *s_localName; + const xmlChar *format; + xmlChar expr[256]; + xmlNodePtr node; + xmlXPathContextPtr ctx; + xmlXPathObjectPtr eval = NULL; + + node = xmljGetNodeID (env, self); + if (node == NULL) + { + return NULL; + } + s_uri = xmljGetStringChars (env, uri); + s_localName = xmljGetStringChars (env, localName); + if (uri == NULL) + { + /* namespace URI is empty */ + if (xmlStrEqual (s_localName, BAD_CAST "*")) + { + format = xmlCharStrdup ("descendant-or-self::*[namespace-uri()='' and node-type()=1]"); + if (xmlStrPrintf (expr, 256, format) == -1) + { + return NULL; + } + } + else + { + format = xmlCharStrdup ("descendant-or-self::*[namespace-uri()='' and local-name()='%s']"); + if (xmlStrPrintf (expr, 256, format, s_localName) == -1) + { + return NULL; + } + } + } + else if (xmlStrEqual (s_uri, BAD_CAST "*")) + { + /* matches all namespaces */ + if (xmlStrEqual (s_localName, BAD_CAST "*")) + { + format = xmlCharStrdup ("descendant-or-self::*[node-type()=1]"); + if (xmlStrPrintf (expr, 256, format) == -1) + { + return NULL; + } + } + else + { + format = xmlCharStrdup ("descendant-or-self::*[local-name()='%s']"); + if (xmlStrPrintf (expr, 256, format, s_localName) == -1) + { + return NULL; + } + } + } + else + { + if (xmlStrEqual (s_localName, BAD_CAST "*")) + { + format = xmlCharStrdup ("descendant-or-self::*[namespace-uri()='%s' and node-type()=1]"); + if (xmlStrPrintf (expr, 256, format, s_uri) == -1) + { + return NULL; + } + } + else + { + format = xmlCharStrdup ("descendant-or-self::*[namespace-uri()='%s' and local-name()='%s']"); + if (xmlStrPrintf (expr, 256, format, s_uri, s_localName) == -1) + { + return NULL; + } + } + } + xmlFree ((xmlChar *) s_uri); + xmlFree ((xmlChar *) s_localName); + ctx = xmljCreateXPathContextPtr (node); + if (ctx != NULL) + { + eval = xmlXPathEval (expr, ctx); + xmlXPathFreeContext (ctx); + } + return xmljGetXPathNodeList (env, eval); +} + +JNIEXPORT void JNICALL +Java_gnu_xml_libxmlj_dom_GnomeXPathNodeList_free (JNIEnv *env, + jobject self + __attribute__((__unused__)), + jobject obj) +{ + xmlXPathFreeObject ((xmlXPathObjectPtr) xmljAsPointer (env, obj)); +} + +JNIEXPORT jint JNICALL +Java_gnu_xml_libxmlj_dom_GnomeXPathNodeList_getLength (JNIEnv *env, + jobject self) +{ + xmlXPathObjectPtr obj; + + obj = xmljGetXPathObjectID (env, self); + if (obj == NULL) + { + return 0; + } + if (obj->nodesetval == NULL) + { + return 0; + } + return obj->nodesetval->nodeNr; +} + +JNIEXPORT jobject JNICALL +Java_gnu_xml_libxmlj_dom_GnomeXPathNodeList_item (JNIEnv *env, + jobject self, + jint index) +{ + xmlXPathObjectPtr obj; + + obj = xmljGetXPathObjectID (env, self); + if (obj == NULL) + { + return NULL; + } + if (obj->nodesetval == NULL) + { + return NULL; + } + if (obj->nodesetval->nodeNr > 0) + { + return xmljGetNodeInstance (env, obj->nodesetval->nodeTab[index]); + } + else + { + return NULL; + } +} + diff --git a/libjava/classpath/native/plugin/.cvsignore b/libjava/classpath/native/plugin/.cvsignore new file mode 100644 index 000000000..17cbfe80b --- /dev/null +++ b/libjava/classpath/native/plugin/.cvsignore @@ -0,0 +1,6 @@ +Makefile.in +.deps +.libs +libgcjwebplugin_la-gcjwebplugin.lo +libgcjwebplugin.la +Makefile diff --git a/libjava/classpath/native/plugin/Makefile.am b/libjava/classpath/native/plugin/Makefile.am new file mode 100644 index 000000000..28268bf48 --- /dev/null +++ b/libjava/classpath/native/plugin/Makefile.am @@ -0,0 +1,18 @@ +nativeexeclib_LTLIBRARIES = libgcjwebplugin.la + +libgcjwebplugin_la_SOURCES = gcjwebplugin.cc + +libgcjwebplugin_la_CXXFLAGS = \ + -Wall -DAPPLETVIEWER_EXECUTABLE="\"$(bindir)/`echo gappletviewer | sed '$(program_transform_name)'`\"" \ + $(MOZILLA_CFLAGS) $(GLIB_CFLAGS) $(GTK_CFLAGS) + +libgcjwebplugin_la_LDFLAGS = -avoid-version \ + $(GLIB_LIBS) $(GTK_LIBS) \ + -lstdc++ $(AM_LDFLAGS) + +install-plugin: $(nativeexeclib_LTLIBRARIES) + $(INSTALL) -d -m0755 $(DESTDIR)$(PLUGIN_DIR) + $(INSTALL) .libs/libgcjwebplugin.so $(DESTDIR)$(PLUGIN_DIR) + +uninstall-plugin: + rm -f $(DESTDIR)$(PLUGIN_DIR)/libgcjwebplugin.so diff --git a/libjava/classpath/native/plugin/Makefile.in b/libjava/classpath/native/plugin/Makefile.in new file mode 100644 index 000000000..798bc6d12 --- /dev/null +++ b/libjava/classpath/native/plugin/Makefile.in @@ -0,0 +1,627 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +subdir = native/plugin +DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/../../config/depstand.m4 \ + $(top_srcdir)/../../config/lead-dot.m4 \ + $(top_srcdir)/../../config/lib-ld.m4 \ + $(top_srcdir)/../../config/lib-link.m4 \ + $(top_srcdir)/../../config/lib-prefix.m4 \ + $(top_srcdir)/../../config/multi.m4 \ + $(top_srcdir)/../../config/no-executables.m4 \ + $(top_srcdir)/../../config/override.m4 \ + $(top_srcdir)/../../libtool.m4 \ + $(top_srcdir)/../../ltoptions.m4 \ + $(top_srcdir)/../../ltsugar.m4 \ + $(top_srcdir)/../../ltversion.m4 \ + $(top_srcdir)/../../lt~obsolete.m4 \ + $(top_srcdir)/m4/ac_prog_antlr.m4 \ + $(top_srcdir)/m4/ac_prog_java.m4 \ + $(top_srcdir)/m4/ac_prog_java_works.m4 \ + $(top_srcdir)/m4/ac_prog_javac.m4 \ + $(top_srcdir)/m4/ac_prog_javac_works.m4 \ + $(top_srcdir)/m4/acattribute.m4 $(top_srcdir)/m4/accross.m4 \ + $(top_srcdir)/m4/acinclude.m4 \ + $(top_srcdir)/m4/ax_create_stdint_h.m4 \ + $(top_srcdir)/m4/ax_func_which_gethostbyname_r.m4 \ + $(top_srcdir)/m4/gcc_attribute.m4 $(top_srcdir)/m4/iconv.m4 \ + $(top_srcdir)/m4/pkg.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/../../mkinstalldirs +CONFIG_HEADER = $(top_builddir)/include/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__installdirs = "$(DESTDIR)$(nativeexeclibdir)" +LTLIBRARIES = $(nativeexeclib_LTLIBRARIES) +libgcjwebplugin_la_LIBADD = +am_libgcjwebplugin_la_OBJECTS = libgcjwebplugin_la-gcjwebplugin.lo +libgcjwebplugin_la_OBJECTS = $(am_libgcjwebplugin_la_OBJECTS) +libgcjwebplugin_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CXXLD) \ + $(libgcjwebplugin_la_CXXFLAGS) $(CXXFLAGS) \ + $(libgcjwebplugin_la_LDFLAGS) $(LDFLAGS) -o $@ +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/include +depcomp = $(SHELL) $(top_srcdir)/../../depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +LTCXXCOMPILE = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +CXXLD = $(CXX) +CXXLINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(libgcjwebplugin_la_SOURCES) +ETAGS = etags +CTAGS = ctags +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +ANTLR = @ANTLR@ +ANTLR_JAR = @ANTLR_JAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CAIRO_CFLAGS = @CAIRO_CFLAGS@ +CAIRO_LIBS = @CAIRO_LIBS@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CLASSPATH_CONVENIENCE = @CLASSPATH_CONVENIENCE@ +CLASSPATH_INCLUDES = @CLASSPATH_INCLUDES@ +CLASSPATH_MODULE = @CLASSPATH_MODULE@ +COLLECTIONS_PREFIX = @COLLECTIONS_PREFIX@ +CP = @CP@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DATE = @DATE@ +DEFAULT_PREFS_PEER = @DEFAULT_PREFS_PEER@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +ECJ_JAR = @ECJ_JAR@ +EGREP = @EGREP@ +ERROR_CFLAGS = @ERROR_CFLAGS@ +EXAMPLESDIR = @EXAMPLESDIR@ +EXEEXT = @EXEEXT@ +EXTRA_CFLAGS = @EXTRA_CFLAGS@ +FGREP = @FGREP@ +FIND = @FIND@ +FREETYPE2_CFLAGS = @FREETYPE2_CFLAGS@ +FREETYPE2_LIBS = @FREETYPE2_LIBS@ +GCONF_CFLAGS = @GCONF_CFLAGS@ +GCONF_LIBS = @GCONF_LIBS@ +GDK_CFLAGS = @GDK_CFLAGS@ +GDK_LIBS = @GDK_LIBS@ +GJDOC = @GJDOC@ +GLIB_CFLAGS = @GLIB_CFLAGS@ +GLIB_LIBS = @GLIB_LIBS@ +GMP_CFLAGS = @GMP_CFLAGS@ +GMP_LIBS = @GMP_LIBS@ +GREP = @GREP@ +GSTREAMER_BASE_CFLAGS = @GSTREAMER_BASE_CFLAGS@ +GSTREAMER_BASE_LIBS = @GSTREAMER_BASE_LIBS@ +GSTREAMER_CFLAGS = @GSTREAMER_CFLAGS@ +GSTREAMER_FILE_READER = @GSTREAMER_FILE_READER@ +GSTREAMER_LIBS = @GSTREAMER_LIBS@ +GSTREAMER_MIXER_PROVIDER = @GSTREAMER_MIXER_PROVIDER@ +GSTREAMER_PLUGINS_BASE_CFLAGS = @GSTREAMER_PLUGINS_BASE_CFLAGS@ +GSTREAMER_PLUGINS_BASE_LIBS = @GSTREAMER_PLUGINS_BASE_LIBS@ +GST_PLUGIN_LDFLAGS = @GST_PLUGIN_LDFLAGS@ +GTK_CFLAGS = @GTK_CFLAGS@ +GTK_LIBS = @GTK_LIBS@ +INIT_LOAD_LIBRARY = @INIT_LOAD_LIBRARY@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAR = @JAR@ +JAVA = @JAVA@ +JAVAC = @JAVAC@ +JAVAC_IS_GCJ = @JAVAC_IS_GCJ@ +JAVAC_MEM_OPT = @JAVAC_MEM_OPT@ +JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION = @JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION@ +JAY = @JAY@ +JAY_SKELETON = @JAY_SKELETON@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBDEBUG = @LIBDEBUG@ +LIBICONV = @LIBICONV@ +LIBMAGIC = @LIBMAGIC@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBVERSION = @LIBVERSION@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBICONV = @LTLIBICONV@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MKDIR = @MKDIR@ +MKDIR_P = @MKDIR_P@ +MOC = @MOC@ +MOZILLA_CFLAGS = @MOZILLA_CFLAGS@ +MOZILLA_LIBS = @MOZILLA_LIBS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PANGOFT2_CFLAGS = @PANGOFT2_CFLAGS@ +PANGOFT2_LIBS = @PANGOFT2_LIBS@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PATH_TO_ESCHER = @PATH_TO_ESCHER@ +PATH_TO_GLIBJ_ZIP = @PATH_TO_GLIBJ_ZIP@ +PERL = @PERL@ +PKG_CONFIG = @PKG_CONFIG@ +PLUGIN_DIR = @PLUGIN_DIR@ +QT_CFLAGS = @QT_CFLAGS@ +QT_LIBS = @QT_LIBS@ +RANLIB = @RANLIB@ +REMOVE = @REMOVE@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRICT_WARNING_CFLAGS = @STRICT_WARNING_CFLAGS@ +STRIP = @STRIP@ +TOOLSDIR = @TOOLSDIR@ +USER_JAVAH = @USER_JAVAH@ +VERSION = @VERSION@ +WANT_NATIVE_BIG_INTEGER = @WANT_NATIVE_BIG_INTEGER@ +WARNING_CFLAGS = @WARNING_CFLAGS@ +XMKMF = @XMKMF@ +XML_CFLAGS = @XML_CFLAGS@ +XML_LIBS = @XML_LIBS@ +XSLT_CFLAGS = @XSLT_CFLAGS@ +XSLT_LIBS = @XSLT_LIBS@ +XTEST_LIBS = @XTEST_LIBS@ +X_CFLAGS = @X_CFLAGS@ +X_EXTRA_LIBS = @X_EXTRA_LIBS@ +X_LIBS = @X_LIBS@ +X_PRE_LIBS = @X_PRE_LIBS@ +ZIP = @ZIP@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_ANTLR = @ac_ct_ANTLR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +default_toolkit = @default_toolkit@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +glibjdir = @glibjdir@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +multi_basedir = @multi_basedir@ +nativeexeclibdir = @nativeexeclibdir@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +toolexeclibdir = @toolexeclibdir@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +uudecode = @uudecode@ +vm_classes = @vm_classes@ +nativeexeclib_LTLIBRARIES = libgcjwebplugin.la +libgcjwebplugin_la_SOURCES = gcjwebplugin.cc +libgcjwebplugin_la_CXXFLAGS = \ + -Wall -DAPPLETVIEWER_EXECUTABLE="\"$(bindir)/`echo gappletviewer | sed '$(program_transform_name)'`\"" \ + $(MOZILLA_CFLAGS) $(GLIB_CFLAGS) $(GTK_CFLAGS) + +libgcjwebplugin_la_LDFLAGS = -avoid-version \ + $(GLIB_LIBS) $(GTK_LIBS) \ + -lstdc++ $(AM_LDFLAGS) + +all: all-am + +.SUFFIXES: +.SUFFIXES: .cc .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu native/plugin/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu native/plugin/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-nativeexeclibLTLIBRARIES: $(nativeexeclib_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(nativeexeclibdir)" || $(MKDIR_P) "$(DESTDIR)$(nativeexeclibdir)" + @list='$(nativeexeclib_LTLIBRARIES)'; test -n "$(nativeexeclibdir)" || list=; \ + list2=; for p in $$list; do \ + if test -f $$p; then \ + list2="$$list2 $$p"; \ + else :; fi; \ + done; \ + test -z "$$list2" || { \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(nativeexeclibdir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(nativeexeclibdir)"; \ + } + +uninstall-nativeexeclibLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(nativeexeclib_LTLIBRARIES)'; test -n "$(nativeexeclibdir)" || list=; \ + for p in $$list; do \ + $(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(nativeexeclibdir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(nativeexeclibdir)/$$f"; \ + done + +clean-nativeexeclibLTLIBRARIES: + -test -z "$(nativeexeclib_LTLIBRARIES)" || rm -f $(nativeexeclib_LTLIBRARIES) + @list='$(nativeexeclib_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libgcjwebplugin.la: $(libgcjwebplugin_la_OBJECTS) $(libgcjwebplugin_la_DEPENDENCIES) + $(libgcjwebplugin_la_LINK) -rpath $(nativeexeclibdir) $(libgcjwebplugin_la_OBJECTS) $(libgcjwebplugin_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgcjwebplugin_la-gcjwebplugin.Plo@am__quote@ + +.cc.o: +@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $< + +.cc.obj: +@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.cc.lo: +@am__fastdepCXX_TRUE@ $(LTCXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(LTCXXCOMPILE) -c -o $@ $< + +libgcjwebplugin_la-gcjwebplugin.lo: gcjwebplugin.cc +@am__fastdepCXX_TRUE@ $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgcjwebplugin_la_CXXFLAGS) $(CXXFLAGS) -MT libgcjwebplugin_la-gcjwebplugin.lo -MD -MP -MF $(DEPDIR)/libgcjwebplugin_la-gcjwebplugin.Tpo -c -o libgcjwebplugin_la-gcjwebplugin.lo `test -f 'gcjwebplugin.cc' || echo '$(srcdir)/'`gcjwebplugin.cc +@am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/libgcjwebplugin_la-gcjwebplugin.Tpo $(DEPDIR)/libgcjwebplugin_la-gcjwebplugin.Plo +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='gcjwebplugin.cc' object='libgcjwebplugin_la-gcjwebplugin.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgcjwebplugin_la_CXXFLAGS) $(CXXFLAGS) -c -o libgcjwebplugin_la-gcjwebplugin.lo `test -f 'gcjwebplugin.cc' || echo '$(srcdir)/'`gcjwebplugin.cc + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) +installdirs: + for dir in "$(DESTDIR)$(nativeexeclibdir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-nativeexeclibLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-nativeexeclibLTLIBRARIES + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-nativeexeclibLTLIBRARIES + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-nativeexeclibLTLIBRARIES ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags dvi dvi-am html html-am info info-am install \ + install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-nativeexeclibLTLIBRARIES install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-nativeexeclibLTLIBRARIES + + +install-plugin: $(nativeexeclib_LTLIBRARIES) + $(INSTALL) -d -m0755 $(DESTDIR)$(PLUGIN_DIR) + $(INSTALL) .libs/libgcjwebplugin.so $(DESTDIR)$(PLUGIN_DIR) + +uninstall-plugin: + rm -f $(DESTDIR)$(PLUGIN_DIR)/libgcjwebplugin.so + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/libjava/classpath/native/plugin/gcjwebplugin.cc b/libjava/classpath/native/plugin/gcjwebplugin.cc new file mode 100644 index 000000000..71cffccb6 --- /dev/null +++ b/libjava/classpath/native/plugin/gcjwebplugin.cc @@ -0,0 +1,1803 @@ +/* gcjwebplugin.cc -- web browser plugin to execute Java applets + Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +// System includes. +#include +#include +#include +#include +#include +#include + +// Netscape plugin API includes. +#include +#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20) +#include +#else +#include +#endif + +// GLib includes. +#include +#include + +// GTK includes. +#include + +// gcjwebplugin includes. +#include "config.h" + +// Documentbase retrieval includes. +#include +#include +#include + +// Debugging macros. +#define PLUGIN_DEBUG(message) \ + g_print ("GCJ PLUGIN: thread %p: %s\n", g_thread_self (), message) + +#define PLUGIN_DEBUG_TWO(first, second) \ + g_print ("GCJ PLUGIN: thread %p: %s %s\n", g_thread_self (), \ + first, second) + +// Error reporting macros. +#define PLUGIN_ERROR(message) \ + g_printerr ("%s:%d: thread %p: Error: %s\n", __FILE__, __LINE__, \ + g_thread_self (), message) + +#define PLUGIN_ERROR_TWO(first, second) \ + g_printerr ("%s:%d: thread %p: Error: %s: %s\n", __FILE__, __LINE__, \ + g_thread_self (), first, second) + +#define PLUGIN_ERROR_THREE(first, second, third) \ + g_printerr ("%s:%d: thread %p: Error: %s: %s: %s\n", __FILE__, \ + __LINE__, g_thread_self (), first, second, third) + +// Plugin information passed to about:plugins. +#define PLUGIN_NAME "GCJ Web Browser Plugin" +#define PLUGIN_DESC "The " PLUGIN_NAME " executes Java applets." +#define PLUGIN_MIME_DESC \ + "application/x-java-vm:class,jar:GCJ;" \ + "application/x-java-applet:class,jar:GCJ;" \ + "application/x-java-applet;version=1.1:class,jar:GCJ;" \ + "application/x-java-applet;version=1.1.1:class,jar:GCJ;" \ + "application/x-java-applet;version=1.1.2:class,jar:GCJ;" \ + "application/x-java-applet;version=1.1.3:class,jar:GCJ;" \ + "application/x-java-applet;version=1.2:class,jar:GCJ;" \ + "application/x-java-applet;version=1.2.1:class,jar:GCJ;" \ + "application/x-java-applet;version=1.2.2:class,jar:GCJ;" \ + "application/x-java-applet;version=1.3:class,jar:GCJ;" \ + "application/x-java-applet;version=1.3.1:class,jar:GCJ;" \ + "application/x-java-applet;version=1.4:class,jar:GCJ;" \ + "application/x-java-applet;version=1.4.1:class,jar:GCJ;" \ + "application/x-java-applet;version=1.4.2:class,jar:GCJ;" \ + "application/x-java-applet;jpi-version=1.4.2_01:class,jar:GCJ;" \ + "application/x-java-bean:class,jar:GCJ;" \ + "application/x-java-bean;version=1.1:class,jar:GCJ;" \ + "application/x-java-bean;version=1.1.1:class,jar:GCJ;" \ + "application/x-java-bean;version=1.1.2:class,jar:GCJ;" \ + "application/x-java-bean;version=1.1.3:class,jar:GCJ;" \ + "application/x-java-bean;version=1.2:class,jar:GCJ;" \ + "application/x-java-bean;version=1.2.1:class,jar:GCJ;" \ + "application/x-java-bean;version=1.2.2:class,jar:GCJ;" \ + "application/x-java-bean;version=1.3:class,jar:GCJ;" \ + "application/x-java-bean;version=1.3.1:class,jar:GCJ;" \ + "application/x-java-bean;version=1.4:class,jar:GCJ;" \ + "application/x-java-bean;version=1.4.1:class,jar:GCJ;" \ + "application/x-java-bean;version=1.4.2:class,jar:GCJ;" \ + "application/x-java-bean;jpi-version=1.4.2_01:class,jar:GCJ;" +#define PLUGIN_URL NS_INLINE_PLUGIN_CONTRACTID_PREFIX NS_JVM_MIME_TYPE +#define PLUGIN_MIME_TYPE "application/x-java-vm" +#define PLUGIN_FILE_EXTS "class,jar,zip" +#define PLUGIN_MIME_COUNT 1 + +// Security dialog messages. +#define RESPONSE_TRUST_APPLET "Trust Applet" +#define RESPONSE_TRUST_APPLET_ADD_TO_LIST "Trust Applet and Add to Whitelist" +#define SECURITY_WARNING \ + "%s wants to load an applet.\n" \ + "GNU Classpath's security implementation is not complete.\n" \ + "HOSTILE APPLETS WILL STEAL AND/OR DESTROY YOUR DATA!\n" +#define SECURITY_DESCRIPTION \ + "Click \"Cancel\" if you do not trust the source of this applet.\n" \ + "Click \"Trust Applet\" to load and run this applet now.\n" \ + "Click \"Trust Applet and Add To Whitelist\" to always load" \ + " and run this applet from now on, without asking.\n" \ + "The whitelist is a list of the URLs from which you trust" \ + " applets.\n" \ + "Your whitelist file is \" %s \"." +#define FAILURE_MESSAGE \ + "This page wants to load an applet.\n" \ + "The appletviewer is missing or not installed properly in \"" \ + APPLETVIEWER_EXECUTABLE "\"." + +// Documentbase retrieval required definition. +static NS_DEFINE_IID (kIPluginTagInfo2IID, NS_IPLUGINTAGINFO2_IID); + +// Browser function table. +static NPNetscapeFuncs browserFunctions; + +// Data directory for plugin. +static gchar* data_directory; + +// Whitelist filename +static gchar* whitelist_filename; + +// Keeps track of initialization. NP_Initialize should only be +// called once. +gboolean initialized = false; + +// GCJPluginData stores all the data associated with a single plugin +// instance. A separate plugin instance is created for each +// tag. For now, each plugin instance spawns its own applet viewer +// process but this may need to change if we find pages containing +// multiple applets that expect to be running in the same VM. +struct GCJPluginData +{ + // A unique identifier for this plugin window. + gchar* instance_string; + // Applet viewer input pipe name. + gchar* in_pipe_name; + // Applet viewer input channel. + GIOChannel* in_from_appletviewer; + // Applet viewer input watch source. + gint in_watch_source; + // Applet viewer output pipe name. + gchar* out_pipe_name; + // Applet viewer output channel. + GIOChannel* out_to_appletviewer; + // Applet viewer output watch source. + gint out_watch_source; + // Mutex to protect appletviewer_alive. + GMutex* appletviewer_mutex; + // Back-pointer to the plugin instance to which this data belongs. + // This should not be freed but instead simply set to NULL. + NPP owner; + // FALSE if the applet viewer process has died. All code + // communicating with the applet viewer should check this flag + // before attempting to read from/write to the applet viewer pipes. + gboolean appletviewer_alive; + // The address of the plugin window. This should not be freed but + // instead simply set to NULL. + gpointer window_handle; + // The last plugin window width sent to us by the browser. + guint32 window_width; + // The last plugin window height sent to us by the browser. + guint32 window_height; +}; + +// Documentbase retrieval type-punning union. +typedef union +{ + void** void_field; + nsIPluginTagInfo2** info_field; +} info_union; + +// Static instance helper functions. +// Have the browser allocate a new GCJPluginData structure. +static void plugin_data_new (GCJPluginData** data); +// Documentbase retrieval. +static gchar* plugin_get_documentbase (NPP instance); +// plugin failure handling. +static bool plugin_failed (); +// Whitelist handling. +static bool plugin_user_trusts_documentbase (char* documentbase); +static bool plugin_ask_user_about_documentbase (char* documentbase); +static void plugin_add_documentbase_to_whitelist (char* documentbase); +// Callback used to monitor input pipe status. +static gboolean plugin_in_pipe_callback (GIOChannel* source, + GIOCondition condition, + gpointer plugin_data); +// Callback used to monitor output pipe status. +static gboolean plugin_out_pipe_callback (GIOChannel* source, + GIOCondition condition, + gpointer plugin_data); +static NPError plugin_start_appletviewer (GCJPluginData* data); +static gchar* plugin_create_applet_tag (int16 argc, char* argn[], + char* argv[]); +static void plugin_send_message_to_appletviewer (GCJPluginData* data, + gchar const* message); +static void plugin_stop_appletviewer (GCJPluginData* data); +// Uninitialize GCJPluginData structure and delete pipes. +static void plugin_data_destroy (GCJPluginData** data); + +// Global instance counter. +// Mutex to protect plugin_instance_counter. +static GMutex* plugin_instance_mutex = NULL; +// A counter used to create uniquely named pipes. +static gulong plugin_instance_counter = 0; +// The user's documentbase whitelist. +static GIOChannel* whitelist_file = NULL; +// A global variable for reporting GLib errors. This must be free'd +// and set to NULL after each use. +static GError* channel_error = NULL; + +// Functions prefixed by GCJ_ are instance functions. They are called +// by the browser and operate on instances of GCJPluginData. +// Functions prefixed by plugin_ are static helper functions. +// Functions prefixed by NP_ are factory functions. They are called +// by the browser and provide functionality needed to create plugin +// instances. + +// INSTANCE FUNCTIONS + +// Creates a new gcjwebplugin instance. This function creates a +// GCJPluginData* and stores it in instance->pdata. The following +// GCJPluginData fiels are initialized: instance_string, in_pipe_name, +// in_from_appletviewer, in_watch_source, out_pipe_name, +// out_to_appletviewer, out_watch_source, appletviewer_mutex, owner, +// appletviewer_alive. In addition two pipe files are created. All +// of those fields must be properly destroyed, and the pipes deleted, +// by GCJ_Destroy. If an error occurs during initialization then this +// function will free anything that's been allocated so far, set +// instance->pdata to NULL and return an error code. +NPError +GCJ_New (NPMIMEType pluginType, NPP instance, uint16 mode, + int16 argc, char* argn[], char* argv[], + NPSavedData* saved) +{ + PLUGIN_DEBUG ("GCJ_New"); + + NPError np_error = NPERR_NO_ERROR; + GCJPluginData* data = NULL; + + gchar* documentbase = NULL; + gchar* read_message = NULL; + gchar* applet_tag = NULL; + gchar* tag_message = NULL; + + if (!instance) + { + PLUGIN_ERROR ("Browser-provided instance pointer is NULL."); + np_error = NPERR_INVALID_INSTANCE_ERROR; + goto cleanup_done; + } + + // data + plugin_data_new (&data); + if (data == NULL) + { + PLUGIN_ERROR ("Failed to allocate plugin data."); + np_error = NPERR_OUT_OF_MEMORY_ERROR; + goto cleanup_done; + } + + // Initialize data->instance_string. + // + // instance_string should be unique for this process so we use a + // combination of getpid and plugin_instance_counter. + // + // Critical region. Reference and increment plugin_instance_counter + // global. + g_mutex_lock (plugin_instance_mutex); + + // data->instance_string + data->instance_string = g_strdup_printf ("instance-%d-%ld", + getpid (), + plugin_instance_counter++); + + g_mutex_unlock (plugin_instance_mutex); + + // data->appletviewer_mutex + data->appletviewer_mutex = g_mutex_new (); + + // Documentbase retrieval. + documentbase = plugin_get_documentbase (instance); + if (!documentbase) + { + PLUGIN_ERROR ("Documentbase retrieval failed." + " Browser not Mozilla-based?"); + goto cleanup_appletviewer_mutex; + } + + // Open the user's documentbase whitelist. + whitelist_file = g_io_channel_new_file (whitelist_filename, + "a+", &channel_error); + if (!whitelist_file) + { + if (channel_error) + { + PLUGIN_ERROR_THREE ("Failed to open whitelist file", + whitelist_filename, + channel_error->message); + g_error_free (channel_error); + channel_error = NULL; + } + else + PLUGIN_ERROR_TWO ("Failed to open whitelist file", + whitelist_filename); + + return NPERR_GENERIC_ERROR; + } + + if (!plugin_user_trusts_documentbase (documentbase)) + { + PLUGIN_ERROR ("User does not trust applet."); + np_error = NPERR_GENERIC_ERROR; + goto cleanup_appletviewer_mutex; + } + + // Create appletviewer-to-plugin pipe which we refer to as the input + // pipe. + + // data->in_pipe_name + data->in_pipe_name = g_strdup_printf ("%s/gcj-%s-appletviewer-to-plugin", + data_directory, data->instance_string); + if (!data->in_pipe_name) + { + PLUGIN_ERROR ("Failed to create input pipe name."); + np_error = NPERR_OUT_OF_MEMORY_ERROR; + // If data->in_pipe_name is NULL then the g_free at + // cleanup_in_pipe_name will simply return. + goto cleanup_in_pipe_name; + } + + if (mkfifo (data->in_pipe_name, 0700) == -1 && errno != EEXIST) + { + PLUGIN_ERROR_TWO ("Failed to create input pipe", strerror (errno)); + np_error = NPERR_GENERIC_ERROR; + goto cleanup_in_pipe_name; + } + + // Create plugin-to-appletviewer pipe which we refer to as the + // output pipe. + + // data->out_pipe_name + data->out_pipe_name = g_strdup_printf ("%s/gcj-%s-plugin-to-appletviewer", + data_directory, data->instance_string); + + if (!data->out_pipe_name) + { + PLUGIN_ERROR ("Failed to create output pipe name."); + np_error = NPERR_OUT_OF_MEMORY_ERROR; + goto cleanup_out_pipe_name; + } + + if (mkfifo (data->out_pipe_name, 0700) == -1 && errno != EEXIST) + { + PLUGIN_ERROR_TWO ("Failed to create output pipe", strerror (errno)); + np_error = NPERR_GENERIC_ERROR; + goto cleanup_out_pipe_name; + } + + // Start a separate appletviewer process for each applet, even if + // there are multiple applets in the same page. We may need to + // change this behaviour if we find pages with multiple applets that + // rely on being run in the same VM. + + // Critical region. Hold appletviewer_mutex while we start the + // appletviewer, create the IO channels and install the channel + // watch callbacks. + g_mutex_lock (data->appletviewer_mutex); + + np_error = plugin_start_appletviewer (data); + + // If the appletviewer is not installed, then a dialog box will + // show up and the plugin will be killed. + if (np_error != NPERR_NO_ERROR) + { + if (plugin_failed ()) + goto cleanup_applet_failure; + } + + // Create plugin-to-appletviewer channel. The default encoding for + // the file is UTF-8. + // data->out_to_appletviewer + data->out_to_appletviewer = g_io_channel_new_file (data->out_pipe_name, + "w", &channel_error); + if (!data->out_to_appletviewer) + { + if (channel_error) + { + PLUGIN_ERROR_TWO ("Failed to create output channel", + channel_error->message); + g_error_free (channel_error); + channel_error = NULL; + } + else + PLUGIN_ERROR ("Failed to create output channel"); + + np_error = NPERR_GENERIC_ERROR; + goto cleanup_out_to_appletviewer; + } + + // Watch for hangup and error signals on the output pipe. + data->out_watch_source = + g_io_add_watch (data->out_to_appletviewer, + (GIOCondition) (G_IO_ERR | G_IO_HUP), + plugin_out_pipe_callback, (gpointer) data); + + // Create appletviewer-to-plugin channel. The default encoding for + // the file is UTF-8. + // data->in_from_appletviewer + data->in_from_appletviewer = g_io_channel_new_file (data->in_pipe_name, + "r", &channel_error); + if (!data->in_from_appletviewer) + { + if (channel_error) + { + PLUGIN_ERROR_TWO ("Failed to create input channel", + channel_error->message); + g_error_free (channel_error); + channel_error = NULL; + } + else + PLUGIN_ERROR ("Failed to create input channel"); + + np_error = NPERR_GENERIC_ERROR; + goto cleanup_in_from_appletviewer; + } + + // Watch for hangup and error signals on the input pipe. + data->in_watch_source = + g_io_add_watch (data->in_from_appletviewer, + (GIOCondition) (G_IO_IN | G_IO_ERR | G_IO_HUP), + plugin_in_pipe_callback, (gpointer) data); + + // Wait until we receive confirmation that the appletviewer has + // started. + if (g_io_channel_read_line (data->in_from_appletviewer, + &read_message, NULL, NULL, + &channel_error) + != G_IO_STATUS_NORMAL) + { + if (channel_error) + { + PLUGIN_ERROR_TWO ("Receiving confirmation from appletviewer failed", + channel_error->message); + g_error_free (channel_error); + channel_error = NULL; + } + else + PLUGIN_ERROR ("Receiving confirmation from appletviewer failed"); + + np_error = NPERR_GENERIC_ERROR; + goto cleanup_in_watch_source; + } + + PLUGIN_DEBUG ("GCJ_New: got confirmation that appletviewer is running."); + data->appletviewer_alive = TRUE; + + // Send applet tag message to appletviewer. + applet_tag = plugin_create_applet_tag (argc, argn, argv); + tag_message = g_strconcat ("tag ", documentbase, " ", applet_tag, NULL); + + plugin_send_message_to_appletviewer (data, data->instance_string); + plugin_send_message_to_appletviewer (data, tag_message); + + g_mutex_unlock (data->appletviewer_mutex); + + // If initialization succeeded entirely then we store the plugin + // data in the instance structure and return. Otherwise we free the + // data we've allocated so far and set instance->pdata to NULL. + + // Set back-pointer to owner instance. + data->owner = instance; + instance->pdata = data; + goto cleanup_done; + + // An error occurred while initializing the plugin data or spawning + // the appletviewer so we free the data we've already allocated. + + cleanup_in_watch_source: + // Removing a source is harmless if it fails since it just means the + // source has already been removed. + g_source_remove (data->in_watch_source); + data->in_watch_source = 0; + + cleanup_in_from_appletviewer: + if (data->in_from_appletviewer) + g_io_channel_unref (data->in_from_appletviewer); + data->in_from_appletviewer = NULL; + + // cleanup_out_watch_source: + g_source_remove (data->out_watch_source); + data->out_watch_source = 0; + + cleanup_out_to_appletviewer: + if (data->out_to_appletviewer) + g_io_channel_unref (data->out_to_appletviewer); + data->out_to_appletviewer = NULL; + + // cleanup_out_pipe: + // Delete output pipe. + unlink (data->out_pipe_name); + + cleanup_applet_failure: + cleanup_out_pipe_name: + g_free (data->out_pipe_name); + data->out_pipe_name = NULL; + + // cleanup_in_pipe: + // Delete input pipe. + unlink (data->in_pipe_name); + + cleanup_in_pipe_name: + g_free (data->in_pipe_name); + data->in_pipe_name = NULL; + + cleanup_appletviewer_mutex: + g_free (data->appletviewer_mutex); + data->appletviewer_mutex = NULL; + + // cleanup_instance_string: + g_free (data->instance_string); + data->instance_string = NULL; + + // cleanup_data: + // Eliminate back-pointer to plugin instance. + data->owner = NULL; + (*browserFunctions.memfree) (data); + data = NULL; + + // Initialization failed so return a NULL pointer for the browser + // data. + instance->pdata = NULL; + + cleanup_done: + g_free (tag_message); + tag_message = NULL; + g_free (applet_tag); + applet_tag = NULL; + g_free (read_message); + read_message = NULL; + g_free (documentbase); + documentbase = NULL; + + PLUGIN_DEBUG ("GCJ_New return"); + + return np_error; +} + +NPError +GCJ_GetValue (NPP instance, NPPVariable variable, void* value) +{ + PLUGIN_DEBUG ("GCJ_GetValue"); + + NPError np_error = NPERR_NO_ERROR; + + switch (variable) + { + // This plugin needs XEmbed support. + case NPPVpluginNeedsXEmbed: + { + PLUGIN_DEBUG ("GCJ_GetValue: returning TRUE for NeedsXEmbed."); + PRBool* bool_value = (PRBool*) value; + *bool_value = PR_TRUE; + } + break; + + default: + PLUGIN_ERROR ("Unknown plugin value requested."); + np_error = NPERR_GENERIC_ERROR; + break; + } + + PLUGIN_DEBUG ("GCJ_GetValue return"); + + return np_error; +} + +NPError +GCJ_Destroy (NPP instance, NPSavedData** save) +{ + PLUGIN_DEBUG ("GCJ_Destroy"); + + GCJPluginData* data = (GCJPluginData*) instance->pdata; + + if (data) + { + // Critical region. Stop the appletviewer. + g_mutex_lock (data->appletviewer_mutex); + + // Tell the appletviewer to destroy its embedded plugin window. + plugin_send_message_to_appletviewer (data, "destroy"); + // Shut down the appletviewer. + plugin_stop_appletviewer (data); + + g_mutex_unlock (data->appletviewer_mutex); + + // Free plugin data. + plugin_data_destroy (&data); + } + + PLUGIN_DEBUG ("GCJ_Destroy return"); + + return NPERR_NO_ERROR; +} + +NPError +GCJ_SetWindow (NPP instance, NPWindow* window) +{ + PLUGIN_DEBUG ("GCJ_SetWindow"); + + if (instance == NULL) + { + PLUGIN_ERROR ("Invalid instance."); + + return NPERR_INVALID_INSTANCE_ERROR; + } + + GCJPluginData* data = (GCJPluginData*) instance->pdata; + + // Simply return if we receive a NULL window. + if ((window == NULL) || (window->window == NULL)) + { + PLUGIN_DEBUG ("GCJ_SetWindow: got NULL window."); + + return NPERR_NO_ERROR; + } + + if (data->window_handle) + { + // The window already exists. + if (data->window_handle == window->window) + { + // The parent window is the same as in previous calls. + PLUGIN_DEBUG ("GCJ_SetWindow: window already exists."); + + // Critical region. Read data->appletviewer_mutex and send + // a message to the appletviewer. + g_mutex_lock (data->appletviewer_mutex); + + if (data->appletviewer_alive) + { + // The window is the same as it was for the last + // SetWindow call. + if (window->width != data->window_width) + { + PLUGIN_DEBUG ("GCJ_SetWindow: window width changed."); + // The width of the plugin window has changed. + + // Send the new width to the appletviewer. + plugin_send_message_to_appletviewer (data, + data->instance_string); + gchar* width_message = g_strdup_printf ("width %d", + window->width); + plugin_send_message_to_appletviewer (data, width_message); + g_free (width_message); + width_message = NULL; + + // Store the new width. + data->window_width = window->width; + } + + if (window->height != data->window_height) + { + PLUGIN_DEBUG ("GCJ_SetWindow: window height changed."); + // The height of the plugin window has changed. + + // Send the new height to the appletviewer. + plugin_send_message_to_appletviewer (data, + data->instance_string); + gchar* height_message = g_strdup_printf ("height %d", + window->height); + plugin_send_message_to_appletviewer (data, height_message); + g_free (height_message); + height_message = NULL; + + // Store the new height. + data->window_height = window->height; + } + } + else + { + // The appletviewer is not running. + PLUGIN_DEBUG ("GCJ_SetWindow: appletviewer is not running."); + } + + g_mutex_unlock (data->appletviewer_mutex); + } + else + { + // The parent window has changed. This branch does run but + // doing nothing in response seems to be sufficient. + PLUGIN_DEBUG ("GCJ_SetWindow: parent window changed."); + } + } + else + { + PLUGIN_DEBUG ("GCJ_SetWindow: setting window."); + + // Critical region. Send messages to appletviewer. + g_mutex_lock (data->appletviewer_mutex); + + plugin_send_message_to_appletviewer (data, data->instance_string); + gchar *window_message = g_strdup_printf ("handle %ld", + (gulong) window->window); + plugin_send_message_to_appletviewer (data, window_message); + g_free (window_message); + window_message = NULL; + + g_mutex_unlock (data->appletviewer_mutex); + + // Store the window handle. + data->window_handle = window->window; + } + + PLUGIN_DEBUG ("GCJ_SetWindow return"); + + return NPERR_NO_ERROR; +} + +NPError +GCJ_NewStream (NPP instance, NPMIMEType type, NPStream* stream, + NPBool seekable, uint16* stype) +{ + PLUGIN_DEBUG ("GCJ_NewStream"); + + PLUGIN_DEBUG ("GCJ_NewStream return"); + + return NPERR_NO_ERROR; +} + +void +GCJ_StreamAsFile (NPP instance, NPStream* stream, const char* filename) +{ + PLUGIN_DEBUG ("GCJ_StreamAsFile"); + + PLUGIN_DEBUG ("GCJ_StreamAsFile return"); +} + +NPError +GCJ_DestroyStream (NPP instance, NPStream* stream, NPReason reason) +{ + PLUGIN_DEBUG ("GCJ_DestroyStream"); + + PLUGIN_DEBUG ("GCJ_DestroyStream return"); + + return NPERR_NO_ERROR; +} + +int32 +GCJ_WriteReady (NPP instance, NPStream* stream) +{ + PLUGIN_DEBUG ("GCJ_WriteReady"); + + PLUGIN_DEBUG ("GCJ_WriteReady return"); + + return 0; +} + +int32 +GCJ_Write (NPP instance, NPStream* stream, int32 offset, int32 len, + void* buffer) +{ + PLUGIN_DEBUG ("GCJ_Write"); + + PLUGIN_DEBUG ("GCJ_Write return"); + + return 0; +} + +void +GCJ_Print (NPP instance, NPPrint* platformPrint) +{ + PLUGIN_DEBUG ("GCJ_Print"); + + PLUGIN_DEBUG ("GCJ_Print return"); +} + +int16 +GCJ_HandleEvent (NPP instance, void* event) +{ + PLUGIN_DEBUG ("GCJ_HandleEvent"); + + PLUGIN_DEBUG ("GCJ_HandleEvent return"); + + return 0; +} + +void +GCJ_URLNotify (NPP instance, const char* url, NPReason reason, + void* notifyData) +{ + PLUGIN_DEBUG ("GCJ_URLNotify"); + + PLUGIN_DEBUG ("GCJ_URLNotify return"); +} + +#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20) +jref +#else +void* +#endif +GCJ_GetJavaClass (void) +{ + PLUGIN_DEBUG ("GCJ_GetJavaClass"); + + PLUGIN_DEBUG ("GCJ_GetJavaClass return"); + + return 0; +} + +// HELPER FUNCTIONS + +static void +plugin_data_new (GCJPluginData** data) +{ + PLUGIN_DEBUG ("plugin_data_new"); + + *data = (GCJPluginData*) + (*browserFunctions.memalloc) (sizeof (struct GCJPluginData)); + + // appletviewer_alive is false until the applet viewer is spawned. + if (*data) + memset (*data, 0, sizeof (struct GCJPluginData)); + + PLUGIN_DEBUG ("plugin_data_new return"); +} + +// Documentbase retrieval. This function gets the current document's +// documentbase. This function relies on browser-private data so it +// will only work when the plugin is loaded in a Mozilla-based +// browser. We could not find a way to retrieve the documentbase +// using the original Netscape plugin API so we use the XPCOM API +// instead. +static gchar* +plugin_get_documentbase (NPP instance) +{ + PLUGIN_DEBUG ("plugin_get_documentbase"); + + nsIPluginInstance* xpcom_instance = NULL; + nsIPluginInstancePeer* peer = NULL; + nsresult result = 0; + nsIPluginTagInfo2* pluginTagInfo2 = NULL; + info_union u = { NULL }; + char const* documentbase = NULL; + gchar* documentbase_copy = NULL; + + xpcom_instance = (nsIPluginInstance*) (instance->ndata); + if (!xpcom_instance) + { + PLUGIN_ERROR ("xpcom_instance is NULL."); + goto cleanup_done; + } + + xpcom_instance->GetPeer (&peer); + if (!peer) + { + PLUGIN_ERROR ("peer is NULL."); + goto cleanup_done; + } + + u.info_field = &pluginTagInfo2; + + result = peer->QueryInterface (kIPluginTagInfo2IID, + u.void_field); + if (result || !pluginTagInfo2) + { + PLUGIN_ERROR ("pluginTagInfo2 retrieval failed."); + goto cleanup_peer; + } + + pluginTagInfo2->GetDocumentBase (&documentbase); + + if (!documentbase) + { + PLUGIN_ERROR ("documentbase is NULL."); + goto cleanup_plugintaginfo2; + } + + documentbase_copy = g_strdup (documentbase); + + // Release references. + cleanup_plugintaginfo2: + NS_RELEASE (pluginTagInfo2); + + cleanup_peer: + NS_RELEASE (peer); + + cleanup_done: + PLUGIN_DEBUG ("plugin_get_documentbase return"); + + return documentbase_copy; +} + +// This function shows a error message if the appletviewer has +// not been installed. It returns true, if the user presses the +// ok button. +static bool +plugin_failed () +{ + GtkWidget* dialog = NULL; + GtkWidget* ok_button = NULL; + + dialog = gtk_message_dialog_new (NULL, + GTK_DIALOG_MODAL, + GTK_MESSAGE_WARNING, + GTK_BUTTONS_NONE, + FAILURE_MESSAGE); + ok_button = gtk_dialog_add_button (GTK_DIALOG (dialog), + GTK_STOCK_OK, + GTK_RESPONSE_OK); + gtk_widget_show_all (dialog); + if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) + { + gtk_widget_destroy (dialog); + return true; + } + return false; +} + +// plugin_user_trusts_documentbase returns true if the given +// documentbase is in the documentbase whitelist. Otherwise it asks +// the user if he trusts the given documentbase by calling +// plugin_ask_user_about_documentbase. +static bool +plugin_user_trusts_documentbase (char* documentbase) +{ + bool applet_in_whitelist = false; + + // Check if documentbase is in whitelist. + while (true) + { + gchar* whitelist_entry = NULL; + gchar* newline_documentbase = NULL; + + // If reading fails, break out of this loop with + // applet_in_whitelist still set to false. + if (g_io_channel_read_line (whitelist_file, &whitelist_entry, + NULL, NULL, &channel_error) + != G_IO_STATUS_NORMAL) + { + if (channel_error) + { + PLUGIN_ERROR_TWO ("Failed to read line from whitelist file", + channel_error->message); + g_error_free (channel_error); + channel_error = NULL; + } + else + PLUGIN_ERROR ("Failed to read line from whitelist file."); + g_free (whitelist_entry); + whitelist_entry = NULL; + break; + } + + newline_documentbase = g_strdup_printf ("%s\n", documentbase); + if (!strcmp (newline_documentbase, whitelist_entry)) + { + applet_in_whitelist = true; + g_free (newline_documentbase); + newline_documentbase = NULL; + g_free (whitelist_entry); + whitelist_entry = NULL; + break; + } + g_free (whitelist_entry); + whitelist_entry = NULL; + g_free (newline_documentbase); + newline_documentbase = NULL; + } + + return applet_in_whitelist ? true + : plugin_ask_user_about_documentbase (documentbase); +} + +// plugin_add_documentbase_to_whitelist adds the given documentbase to +// the user's documentbase whitelist. +static void +plugin_add_documentbase_to_whitelist (char* documentbase) +{ + gsize bytes_written = 0; + char* newline_documentbase = NULL; + GIOStatus status = G_IO_STATUS_NORMAL; + + newline_documentbase = g_strdup_printf ("%s\n", documentbase); + status = g_io_channel_write_chars (whitelist_file, + newline_documentbase, -1, &bytes_written, + &channel_error); + g_free (newline_documentbase); + newline_documentbase = NULL; + + if (status != G_IO_STATUS_NORMAL) + { + if (channel_error) + { + PLUGIN_ERROR_TWO ("Error writing to whitelist file", + channel_error->message); + g_error_free (channel_error); + channel_error = NULL; + } + else + PLUGIN_ERROR ("Error writing to whitelist file."); + } + + if (g_io_channel_flush (whitelist_file, &channel_error) + != G_IO_STATUS_NORMAL) + { + if (channel_error) + { + PLUGIN_ERROR_TWO ("Failed to write whitelist file", + channel_error->message); + g_error_free (channel_error); + channel_error = NULL; + } + else + PLUGIN_ERROR ("Failed to write whitelist file."); + } + + if (g_io_channel_shutdown (whitelist_file, TRUE, &channel_error) + != G_IO_STATUS_NORMAL) + { + if (channel_error) + { + PLUGIN_ERROR_TWO ("Failed to close whitelist file", + channel_error->message); + g_error_free (channel_error); + channel_error = NULL; + } + else + PLUGIN_ERROR ("Failed to close whitelist file."); + } +} + +// plugin_ask_user_about_documentbase puts up a dialog box that asks if the +// user trusts applets from this documentbase. The user has three +// options: "Cancel", "Trust Applet" and "Trust Applet and Add to +// Whitelist". If the user selects Cancel (the default) then a +// generic error code is returned from GCJ_New, telling the browser +// that the applet failed to load. If the user selects "Trust Applet" +// then plugin loading proceeds. If the user selects "Trust Applet +// and Add to Whitelist" then this documentbase is added to the user's +// applet whitelist and plugin loading proceeds. +static bool +plugin_ask_user_about_documentbase (char* documentbase) +{ + GtkWidget* dialog = NULL; + GtkWidget* ok_button = NULL; + GtkWidget* cancel_button = NULL; + GtkWidget* whitelist_button = NULL; + gint dialog_response = GTK_RESPONSE_NONE; + + dialog = gtk_message_dialog_new (NULL, + GTK_DIALOG_MODAL, + GTK_MESSAGE_WARNING, + GTK_BUTTONS_NONE, + SECURITY_WARNING, + documentbase); + gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), + SECURITY_DESCRIPTION, whitelist_filename); + + cancel_button = gtk_dialog_add_button (GTK_DIALOG (dialog), + GTK_STOCK_CANCEL, + GTK_RESPONSE_CANCEL); + ok_button = gtk_dialog_add_button (GTK_DIALOG (dialog), + RESPONSE_TRUST_APPLET, + GTK_RESPONSE_OK); + whitelist_button = gtk_dialog_add_button (GTK_DIALOG (dialog), + RESPONSE_TRUST_APPLET_ADD_TO_LIST, + GTK_RESPONSE_APPLY); + gtk_widget_grab_focus (cancel_button); + + gtk_widget_show_all (dialog); + dialog_response = gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + if (dialog_response == GTK_RESPONSE_CANCEL) + { + // The user does not trust this documentbase. + return false; + } + else if (dialog_response == GTK_RESPONSE_APPLY) + { + // The user wants this documentbase added to his documentbase + // whitelist. + plugin_add_documentbase_to_whitelist (documentbase); + } + // The user trusts this documentbase. + return true; +} + +// plugin_in_pipe_callback is called when data is available on the +// input pipe, or when the appletviewer crashes or is killed. It may +// be called after data has been destroyed in which case it simply +// returns FALSE to remove itself from the glib main loop. +static gboolean +plugin_in_pipe_callback (GIOChannel* source, + GIOCondition condition, + gpointer plugin_data) +{ + PLUGIN_DEBUG ("plugin_in_pipe_callback"); + + GCJPluginData* data = (GCJPluginData*) plugin_data; + gboolean keep_installed = TRUE; + + // If data is NULL then GCJ_Destroy has already been called and + // plugin_in_pipe_callback is being called after plugin + // destruction. In that case all we need to do is return FALSE so + // that the plugin_in_pipe_callback watch is removed. + if (data) + { + // Critical region. Set or clear data->appletviewer_alive. + g_mutex_lock (data->appletviewer_mutex); + + if (condition & G_IO_IN) + { + gchar* message = NULL; + + if (g_io_channel_read_line (data->in_from_appletviewer, + &message, NULL, NULL, + &channel_error) + != G_IO_STATUS_NORMAL) + { + if (channel_error) + { + PLUGIN_ERROR_TWO ("Failed to read line from input channel", + channel_error->message); + g_error_free (channel_error); + channel_error = NULL; + } + else + PLUGIN_ERROR ("Failed to read line from input channel"); + } + else + { + if (g_str_has_prefix (message, "url ")) + { + gchar** parts = g_strsplit (message, " ", 3); + PLUGIN_DEBUG_TWO ("plugin_in_pipe_callback:" + " opening URL", parts[1]); + PLUGIN_DEBUG_TWO ("plugin_in_pipe_callback:" + " URL target", parts[2]); + // Open the URL in a new browser window. + NPError np_error = + (*browserFunctions.geturl) (data->owner, parts[1], parts[2]); + if (np_error != NPERR_NO_ERROR) + PLUGIN_ERROR ("Failed to load URL."); + g_strfreev (parts); + parts = NULL; + } + else if (g_str_has_prefix (message, "status ")) + { + gchar** parts = g_strsplit (message, " ", 2); + + PLUGIN_DEBUG_TWO ("plugin_in_pipe_callback:" + " setting status", parts[1]); + (*browserFunctions.status) (data->owner, parts[1]); + g_strfreev (parts); + parts = NULL; + } + g_print (" PIPE: plugin read %s\n", message); + } + + g_free (message); + message = NULL; + + keep_installed = TRUE; + } + + if (condition & (G_IO_ERR | G_IO_HUP)) + { + PLUGIN_DEBUG ("appletviewer has stopped."); + data->appletviewer_alive = FALSE; + keep_installed = FALSE; + } + g_mutex_unlock (data->appletviewer_mutex); + } + + PLUGIN_DEBUG ("plugin_in_pipe_callback return"); + + return keep_installed; +} + +// plugin_out_pipe_callback is called when the appletviewer crashes or +// is killed. It may be called after data has been destroyed in which +// case it simply returns FALSE to remove itself from the glib main +// loop. +static gboolean +plugin_out_pipe_callback (GIOChannel* source, + GIOCondition condition, + gpointer plugin_data) +{ + PLUGIN_DEBUG ("plugin_out_pipe_callback"); + + GCJPluginData* data = (GCJPluginData*) plugin_data; + + // If data is NULL then GCJ_Destroy has already been called and + // plugin_out_pipe_callback is being called after plugin + // destruction. In that case all we need to do is return FALSE so + // that the plugin_out_pipe_callback watch is removed. + if (data) + { + // Critical region. Clear data->appletviewer_alive. + g_mutex_lock (data->appletviewer_mutex); + + PLUGIN_DEBUG ("plugin_out_pipe_callback: appletviewer has stopped."); + data->appletviewer_alive = FALSE; + + g_mutex_unlock (data->appletviewer_mutex); + } + + PLUGIN_DEBUG ("plugin_out_pipe_callback return"); + + return FALSE; +} + +static NPError +plugin_start_appletviewer (GCJPluginData* data) +{ + PLUGIN_DEBUG ("plugin_start_appletviewer"); + NPError error = NPERR_NO_ERROR; + + if (!data->appletviewer_alive) + { + gchar* command_line[3] = { NULL, NULL, NULL }; + + command_line[0] = g_strdup (APPLETVIEWER_EXECUTABLE); + // Output from plugin's perspective is appletviewer's input. + // Input from plugin's perspective is appletviewer's output. + command_line[1] = g_strdup_printf ("--plugin=%s,%s", + data->out_pipe_name, + data->in_pipe_name); + command_line[2] = NULL; + + if (!g_spawn_async (NULL, command_line, NULL, (GSpawnFlags) 0, + NULL, NULL, NULL, &channel_error)) + { + if (channel_error) + { + PLUGIN_ERROR_TWO ("Failed to spawn applet viewer", + channel_error->message); + g_error_free (channel_error); + channel_error = NULL; + } + else + PLUGIN_ERROR ("Failed to spawn applet viewer"); + error = NPERR_GENERIC_ERROR; + goto cleanup; + } + + cleanup: + g_free (command_line[0]); + command_line[0] = NULL; + g_free (command_line[1]); + command_line[1] = NULL; + g_free (command_line[2]); + command_line[2] = NULL; + } + + PLUGIN_DEBUG ("plugin_start_appletviewer return"); + return error; +} + +// Build up the applet tag string that we'll send to the applet +// viewer. +static gchar* +plugin_create_applet_tag (int16 argc, char* argn[], char* argv[]) +{ + PLUGIN_DEBUG ("plugin_create_applet_tag"); + + gchar* applet_tag = g_strdup ("", NULL); + + g_free (escaped); + escaped = NULL; + } + } + } + + applet_tag = g_strconcat (applet_tag, ">", parameters, "", NULL); + + g_free (parameters); + parameters = NULL; + + PLUGIN_DEBUG ("plugin_create_applet_tag return"); + + return applet_tag; +} + +// plugin_send_message_to_appletviewer must be called while holding +// data->appletviewer_mutex. +static void +plugin_send_message_to_appletviewer (GCJPluginData* data, gchar const* message) +{ + PLUGIN_DEBUG ("plugin_send_message_to_appletviewer"); + + if (data->appletviewer_alive) + { + gchar* newline_message = NULL; + gsize bytes_written = 0; + + // Send message to appletviewer. + newline_message = g_strdup_printf ("%s\n", message); + + // g_io_channel_write_chars will return something other than + // G_IO_STATUS_NORMAL if not all the data is written. In that + // case we fail rather than retrying. + if (g_io_channel_write_chars (data->out_to_appletviewer, + newline_message, -1, &bytes_written, + &channel_error) + != G_IO_STATUS_NORMAL) + { + if (channel_error) + { + PLUGIN_ERROR_TWO ("Failed to write bytes to output channel", + channel_error->message); + g_error_free (channel_error); + channel_error = NULL; + } + else + PLUGIN_ERROR ("Failed to write bytes to output channel"); + } + + if (g_io_channel_flush (data->out_to_appletviewer, &channel_error) + != G_IO_STATUS_NORMAL) + { + if (channel_error) + { + PLUGIN_ERROR_TWO ("Failed to flush bytes to output channel", + channel_error->message); + g_error_free (channel_error); + channel_error = NULL; + } + else + PLUGIN_ERROR ("Failed to flush bytes to output channel"); + } + g_free (newline_message); + newline_message = NULL; + + g_print (" PIPE: plugin wrote %s\n", message); + } + + PLUGIN_DEBUG ("plugin_send_message_to_appletviewer return"); +} + +// Stop the appletviewer process. When this is called the +// appletviewer can be in any of three states: running, crashed or +// hung. If the appletviewer is running then sending it "shutdown" +// will cause it to exit. This will cause +// plugin_out_pipe_callback/plugin_in_pipe_callback to be called and +// the input and output channels to be shut down. If the appletviewer +// has crashed then plugin_out_pipe_callback/plugin_in_pipe_callback +// would already have been called and data->appletviewer_alive cleared +// in which case this function simply returns. If the appletviewer is +// hung then this function will be successful and the input and output +// watches will be removed by plugin_data_destroy. +// plugin_stop_appletviewer must be called with +// data->appletviewer_mutex held. +static void +plugin_stop_appletviewer (GCJPluginData* data) +{ + PLUGIN_DEBUG ("plugin_stop_appletviewer"); + + if (data->appletviewer_alive) + { + // Shut down the appletviewer. + gsize bytes_written = 0; + + if (data->out_to_appletviewer) + { + if (g_io_channel_write_chars (data->out_to_appletviewer, "shutdown", + -1, &bytes_written, &channel_error) + != G_IO_STATUS_NORMAL) + { + if (channel_error) + { + PLUGIN_ERROR_TWO ("Failed to write shutdown message to" + " appletviewer", channel_error->message); + g_error_free (channel_error); + channel_error = NULL; + } + else + PLUGIN_ERROR ("Failed to write shutdown message to"); + } + + if (g_io_channel_flush (data->out_to_appletviewer, &channel_error) + != G_IO_STATUS_NORMAL) + { + if (channel_error) + { + PLUGIN_ERROR_TWO ("Failed to write shutdown message to" + " appletviewer", channel_error->message); + g_error_free (channel_error); + channel_error = NULL; + } + else + PLUGIN_ERROR ("Failed to write shutdown message to"); + } + + if (g_io_channel_shutdown (data->out_to_appletviewer, + TRUE, &channel_error) + != G_IO_STATUS_NORMAL) + { + if (channel_error) + { + PLUGIN_ERROR_TWO ("Failed to shut down appletviewer" + " output channel", channel_error->message); + g_error_free (channel_error); + channel_error = NULL; + } + else + PLUGIN_ERROR ("Failed to shut down appletviewer"); + } + } + + if (data->in_from_appletviewer) + { + if (g_io_channel_shutdown (data->in_from_appletviewer, + TRUE, &channel_error) + != G_IO_STATUS_NORMAL) + { + if (channel_error) + { + PLUGIN_ERROR_TWO ("Failed to shut down appletviewer" + " input channel", channel_error->message); + g_error_free (channel_error); + channel_error = NULL; + } + else + PLUGIN_ERROR ("Failed to shut down appletviewer"); + } + } + } + + PLUGIN_DEBUG ("plugin_stop_appletviewer return"); +} + +static void +plugin_data_destroy (GCJPluginData** data) +{ + PLUGIN_DEBUG ("plugin_data_destroy"); + + GCJPluginData* tofree = *data; + + tofree->window_handle = NULL; + tofree->window_height = 0; + tofree->window_width = 0; + + // Copied from GCJ_New. + + // cleanup_in_watch_source: + // Removing a source is harmless if it fails since it just means the + // source has already been removed. + g_source_remove (tofree->in_watch_source); + tofree->in_watch_source = 0; + + // cleanup_in_from_appletviewer: + if (tofree->in_from_appletviewer) + g_io_channel_unref (tofree->in_from_appletviewer); + tofree->in_from_appletviewer = NULL; + + // cleanup_out_watch_source: + g_source_remove (tofree->out_watch_source); + tofree->out_watch_source = 0; + + // cleanup_out_to_appletviewer: + if (tofree->out_to_appletviewer) + g_io_channel_unref (tofree->out_to_appletviewer); + tofree->out_to_appletviewer = NULL; + + // cleanup_out_pipe: + // Delete output pipe. + unlink (tofree->out_pipe_name); + + // cleanup_out_pipe_name: + g_free (tofree->out_pipe_name); + tofree->out_pipe_name = NULL; + + // cleanup_in_pipe: + // Delete input pipe. + unlink (tofree->in_pipe_name); + + // cleanup_in_pipe_name: + g_free (tofree->in_pipe_name); + tofree->in_pipe_name = NULL; + + // cleanup_appletviewer_mutex: + g_free (tofree->appletviewer_mutex); + tofree->appletviewer_mutex = NULL; + + // cleanup_instance_string: + g_free (tofree->instance_string); + tofree->instance_string = NULL; + + // cleanup_data: + // Eliminate back-pointer to plugin instance. + tofree->owner = NULL; + (*browserFunctions.memfree) (tofree); + tofree = NULL; + + PLUGIN_DEBUG ("plugin_data_destroy return"); +} + +// FACTORY FUNCTIONS + +// Provides the browser with pointers to the plugin functions that we +// implement and initializes a local table with browser functions that +// we may wish to call. Called once, after browser startup and before +// the first plugin instance is created. +// The field 'initialized' is set to true once this function has +// finished. If 'initialized' is already true at the beginning of +// this function, then it is evident that NP_Initialize has already +// been called. There is no need to call this function more than once and +// this workaround avoids any duplicate calls. +NPError +NP_Initialize (NPNetscapeFuncs* browserTable, NPPluginFuncs* pluginTable) +{ + PLUGIN_DEBUG ("NP_Initialize"); + + if (initialized) + return NPERR_NO_ERROR; + else if ((browserTable == NULL) || (pluginTable == NULL)) + { + PLUGIN_ERROR ("Browser or plugin function table is NULL."); + + return NPERR_INVALID_FUNCTABLE_ERROR; + } + + // Ensure that the major version of the plugin API that the browser + // expects is not more recent than the major version of the API that + // we've implemented. + if ((browserTable->version >> 8) > NP_VERSION_MAJOR) + { + PLUGIN_ERROR ("Incompatible version."); + + return NPERR_INCOMPATIBLE_VERSION_ERROR; + } + + // Ensure that the plugin function table we've received is large + // enough to store the number of functions that we may provide. + if (pluginTable->size < sizeof (NPPluginFuncs)) + { + PLUGIN_ERROR ("Invalid plugin function table."); + + return NPERR_INVALID_FUNCTABLE_ERROR; + } + + // Ensure that the browser function table is large enough to store + // the number of browser functions that we may use. + if (browserTable->size < sizeof (NPNetscapeFuncs)) + { + PLUGIN_ERROR ("Invalid browser function table."); + + return NPERR_INVALID_FUNCTABLE_ERROR; + } + + data_directory = g_strconcat(getenv("HOME"), "/.gcjwebplugin", NULL); + whitelist_filename = g_strconcat (data_directory, "/whitelist.txt", NULL); + // Make sure the plugin data directory exists, creating it if + // necessary. + if (!g_file_test (data_directory, + (GFileTest) (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))) + { + int file_error = 0; + + file_error = g_mkdir (data_directory, 0700); + if (file_error != 0) + { + PLUGIN_ERROR_THREE ("Failed to create data directory", + data_directory, + strerror (errno)); + return NPERR_GENERIC_ERROR; + } + } + + // Store in a local table the browser functions that we may use. + browserFunctions.version = browserTable->version; + browserFunctions.size = browserTable->size; + browserFunctions.posturl = browserTable->posturl; + browserFunctions.geturl = browserTable->geturl; + browserFunctions.geturlnotify = browserTable->geturlnotify; + browserFunctions.requestread = browserTable->requestread; + browserFunctions.newstream = browserTable->newstream; + browserFunctions.write = browserTable->write; + browserFunctions.destroystream = browserTable->destroystream; + browserFunctions.status = browserTable->status; + browserFunctions.uagent = browserTable->uagent; + browserFunctions.memalloc = browserTable->memalloc; + browserFunctions.memfree = browserTable->memfree; + browserFunctions.memflush = browserTable->memflush; + browserFunctions.reloadplugins = browserTable->reloadplugins; + browserFunctions.getvalue = browserTable->getvalue; + + // Return to the browser the plugin functions that we implement. + pluginTable->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR; + pluginTable->size = sizeof (NPPluginFuncs); +#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20) + pluginTable->newp = NewNPP_NewProc (GCJ_New); + pluginTable->destroy = NewNPP_DestroyProc (GCJ_Destroy); + pluginTable->setwindow = NewNPP_SetWindowProc (GCJ_SetWindow); + pluginTable->newstream = NewNPP_NewStreamProc (GCJ_NewStream); + pluginTable->destroystream = NewNPP_DestroyStreamProc (GCJ_DestroyStream); + pluginTable->asfile = NewNPP_StreamAsFileProc (GCJ_StreamAsFile); + pluginTable->writeready = NewNPP_WriteReadyProc (GCJ_WriteReady); + pluginTable->write = NewNPP_WriteProc (GCJ_Write); + pluginTable->print = NewNPP_PrintProc (GCJ_Print); + pluginTable->urlnotify = NewNPP_URLNotifyProc (GCJ_URLNotify); + pluginTable->getvalue = NewNPP_GetValueProc (GCJ_GetValue); +#else + pluginTable->newp = (NPP_NewProcPtr) (GCJ_New); + pluginTable->destroy = (NPP_DestroyProcPtr) (GCJ_Destroy); + pluginTable->setwindow = (NPP_SetWindowProcPtr) (GCJ_SetWindow); + pluginTable->newstream = (NPP_NewStreamProcPtr) (GCJ_NewStream); + pluginTable->destroystream = (NPP_DestroyStreamProcPtr) (GCJ_DestroyStream); + pluginTable->asfile = (NPP_StreamAsFileProcPtr) (GCJ_StreamAsFile); + pluginTable->writeready = (NPP_WriteReadyProcPtr) (GCJ_WriteReady); + pluginTable->write = (NPP_WriteProcPtr) (GCJ_Write); + pluginTable->print = (NPP_PrintProcPtr) (GCJ_Print); + pluginTable->urlnotify = (NPP_URLNotifyProcPtr) (GCJ_URLNotify); + pluginTable->getvalue = (NPP_GetValueProcPtr) (GCJ_GetValue); +#endif + + initialized = true; + + // Initialize threads (needed for mutexes). + if (!g_thread_supported ()) + g_thread_init (NULL); + + plugin_instance_mutex = g_mutex_new (); + + PLUGIN_DEBUG ("NP_Initialize: using " APPLETVIEWER_EXECUTABLE "."); + + PLUGIN_DEBUG ("NP_Initialize return"); + + return NPERR_NO_ERROR; +} + +// Returns a string describing the MIME type that this plugin +// handles. +char* +NP_GetMIMEDescription (void) +{ + PLUGIN_DEBUG ("NP_GetMIMEDescription"); + + PLUGIN_DEBUG ("NP_GetMIMEDescription return"); + + return (char*) PLUGIN_MIME_DESC; +} + +// Returns a value relevant to the plugin as a whole. The browser +// calls this function to obtain information about the plugin. +NPError +NP_GetValue (void* future, NPPVariable variable, void* value) +{ + PLUGIN_DEBUG ("NP_GetValue"); + + NPError result = NPERR_NO_ERROR; + gchar** char_value = (gchar**) value; + + switch (variable) + { + case NPPVpluginNameString: + PLUGIN_DEBUG ("NP_GetValue: returning plugin name."); + *char_value = g_strdup (PLUGIN_NAME " " PACKAGE_VERSION); + break; + + case NPPVpluginDescriptionString: + PLUGIN_DEBUG ("NP_GetValue: returning plugin description."); + *char_value = g_strdup (PLUGIN_DESC); + break; + + default: + PLUGIN_ERROR ("Unknown plugin value requested."); + result = NPERR_GENERIC_ERROR; + break; + } + + PLUGIN_DEBUG ("NP_GetValue return"); + + return result; +} + +// Shuts down the plugin. Called after the last plugin instance is +// destroyed. +NPError +NP_Shutdown (void) +{ + PLUGIN_DEBUG ("NP_Shutdown"); + + // Free mutex. + if (plugin_instance_mutex) + { + g_mutex_free (plugin_instance_mutex); + plugin_instance_mutex = NULL; + } + + if (whitelist_file) + { + g_io_channel_close (whitelist_file); + whitelist_file = NULL; + } + + if (data_directory) + { + g_free (data_directory); + data_directory = NULL; + } + + if (whitelist_filename) + { + g_free (whitelist_filename); + whitelist_filename = NULL; + } + + initialized = false; + + PLUGIN_DEBUG ("NP_Shutdown return"); + + return NPERR_NO_ERROR; +} -- cgit v1.2.3