WIP.
authorHuang Peng <shawn.p.huang@gmail.com>
Sat, 16 Aug 2008 04:51:47 +0000 (12:51 +0800)
committerHuang Peng <shawn.p.huang@gmail.com>
Sat, 16 Aug 2008 04:51:47 +0000 (12:51 +0800)
86 files changed:
Makefile.am
client/Makefile.am [new file with mode: 0644]
client/gtk2/Makefile.am [new file with mode: 0644]
client/gtk2/ibusim.c [new file with mode: 0644]
client/gtk2/ibusimclient.c [new file with mode: 0644]
client/gtk2/ibusimclient.h [new file with mode: 0644]
client/gtk2/ibusimcontext.c [new file with mode: 0644]
client/gtk2/ibusimcontext.h [new file with mode: 0644]
client/gtk2/ibusmarshalers.list [new file with mode: 0644]
client/qt4/.gitignore [new file with mode: 0644]
client/qt4/Makefile.am [new file with mode: 0644]
client/qt4/ibus-client.cpp [new file with mode: 0644]
client/qt4/ibus-client.h [new file with mode: 0644]
client/qt4/ibus-input-context.cpp [new file with mode: 0644]
client/qt4/ibus-input-context.h [new file with mode: 0644]
client/qt4/ibus.pro [new file with mode: 0644]
client/qt4/im-ibus-qt.cpp [new file with mode: 0644]
client/x11/IMdkit/FrameMgr.c [new file with mode: 0644]
client/x11/IMdkit/FrameMgr.h [new file with mode: 0644]
client/x11/IMdkit/IMConn.c [new file with mode: 0644]
client/x11/IMdkit/IMMethod.c [new file with mode: 0644]
client/x11/IMdkit/IMValues.c [new file with mode: 0644]
client/x11/IMdkit/IMdkit.h [new file with mode: 0644]
client/x11/IMdkit/Makefile.am [new file with mode: 0644]
client/x11/IMdkit/Xi18n.h [new file with mode: 0644]
client/x11/IMdkit/Xi18nX.h [new file with mode: 0644]
client/x11/IMdkit/XimFunc.h [new file with mode: 0644]
client/x11/IMdkit/XimProto.h [new file with mode: 0644]
client/x11/IMdkit/Xtrans.h [new file with mode: 0644]
client/x11/IMdkit/i18nAttr.c [new file with mode: 0644]
client/x11/IMdkit/i18nClbk.c [new file with mode: 0644]
client/x11/IMdkit/i18nIMProto.c [new file with mode: 0644]
client/x11/IMdkit/i18nIc.c [new file with mode: 0644]
client/x11/IMdkit/i18nMethod.c [new file with mode: 0644]
client/x11/IMdkit/i18nPtHdr.c [new file with mode: 0644]
client/x11/IMdkit/i18nUtil.c [new file with mode: 0644]
client/x11/IMdkit/i18nX.c [new file with mode: 0644]
client/x11/Makefile.am [new file with mode: 0644]
client/x11/gdk-private.c [new file with mode: 0644]
client/x11/gdk-private.h [new file with mode: 0644]
client/x11/main.c [new file with mode: 0644]
configure.ac
gtk2/Makefile.am [deleted file]
gtk2/ibusim.c [deleted file]
gtk2/ibusimclient.c [deleted file]
gtk2/ibusimclient.h [deleted file]
gtk2/ibusimcontext.c [deleted file]
gtk2/ibusimcontext.h [deleted file]
gtk2/ibusmarshalers.list [deleted file]
lib/Makefile.am [new file with mode: 0644]
lib/gtk2/Makefile.am [new file with mode: 0644]
lib/gtk2/ibusimclient.c [new file with mode: 0644]
lib/gtk2/ibusimclient.h [new file with mode: 0644]
lib/gtk2/ibusmarshalers.list [new file with mode: 0644]
qt4/.gitignore [deleted file]
qt4/Makefile.am [deleted file]
qt4/ibus-client.cpp [deleted file]
qt4/ibus-client.h [deleted file]
qt4/ibus-input-context.cpp [deleted file]
qt4/ibus-input-context.h [deleted file]
qt4/ibus.pro [deleted file]
qt4/im-ibus-qt.cpp [deleted file]
x11/IMdkit/FrameMgr.c [deleted file]
x11/IMdkit/FrameMgr.h [deleted file]
x11/IMdkit/IMConn.c [deleted file]
x11/IMdkit/IMMethod.c [deleted file]
x11/IMdkit/IMValues.c [deleted file]
x11/IMdkit/IMdkit.h [deleted file]
x11/IMdkit/Makefile.am [deleted file]
x11/IMdkit/Xi18n.h [deleted file]
x11/IMdkit/Xi18nX.h [deleted file]
x11/IMdkit/XimFunc.h [deleted file]
x11/IMdkit/XimProto.h [deleted file]
x11/IMdkit/Xtrans.h [deleted file]
x11/IMdkit/i18nAttr.c [deleted file]
x11/IMdkit/i18nClbk.c [deleted file]
x11/IMdkit/i18nIMProto.c [deleted file]
x11/IMdkit/i18nIc.c [deleted file]
x11/IMdkit/i18nMethod.c [deleted file]
x11/IMdkit/i18nPtHdr.c [deleted file]
x11/IMdkit/i18nUtil.c [deleted file]
x11/IMdkit/i18nX.c [deleted file]
x11/Makefile.am [deleted file]
x11/gdk-private.c [deleted file]
x11/gdk-private.h [deleted file]
x11/main.c [deleted file]

index bff6e8f526fdbf653c0d118f1195fac2f06cb501..977d057e473fea029fb51382bf3ee1fb000c45af 100644 (file)
@@ -26,10 +26,9 @@ SUBDIRS = \
        launcher \
        panel \
        engine \
-       gtk2 \
-       qt4 \
+       lib \
+       client \
        setup \
-       x11 \
        icons \
        m4 \
        po \
diff --git a/client/Makefile.am b/client/Makefile.am
new file mode 100644 (file)
index 0000000..c7bd313
--- /dev/null
@@ -0,0 +1,26 @@
+# vim:set noet ts=4:
+#
+# ibus - The Input Bus
+#
+# Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this program; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+# Boston, MA  02111-1307  USA
+
+SUBDIRS = \
+       gtk2 \
+       qt4 \
+       x11 \
+       $(NULL)
diff --git a/client/gtk2/Makefile.am b/client/gtk2/Makefile.am
new file mode 100644 (file)
index 0000000..465e0ce
--- /dev/null
@@ -0,0 +1,50 @@
+# vim:set noet ts=4:
+#
+# ibus - The Input Bus
+#
+# Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this program; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+# Boston, MA  02111-1307  USA
+
+INCLUDES = \
+       -I$(top_srcdir)/lib/gtk2 \
+       $(NULL)
+
+immoduledir = @GTK_IM_MODULEDIR@
+# $(libdir)/gtk-2.0/immodules
+immodule_LTLIBRARIES = im-ibus.la
+im_ibus_la_DEPENDENCIES = libibus-gtk.la
+im_ibus_la_SOURCES = \
+       ibusim.c \
+       $(NULL)
+im_ibus_la_CFLAGS = \
+       @GTK2_CFLAGS@ \
+       @DBUS_CFLAGS@ \
+       -DG_LOG_DOMAIN=\"IBUS\" \
+       $(NULL)
+im_ibus_la_LDFLAGS = \
+       @GTK2_LIBS@ \
+       @DBUS_LIBS@ \
+       $(builddir)/libibus-gtk.la \
+       -avoid-version \
+       -module \
+       $(NULL)
+
+EXTRA_DIST = \
+       $(NULL)
+
+test: all
+       GTK_IM_MODULE=ibus gedit
diff --git a/client/gtk2/ibusim.c b/client/gtk2/ibusim.c
new file mode 100644 (file)
index 0000000..e87c9f6
--- /dev/null
@@ -0,0 +1,77 @@
+/* vim:set et ts=4: */
+/* IBus - The Input Bus
+ * Copyright (C) 2008-2009 Huang Peng <shawn.p.huang@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include <gtk/gtk.h>
+#include <gtk/gtkimmodule.h>
+#include <string.h>
+#include <stdio.h>
+#include "ibusimclient.h"
+#include "ibusimcontext.h"
+
+#define IBUS_LOCALDIR ""
+
+IBusIMClient *_client = NULL;
+static const GtkIMContextInfo ibus_im_info = {
+    "ibus",
+    "The Input Bus",
+    "ibus",
+    IBUS_LOCALDIR,
+    ""
+};
+
+static const GtkIMContextInfo * info_list[] = {
+    &ibus_im_info
+};
+
+
+void
+im_module_init (GTypeModule *type_module)
+{
+    ibus_im_client_register_type(type_module);
+    ibus_im_context_register_type(type_module);
+
+    _client = ibus_im_client_new ();
+}
+
+void
+im_module_exit (void)
+{
+    g_object_unref (_client);
+}
+
+GtkIMContext *
+im_module_create (const gchar *context_id)
+{
+    if (strcmp (context_id, "ibus") == 0) {
+        const gchar *ic;
+        IBusIMContext *context;
+        ic = ibus_im_client_create_input_context (_client);
+        return GTK_IM_CONTEXT(context);
+    }
+    return NULL;
+}
+
+void
+im_module_list (const GtkIMContextInfo ***contexts,
+                int                      *n_contexts)
+{
+    *contexts = info_list;
+    *n_contexts = G_N_ELEMENTS (info_list);
+}
+
diff --git a/client/gtk2/ibusimclient.c b/client/gtk2/ibusimclient.c
new file mode 100644 (file)
index 0000000..c1535b7
--- /dev/null
@@ -0,0 +1,1308 @@
+/* vim:set et ts=4: */
+/* IBus - The Input Bus
+ * Copyright (C) 2008-2009 Huang Peng <shawn.p.huang@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include <config.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <sys/un.h>
+#include <string.h>
+#include <stdarg.h>
+#include <glib/gstdio.h>
+#include <gdk/gdkkeysyms.h>
+#include <gdk/gdkx.h>
+#include <dbus/dbus.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+
+#ifdef HAVE_SYS_INOTIFY_H
+#define HAVE_INOTIFY
+#  include <sys/inotify.h>
+#endif
+#include "ibusmarshalers.h"
+#include "ibusimclient.h"
+
+enum {
+    CONNECTED,
+    DISCONNECTED,
+    FORWARD_EVENT,
+    COMMIT_STRING,
+    UPDATE_PREEDIT,
+    SHOW_PREEDIT,
+    HIDE_PREEDIT,
+    ENABLED,
+    DISABLED,
+    LAST_SIGNAL,
+};
+
+#define IBUS_NAME  "org.freedesktop.IBus"
+#define IBUS_IFACE "org.freedesktop.IBus"
+#define IBUS_PATH  "/org/freedesktop/IBus"
+
+#define I_(string) g_intern_static_string (string)
+
+/* IBusIMClientPriv */
+struct _IBusIMClientPrivate {
+#if USE_DBUS_SESSION_BUS
+    DBusConnection  *dbus;
+#endif
+
+#ifdef HAVE_INOTIFY
+    /* inotify */
+    gint            inotify_wd;
+    GIOChannel     *inotify_channel;
+    guint           inotify_source;
+#endif
+
+    DBusConnection *ibus;
+
+};
+
+/* variables */
+static guint            client_signals[LAST_SIGNAL] = { 0 };
+
+/* functions prototype */
+static void     ibus_im_client_class_init   (IBusIMClientClass  *klass);
+static void     ibus_im_client_init         (IBusIMClient       *client);
+static void     ibus_im_client_finalize     (GObject            *obj);
+
+static void     _ibus_im_client_ibus_open   (IBusIMClient       *client);
+static void     _ibus_im_client_ibus_close  (IBusIMClient       *client);
+
+static gboolean _ibus_call_with_reply_and_block
+                                           (DBusConnection      *connection,
+                                            const gchar         *method,
+                                            int                 first_arg_type,
+                                                                ...);
+static gboolean _ibus_call_with_reply      (DBusConnection      *connection,
+                                            const gchar         *method,
+                                            DBusPendingCallNotifyFunction
+                                                                function,
+                                            void                *data,
+                                            DBusFreeFunction    free_function,
+                                            int                 first_arg_type,
+                                                                ...);
+static gboolean _dbus_call_with_reply_and_block
+                                           (DBusConnection      *connection,
+                                            const gchar         *dest,
+                                            const gchar         *path,
+                                            const gchar         *iface,
+                                            const char          *method,
+                                            int                 first_arg_type,
+                                                                ...);
+
+/* callback functions */
+static DBusHandlerResult
+                _ibus_im_client_message_filter_cb
+                                           (DBusConnection      *connection,
+                                            DBusMessage         *message,
+                                            void                *user_data);
+
+static GType ibus_type_im_client = 0;
+static GtkObjectClass *parent_class = NULL;
+
+
+GType
+ibus_im_client_get_type (void)
+{
+    if (ibus_type_im_client == 0) {
+        ibus_im_client_register_type (NULL);
+    }
+
+    g_assert (ibus_type_im_client != 0);
+    return ibus_type_im_client;
+}
+
+void
+ibus_im_client_register_type (GTypeModule *type_module)
+{
+    static const GTypeInfo ibus_im_client_info = {
+        sizeof (IBusIMClientClass),
+        (GBaseInitFunc)     NULL,
+        (GBaseFinalizeFunc) NULL,
+        (GClassInitFunc)    ibus_im_client_class_init,
+        NULL,               /* class finialize */
+        NULL,               /* class data */
+        sizeof (IBusIMClient),
+        0,
+        (GInstanceInitFunc) ibus_im_client_init,
+    };
+
+    if (! ibus_type_im_client ) {
+        if (type_module) {
+            ibus_type_im_client =
+                g_type_module_register_type (type_module,
+                    GTK_TYPE_OBJECT,
+                    "IBusIMClient",
+                    &ibus_im_client_info,
+                    (GTypeFlags)0);
+        }
+        else {
+            ibus_type_im_client =
+                g_type_register_static (GTK_TYPE_OBJECT,
+                    "IBusIMClient",
+                    &ibus_im_client_info,
+                    (GTypeFlags)0);
+        }
+    }
+}
+
+IBusIMClient *
+ibus_im_client_new (void)
+{
+    IBusIMClient *client;
+
+    client = IBUS_IM_CLIENT(g_object_new (IBUS_TYPE_IM_CLIENT, NULL));
+
+    return client;
+}
+
+static void
+ibus_im_client_class_init     (IBusIMClientClass *klass)
+{
+    /* GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass); */
+    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+    parent_class = (GtkObjectClass *) g_type_class_peek_parent (klass);
+
+    g_type_class_add_private (klass, sizeof (IBusIMClientPrivate));
+
+    gobject_class->finalize = ibus_im_client_finalize;
+
+    client_signals[CONNECTED] =
+        g_signal_new (I_("connected"),
+            G_TYPE_FROM_CLASS (gobject_class),
+            G_SIGNAL_RUN_FIRST,
+            G_STRUCT_OFFSET (IBusIMClientClass, connected),
+            NULL, NULL,
+            ibus_marshal_VOID__VOID,
+            G_TYPE_NONE, 0);
+
+    client_signals[DISCONNECTED] =
+        g_signal_new (I_("disconnected"),
+            G_TYPE_FROM_CLASS (gobject_class),
+            G_SIGNAL_RUN_FIRST,
+            G_STRUCT_OFFSET (IBusIMClientClass, disconnected),
+            NULL, NULL,
+            ibus_marshal_VOID__VOID,
+            G_TYPE_NONE, 0);
+
+    client_signals[FORWARD_EVENT] =
+        g_signal_new (I_("forward-event"),
+            G_TYPE_FROM_CLASS (gobject_class),
+            G_SIGNAL_RUN_FIRST,
+            G_STRUCT_OFFSET (IBusIMClientClass, commit_string),
+            NULL, NULL,
+            ibus_marshal_VOID__STRING_POINTER,
+            G_TYPE_NONE, 2,
+            G_TYPE_STRING,
+            G_TYPE_POINTER);
+
+
+    client_signals[COMMIT_STRING] =
+        g_signal_new (I_("commit-string"),
+            G_TYPE_FROM_CLASS (gobject_class),
+            G_SIGNAL_RUN_FIRST,
+            G_STRUCT_OFFSET (IBusIMClientClass, commit_string),
+            NULL, NULL,
+            ibus_marshal_VOID__STRING_STRING,
+            G_TYPE_NONE, 2,
+            G_TYPE_STRING,
+            G_TYPE_STRING);
+
+    client_signals[UPDATE_PREEDIT] =
+        g_signal_new (I_("update-preedit"),
+            G_TYPE_FROM_CLASS (gobject_class),
+            G_SIGNAL_RUN_FIRST,
+            G_STRUCT_OFFSET (IBusIMClientClass, update_preedit),
+            NULL, NULL,
+            ibus_marshal_VOID__STRING_STRING_POINTER_INT_BOOLEAN,
+            G_TYPE_NONE, 5,
+            G_TYPE_STRING,
+            G_TYPE_STRING,
+            G_TYPE_POINTER,
+            G_TYPE_INT,
+            G_TYPE_BOOLEAN
+            );
+
+    client_signals[SHOW_PREEDIT] =
+        g_signal_new (I_("show-preedit"),
+            G_TYPE_FROM_CLASS (gobject_class),
+            G_SIGNAL_RUN_FIRST,
+            G_STRUCT_OFFSET (IBusIMClientClass, show_preedit),
+            NULL, NULL,
+            ibus_marshal_VOID__STRING,
+            G_TYPE_NONE, 1,
+            G_TYPE_STRING);
+
+    client_signals[HIDE_PREEDIT] =
+        g_signal_new (I_("hide-preedit"),
+            G_TYPE_FROM_CLASS (gobject_class),
+            G_SIGNAL_RUN_FIRST,
+            G_STRUCT_OFFSET (IBusIMClientClass, hide_preedit),
+            NULL, NULL,
+            ibus_marshal_VOID__STRING,
+            G_TYPE_NONE, 1,
+            G_TYPE_STRING);
+
+    client_signals[ENABLED] =
+        g_signal_new (I_("enabled"),
+            G_TYPE_FROM_CLASS (gobject_class),
+            G_SIGNAL_RUN_FIRST,
+            G_STRUCT_OFFSET (IBusIMClientClass, enabled),
+            NULL, NULL,
+            ibus_marshal_VOID__STRING,
+            G_TYPE_NONE, 1,
+            G_TYPE_STRING);
+
+    client_signals[DISABLED] =
+        g_signal_new (I_("disabled"),
+            G_TYPE_FROM_CLASS (gobject_class),
+            G_SIGNAL_RUN_FIRST,
+            G_STRUCT_OFFSET (IBusIMClientClass, disabled),
+            NULL, NULL,
+            ibus_marshal_VOID__STRING,
+            G_TYPE_NONE, 1,
+            G_TYPE_STRING);
+
+}
+
+/*
+ * open ibus connection
+ */
+static void
+_ibus_im_client_ibus_open (IBusIMClient *client)
+{
+    gchar *ibus_addr = NULL;
+    DBusError error;
+
+    IBusIMClientPrivate *priv = client->priv;
+
+    if (priv->ibus != NULL)
+        return;
+
+#if USE_DBUS_SESSION_BUS
+    dbus_connection_setup_with_g_main (priv->dbus, NULL);
+    if (!_dbus_call_with_reply_and_block (priv->dbus,
+                        IBUS_NAME, IBUS_PATH, IBUS_IFACE,
+                        "GetIBusAddress",
+                        DBUS_TYPE_INVALID,
+                        DBUS_TYPE_STRING, &ibus_addr,
+                        DBUS_TYPE_INVALID
+                        )) {
+        g_warning ("Can not get ibus address");
+        return;
+    }
+#endif
+    if (ibus_addr == NULL) {
+        gchar *display;
+        gchar *hostname = "";
+        gchar *displaynumber = "0";
+        gchar *screennumber = "0";
+        gchar *username = NULL;
+        gchar *p;
+
+        display = g_strdup (g_getenv ("DISPLAY"));
+        if (display == NULL) {
+            g_warning ("DISPLAY is empty! We use default DISPLAY (:0.0)");
+        }
+        else {
+            p = display;
+            hostname = display;
+            for (; *p != ':' && *p != '\0'; p++);
+
+            if (*p == ':') {
+                *p = '\0';
+                p++;
+                displaynumber = p;
+            }
+
+            for (; *p != '.' && *p != '\0'; p++);
+
+            if (*p == '.') {
+                *p = '\0';
+                p++;
+                screennumber = p;
+            }
+        }
+
+        username = g_strdup (getlogin());
+        if (username == NULL)
+            username = g_strdup (g_getenv("LOGNAME"));
+        if (username == NULL)
+            username = g_strdup (g_getenv("USER"));
+        if (username == NULL)
+            username = g_strdup (g_getenv("LNAME"));
+        if (username == NULL)
+            username = g_strdup (g_getenv("USERNAME"));
+
+        ibus_addr = g_strdup_printf (
+            "unix:path=/tmp/ibus-%s/ibus-%s-%s.%s",
+            username, hostname, displaynumber, screennumber);
+
+        g_free (display);
+        g_free (username);
+    }
+
+    /*
+     * Init ibus and proxy object
+     */
+    dbus_error_init (&error);
+    priv->ibus = dbus_connection_open_private (ibus_addr, &error);
+    g_free (ibus_addr);
+    if (priv->ibus == NULL) {
+        g_warning ("Error: %s", error.message);
+        dbus_error_free (&error);
+        return;
+    }
+
+    if (!dbus_connection_add_filter (priv->ibus,
+            _ibus_im_client_message_filter_cb,
+            client, NULL)) {
+        g_warning ("Out of memory");
+        return;
+    }
+
+    dbus_connection_setup_with_g_main (priv->ibus, NULL);
+
+    g_signal_emit (client, client_signals[CONNECTED], 0);
+
+}
+
+/*
+ * close ibus connection
+ */
+static void
+_ibus_im_client_ibus_close (IBusIMClient *client)
+{
+    IBusIMClientPrivate *priv = client->priv;
+
+    if (priv->ibus) {
+        dbus_connection_close (priv->ibus);
+        dbus_connection_unref (priv->ibus);
+        priv->ibus = NULL;
+        g_signal_emit (client, client_signals[DISCONNECTED], 0);
+    }
+}
+
+/*
+ * create a ibus input context
+ */
+const gchar *
+ibus_im_client_create_input_context (IBusIMClient *client)
+{
+    IBusIMClientPrivate *priv = client->priv;
+
+    if (priv->ibus == NULL)
+        return NULL;
+
+    const gchar *app_name = g_get_application_name ();
+    gchar *ic = NULL;
+    _ibus_call_with_reply_and_block (priv->ibus, "CreateInputContext",
+                DBUS_TYPE_STRING, &app_name,
+                DBUS_TYPE_INVALID,
+                DBUS_TYPE_STRING, &ic,
+                DBUS_TYPE_INVALID);
+    return ic;
+}
+
+#ifdef HAVE_INOTIFY
+static gboolean
+_ibus_im_client_inotify_cb (GIOChannel *source, GIOCondition condition, IBusIMClient *client)
+{
+    struct inotify_event *p = NULL;
+    gchar *name;
+    gsize n;
+
+    if ((condition & G_IO_IN) == 0)
+        return TRUE;
+
+    p = g_malloc0 (sizeof (struct inotify_event) + 1024);
+
+    g_io_channel_read_chars (source, (gchar *) p, sizeof (struct inotify_event),  &n, NULL);
+    g_io_channel_read_chars (source, ((gchar *)p) + sizeof (struct inotify_event), p->len,  &n, NULL);
+
+    name = g_strdup_printf ("ibus-%s", g_getenv ("DISPLAY"));
+    for (n = 0; name[n] != 0; n++) {
+        if (name[n] != ':')
+            continue;
+        name[n] = '-';
+        break;
+    }
+
+    if (g_strcmp0 (p->name, name) == 0) {
+        if (p->mask & IN_CREATE) {
+            g_usleep (1000);
+            _ibus_im_client_ibus_open (client);
+        }
+    }
+    g_free (name);
+    g_free (p);
+
+    return TRUE;
+}
+#endif
+
+static void
+ibus_im_client_init (IBusIMClient *obj)
+{
+    DEBUG_FUNCTION_IN;
+
+    IBusIMClient *client = IBUS_IM_CLIENT (obj);
+    IBusIMClientPrivate *priv;
+
+    gchar *watch_path;
+    struct stat stat_buf;
+
+#ifdef HAVE_INOTIFY
+    gint inotify_fd = inotify_init ();
+#endif
+
+    priv = G_TYPE_INSTANCE_GET_PRIVATE (client, IBUS_TYPE_IM_CLIENT, IBusIMClientPrivate);
+    client->priv = priv;
+
+    watch_path = g_strdup_printf ("/tmp/ibus-%s", g_get_user_name ());
+
+    if (g_stat (watch_path, &stat_buf) != 0) {
+        g_mkdir (watch_path, 0750);
+    }
+
+#ifdef HAVE_INOTIFY
+    /* init inotify */
+    priv->inotify_wd = inotify_add_watch (inotify_fd, watch_path, IN_CREATE | IN_DELETE);
+    priv->inotify_channel = g_io_channel_unix_new (inotify_fd);
+    g_io_channel_set_close_on_unref (priv->inotify_channel, TRUE);
+    priv->inotify_source = g_io_add_watch (priv->inotify_channel,
+                                    G_IO_IN,
+                                    (GIOFunc)_ibus_im_client_inotify_cb,
+                                    (gpointer)client);
+#endif
+    g_free (watch_path);
+
+#if USE_DBUS_SESSION_BUS
+    /*
+     * Init dbus
+     */
+    dbus_error_init (&error);
+    priv->dbus = dbus_bus_get (DBUS_BUS_SESSION, &error);
+    if (priv->dbus == NULL) {
+        g_warning ("Error: %s", error.message);
+        dbus_error_free (&error);
+        return;
+    }
+#endif
+
+    _ibus_im_client_ibus_open (client);
+
+#if USE_DBUS_SESSION_BUS
+    if (!dbus_connection_add_filter (priv->dbus,
+            _ibus_im_client_message_filter_cb,
+            client, NULL)) {
+        g_warning ("Out of memory");
+        return;
+    }
+
+    gchar *rule =
+            "type='signal',"
+            "sender='" DBUS_SERVICE_DBUS "',"
+            "interface='" DBUS_INTERFACE_DBUS "',"
+            "member='NameOwnerChanged',"
+            "path='" DBUS_PATH_DBUS "',"
+            "arg0='" IBUS_NAME "'";
+
+    if (!_dbus_call_with_reply_and_block (priv->dbus,
+                        DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS,
+                        "AddMatch",
+                        DBUS_TYPE_STRING, &rule,
+                        DBUS_TYPE_INVALID,
+                        DBUS_TYPE_INVALID
+                        )) {
+        g_warning ("Can not get ibus address");
+        return;
+    }
+#endif
+#if 0
+    /* get dbus proxy */
+    priv->dbus = dbus_g_proxy_new_for_name (priv->ibus,
+                                DBUS_SERVICE_DBUS,
+                                DBUS_PATH_DBUS,
+                                DBUS_INTERFACE_DBUS);
+    g_assert (priv->dbus != NULL);
+
+    /* connect NameOwnerChanged signal */
+    dbus_g_proxy_add_signal (priv->dbus, "NameOwnerChanged",
+                                G_TYPE_STRING,
+                                G_TYPE_STRING,
+                                G_TYPE_STRING,
+                                G_TYPE_INVALID);
+
+    dbus_g_proxy_connect_signal (priv->dbus, "NameOwnerChanged",
+                                G_CALLBACK (_dbus_name_owner_changed_cb),
+                                (gpointer)client, NULL);
+    dbus_bus_add_match ((DBusConnection *)dbus_g_connection_get_connection (priv->ibus),
+                        "type='signal',"
+                        "sender='" DBUS_SERVICE_DBUS
+                        "',interface='" DBUS_INTERFACE_DBUS
+                        "',path='" DBUS_PATH_DBUS
+                        "',member='NameOwnerChanged',"
+                        "arg0='" IBUS_DBUS_SERVICE "'",
+                        &dbus_error);
+
+     _ibus_im_client_reinit_imm (client);
+#endif
+
+}
+
+
+static void
+ibus_im_client_finalize (GObject *obj)
+{
+    DEBUG_FUNCTION_IN;
+
+    IBusIMClient *client = IBUS_IM_CLIENT (obj);
+    IBusIMClientPrivate *priv = client->priv;
+
+    g_assert (client == _client);
+
+#ifdef HAVE_INOTIFY
+    g_source_remove (priv->inotify_source);
+    g_io_channel_unref (priv->inotify_channel);
+#endif
+
+#if USE_DBUS_SESSION_BUS
+    if (priv->dbus) {
+        dbus_connection_unref (priv->dbus);
+    }
+#endif
+    _ibus_im_client_ibus_close (client);
+
+    G_OBJECT_CLASS(parent_class)->finalize (obj);
+
+    _client = NULL;
+}
+
+static void
+_ibus_signal_commit_string_handler (DBusConnection *connection, DBusMessage *message, IBusIMClient *client)
+{
+    /* Handle CommitString signal */
+    DBusError error = {0};
+    gchar *ic = NULL;
+    gchar *string = NULL;
+
+    if (!dbus_message_get_args (message, &error,
+            DBUS_TYPE_STRING, &ic,
+            DBUS_TYPE_STRING, &string,
+            DBUS_TYPE_INVALID)) {
+        g_warning ("%s", error.message);
+        dbus_error_free (&error);
+    }
+    else {
+        g_signal_emit (client, client_signals[COMMIT_STRING], 0, ic, string);
+    }
+}
+
+static void
+_ibus_signal_update_preedit_handler (DBusConnection *connection, DBusMessage *message, IBusIMClient *client)
+{
+    /* Handle UpdatePreedit signal */
+    DBusMessageIter iter, sub_iter;
+    int type, sub_type;
+
+    gchar *ic = NULL;
+    gchar *string = NULL;
+    PangoAttrList *attrs = NULL;
+    int cursor = 0;
+    gboolean visible = False;
+
+    if (!dbus_message_iter_init (message, &iter)) {
+        g_warning ("The UpdatePreedit signal does have args!");
+        return;
+    }
+
+    type = dbus_message_iter_get_arg_type (&iter);
+    if (type != DBUS_TYPE_STRING) {
+        g_warning ("The 1st argument of UpdatePreedit signal must be a String");
+        return;
+    }
+    dbus_message_iter_get_basic (&iter, &ic);
+    dbus_message_iter_next (&iter);
+
+    type = dbus_message_iter_get_arg_type (&iter);
+    if (type != DBUS_TYPE_STRING) {
+        g_warning ("The 2nd argument of UpdatePreedit signal must be a String");
+        return;
+    }
+    dbus_message_iter_get_basic (&iter, &string);
+    dbus_message_iter_next (&iter);
+
+
+    type = dbus_message_iter_get_arg_type (&iter);
+    if (type != DBUS_TYPE_ARRAY) {
+        g_warning ("The 3rd argument of UpdatePreedit signal must be a Struct Array");
+        return;
+    }
+
+    dbus_message_iter_recurse (&iter, &sub_iter);
+
+    if (dbus_message_iter_get_arg_type (&sub_iter) != DBUS_TYPE_INVALID) {
+        if (dbus_message_iter_get_arg_type (&sub_iter) != DBUS_TYPE_ARRAY ||
+            dbus_message_iter_get_element_type (&sub_iter) != DBUS_TYPE_UINT32 ) {
+            g_warning ("The 3rd argument of UpdatePreedit signal must be a Struct Array");
+            return;
+        }
+
+        attrs = pango_attr_list_new ();
+
+        while ((sub_type = dbus_message_iter_get_arg_type (&sub_iter) != DBUS_TYPE_INVALID)) {
+            PangoAttribute *attr;
+            DBusMessageIter sub_sub_iter;
+            guint *values = NULL;
+            gint length = 0;
+            dbus_message_iter_recurse (&sub_iter, &sub_sub_iter);
+            dbus_message_iter_get_fixed_array (&sub_sub_iter, &values, &length);
+
+            if (length <= 0) {
+                g_warning ("The element of the 3rd argument of UpdatePreedit should not be a empty array");
+                continue;
+            }
+
+            switch (values[0]) {
+            case 1: /* Underline */
+                attr = pango_attr_underline_new (values[1]);
+                attr->start_index = g_utf8_offset_to_pointer (string, values[2]) - string;
+                attr->end_index = g_utf8_offset_to_pointer (string, values[3]) - string;
+                pango_attr_list_insert (attrs, attr);
+                break;
+
+            case 2: /* Foreground Color */
+                attr = pango_attr_foreground_new (
+                                (values[1] & 0xff0000) >> 8,
+                                (values[1] & 0x00ff00),
+                                (values[1] & 0x0000ff) << 8
+                                );
+                attr->start_index = g_utf8_offset_to_pointer (string, values[2]) - string;
+                attr->end_index = g_utf8_offset_to_pointer (string, values[3]) - string;
+                pango_attr_list_insert (attrs, attr);
+                break;
+            case 3: /* Background Color */
+                attr = pango_attr_background_new (
+                                (values[1] & 0xff0000) >> 8,
+                                (values[1] & 0x00ff00),
+                                (values[1] & 0x0000ff) << 8
+                                );
+                attr->start_index = g_utf8_offset_to_pointer (string, values[2]) - string;
+                attr->end_index = g_utf8_offset_to_pointer (string, values[3]) - string;
+                pango_attr_list_insert (attrs, attr);
+                break;
+            default:
+                g_warning ("Unkown type attribute type = %d", values[0]);
+
+            }
+
+            dbus_message_iter_next (&sub_iter);
+
+        }
+    }
+    dbus_message_iter_next (&iter);
+
+    type = dbus_message_iter_get_arg_type (&iter);
+    if (type != DBUS_TYPE_INT32) {
+        g_warning ("The 4th argument of UpdatePreedit signal must be an Int32 %c", type);
+        pango_attr_list_unref (attrs);
+        return;
+    }
+    dbus_message_iter_get_basic (&iter, &cursor);
+    dbus_message_iter_next (&iter);
+
+    type = dbus_message_iter_get_arg_type (&iter);
+    if (type != DBUS_TYPE_BOOLEAN) {
+        g_warning ("The 4th argument of UpdatePreedit signal must be an Int32 %c", type);
+        pango_attr_list_unref (attrs);
+        return;
+    }
+    dbus_message_iter_get_basic (&iter, &visible);
+    dbus_message_iter_next (&iter);
+
+    {
+        g_signal_emit (client, client_signals[UPDATE_PREEDIT], 0,
+                ic, string, attrs, cursor, visible);
+    }
+    pango_attr_list_unref (attrs);
+
+}
+
+static void
+_ibus_signal_show_preedit_handler (DBusConnection *connection, DBusMessage *message, IBusIMClient *client)
+{
+    /* Handle CommitString signal */
+    DBusError error = {0};
+    gchar *ic = NULL;
+
+    if (!dbus_message_get_args (message, &error,
+            DBUS_TYPE_STRING, &ic,
+            DBUS_TYPE_INVALID)) {
+        g_warning ("%s", error.message);
+        dbus_error_free (&error);
+    }
+    else {
+        g_signal_emit (client, client_signals[SHOW_PREEDIT], 0, ic);
+    }
+}
+
+static void
+_ibus_signal_hide_preedit_handler (DBusConnection *connection, DBusMessage *message, IBusIMClient *client)
+{
+    /* Handle CommitString signal */
+    DBusError error = {0};
+    gchar *ic = NULL;
+
+    if (!dbus_message_get_args (message, &error,
+            DBUS_TYPE_STRING, &ic,
+            DBUS_TYPE_INVALID)) {
+        g_warning ("%s", error.message);
+        dbus_error_free (&error);
+    }
+    else {
+        g_signal_emit (client, client_signals[HIDE_PREEDIT], 0, ic);
+    }
+}
+
+#ifdef USE_DBUS_SESSION_BUS
+static void
+_ibus_signal_name_owner_changed_handler (DBusConnection *connection, DBusMessage *message, IBusIMClient *client)
+{
+    gchar *name = NULL;
+    gchar *old_name = NULL;
+    gchar *new_name = NULL;
+    DBusError error = {0};
+
+    if (!dbus_message_get_args (message, &error,
+            DBUS_TYPE_STRING, &name,
+            DBUS_TYPE_STRING, &old_name,
+            DBUS_TYPE_STRING, &new_name,
+            DBUS_TYPE_INVALID)) {
+        g_warning ("%s", error.message);
+        dbus_error_free (&error);
+    }
+
+    g_return_if_fail (strcmp (name, IBUS_NAME) == 0);
+
+    if (g_strcmp0 (new_name, "") == 0) {
+        _ibus_im_client_ibus_close (client);
+        priv->enable = FALSE;
+    }
+    else {
+        _ibus_im_client_ibus_open (client);
+        priv->enable = TRUE;
+    }
+}
+#endif
+
+static void
+_ibus_signal_disconnected_handler (DBusConnection *connection, DBusMessage *message, IBusIMClient *client)
+{
+    _ibus_im_client_ibus_close (client);
+}
+
+static void
+_ibus_signal_enabled_handler (DBusConnection *connection, DBusMessage *message, IBusIMClient *client)
+{
+    DEBUG_FUNCTION_IN;
+    /* Handle CommitString signal */
+    DBusError error = {0};
+    gchar *ic = NULL;
+
+    if (!dbus_message_get_args (message, &error,
+            DBUS_TYPE_STRING, &ic,
+            DBUS_TYPE_INVALID)) {
+        g_warning ("%s", error.message);
+        dbus_error_free (&error);
+    }
+    else {
+        g_signal_emit (client, client_signals[ENABLED], 0, ic);
+    }
+}
+
+
+static void
+_ibus_signal_disabled_handler (DBusConnection *connection, DBusMessage *message, IBusIMClient *client)
+{
+    DEBUG_FUNCTION_IN;
+    /* Handle CommitString signal */
+    DBusError error = {0};
+    gchar *ic = NULL;
+
+    if (!dbus_message_get_args (message, &error,
+            DBUS_TYPE_STRING, &ic,
+            DBUS_TYPE_INVALID)) {
+        g_warning ("%s", error.message);
+        dbus_error_free (&error);
+    }
+    else {
+        g_signal_emit (client, client_signals[DISABLED], 0, ic);
+    }
+}
+
+
+static DBusHandlerResult
+_ibus_im_client_message_filter_cb (DBusConnection *connection, DBusMessage *message, void *user_data)
+{
+    IBusIMClient *client = (IBusIMClient *) user_data;
+
+    static struct SIGNAL_HANDLER {
+        const gchar *iface;
+        const gchar *name;
+        void (* handler) (DBusConnection *, DBusMessage *, IBusIMClient *);
+    } handlers[] = {
+#ifdef USE_DBUS_SESSION_BUS
+        { DBUS_INTERFACE_DBUS, "NameOwnerChanged", _ibus_signal_name_owner_changed_handler },
+#endif
+        { DBUS_INTERFACE_LOCAL, "Disconnected", _ibus_signal_disconnected_handler },
+        { IBUS_IFACE, "CommitString", _ibus_signal_commit_string_handler },
+        { IBUS_IFACE, "UpdatePreedit", _ibus_signal_update_preedit_handler },
+        { IBUS_IFACE, "ShowPreedit", _ibus_signal_show_preedit_handler },
+        { IBUS_IFACE, "HidePreedit", _ibus_signal_hide_preedit_handler },
+        { IBUS_IFACE, "Enabled", _ibus_signal_enabled_handler },
+        { IBUS_IFACE, "Disabled", _ibus_signal_disabled_handler },
+        {0},
+    };
+
+    gint i;
+    for (i = 0; handlers[i].iface != NULL; i++) {
+        if (dbus_message_is_signal (message, handlers[i].iface, handlers[i].name)) {
+            handlers[i].handler (connection, message, client);
+            return DBUS_HANDLER_RESULT_HANDLED;
+        }
+    }
+    g_debug ("Unknown message %s", dbus_message_get_member (message));
+    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+inline static gboolean
+_dbus_call_with_reply_and_block_valist (DBusConnection *connection,
+    const gchar *dest, const gchar *path, const gchar* iface, const char *method,
+    int first_arg_type, va_list args)
+{
+
+    DBusMessage *message, *reply;
+    DBusError error = {0};
+    int type;
+    va_list tmp;
+
+    if (connection == NULL)
+        return FALSE;
+
+    message = dbus_message_new_method_call (dest,
+                                    path, iface, method);
+    if (!message) {
+        g_warning ("Out of memory!");
+        return FALSE;
+    }
+
+    va_copy (tmp, args);
+    if (!dbus_message_append_args_valist (message, first_arg_type, tmp)) {
+        dbus_message_unref (message);
+        g_warning ("Can not create call message");
+        return FALSE;
+    }
+
+    reply = dbus_connection_send_with_reply_and_block (connection,
+                        message, -1, &error);
+
+    dbus_message_unref (message);
+
+    if (!reply) {
+        g_warning ("%s", error.message);
+        dbus_error_free (&error);
+        return FALSE;
+    }
+
+    type = first_arg_type;
+    while (type != DBUS_TYPE_INVALID) {
+        if (type == DBUS_TYPE_ARRAY) {
+            va_arg (args, int);
+            va_arg (args, void *);
+            va_arg (args, int);
+        }
+        else {
+            va_arg (args, void *);
+        }
+        type = va_arg (args, int);
+    }
+
+    type = va_arg (args, int);
+    if (!dbus_message_get_args_valist (reply, &error, type, args)) {
+        g_warning ("%s", error.message);
+        dbus_error_free (&error);
+        dbus_message_unref (reply);
+        return FALSE;
+    }
+    dbus_message_unref (reply);
+
+    return TRUE;
+
+}
+
+inline static gboolean
+_dbus_call_with_reply_and_block (DBusConnection *connection,
+    const gchar *dest, const gchar *path, const gchar* iface, const char *method,
+    gint first_arg_type, ...)
+{
+    va_list args;
+    gboolean retval;
+
+    if (connection == NULL)
+        return FALSE;
+
+    va_start (args, first_arg_type);
+    retval = _dbus_call_with_reply_and_block_valist (connection,
+                    dest, path, iface, method, first_arg_type, args);
+    va_end (args);
+
+    return TRUE;
+
+}
+
+static gboolean
+_ibus_call_with_reply_and_block (DBusConnection *connection, const gchar *method, int first_arg_type, ...)
+{
+    va_list args;
+    gboolean retval;
+
+    if (connection == NULL)
+        return FALSE;
+
+    va_start (args, first_arg_type);
+    retval = _dbus_call_with_reply_and_block_valist (connection,
+                    IBUS_NAME, IBUS_PATH, IBUS_IFACE, method, first_arg_type, args);
+    va_end (args);
+
+    return retval;
+
+}
+
+
+inline static gboolean
+_dbus_call_with_reply_valist (DBusConnection *connection,
+    const gchar *dest, const gchar *path, const gchar* iface, const char *method,
+    DBusPendingCallNotifyFunction notify_function,
+    void *user_data, DBusFreeFunction free_function,
+    gint first_arg_type, va_list args)
+{
+    DBusMessage *message = NULL;
+    DBusPendingCall *pendingcall = NULL;
+
+    if (connection == NULL) {
+        goto error;
+    }
+
+    message = dbus_message_new_method_call (dest,
+                                    path, iface, method);
+    if (!message) {
+        g_warning ("Out of memory!");
+        goto error;
+    }
+
+    if (!dbus_message_append_args_valist (message, first_arg_type, args)) {
+        g_warning ("Can not create call message");
+        goto error;
+    }
+
+    if (!dbus_connection_send_with_reply (connection,
+                        message, &pendingcall, -1)) {
+        g_warning ("Out of memory!");
+        goto error;
+    }
+
+    if (!dbus_pending_call_set_notify (pendingcall, notify_function,
+            user_data, free_function)) {
+        g_warning ("Out of memory!");
+        goto error;
+    }
+
+    dbus_message_unref (message);
+    return TRUE;
+
+error:
+    if (message)
+        dbus_message_unref (message);
+    if (pendingcall)
+        dbus_pending_call_cancel (pendingcall);
+    if (user_data && free_function)
+        free_function (user_data);
+    return False;
+}
+
+inline static gboolean
+_dbus_call_with_reply (DBusConnection *connection,
+    const gchar *dest, const gchar *path, const gchar* iface, const char *method,
+    DBusPendingCallNotifyFunction notify_function,
+    void *user_data, DBusFreeFunction free_function,
+    gint first_arg_type, ...)
+{
+    va_list args;
+    gboolean retval;
+
+    if (connection == NULL)
+        return FALSE;
+
+    va_start (args, first_arg_type);
+    retval = _dbus_call_with_reply_valist (connection,
+                    dest, path, iface, method,
+                    notify_function,
+                    user_data, free_function,
+                    first_arg_type, args);
+    va_end (args);
+
+    return TRUE;
+
+}
+
+
+
+static gboolean
+_ibus_call_with_reply (DBusConnection *connection, const gchar *method,
+       DBusPendingCallNotifyFunction notify_function,
+       void *user_data, DBusFreeFunction free_function,
+       int first_arg_type, ...)
+{
+    va_list args;
+    gboolean retval;
+
+    if (connection == NULL)
+        return FALSE;
+
+    va_start (args, first_arg_type);
+    retval = _dbus_call_with_reply_valist (connection,
+                    IBUS_NAME, IBUS_PATH, IBUS_IFACE,
+                    method, notify_function,
+                    user_data, free_function,
+                    first_arg_type, args);
+    va_end (args);
+
+    return retval;
+}
+
+typedef struct {
+    IBusIMClient *client;
+    gchar *ic;
+    GdkEvent event;
+}KeyPressCallData;
+
+static KeyPressCallData *
+_key_press_call_data_new (IBusIMClient *client, const gchar *ic, GdkEvent *event)
+{
+    KeyPressCallData *p = g_new (KeyPressCallData, 1);
+    p->client = g_object_ref (client);
+    p->ic = g_strdup (ic);
+    p->event = *event;
+    return p;
+}
+
+static void
+_key_press_call_data_free (KeyPressCallData *p)
+{
+    if (p) {
+        g_object_unref (p->client);
+        g_free (p->ic);
+    }
+    g_free (p);
+}
+
+static void
+_ibus_filter_keypress_reply_cb (DBusPendingCall *pending, void *user_data)
+{
+    DBusMessage *reply;
+    DBusError error = {0};
+    KeyPressCallData *call_data = (KeyPressCallData *) user_data;
+    gboolean retval;
+
+
+    reply = dbus_pending_call_steal_reply (pending);
+    dbus_pending_call_unref (pending);
+
+    if (dbus_set_error_from_message (&error, reply)) {
+        g_warning ("%s", error.message);
+        dbus_error_free (&error);
+        retval = FALSE;
+    }
+    else {
+        if (!dbus_message_get_args (reply, &error,
+                DBUS_TYPE_BOOLEAN, &retval, DBUS_TYPE_INVALID)) {
+            g_warning ("%s", error.message);
+            dbus_error_free (&error);
+            retval = FALSE;
+        }
+    }
+
+    if (!retval) {
+        g_signal_emit (call_data->client, client_signals[FORWARD_EVENT], 0,
+                call_data->ic, &(call_data->event));
+    }
+}
+
+gboolean
+ibus_im_client_filter_keypress (IBusIMClient *client, const gchar *ic, GdkEventKey *event)
+{
+    g_return_val_if_fail (IBUS_IS_IM_CLIENT(client), FALSE);
+    g_return_val_if_fail (ic != NULL, FALSE);
+    g_return_val_if_fail (event != NULL, FALSE);
+
+    IBusIMClientPrivate *priv = client->priv;
+
+    guint state = event->state & GDK_MODIFIER_MASK;
+    gboolean is_press = event->type == GDK_KEY_PRESS;
+
+    if (event->send_event) {
+        return FALSE;
+    }
+
+    /* Call IBus ProcessKeyEvent method */
+    if (!_ibus_call_with_reply (priv->ibus,
+            "ProcessKeyEvent",
+            _ibus_filter_keypress_reply_cb,
+            _key_press_call_data_new (client, ic, (GdkEvent *)event),
+            (DBusFreeFunction)_key_press_call_data_free,
+            DBUS_TYPE_STRING, &ic,
+            DBUS_TYPE_UINT32, &event->keyval,
+            DBUS_TYPE_BOOLEAN, &is_press,
+            DBUS_TYPE_UINT32, &state,
+            DBUS_TYPE_INVALID))
+        return FALSE;
+
+    return TRUE;
+}
+
+
+void
+ibus_im_client_focus_in (IBusIMClient *client, const gchar *ic)
+{
+    g_return_if_fail (IBUS_IS_IM_CLIENT(client));
+    g_return_if_fail (ic != NULL);
+
+    IBusIMClientPrivate *priv = client->priv;
+
+    /* Call IBus FocusIn method */
+     _ibus_call_with_reply_and_block (priv->ibus,
+            "FocusIn",
+            DBUS_TYPE_STRING, &ic,
+            DBUS_TYPE_INVALID,
+            DBUS_TYPE_INVALID);
+}
+
+void
+ibus_im_client_focus_out (IBusIMClient *client, const gchar *ic)
+{
+    g_return_if_fail (IBUS_IS_IM_CLIENT(client));
+    g_return_if_fail (ic != NULL);
+
+    IBusIMClientPrivate *priv = client->priv;
+
+    /* Call IBus FocusOut method */
+    _ibus_call_with_reply_and_block (priv->ibus,
+            "FocusOut",
+            DBUS_TYPE_STRING, &ic,
+            DBUS_TYPE_INVALID,
+            DBUS_TYPE_INVALID);
+
+}
+
+void
+ibus_im_client_reset (IBusIMClient *client, const gchar *ic)
+{
+    g_return_if_fail (IBUS_IS_IM_CLIENT(client));
+    g_return_if_fail (ic != NULL);
+
+    IBusIMClientPrivate *priv = client->priv;
+
+    /* Call IBus Reset method */
+    _ibus_call_with_reply_and_block (priv->ibus,
+            "Reset",
+            DBUS_TYPE_STRING, &ic,
+            DBUS_TYPE_INVALID,
+            DBUS_TYPE_INVALID);
+
+}
+
+void
+ibus_im_client_set_cursor_location (IBusIMClient *client, const gchar *ic, GdkRectangle *area)
+{
+    g_return_if_fail (IBUS_IS_IM_CLIENT(client));
+    g_return_if_fail (ic != NULL);
+    g_return_if_fail (area != NULL);
+
+    _ibus_call_with_reply_and_block (client->priv->ibus,
+            "SetCursorLocation",
+            DBUS_TYPE_STRING, &ic,
+            DBUS_TYPE_INT32, &area->x,
+            DBUS_TYPE_INT32, &area->y,
+            DBUS_TYPE_INT32, &area->width,
+            DBUS_TYPE_INT32, &area->height,
+            DBUS_TYPE_INVALID,
+            DBUS_TYPE_INVALID);
+}
+
+void
+ibus_im_client_set_use_preedit (IBusIMClient *client, const gchar *ic, gboolean use_preedit)
+{
+    g_return_if_fail (IBUS_IS_IM_CLIENT(client));
+    g_return_if_fail (ic != NULL);
+
+    _ibus_call_with_reply_and_block (client->priv->ibus,
+            "SetCapabilities",
+            DBUS_TYPE_STRING, &ic,
+            DBUS_TYPE_INT32, &use_preedit,
+            DBUS_TYPE_INVALID,
+            DBUS_TYPE_INVALID);
+}
+
+void
+ibus_im_client_release_input_context (IBusIMClient *client, const gchar *ic)
+{
+    g_return_if_fail (IBUS_IS_IM_CLIENT(client));
+    g_return_if_fail (ic != NULL);
+
+    IBusIMClientPrivate *priv = client->priv;
+
+    _ibus_call_with_reply_and_block (priv->ibus, "ReleaseInputContext",
+                DBUS_TYPE_STRING, &ic,
+                DBUS_TYPE_INVALID,
+                DBUS_TYPE_INVALID);
+
+}
+
+void
+ibus_im_client_kill_daemon (IBusIMClient *client)
+{
+    IBusIMClientPrivate *priv = client->priv;
+    _ibus_call_with_reply_and_block (priv->ibus, "Kill",
+                DBUS_TYPE_INVALID,
+                DBUS_TYPE_INVALID);
+}
+
+
+gboolean
+ibus_im_client_get_connected (IBusIMClient *client)
+{
+    IBusIMClientPrivate *priv = client->priv;
+    if (priv->ibus == NULL)
+        return FALSE;
+    return dbus_connection_get_is_connected (priv->ibus);
+}
diff --git a/client/gtk2/ibusimclient.h b/client/gtk2/ibusimclient.h
new file mode 100644 (file)
index 0000000..a0e4f75
--- /dev/null
@@ -0,0 +1,125 @@
+/* vim:set et ts=4: */
+/* IBus - The Input Bus
+ * Copyright (C) 2008-2009 Huang Peng <shawn.p.huang@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#ifndef __IBUS_IM_CLIENT_H_
+#define __IBUS_IM_CLIENT_H_
+
+#include <gtk/gtk.h>
+/*
+ * Type macros.
+ */
+
+/* define GOBJECT macros */
+#define IBUS_TYPE_IM_CLIENT             \
+    (ibus_im_client_get_type ())
+#define IBUS_IM_CLIENT(obj)             \
+    (GTK_CHECK_CAST ((obj), IBUS_TYPE_IM_CLIENT, IBusIMClient))
+#define IBUS_IM_CLIENT_CLASS(klass)     \
+    (GTK_CHECK_CLASS_CAST ((klass), IBUS_TYPE_IM_CLIENT, IBusIMClientClass))
+#define IBUS_IS_IM_CLIENT(obj)          \
+    (GTK_CHECK_TYPE ((obj), IBUS_TYPE_IM_CLIENT))
+#define IBUS_IS_IM_CLIENT_CLASS(klass)  \
+    (GTK_CHECK_CLASS_TYPE ((klass), IBUS_TYPE_IM_CLIENT))
+#define IBUS_IM_CLIENT_GET_CLASS(obj)   \
+    (GTK_CHECK_GET_CLASS ((obj), IBUS_TYPE_IM_CLIENT, IBusIMClientClass))
+
+#if 0
+#define DEBUG_FUNCTION_IN   g_debug("%s IN", __FUNCTION__);
+#define DEBUG_FUNCTION_OUT  g_debug("%s OUT", __FUNCTION__);
+#else
+#define DEBUG_FUNCTION_IN
+#define DEBUG_FUNCTION_OUT
+#endif
+
+
+
+#define IBUS_DBUS_SERVICE    "org.freedesktop.ibus"
+#define IBUS_DBUS_INTERFACE  "org.freedesktop.ibus.Manager"
+#define IBUS_DBUS_PATH       "/org/freedesktop/ibus/Manager"
+
+G_BEGIN_DECLS
+typedef struct _IBusIMClient IBusIMClient;
+typedef struct _IBusIMClientClass IBusIMClientClass;
+typedef struct _IBusIMClientPrivate IBusIMClientPrivate;
+
+struct _IBusIMClient {
+  GtkObject parent;
+  /* instance members */
+  IBusIMClientPrivate *priv;
+};
+
+struct _IBusIMClientClass {
+  GtkObjectClass parent;
+  /* class members */
+  void (* connected)        (IBusIMClient   *client);
+  void (* disconnected)     (IBusIMClient   *client);
+  void (* commit_string)    (IBusIMClient   *client,
+                             const gchar    *ic,
+                             const gchar    *text);
+  void (* update_preedit)   (IBusIMClient   *client,
+                             const gchar    *ic,
+                             const gchar    *text,
+                             gpointer       *attrs,
+                             gint            cursor_pos,
+                             gboolean        visible);
+  void (* show_preedit)     (IBusIMClient   *client,
+                             const gchar    *ic);
+  void (* hide_preedit)     (IBusIMClient   *client,
+                             const gchar    *ic);
+  void (* enabled)          (IBusIMClient   *client,
+                             const gchar    *ic);
+  void (* disabled)         (IBusIMClient   *client,
+                             const gchar    *ic);
+};
+
+extern IBusIMClient                *_client;
+
+GType           ibus_im_client_get_type          (void);
+void            ibus_im_client_register_type     (GTypeModule     *type_module);
+IBusIMClient   *ibus_im_client_new               (void);
+const gchar    *ibus_im_client_create_input_context
+                                                 (IBusIMClient    *client);
+void            ibus_im_client_shutdown          (void);
+void            ibus_im_client_focus_in          (IBusIMClient    *client,
+                                                  const gchar     *ic);
+void            ibus_im_client_focus_out         (IBusIMClient    *client,
+                                                  const gchar     *ic);
+void            ibus_im_client_reset             (IBusIMClient    *client,
+                                                  const gchar     *ic);
+gboolean        ibus_im_client_filter_keypress   (IBusIMClient    *client,
+                                                  const gchar     *ic,
+                                                  GdkEventKey     *key);
+void            ibus_im_client_set_cursor_location
+                                                 (IBusIMClient    *client,
+                                                  const gchar     *ic,
+                                                  GdkRectangle    *area);
+void            ibus_im_client_set_use_preedit   (IBusIMClient    *client,
+                                                  const gchar     *ic,
+                                                  gboolean         use_preedit);
+gboolean        ibus_im_client_is_enabled        (IBusIMClient    *client);
+void            ibus_im_client_release_input_context
+                                                 (IBusIMClient    *client,
+                                                  const gchar     *ic);
+void            ibus_im_client_kill_daemon       (IBusIMClient    *client);
+gboolean        ibus_im_client_get_connected     (IBusIMClient    *client);
+
+
+G_END_DECLS
+#endif
+
diff --git a/client/gtk2/ibusimcontext.c b/client/gtk2/ibusimcontext.c
new file mode 100644 (file)
index 0000000..1a14564
--- /dev/null
@@ -0,0 +1,534 @@
+/* vim:set et ts=4: */
+/* IBus - The Input Bus
+ * Copyright (C) 2008-2009 Huang Peng <shawn.p.huang@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include <gdk/gdkkeysyms.h>
+#include <gdk/gdkx.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <sys/un.h>
+#include "ibusimcontext.h"
+#include "ibusimclient.h"
+
+/* IBusIMContextPriv */
+struct _IBusIMContextPrivate {
+    GtkIMContext *slave;
+    GdkWindow *client_window;
+
+    /* enabled */
+    gboolean        enable;
+    gchar           *ic;
+
+    /* preedit status */
+    gchar           *preedit_string;
+    PangoAttrList   *preedit_attrs;
+    gint             preedit_cursor_pos;
+    gboolean         preedit_visible;
+
+    GdkRectangle     cursor_area;
+    gboolean         has_focus;
+};
+
+
+/* functions prototype */
+static void     ibus_im_context_class_init   (IBusIMContextClass  *klass);
+static void     ibus_im_context_init         (IBusIMContext       *obj);
+static void     ibus_im_context_finalize     (GObject            *obj);
+static void     ibus_im_context_reset        (GtkIMContext       *context);
+static gboolean ibus_im_context_filter_keypress
+                                            (GtkIMContext       *context,
+                                             GdkEventKey        *key);
+static void     ibus_im_context_focus_in     (GtkIMContext       *context);
+static void     ibus_im_context_focus_out    (GtkIMContext       *context);
+static void     ibus_im_context_get_preedit_string
+                                            (GtkIMContext       *context,
+                                             gchar              **str,
+                                             PangoAttrList      **attrs,
+                                             gint               *cursor_pos);
+static void     ibus_im_context_set_client_window
+                                            (GtkIMContext       *context,
+                                             GdkWindow          *client);
+static void     ibus_im_context_set_cursor_location
+                                            (GtkIMContext       *context,
+                                             GdkRectangle       *area);
+static void     ibus_im_context_set_use_preedit
+                                            (GtkIMContext       *context,
+                                             gboolean           use_preedit);
+
+/* callback functions for slave context */
+static void     _slave_commit_cb            (GtkIMContext       *slave,
+                                             gchar              *string,
+                                             IBusIMContext       *context);
+static void     _slave_preedit_changed_cb   (GtkIMContext       *slave,
+                                             IBusIMContext       *context);
+static void     _slave_preedit_start_cb     (GtkIMContext       *slave,
+                                             IBusIMContext       *context);
+static void     _slave_preedit_end_cb       (GtkIMContext       *slave,
+                                             IBusIMContext       *context);
+static void     _slave_retrieve_surrounding_cb
+                                            (GtkIMContext       *slave,
+                                             IBusIMContext       *context);
+static void     _slave_delete_surrounding_cb
+                                            (GtkIMContext       *slave,
+                                             gint               arg1,
+                                             gint               arg2,
+                                             IBusIMContext       *context);
+
+
+
+static GType                _ibus_type_im_context = 0;
+static GtkIMContextClass    *parent_class = NULL;
+
+void
+ibus_im_context_register_type (GTypeModule *type_module)
+{
+    static const GTypeInfo ibus_im_context_info = {
+        sizeof (IBusIMContextClass),
+        (GBaseInitFunc)        NULL,
+        (GBaseFinalizeFunc)     NULL,
+        (GClassInitFunc)     ibus_im_context_class_init,
+        NULL,            /* class finialize */
+        NULL,            /* class data */
+        sizeof (IBusIMContext),
+        0,
+        (GInstanceInitFunc)    ibus_im_context_init,
+    };
+
+    if (! _ibus_type_im_context ) {
+        if (type_module) {
+            _ibus_type_im_context =
+                g_type_module_register_type (type_module,
+                    GTK_TYPE_IM_CONTEXT,
+                    "IBusIMContext",
+                    &ibus_im_context_info,
+                    (GTypeFlags)0);
+        }
+        else {
+            _ibus_type_im_context =
+                g_type_register_static (GTK_TYPE_IM_CONTEXT,
+                    "IBusIMContext",
+                    &ibus_im_context_info,
+                    (GTypeFlags)0);
+        }
+    }
+}
+
+int
+ibus_im_context_get_type (void)
+{
+    if (_ibus_type_im_context == 0) {
+        ibus_im_context_register_type (NULL);
+    }
+
+    g_assert (_ibus_type_im_context != 0);
+    return _ibus_type_im_context;
+}
+
+GtkIMContext *
+ibus_im_context_new (void)
+{
+    IBusIMContext *obj;
+
+    obj = IBUS_IM_CONTEXT(g_object_new (IBUS_TYPE_IM_CONTEXT, NULL));
+
+    return GTK_IM_CONTEXT(obj);
+}
+
+static void
+ibus_im_context_class_init     (IBusIMContextClass *klass)
+{
+    GtkIMContextClass *im_context_class = GTK_IM_CONTEXT_CLASS (klass);
+    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+    parent_class = (GtkIMContextClass *) g_type_class_peek_parent (klass);
+
+    g_type_class_add_private (klass, sizeof (IBusIMContextPrivate));
+
+    im_context_class->reset = ibus_im_context_reset;
+    im_context_class->focus_in = ibus_im_context_focus_in;
+    im_context_class->focus_out = ibus_im_context_focus_out;
+    im_context_class->filter_keypress = ibus_im_context_filter_keypress;
+    im_context_class->get_preedit_string = ibus_im_context_get_preedit_string;
+    im_context_class->set_client_window = ibus_im_context_set_client_window;
+    im_context_class->set_cursor_location = ibus_im_context_set_cursor_location;
+    im_context_class->set_use_preedit = ibus_im_context_set_use_preedit;
+    gobject_class->finalize = ibus_im_context_finalize;
+}
+
+static void
+ibus_im_context_init     (IBusIMContext *obj)
+{
+    DEBUG_FUNCTION_IN;
+
+    IBusIMContext *ibus = IBUS_IM_CONTEXT (obj);
+    IBusIMContextPrivate *priv = ibus->priv =
+        G_TYPE_INSTANCE_GET_PRIVATE (ibus, IBUS_TYPE_IM_CONTEXT, IBusIMContextPrivate);
+
+    priv->client_window = NULL;
+
+    // Init ibus status
+    priv->enable = FALSE;
+
+    // Init preedit status
+    priv->preedit_string = NULL;
+    priv->preedit_attrs = NULL;
+    priv->preedit_cursor_pos = 0;
+    priv->preedit_visible = FALSE;
+
+    // Init cursor area
+    priv->cursor_area.x = 0;
+    priv->cursor_area.y = 0;
+    priv->cursor_area.width = 0;
+    priv->cursor_area.height = 0;
+
+    priv->has_focus = FALSE;
+
+
+    // Create slave im context
+    ibus->priv->slave = gtk_im_context_simple_new ();
+    g_signal_connect (ibus->priv->slave,
+                "commit", G_CALLBACK (_slave_commit_cb), obj);
+    g_signal_connect (ibus->priv->slave,
+                "preedit-start", G_CALLBACK (_slave_preedit_start_cb), obj);
+    g_signal_connect (ibus->priv->slave,
+                "preedit-end", G_CALLBACK (_slave_preedit_end_cb), obj);
+    g_signal_connect (ibus->priv->slave,
+                "preedit-changed", G_CALLBACK (_slave_preedit_changed_cb), obj);
+    g_signal_connect (ibus->priv->slave,
+                "retrieve-surrounding", G_CALLBACK (_slave_retrieve_surrounding_cb), obj);
+    g_signal_connect (ibus->priv->slave,
+                "delete-surrounding", G_CALLBACK (_slave_delete_surrounding_cb), obj);
+}
+
+static void
+ibus_im_context_finalize (GObject *obj)
+{
+    DEBUG_FUNCTION_IN;
+
+    IBusIMContext *ibus = IBUS_IM_CONTEXT (obj);
+    IBusIMContextPrivate *priv = ibus->priv;
+
+    ibus_im_client_release_im_context (_client, ibus);
+
+    g_object_unref (priv->slave);
+
+    if (priv->client_window) g_object_unref (priv->client_window);
+    // release preedit
+    if (priv->preedit_string) g_free (priv->preedit_string);
+    if (priv->preedit_attrs) pango_attr_list_unref (priv->preedit_attrs);
+
+    G_OBJECT_CLASS(parent_class)->finalize (obj);
+}
+
+static gboolean
+ibus_im_context_filter_keypress (GtkIMContext *context,
+                GdkEventKey  *event)
+{
+    DEBUG_FUNCTION_IN;
+
+    IBusIMContext *ibus = IBUS_IM_CONTEXT (context);
+    IBusIMContextPrivate *priv = ibus->priv;
+
+    if (ibus_im_client_filter_keypress (_client, ibus, event))
+        return TRUE;
+    else
+        return gtk_im_context_filter_keypress (priv->slave, event);
+}
+
+static void
+ibus_im_context_focus_in (GtkIMContext *context)
+{
+    DEBUG_FUNCTION_IN;
+
+    IBusIMContext *ibus = IBUS_IM_CONTEXT (context);
+    IBusIMContextPrivate *priv = ibus->priv;
+
+    priv->has_focus = TRUE;
+    ibus_im_client_focus_in (_client, ibus);
+    gtk_im_context_focus_in (priv->slave);
+
+    ibus_im_context_set_cursor_location(context, &priv->cursor_area);
+}
+
+static void
+ibus_im_context_focus_out (GtkIMContext *context)
+{
+    DEBUG_FUNCTION_IN;
+
+    IBusIMContext *ibus = IBUS_IM_CONTEXT (context);
+    IBusIMContextPrivate *priv = ibus->priv;
+
+    priv->has_focus = FALSE;
+    ibus_im_client_focus_out (_client, ibus);
+    gtk_im_context_focus_out (priv->slave);
+}
+
+static void
+ibus_im_context_reset (GtkIMContext *context)
+{
+    DEBUG_FUNCTION_IN;
+
+    IBusIMContext *ibus = IBUS_IM_CONTEXT (context);
+    IBusIMContextPrivate *priv = ibus->priv;
+
+    ibus_im_client_reset (_client, ibus);
+    gtk_im_context_reset (priv->slave);
+}
+
+
+static void
+ibus_im_context_get_preedit_string (GtkIMContext   *context,
+                   gchar         **str,
+                   PangoAttrList **attrs,
+                   gint           *cursor_pos)
+{
+    DEBUG_FUNCTION_IN;
+
+    IBusIMContext *ibus = IBUS_IM_CONTEXT (context);
+    IBusIMContextPrivate *priv = ibus->priv;
+
+    if (priv->enable) {
+        if (priv->preedit_visible) {
+            if (str) {
+                *str = g_strdup (priv->preedit_string ? priv->preedit_string: "");
+            }
+
+            if (attrs) {
+                *attrs = priv->preedit_attrs ?
+                            pango_attr_list_ref (priv->preedit_attrs):
+                            pango_attr_list_new ();
+            }
+
+            if (cursor_pos) {
+                *cursor_pos = priv->preedit_cursor_pos;
+            }
+        }
+        else {
+            if (str) *str = g_strdup ("");
+            if (attrs) *attrs = pango_attr_list_new ();
+            if (cursor_pos) *cursor_pos = 0;
+        }
+    }
+    else {
+        gtk_im_context_get_preedit_string (priv->slave, str, attrs, cursor_pos);
+    }
+}
+
+
+static void
+ibus_im_context_set_client_window  (GtkIMContext *context, GdkWindow *client)
+{
+    DEBUG_FUNCTION_IN;
+
+    IBusIMContext *ibus = IBUS_IM_CONTEXT (context);
+    IBusIMContextPrivate *priv = ibus->priv;
+
+    if (priv->client_window)
+        g_object_unref (priv->client_window);
+    if (client)
+        g_object_ref (client);
+    priv->client_window = client;
+    gtk_im_context_set_client_window (priv->slave, client);
+}
+
+static void
+ibus_im_context_set_cursor_location (GtkIMContext *context, GdkRectangle *area)
+{
+    DEBUG_FUNCTION_IN;
+
+    IBusIMContext *ibus = IBUS_IM_CONTEXT (context);
+    IBusIMContextPrivate *priv = ibus->priv;
+    gint x, y;
+
+    priv->cursor_area = *area;
+
+    if(priv->client_window) {
+        gdk_window_get_origin (priv->client_window, &x, &y);
+        area->x += x;
+        area->y += y;
+    }
+    ibus_im_client_set_cursor_location (_client, ibus, area);
+    gtk_im_context_set_cursor_location (priv->slave, area);
+}
+
+static void
+ibus_im_context_set_use_preedit (GtkIMContext *context, gboolean use_preedit)
+{
+    DEBUG_FUNCTION_IN;
+
+    IBusIMContext *ibus = IBUS_IM_CONTEXT (context);
+    IBusIMContextPrivate *priv = ibus->priv;
+
+    ibus_im_client_set_use_preedit (_client, ibus, use_preedit);
+    gtk_im_context_set_use_preedit (priv->slave, use_preedit);
+}
+
+
+/* Callback functions for slave context */
+static void
+_slave_commit_cb (GtkIMContext *slave, gchar *string, IBusIMContext *context)
+{
+    DEBUG_FUNCTION_IN;
+
+    /* IBusIMContextPrivate *priv = context->priv; */
+#if 0
+    if ((GtkIMContext *)context == CURRENT_CONTEXT && ibus_im_client_is_enabled (_client))
+        return;
+#endif
+    g_signal_emit_by_name (context, "commit", string);
+}
+
+static void
+_slave_preedit_changed_cb (GtkIMContext *slave, IBusIMContext *context)
+{
+    DEBUG_FUNCTION_IN;
+    IBusIMContextPrivate *priv = context->priv;
+
+    if (priv->enable && priv->ic)
+        return;
+
+    g_signal_emit_by_name (context, "preedit-changed");
+}
+
+static void
+_slave_preedit_start_cb (GtkIMContext *slave, IBusIMContext *context)
+{
+    DEBUG_FUNCTION_IN;
+    IBusIMContextPrivate *priv = context->priv;
+
+    if (priv->enable && priv->ic)
+        return;
+    g_signal_emit_by_name (context, "preedit-start");
+}
+
+static void
+_slave_preedit_end_cb (GtkIMContext *slave, IBusIMContext *context)
+{
+    DEBUG_FUNCTION_IN;
+    IBusIMContextPrivate *priv = context->priv;
+
+    if (priv->enable && priv->ic)
+        return;
+    g_signal_emit_by_name (context, "preedit-end");
+}
+
+static void
+_slave_retrieve_surrounding_cb (GtkIMContext *slave, IBusIMContext *context)
+{
+    DEBUG_FUNCTION_IN;
+    IBusIMContextPrivate *priv = context->priv;
+
+    if (priv->enable && priv->ic)
+        return;
+    g_signal_emit_by_name (context, "retrieve-surrounding");
+}
+
+static void
+_slave_delete_surrounding_cb (GtkIMContext *slave, gint a1, gint a2, IBusIMContext *context)
+{
+    DEBUG_FUNCTION_IN;
+    IBusIMContextPrivate *priv = context->priv;
+
+    if (priv->enable && priv->ic)
+        return;
+    g_signal_emit_by_name (context, "delete-surrounding", a1, a2);
+}
+
+gchar *
+ibus_im_context_get_ic (IBusIMContext *context)
+{
+    IBusIMContextPrivate *priv = context->priv;
+    return priv->ic;
+}
+
+void
+ibus_im_context_set_ic (IBusIMContext *context, const gchar *ic)
+{
+    IBusIMContextPrivate *priv = context->priv;
+    g_free (priv->ic);
+
+    priv->ic = g_strdup (ic);
+
+    if (priv->ic == NULL) {
+        priv->enable = FALSE;
+    }
+    else if (priv->has_focus) {
+        ibus_im_context_focus_in (GTK_IM_CONTEXT (context));
+    }
+}
+
+void
+ibus_im_context_enable (IBusIMContext *context)
+{
+    IBusIMContextPrivate *priv = context->priv;
+    priv->enable = TRUE;
+}
+
+void
+ibus_im_context_disable (IBusIMContext *context)
+{
+    IBusIMContextPrivate *priv = context->priv;
+    priv->enable = FALSE;
+}
+
+
+void
+ibus_im_context_commit_string (IBusIMContext  *context, const gchar *string)
+{
+    g_signal_emit_by_name (context, "commit", string);
+}
+
+void
+ibus_im_context_update_preedit (IBusIMContext *context, const gchar *string,
+        PangoAttrList *attrs, gint cursor_pos, gboolean visible)
+{
+    IBusIMContextPrivate *priv = context->priv;
+
+    priv->preedit_string = g_strdup (string);
+    priv->preedit_attrs = pango_attr_list_ref (attrs);
+    priv->preedit_cursor_pos = cursor_pos;
+    priv->preedit_visible = visible;
+
+    g_signal_emit_by_name (context, "preedit-changed");
+}
+
+void
+ibus_im_context_show_preedit (IBusIMContext *context)
+{
+    IBusIMContextPrivate *priv = context->priv;
+    if (priv->preedit_visible)
+        return;
+
+    priv->preedit_visible = TRUE;
+
+    g_signal_emit_by_name (context, "preedit-changed");
+}
+
+void
+ibus_im_context_hide_preedit (IBusIMContext *context)
+{
+    IBusIMContextPrivate *priv = context->priv;
+
+    if (!priv->preedit_visible)
+        return;
+
+    priv->preedit_visible = FALSE;
+
+    g_signal_emit_by_name (context, "preedit-changed");
+}
diff --git a/client/gtk2/ibusimcontext.h b/client/gtk2/ibusimcontext.h
new file mode 100644 (file)
index 0000000..934a022
--- /dev/null
@@ -0,0 +1,84 @@
+/* vim:set et ts=4: */
+/* IBus - The Input Bus
+ * Copyright (C) 2008-2009 Huang Peng <shawn.p.huang@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#ifndef __IBUS_IM_CONTEXT_H_
+#define __IBUS_IM_CONTEXT_H_
+
+#include <gtk/gtk.h>
+
+/*
+ * Type macros.
+ */
+#define IBUS_TYPE_IM_CONTEXT             \
+    (ibus_im_context_get_type ())
+#define IBUS_IM_CONTEXT(obj)             \
+    (GTK_CHECK_CAST ((obj), IBUS_TYPE_IM_CONTEXT, IBusIMContext))
+#define IBUS_IM_CONTEXT_CLASS(klass)     \
+    (GTK_CHECK_CLASS_CAST ((klass), IBUS_TYPE_IM_CONTEXT, IBusIMContextClass))
+#define IBUS_IS_IM_CONTEXT(obj)          \
+    (GTK_CHECK_TYPE ((obj), IBUS_TYPE_IM_CONTEXT))
+#define IBUS_IS_IM_CONTEXT_CLASS(klass)  \
+    (GTK_CHECK_CLASS_TYPE ((klass), IBUS_TYPE_IM_CONTEXT))
+#define IBUS_IM_CONTEXT_GET_CLASS(obj)   \
+    (GTK_CHECK_GET_CLASS ((obj), IBUS_TYPE_IM_CONTEXT, IBusIMContextClass))
+
+G_BEGIN_DECLS
+typedef struct _IBusIMContext IBusIMContext;
+typedef struct _IBusIMContextClass IBusIMContextClass;
+typedef struct _IBusIMContextPrivate IBusIMContextPrivate;
+
+struct _IBusIMContext {
+  GtkIMContext parent;
+  /* instance members */
+  IBusIMContextPrivate *priv;
+};
+
+struct _IBusIMContextClass {
+  GtkIMContextClass parent;
+  /* class members */
+};
+
+int     ibus_im_context_get_type(void);
+GtkIMContext
+        *ibus_im_context_new    (void);
+void    ibus_im_context_register_type
+                                (GTypeModule    *type_module);
+void    ibus_im_context_shutdown
+                                (void);
+gchar   *ibus_im_context_get_ic (IBusIMContext  *context);
+void    ibus_im_context_set_ic  (IBusIMContext  *context,
+                                 const gchar    *ic);
+void    ibus_im_context_enable  (IBusIMContext  *context);
+void    ibus_im_context_disable (IBusIMContext  *context);
+void    ibus_im_context_commit_string
+                                (IBusIMContext  *context,
+                                const gchar     *string);
+void    ibus_im_context_update_preedit
+                                (IBusIMContext  *context,
+                                const gchar     *string,
+                                PangoAttrList   *attrs,
+                                gint            cursor_pos,
+                                gboolean        visible);
+void    ibus_im_context_show_preedit
+                                (IBusIMContext  *context);
+void    ibus_im_context_hide_preedit
+                                (IBusIMContext  *context);
+G_END_DECLS
+#endif
+
diff --git a/client/gtk2/ibusmarshalers.list b/client/gtk2/ibusmarshalers.list
new file mode 100644 (file)
index 0000000..89c4f76
--- /dev/null
@@ -0,0 +1,5 @@
+NONE:NONE
+NONE:STRING
+NONE:STRING,STRING
+NONE:STRING,POINTER
+NONE:STRING,STRING,POINTER,INT,BOOL
diff --git a/client/qt4/.gitignore b/client/qt4/.gitignore
new file mode 100644 (file)
index 0000000..52bae9b
--- /dev/null
@@ -0,0 +1 @@
+moc*.cpp
diff --git a/client/qt4/Makefile.am b/client/qt4/Makefile.am
new file mode 100644 (file)
index 0000000..012a6b0
--- /dev/null
@@ -0,0 +1,55 @@
+# vim:set noet ts=4:
+#
+# ibus - The Input Bus
+#
+# Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this program; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+# Boston, MA  02111-1307  USA
+
+EXTRA_DIST = \
+       ibus-client.cpp \
+       ibus-client.h \
+       ibus-input-context.cpp \
+       ibus-input-context.h \
+       ibus.pro \
+       im-ibus-qt.cpp \
+       $(NULL)
+
+if IBUS_BUILD_QT4
+Makefile.qmake: ibus.pro
+       $(QMAKE) -makefile -o Makefile.qmake $(srcdir)/ibus.pro
+
+all-local: Makefile.qmake
+       $(MAKE) -f Makefile.qmake $(AM_MAKEFLAGS) all 
+
+check-local: Makefile.qmake
+
+clean-local: Makefile.qmake
+       $(MAKE) -f Makefile.qmake $(AM_MAKEFLAGS) clean
+
+distclean-local: Makefile.qmake
+       $(MAKE) -f Makefile.qmake $(AM_MAKEFLAGS) distclean
+
+install-exec-local: Makefile.qmake
+       $(MAKE) -f Makefile.qmake $(AM_MAKEFLAGS) INSTALL_ROOT=$(DESTDIR) install
+
+uninstall-local: Makefile.qmake
+       $(MAKE) -f Makefile.qmake $(AM_MAKEFLAGS) INSTALL_ROOT=$(DESTDIR) uninstall
+
+test: all
+       QT_IM_MODULE=ibus kwrite
+endif
+
diff --git a/client/qt4/ibus-client.cpp b/client/qt4/ibus-client.cpp
new file mode 100644 (file)
index 0000000..cb37b1b
--- /dev/null
@@ -0,0 +1,548 @@
+/* vim:set noet ts=4: */
+/*
+ * ibus - The Input Bus
+ *
+ * Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA  02111-1307  USA
+ */
+#include <QtDebug>
+#include <QFile>
+#include <QDBusConnection>
+#include <QCoreApplication>
+#include <QDBusMessage>
+#include <QDBusArgument>
+
+#include "ibus-client.h"
+#include "ibus-input-context.h"
+
+#ifdef Q_WS_X11
+# include <QX11Info>
+# include <X11/Xlib.h>
+# include <X11/keysym.h>
+# include <X11/Xutil.h>
+#endif
+
+#define IBUS_NAME      "org.freedesktop.IBus"
+#define IBUS_PATH      "/org/freedesktop/IBus"
+#define IBUS_INTERFACE "org.freedesktop.IBus"
+
+
+IBusClient::IBusClient ()
+       : ibus (NULL), focused_context (NULL)
+{
+       username = getlogin ();
+       if (username.isNull ())
+               username = getenv ("LOGNAME");
+       if (username.isNull ())
+               username = getenv ("USER");
+       if (username.isNull ())
+               username = getenv ("LNAME");
+       if (username.isNull ())
+               username = getenv ("USERNAME");
+
+       session = getenv ("DISPLAY");
+       session.replace (":", "-");
+
+       ibus_addr = QString("unix:path=/tmp/ibus-%1/ibus-%2").arg (username, session);
+       connectToBus ();
+
+       QObject::connect (
+               &watcher,
+               SIGNAL(directoryChanged(const QString &)),
+               this,
+               SLOT(slotDirectoryChanged(const QString &)));
+
+       QString ibus_dir;
+
+       ibus_dir = QString ("/tmp/ibus-%1/").arg (username);
+       watcher.addPath (ibus_dir);
+}
+
+IBusClient::~IBusClient ()
+{
+       if (ibus)
+               delete ibus;
+}
+
+QString
+IBusClient::createInputContextRemote ()
+{
+       QString ic;
+       if (ibus) {
+               QDBusMessage message = QDBusMessage::createMethodCall (
+                                                               IBUS_NAME,
+                                                               IBUS_PATH,
+                                                               IBUS_INTERFACE,
+                                                               "CreateInputContext");
+               message << QCoreApplication::applicationName ();
+               message = ibus->call (message);
+
+               if (message.type () == QDBusMessage::ErrorMessage) {
+                       qWarning() << message.errorMessage ();
+               }
+               else if (message.type () == QDBusMessage::ReplyMessage) {
+                       ic = message.arguments () [0].toString ();
+               }
+       }
+       return ic;
+}
+
+QInputContext *
+IBusClient::createInputContext ()
+{
+       IBusInputContext *ctx;
+       QString ic;
+
+       ic = createInputContextRemote ();
+
+       ctx = new IBusInputContext (0, this, ic);
+       context_list.append (ctx);
+
+       if (! ic.isEmpty ()) {
+               context_dict[ic] = ctx;
+       }
+
+       return (QInputContext *) ctx;
+}
+
+void
+IBusClient::releaseInputContext (IBusInputContext *ctx)
+{
+       Q_ASSERT (ctx);
+
+       QString ic = ctx->getIC ();
+
+       if (ibus && !ic.isEmpty ()) {
+               QDBusMessage message = QDBusMessage::createMethodCall (
+                                                               IBUS_NAME,
+                                                               IBUS_PATH,
+                                                               IBUS_INTERFACE,
+                                                               "ReleaseInputContext");
+               message << ctx->getIC ();
+               message = ibus->call (message);
+
+               if (message.type () == QDBusMessage::ErrorMessage) {
+                       qWarning() << message.errorMessage ();
+               }
+               context_dict.remove (ic);
+       }
+       context_list.removeAll (ctx);
+}
+
+#ifndef Q_WS_X11
+static void
+translate_key_event (const QKeyEvent *event, quint32 *keyval, bool *is_press, quint32 *state)
+{
+       Q_ASSERT (event);
+       Q_ASSERT (keyval);
+       Q_ASSERT (is_press);
+       Q_ASSERT (state);
+
+       *keyval = event->key ();
+       *is_press = (event->type() == QEvent::KeyPress);
+
+       Qt::KeyboardModifiers modifiers = event->modifiers ();
+       *state = 0;
+       if (modifiers & Qt::ShiftModifier) {
+               *state |= (1<< 0);
+       }
+       if (modifiers & Qt::ControlModifier) {
+               *state |= (1<< 2);
+       }
+       if (modifiers & Qt::AltModifier) {
+               *state |= (1<< 3);
+       }
+       if (modifiers & Qt::MetaModifier) {
+               *state |= (1<< 28);
+       }
+       if (modifiers & Qt::KeypadModifier) {
+               // *state |= (1<< 28);
+       }
+       if (modifiers & Qt::GroupSwitchModifier) {
+               // *state |= (1<< 28);
+       }
+}
+
+bool
+IBusClient::filterEvent (IBusInputContext *ctx, QEvent *event)
+{
+       return true;
+}
+#endif
+
+#ifdef Q_WS_X11
+static inline bool
+translate_x_key_event (XEvent *xevent, quint32 *keyval, bool *is_press, quint32 *state)
+{
+       Q_ASSERT (xevent);
+       Q_ASSERT (keyval);
+       Q_ASSERT (state);
+       Q_ASSERT (is_press);
+
+       if (xevent->type != KeyPress && xevent->type != KeyRelease)
+               return false;
+
+       *is_press = (xevent->type == KeyPress);
+       *state = xevent->xkey.state;
+
+       char key_str[64];
+
+       if (XLookupString (&xevent->xkey, key_str, sizeof (key_str), (KeySym *)keyval, 0) <= 0) {
+               *keyval = (quint32) XLookupKeysym (&xevent->xkey, 0);
+       }
+
+       return true;
+
+}
+
+bool
+IBusClient::x11FilterEvent (IBusInputContext *ctx, QWidget * /* keywidget */, XEvent *xevent)
+{
+       Q_ASSERT (ctx);
+       Q_ASSERT (keywidget);
+       Q_ASSERT (xevent);
+
+       quint32 keyval;
+       quint32 state;
+       bool is_press;
+
+       if (focused_context != ctx) {
+               focusIn (ctx);
+       }
+
+       if (ibus == NULL || !ibus->isConnected () || ctx->getIC().isEmpty ())
+               return false;
+
+       if (!translate_x_key_event (xevent, &keyval, &is_press, &state))
+               return false;
+       QDBusMessage message = QDBusMessage::createMethodCall (
+                                                       IBUS_NAME,
+                                                       IBUS_PATH,
+                                                       IBUS_INTERFACE,
+                                                       "ProcessKeyEvent");
+       message << ctx->getIC ();
+       message << keyval;
+       message << is_press;
+       message << state;
+
+       message = ibus->call (message);
+
+       if (message.type() == QDBusMessage::ErrorMessage) {
+               qWarning() << message.errorMessage ();
+               return false;
+       }
+       else
+               return message.arguments ()[0].toBool ();
+}
+#endif
+
+void
+IBusClient::mouseHandler (IBusInputContext * /*ctx */, int /* x */, QMouseEvent * /* event */)
+{
+       return;
+}
+
+void
+IBusClient::setCursorLocation (IBusInputContext *ctx, QRect &rect)
+{
+       Q_ASSERT (ctx);
+
+       if (focused_context != ctx) {
+               focusIn (ctx);
+       }
+
+       if (ibus == NULL || !ibus->isConnected () || ctx->getIC().isEmpty ())
+               return;
+
+       QDBusMessage message = QDBusMessage::createMethodCall (
+                                                       IBUS_NAME,
+                                                       IBUS_PATH,
+                                                       IBUS_INTERFACE,
+                                                       "SetCursorLocation");
+       message << ctx->getIC ();
+       message << rect.x ();
+       message << rect.y ();
+       message << rect.width ();
+       message << rect.height ();
+       message = ibus->call (message);
+       if (message.type() == QDBusMessage::ErrorMessage) {
+               qWarning() << message.errorMessage ();
+       }
+}
+
+void
+IBusClient::reset (IBusInputContext *ctx)
+{
+       Q_ASSERT (ctx);
+
+       if (ibus == NULL || !ibus->isConnected () || ctx->getIC().isEmpty ())
+               return;
+       QDBusMessage message = QDBusMessage::createMethodCall (
+                                                       IBUS_NAME,
+                                                       IBUS_PATH,
+                                                       IBUS_INTERFACE,
+                                                       "Reset");
+       message << ctx->getIC ();
+       message = ibus->call (message);
+       if (message.type() == QDBusMessage::ErrorMessage) {
+               qWarning() << message.errorMessage ();
+       }
+}
+
+void
+IBusClient::focusIn (IBusInputContext *ctx)
+{
+       Q_ASSERT (ctx);
+       if (focused_context != ctx && focused_context != NULL)
+               focusOut (focused_context);
+       focused_context = ctx;
+
+       if (ibus == NULL || !ibus->isConnected () || ctx->getIC().isEmpty ())
+               return;
+       QDBusMessage message = QDBusMessage::createMethodCall (
+                                                       IBUS_NAME,
+                                                       IBUS_PATH,
+                                                       IBUS_INTERFACE,
+                                                       "FocusIn");
+       message << ctx->getIC ();
+       message = ibus->call (message);
+       if (message.type() == QDBusMessage::ErrorMessage) {
+               qWarning() << message.errorMessage ();
+       }
+
+}
+
+void
+IBusClient::focusOut (IBusInputContext *ctx)
+{
+       Q_ASSERT (ctx);
+
+       if (focused_context != ctx)
+               return;
+
+       focused_context = NULL;
+
+       if (ibus == NULL || !ibus->isConnected () || ctx->getIC().isEmpty ())
+               return;
+
+       QDBusMessage message = QDBusMessage::createMethodCall (
+                                                       IBUS_NAME,
+                                                       IBUS_PATH,
+                                                       IBUS_INTERFACE,
+                                                       "FocusOut");
+       message << ctx->getIC ();
+       message = ibus->call (message);
+       if (message.type() == QDBusMessage::ErrorMessage) {
+               qWarning() << message.errorMessage ();
+       }
+}
+void
+IBusClient::widgetDestroyed (IBusInputContext * /* ctx */, QWidget * /* widget */)
+{
+}
+
+bool
+IBusClient::connectToBus ()
+{
+       QDBusConnection *connection = NULL;
+
+       if (ibus != NULL)
+               return false;
+
+       connection = new QDBusConnection (
+               QDBusConnection::connectToBus (
+                       ibus_addr,
+                       QString ("ibus")));
+
+       if (!connection->isConnected ()) {
+               delete connection;
+               QDBusConnection::disconnectFromBus ("ibus");
+               return false;
+       }
+
+       if (!connection->connect ("",
+                       "",
+                       "org.freedesktop.DBus.Local",
+                       "Disconnected",
+                       this, SLOT (slotIBusDisconnected()))) {
+               qWarning () << "Can not connect Disconnected signal";
+               delete connection;
+               QDBusConnection::disconnectFromBus ("ibus");
+               return false;
+       }
+
+       if (!connection->connect ("",
+                       IBUS_PATH,
+                       IBUS_INTERFACE,
+                       "CommitString",
+                       this, SLOT (slotCommitString(QString, QString)))) {
+               qWarning () << "Can not connect CommitString signal";
+               delete connection;
+               QDBusConnection::disconnectFromBus ("ibus");
+               return false;
+       }
+
+       if (!connection->connect ("",
+                       IBUS_PATH,
+                       IBUS_INTERFACE,
+                       "UpdatePreedit",
+                       this, SLOT (slotUpdatePreedit(QDBusMessage)))) {
+               qWarning () << "Can not connect UpdatePreedit signal";
+               delete connection;
+               QDBusConnection::disconnectFromBus ("ibus");
+               return false;
+       }
+
+       if (!connection->connect ("",
+                       IBUS_PATH,
+                       IBUS_INTERFACE,
+                       "ShowPreedit",
+                       this, SLOT (slotShowPreedit(QDBusMessage)))) {
+               qWarning () << "Can not connect ShowPreedit signal";
+               delete connection;
+               QDBusConnection::disconnectFromBus ("ibus");
+               return false;
+       }
+
+       if (!connection->connect ("",
+                       IBUS_PATH,
+                       IBUS_INTERFACE,
+                       "HidePreedit",
+                       this, SLOT (slotHidePreedit(QDBusMessage)))) {
+               qWarning () << "Can not connect ShowPreedit signal";
+               delete connection;
+               QDBusConnection::disconnectFromBus ("ibus");
+               return false;
+       }
+
+       ibus = connection;
+
+       QList <IBusInputContext *>::iterator i;
+       for (i = context_list.begin (); i != context_list.end (); ++i ) {
+               QString ic = createInputContextRemote ();
+               (*i)->setIC (ic);
+               context_dict[ic] = *i;
+       }
+
+       return true;
+}
+
+void
+IBusClient::disconnectFromBus ()
+{
+       if (ibus) {
+               delete ibus;
+               ibus = NULL;
+               QDBusConnection::disconnectFromBus ("ibus");
+               QList <IBusInputContext *>::iterator i;
+               for (i = context_list.begin (); i != context_list.end (); ++i ) {
+                       (*i)->setIC ("");
+               }
+               context_dict.clear ();
+       }
+}
+
+void
+IBusClient::slotDirectoryChanged (const QString & /*path*/)
+{
+       if (ibus && !ibus->isConnected ())
+               disconnectFromBus ();
+
+       if (ibus == NULL ) {
+               if (QFile::exists (ibus_addr)) {
+                       usleep (500);
+                       connectToBus ();
+               }
+       }
+}
+
+void
+IBusClient::slotIBusDisconnected ()
+{
+       disconnectFromBus ();
+}
+
+
+void
+IBusClient::slotCommitString (QString ic, QString text)
+{
+       IBusInputContext *ctx = context_dict[ic];
+       ctx->commitString (text);
+}
+
+void
+IBusClient::slotUpdatePreedit (QDBusMessage message)
+{
+       QString ic;
+       QString text;
+       QVariant attrs;
+       int cursor_pos;
+       bool visible;
+
+       QList<QVariant> args = message.arguments ();
+
+       ic = args[0].toString ();
+       text = args[1].toString ();
+       attrs = args[2];
+       cursor_pos = args[3].toInt ();
+       visible = args[4].toBool ();
+       QList <QList <quint32> > attr_list;
+       const QDBusArgument arg = attrs.value <QDBusArgument> ();
+       arg.beginArray ();
+       while ( !arg.atEnd ()) {
+               quint32 type, value, start_index, end_index;
+
+               arg.beginArray ();
+               arg >> type >> value >> start_index >> end_index;
+               arg.endArray ();
+               QList <quint32> attr;
+               attr.append (type);
+               attr.append (value);
+               attr.append (start_index);
+               attr.append (end_index);
+               attr_list.append (attr);
+       }
+       arg.endArray ();
+
+       IBusInputContext *ctx = context_dict[ic];
+       ctx->updatePreedit (text, attr_list, cursor_pos, visible);
+}
+
+void
+IBusClient::slotShowPreedit (QDBusMessage message)
+{
+       QString ic;
+
+       QList<QVariant> args = message.arguments ();
+
+       ic = args[0].toString ();
+       IBusInputContext *ctx = context_dict[ic];
+       ctx->showPreedit ();
+}
+
+void
+IBusClient::slotHidePreedit (QDBusMessage message)
+{
+       QString ic;
+
+       QList<QVariant> args = message.arguments ();
+
+       ic = args[0].toString ();
+       IBusInputContext *ctx = context_dict[ic];
+       ctx->hidePreedit ();
+}
+
diff --git a/client/qt4/ibus-client.h b/client/qt4/ibus-client.h
new file mode 100644 (file)
index 0000000..285d633
--- /dev/null
@@ -0,0 +1,87 @@
+/* vim:set noet ts=4: */
+/*
+ * ibus - The Input Bus
+ *
+ * Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA  02111-1307  USA
+ */
+#ifndef __IBUS_CLIENT_H_
+#define __IBUS_CLIENT_H_
+#include <QObject>
+#include <QList>
+#include <QHash>
+#include <QInputContext>
+#include <QFileSystemWatcher>
+#include <QDBusMessage>
+
+class QDBusConnection;
+class IBusInputContext;
+
+class IBusClient : public QObject {
+       Q_OBJECT
+public:
+       IBusClient ();
+       ~IBusClient ();
+
+public:
+
+#ifndef Q_WS_X11
+    bool filterEvent (IBusInputContext *ctx, const QEvent *event);
+#endif
+
+       bool isComposing (IBusInputContext const *ctx);
+       void mouseHandler (IBusInputContext *ctx, int x, QMouseEvent *event);
+       void widgetDestroyed (IBusInputContext *ctx, QWidget *widget);
+
+#ifdef Q_WS_X11
+       bool x11FilterEvent (IBusInputContext *ctx, QWidget *keywidget, XEvent *xevent);
+#endif
+
+public:
+       QInputContext *createInputContext ();
+       void releaseInputContext (IBusInputContext *ctx);
+       void setCursorLocation (IBusInputContext *ctx, QRect &rect);
+       void focusIn (IBusInputContext *ctx);
+       void focusOut (IBusInputContext *ctx);
+       void reset (IBusInputContext *ctx);
+
+private slots:
+       void slotDirectoryChanged (const QString &path);
+       void slotFileChanged (const QString &path);
+       void slotIBusDisconnected ();
+       void slotCommitString (QString ic, QString text);
+       //void slotUpdatePreedit (QString ic, QString text, QVariant attrs, int cursor_pos, bool show);
+       void slotUpdatePreedit (QDBusMessage message);
+       void slotShowPreedit (QDBusMessage message);
+       void slotHidePreedit (QDBusMessage message);
+
+private:
+       bool connectToBus ();
+       void disconnectFromBus ();
+       QString createInputContextRemote ();
+
+       QDBusConnection *ibus;
+       QFileSystemWatcher watcher;
+       QList <IBusInputContext *> context_list;
+       QHash <QString, IBusInputContext *>context_dict;
+       IBusInputContext *focused_context;
+       QString username;
+       QString session;
+       QString ibus_addr;
+};
+
+#endif // __IBUS_CLIENT_H_
diff --git a/client/qt4/ibus-input-context.cpp b/client/qt4/ibus-input-context.cpp
new file mode 100644 (file)
index 0000000..692fecb
--- /dev/null
@@ -0,0 +1,243 @@
+/* vim:set noet ts=4: */
+/*
+ * ibus - The Input Bus
+ *
+ * Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA  02111-1307  USA
+ */
+#include "ibus-input-context.h"
+#include "ibus-client.h"
+#include <QtDebug>
+#include <QInputMethodEvent>
+#include <QTextCharFormat>
+
+typedef QInputMethodEvent::Attribute QAttribute;
+
+IBusInputContext::IBusInputContext (QObject *parent, IBusClient *client, QString &ic)
+       : QInputContext (parent), client (client), ic (ic), preedit_visible (false)
+{
+}
+
+IBusInputContext::~IBusInputContext ()
+{
+       client->releaseInputContext (this);
+}
+
+bool
+IBusInputContext::filterEvent (const QEvent *event)
+{
+#ifndef Q_WS_X11
+       if (client->filterEvent (this, event))
+               return true;
+       return QInputContext::filterEvent (event);
+#else
+       return QInputContext::filterEvent (event);
+#endif
+}
+
+QFont
+IBusInputContext::font () const
+{
+       return QInputContext::font ();
+}
+
+QString
+IBusInputContext::identifierName ()
+{
+       return QString ("ibus");
+}
+
+QString
+IBusInputContext::language()
+{
+       return QString ("");
+}
+
+void
+IBusInputContext::mouseHandler (int x, QMouseEvent *event)
+{
+       client->mouseHandler (this, x, event);
+       QInputContext::mouseHandler (x, event);
+}
+
+void
+IBusInputContext::reset()
+{
+       client->reset (this);
+}
+
+void
+IBusInputContext::update ()
+{
+       QWidget *widget;
+
+       if ((widget = focusWidget ()) == NULL)
+               return;
+
+       QRect rect = widget->inputMethodQuery(Qt::ImMicroFocus).toRect ();
+
+#if 0
+       QFont font = widget->inputMethodQuery(Qt::ImFont).value <QFont> ();
+       qDebug () << rect << preedit_string << preedit_cursor_pos;
+
+       QFontMetrics fm(font);
+       int textWidth = fm.width (preedit_string.left (preedit_cursor_pos));
+       rect.translate (textWidth, 0);
+#endif
+
+       QPoint topleft = widget->mapToGlobal(QPoint(0,0));
+       rect.translate (topleft);
+       if (cursor_location != rect ) {
+               client->setCursorLocation (this, rect);
+               cursor_location = rect;
+       }
+
+#if 0
+       QVariant value;
+       value = widget->inputMethodQuery(Qt::ImMicroFocus);
+       qDebug () << value;
+       value = widget->inputMethodQuery(Qt::ImFont);
+       qDebug () << value;
+       value = widget->inputMethodQuery(Qt::ImCursorPosition);
+       qDebug () << value;
+       value = widget->inputMethodQuery(Qt::ImSurroundingText);
+       qDebug () << value;
+       value = widget->inputMethodQuery(Qt::ImCurrentSelection);
+       qDebug () << value;
+#endif
+}
+
+bool
+IBusInputContext::isComposing() const
+{
+       return (!preedit_string.isEmpty ()) && preedit_visible;
+}
+
+void
+IBusInputContext::setFocusWidget (QWidget *widget)
+{
+       // qDebug () << "setFocusWidget (" << widget << ")";
+       QInputContext::setFocusWidget (widget);
+       update ();
+}
+
+void
+IBusInputContext::widgetDestroyed (QWidget *widget)
+{
+       QInputContext::widgetDestroyed (widget);
+       update ();
+}
+
+#ifdef Q_WS_X11
+bool
+IBusInputContext::x11FilterEvent (QWidget *keywidget, XEvent *xevent)
+{
+       if (client->x11FilterEvent (this, keywidget, xevent))
+               return true;
+       return QInputContext::x11FilterEvent (keywidget, xevent);
+}
+#endif
+
+void
+IBusInputContext::setIC (QString ic)
+{
+       this->ic = ic;
+}
+
+QString
+IBusInputContext::getIC ()
+{
+       return ic;
+}
+
+void
+IBusInputContext::commitString (QString text)
+{
+       QInputMethodEvent event;
+       event.setCommitString (text);
+       sendEvent (event);
+       update ();
+}
+
+void
+IBusInputContext::updatePreedit (QString text, QList <QList <quint32> > attr_list, int cursor_pos, bool visible)
+{
+       // qDebug () << text << cursor_pos << show;
+       QList <QAttribute> qattrs;
+
+       if (visible) {
+               // append cursor pos
+               qattrs.append (QAttribute (QInputMethodEvent::Cursor, cursor_pos, true, 0));
+
+               // append attributes
+               for (QList <QList <quint32> >::iterator it = attr_list.begin (); it != attr_list.end(); ++ it) {
+
+                       QList <quint32> attr = *it;
+                       QTextCharFormat format;
+
+                       switch (attr[0]) {
+                       case 1: // underline
+                               format.setUnderlineStyle (QTextCharFormat::SingleUnderline);
+                               break;
+                       case 2: // foreground
+                               format.setForeground (QBrush (QColor (attr[1])));
+                               break;
+                       case 3: // background
+                               format.setBackground (QBrush (QColor (attr[1])));
+                               break;
+                       default:
+                               break;
+                       }
+
+                       qattrs.append (QAttribute (QInputMethodEvent::TextFormat, attr[2], attr[3] - attr[2], QVariant (format)));
+                       // qDebug () << attr[0] << attr[2] << attr[3] - attr[2];
+               }
+       }
+       else {
+               qattrs.append (QAttribute (QInputMethodEvent::Cursor, 0, true, 0));
+               text = "";
+               cursor_pos = 0;
+       }
+
+       preedit_string = text;
+       preedit_visible = visible;
+       preedit_attrs = attr_list;
+       preedit_cursor_pos = cursor_pos;
+
+       QInputMethodEvent event (text, qattrs);
+       sendEvent (event);
+       update ();
+}
+
+void
+IBusInputContext::showPreedit ()
+{
+       if (preedit_visible)
+               return;
+
+       updatePreedit (preedit_string, preedit_attrs, preedit_cursor_pos, TRUE);
+}
+
+void
+IBusInputContext::hidePreedit ()
+{
+       if (!preedit_visible)
+               return;
+
+       updatePreedit (preedit_string, preedit_attrs, preedit_cursor_pos, FALSE);
+}
+
diff --git a/client/qt4/ibus-input-context.h b/client/qt4/ibus-input-context.h
new file mode 100644 (file)
index 0000000..317c876
--- /dev/null
@@ -0,0 +1,69 @@
+/* vim:set noet ts=4: */
+/*
+ * ibus - The Input Bus
+ *
+ * Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA  02111-1307  USA
+ */
+#ifndef __IBUS_INPUT_CONTEXT_H_
+#define __IBUS_INPUT_CONTEXT_H_
+#include <QInputContext>
+#include <QList>
+#include "ibus-client.h"
+
+class IBusClient;
+
+class IBusInputContext : public QInputContext  {
+       Q_OBJECT
+public:
+       IBusInputContext (QObject *parent, IBusClient *client, QString &ic);
+       ~IBusInputContext ();
+
+public:
+       bool filterEvent (const QEvent *event);
+       QFont font () const;
+       QString identifierName ();
+       bool isComposing() const;
+       QString language();
+       void mouseHandler (int x, QMouseEvent *event);
+       void reset();
+       void update ();
+       void setFocusWidget (QWidget *widget );
+       void widgetDestroyed (QWidget *widget);
+#ifdef Q_WS_X11
+       bool x11FilterEvent (QWidget *keywidget, XEvent *event);
+#endif
+       void setIC (QString ic);
+       QString getIC ();
+
+       void commitString (QString text);
+       void updatePreedit (QString text, QList <QList <quint32> > attr_list, int cursor_pos, bool visible);
+       void showPreedit ();
+       void hidePreedit ();
+
+
+private:
+       IBusClient *client;
+       QString ic;
+       QString preedit_string;
+       bool preedit_visible;
+       int preedit_cursor_pos;
+       QList <QList <quint32> > preedit_attrs;
+       QRect cursor_location;
+};
+
+#endif //__IBUS_INPUT_CONTEXT_H_
diff --git a/client/qt4/ibus.pro b/client/qt4/ibus.pro
new file mode 100644 (file)
index 0000000..1c308a2
--- /dev/null
@@ -0,0 +1,40 @@
+# vim:set noet ts=4:
+#
+# ibus - The Input Bus
+#
+# Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this program; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+# Boston, MA  02111-1307  USA
+
+TEMPLATE = lib
+TARGET = ibus
+DEPENDPATH += . 
+INCLUDEPATH += .
+
+CONFIG += qt qdbus plugin
+
+# Input
+HEADERS += \
+       ibus-client.h \
+       ibus-input-context.h
+
+SOURCES += \
+       ibus-client.cpp \
+       ibus-input-context.cpp \
+       im-ibus-qt.cpp
+
+target.path += $$[QT_INSTALL_PLUGINS]/inputmethods
+INSTALLS    += target
diff --git a/client/qt4/im-ibus-qt.cpp b/client/qt4/im-ibus-qt.cpp
new file mode 100644 (file)
index 0000000..0d6944b
--- /dev/null
@@ -0,0 +1,136 @@
+/* vim:set noet ts=4: */
+/*
+ * ibus - The Input Bus
+ *
+ * Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA  02111-1307  USA
+ */
+#include <cassert>
+#include <Qt>
+#include <QInputContextPlugin>
+#include "ibus-client.h"
+
+using namespace Qt;
+
+#define IBUS_IDENTIFIER_NAME "ibus"
+
+static IBusClient *client;
+
+/* The class Definition */
+class IBusInputContextPlugin: public QInputContextPlugin
+{
+
+    private:
+
+        /**
+         * The language list for SCIM.
+         */
+        static QStringList ibus_languages;
+
+    public:
+
+               IBusInputContextPlugin (QObject *parent = 0);
+
+        ~IBusInputContextPlugin ();
+
+        QStringList keys () const;
+
+        QStringList languages (const QString &key);
+
+        QString description (const QString &key);
+        
+        QInputContext *create (const QString &key);
+
+        QString displayName (const QString &key);
+
+};
+
+
+/* Implementations */
+QStringList IBusInputContextPlugin::ibus_languages;
+
+
+IBusInputContextPlugin::IBusInputContextPlugin (QObject *parent)
+       :QInputContextPlugin (parent)
+{
+}
+
+
+IBusInputContextPlugin::~IBusInputContextPlugin ()
+{
+       if (client != NULL) {
+               delete client;
+               client = NULL;
+       }
+}
+
+QStringList 
+IBusInputContextPlugin::keys () const 
+{
+    QStringList identifiers;
+    identifiers.push_back (IBUS_IDENTIFIER_NAME);
+    return identifiers;
+}
+
+
+QStringList
+IBusInputContextPlugin::languages (const QString & key)
+{
+       if (key.toLower () != IBUS_IDENTIFIER_NAME)
+               return QStringList ();
+
+    if (ibus_languages.empty ()) {
+        ibus_languages.push_back ("zh_CN");
+        ibus_languages.push_back ("zh_TW");
+        ibus_languages.push_back ("zh_HK");
+        ibus_languages.push_back ("ja");
+        ibus_languages.push_back ("ko");
+    }
+    return ibus_languages;
+}
+
+
+QString
+IBusInputContextPlugin::description (const QString &key)
+{
+       if (key.toLower () != IBUS_IDENTIFIER_NAME)
+               return QString ("");
+    
+       return QString::fromUtf8 ("Qt immodule plugin for IBus");
+}
+
+
+QInputContext *
+IBusInputContextPlugin::create (const QString &key)
+{
+    if (key.toLower () != IBUS_IDENTIFIER_NAME) {
+        return NULL;
+    } else {
+               if (client == NULL) {
+                       client = new IBusClient ();
+               }
+        return client->createInputContext ();
+    }
+}
+
+
+QString IBusInputContextPlugin::displayName (const QString &key)
+{
+    return key;
+}
+
+Q_EXPORT_PLUGIN2 (IBusInputContextPlugin, IBusInputContextPlugin)
diff --git a/client/x11/IMdkit/FrameMgr.c b/client/x11/IMdkit/FrameMgr.c
new file mode 100644 (file)
index 0000000..9b49794
--- /dev/null
@@ -0,0 +1,2466 @@
+/******************************************************************
+Copyright 1993, 1994 by Digital Equipment Corporation, Maynard, Massachusetts,
+                        All Rights Reserved
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the names of Digital or MIT not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+  Author: Hiroyuki Miyamoto  Digital Equipment Corporation
+                             miyamoto@jrd.dec.com
+
+    This version tidied and debugged by Steve Underwood May 1999
+
+******************************************************************/
+
+#include <X11/Xlibint.h>
+#include <stdlib.h>
+#include "FrameMgr.h"
+
+/* Convenient macro */
+
+#define _UNIT(n)   ((int)(n) & 0xFF)
+#define _NUMBER(n) (((int)(n) >> 8) & 0xFF)
+
+/* For byte swapping */
+
+#define Swap16(p, n) ((p)->byte_swap ?       \
+(((n) << 8 & 0xFF00) | \
+ ((n) >> 8 & 0xFF)     \
+) : n)
+#define Swap32(p, n) ((p)->byte_swap ?            \
+        (((n) << 24 & 0xFF000000) | \
+         ((n) <<  8 & 0xFF0000) |   \
+         ((n) >>  8 & 0xFF00) |     \
+         ((n) >> 24 & 0xFF)         \
+        ) : n)
+#define Swap64(p, n) ((p)->byte_swap ?            \
+        (((n) << 56 & 0xFF00000000000000) | \
+         ((n) << 40 & 0xFF000000000000) |   \
+         ((n) << 24 & 0xFF0000000000) |     \
+         ((n) <<  8 & 0xFF00000000) |       \
+         ((n) >>  8 & 0xFF000000) |         \
+         ((n) >> 24 & 0xFF0000) |           \
+         ((n) >> 40 & 0xFF00) |             \
+         ((n) >> 56 & 0xFF)                 \
+        ) : n)
+
+/* Type definition */
+
+typedef struct _Iter *Iter;
+
+typedef struct _FrameInst *FrameInst;
+
+typedef union
+{
+    int num;           /* For BARRAY */
+    FrameInst fi;      /* For POINTER */
+    Iter iter;                 /* For ITER */
+} ExtraDataRec, *ExtraData;
+
+typedef struct _Chain
+{
+    ExtraDataRec d;
+    int frame_no;
+    struct _Chain *next;
+} ChainRec, *Chain;
+
+typedef struct _ChainMgr
+{
+    Chain top;
+    Chain tail;
+} ChainMgrRec, *ChainMgr;
+
+typedef struct _ChainIter
+{
+    Chain cur;
+} ChainIterRec, *ChainIter;
+
+typedef struct _FrameIter
+{
+    Iter iter;
+    Bool counting;
+    unsigned int counter;
+    int end;
+    struct _FrameIter* next;
+} FrameIterRec, *FrameIter;
+
+typedef struct _FrameInst
+{
+    XimFrame template;
+    ChainMgrRec cm;
+    int cur_no;
+} FrameInstRec;
+
+typedef void (*IterStartWatchProc) (Iter it, void *client_data);
+
+typedef struct _Iter
+{
+    XimFrame template;
+    int max_count;
+    Bool allow_expansion;
+    ChainMgrRec cm;
+    int cur_no;
+    IterStartWatchProc start_watch_proc;
+    void *client_data;
+    Bool start_counter;
+} IterRec;
+
+typedef struct _FrameMgr
+{
+    XimFrame frame;
+    FrameInst fi;
+    char *area;
+    int idx;
+    Bool byte_swap;
+    int total_size;
+    FrameIter iters;
+} FrameMgrRec;
+
+typedef union
+{
+    int num;           /* For BARRAY and PAD */
+    struct
+    {          /* For COUNTER_* */
+        Iter iter;
+        Bool is_byte_len;
+    } counter;
+} XimFrameTypeInfoRec, *XimFrameTypeInfo;
+
+/* Special values */
+#define NO_VALUE -1
+#define NO_VALID_FIELD -2
+
+static FrameInst FrameInstInit(XimFrame frame);
+static void FrameInstFree(FrameInst fi);
+static XimFrameType FrameInstGetNextType(FrameInst fi, XimFrameTypeInfo info);
+static XimFrameType FrameInstPeekNextType(FrameInst fi, XimFrameTypeInfo info);
+static FmStatus FrameInstSetSize(FrameInst fi, int num);
+static FmStatus FrameInstSetIterCount(FrameInst fi, int num);
+static int FrameInstGetTotalSize(FrameInst fi);
+static void FrameInstReset(FrameInst fi);
+
+static Iter IterInit(XimFrame frame, int count);
+static void IterFree(Iter it);
+static int FrameInstGetSize(FrameInst fi);
+static int IterGetSize(Iter it);
+static XimFrameType IterGetNextType(Iter it, XimFrameTypeInfo info);
+static XimFrameType IterPeekNextType(Iter it, XimFrameTypeInfo info);
+static FmStatus IterSetSize(Iter it, int num);
+static FmStatus IterSetIterCount(Iter it, int num);
+static int IterGetTotalSize(Iter it);
+static void IterReset(Iter it);
+static Bool IterIsLoopEnd(Iter it, Bool* myself);
+static void IterSetStartWatch(Iter it, IterStartWatchProc proc, void* client_data);
+static void _IterStartWatch(Iter it, void* client_data);
+
+static ExtraData ChainMgrGetExtraData(ChainMgr cm, int frame_no);
+static ExtraData ChainMgrSetData(ChainMgr cm, int frame_no,
+                                 ExtraDataRec data);
+static Bool ChainIterGetNext(ChainIter ci, int* frame_no, ExtraData d);
+static int _FrameInstIncrement(XimFrame frame, int count);
+static int _FrameInstDecrement(XimFrame frame, int count);
+static int _FrameInstGetItemSize(FrameInst fi, int cur_no);
+static Bool FrameInstIsIterLoopEnd(FrameInst fi);
+
+static FrameIter _FrameMgrAppendIter(FrameMgr fm, Iter it, int end);
+static FrameIter _FrameIterCounterIncr(FrameIter fitr, int i);
+static void _FrameMgrRemoveIter(FrameMgr fm, FrameIter it);
+static Bool _FrameMgrIsIterLoopEnd(FrameMgr fm);
+static Bool _FrameMgrProcessPadding(FrameMgr fm, FmStatus* status);
+
+#define IterGetIterCount(it) ((it)->allow_expansion ? \
+NO_VALUE : (it)->max_count)
+
+#define IterFixIteration(it) ((it)->allow_expansion = False)
+
+#define IterSetStarter(it) ((it)->start_counter = True)
+
+#define ChainMgrInit(cm) (cm)->top = (cm)->tail = NULL
+#define ChainMgrFree(cm)                \
+{                                       \
+    Chain tmp;                          \
+    Chain cur = (cm)->top;              \
+                                       \
+    while (cur)                         \
+    {                                   \
+        tmp = cur->next;                \
+        Xfree (cur);                    \
+       cur = tmp;                      \
+    }                                   \
+}
+
+#define ChainIterInit(ci, cm)           \
+{                                       \
+    (ci)->cur = (cm)->top;              \
+}
+
+/* ChainIterFree has nothing to do. */
+#define ChainIterFree(ci)
+
+#define FrameInstIsEnd(fi) ((fi)->template[(fi)->cur_no].type == EOL)
+
+FrameMgr FrameMgrInit (XimFrame frame, char* area, Bool byte_swap)
+{
+    FrameMgr fm;
+
+    fm = (FrameMgr) Xmalloc (sizeof (FrameMgrRec));
+
+    fm->frame = frame;
+    fm->fi = FrameInstInit (frame);
+    fm->area = (char *) area;
+    fm->idx = 0;
+    fm->byte_swap = byte_swap;
+    fm->total_size = NO_VALUE;
+    fm->iters = NULL;
+
+    return fm;
+}
+
+void FrameMgrInitWithData (FrameMgr fm,
+                           XimFrame frame,
+                           void * area,
+                           Bool byte_swap)
+{
+    fm->frame = frame;
+    fm->fi = FrameInstInit (frame);
+    fm->area = (char *) area;
+    fm->idx = 0;
+    fm->byte_swap = byte_swap;
+    fm->total_size = NO_VALUE;
+}
+
+void FrameMgrFree (FrameMgr fm)
+{
+    FrameIter p, cur;
+
+    p = fm->iters;
+    cur = p;
+
+    while (p)
+    {
+        p = p->next;
+        Xfree (cur);
+        cur = p;
+    }
+    /*endwhile*/
+
+    FrameInstFree (fm->fi);
+    Xfree (fm);
+}
+
+FmStatus FrameMgrSetBuffer (FrameMgr fm, void* area)
+{
+    if (fm->area)
+        return FmBufExist;
+    fm->area = (char *) area;
+    return FmSuccess;
+}
+
+FmStatus _FrameMgrPutToken (FrameMgr fm, void *data, int data_size)
+{
+    XimFrameType type;
+    XimFrameTypeInfoRec info;
+
+    if (fm->total_size != NO_VALUE  &&  fm->idx >= fm->total_size)
+        return FmNoMoreData;
+    /*endif*/
+    
+    type = FrameInstGetNextType(fm->fi, &info);
+
+    if (type & COUNTER_MASK)
+    {
+        unsigned long input_length;
+
+        if (info.counter.is_byte_len)
+        {
+            if ((input_length = IterGetTotalSize (info.counter.iter))
+                    == NO_VALUE)
+            {
+                return FmCannotCalc;
+            }
+            /*endif*/
+        }
+        else
+        {
+            if ((input_length = IterGetIterCount (info.counter.iter))
+                == NO_VALUE)
+            {
+                return FmCannotCalc;
+            }
+            /*endif*/
+        }
+        /*endif*/
+        switch (type)
+        {
+        case COUNTER_BIT8:
+            *(CARD8 *) (fm->area + fm->idx) = input_length;
+            fm->idx++;
+            break;
+        
+        case COUNTER_BIT16:
+            *(CARD16 *) (fm->area + fm->idx) = Swap16 (fm, input_length);
+            fm->idx += 2;
+            break;
+            
+        case COUNTER_BIT32:
+            *(CARD32 *) (fm->area + fm->idx) = Swap32 (fm, input_length);
+            fm->idx += 4;
+            break;
+
+#if defined(_NEED64BIT)
+        case COUNTER_BIT64:
+            *(CARD64 *) (fm->area + fm->idx) = Swap64 (fm, input_length);
+            fm->idx += 8;
+            break;
+#endif
+       default:
+           break;
+        }
+        /*endswitch*/
+        _FrameMgrPutToken(fm, data, data_size);
+        return FmSuccess;
+    }
+    /*endif*/
+
+    switch (type)
+    {
+    case BIT8:
+        if (data_size == sizeof (unsigned char))
+        {
+            unsigned long num = *(unsigned char *) data;
+            *(CARD8 *) (fm->area + fm->idx) = num;
+        }
+        else if (data_size == sizeof (unsigned short))
+        {
+            unsigned long num = *(unsigned short *) data;
+            *(CARD8 *) (fm->area + fm->idx) = num;
+        }
+        else if (data_size == sizeof (unsigned int))
+        {
+            unsigned long num = *(unsigned int *) data;
+            *(CARD8 *) (fm->area + fm->idx) = num;
+        }
+        else if (data_size == sizeof (unsigned long))
+        {
+            unsigned long num = *(unsigned long *) data;
+            *(CARD8 *) (fm->area + fm->idx) = num;
+        }
+        else
+        {
+            ; /* Should never be reached */
+        }
+        /*endif*/
+        fm->idx++;
+        return FmSuccess;
+
+    case BIT16:
+        if (data_size == sizeof (unsigned char))
+        {
+            unsigned long num = *(unsigned char *) data;
+            *(CARD16*)(fm->area + fm->idx) = Swap16 (fm, num);
+        }
+        else if (data_size == sizeof (unsigned short))
+        {
+            unsigned long num = *(unsigned short *) data;
+            *(CARD16 *) (fm->area + fm->idx) = Swap16 (fm, num);
+        }
+        else if (data_size == sizeof (unsigned int))
+        {
+            unsigned long num = *(unsigned int *) data;
+            *(CARD16 *) (fm->area + fm->idx) = Swap16 (fm, num);
+        }
+        else if (data_size == sizeof (unsigned long))
+        {
+            unsigned long num = *(unsigned long *) data;
+            *(CARD16 *) (fm->area + fm->idx) = Swap16 (fm, num);
+        }
+        else
+        {
+            ; /* Should never reached */
+        }
+        /*endif*/
+        fm->idx += 2;
+        return FmSuccess;
+
+    case BIT32:
+        if (data_size == sizeof (unsigned char))
+        {
+            unsigned long num = *(unsigned char *) data;
+            *(CARD32 *) (fm->area + fm->idx) = Swap32 (fm, num);
+        }
+        else if (data_size == sizeof (unsigned short))
+        {
+            unsigned long num = *(unsigned short *) data;
+            *(CARD32 *) (fm->area + fm->idx) = Swap32 (fm, num);
+        }
+        else if (data_size == sizeof (unsigned int))
+        {
+            unsigned long num = *(unsigned int *) data;
+            *(CARD32 *) (fm->area + fm->idx) = Swap32 (fm, num);
+        }
+        else if (data_size == sizeof (unsigned long))
+        {
+            unsigned long num = *(unsigned long *) data;
+            *(CARD32 *) (fm->area + fm->idx) = Swap32 (fm, num);
+        }
+        else
+        {
+            ; /* Should never reached */
+        }
+        /*endif*/
+        fm->idx += 4;
+        return FmSuccess;
+
+#if defined(_NEED64BIT)
+    case BIT64:
+        if (data_size == sizeof (unsigned char))
+        {
+            unsigned long num = *(unsigned char *) data;
+            *(CARD64 *) (fm->area + fm->idx) = Swap64 (fm, num);
+        }
+        else if (data_size == sizeof (unsigned short))
+        {
+            unsigned long num = *(unsigned short *) data;
+            *(CARD64 *) (fm->area + fm->idx) = Swap64 (fm, num);
+        }
+        else if (data_size == sizeof (unsigned int))
+        {
+            unsigned long num = *(unsigned int *) data;
+            *(CARD64 *) (fm->area + fm->idx) = Swap64 (fm, num);
+        }
+        else if (data_size == sizeof (unsigned long))
+        {
+            unsigned long num = *(unsigned long *) data;
+            *(CARD64 *) (fm->area + fm->idx) = Swap64 (fm, num);
+        }
+        else
+        {
+            ; /* Should never reached */
+        }
+        /*endif*/
+        fm->idx += 4;
+        return FmSuccess;
+#endif
+
+    case BARRAY:
+        if (info.num == NO_VALUE)
+            return FmInvalidCall;
+        /*endif*/
+        if (info.num > 0)
+        {
+            bcopy (*(char **) data, fm->area + fm->idx, info.num);
+            fm->idx += info.num;
+        }
+        /*endif*/
+        return FmSuccess;
+
+    case PADDING:
+        if (info.num == NO_VALUE)
+            return FmInvalidCall;
+        /*endif*/
+        fm->idx += info.num;
+        return _FrameMgrPutToken(fm, data, data_size);
+
+    case ITER:
+        return FmInvalidCall;
+        
+    case EOL:
+        return FmEOD;
+    default:
+       break;
+    }
+    /*endswitch*/
+    return (FmStatus) NULL;  /* Should never be reached */
+}
+
+FmStatus _FrameMgrGetToken (FrameMgr fm , void* data, int data_size)
+{
+    XimFrameType type;
+    static XimFrameTypeInfoRec info;  /* memory */
+    FrameIter fitr;
+
+    if (fm->total_size != NO_VALUE  &&  fm->idx >= fm->total_size)
+        return FmNoMoreData;
+    /*endif*/
+    
+    type = FrameInstGetNextType(fm->fi, &info);
+
+    if (type & COUNTER_MASK)
+    {
+        int end=0;
+        FrameIter client_data;
+
+        type &= ~COUNTER_MASK;
+        switch (type)
+        {
+        case BIT8:
+            end = *(CARD8 *) (fm->area + fm->idx);
+            break;
+        
+        case BIT16:
+            end = Swap16 (fm, *(CARD16 *) (fm->area + fm->idx));
+            break;
+        
+        case BIT32:
+            end = Swap32 (fm, *(CARD32 *) (fm->area + fm->idx));
+            break;
+
+#if defined(_NEED64BIT)        
+        case BIT64:
+            end = Swap64 (fm, *(CARD64 *) (fm->area + fm->idx));
+            break;
+#endif
+       default:
+           break;
+        }
+        /*endswitch*/
+        
+        if ((client_data = _FrameMgrAppendIter (fm, info.counter.iter, end)))
+        {
+            IterSetStarter (info.counter.iter);
+            IterSetStartWatch (info.counter.iter,
+                               _IterStartWatch,
+                               (void *) client_data);
+        }
+        /*endif*/
+    }
+    /*endif*/
+
+    type &= ~COUNTER_MASK;
+    switch (type)
+    {
+    case BIT8:
+        if (data_size == sizeof (unsigned char))
+        {
+            *(unsigned char*) data = *(CARD8 *) (fm->area + fm->idx);
+        }
+        else if (data_size == sizeof (unsigned short))
+        {
+            *(unsigned short *) data = *(CARD8 *) (fm->area + fm->idx);
+        }
+        else if (data_size == sizeof (unsigned int))
+        {
+            *(unsigned int *) data = *(CARD8 *) (fm->area + fm->idx);
+        }
+        else if (data_size == sizeof (unsigned long))
+        {
+            *(unsigned long *) data = *(CARD8 *) (fm->area + fm->idx);
+        }
+        else
+        {
+            ; /* Should never reached */
+        }
+        /*endif*/
+        fm->idx++;
+        if ((fitr = _FrameIterCounterIncr (fm->iters, 1/*BIT8*/)))
+            _FrameMgrRemoveIter (fm, fitr);
+        /*endif*/
+        return FmSuccess;
+
+    case BIT16:
+        if (data_size == sizeof (unsigned char))
+        {
+            *(unsigned char *) data =
+                Swap16 (fm, *(CARD16 *) (fm->area + fm->idx));
+        }
+        else if (data_size == sizeof (unsigned short))
+        {
+            *(unsigned short *) data =
+                Swap16 (fm, *(CARD16 *) (fm->area + fm->idx));
+        }
+        else if (data_size == sizeof (unsigned int))
+        {
+            *(unsigned int *) data =
+                Swap16 (fm, *(CARD16 *) (fm->area + fm->idx));
+        }
+        else if (data_size == sizeof (unsigned long))
+        {
+            *(unsigned long *) data =
+                Swap16 (fm, *(CARD16 *) (fm->area + fm->idx));
+        }
+        else
+        {
+            ; /* Should never reached */
+        }
+        /*endif*/
+        fm->idx += 2;
+        if ((fitr = _FrameIterCounterIncr (fm->iters, 2/*BIT16*/)))
+            _FrameMgrRemoveIter(fm, fitr);
+        /*endif*/
+        return FmSuccess;
+
+    case BIT32:
+        if (data_size == sizeof (unsigned char))
+        {
+            *(unsigned char *) data =
+                Swap32 (fm, *(CARD32 *) (fm->area + fm->idx));
+        }
+        else if (data_size == sizeof (unsigned short))
+        {
+            *(unsigned short *) data =
+                Swap32 (fm, *(CARD32 *) (fm->area + fm->idx));
+        }
+        else if (data_size == sizeof (unsigned int))
+        {
+            *(unsigned int *) data =
+                Swap32 (fm, *(CARD32 *) (fm->area + fm->idx));
+        }
+        else if (data_size == sizeof (unsigned long))
+        {
+            *(unsigned long *) data =
+                Swap32 (fm, *(CARD32 *) (fm->area + fm->idx));
+        }
+        else
+        {
+            ; /* Should never reached */
+        }
+        /*endif*/
+        fm->idx += 4;
+        if ((fitr = _FrameIterCounterIncr (fm->iters, 4/*BIT32*/)))
+            _FrameMgrRemoveIter (fm, fitr);
+        /*endif*/
+        return FmSuccess;
+
+#if defined(_NEED64BIT)    
+    case BIT64:
+        if (data_size == sizeof (unsigned char))
+        {
+            *(unsigned char *) data =
+                Swap64 (fm, *(CARD64 *) (fm->area + fm->idx));
+        }
+        else if (data_size == sizeof (unsigned short))
+        {
+            *(unsigned short *) data =
+                Swap64 (fm, *(CARD64 *) (fm->area + fm->idx));
+        }
+        else if (data_size == sizeof (unsigned int))
+        {
+            *(unsigned int *) data =
+                Swap64 (fm, *(CARD64 *) (fm->area + fm->idx));
+        }
+        else if (data_size == sizeof (unsigned long))
+        {
+            *(unsigned long *) data =
+                Swap64 (fm, *(CARD64 *) (fm->area + fm->idx));
+        }
+        else
+        {
+            ; /* Should never reached */
+        }
+        /*endif*/
+        fm->idx += 8;
+        if ((fitr = _FrameIterCounterIncr (fm->iters, 8/*BIT64*/)))
+            _FrameMgrRemoveIter (fm, fitr);
+        /*endif*/
+        return FmSuccess;
+#endif
+
+    case BARRAY:
+        if (info.num == NO_VALUE)
+            return FmInvalidCall;
+        /*endif*/
+        if (info.num > 0)
+        {
+            *(char **) data = fm->area + fm->idx;
+            
+            fm->idx += info.num;
+            if ((fitr = _FrameIterCounterIncr (fm->iters, info.num)))
+                _FrameMgrRemoveIter (fm, fitr);
+            /*endif*/
+        }
+        else
+        {
+            *(char **) data = NULL;
+        }
+        /*endif*/
+        return FmSuccess;
+
+    case PADDING:
+        if (info.num == NO_VALUE)
+            return FmInvalidCall;
+        /*endif*/
+        fm->idx += info.num;
+        if ((fitr = _FrameIterCounterIncr (fm->iters, info.num)))
+            _FrameMgrRemoveIter (fm, fitr);
+        /*endif*/
+        return _FrameMgrGetToken (fm, data, data_size);
+
+    case ITER:
+        return FmInvalidCall;  /* if comes here, it's a bug! */
+
+    case EOL:
+        return FmEOD;
+    default:
+       break;
+    }
+    /*endswitch*/
+    return (FmStatus) NULL;  /* Should never be reached */
+}
+
+FmStatus FrameMgrSetSize (FrameMgr fm, int barray_size)
+{
+    if (FrameInstSetSize (fm->fi, barray_size) == FmSuccess)
+        return FmSuccess;
+    /*endif*/
+    return FmNoMoreData;
+}
+
+FmStatus FrameMgrSetIterCount (FrameMgr fm, int count)
+{
+    if (FrameInstSetIterCount (fm->fi, count) == FmSuccess)
+        return FmSuccess;
+    /*endif*/
+    return FmNoMoreData;
+}
+
+FmStatus FrameMgrSetTotalSize (FrameMgr fm, int total_size)
+{
+    fm->total_size = total_size;
+    return FmSuccess;
+}
+
+int FrameMgrGetTotalSize (FrameMgr fm)
+{
+    return FrameInstGetTotalSize (fm->fi);
+}
+
+int FrameMgrGetSize (FrameMgr fm)
+{
+    register int ret_size;
+
+    ret_size = FrameInstGetSize (fm->fi);
+    if (ret_size == NO_VALID_FIELD)
+        return NO_VALUE;
+    /*endif*/
+    return ret_size;
+}
+
+FmStatus FrameMgrSkipToken (FrameMgr fm, int skip_count)
+{
+    XimFrameType type;
+    XimFrameTypeInfoRec info;
+    register int i;
+
+    if (fm->total_size != NO_VALUE  &&  fm->idx >= fm->total_size)
+        return FmNoMoreData;
+    /*endif*/
+    for (i = 0;  i < skip_count;  i++)
+    {
+        type = FrameInstGetNextType (fm->fi, &info);
+        type &= ~COUNTER_MASK;
+
+        switch (type)
+        {
+        case BIT8:
+            fm->idx++;
+            break;
+            
+        case BIT16:
+            fm->idx += 2;
+            break;
+            
+        case BIT32:
+            fm->idx += 4;
+            break;
+            
+        case BIT64:
+            fm->idx += 8;
+            break;
+            
+        case BARRAY:
+            if (info.num == NO_VALUE)
+                return FmInvalidCall;
+            /*endif*/
+            fm->idx += info.num;
+            break;
+            
+        case PADDING:
+            if (info.num == NO_VALUE)
+                return FmInvalidCall;
+            /*endif*/
+            fm->idx += info.num;
+            return FrameMgrSkipToken (fm, skip_count);
+            
+        case ITER:
+            return FmInvalidCall;
+            
+        case EOL:
+            return FmEOD;
+       default:
+           break;
+        }
+        /*endswitch*/
+    }
+    /*endfor*/
+    return FmSuccess;
+}
+
+void FrameMgrReset (FrameMgr fm)
+{
+    fm->idx = 0;
+    FrameInstReset (fm->fi);
+}
+
+Bool FrameMgrIsIterLoopEnd (FrameMgr fm, FmStatus* status)
+{
+    do
+    {
+        if (_FrameMgrIsIterLoopEnd (fm))
+            return  True;
+        /*endif*/
+    }
+    while (_FrameMgrProcessPadding (fm, status));
+
+    return False;
+}
+
+
+/* Internal routines */
+
+static Bool _FrameMgrIsIterLoopEnd (FrameMgr fm)
+{
+    return FrameInstIsIterLoopEnd (fm->fi);
+}
+
+static Bool _FrameMgrProcessPadding (FrameMgr fm, FmStatus* status)
+{
+    XimFrameTypeInfoRec info;
+    XimFrameType next_type = FrameInstPeekNextType (fm->fi, &info);
+    FrameIter fitr;
+
+    if (next_type == PADDING)
+    {
+        if (info.num == NO_VALUE)
+        {
+            *status = FmInvalidCall;
+            return True;
+        }
+        /*endif*/
+        next_type = FrameInstGetNextType (fm->fi, &info);
+        fm->idx += info.num;
+        if ((fitr = _FrameIterCounterIncr (fm->iters, info.num)))
+            _FrameMgrRemoveIter (fm, fitr);
+        /*endif*/
+        *status = FmSuccess;
+        return True;
+    }
+    /*endif*/
+    *status = FmSuccess;
+    return False;
+}
+
+static FrameInst FrameInstInit (XimFrame frame)
+{
+    FrameInst fi;
+
+    fi = (FrameInst) Xmalloc (sizeof (FrameInstRec));
+
+    fi->template = frame;
+    fi->cur_no = 0;
+    ChainMgrInit (&fi->cm);
+    return fi;
+}
+
+static void FrameInstFree (FrameInst fi)
+{
+    ChainIterRec ci;
+    int frame_no;
+    ExtraDataRec d;
+
+    ChainIterInit (&ci, &fi->cm);
+
+    while (ChainIterGetNext (&ci, &frame_no, &d))
+    {
+        register XimFrameType type;
+        type = fi->template[frame_no].type;
+        if (type == ITER)
+        {
+            if (d.iter)
+                IterFree (d.iter);
+            /*endif*/
+        }
+        else if (type == POINTER)
+        {
+            if (d.fi)
+                FrameInstFree (d.fi);
+            /*endif*/
+        }
+        /*endif*/
+    }
+    /*endwhile*/
+    ChainIterFree (&ci);
+    ChainMgrFree (&fi->cm);
+    Xfree (fi);
+}
+
+static XimFrameType FrameInstGetNextType(FrameInst fi, XimFrameTypeInfo info)
+{
+    XimFrameType ret_type;
+
+    ret_type = fi->template[fi->cur_no].type;
+
+    switch (ret_type)
+    {
+    case BIT8:
+    case BIT16:
+    case BIT32:
+    case BIT64:
+    case EOL:
+        fi->cur_no = _FrameInstIncrement(fi->template, fi->cur_no);
+        break;
+
+    case COUNTER_BIT8:
+    case COUNTER_BIT16:
+    case COUNTER_BIT32:
+    case COUNTER_BIT64:
+        if (info)
+        {
+            register int offset, iter_idx;
+
+            info->counter.is_byte_len =
+                (((long) fi->template[fi->cur_no].data & 0xFF)) == FmCounterByte;
+            offset = ((long) fi->template[fi->cur_no].data) >> 8;
+            iter_idx = fi->cur_no + offset;
+            if (fi->template[iter_idx].type == ITER)
+            {
+                ExtraData d;
+                ExtraDataRec dr;
+
+                if ((d = ChainMgrGetExtraData (&fi->cm, iter_idx)) == NULL)
+                {
+                    dr.iter = IterInit (&fi->template[iter_idx + 1], NO_VALUE);
+                    d = ChainMgrSetData (&fi->cm, iter_idx, dr);
+                }
+                /*endif*/
+                info->counter.iter = d->iter;
+            }
+            else
+            {
+                /* Should never reach here */
+            }
+            /*endif*/
+        }
+        /*endif*/
+        fi->cur_no = _FrameInstIncrement (fi->template, fi->cur_no);
+        break;
+
+    case BARRAY:
+        if (info)
+        {
+            ExtraData d;
+
+            if ((d = ChainMgrGetExtraData (&fi->cm, fi->cur_no)) == NULL)
+                info->num = NO_VALUE;
+            else
+                info->num = d->num;
+            /*endif*/
+        }
+        /*endif*/
+        fi->cur_no = _FrameInstIncrement (fi->template, fi->cur_no);
+        break;
+
+    case PADDING:
+        if (info)
+        {
+            register int unit;
+            register int number;
+            register int size;
+            register int i;
+
+            unit = _UNIT ((long) fi->template[fi->cur_no].data);
+            number = _NUMBER ((long) fi->template[fi->cur_no].data);
+
+            i = fi->cur_no;
+            size = 0;
+            while (number > 0)
+            {
+                i = _FrameInstDecrement (fi->template, i);
+                size += _FrameInstGetItemSize (fi, i);
+                number--;
+            }
+            /*endwhile*/
+            info->num = (unit - (size%unit))%unit;
+        }
+        /*endif*/
+        fi->cur_no = _FrameInstIncrement (fi->template, fi->cur_no);
+        break;
+
+    case ITER:
+        {
+            ExtraData d;
+            ExtraDataRec dr;
+            XimFrameType sub_type;
+
+
+            if ((d = ChainMgrGetExtraData (&fi->cm, fi->cur_no)) == NULL)
+            {
+                dr.iter = IterInit (&fi->template[fi->cur_no + 1], NO_VALUE);
+                d = ChainMgrSetData (&fi->cm, fi->cur_no, dr);
+            }
+            /*endif*/
+            sub_type = IterGetNextType (d->iter, info);
+            if (sub_type == EOL)
+            {
+                fi->cur_no = _FrameInstIncrement (fi->template, fi->cur_no);
+                ret_type = FrameInstGetNextType (fi, info);
+            }
+            else
+            {
+                ret_type = sub_type;
+            }
+            /*endif*/
+        }
+        break;
+
+    case POINTER:
+        {
+            ExtraData d;
+            ExtraDataRec dr;
+            XimFrameType sub_type;
+
+            if ((d = ChainMgrGetExtraData (&fi->cm, fi->cur_no)) == NULL)
+            {
+                dr.fi = FrameInstInit (fi->template[fi->cur_no + 1].data);
+                d = ChainMgrSetData (&fi->cm, fi->cur_no, dr);
+            }
+            /*endif*/
+            sub_type = FrameInstGetNextType (d->fi, info);
+            if (sub_type == EOL)
+            {
+                fi->cur_no = _FrameInstIncrement (fi->template, fi->cur_no);
+                ret_type = FrameInstGetNextType (fi, info);
+            }
+            else
+            {
+                ret_type = sub_type;
+            }
+            /*endif*/
+        }
+        break;
+    default:
+       break;
+    }
+    /*endswitch*/
+    return ret_type;
+}
+
+static XimFrameType FrameInstPeekNextType (FrameInst fi, XimFrameTypeInfo info)
+{
+    XimFrameType ret_type;
+
+    ret_type = fi->template[fi->cur_no].type;
+
+    switch (ret_type)
+    {
+    case BIT8:
+    case BIT16:
+    case BIT32:
+    case BIT64:
+    case EOL:
+        break;
+
+    case COUNTER_BIT8:
+    case COUNTER_BIT16:
+    case COUNTER_BIT32:
+    case COUNTER_BIT64:
+        if (info)
+        {
+            register int offset;
+           register int iter_idx;
+
+            info->counter.is_byte_len =
+                (((long) fi->template[fi->cur_no].data) & 0xFF) == FmCounterByte;
+            offset = ((long)fi->template[fi->cur_no].data) >> 8;
+            iter_idx = fi->cur_no + offset;
+            if (fi->template[iter_idx].type == ITER)
+            {
+                ExtraData d;
+                ExtraDataRec dr;
+
+                if ((d = ChainMgrGetExtraData (&fi->cm, iter_idx)) == NULL)
+                {
+                    dr.iter = IterInit (&fi->template[iter_idx + 1], NO_VALUE);
+                    d = ChainMgrSetData (&fi->cm, iter_idx, dr);
+                }
+                /*endif*/
+                info->counter.iter = d->iter;
+            }
+            else
+            {
+                /* Should not be reached here */
+            }
+            /*endif*/
+        }
+        /*endif*/
+        break;
+
+    case BARRAY:
+        if (info)
+        {
+            ExtraData d;
+
+            if ((d = ChainMgrGetExtraData (&fi->cm, fi->cur_no)) == NULL)
+                info->num = NO_VALUE;
+            else
+                info->num = d->num;
+            /*endif*/
+        }
+        /*endif*/
+        break;
+
+    case PADDING:
+        if (info)
+        {
+            register int unit;
+            register int number;
+            register int size;
+            register int i;
+
+            unit = _UNIT ((long) fi->template[fi->cur_no].data);
+            number = _NUMBER ((long) fi->template[fi->cur_no].data);
+
+            i = fi->cur_no;
+            size = 0;
+            while (number > 0)
+            {
+                i = _FrameInstDecrement (fi->template, i);
+                size += _FrameInstGetItemSize (fi, i);
+                number--;
+            }
+            /*endwhile*/
+            info->num = (unit - (size%unit))%unit;
+        }
+        /*endif*/
+        break;
+
+    case ITER:
+        {
+            ExtraData d;
+            ExtraDataRec dr;
+            XimFrameType sub_type;
+
+            if ((d = ChainMgrGetExtraData (&fi->cm, fi->cur_no)) == NULL)
+            {
+                dr.iter = IterInit (&fi->template[fi->cur_no + 1], NO_VALUE);
+                d = ChainMgrSetData (&fi->cm, fi->cur_no, dr);
+            }
+            /*endif*/
+            sub_type = IterPeekNextType (d->iter, info);
+            if (sub_type == EOL)
+                ret_type = FrameInstPeekNextType (fi, info);
+            else
+                ret_type = sub_type;
+            /*endif*/
+        }
+        break;
+
+    case POINTER:
+        {
+            ExtraData d;
+            ExtraDataRec dr;
+            XimFrameType sub_type;
+
+            if ((d = ChainMgrGetExtraData (&fi->cm, fi->cur_no)) == NULL)
+            {
+                dr.fi = FrameInstInit (fi->template[fi->cur_no + 1].data);
+                d = ChainMgrSetData (&fi->cm, fi->cur_no, dr);
+            }
+            /*endif*/
+            sub_type = FrameInstPeekNextType (d->fi, info);
+            if (sub_type == EOL)
+                ret_type = FrameInstPeekNextType (fi, info);
+            else
+                ret_type = sub_type;
+            /*endif*/
+       default:
+           break;
+        }
+        break;
+    }
+    /*endswitch*/
+    return ret_type;
+}
+
+static Bool FrameInstIsIterLoopEnd (FrameInst fi)
+{
+    Bool ret = False;
+
+    if (fi->template[fi->cur_no].type == ITER)
+    {
+        ExtraData d = ChainMgrGetExtraData (&fi->cm, fi->cur_no);
+        Bool yourself;
+
+        if (d)
+        {
+            ret = IterIsLoopEnd (d->iter, &yourself);
+            if (ret  &&  yourself)
+                fi->cur_no = _FrameInstIncrement (fi->template, fi->cur_no);
+            /*endif*/
+        }
+        /*endif*/
+    }
+    /*endif*/
+    return (ret);
+}
+
+static FrameIter _FrameMgrAppendIter (FrameMgr fm, Iter it, int end)
+{
+    FrameIter p = fm->iters;
+
+    while (p  &&  p->next)
+        p = p->next;
+    /*endwhile*/
+    
+    if (!p)
+    {
+        fm->iters =
+        p = (FrameIter) Xmalloc (sizeof (FrameIterRec));
+    }
+    else
+    {
+        p->next = (FrameIter) Xmalloc (sizeof (FrameIterRec));
+        p = p->next;
+    }
+    /*endif*/
+    if (p)
+    {
+        p->iter = it;
+        p->counting = False;
+        p->counter = 0;
+        p->end = end;
+        p->next = NULL;
+    }
+    /*endif*/
+    return (p);
+}
+
+static void _FrameMgrRemoveIter (FrameMgr fm, FrameIter it)
+{
+    FrameIter prev;
+    FrameIter p;
+
+    prev = NULL;
+    p = fm->iters;
+    while (p)
+    {
+        if (p == it)
+        {
+            if (prev)
+                prev->next = p->next;
+            else
+                fm->iters = p->next;
+            /*endif*/
+            Xfree (p);
+            break;
+        }
+        /*endif*/
+        prev = p;
+        p = p->next;
+    }
+    /*endwhile*/
+}
+
+static FrameIter _FrameIterCounterIncr (FrameIter fitr, int i)
+{
+    FrameIter p = fitr;
+
+    while (p)
+    {
+        if (p->counting)
+        {
+            p->counter += i;
+            if (p->counter >= p->end)
+            {
+                IterFixIteration (p->iter);
+                return (p);
+            }
+            /*endif*/
+        }
+        /*endif*/
+        p = p->next;
+    }
+    /*endwhile*/
+    return (NULL);
+}
+
+static void _IterStartWatch (Iter it, void *client_data)
+{
+    FrameIter p = (FrameIter) client_data;
+    p->counting = True;
+}
+
+static FmStatus FrameInstSetSize (FrameInst fi, int num)
+{
+    ExtraData d;
+    ExtraDataRec dr;
+    XimFrameType type;
+    register int i;
+
+    i = 0;
+    while ((type = fi->template[i].type) != EOL)
+    {
+        switch (type)
+        {
+        case BARRAY:
+            if ((d = ChainMgrGetExtraData (&fi->cm, i)) == NULL)
+            {
+                dr.num = -1;
+                d = ChainMgrSetData (&fi->cm, i, dr);
+            }
+            /*endif*/
+            if (d->num == NO_VALUE)
+            {
+                d->num = num;
+                return FmSuccess;
+            }
+            /*endif*/
+            break;
+        case ITER:
+            if ((d = ChainMgrGetExtraData (&fi->cm, i)) == NULL)
+            {
+                dr.iter = IterInit (&fi->template[i + 1], NO_VALUE);
+                d = ChainMgrSetData (&fi->cm, i, dr);
+            }
+            /*endif*/
+            if (IterSetSize (d->iter, num) == FmSuccess)
+                return FmSuccess;
+            /*endif*/
+            break;
+            
+        case POINTER:
+            if ((d = ChainMgrGetExtraData(&fi->cm, i)) == NULL)
+            {
+                dr.fi = FrameInstInit(fi->template[i + 1].data);
+                d = ChainMgrSetData(&fi->cm, i, dr);
+            }
+            /*endif*/
+            if (FrameInstSetSize(d->fi, num) == FmSuccess)
+                return FmSuccess;
+            /*endif*/
+            break;
+       default:
+           break;
+        }
+        /*endswitch*/
+        i = _FrameInstIncrement(fi->template, i);
+    }
+    /*endwhile*/
+    return FmNoMoreData;
+}
+
+static int FrameInstGetSize (FrameInst fi)
+{
+    XimFrameType type;
+    register int i;
+    ExtraData d;
+    ExtraDataRec dr;
+    int ret_size;
+
+    i = fi->cur_no;
+    while ((type = fi->template[i].type) != EOL)
+    {
+        switch (type)
+        {
+        case BARRAY:
+            if ((d = ChainMgrGetExtraData (&fi->cm, i)) == NULL)
+                return NO_VALUE;
+            /*endif*/
+            return d->num;
+
+        case ITER:
+            if ((d = ChainMgrGetExtraData (&fi->cm, i)) == NULL)
+            {
+                dr.iter = IterInit (&fi->template[i + 1], NO_VALUE);
+                d = ChainMgrSetData (&fi->cm, i, dr);
+            }
+            /*endif*/
+            ret_size = IterGetSize(d->iter);
+            if (ret_size != NO_VALID_FIELD)
+                return ret_size;
+            /*endif*/
+            break;
+            
+        case POINTER:
+            if ((d = ChainMgrGetExtraData (&fi->cm, i)) == NULL)
+            {
+                dr.fi = FrameInstInit (fi->template[i + 1].data);
+                d = ChainMgrSetData (&fi->cm, i, dr);
+            }
+            /*endif*/
+            ret_size = FrameInstGetSize (d->fi);
+            if (ret_size != NO_VALID_FIELD)
+                return ret_size;
+            /*endif*/
+            break;
+       default:
+           break;
+        }
+        /*endswitch*/
+        i = _FrameInstIncrement (fi->template, i);
+    }
+    /*endwhile*/
+    return NO_VALID_FIELD;
+}
+
+static FmStatus FrameInstSetIterCount (FrameInst fi, int num)
+{
+    ExtraData d;
+    ExtraDataRec dr;
+    register int i;
+    XimFrameType type;
+
+    i = 0;
+    while ((type = fi->template[i].type) != EOL)
+    {
+        switch (type)
+        {
+        case ITER:
+            if ((d = ChainMgrGetExtraData (&fi->cm, i)) == NULL)
+            {
+                dr.iter = IterInit (&fi->template[i + 1], num);
+                (void)ChainMgrSetData (&fi->cm, i, dr);
+                return FmSuccess;
+            }
+            /*endif*/
+            if (IterSetIterCount (d->iter, num) == FmSuccess)
+                return FmSuccess;
+            /*endif*/
+            break;
+            
+        case POINTER:
+            if ((d = ChainMgrGetExtraData (&fi->cm, i)) == NULL)
+            {
+                dr.fi = FrameInstInit (fi->template[i + 1].data);
+                d = ChainMgrSetData (&fi->cm, i, dr);
+            }
+            /*endif*/
+            if (FrameInstSetIterCount (d->fi, num) == FmSuccess)
+                return FmSuccess;
+            /*endif*/
+            break;
+
+       default:
+           break;
+        }
+        /*endswitch*/
+        i = _FrameInstIncrement (fi->template, i);
+    }
+    /*endwhile*/
+    return FmNoMoreData;
+}
+
+static int FrameInstGetTotalSize (FrameInst fi)
+{
+    register int size;
+    register int i;
+
+    size = 0;
+    i = 0;
+
+    while (fi->template[i].type != EOL)
+    {
+        size += _FrameInstGetItemSize (fi, i);
+        i = _FrameInstIncrement (fi->template, i);
+    }
+    /*endwhile*/
+    return size;
+}
+
+static void FrameInstReset (FrameInst fi)
+{
+    ChainIterRec ci;
+    int frame_no;
+    ExtraDataRec d;
+
+    ChainIterInit (&ci, &fi->cm);
+
+    while (ChainIterGetNext (&ci, &frame_no, &d))
+    {
+        register XimFrameType type;
+        type = fi->template[frame_no].type;
+        if (type == ITER)
+        {
+            if (d.iter)
+                IterReset (d.iter);
+            /*endif*/
+        }
+        else if (type == POINTER)
+        {
+            if (d.fi)
+                FrameInstReset (d.fi);
+            /*endif*/
+        }
+        /*endif*/
+    }
+    /*endwhile*/
+    ChainIterFree (&ci);
+
+    fi->cur_no = 0;
+}
+
+static Iter IterInit (XimFrame frame, int count)
+{
+    Iter it;
+    register XimFrameType type;
+
+    it = (Iter) Xmalloc (sizeof (IterRec));
+    it->template = frame;
+    it->max_count = (count == NO_VALUE)  ?  0  :  count;
+    it->allow_expansion = (count == NO_VALUE);
+    it->cur_no = 0;
+    it->start_watch_proc = NULL;
+    it->client_data = NULL;
+    it->start_counter = False;
+
+    type = frame->type;
+    if (type & COUNTER_MASK)
+    {
+        /* COUNTER_XXX cannot be an item of a ITER */
+        Xfree (it);
+        return NULL;
+    }
+    /*endif*/
+
+    switch (type)
+    {
+    case BIT8:
+    case BIT16:
+    case BIT32:
+    case BIT64:
+        /* Do nothing */
+        break;
+        
+    case BARRAY:
+    case ITER:
+    case POINTER:
+        ChainMgrInit (&it->cm);
+        break;
+        
+    default:
+        Xfree (it);
+        return NULL; /* This should never occur */
+    }
+    /*endswitch*/
+    return it;
+}
+
+static void IterFree (Iter it)
+{
+    switch (it->template->type)
+    {
+    case BARRAY:
+        ChainMgrFree (&it->cm);
+        break;
+    
+    case ITER:
+        {
+            ChainIterRec ci;
+            int count;
+            ExtraDataRec d;
+
+            ChainIterInit (&ci, &it->cm);
+            while (ChainIterGetNext (&ci, &count, &d))
+                IterFree (d.iter);
+            /*endwhile*/
+            ChainIterFree (&ci);
+            ChainMgrFree (&it->cm);
+        }
+        break;
+    
+    case POINTER:
+        {
+            ChainIterRec ci;
+            int count;
+            ExtraDataRec dr;
+    
+            ChainIterInit (&ci, &it->cm);
+            while (ChainIterGetNext (&ci, &count, &dr))
+                FrameInstFree (dr.fi);
+            /*endwhile*/
+            ChainIterFree (&ci);
+            ChainMgrFree (&it->cm);
+        }
+        break;
+
+    default:
+       break;
+    }
+    /*endswitch*/
+    Xfree (it);
+}
+
+static Bool IterIsLoopEnd (Iter it, Bool *myself)
+{
+    Bool ret = False;
+    *myself = False;
+
+    if (!it->allow_expansion  &&  (it->cur_no == it->max_count))
+    {
+        *myself = True;
+        return True;
+    }
+    /*endif*/
+    
+    if (it->template->type == POINTER)
+    {
+        ExtraData d = ChainMgrGetExtraData (&it->cm, it->cur_no);
+        if (d)
+        {
+            if (FrameInstIsIterLoopEnd (d->fi))
+            {
+                ret = True;
+            }
+            else
+            {
+                if (FrameInstIsEnd (d->fi))
+                {
+                    it->cur_no++;
+                    if (!it->allow_expansion  &&  it->cur_no == it->max_count)
+                    {
+                        *myself = True;
+                        ret = True;
+                    }
+                    /*endif*/
+                }
+                /*endif*/
+            }
+            /*endif*/
+        }
+        /*endif*/
+    }
+    else if (it->template->type == ITER)
+    {
+        ExtraData d = ChainMgrGetExtraData (&it->cm, it->cur_no);
+        if (d)
+        {
+            Bool yourself;
+            
+            if (IterIsLoopEnd (d->iter, &yourself))
+                ret = True;
+            /*endif*/
+        }
+        /*endif*/
+    }
+    /*endif*/
+
+    return ret;
+}
+
+static XimFrameType IterGetNextType (Iter it, XimFrameTypeInfo info)
+{
+    XimFrameType type = it->template->type;
+
+    if (it->start_counter)
+    {
+        (*it->start_watch_proc) (it, it->client_data);
+        it->start_counter = False;
+    }
+    /*endif*/
+    if (it->cur_no >= it->max_count)
+    {
+        if (it->allow_expansion)
+            it->max_count = it->cur_no + 1;
+        else
+            return EOL;
+        /*endif*/
+    }
+    /*endif*/
+
+    switch (type)
+    {
+    case BIT8:
+    case BIT16:
+    case BIT32:
+    case BIT64:
+        it->cur_no++;
+        return type;
+
+    case BARRAY:
+        if (info)
+        {
+            ExtraData d;
+    
+            if ((d = ChainMgrGetExtraData (&it->cm, it->cur_no)) == NULL)
+                info->num = NO_VALUE;
+            else
+                info->num = d->num;
+            /*endif*/
+        }
+        /*endif*/
+        it->cur_no++;
+        return BARRAY;
+
+    case ITER:
+        {
+            XimFrameType ret_type;
+            ExtraData d;
+            ExtraDataRec dr;
+
+            if ((d = ChainMgrGetExtraData (&it->cm, it->cur_no)) == NULL)
+            {
+                dr.iter = IterInit (it->template + 1, NO_VALUE);
+                d = ChainMgrSetData (&it->cm, it->cur_no, dr);
+            }
+            /*endif*/
+
+            ret_type = IterGetNextType (d->iter, info);
+            if (ret_type == EOL)
+            {
+                it->cur_no++;
+                ret_type = IterGetNextType (it, info);
+            }
+            /*endif*/
+           return ret_type;
+        }
+
+    case POINTER:
+        {
+            XimFrameType ret_type;
+            ExtraData d;
+            ExtraDataRec dr;
+
+            if ((d = ChainMgrGetExtraData (&it->cm, it->cur_no)) == NULL)
+            {
+                dr.fi = FrameInstInit (it->template[1].data);
+                d = ChainMgrSetData (&it->cm, it->cur_no, dr);
+            }
+            /*endif*/
+
+            ret_type = FrameInstGetNextType (d->fi, info);
+            if (ret_type == EOL)
+            {
+                it->cur_no++;
+                ret_type = IterGetNextType (it, info);
+            }
+            /*endif*/
+           return ret_type;
+        }
+
+    default:
+       return (XimFrameType) NULL;
+    }
+    /*endswitch*/
+    return (XimFrameType) NULL;  /* This should never occur */
+}
+
+static XimFrameType IterPeekNextType (Iter it, XimFrameTypeInfo info)
+{
+    XimFrameType type = it->template->type;
+
+    if (!it->allow_expansion  &&  it->cur_no >= it->max_count)
+        return (EOL);
+    /*endif*/
+    
+    switch (type)
+    {
+    case BIT8:
+    case BIT16:
+    case BIT32:
+    case BIT64:
+        return type;
+
+    case BARRAY:
+        if (info)
+        {
+            ExtraData d;
+
+            if ((d = ChainMgrGetExtraData (&it->cm, it->cur_no)) == NULL)
+                info->num = NO_VALUE;
+            else
+                info->num = d->num;
+            /*endif*/
+        }
+        /*endif*/
+        return BARRAY;
+    
+    case ITER:
+        {
+            XimFrameType ret_type;
+            ExtraData d;
+            ExtraDataRec dr;
+
+            if ((d = ChainMgrGetExtraData (&it->cm, it->cur_no)) == NULL)
+            {
+                dr.iter = IterInit (it->template + 1, NO_VALUE);
+                d = ChainMgrSetData (&it->cm, it->cur_no, dr);
+            }
+            /*endif*/
+
+            ret_type = IterPeekNextType (d->iter, info);
+            if (ret_type == EOL)
+                ret_type = IterPeekNextType (it, info);
+            /*endif*/
+            return ret_type;
+        }
+        
+    case POINTER:
+        {
+            XimFrameType ret_type;
+            ExtraData d;
+            ExtraDataRec dr;
+
+            if ((d = ChainMgrGetExtraData (&it->cm, it->cur_no)) == NULL)
+            {
+                dr.fi = FrameInstInit (it->template[1].data);
+                d = ChainMgrSetData (&it->cm, it->cur_no, dr);
+            }
+            /*endif*/
+
+            ret_type = FrameInstPeekNextType (d->fi, info);
+            if (ret_type == EOL)
+                ret_type = IterPeekNextType (it, info);
+            /*endif*/
+            return (ret_type);
+        }
+
+    default:
+       break;
+    }
+    /*endswitch*/
+    /* Reaching here is a bug! */
+    return (XimFrameType) NULL;
+}
+
+static FmStatus IterSetSize (Iter it, int num)
+{
+    XimFrameType type;
+    register int i;
+
+    if (!it->allow_expansion  &&  it->max_count == 0)
+        return FmNoMoreData;
+    /*endif*/
+    
+    type = it->template->type;
+    switch (type)
+    {
+    case BARRAY:
+        {
+            ExtraData d;
+            ExtraDataRec dr;
+
+            for (i = 0;  i < it->max_count;  i++)
+            {
+                if ((d = ChainMgrGetExtraData (&it->cm, i)) == NULL)
+                {
+                    dr.num = NO_VALUE;
+                    d = ChainMgrSetData (&it->cm, i, dr);
+                }
+                /*endif*/
+                if (d->num == NO_VALUE)
+                {
+                    d->num = num;
+                    return FmSuccess;
+                }
+                /*endif*/
+            }
+            /*endfor*/
+            if (it->allow_expansion)
+            {
+                ExtraDataRec dr;
+                
+                dr.num = num;
+                ChainMgrSetData (&it->cm, it->max_count, dr);
+                it->max_count++;
+    
+                return FmSuccess;
+            }
+            /*endif*/
+        }   
+        return FmNoMoreData;
+
+    case ITER:
+        {
+            ExtraData d;
+            ExtraDataRec dr;
+
+            for (i = 0;  i < it->max_count;  i++)
+            {
+                if ((d = ChainMgrGetExtraData (&it->cm, i)) == NULL)
+                {
+                    dr.iter = IterInit (it->template + 1, NO_VALUE);
+                    d = ChainMgrSetData (&it->cm, i, dr);
+                }
+                /*endif*/
+                if (IterSetSize (d->iter, num) == FmSuccess)
+                    return FmSuccess;
+                /*endif*/
+            }
+            /*endfor*/
+            if (it->allow_expansion)
+            {
+                ExtraDataRec dr;
+
+                dr.iter = IterInit (it->template + 1, NO_VALUE);
+                ChainMgrSetData (&it->cm, it->max_count, dr);
+                it->max_count++;
+
+                if (IterSetSize(dr.iter, num) == FmSuccess)
+                    return FmSuccess;
+                /*endif*/
+            }
+            /*endif*/
+        }
+        return FmNoMoreData;
+
+    case POINTER:
+        {
+            ExtraData d;
+            ExtraDataRec dr;
+
+            for (i = 0;  i < it->max_count;  i++)
+            {
+                if ((d = ChainMgrGetExtraData (&it->cm, i)) == NULL)
+                {
+                    dr.fi = FrameInstInit (it->template[1].data);
+                    d = ChainMgrSetData (&it->cm, i, dr);
+                }
+                /*endif*/
+                if (FrameInstSetSize (d->fi, num) == FmSuccess)
+                    return FmSuccess;
+                /*endif*/
+            }
+            /*endfor*/
+            if (it->allow_expansion)
+            {
+                ExtraDataRec dr;
+
+                dr.fi = FrameInstInit (it->template[1].data);
+                ChainMgrSetData (&it->cm, it->max_count, dr);
+                it->max_count++;
+
+                if (FrameInstSetSize (dr.fi, num) == FmSuccess)
+                    return FmSuccess;
+                /*endif*/
+            }
+            /*endif*/
+        }
+        return FmNoMoreData;
+
+    default:
+       break;
+    }
+    /*endswitch*/
+    return FmNoMoreData;
+}
+
+static int IterGetSize (Iter it)
+{
+    register int i;
+    ExtraData d;
+    ExtraDataRec dr;
+
+    if (it->cur_no >= it->max_count)
+        return NO_VALID_FIELD;
+    /*endif*/
+    
+    switch (it->template->type)
+    {
+    case BARRAY:
+        if ((d = ChainMgrGetExtraData (&it->cm, it->cur_no)) == NULL)
+            return NO_VALUE;
+        /*endif*/
+        return d->num;
+
+    case ITER:
+        for (i = it->cur_no; i < it->max_count; i++)
+        {
+            int ret_size;
+
+            if ((d = ChainMgrGetExtraData (&it->cm, i)) == NULL)
+            {
+                dr.iter = IterInit (it->template + 1, NO_VALUE);
+                d = ChainMgrSetData (&it->cm, i, dr);
+            }
+            /*endif*/
+            ret_size = IterGetSize (d->iter);
+            if (ret_size != NO_VALID_FIELD)
+                return ret_size;
+            /*endif*/
+        }
+        /*endfor*/
+        return NO_VALID_FIELD;
+    
+    case POINTER:
+        for (i = it->cur_no;  i < it->max_count;  i++)
+        {
+            int ret_size;
+            
+            if ((d = ChainMgrGetExtraData (&it->cm, i)) == NULL)
+            {
+                dr.fi = FrameInstInit (it->template[1].data);
+                d = ChainMgrSetData (&it->cm, i, dr);
+            }
+            /*endif*/
+            ret_size = FrameInstGetSize (d->fi);
+            if (ret_size != NO_VALID_FIELD)
+                return ret_size;
+            /*endif*/
+        }
+        /*endfor*/
+        return NO_VALID_FIELD;
+
+    default:
+       break;
+    }
+    /*endswitch*/
+    return NO_VALID_FIELD;
+}
+
+static FmStatus IterSetIterCount (Iter it, int num)
+{
+    register int i;
+
+    if (it->allow_expansion)
+    {
+        it->max_count = num;
+        it->allow_expansion = False;
+        return FmSuccess;
+    }
+    /*endif*/
+
+    if (it->max_count == 0)
+        return FmNoMoreData;
+    /*endif*/
+
+    switch (it->template->type)
+    {
+    case ITER:
+        for (i = 0;  i < it->max_count;  i++)
+        {
+            ExtraData d;
+            ExtraDataRec dr;
+
+            if ((d = ChainMgrGetExtraData(&it->cm, i)) == NULL)
+            {
+                dr.iter = IterInit(it->template + 1, num);
+                (void)ChainMgrSetData(&it->cm, i, dr);
+                return FmSuccess;
+            }
+            /*endif*/
+            if (IterSetIterCount(d->iter, num) == FmSuccess)
+                return FmSuccess;
+            /*endif*/
+        }
+        /*endfor*/
+        if (it->allow_expansion)
+        {
+            ExtraDataRec dr;
+
+            dr.iter = IterInit (it->template + 1, num);
+            ChainMgrSetData (&it->cm, it->max_count, dr);
+            it->max_count++;
+
+            return FmSuccess;
+        }
+        /*endif*/
+        break;
+    
+    case POINTER:
+        for (i = 0;  i < it->max_count;  i++)
+        {
+            ExtraData d;
+            ExtraDataRec dr;
+            
+            if ((d = ChainMgrGetExtraData (&it->cm, i)) == NULL)
+            {
+                dr.fi = FrameInstInit (it->template[1].data);
+                d = ChainMgrSetData (&it->cm, i, dr);
+            }
+            /*endif*/
+            if (FrameInstSetIterCount (d->fi, num) == FmSuccess)
+                return FmSuccess;
+            /*endif*/
+        }
+        /*endfor*/
+        if (it->allow_expansion)
+        {
+            ExtraDataRec dr;
+            
+            dr.fi = FrameInstInit (it->template[1].data);
+            ChainMgrSetData (&it->cm, it->max_count, dr);
+            it->max_count++;
+
+            if (FrameInstSetIterCount (dr.fi, num) == FmSuccess)
+                return FmSuccess;
+            /*endif*/
+        }
+        /*endif*/
+        break;
+
+    default:
+       break;
+    }
+    /*endswitch*/
+    return FmNoMoreData;
+}
+
+static int IterGetTotalSize (Iter it)
+{
+    register int size, i;
+    XimFrameType type;
+
+    if (it->allow_expansion)
+        return NO_VALUE;
+    /*endif*/
+    if (it->max_count == 0)
+        return 0;
+    /*endif*/
+
+    size = 0;
+    type = it->template->type;
+
+    switch (type)
+    {
+    case BIT8:
+        size = it->max_count;
+        break;
+
+    case BIT16:
+        size = it->max_count*2;
+        break;
+
+    case BIT32:
+        size = it->max_count*4;
+        break;
+
+    case BIT64:
+        size = it->max_count*8;
+        break;
+
+    case BARRAY:
+        for (i = 0;  i < it->max_count;  i++)
+        {
+            register int num;
+            ExtraData d;
+            
+            if ((d = ChainMgrGetExtraData (&it->cm, i)) == NULL)
+                return  NO_VALUE;
+            /*endif*/
+            if ((num = d->num) == NO_VALUE)
+                return  NO_VALUE;
+            /*endif*/
+            size += num;
+        }
+        /*endfor*/
+        break;
+        
+    case ITER:
+        for (i = 0;  i < it->max_count;  i++)
+        {
+            register int num;
+            ExtraData d;
+            
+            if ((d = ChainMgrGetExtraData (&it->cm, i)) == NULL)
+                return  NO_VALUE;
+            /*endif*/
+            if ((num = IterGetTotalSize (d->iter)) == NO_VALUE)
+                return  NO_VALUE;
+            /*endif*/
+            size += num;
+        }
+        /*endfor*/
+        break;
+        
+    case POINTER:
+        for (i = 0;  i < it->max_count;  i++)
+        {
+            register int num;
+            ExtraData d;
+            ExtraDataRec dr;
+            
+            if ((d = ChainMgrGetExtraData (&it->cm, i)) == NULL)
+            {
+                dr.fi = FrameInstInit (it->template[1].data);
+                d = ChainMgrSetData (&it->cm, i, dr);
+            }
+            /*endif*/
+            if ((num = FrameInstGetTotalSize (d->fi)) == NO_VALUE)
+                return NO_VALUE;
+            /*endif*/
+            size += num;
+        }
+        /*endfor*/
+        break;
+
+    default:
+       break;
+    }
+    /*endswitch*/
+    return  size;
+}
+
+static void IterReset (Iter it)
+{
+    ChainIterRec ci;
+    int count;
+    ExtraDataRec d;
+
+    switch (it->template->type)
+    {
+    case ITER:
+        ChainIterInit (&ci, &it->cm);
+        while (ChainIterGetNext (&ci, &count, &d))
+            IterReset (d.iter);
+        /*endwhile*/
+        ChainIterFree (&ci);
+        break;
+  
+    case POINTER:
+        ChainIterInit (&ci, &it->cm);
+        while (ChainIterGetNext (&ci, &count, &d))
+            FrameInstReset (d.fi);
+        /*endwhile*/
+        ChainIterFree (&ci);
+        break;
+
+    default:
+       break;
+    }
+    /*endswitch*/
+    it->cur_no = 0;
+}
+
+static void IterSetStartWatch (Iter it,
+                               IterStartWatchProc proc,
+                               void *client_data)
+{
+    it->start_watch_proc = proc;
+    it->client_data = client_data;
+}
+
+static ExtraData ChainMgrSetData (ChainMgr cm,
+                                  int frame_no,
+                                  ExtraDataRec data)
+{
+    Chain cur = (Chain) Xmalloc (sizeof (ChainRec));
+
+    cur->frame_no = frame_no;
+    cur->d = data;
+    cur->next = NULL;
+
+    if (cm->top == NULL)
+    {
+        cm->top = cm->tail = cur;
+    }
+    else
+    {
+        cm->tail->next = cur;
+        cm->tail = cur;
+    }
+    /*endif*/
+    return &cur->d;
+}
+
+static ExtraData ChainMgrGetExtraData (ChainMgr cm, int frame_no)
+{
+    Chain cur;
+
+    cur = cm->top;
+
+    while (cur)
+    {
+        if (cur->frame_no == frame_no)
+            return &cur->d;
+        /*endif*/
+        cur = cur->next;
+    }
+    /*endwhile*/
+    return NULL;
+}
+
+static Bool ChainIterGetNext (ChainIter ci, int *frame_no, ExtraData d)
+{
+    if (ci->cur == NULL)
+        return False;
+    /*endif*/
+    
+    *frame_no = ci->cur->frame_no;
+    *d = ci->cur->d;
+
+    ci->cur = ci->cur->next;
+
+    return True;
+}
+
+static int _FrameInstIncrement (XimFrame frame, int count)
+{
+    XimFrameType type;
+
+    type = frame[count].type;
+    type &= ~COUNTER_MASK;
+
+    switch (type)
+    {
+    case BIT8:
+    case BIT16:
+    case BIT32:
+    case BIT64:
+    case BARRAY:
+    case PADDING:
+        return count + 1;
+        
+    case POINTER:
+        return count + 2;
+        
+    case ITER:
+        return _FrameInstIncrement (frame, count + 1);
+    default:
+       break;
+    }
+    /*endswitch*/
+    return - 1;    /* Error */
+}
+
+static int _FrameInstDecrement (XimFrame frame, int count)
+{
+    register int i;
+    XimFrameType type;
+
+    if (count == 0)
+        return - 1;    /* cannot decrement */
+    /*endif*/
+    
+    if (count == 1)
+        return 0;     /* BOGUS - It should check the contents of data */
+    /*endif*/
+    
+    type = frame[count - 2].type;
+    type &= ~COUNTER_MASK;
+
+    switch (type)
+    {
+    case BIT8:
+    case BIT16:
+    case BIT32:
+    case BIT64:
+    case BARRAY:
+    case PADDING:
+    case PTR_ITEM:
+        return count - 1;
+
+    case POINTER:
+    case ITER:
+        i = count - 3;
+        while (i >= 0)
+        {
+            if (frame[i].type != ITER)
+                return i + 1;
+            /*endif*/
+            i--;
+        }
+        /*endwhile*/
+        return 0;
+    default:
+       break;
+    }
+    /*enswitch*/
+    return - 1;    /* Error */
+}
+
+static int _FrameInstGetItemSize (FrameInst fi, int cur_no)
+{
+    XimFrameType type;
+
+    type = fi->template[cur_no].type;
+    type &= ~COUNTER_MASK;
+
+    switch (type)
+    {
+    case BIT8:
+        return 1;
+
+    case BIT16:
+        return 2;
+
+    case BIT32:
+        return 4;
+
+    case BIT64:
+        return 8;
+
+    case BARRAY:
+        {
+            ExtraData d;
+
+            if ((d = ChainMgrGetExtraData (&fi->cm, cur_no)) == NULL)
+                return NO_VALUE;
+            /*endif*/
+            if (d->num == NO_VALUE)
+                return NO_VALUE;
+            /*endif*/
+            return d->num;
+        }
+
+    case PADDING:
+        {
+            register int unit;
+            register int number;
+            register int size;
+            register int i;
+
+            unit = _UNIT ((long) fi->template[cur_no].data);
+            number = _NUMBER ((long) fi->template[cur_no].data);
+
+            i = cur_no;
+            size = 0;
+            while (number > 0)
+            {
+                i = _FrameInstDecrement (fi->template, i);
+                size += _FrameInstGetItemSize (fi, i);
+                number--;
+            }
+            /*endwhile*/
+            size = (unit - (size%unit))%unit;
+            return size;
+        }
+
+    case ITER:
+        {
+            ExtraData d;
+            int sub_size;
+
+            if ((d = ChainMgrGetExtraData (&fi->cm, cur_no)) == NULL)
+                return NO_VALUE;
+            /*endif*/
+            sub_size = IterGetTotalSize (d->iter);
+            if (sub_size == NO_VALUE)
+                return NO_VALUE;
+            /*endif*/
+            return sub_size;
+        }
+
+    case POINTER:
+        {
+            ExtraData d;
+            int sub_size;
+
+            if ((d = ChainMgrGetExtraData (&fi->cm, cur_no)) == NULL)
+                return NO_VALUE;
+            /*endif*/
+            sub_size = FrameInstGetTotalSize (d->fi);
+            if (sub_size == NO_VALUE)
+                return NO_VALUE;
+            /*endif*/
+            return sub_size;
+        }
+
+    default:
+       break;
+    }
+    /*endswitch*/
+    return NO_VALUE;
+}
diff --git a/client/x11/IMdkit/FrameMgr.h b/client/x11/IMdkit/FrameMgr.h
new file mode 100644 (file)
index 0000000..ce7ed50
--- /dev/null
@@ -0,0 +1,131 @@
+/******************************************************************
+Copyright 1993, 1994 by Digital Equipment Corporation, Maynard, Massachusetts,
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the names of Digital or MIT not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+  Author: Hiroyuki Miyamoto  Digital Equipment Corporation
+                             miyamoto@jrd.dec.com
+
+    This version tidied and debugged by Steve Underwood May 1999
+
+******************************************************************/
+
+#ifndef FRAMEMGR_H
+#define FRAMEMGR_H
+
+#include <X11/Xmd.h>
+#include <X11/Xlib.h>
+#include <stdio.h>
+
+#if defined(VAXC) && !defined(__DECC)
+#define xim_externalref globalref
+#define xim_externaldef globaldef
+#else
+#define xim_externalref extern
+#define xim_externaldef
+#endif
+
+/* Definitions for FrameMgr */
+
+#define COUNTER_MASK 0x10
+
+typedef enum
+{
+    BIT8     = 0x1,       /* {CARD8* | INT8*}   */
+    BIT16    = 0x2,       /* {CARD16* | INT16*} */
+    BIT32    = 0x3,       /* {CARD32* | INT32*} */
+    BIT64    = 0x4,      /* {CARD64* | INT64*} */
+    BARRAY   = 0x5,       /* int*, void*        */
+    ITER     = 0x6,       /* int*               */
+    POINTER  = 0x7,       /* specifies next item is a PTR_ITEM */
+    PTR_ITEM = 0x8,       /* specifies the item has a pointer */
+    /* BOGUS - POINTER and PTR_ITEM
+     *   In the current implementation, PTR_ITEM should be lead by
+     *   POINTER.  But actually, it's just redundant logically.  Someone 
+     *   may remove this redundancy and POINTER from the enum member but he
+     *   should also modify the logic in FrameMgr program.
+     */
+    PADDING  = 0x9,       /* specifies that a padding is needed.
+                          * This requires extra data in data field.
+                          */
+    EOL      = 0xA,       /* specifies the end of list */
+
+    COUNTER_BIT8  = COUNTER_MASK | 0x1,
+    COUNTER_BIT16 = COUNTER_MASK | 0x2,
+    COUNTER_BIT32 = COUNTER_MASK | 0x3,
+    COUNTER_BIT64 = COUNTER_MASK | 0x4
+} XimFrameType;
+
+/* Convenient macro */
+#define _FRAME(a) {a, NULL}
+#define _PTR(p)   {PTR_ITEM, (void *)p}
+/* PADDING's usage of data field
+ * B15-B8  : Shows the number of effective items.
+ * B7-B0   : Shows padding unit.  ex) 04 shows 4 unit padding.
+ */
+#define _PAD2(n)   {PADDING, (void*)((n)<<8|2)}
+#define _PAD4(n)   {PADDING, (void*)((n)<<8|4)}
+
+#define FmCounterByte 0
+#define FmCounterNumber 1
+    
+#define _BYTE_COUNTER(type, offset) \
+               {(COUNTER_MASK|type), (void*)((offset)<<8|FmCounterByte)}
+
+#define _NUMBER_COUNTER(type, offset) \
+               {(COUNTER_MASK|type), (void*)((offset)<<8|FmCounterNumber)}
+
+typedef struct _XimFrame
+{
+    XimFrameType type;
+    void* data;       /* For PTR_ITEM and PADDING */
+} XimFrameRec, *XimFrame;
+
+typedef enum
+{
+    FmSuccess, 
+    FmEOD,
+    FmInvalidCall,
+    FmBufExist,
+    FmCannotCalc,
+    FmNoMoreData
+} FmStatus;
+
+typedef struct _FrameMgr *FrameMgr;
+
+FrameMgr FrameMgrInit(XimFrame frame, char* area, Bool byte_swap);
+void FrameMgrInitWithData(FrameMgr fm, XimFrame frame, void* area,
+                         Bool byte_swap);
+void FrameMgrFree(FrameMgr fm);
+FmStatus FrameMgrSetBuffer(FrameMgr, void*);
+FmStatus _FrameMgrPutToken(FrameMgr, void*, int);
+FmStatus _FrameMgrGetToken(FrameMgr, void*, int);
+FmStatus FrameMgrSetSize(FrameMgr, int);
+FmStatus FrameMgrSetIterCount(FrameMgr, int);
+FmStatus FrameMgrSetTotalSize(FrameMgr, int);
+int FrameMgrGetTotalSize(FrameMgr);
+int FrameMgrGetSize(FrameMgr);
+FmStatus FrameMgrSkipToken(FrameMgr, int);
+void FrameMgrReset(FrameMgr);
+Bool FrameMgrIsIterLoopEnd(FrameMgr, FmStatus*);
+
+#define FrameMgrPutToken(fm, obj) _FrameMgrPutToken((fm), &(obj), sizeof(obj))
+#define FrameMgrGetToken(fm, obj) _FrameMgrGetToken((fm), &(obj), sizeof(obj))
+
+#endif /* FRAMEMGR_H */
diff --git a/client/x11/IMdkit/IMConn.c b/client/x11/IMdkit/IMConn.c
new file mode 100644 (file)
index 0000000..6d36589
--- /dev/null
@@ -0,0 +1,176 @@
+/******************************************************************
+         Copyright 1994, 1995 by Sun Microsystems, Inc.
+         Copyright 1993, 1994 by Hewlett-Packard Company
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear
+in supporting documentation, and that the name of Sun Microsystems, Inc.
+and Hewlett-Packard not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior permission.
+Sun Microsystems, Inc. and Hewlett-Packard make no representations about
+the suitability of this software for any purpose.  It is provided "as is"
+without express or implied warranty.
+SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL
+WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+  Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
+
+    This version tidied and debugged by Steve Underwood May 1999
+******************************************************************/
+
+#include <X11/Xlib.h>
+#include <stdlib.h>
+#include <string.h>
+#include "IMdkit.h"
+#include <stdarg.h>
+
+#define Va_start(a,b) va_start(a,b)
+
+static void _IMCountVaList(va_list var, int *total_count)
+{
+    char *attr;
+
+    *total_count = 0;
+
+    for (attr = va_arg (var, char*);  attr;  attr = va_arg (var, char*))
+    {
+       (void)va_arg (var, XIMArg *);
+       ++(*total_count);
+    }
+    /*endfor*/
+}
+
+static void _IMVaToNestedList(va_list var, int max_count, XIMArg **args_return)
+{
+    XIMArg *args;
+    char   *attr;
+
+    if (max_count <= 0)
+    {
+       *args_return = (XIMArg *) NULL;
+       return;
+    }
+    /*endif*/
+
+    args = (XIMArg *) malloc ((unsigned) (max_count + 1)*sizeof (XIMArg));
+    *args_return = args;
+    if (!args)
+        return;
+    /*endif*/
+
+    for (attr = va_arg (var, char*);  attr;  attr = va_arg (var, char *))
+    {
+       args->name = attr;
+       args->value = va_arg (var, XPointer);
+       args++;
+    }
+    /*endfor*/
+    args->name = (char*)NULL;
+}
+
+static char *_FindModifiers (XIMArg *args)
+{
+    char *modifiers;
+
+    while (args->name)
+    {
+       if (strcmp (args->name, IMModifiers) == 0)
+       {
+           modifiers = args->value;
+           return modifiers;
+       }
+       else
+       {
+           args++;
+       }
+       /*endif*/
+    }
+    /*endwhile*/
+    return NULL;
+}
+
+XIMS _GetIMS (char *modifiers)
+{
+    XIMS ims;
+    extern IMMethodsRec Xi18n_im_methods;
+
+    if ((ims = (XIMS) malloc (sizeof (XIMProtocolRec))) == (XIMS) NULL)
+       return ((XIMS) NULL);
+    /*endif*/
+    memset ((void *) ims, 0, sizeof (XIMProtocolRec));
+
+    if (modifiers == NULL
+       ||
+       modifiers[0] == '\0'
+       ||
+       strcmp (modifiers, "Xi18n") == 0)
+    {
+       ims->methods = &Xi18n_im_methods;
+       return ims;
+    }
+    /*endif*/
+    XFree (ims);
+    return (XIMS) NULL;
+}
+
+XIMS IMOpenIM (Display *display, ...)
+{
+    va_list var;
+    int total_count;
+    XIMArg *args;
+    XIMS ims;
+    char *modifiers;
+    Status ret;
+
+    Va_start (var, display);
+    _IMCountVaList (var, &total_count);
+    va_end (var);
+
+    Va_start (var, display);
+    _IMVaToNestedList (var, total_count, &args);
+    va_end (var);
+
+    modifiers = _FindModifiers (args);
+
+    ims = _GetIMS (modifiers);
+    if (ims == (XIMS) NULL)
+        return (XIMS) NULL;
+    /*endif*/
+    
+    ims->core.display = display;
+
+    ims->protocol = (*ims->methods->setup) (display, args);
+    XFree (args);
+    if (ims->protocol == (void *) NULL)
+    {
+       XFree (ims);
+       return (XIMS) NULL;
+    }
+    /*endif*/
+    ret = (ims->methods->openIM) (ims);
+    if (ret == False)
+    {
+       XFree (ims);
+       return (XIMS) NULL;
+    }
+    /*endif*/
+    return (XIMS) ims;
+}
+
+Status IMCloseIM (XIMS ims)
+{
+    (ims->methods->closeIM) (ims);
+    XFree (ims);
+    return True;
+}
diff --git a/client/x11/IMdkit/IMMethod.c b/client/x11/IMdkit/IMMethod.c
new file mode 100644 (file)
index 0000000..5a33878
--- /dev/null
@@ -0,0 +1,65 @@
+/******************************************************************
+         Copyright 1994, 1995 by Sun Microsystems, Inc.
+         Copyright 1993, 1994 by Hewlett-Packard Company
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear
+in supporting documentation, and that the name of Sun Microsystems, Inc.
+and Hewlett-Packard not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior permission.
+Sun Microsystems, Inc. and Hewlett-Packard make no representations about
+the suitability of this software for any purpose.  It is provided "as is"
+without express or implied warranty.
+SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL
+WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+  Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
+
+    This version tidied and debugged by Steve Underwood May 1999
+******************************************************************/
+
+#include <X11/Xlib.h>
+#include "IMdkit.h"
+
+/* Public Function */
+void IMForwardEvent (XIMS ims, XPointer call_data)
+{
+    (ims->methods->forwardEvent) (ims, call_data);
+}
+
+void IMCommitString (XIMS ims, XPointer call_data)
+{
+    (ims->methods->commitString) (ims, call_data);
+}
+
+int IMCallCallback (XIMS ims, XPointer call_data)
+{
+    return (ims->methods->callCallback) (ims, call_data);
+}
+
+int IMPreeditStart (XIMS ims, XPointer call_data)
+{
+    return (ims->methods->preeditStart) (ims, call_data);
+}
+
+int IMPreeditEnd (XIMS ims, XPointer call_data)
+{
+    return (ims->methods->preeditEnd) (ims, call_data);
+}
+
+int IMSyncXlib(XIMS ims, XPointer call_data)
+{
+    ims->sync = True;
+    return (ims->methods->syncXlib) (ims, call_data);
+}
diff --git a/client/x11/IMdkit/IMValues.c b/client/x11/IMdkit/IMValues.c
new file mode 100644 (file)
index 0000000..687014a
--- /dev/null
@@ -0,0 +1,124 @@
+/******************************************************************
+         Copyright 1994, 1995 by Sun Microsystems, Inc.
+         Copyright 1993, 1994 by Hewlett-Packard Company
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear
+in supporting documentation, and that the name of Sun Microsystems, Inc.
+and Hewlett-Packard not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior permission.
+Sun Microsystems, Inc. and Hewlett-Packard make no representations about
+the suitability of this software for any purpose.  It is provided "as is"
+without express or implied warranty.
+SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL
+WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+  Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
+
+    This version tidied and debugged by Steve Underwood May 1999
+******************************************************************/
+
+#include <stdlib.h>
+#include <X11/Xlib.h>
+#include "IMdkit.h"
+#include <stdarg.h>
+
+#define Va_start(a,b) va_start(a,b)
+
+static void _IMCountVaList (va_list var, int *total_count)
+{
+    char *attr;
+
+    *total_count = 0;
+
+    for (attr = va_arg (var, char *);  attr;  attr = va_arg (var, char *))
+    {
+       (void)va_arg (var, XIMArg *);
+       ++(*total_count);
+    }
+    /*endfor*/
+}
+
+static void _IMVaToNestedList (va_list var, int max_count, XIMArg **args_return)
+{
+    XIMArg *args;
+    char   *attr;
+
+    if (max_count <= 0)
+    {
+       *args_return = (XIMArg *) NULL;
+       return;
+    }
+    /*endif*/
+
+    args = (XIMArg *) malloc ((unsigned) (max_count + 1)*sizeof (XIMArg));
+    *args_return = args;
+    if (!args)
+        return;
+    /*endif*/
+    for (attr = va_arg (var, char *);  attr;  attr = va_arg (var, char *))
+    {
+       args->name = attr;
+       args->value = va_arg (var, XPointer);
+       args++;
+    }
+    /*endfor*/
+    args->name = (char *) NULL;
+}
+
+char *IMGetIMValues (XIMS ims, ...)
+{
+    va_list var;
+    int total_count;
+    XIMArg *args;
+    char *ret;
+
+    Va_start (var, ims);
+    _IMCountVaList (var, &total_count);
+    va_end (var);
+
+    Va_start (var, ims);
+    _IMVaToNestedList (var, total_count, &args);
+    va_end (var);
+
+    ret = (*ims->methods->getIMValues) (ims, args);
+
+    if (args)
+        XFree ((char *) args);
+    /*endif*/
+    return ret;
+}
+
+char *IMSetIMValues (XIMS ims, ...)
+{
+    va_list var;
+    int total_count;
+    XIMArg *args;
+    char *ret;  
+
+    Va_start (var, ims);
+    _IMCountVaList (var, &total_count);
+    va_end (var);
+
+    Va_start (var, ims);
+    _IMVaToNestedList (var, total_count, &args);
+    va_end (var);
+
+    ret = (*ims->methods->setIMValues) (ims, args);
+
+    if (args)
+        XFree ((char *) args);
+    /*endif*/
+    return ret;
+}
diff --git a/client/x11/IMdkit/IMdkit.h b/client/x11/IMdkit/IMdkit.h
new file mode 100644 (file)
index 0000000..6f8d673
--- /dev/null
@@ -0,0 +1,144 @@
+/******************************************************************
+         Copyright 1994, 1995 by Sun Microsystems, Inc.
+         Copyright 1993, 1994 by Hewlett-Packard Company
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear
+in supporting documentation, and that the name of Sun Microsystems, Inc.
+and Hewlett-Packard not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior permission.
+Sun Microsystems, Inc. and Hewlett-Packard make no representations about
+the suitability of this software for any purpose.  It is provided "as is"
+without express or implied warranty.
+SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL
+WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+  Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
+
+    This version tidied and debugged by Steve Underwood May 1999
+******************************************************************/
+
+#ifndef _IMdkit_h
+#define _IMdkit_h
+
+#include <X11/Xmd.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* IM Attributes Name */
+#define IMModifiers            "modifiers"
+#define IMServerWindow         "serverWindow"
+#define IMServerName           "serverName"
+#define IMServerTransport      "serverTransport"
+#define IMLocale               "locale"
+#define IMInputStyles          "inputStyles"
+#define IMProtocolHandler      "protocolHandler"
+#define IMOnKeysList           "onKeysList"
+#define IMOffKeysList          "offKeysList"
+#define IMEncodingList         "encodingList"
+#define IMFilterEventMask      "filterEventMask"
+#define IMProtocolDepend       "protocolDepend"
+
+/* Masks for IM Attributes Name */
+#define I18N_IMSERVER_WIN      0x0001 /* IMServerWindow */
+#define I18N_IM_NAME           0x0002 /* IMServerName */
+#define I18N_IM_LOCALE         0x0004 /* IMLocale */
+#define I18N_IM_ADDRESS                0x0008 /* IMServerTransport */
+#define I18N_INPUT_STYLES      0x0010 /* IMInputStyles */
+#define I18N_ON_KEYS           0x0020 /* IMOnKeysList */
+#define I18N_OFF_KEYS          0x0040 /* IMOffKeysList */
+#define I18N_IM_HANDLER                0x0080 /* IMProtocolHander */
+#define I18N_ENCODINGS         0x0100 /* IMEncodingList */
+#define I18N_FILTERMASK                0x0200 /* IMFilterEventMask */
+#define I18N_PROTO_DEPEND      0x0400 /* IMProtoDepend */
+
+typedef struct
+{
+    char       *name;
+    XPointer   value;
+} XIMArg;
+
+typedef struct
+{
+    CARD32     keysym;
+    CARD32     modifier;
+    CARD32     modifier_mask;
+} XIMTriggerKey;
+
+typedef struct
+{
+    unsigned short count_keys;
+    XIMTriggerKey *keylist;
+} XIMTriggerKeys;
+
+typedef char *XIMEncoding;
+
+typedef struct
+{
+    unsigned short count_encodings;
+    XIMEncoding *supported_encodings;
+} XIMEncodings;
+
+typedef struct _XIMS *XIMS;
+
+typedef struct
+{
+    void*      (*setup) (Display *, XIMArg *);
+    Status     (*openIM) (XIMS);
+    Status     (*closeIM) (XIMS);
+    char*      (*setIMValues) (XIMS, XIMArg *);
+    char*      (*getIMValues) (XIMS, XIMArg *);
+    Status     (*forwardEvent) (XIMS, XPointer);
+    Status     (*commitString) (XIMS, XPointer);
+    int                (*callCallback) (XIMS, XPointer);
+    int                (*preeditStart) (XIMS, XPointer);
+    int                (*preeditEnd) (XIMS, XPointer);
+    int                (*syncXlib) (XIMS, XPointer);
+} IMMethodsRec, *IMMethods;
+
+typedef struct
+{
+    Display    *display;
+    int                screen;
+} IMCoreRec, *IMCore;
+
+typedef struct _XIMS
+{
+    IMMethods  methods;
+    IMCoreRec  core;
+    Bool       sync;
+    void       *protocol;
+} XIMProtocolRec;
+
+/* 
+ * X function declarations.
+ */
+extern XIMS IMOpenIM (Display *, ...);
+extern Status IMCloseIM (XIMS);
+extern char *IMSetIMValues (XIMS, ...);
+extern char *IMGetIMValues (XIMS, ...);
+void IMForwardEvent (XIMS, XPointer);
+void IMCommitString (XIMS, XPointer);
+int IMCallCallback (XIMS, XPointer);
+int IMPreeditStart (XIMS, XPointer);
+int IMPreeditEnd (XIMS, XPointer);
+int IMSyncXlib (XIMS, XPointer);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* IMdkit_h */
diff --git a/client/x11/IMdkit/Makefile.am b/client/x11/IMdkit/Makefile.am
new file mode 100644 (file)
index 0000000..b567d9d
--- /dev/null
@@ -0,0 +1,27 @@
+noinst_LTLIBRARIES = libIMdkit.la
+
+libIMdkit_la_SOURCES = \
+       FrameMgr.c \
+       i18nAttr.c \
+       i18nClbk.c \
+       i18nIc.c \
+       i18nIMProto.c \
+       i18nMethod.c \
+       i18nPtHdr.c \
+       i18nUtil.c \
+       i18nX.c \
+       IMConn.c \
+       IMMethod.c \
+       IMValues.c \
+       $(NULL)
+
+noinst_HEADERS = \
+       FrameMgr.h \
+       IMdkit.h \
+       Xi18n.h \
+       Xi18nX.h \
+       XimFunc.h \
+       XimProto.h \
+       Xtrans.h \
+       $(NULL)
+
diff --git a/client/x11/IMdkit/Xi18n.h b/client/x11/IMdkit/Xi18n.h
new file mode 100644 (file)
index 0000000..aaf7768
--- /dev/null
@@ -0,0 +1,505 @@
+/******************************************************************
+         Copyright 1994, 1995 by Sun Microsystems, Inc.
+         Copyright 1993, 1994 by Hewlett-Packard Company
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear
+in supporting documentation, and that the name of Sun Microsystems, Inc.
+and Hewlett-Packard not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior permission.
+Sun Microsystems, Inc. and Hewlett-Packard make no representations about
+the suitability of this software for any purpose.  It is provided "as is"
+without express or implied warranty.
+SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL
+WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+  Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
+
+    This version tidied and debugged by Steve Underwood May 1999
+******************************************************************/
+
+#ifndef _Xi18n_h
+#define _Xi18n_h
+#include <X11/Xlib.h>
+#include <X11/Xfuncs.h>
+#include <X11/Xos.h>
+#include "XimProto.h"
+
+/*
+ * Minor Protocol Number for Extension Protocol 
+ */
+#define XIM_EXTENSION                          128
+#define XIM_EXT_SET_EVENT_MASK                 (0x30)
+#define        XIM_EXT_FORWARD_KEYEVENT                (0x32)
+#define        XIM_EXT_MOVE                            (0x33)
+#define COMMON_EXTENSIONS_NUM                  3
+
+#include <stdlib.h>
+#include "IMdkit.h"
+
+/* XI18N Valid Attribute Name Definition */
+#define ExtForwardKeyEvent     "extForwardKeyEvent"
+#define ExtMove                        "extMove"
+#define ExtSetEventMask                "extSetEventMask"
+
+/*
+ * Padding macro
+ */
+#define        IMPAD(length) ((4 - ((length)%4))%4)
+
+/*
+ * Target Atom for Transport Connection
+ */
+#define LOCALES                "LOCALES"
+#define TRANSPORT      "TRANSPORT"
+
+#define I18N_OPEN      0
+#define I18N_SET       1
+#define I18N_GET       2
+
+typedef struct
+{
+    char        *transportname;
+    int         namelen;
+    Bool        (*checkAddr) ();
+} TransportSW;
+
+typedef struct _XIMPending
+{
+    unsigned    char *p;
+    struct _XIMPending *next;
+} XIMPending;
+
+typedef struct _XimProtoHdr
+{
+    CARD8      major_opcode;
+    CARD8      minor_opcode;
+    CARD16     length;
+} XimProtoHdr;
+
+typedef struct
+{
+    CARD16     attribute_id;
+    CARD16     type;
+    CARD16     length;
+    char       *name;
+} XIMAttr;
+
+typedef struct
+{
+    CARD16     attribute_id;
+    CARD16     type;
+    CARD16     length;
+    char       *name;
+} XICAttr;
+
+typedef struct
+{
+    int                attribute_id;
+    CARD16     name_length; 
+    char       *name;
+    int                value_length;
+    void       *value;
+    int                type;
+} XIMAttribute;
+
+typedef struct
+{
+    int                attribute_id;
+    CARD16     name_length;
+    char       *name;
+    int                value_length;
+    void       *value;
+    int                type;
+} XICAttribute;
+
+typedef struct
+{
+    int                length;
+    char       *name;
+} XIMStr;
+
+typedef struct
+{
+    CARD16     major_opcode;
+    CARD16     minor_opcode;
+    CARD16     length;
+    char       *name;
+} XIMExt;
+
+typedef struct _Xi18nClient
+{
+    int                connect_id;
+    CARD8      byte_order;
+    /*
+       '?': initial value
+       'B': for Big-Endian
+       'l': for little-endian
+     */
+    int                sync;
+    XIMPending  *pending;
+    void *trans_rec;           /* contains transport specific data  */
+    struct _Xi18nClient *next;
+} Xi18nClient;
+
+typedef struct _Xi18nCore *Xi18n;
+
+/*
+ * Callback Struct for XIM Protocol
+ */
+typedef struct
+{
+    int                major_code;
+    int                minor_code;
+    CARD16     connect_id;
+} IMAnyStruct;
+
+typedef struct
+{
+    int                major_code;
+    int                minor_code;
+    CARD16     connect_id;
+    CARD8      byte_order;
+    CARD16     major_version;
+    CARD16     minor_version;
+} IMConnectStruct;
+
+typedef struct
+{
+    int                major_code;
+    int                minor_code;
+    CARD16     connect_id;
+} IMDisConnectStruct;
+
+typedef struct
+{
+    int                major_code;
+    int                minor_code;
+    CARD16     connect_id;
+    XIMStr     lang;
+} IMOpenStruct;
+
+typedef struct
+{
+    int                major_code;
+    int                minor_code;
+    CARD16     connect_id;
+} IMCloseStruct;
+
+typedef struct
+{
+    int                major_code;
+    int                minor_code;
+    CARD16     connect_id;
+    CARD16     number;
+    XIMStr     *extension;
+} IMQueryExtensionStruct;
+
+typedef struct
+{
+    int                major_code;
+    int                minor_code;
+    CARD16     connect_id;
+    CARD16     number;
+    char       **im_attr_list;
+} IMGetIMValuesStruct;
+
+typedef struct
+{
+    int                major_code;
+    int                minor_code;
+    CARD16     connect_id;
+    CARD16     icid;
+    CARD16     preedit_attr_num;
+    CARD16     status_attr_num;
+    CARD16     ic_attr_num;
+    XICAttribute *preedit_attr;
+    XICAttribute *status_attr;
+    XICAttribute *ic_attr;
+} IMChangeICStruct;
+
+typedef struct
+{
+    int                major_code;
+    int                minor_code;
+    CARD16     connect_id;
+    CARD16     icid;
+} IMDestroyICStruct;
+
+typedef struct
+{
+    int                major_code;
+    int                minor_code;
+    CARD16     connect_id;
+    CARD16     icid;
+    CARD16     length;
+    char       *commit_string;
+} IMResetICStruct;
+
+typedef struct
+{
+    int                major_code;
+    int                minor_code;
+    CARD16     connect_id;
+    CARD16     icid;
+} IMChangeFocusStruct;
+
+typedef struct
+{
+    int                major_code;
+    int                minor_code;
+    CARD16     connect_id;
+    CARD16     icid;
+    BITMASK16  sync_bit;
+    CARD16     serial_number;
+    XEvent     event;
+} IMForwardEventStruct;
+
+typedef struct
+{
+    int                major_code;
+    int                minor_code;
+    CARD16     connect_id;
+    CARD16     icid;
+    CARD16     flag;
+    KeySym     keysym;
+    char       *commit_string;
+} IMCommitStruct;
+
+typedef struct
+{
+    int                major_code;
+    int                minor_code;
+    CARD16     connect_id;
+    CARD16     icid;
+    CARD32     flag;
+    CARD32     key_index;
+    CARD32     event_mask;
+} IMTriggerNotifyStruct;
+
+typedef struct
+{
+    int                major_code;
+    int                minor_code;
+    CARD16     connect_id;
+    CARD16     encoding_number;
+    XIMStr     *encoding;      /* name information */
+    CARD16     encoding_info_number;
+    XIMStr     *encodinginfo;  /* detailed information */
+    CARD16     category;       /* #0 for name, #1 for detail */
+    INT16      enc_index;      /* index of the encoding determined */
+} IMEncodingNegotiationStruct;
+
+typedef struct
+{
+    int                major_code;
+    int                minor_code;
+    CARD16     connect_id;
+    CARD16     icid;
+    CARD32     flag;
+    CARD32     forward_event_mask;
+    CARD32     sync_event_mask;
+} IMSetEventMaskStruct;
+
+typedef struct
+{
+    int                major_code;
+    int                minor_code;
+    CARD16     connect_id;
+    CARD16     icid;
+    CARD32     filter_event_mask;
+    CARD32     intercept_event_mask;
+    CARD32     select_event_mask;
+    CARD32     forward_event_mask;
+    CARD32     sync_event_mask;
+} IMExtSetEventMaskStruct;
+
+typedef struct
+{
+    int                major_code;
+    int                minor_code;
+    CARD16     connect_id;
+    CARD16     icid;
+    CARD16     x;
+    CARD16     y;
+} IMMoveStruct;
+
+typedef struct
+{
+    int                major_code;
+    int                minor_code;
+    CARD16     connect_id;
+    CARD16     icid;
+    BITMASK16  flag;
+    CARD16     error_code;
+    CARD16     str_length;
+    CARD16     error_type;
+    char       *error_detail;
+} IMErrorStruct;
+
+typedef struct
+{
+    int                major_code;
+    int                minor_code;
+    CARD16     connect_id;
+    CARD16     icid;
+} IMPreeditStateStruct;
+
+/* Callbacks */
+typedef struct
+{
+    int                major_code;
+    int                minor_code;
+    CARD16     connect_id;
+    CARD16     icid;
+} IMGeometryCBStruct;
+
+typedef struct
+{
+    int                major_code;
+    int                minor_code;
+    CARD16     connect_id;
+    CARD16     icid;
+    union
+    {
+       int return_value;                       /* PreeditStart */
+       XIMPreeditDrawCallbackStruct draw;      /* PreeditDraw */
+       XIMPreeditCaretCallbackStruct caret;    /* PreeditCaret */
+    } todo;
+} IMPreeditCBStruct;
+
+typedef struct
+{
+    int                major_code;
+    int                minor_code;
+    CARD16     connect_id;
+    CARD16     icid;
+    union
+    {
+       XIMStatusDrawCallbackStruct draw;       /* StatusDraw */
+    } todo;
+} IMStatusCBStruct;
+
+typedef struct
+{
+    int                major_code;
+    int                minor_code;
+    CARD16     connect_id;
+    CARD16     icid;
+    XIMStringConversionCallbackStruct strconv;
+} IMStrConvCBStruct;
+
+typedef struct
+{
+    int                major_code;
+    int                minor_code;
+    CARD16     connect_id;
+    CARD16     icid;
+} IMSyncXlibStruct;
+
+typedef union _IMProtocol
+{
+    int        major_code;
+    IMAnyStruct any;
+    IMConnectStruct imconnect;
+    IMDisConnectStruct imdisconnect;
+    IMOpenStruct imopen;
+    IMCloseStruct imclose;
+    IMQueryExtensionStruct queryext;
+    IMGetIMValuesStruct getim;
+    IMEncodingNegotiationStruct encodingnego;
+    IMExtSetEventMaskStruct extsetevent;
+    IMMoveStruct extmove;
+    IMSetEventMaskStruct setevent;
+    IMChangeICStruct changeic;
+    IMDestroyICStruct destroyic;
+    IMResetICStruct resetic;
+    IMChangeFocusStruct changefocus;
+    IMCommitStruct commitstring;
+    IMForwardEventStruct forwardevent;
+    IMTriggerNotifyStruct triggernotify;
+    IMPreeditStateStruct preedit_state;
+    IMErrorStruct imerror;
+    IMGeometryCBStruct geometry_callback;
+    IMPreeditCBStruct preedit_callback;
+    IMStatusCBStruct status_callback;
+    IMStrConvCBStruct strconv_callback;
+    IMSyncXlibStruct sync_xlib;
+    long pad[32];
+} IMProtocol;
+
+typedef int (*IMProtoHandler) (XIMS, IMProtocol*);
+
+#define DEFAULT_FILTER_MASK    (KeyPressMask)
+
+/* Xi18nAddressRec structure */
+typedef struct _Xi18nAddressRec
+{
+    Display    *dpy;
+    CARD8      im_byteOrder;   /* byte order 'B' or 'l' */
+    /* IM Values */
+    long       imvalue_mask;
+    Window     im_window;      /* IMServerWindow */
+    char       *im_name;       /* IMServerName */
+    char       *im_locale;     /* IMLocale */
+    char       *im_addr;       /* IMServerTransport */
+    XIMStyles  input_styles;   /* IMInputStyles */
+    XIMTriggerKeys on_keys;    /* IMOnKeysList */
+    XIMTriggerKeys off_keys;   /* IMOffKeysList */
+    XIMEncodings encoding_list; /* IMEncodingList */
+    IMProtoHandler improto;    /* IMProtocolHander */
+    long       filterevent_mask; /* IMFilterEventMask */
+    /* XIM_SERVERS target Atoms */
+    Atom       selection;
+    Atom       Localename;
+    Atom       Transportname;
+    /* XIM/XIC Attr */
+    int                im_attr_num;
+    XIMAttr    *xim_attr;
+    int                ic_attr_num;
+    XICAttr    *xic_attr;
+    CARD16     preeditAttr_id;
+    CARD16     statusAttr_id;
+    CARD16     separatorAttr_id;
+    /* XIMExtension List */
+    int                ext_num;
+    XIMExt     extension[COMMON_EXTENSIONS_NUM];
+    /* transport specific connection address */
+    void       *connect_addr;
+    /* actual data is defined:
+       XSpecRec in Xi18nX.h for X-based connection.
+       TransSpecRec in Xi18nTr.h for Socket-based connection.
+     */
+    /* clients table */
+    Xi18nClient *clients;
+    Xi18nClient *free_clients;
+} Xi18nAddressRec;
+
+typedef struct _Xi18nMethodsRec
+{
+    Bool (*begin) (XIMS);
+    Bool (*end) (XIMS);
+    Bool (*send) (XIMS, CARD16, unsigned char*, long);
+    Bool (*wait) (XIMS, CARD16, CARD8, CARD8);
+    Bool (*disconnect) (XIMS, CARD16);
+} Xi18nMethodsRec;
+
+typedef struct _Xi18nCore
+{
+    Xi18nAddressRec address;
+    Xi18nMethodsRec methods;
+} Xi18nCore;
+
+#endif
+
diff --git a/client/x11/IMdkit/Xi18nX.h b/client/x11/IMdkit/Xi18nX.h
new file mode 100644 (file)
index 0000000..ff91b1a
--- /dev/null
@@ -0,0 +1,52 @@
+/******************************************************************
+         Copyright 1994, 1995 by Sun Microsystems, Inc.
+         Copyright 1993, 1994 by Hewlett-Packard Company
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear
+in supporting documentation, and that the name of Sun Microsystems, Inc.
+and Hewlett-Packard not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior permission.
+Sun Microsystems, Inc. and Hewlett-Packard make no representations about
+the suitability of this software for any purpose.  It is provided "as is"
+without express or implied warranty.
+SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL
+WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+  Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
+
+    This version tidied and debugged by Steve Underwood May 1999
+******************************************************************/
+
+#ifndef _Xi18nTrX_h
+#define _Xi18nTrX_h
+
+#define _XIM_PROTOCOL           "_XIM_PROTOCOL"
+#define _XIM_XCONNECT           "_XIM_XCONNECT"
+
+#define XCM_DATA_LIMIT         20
+
+typedef struct _XClient
+{
+    Window     client_win;     /* client window */
+    Window     accept_win;     /* accept window */
+} XClient;
+
+typedef struct
+{
+    Atom       xim_request;
+    Atom       connect_request;
+} XSpecRec;
+
+#endif
diff --git a/client/x11/IMdkit/XimFunc.h b/client/x11/IMdkit/XimFunc.h
new file mode 100644 (file)
index 0000000..a9f4a04
--- /dev/null
@@ -0,0 +1,72 @@
+/******************************************************************
+         Copyright 1994, 1995 by Sun Microsystems, Inc.
+         Copyright 1993, 1994 by Hewlett-Packard Company
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear
+in supporting documentation, and that the name of Sun Microsystems, Inc.
+and Hewlett-Packard not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior permission.
+Sun Microsystems, Inc. and Hewlett-Packard make no representations about
+the suitability of this software for any purpose.  It is provided "as is"
+without express or implied warranty.
+SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL
+WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+  Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
+
+    This version tidied and debugged by Steve Underwood May 1999
+******************************************************************/
+
+#ifndef _XimFunc_h
+#define _XimFunc_h
+
+/* i18nAttr.c */
+void _Xi18nInitAttrList (Xi18n i18n_core);
+void _Xi18nInitExtension(Xi18n i18n_core);
+
+/* i18nClbk.c */
+int _Xi18nGeometryCallback (XIMS ims, IMProtocol *call_data);
+int _Xi18nPreeditStartCallback (XIMS ims, IMProtocol *call_data);
+int _Xi18nPreeditDrawCallback (XIMS ims, IMProtocol *call_data);
+int _Xi18nPreeditCaretCallback (XIMS ims, IMProtocol *call_data);
+int _Xi18nPreeditDoneCallback (XIMS ims, IMProtocol *call_data);
+int _Xi18nStatusStartCallback (XIMS ims, IMProtocol *call_data);
+int _Xi18nStatusDrawCallback (XIMS ims, IMProtocol *call_data);
+int _Xi18nStatusDoneCallback (XIMS ims, IMProtocol *call_data);
+int _Xi18nStringConversionCallback (XIMS ims, IMProtocol *call_data);
+
+/* i18nIc.c */
+void _Xi18nChangeIC (XIMS ims, IMProtocol *call_data, unsigned char *p,
+                     int create_flag);
+void _Xi18nGetIC (XIMS ims, IMProtocol *call_data, unsigned char *p);
+
+/* i18nUtil.c */
+int _Xi18nNeedSwap (Xi18n i18n_core, CARD16 connect_id);
+Xi18nClient *_Xi18nNewClient(Xi18n i18n_core);
+Xi18nClient *_Xi18nFindClient (Xi18n i18n_core, CARD16 connect_id);
+void _Xi18nDeleteClient (Xi18n i18n_core, CARD16 connect_id);
+void _Xi18nSendMessage (XIMS ims, CARD16 connect_id, CARD8 major_opcode,
+                        CARD8 minor_opcode, unsigned char *data, long length);
+void _Xi18nSendTriggerKey (XIMS ims, CARD16 connect_id);
+void _Xi18nSetEventMask (XIMS ims, CARD16 connect_id, CARD16 im_id,
+                         CARD16 ic_id, CARD32 forward_mask, CARD32 sync_mask);
+
+/* Xlib internal */
+void _XRegisterFilterByType(Display*, Window, int, int,
+               Bool (*filter)(Display*, Window, XEvent*, XPointer), XPointer);
+void _XUnregisterFilter(Display*, Window, 
+               Bool (*filter)(Display*, Window, XEvent*, XPointer), XPointer);
+
+#endif
diff --git a/client/x11/IMdkit/XimProto.h b/client/x11/IMdkit/XimProto.h
new file mode 100644 (file)
index 0000000..e3ed168
--- /dev/null
@@ -0,0 +1,230 @@
+/* $XConsortium: XimProto.h,v 1.2 94/01/20 18:02:24 rws Exp $ */
+/******************************************************************
+
+           Copyright 1992, 1993, 1994 by FUJITSU LIMITED
+
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear
+in supporting documentation, and that the name of FUJITSU LIMITED
+not be used in advertising or publicity pertaining to distribution
+of the software without specific, written prior permission.
+FUJITSU LIMITED makes no representations about the suitability of
+this software for any purpose. 
+It is provided "as is" without express or implied warranty.
+
+FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
+USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+
+  Author: Takashi Fujiwara     FUJITSU LIMITED 
+                               fujiwara@a80.tech.yk.fujitsu.co.jp
+
+    This version tidied and debugged by Steve Underwood May 1999
+
+******************************************************************/
+
+#ifndef _XIMPROTO_H
+#define _XIMPROTO_H
+
+/*
+ * Default Preconnection selection target
+ */
+#define XIM_SERVERS            "XIM_SERVERS"
+#define XIM_LOCALES            "LOCALES"
+#define XIM_TRANSPORT          "TRANSPORT"
+
+/*
+ * categories in XIM_SERVERS
+ */
+#define XIM_SERVER_CATEGORY    "@server="
+#define XIM_LOCAL_CATEGORY     "@locale="
+#define XIM_TRANSPORT_CATEGORY "@transport="
+
+/*
+ * Xim implementation revision
+ */
+#define PROTOCOLMAJORVERSION           0
+#define PROTOCOLMINORVERSION           0
+
+/*
+ * Major Protocol number
+ */
+#define        XIM_CONNECT                       1
+#define        XIM_CONNECT_REPLY                 2
+#define        XIM_DISCONNECT                    3
+#define        XIM_DISCONNECT_REPLY              4
+
+#define XIM_AUTH_REQUIRED               10
+#define XIM_AUTH_REPLY                  11
+#define XIM_AUTH_NEXT                   12
+#define XIM_AUTH_SETUP                  13
+#define XIM_AUTH_NG                     14
+
+#define        XIM_ERROR                        20
+
+#define        XIM_OPEN                         30
+#define        XIM_OPEN_REPLY                   31
+#define        XIM_CLOSE                        32
+#define        XIM_CLOSE_REPLY                  33
+#define        XIM_REGISTER_TRIGGERKEYS         34
+#define        XIM_TRIGGER_NOTIFY               35
+#define        XIM_TRIGGER_NOTIFY_REPLY         36
+#define        XIM_SET_EVENT_MASK               37
+#define        XIM_ENCODING_NEGOTIATION         38
+#define        XIM_ENCODING_NEGOTIATION_REPLY   39
+#define        XIM_QUERY_EXTENSION              40
+#define        XIM_QUERY_EXTENSION_REPLY        41
+#define        XIM_SET_IM_VALUES                42
+#define        XIM_SET_IM_VALUES_REPLY          43
+#define        XIM_GET_IM_VALUES                44
+#define        XIM_GET_IM_VALUES_REPLY          45
+
+#define XIM_CREATE_IC                   50
+#define        XIM_CREATE_IC_REPLY              51
+#define        XIM_DESTROY_IC                   52
+#define        XIM_DESTROY_IC_REPLY             53
+#define XIM_SET_IC_VALUES               54
+#define        XIM_SET_IC_VALUES_REPLY          55
+#define XIM_GET_IC_VALUES               56
+#define XIM_GET_IC_VALUES_REPLY                 57
+#define        XIM_SET_IC_FOCUS                 58
+#define        XIM_UNSET_IC_FOCUS               59
+#define        XIM_FORWARD_EVENT                60
+#define        XIM_SYNC                         61
+#define        XIM_SYNC_REPLY                   62
+#define        XIM_COMMIT                       63
+#define        XIM_RESET_IC                     64
+#define        XIM_RESET_IC_REPLY               65
+
+#define        XIM_GEOMETRY                     70
+#define        XIM_STR_CONVERSION               71
+#define        XIM_STR_CONVERSION_REPLY         72
+#define        XIM_PREEDIT_START                73
+#define        XIM_PREEDIT_START_REPLY          74
+#define        XIM_PREEDIT_DRAW                 75
+#define        XIM_PREEDIT_CARET                76
+#define XIM_PREEDIT_CARET_REPLY                 77
+#define        XIM_PREEDIT_DONE                 78
+#define        XIM_STATUS_START                 79
+#define        XIM_STATUS_DRAW                  80
+#define        XIM_STATUS_DONE                  81
+
+/*
+ * values for the flag of XIM_ERROR
+ */
+#define        XIM_IMID_VALID                  0x0001
+#define        XIM_ICID_VALID                  0x0002
+
+/*
+ * XIM Error Code
+ */
+#define XIM_BadAlloc                   1
+#define XIM_BadStyle                   2
+#define XIM_BadClientWindow            3
+#define XIM_BadFocusWindow             4
+#define XIM_BadArea                    5
+#define XIM_BadSpotLocation            6
+#define XIM_BadColormap                        7
+#define XIM_BadAtom                    8
+#define XIM_BadPixel                   9
+#define XIM_BadPixmap                  10
+#define XIM_BadName                    11
+#define XIM_BadCursor                  12
+#define XIM_BadProtocol                        13
+#define XIM_BadForeground              14
+#define XIM_BadBackground              15
+#define XIM_LocaleNotSupported         16
+#define XIM_BadSomething               999
+
+/*
+ * byte order
+ */
+#define BIGENDIAN      (CARD8) 0x42    /* MSB first */
+#define LITTLEENDIAN   (CARD8) 0x6c    /* LSB first */
+
+/*
+ * values for the type of XIMATTR & XICATTR
+ */
+#define        XimType_SeparatorOfNestedList   0
+#define        XimType_CARD8                   1
+#define        XimType_CARD16                  2
+#define        XimType_CARD32                  3
+#define        XimType_STRING8                 4
+#define        XimType_Window                  5
+#define        XimType_XIMStyles               10
+#define        XimType_XRectangle              11
+#define        XimType_XPoint                  12
+#define XimType_XFontSet               13
+#define XimType_XIMOptions             14
+#define XimType_XIMHotKeyTriggers      15
+#define XimType_XIMHotKeyState         16
+#define XimType_XIMStringConversion    17
+#define XimType_XIMValuesList          18
+#define        XimType_NEST                    0x7FFF
+
+/*
+ * values for the category of XIM_ENCODING_NEGOTIATON_REPLY
+ */
+#define        XIM_Encoding_NameCategory       0
+#define        XIM_Encoding_DetailCategory     1
+
+/*
+ * value for the index of XIM_ENCODING_NEGOTIATON_REPLY
+ */
+#define        XIM_Default_Encoding_IDX        -1
+
+/*
+ * value for the flag of XIM_FORWARD_EVENT, XIM_COMMIT
+ */
+#define XimSYNCHRONUS            0x0001
+#define XimLookupChars           0x0002
+#define XimLookupKeySym                  0x0004
+#define XimLookupBoth            0x0006
+
+/*
+ * request packet header size
+ */
+#define XIM_HEADER_SIZE                                                \
+         sizeof(CARD8)         /* sizeof mejor-opcode */       \
+       + sizeof(CARD8)         /* sizeof minor-opcode */       \
+       + sizeof(INT16)         /* sizeof length */
+
+/*
+ * Client Message data size
+ */
+#define        XIM_CM_DATA_SIZE        20
+
+/*
+ * XIM data structure
+ */
+typedef CARD16 BITMASK16;
+typedef CARD32 BITMASK32;
+typedef CARD32 EVENTMASK;
+
+typedef CARD16 XIMID;          /* Input Method ID */
+typedef CARD16 XICID;          /* Input Context ID */
+
+/*
+ * Padding macro
+ */
+#define        XIM_PAD(length) ((4 - ((length) % 4)) % 4)
+
+#define XIM_SET_PAD(ptr, length)                                       \
+    {                                                                  \
+       register int     Counter = XIM_PAD((int)length);                \
+       if (Counter) {                                                  \
+           register char       *Ptr = (char *)(ptr) + (length);        \
+           length += Counter;                                          \
+           for (; Counter; --Counter, ++Ptr)                           \
+               *Ptr = '\0';                                            \
+       }                                                               \
+    }
+
+#endif
+
diff --git a/client/x11/IMdkit/Xtrans.h b/client/x11/IMdkit/Xtrans.h
new file mode 100644 (file)
index 0000000..cae691c
--- /dev/null
@@ -0,0 +1,470 @@
+/* $XConsortium: Xtrans.h,v 1.24 94/05/02 10:45:32 mor Exp $ */
+/*
+
+Copyright (c) 1993, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/* Copyright (c) 1993, 1994 NCR Corporation - Dayton, Ohio, USA
+ *
+ * All Rights Reserved
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name NCR not be used in advertising
+ * or publicity pertaining to distribution of the software without specific,
+ * written prior permission.  NCR makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as is"
+ * without express or implied warranty.
+ *
+ * NCR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL NCR BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _XTRANS_H_
+#define _XTRANS_H_
+
+#include <X11/Xfuncproto.h>
+#include <X11/Xos.h>
+
+
+/*
+ * Set the functions names according to where this code is being compiled.
+ */
+
+#ifdef X11_t
+#if (__STDC__ && !defined(UNIXCPP)) || defined(ANSICPP)
+#define TRANS(func) _X11Trans##func
+#else
+#define TRANS(func) _X11Trans/**/func
+#endif
+#endif /* X11_t */
+
+#ifdef XSERV_t
+#if (__STDC__ && !defined(UNIXCPP)) || defined(ANSICPP)
+#define TRANS(func) _XSERVTrans##func
+#else
+#define TRANS(func) _XSERVTrans/**/func
+#endif
+#define X11_t
+#endif /* X11_t */
+
+#ifdef XIM_t
+#if (__STDC__ && !defined(UNIXCPP)) || defined(ANSICPP)
+#define TRANS(func) _XimdXTrans##func
+#else
+#define TRANS(func) _XimdXTrans/**/func
+#endif
+#endif /* XIM_t */
+
+#ifdef FS_t
+#if (__STDC__ && !defined(UNIXCPP)) || defined(ANSICPP)
+#define TRANS(func) _FSTrans##func
+#else
+#define TRANS(func) _FSTrans/**/func
+#endif
+#endif /* FS_t */
+
+#ifdef FONT_t
+#if (__STDC__ && !defined(UNIXCPP)) || defined(ANSICPP)
+#define TRANS(func) _FontTrans##func
+#else
+#define TRANS(func) _FontTrans/**/func
+#endif
+#endif /* FONT_t */
+
+#ifdef ICE_t
+#if (__STDC__ && !defined(UNIXCPP)) || defined(ANSICPP)
+#define TRANS(func) _IceTrans##func
+#else
+#define TRANS(func) _IceTrans/**/func
+#endif
+#endif /* ICE_t */
+
+#ifdef TEST_t
+#if (__STDC__ && !defined(UNIXCPP)) || defined(ANSICPP)
+#define TRANS(func) _TESTTrans##func
+#else
+#define TRANS(func) _TESTTrans/**/func
+#endif
+#endif /* TEST_t */
+
+#if !defined(TRANS)
+#if (__STDC__ && !defined(UNIXCPP)) || defined(ANSICPP)
+#define TRANS(func) _XTrans##func
+#else
+#define TRANS(func) _XTrans/**/func
+#endif
+#endif /* !TRANS */
+
+
+/*
+ * Create a single address structure that can be used wherever
+ * an address structure is needed. struct sockaddr is not big enough
+ * to hold a sockadd_un, so we create this definition to have a single
+ * structure that is big enough for all the structures we might need.
+ *
+ * This structure needs to be independent of the socket/TLI interface used.
+ */
+
+#define XTRANS_MAX_ADDR_LEN    128     /* large enough to hold sun_path */
+
+typedef        struct {
+    unsigned char      addr[XTRANS_MAX_ADDR_LEN];
+} Xtransaddr;
+
+
+#ifdef LONG64
+typedef int BytesReadable_t;
+#else
+typedef long BytesReadable_t;
+#endif
+
+
+#if defined(WIN32) || (defined(USG) && !defined(CRAY) && !defined(umips) && !defined(MOTOROLA) && !defined(uniosu) && !defined(__sxg__))
+
+/*
+ *      TRANS(Readv) and TRANS(Writev) use struct iovec, normally found
+ *      in Berkeley systems in <sys/uio.h>.  See the readv(2) and writev(2)
+ *      manual pages for details.
+ */
+
+struct iovec {
+    caddr_t iov_base;
+    int iov_len;
+};
+
+#else
+#include <sys/uio.h>
+#endif
+
+typedef struct _XtransConnInfo *XtransConnInfo;
+
+
+/*
+ * Transport Option definitions
+ */
+
+#define TRANS_NONBLOCKING      1
+#define        TRANS_CLOSEONEXEC       2
+
+
+/*
+ * Return values of Connect (0 is success)
+ */
+
+#define TRANS_CONNECT_FAILED   -1
+#define TRANS_TRY_CONNECT_AGAIN -2
+
+
+/*
+ * Return values of Accept (0 is success)
+ */
+
+#define TRANS_ACCEPT_BAD_MALLOC                        -1
+#define TRANS_ACCEPT_FAILED                    -2
+#define TRANS_ACCEPT_MISC_ERROR                        -3
+
+
+/*
+ * ResetListener return values
+ */
+
+#define TRANS_RESET_NOOP       1
+#define TRANS_RESET_NEW_FD     2
+#define TRANS_RESET_FAILURE    3
+
+
+/*
+ * Function prototypes for the exposed interface
+ */
+
+#ifdef TRANS_CLIENT
+
+XtransConnInfo TRANS(OpenCOTSClient)(
+#if NeedFunctionPrototypes
+    char *             /* address */
+#endif
+);
+
+#endif /* TRANS_CLIENT */
+
+#ifdef TRANS_SERVER
+
+XtransConnInfo TRANS(OpenCOTSServer)(
+#if NeedFunctionPrototypes
+    char *             /* address */
+#endif
+);
+
+#endif /* TRANS_SERVER */
+
+#ifdef TRANS_CLIENT
+
+XtransConnInfo TRANS(OpenCLTSClient)(
+#if NeedFunctionPrototypes
+    char *             /* address */
+#endif
+);
+
+#endif /* TRANS_CLIENT */
+
+#ifdef TRANS_SERVER
+
+XtransConnInfo TRANS(OpenCLTSServer)(
+#if NeedFunctionPrototypes
+    char *             /* address */
+#endif
+);
+
+#endif /* TRANS_SERVER */
+
+#ifdef TRANS_REOPEN
+
+XtransConnInfo TRANS(ReopenCOTSServer)(
+#if NeedFunctionPrototypes
+    int,               /* trans_id */
+    int,               /* fd */
+    char *             /* port */
+#endif
+);
+
+XtransConnInfo TRANS(ReopenCLTSServer)(
+#if NeedFunctionPrototypes
+    int,               /* trans_id */
+    int,               /* fd */
+    char *             /* port */
+#endif
+);
+
+int TRANS(GetReopenInfo)(
+#if NeedFunctionPrototypes
+    XtransConnInfo,    /* ciptr */
+    int *,             /* trans_id */
+    int *,             /* fd */
+    char **            /* port */
+#endif
+);
+
+#endif /* TRANS_REOPEN */
+
+
+int TRANS(SetOption)(
+#if NeedFunctionPrototypes
+    XtransConnInfo,    /* ciptr */
+    int,               /* option */
+    int                        /* arg */
+#endif
+);
+
+#ifdef TRANS_SERVER
+
+int TRANS(CreateListener)(
+#if NeedFunctionPrototypes
+    XtransConnInfo,    /* ciptr */
+    char *             /* port */
+#endif
+);
+
+int TRANS(ResetListener)(
+#if NeedFunctionPrototypes
+    XtransConnInfo     /* ciptr */
+#endif
+);
+
+XtransConnInfo TRANS(Accept)(
+#if NeedFunctionPrototypes
+    XtransConnInfo,    /* ciptr */
+    int *              /* status */
+#endif
+);
+
+#endif /* TRANS_SERVER */
+
+#ifdef TRANS_CLIENT
+
+int TRANS(Connect)(
+#if NeedFunctionPrototypes
+    XtransConnInfo,    /* ciptr */
+    char *             /* address */
+#endif
+);
+
+#endif /* TRANS_CLIENT */
+
+int TRANS(BytesReadable)(
+#if NeedFunctionPrototypes
+    XtransConnInfo,    /* ciptr */
+    BytesReadable_t *  /* pend */
+#endif
+);
+
+int TRANS(Read)(
+#if NeedFunctionPrototypes
+    XtransConnInfo,    /* ciptr */
+    char *,            /* buf */
+    int                        /* size */
+#endif
+);
+
+int TRANS(Write)(
+#if NeedFunctionPrototypes
+    XtransConnInfo,    /* ciptr */
+    char *,            /* buf */
+    int                        /* size */
+#endif
+);
+
+int TRANS(Readv)(
+#if NeedFunctionPrototypes
+    XtransConnInfo,    /* ciptr */
+    struct iovec *,    /* buf */
+    int                        /* size */
+#endif
+);
+
+int TRANS(Writev)(
+#if NeedFunctionPrototypes
+    XtransConnInfo,    /* ciptr */
+    struct iovec *,    /* buf */
+    int                        /* size */
+#endif
+);
+
+int TRANS(Disconnect)(
+#if NeedFunctionPrototypes
+    XtransConnInfo     /* ciptr */
+#endif
+);
+
+int TRANS(Close)(
+#if NeedFunctionPrototypes
+    XtransConnInfo     /* ciptr */
+#endif
+);
+
+int TRANS(CloseForCloning)(
+#if NeedFunctionPrototypes
+    XtransConnInfo     /* ciptr */
+#endif
+);
+
+int TRANS(IsLocal)(
+#if NeedFunctionPrototypes
+    XtransConnInfo     /* ciptr */
+#endif
+);
+
+int TRANS(GetMyAddr)(
+#if NeedFunctionPrototypes
+    XtransConnInfo,    /* ciptr */
+    int *,             /* familyp */
+    int *,             /* addrlenp */
+    Xtransaddr **      /* addrp */
+#endif
+);
+
+int TRANS(GetPeerAddr)(
+#if NeedFunctionPrototypes
+    XtransConnInfo,    /* ciptr */
+    int *,             /* familyp */
+    int *,             /* addrlenp */
+    Xtransaddr **      /* addrp */
+#endif
+);
+
+int TRANS(GetConnectionNumber)(
+#if NeedFunctionPrototypes
+    XtransConnInfo     /* ciptr */
+#endif
+);
+
+#ifdef TRANS_SERVER
+
+int TRANS(MakeAllCOTSServerListeners)(
+#if NeedFunctionPrototypes
+    char *,            /* port */
+    int *,             /* partial */
+    int *,             /* count_ret */
+    XtransConnInfo **  /* ciptrs_ret */
+#endif
+);
+
+int TRANS(MakeAllCLTSServerListeners)(
+#if NeedFunctionPrototypes
+    char *,            /* port */
+    int *,             /* partial */
+    int *,             /* count_ret */
+    XtransConnInfo **  /* ciptrs_ret */
+#endif
+);
+
+#endif /* TRANS_SERVER */
+
+
+/*
+ * Function Prototypes for Utility Functions.
+ */
+
+#ifdef X11_t
+
+int TRANS(ConvertAddress)(
+#if NeedFunctionPrototypes
+    int *,             /* familyp */
+    int *,             /* addrlenp */
+    Xtransaddr *       /* addrp */
+#endif
+);
+
+#endif /* X11_t */
+
+#ifdef ICE_t
+
+char *
+TRANS(GetMyNetworkId)(
+#if NeedFunctionPrototypes
+    XtransConnInfo     /* ciptr */
+#endif
+);
+
+char *
+TRANS(GetPeerNetworkId)(
+#if NeedFunctionPrototypes
+    XtransConnInfo     /* ciptr */
+#endif
+);
+
+#endif /* ICE_t */
+
+#endif /* _XTRANS_H_ */
diff --git a/client/x11/IMdkit/i18nAttr.c b/client/x11/IMdkit/i18nAttr.c
new file mode 100644 (file)
index 0000000..a52370b
--- /dev/null
@@ -0,0 +1,175 @@
+/******************************************************************
+         Copyright 1994, 1995 by Sun Microsystems, Inc.
+         Copyright 1993, 1994 by Hewlett-Packard Company
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear
+in supporting documentation, and that the name of Sun Microsystems, Inc.
+and Hewlett-Packard not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior permission.
+Sun Microsystems, Inc. and Hewlett-Packard make no representations about
+the suitability of this software for any purpose.  It is provided "as is"
+without express or implied warranty.
+SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL
+WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+  Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
+
+    This version tidied and debugged by Steve Underwood May 1999
+******************************************************************/
+
+#include <X11/Xlib.h>
+#include <X11/Xresource.h>
+#include "IMdkit.h"
+#include "Xi18n.h"
+#include "XimFunc.h"
+
+typedef struct 
+{
+    char *name;
+    CARD16 type;
+} IMListOfAttr;
+
+typedef struct
+{
+    char *name;
+    CARD8 major_opcode;
+    CARD8 minor_opcode;
+} IMExtList;
+
+IMListOfAttr Default_IMattr[] =
+{
+    {XNQueryInputStyle,   XimType_XIMStyles},
+/*    {XNQueryIMValuesList, XimType_XIMValuesList},    */
+    {(char *) NULL, (CARD16) 0}
+};
+
+IMListOfAttr Default_ICattr[] =
+{
+    {XNInputStyle,              XimType_CARD32},
+    {XNClientWindow,            XimType_Window},
+    {XNFocusWindow,             XimType_Window},
+    {XNFilterEvents,            XimType_CARD32},
+    {XNPreeditAttributes,       XimType_NEST},
+    {XNStatusAttributes,        XimType_NEST},
+    {XNFontSet,                 XimType_XFontSet},
+    {XNArea,                    XimType_XRectangle},
+    {XNAreaNeeded,              XimType_XRectangle},
+    {XNColormap,                XimType_CARD32},
+    {XNStdColormap,             XimType_CARD32},
+    {XNForeground,              XimType_CARD32},
+    {XNBackground,              XimType_CARD32},
+    {XNBackgroundPixmap,        XimType_CARD32},
+    {XNSpotLocation,            XimType_XPoint},
+    {XNLineSpace,               XimType_CARD32},
+    {XNPreeditState,            XimType_CARD32},
+    {XNSeparatorofNestedList,   XimType_SeparatorOfNestedList},
+    {(char *) NULL, 0}
+};
+
+IMExtList Default_Extension[] =
+{
+    {"XIM_EXT_MOVE", XIM_EXTENSION, XIM_EXT_MOVE},
+    {"XIM_EXT_SET_EVENT_MASK", XIM_EXTENSION, XIM_EXT_SET_EVENT_MASK},
+    {"XIM_EXT_FORWARD_KEYEVENT", XIM_EXTENSION, XIM_EXT_FORWARD_KEYEVENT},
+    {(char *) NULL, 0, 0}
+};
+
+static void CountAttrList(IMListOfAttr *attr, int *total_count)
+{
+    *total_count = 0;
+
+    while (attr->name != NULL)
+    {
+        attr++;
+        ++(*total_count);
+    }
+}
+
+static XIMAttr *CreateAttrList (Xi18n i18n_core,
+                                IMListOfAttr *attr,
+                                int *total_count)
+{
+    XIMAttr *args, *p;
+    unsigned int buf_size;
+
+    CountAttrList(attr, total_count);
+
+    buf_size = (unsigned) (*total_count + 1)*sizeof (XIMAttr);
+    args = (XIMAttr *) malloc (buf_size);
+    if (!args)
+        return (XIMAttr *) NULL;
+    /*endif*/
+    memset (args, 0, buf_size);
+
+    for (p = args;  attr->name != NULL;  attr++, p++)
+    {
+        p->name = attr->name;
+        p->length = strlen (attr->name);
+        p->type = (CARD16) attr->type;
+        p->attribute_id = XrmStringToQuark (p->name);
+        if (strcmp (p->name, XNPreeditAttributes) == 0)
+            i18n_core->address.preeditAttr_id = p->attribute_id;
+        else if (strcmp (p->name, XNStatusAttributes) == 0)
+            i18n_core->address.statusAttr_id = p->attribute_id;
+        else if (strcmp (p->name, XNSeparatorofNestedList) == 0)
+            i18n_core->address.separatorAttr_id = p->attribute_id;
+        /*endif*/
+    }
+    /*endfor*/
+    p->name = (char *) NULL;
+
+    return args;
+}
+
+void _Xi18nInitAttrList (Xi18n i18n_core)
+{
+    XIMAttr *args;
+    int        total_count;
+
+    /* init IMAttr list */
+    if (i18n_core->address.xim_attr)
+        XFree ((char *)i18n_core->address.xim_attr);
+    /*endif*/
+    args = CreateAttrList (i18n_core, Default_IMattr, &total_count);
+
+    i18n_core->address.im_attr_num = total_count;
+    i18n_core->address.xim_attr = (XIMAttr *)args;
+
+    /* init ICAttr list */
+    if (i18n_core->address.xic_attr)
+        XFree ((char *) i18n_core->address.xic_attr);
+    /*endif*/
+    args = CreateAttrList (i18n_core, Default_ICattr, &total_count);
+
+    i18n_core->address.ic_attr_num = total_count;
+    i18n_core->address.xic_attr = (XICAttr *) args;
+}
+
+void _Xi18nInitExtension(Xi18n i18n_core)
+{
+    register int i;
+    IMExtList *extensions = (IMExtList *) Default_Extension;
+    XIMExt *ext_list = (XIMExt *) i18n_core->address.extension;
+
+    for (i = 0;  extensions->name;  i++, ext_list++, extensions++)
+    {
+        ext_list->major_opcode = extensions->major_opcode;
+        ext_list->minor_opcode = extensions->minor_opcode;
+        ext_list->name = extensions->name;
+        ext_list->length = strlen(ext_list->name);
+    }
+    /*endfor*/
+    i18n_core->address.ext_num = i;
+}
diff --git a/client/x11/IMdkit/i18nClbk.c b/client/x11/IMdkit/i18nClbk.c
new file mode 100644 (file)
index 0000000..b3edf3a
--- /dev/null
@@ -0,0 +1,513 @@
+/******************************************************************
+         Copyright 1994, 1995 by Sun Microsystems, Inc.
+         Copyright 1993, 1994 by Hewlett-Packard Company
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear
+in supporting documentation, and that the name of Sun Microsystems, Inc.
+and Hewlett-Packard not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior permission.
+Sun Microsystems, Inc. and Hewlett-Packard make no representations about
+the suitability of this software for any purpose.  It is provided "as is"
+without express or implied warranty.
+SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL
+WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+  Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
+
+    This version tidied and debugged by Steve Underwood May 1999
+******************************************************************/
+
+#include <X11/Xlib.h>
+#include "IMdkit.h"
+#include "Xi18n.h"
+#include "FrameMgr.h"
+#include "XimFunc.h"
+
+int _Xi18nGeometryCallback (XIMS ims, IMProtocol *call_data)
+{
+    Xi18n i18n_core = ims->protocol;
+    FrameMgr fm;
+    extern XimFrameRec geometry_fr[];
+    register int total_size;
+    unsigned char *reply = NULL;
+    IMGeometryCBStruct *geometry_CB =
+        (IMGeometryCBStruct *) &call_data->geometry_callback;
+    CARD16 connect_id = call_data->any.connect_id;
+
+    fm = FrameMgrInit (geometry_fr,
+                       NULL,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+
+    total_size = FrameMgrGetTotalSize (fm);
+    reply = (unsigned char *) malloc (total_size);
+    if (!reply)
+    {
+        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
+        return False;
+    }
+    /*endif*/
+    memset (reply, 0, total_size);
+    FrameMgrSetBuffer (fm, reply);
+
+    FrameMgrPutToken (fm, connect_id);
+    FrameMgrPutToken (fm, geometry_CB->icid);
+
+    _Xi18nSendMessage (ims,
+                       connect_id,
+                       XIM_GEOMETRY,
+                       0,
+                       reply,
+                       total_size);
+    FrameMgrFree (fm);
+    XFree (reply);
+
+    /* XIM_GEOMETRY is an asyncronous protocol,
+       so return immediately. */
+    return True;
+}
+
+int _Xi18nPreeditStartCallback (XIMS ims, IMProtocol *call_data)
+{
+    Xi18n i18n_core = ims->protocol;
+    FrameMgr fm;
+    extern XimFrameRec preedit_start_fr[];
+    register int total_size;
+    unsigned char *reply = NULL;
+    IMPreeditCBStruct *preedit_CB =
+        (IMPreeditCBStruct*) &call_data->preedit_callback;
+    CARD16 connect_id = call_data->any.connect_id;
+
+    fm = FrameMgrInit (preedit_start_fr,
+                       NULL,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+    total_size = FrameMgrGetTotalSize (fm);
+    reply = (unsigned char *) malloc (total_size);
+    if (!reply)
+    {
+        _Xi18nSendMessage(ims, connect_id, XIM_ERROR, 0, 0, 0);
+        return False;
+    }
+    /*endif*/
+    memset (reply, 0, total_size);
+    FrameMgrSetBuffer (fm, reply);
+
+    FrameMgrPutToken (fm, connect_id);
+    FrameMgrPutToken (fm, preedit_CB->icid);
+
+    _Xi18nSendMessage (ims,
+                       connect_id,
+                       XIM_PREEDIT_START,
+                       0,
+                       reply,
+                       total_size);
+    FrameMgrFree (fm);
+    XFree (reply);
+
+    return True;
+}
+
+int _Xi18nPreeditDrawCallback (XIMS ims, IMProtocol *call_data)
+{
+    Xi18n i18n_core = ims->protocol;
+    FrameMgr fm;
+    extern XimFrameRec preedit_draw_fr[];
+    register int total_size;
+    unsigned char *reply = NULL;
+    IMPreeditCBStruct *preedit_CB =
+        (IMPreeditCBStruct *) &call_data->preedit_callback;
+    XIMPreeditDrawCallbackStruct *draw =
+        (XIMPreeditDrawCallbackStruct *) &preedit_CB->todo.draw;
+    CARD16 connect_id = call_data->any.connect_id;
+    register int feedback_count;
+    register int i;
+    BITMASK32 status = 0x0;
+
+    if (draw->text->length == 0)
+        status = 0x00000001;
+    else if (draw->text->feedback[0] == 0)
+        status = 0x00000002;
+    /*endif*/
+
+    fm = FrameMgrInit (preedit_draw_fr,
+                       NULL,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+
+    /* set length of preedit string */
+    FrameMgrSetSize (fm, draw->text->length);
+
+    /* set iteration count for list of feedback */
+    for (i = 0;  draw->text->feedback[i] != 0;  i++)
+        ;
+    /*endfor*/
+    feedback_count = i;
+    FrameMgrSetIterCount (fm, feedback_count);
+
+    total_size = FrameMgrGetTotalSize (fm);
+    reply = (unsigned char *) malloc (total_size);
+    if (!reply)
+    {
+        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
+        return False;
+    }
+    /*endif*/
+    memset (reply, 0, total_size);
+    FrameMgrSetBuffer (fm, reply);
+
+    FrameMgrPutToken (fm, connect_id);
+    FrameMgrPutToken (fm, preedit_CB->icid);
+    FrameMgrPutToken (fm, draw->caret);
+    FrameMgrPutToken (fm, draw->chg_first);
+    FrameMgrPutToken (fm, draw->chg_length);
+    FrameMgrPutToken (fm, status);
+    FrameMgrPutToken (fm, draw->text->length);
+    FrameMgrPutToken (fm, draw->text->string);
+    for (i = 0;  i < feedback_count;  i++)
+        FrameMgrPutToken (fm, draw->text->feedback[i]);
+    /*endfor*/
+    
+    _Xi18nSendMessage (ims,
+                       connect_id,
+                       XIM_PREEDIT_DRAW,
+                       0,
+                       reply,
+                       total_size);
+    FrameMgrFree (fm);
+    XFree (reply);
+
+    /* XIM_PREEDIT_DRAW is an asyncronous protocol, so return immediately. */
+    return True;
+}
+
+int _Xi18nPreeditCaretCallback (XIMS ims, IMProtocol *call_data)
+{
+    Xi18n i18n_core = ims->protocol;
+    FrameMgr fm;
+    extern XimFrameRec preedit_caret_fr[];
+    register int total_size;
+    unsigned char *reply = NULL;
+    IMPreeditCBStruct *preedit_CB =
+        (IMPreeditCBStruct*) &call_data->preedit_callback;
+    XIMPreeditCaretCallbackStruct *caret =
+        (XIMPreeditCaretCallbackStruct *) &preedit_CB->todo.caret;
+    CARD16 connect_id = call_data->any.connect_id;
+
+    fm = FrameMgrInit (preedit_caret_fr,
+                       NULL,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+
+    total_size = FrameMgrGetTotalSize (fm);
+    reply = (unsigned char *) malloc (total_size);
+    if (!reply)
+    {
+        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
+        return False;
+    }
+    /*endif*/
+    memset (reply, 0, total_size);
+    FrameMgrSetBuffer (fm, reply);
+
+    FrameMgrPutToken (fm, connect_id);
+    FrameMgrPutToken (fm, preedit_CB->icid);
+    FrameMgrPutToken (fm, caret->position);
+    FrameMgrPutToken (fm, caret->direction);
+    FrameMgrPutToken (fm, caret->style);
+
+    _Xi18nSendMessage (ims,
+                       connect_id,
+                       XIM_PREEDIT_CARET,
+                       0,
+                       reply,
+                       total_size);
+    FrameMgrFree (fm);
+    XFree (reply);
+
+    return True;
+}
+
+int _Xi18nPreeditDoneCallback (XIMS ims, IMProtocol *call_data)
+{
+    Xi18n i18n_core = ims->protocol;
+    FrameMgr fm;
+    extern XimFrameRec preedit_done_fr[];
+    register int total_size;
+    unsigned char *reply = NULL;
+    IMPreeditCBStruct *preedit_CB =
+        (IMPreeditCBStruct *) &call_data->preedit_callback;
+    CARD16 connect_id = call_data->any.connect_id;
+
+    fm = FrameMgrInit (preedit_done_fr,
+                       NULL,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+
+    total_size = FrameMgrGetTotalSize (fm);
+    reply = (unsigned char *) malloc (total_size);
+    if (!reply)
+    {
+        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
+        return False;
+    }
+    /*endif*/
+    memset (reply, 0, total_size);
+    FrameMgrSetBuffer (fm, reply);
+
+    FrameMgrPutToken (fm, connect_id);
+    FrameMgrPutToken (fm, preedit_CB->icid);
+
+    _Xi18nSendMessage (ims,
+                       connect_id,
+                       XIM_PREEDIT_DONE,
+                       0,
+                       reply,
+                       total_size);
+    FrameMgrFree (fm);
+    XFree (reply);
+
+    /* XIM_PREEDIT_DONE is an asyncronous protocol, so return immediately. */
+    return True;
+}
+
+int _Xi18nStatusStartCallback (XIMS ims, IMProtocol *call_data)
+{
+    Xi18n i18n_core = ims->protocol;
+    FrameMgr fm;
+    extern XimFrameRec status_start_fr[];
+    register int total_size;
+    unsigned char *reply = NULL;
+    IMStatusCBStruct *status_CB =
+        (IMStatusCBStruct*) &call_data->status_callback;
+    CARD16 connect_id = call_data->any.connect_id;
+
+    fm = FrameMgrInit (status_start_fr,
+                       NULL,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+    total_size = FrameMgrGetTotalSize (fm);
+    reply = (unsigned char *) malloc (total_size);
+    if (!reply)
+    {
+        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
+        return False;
+    }
+    /*endif*/
+    memset (reply, 0, total_size);
+    FrameMgrSetBuffer (fm, reply);
+
+    FrameMgrPutToken (fm, connect_id);
+    FrameMgrPutToken (fm, status_CB->icid);
+
+    _Xi18nSendMessage (ims,
+                       connect_id,
+                       XIM_STATUS_START,
+                       0,
+                       reply,
+                       total_size);
+    FrameMgrFree (fm);
+    XFree (reply);
+
+    /* XIM_STATUS_START is an asyncronous protocol, so return immediately. */
+    return True;
+}
+
+int _Xi18nStatusDrawCallback (XIMS ims, IMProtocol *call_data)
+{
+    Xi18n i18n_core = ims->protocol;
+    FrameMgr fm = (FrameMgr)0;
+    extern XimFrameRec status_draw_text_fr[];
+    extern XimFrameRec status_draw_bitmap_fr[];
+    register int total_size = 0;
+    unsigned char *reply = NULL;
+    IMStatusCBStruct *status_CB =
+        (IMStatusCBStruct *) &call_data->status_callback;
+    XIMStatusDrawCallbackStruct *draw =
+        (XIMStatusDrawCallbackStruct *) &status_CB->todo.draw;
+    CARD16 connect_id = call_data->any.connect_id;
+    register int feedback_count;
+    register int i;
+    BITMASK32 status = 0x0;
+
+    switch (draw->type)
+    {
+    case XIMTextType:
+        fm = FrameMgrInit (status_draw_text_fr,
+                           NULL,
+                           _Xi18nNeedSwap (i18n_core, connect_id));
+
+        if (draw->data.text->length == 0)
+            status = 0x00000001;
+        else if (draw->data.text->feedback[0] == 0)
+            status = 0x00000002;
+        /*endif*/
+        
+        /* set length of status string */
+        FrameMgrSetSize(fm, draw->data.text->length);
+        /* set iteration count for list of feedback */
+        for (i = 0;  draw->data.text->feedback[i] != 0;  i++)
+            ;
+        /*endfor*/
+        feedback_count = i;
+        FrameMgrSetIterCount (fm, feedback_count);
+
+        total_size = FrameMgrGetTotalSize (fm);
+        reply = (unsigned char *) malloc (total_size);
+        if (!reply)
+        {
+            _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
+            return False;
+        }
+        /*endif*/
+        memset (reply, 0, total_size);
+        FrameMgrSetBuffer (fm, reply);
+
+        FrameMgrPutToken (fm, connect_id);
+        FrameMgrPutToken (fm, status_CB->icid);
+        FrameMgrPutToken (fm, draw->type);
+        FrameMgrPutToken (fm, status);
+        FrameMgrPutToken (fm, draw->data.text->length);
+        FrameMgrPutToken (fm, draw->data.text->string);
+        for (i = 0;  i < feedback_count;  i++)
+            FrameMgrPutToken (fm, draw->data.text->feedback[i]);
+        /*endfor*/
+        break;
+
+    case XIMBitmapType:
+        fm = FrameMgrInit (status_draw_bitmap_fr,
+                           NULL,
+                           _Xi18nNeedSwap (i18n_core, connect_id));
+
+        total_size = FrameMgrGetTotalSize (fm);
+        reply = (unsigned char *) malloc (total_size);
+        if (!reply)
+        {
+            _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
+            return False;
+        }
+        /*endif*/
+        memset (reply, 0, total_size);
+        FrameMgrSetBuffer (fm, reply);
+
+        FrameMgrPutToken (fm, connect_id);
+        FrameMgrPutToken (fm, status_CB->icid);
+        FrameMgrPutToken (fm, draw->data.bitmap);
+        break;
+    }
+    /*endswitch*/
+    _Xi18nSendMessage (ims,
+                       connect_id,
+                       XIM_STATUS_DRAW,
+                       0,
+                       reply,
+                       total_size);
+    FrameMgrFree (fm);
+    XFree (reply);
+
+    /* XIM_STATUS_DRAW is an asyncronous protocol, so return immediately. */
+    return True;
+}
+
+int _Xi18nStatusDoneCallback (XIMS ims, IMProtocol *call_data)
+{
+    Xi18n i18n_core = ims->protocol;
+    FrameMgr fm;
+    extern XimFrameRec status_done_fr[];
+    register int total_size;
+    unsigned char *reply = NULL;
+    IMStatusCBStruct *status_CB =
+        (IMStatusCBStruct *) &call_data->status_callback;
+    CARD16 connect_id = call_data->any.connect_id;
+
+    fm = FrameMgrInit (status_done_fr,
+                       NULL,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+
+    total_size = FrameMgrGetTotalSize (fm);
+    reply = (unsigned char *) malloc (total_size);
+    if (!reply)
+    {
+        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
+        return False;
+    }
+    /*endif*/
+    memset (reply, 0, total_size);
+    FrameMgrSetBuffer (fm, reply);
+
+    FrameMgrPutToken (fm, connect_id);
+    FrameMgrPutToken (fm, status_CB->icid);
+
+    _Xi18nSendMessage (ims,
+                       connect_id,
+                       XIM_STATUS_DONE,
+                       0,
+                       reply,
+                       total_size);
+    FrameMgrFree (fm);
+    XFree (reply);
+
+    /* XIM_STATUS_DONE is an asyncronous protocol, so return immediately. */
+    return True;
+}
+
+int _Xi18nStringConversionCallback (XIMS ims, IMProtocol *call_data)
+{
+    Xi18n i18n_core = ims->protocol;
+    FrameMgr fm;
+    extern XimFrameRec str_conversion_fr[];
+    register int total_size;
+    unsigned char *reply = NULL;
+    IMStrConvCBStruct *call_back =
+        (IMStrConvCBStruct *) &call_data->strconv_callback;
+    XIMStringConversionCallbackStruct *strconv =
+        (XIMStringConversionCallbackStruct *) &call_back->strconv;
+    CARD16 connect_id = call_data->any.connect_id;
+
+    fm = FrameMgrInit (str_conversion_fr,
+                       NULL,
+                      _Xi18nNeedSwap (i18n_core, connect_id));
+
+    total_size = FrameMgrGetTotalSize (fm);
+    reply = (unsigned char *) malloc (total_size);
+    if (!reply)
+    {
+        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
+        return False;
+    }
+    /*endif*/
+    memset (reply, 0, total_size);
+    FrameMgrSetBuffer (fm, reply);
+
+    FrameMgrPutToken (fm, connect_id);
+    FrameMgrPutToken (fm, call_back->icid);
+    FrameMgrPutToken (fm, strconv->position);
+    FrameMgrPutToken (fm, strconv->direction);
+    FrameMgrPutToken (fm, strconv->operation);
+
+    _Xi18nSendMessage (ims, connect_id,
+                       XIM_STR_CONVERSION,
+                       0,
+                       reply,
+                       total_size);
+    FrameMgrFree (fm);
+    XFree (reply);
+
+    /* XIM_STR_CONVERSION is a syncronous protocol,
+       so should wait here for XIM_STR_CONVERSION_REPLY. */
+    if (i18n_core->methods.wait (ims,
+                                 connect_id,
+                                 XIM_STR_CONVERSION_REPLY,
+                                 0) == False)
+    {
+        return False;
+    }
+    /*endif*/
+    return True;
+}
diff --git a/client/x11/IMdkit/i18nIMProto.c b/client/x11/IMdkit/i18nIMProto.c
new file mode 100644 (file)
index 0000000..618da9d
--- /dev/null
@@ -0,0 +1,773 @@
+/******************************************************************
+Copyright 1993, 1994 by Digital Equipment Corporation, Maynard, Massachusetts,
+Copyright 1993, 1994 by Hewlett-Packard Company
+Copyright 1994, 1995 by Sun Microsystems, Inc.
+                        All Rights Reserved
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the names of Digital or MIT not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+DIGITAL AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL WARRANTIES WITH REGARD
+TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS, IN NO EVENT SHALL DIGITAL AND HEWLETT-PACKARD COMPANY BE LIABLE
+FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+  Author: Hiroyuki Miyamoto  Digital Equipment Corporation
+                             miyamoto@jrd.dec.com
+         Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
+
+    This version tidied and debugged by Steve Underwood May 1999
+******************************************************************/
+
+/* Protocol Packet frames */
+
+#include "FrameMgr.h"
+
+/* Data type definitions */
+
+static XimFrameRec ximattr_fr[] =
+{
+    _FRAME(BIT16),             /* attribute ID */
+    _FRAME(BIT16),             /* type of the value */
+    _FRAME(BIT16),             /* length of im-attribute */
+    _FRAME(BARRAY),            /* im-attribute */
+    _PAD4(2),
+    _FRAME(EOL),
+};
+
+static XimFrameRec xicattr_fr[] =
+{
+    _FRAME(BIT16),             /* attribute ID */
+    _FRAME(BIT16),             /* type of the value */
+    _FRAME(BIT16),             /* length of ic-attribute */
+    _FRAME(BARRAY),            /* ic-attribute */
+    _PAD4(2),
+    _FRAME(EOL),
+};
+
+static XimFrameRec ximattribute_fr[] =
+{
+    _FRAME(BIT16),             /* attribute ID */
+    _FRAME(BIT16),             /* value length */
+    _FRAME(BARRAY),             /* value */
+    _PAD4(1),
+    _FRAME(EOL),
+};
+
+static XimFrameRec xicattribute_fr[] =
+{
+    _FRAME(BIT16),             /* attribute ID */
+    _FRAME(BIT16),             /* value length */
+    _FRAME(BARRAY),             /* value */
+    _PAD4(1),
+    _FRAME(EOL),
+};
+
+static XimFrameRec ximtriggerkey_fr[] =
+{
+    _FRAME(BIT32),             /* keysym */
+    _FRAME(BIT32),             /* modifier */
+    _FRAME(BIT32),             /* modifier mask */
+    _FRAME(EOL),
+};
+
+static XimFrameRec encodinginfo_fr[] =
+{
+    _FRAME(BIT16),             /* length of encoding info */
+    _FRAME(BARRAY),            /* encoding info */
+    _PAD4(2),
+    _FRAME(EOL),
+};
+
+static XimFrameRec str_fr[] =
+{
+    _FRAME(BIT8),              /* number of byte */
+    _FRAME(BARRAY),            /* string */
+    _FRAME(EOL),
+};
+
+static XimFrameRec xpcs_fr[] =
+{
+    _FRAME(BIT16),             /* length of string in bytes */
+    _FRAME(BARRAY),            /* string */
+    _PAD4(2),
+};
+
+static XimFrameRec ext_fr[] =
+{
+    _FRAME(BIT8),              /* extension major-opcode */
+    _FRAME(BIT8),              /* extension minor-opcode */
+    _FRAME(BIT16),             /* length of extension name */
+    _FRAME(BARRAY),            /* extension name */
+    _PAD4(1),
+    _FRAME(EOL),
+};
+
+static XimFrameRec inputstyle_fr[] =
+{
+    _FRAME(BIT32),             /* inputstyle */
+    _FRAME(EOL),
+};
+/* Protocol definitions */
+
+xim_externaldef XimFrameRec attr_head_fr[] =
+{
+    _FRAME(BIT16),     /* attribute id */
+    _FRAME(BIT16),     /* attribute length */
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec short_fr[] =
+{
+    _FRAME(BIT16),     /* value */
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec long_fr[] =
+{
+    _FRAME(BIT32),     /* value */
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec xrectangle_fr[] =
+{
+    _FRAME(BIT16),     /* x */
+    _FRAME(BIT16),     /* y */
+    _FRAME(BIT16),     /* width */
+    _FRAME(BIT16),     /* height */
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec xpoint_fr[] =
+{
+    _FRAME(BIT16),     /* x */
+    _FRAME(BIT16),     /* y */
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec fontset_fr[] =
+{
+    _FRAME(BIT16),     /* length of base font name */
+    _FRAME(BARRAY),    /* base font name list */
+    _PAD4(2),          /* unused */
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec input_styles_fr[] =
+{
+    _FRAME(BIT16),             /* number of list */
+    _PAD4(1),                  /* unused */
+    _FRAME(ITER),              /* XIMStyle list */
+    _FRAME(POINTER),
+    _PTR(inputstyle_fr),
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec packet_header_fr[] =
+{
+    _FRAME(BIT8),              /* major-opcode */
+    _FRAME(BIT8),              /* minor-opcode */
+    _FRAME(BIT16),             /* length */
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec error_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _FRAME(BIT16),             /* flag */
+    _FRAME(BIT16),             /* Error Code */
+    _FRAME(BIT16),             /* length of error detail */
+    _FRAME(BIT16),             /* type of error detail */
+    _FRAME(BARRAY),            /* error detail */
+    _PAD4(1),
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec connect_fr[] =
+{
+    _FRAME(BIT8),              /* byte order */
+    _PAD2(1),                  /* unused */
+    _FRAME(BIT16),             /* client-major-protocol-version */
+    _FRAME(BIT16),             /* client-minor-protocol-version */
+    _BYTE_COUNTER(BIT16, 1),   /* length of client-auth-protocol-names */
+    _FRAME(ITER),              /* client-auth-protocol-names */
+    _FRAME(POINTER),
+    _PTR(xpcs_fr),
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec connect_reply_fr[] =
+{
+    _FRAME(BIT16),             /* server-major-protocol-version */
+    _FRAME(BIT16),             /* server-minor-protocol-version */
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec auth_required_fr[] =
+{
+    _FRAME(BIT8),              /* auth-protocol-index */
+    _FRAME(BIT8),              /* auth-data1 */
+    _FRAME(BARRAY),            /* auth-data2 */
+    _PAD4(3),
+    _FRAME(EOL),
+};
+
+
+xim_externaldef XimFrameRec auth_reply_fr[] =
+{
+    _FRAME(BIT8),
+    _FRAME(BARRAY),
+    _PAD4(2),
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec auth_next_fr[] =
+{
+    _FRAME(BIT8),              /* auth-data1 */
+    _FRAME(BARRAY),            /* auth-data2 */
+    _PAD4(2),
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec auth_setup_fr[] =
+{
+    _BYTE_COUNTER(BIT16, 2),   /* number of client-auth-protocol-names */
+    _PAD4(1),                  /* unused */
+    _FRAME(ITER),              /* server-auth-protocol-names */
+    _FRAME(POINTER),
+    _PTR(xpcs_fr),
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec auth_ng_fr[] =
+{
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec disconnect_fr[] =
+{
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec disconnect_reply_fr[] =
+{
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec open_fr[] =
+{
+    _FRAME(POINTER),           /* locale name */
+    _PTR(str_fr),
+    _PAD4(1),
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec open_reply_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _BYTE_COUNTER(BIT16, 1),   /* byte length of IM attributes supported */
+    _FRAME(ITER),              /* IM attribute supported */
+    _FRAME(POINTER),
+    _PTR(ximattr_fr),
+    _BYTE_COUNTER(BIT16, 2),   /* number of IC attribute supported */
+    _PAD4(1),                  /* unused */
+    _FRAME(ITER),              /* IC attribute supported */
+    _FRAME(POINTER),
+    _PTR(xicattr_fr),
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec close_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _PAD4(1),                  /* unused */
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec close_reply_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _PAD4(1),                  /* unused */
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec register_triggerkeys_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _PAD4(1),                  /* unused */
+    _BYTE_COUNTER(BIT32, 1),    /* byte length of on-keys */
+    _FRAME(ITER),              /* on-keys list */
+    _FRAME(POINTER),
+    _PTR(ximtriggerkey_fr),
+    _BYTE_COUNTER(BIT32, 1),   /* byte length of off-keys */
+    _FRAME(ITER),              /* off-keys list */
+    _FRAME(POINTER),
+    _PTR(ximtriggerkey_fr),
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec trigger_notify_fr[] =
+{
+    _FRAME(BIT16),             /* input-mehotd-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _FRAME(BIT32),             /* flag */
+    _FRAME(BIT32),             /* index of keys list */
+    _FRAME(BIT32),             /* client-select-event-mask */
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec trigger_notify_reply_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec set_event_mask_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _FRAME(BIT32),             /* forward-event-mask */
+    _FRAME(BIT32),             /* synchronous-event-mask */
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec encoding_negotiation_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _BYTE_COUNTER(BIT16, 1),   /* byte length of encodings listed by name */
+    _FRAME(ITER),              /* supported list of encoding in IM library */
+    _FRAME(POINTER),
+    _PTR(str_fr),
+    _PAD4(1),
+    _BYTE_COUNTER(BIT16, 2),   /* byte length of encodings listed by
+                                       detailed data */
+    _PAD4(1),
+    _FRAME(ITER),              /* list of encodings supported in the
+                                  IM library */
+    _FRAME(POINTER),
+    _PTR(encodinginfo_fr),
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec encoding_negotiation_reply_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* category of the encoding determined */
+    _FRAME(BIT16),             /* index of the encoding dterminated */
+    _PAD4(1),
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec query_extension_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _BYTE_COUNTER(BIT16, 1),   /* byte length of extensions supported
+                                  by the IM library */
+    _FRAME(ITER),              /* extensions supported by the IM library */
+    _FRAME(POINTER),
+    _PTR(str_fr),
+    _PAD4(1),
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec query_extension_reply_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _BYTE_COUNTER(BIT16, 1),   /* byte length of extensions supported
+                                  by the IM server */
+    _FRAME(ITER),              /* list of extensions supported by the
+                                  IM server */
+    _FRAME(POINTER),
+    _PTR(ext_fr),
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec get_im_values_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _BYTE_COUNTER(BIT16, 1),   /* byte length of im-attribute-id */
+    _FRAME(ITER),              /* im-attribute-id */
+    _FRAME(BIT16),
+    _PAD4(1),
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec get_im_values_reply_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _BYTE_COUNTER(BIT16, 1),   /* byte length of im-attribute returned */
+    _FRAME(ITER),              /* im-attribute returned */
+    _FRAME(POINTER),
+    _PTR(ximattribute_fr),
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec create_ic_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _BYTE_COUNTER(BIT16, 1),   /* byte length of ic-attributes */
+    _FRAME(ITER),              /* ic-attributes */
+    _FRAME(POINTER),
+    _PTR(xicattribute_fr),
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec create_ic_reply_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec destroy_ic_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec destroy_ic_reply_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec set_ic_values_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _BYTE_COUNTER(BIT16, 2),   /* byte length of ic-attributes */
+    _PAD4(1),
+    _FRAME(ITER),              /* ic-attribute */
+    _FRAME(POINTER),
+    _PTR(xicattribute_fr),
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec set_ic_values_reply_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec get_ic_values_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _BYTE_COUNTER(BIT16, 1),   /* byte length of ic-attribute-id */
+    _FRAME(ITER),              /* ic-attribute */
+    _FRAME(BIT16),
+    _PAD4(2),
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec get_ic_values_reply_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _BYTE_COUNTER(BIT16, 2),   /* byte length of ic-attribute */
+    _PAD4(1),
+    _FRAME(ITER),              /* ic-attribute */
+    _FRAME(POINTER),
+    _PTR(xicattribute_fr),
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec set_ic_focus_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec unset_ic_focus_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec forward_event_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _FRAME(BIT16),             /* flag */
+    _FRAME(BIT16),             /* sequence number */
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec wire_keyevent_fr[] = {
+    _FRAME(BIT8),              /* type */
+    _FRAME(BIT8),              /* detail */
+    _FRAME(BIT16),             /* serial number */
+    _FRAME(BIT32),             /* time */
+    _FRAME(BIT32),             /* root */
+    _FRAME(BIT32),             /* window */
+    _FRAME(BIT32),             /* subwindow */
+    _FRAME(BIT16),             /* rootX */
+    _FRAME(BIT16),             /* rootY */
+    _FRAME(BIT16),             /* X */
+    _FRAME(BIT16),             /* Y */
+    _FRAME(BIT16),             /* state */
+    _FRAME(BIT8),              /* sameScreen */
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec sync_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec sync_reply_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _FRAME(EOL),
+};
+
+#if 0
+xim_externaldef XimFrameRec commit_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _FRAME(BIT16),             /* flag */
+    _FRAME(BIT16),             /* byte length of committed string */
+    _FRAME(BARRAY),            /* committed string */
+    _PAD4(1),
+    _BYTE_COUNTER(BIT16, 1),   /* byte length of keysym */
+    _FRAME(ITER),              /* keysym */
+    _FRAME(BIT32),
+    _PAD4(1),
+    _FRAME(EOL),
+};
+#endif
+
+xim_externaldef XimFrameRec commit_chars_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _FRAME(BIT16),             /* flag */
+    _FRAME(BIT16),             /* byte length of committed string */
+    _FRAME(BARRAY),            /* committed string */
+    _PAD4(1),
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec commit_both_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _FRAME(BIT16),             /* flag */
+    _PAD4(1),                  /* unused */
+    _FRAME(BIT32),             /* keysym */
+    _FRAME(BIT16),             /* byte length of committed string */
+    _FRAME(BARRAY),            /* committed string */
+    _PAD4(2),
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec reset_ic_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec reset_ic_reply_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _FRAME(BIT16),             /* byte length of committed string */
+    _FRAME(BARRAY),            /* committed string */
+    _PAD4(2),
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec geometry_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec str_conversion_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _FRAME(BIT32),             /* XIMStringConversionPosition */
+    _FRAME(BIT32),             /* XIMStringConversionType */
+    _FRAME(BIT32),             /* XIMStringConversionOperation */
+    _FRAME(BIT16),             /* length to multiply the
+                                  XIMStringConversionType */
+    _FRAME(BIT16),             /* length of the string to be
+                                  substituted */
+#if 0
+    _FRAME(BARRAY),            /* string */
+    _PAD4(1),
+#endif
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec str_conversion_reply_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _FRAME(BIT32),             /* XIMStringConversionFeedback */
+    _FRAME(BIT16),             /* length of the retrieved string */
+    _FRAME(BARRAY),            /* retrieved string */
+    _PAD4(2),
+    _BYTE_COUNTER(BIT16, 2),   /* number of feedback array */
+    _PAD4(1),
+    _FRAME(ITER),              /* feedback array */
+    _FRAME(BIT32),
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec preedit_start_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec preedit_start_reply_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _FRAME(BIT32),             /* return value */
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec preedit_draw_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _FRAME(BIT32),             /* caret */
+    _FRAME(BIT32),             /* chg_first */
+    _FRAME(BIT32),             /* chg_length */
+    _FRAME(BIT32),             /* status */
+    _FRAME(BIT16),             /* length of preedit string */
+    _FRAME(BARRAY),            /* preedit string */
+    _PAD4(2),
+    _BYTE_COUNTER(BIT16, 2),   /* number of feedback array */
+    _PAD4(1),
+    _FRAME(ITER),              /* feedback array */
+    _FRAME(BIT32),
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec preedit_caret_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _FRAME(BIT32),             /* position */
+    _FRAME(BIT32),             /* direction */
+    _FRAME(BIT32),             /* style */
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec preedit_caret_reply_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _FRAME(BIT32),             /* position */
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec preedit_done_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec status_start_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec status_draw_text_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _FRAME(BIT32),             /* type */
+    _FRAME(BIT32),             /* status */
+    _FRAME(BIT16),             /* length of status string */
+    _FRAME(BARRAY),            /* status string */
+    _PAD4(2),
+    _BYTE_COUNTER(BIT16, 2),   /* number of feedback array */
+    _PAD4(1),
+    _FRAME(ITER),              /* feedback array */
+    _FRAME(BIT32),
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec status_draw_bitmap_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _FRAME(BIT32),             /* type */
+    _FRAME(BIT32),             /* pixmap data */
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec status_done_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec ext_set_event_mask_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _FRAME(BIT32),             /* filter-event-mask */
+    _FRAME(BIT32),             /* intercept-event-mask */
+    _FRAME(BIT32),             /* select-event-mask */
+    _FRAME(BIT32),             /* forward-event-mask */
+    _FRAME(BIT32),             /* synchronous-event-mask */
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec ext_forward_keyevent_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _FRAME(BIT16),             /* flag */
+    _FRAME(BIT16),             /* sequence number */
+    _FRAME(BIT8),              /* xEvent.u.u.type */
+    _FRAME(BIT8),              /* keycode */
+    _FRAME(BIT16),             /* state */
+    _FRAME(BIT32),             /* time */
+    _FRAME(BIT32),             /* window */
+    _FRAME(EOL),
+};
+
+xim_externaldef XimFrameRec ext_move_fr[] =
+{
+    _FRAME(BIT16),             /* input-method-ID */
+    _FRAME(BIT16),             /* input-context-ID */
+    _FRAME(BIT16),             /* X */
+    _FRAME(BIT16),             /* Y */
+    _FRAME(EOL),
+};
diff --git a/client/x11/IMdkit/i18nIc.c b/client/x11/IMdkit/i18nIc.c
new file mode 100644 (file)
index 0000000..61b576f
--- /dev/null
@@ -0,0 +1,1106 @@
+/******************************************************************
+         Copyright 1994, 1995 by Sun Microsystems, Inc.
+         Copyright 1993, 1994 by Hewlett-Packard Company
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear
+in supporting documentation, and that the name of Sun Microsystems, Inc.
+and Hewlett-Packard not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior permission.
+Sun Microsystems, Inc. and Hewlett-Packard make no representations about
+the suitability of this software for any purpose.  It is provided "as is"
+without express or implied warranty.
+SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL
+WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+  Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
+
+    This version tidied and debugged by Steve Underwood May 1999
+******************************************************************/
+
+#include <X11/Xlib.h>
+#include "IMdkit.h"
+#include "Xi18n.h"
+#include "FrameMgr.h"
+#include "XimFunc.h"
+
+#define IC_SIZE 64
+
+/* Set IC values */
+static void SetCardAttribute (XICAttribute *value_ret,
+                              char *p,
+                              XICAttr *ic_attr,
+                              int value_length,
+                              int need_swap,
+                              void **value_buf)
+{
+    FrameMgr fm;
+
+    /*endif*/
+    if (value_length == sizeof (CARD8))
+    {
+        memmove (*value_buf, p, value_length);
+    }
+    else if (value_length == sizeof (CARD16))
+    {
+        INT16 value;
+        extern XimFrameRec short_fr[];
+
+        fm = FrameMgrInit (short_fr, (char *) p, need_swap);
+        /* get data */
+        FrameMgrGetToken (fm, value);
+        FrameMgrFree (fm);
+        memmove (*value_buf, &value, value_length);
+    }
+    else if (value_length == sizeof(CARD32))
+    {
+        INT32 value;
+        extern XimFrameRec long_fr[];
+        
+        fm = FrameMgrInit (long_fr, (char *) p, need_swap);
+        /* get data */
+        FrameMgrGetToken (fm, value);
+        FrameMgrFree (fm);
+        memmove (*value_buf, &value, value_length);
+    }
+    /*endif*/
+    value_ret->attribute_id = ic_attr->attribute_id;
+    value_ret->name = ic_attr->name;
+    value_ret->name_length = ic_attr->length;
+    value_ret->type = ic_attr->type;
+    value_ret->value_length = value_length;
+    value_ret->value = *value_buf;
+    *value_buf += value_length;
+}
+
+static void SetFontAttribute (XICAttribute *value_ret,
+                              char *p,
+                              XICAttr *ic_attr,
+                              int value_length,
+                              int need_swap,
+                              void **value_buf)
+{
+    char *base_name;
+    CARD16 base_length;
+    FrameMgr fm;
+    extern XimFrameRec fontset_fr[];
+
+    fm = FrameMgrInit (fontset_fr, (char *) p, need_swap);
+    /* get data */
+    FrameMgrGetToken (fm, base_length);
+    FrameMgrSetSize (fm, base_length);
+
+    /*endif*/
+    FrameMgrGetToken (fm, base_name);
+    FrameMgrFree(fm);
+    strncpy ((char *) (*value_buf), base_name, base_length);
+    ((char *) *value_buf)[base_length] = (char) 0;
+
+    value_ret->attribute_id = ic_attr->attribute_id;
+    value_ret->name = ic_attr->name;
+    value_ret->name_length = ic_attr->length;
+    value_ret->type = ic_attr->type;
+    value_ret->value_length = value_length;
+    value_ret->value = *value_buf;
+
+    *value_buf += (base_length + 1);
+}
+
+static void SetPointAttribute (XICAttribute *value_ret,
+                               char *p,
+                               XICAttr *ic_attr,
+                               int value_length,
+                               int need_swap,
+                               void **value_buf)
+{
+    XPoint *buf;
+    FrameMgr fm;
+    extern XimFrameRec xpoint_fr[];
+
+    buf = (XPoint *) (*value_buf);
+
+    fm = FrameMgrInit (xpoint_fr, (char *) p, need_swap);
+    /* get data */
+    FrameMgrGetToken (fm, buf->x);
+    FrameMgrGetToken (fm, buf->y);
+    FrameMgrFree (fm);
+
+    value_ret->attribute_id = ic_attr->attribute_id;
+    value_ret->name = ic_attr->name;
+    value_ret->name_length = ic_attr->length;
+    value_ret->type = ic_attr->type;
+    value_ret->value_length = value_length;
+    value_ret->value = (char *) buf;
+
+    *value_buf += value_length;
+}
+
+static void SetRectAttribute (XICAttribute *value_ret,
+                              char *p,
+                              XICAttr *ic_attr,
+                              int value_length,
+                              int need_swap,
+                              void **value_buf)
+{
+    XRectangle *buf;
+    FrameMgr fm;
+    extern XimFrameRec xrectangle_fr[];
+
+    buf = (XRectangle *) (*value_buf);
+    fm = FrameMgrInit (xrectangle_fr, (char *) p, need_swap);
+    /* get data */
+    FrameMgrGetToken (fm, buf->x);
+    FrameMgrGetToken (fm, buf->y);
+    FrameMgrGetToken (fm, buf->width);
+    FrameMgrGetToken (fm, buf->height);
+    FrameMgrFree (fm);
+
+    value_ret->attribute_id = ic_attr->attribute_id;
+    value_ret->name = ic_attr->name;
+    value_ret->name_length = ic_attr->length;
+    value_ret->type = ic_attr->type;
+    value_ret->value_length = value_length;
+    value_ret->value = (char *) buf;
+
+    *value_buf += value_length;
+}
+
+#if 0
+static void SetHotKeyAttribute (XICAttribute *value_ret,
+                                char *p,
+                                XICAttr *ic_attr,
+                                int value_length,
+                                int need_swap,
+                                void **value_buf)
+{
+    INT32 list_number;
+    XIMTriggerKey *hotkeys;
+
+    memmove (&list_number, p, sizeof(INT32)); p += sizeof(INT32);
+
+    hotkeys = (XIMTriggerKey *) (*value_buf);
+
+    memmove (hotkeys, p, list_number*sizeof (XIMTriggerKey));
+
+    value_ret->attribute_id = ic_attr->attribute_id;
+    value_ret->name = ic_attr->name;
+    value_ret->name_length = ic_attr->length;
+    value_ret->type = ic_attr->type;
+    value_ret->value_length = value_length;
+    value_ret->value = (char *) hotkeys;
+
+    *value_buf += value_length;
+}
+#endif
+
+/* get IC values */
+static void GetAttrHeader (unsigned char *rec,
+                           XICAttribute *list,
+                           int need_swap)
+{
+    FrameMgr fm;
+    extern XimFrameRec attr_head_fr[];
+
+    fm = FrameMgrInit (attr_head_fr, (char *) rec, need_swap);
+    /* put data */
+    FrameMgrPutToken (fm, list->attribute_id);
+    FrameMgrPutToken (fm, list->value_length);
+    FrameMgrFree (fm);
+}
+
+static void GetCardAttribute (char *rec, XICAttribute *list, int need_swap)
+{
+    FrameMgr fm;
+    unsigned char *recp = (unsigned char *) rec;
+
+    GetAttrHeader (recp, list, need_swap);
+    recp += sizeof (CARD16)*2;
+
+    if (list->value_length == sizeof (CARD8))
+    {
+        memmove (recp, list->value, list->value_length);
+    }
+    else if (list->value_length == sizeof (CARD16))
+    {
+        INT16 *value = (INT16 *) list->value;
+        extern XimFrameRec short_fr[];
+
+        fm = FrameMgrInit (short_fr, (char *) recp, need_swap);
+        /* put data */
+        FrameMgrPutToken (fm, *value);
+        FrameMgrFree (fm);
+    }
+    else if (list->value_length == sizeof (CARD32))
+    {
+        INT32 *value = (INT32 *) list->value;
+        extern XimFrameRec long_fr[];
+
+        fm = FrameMgrInit (long_fr, (char *) recp, need_swap);
+        /* put data */
+        FrameMgrPutToken (fm, *value);
+        FrameMgrFree (fm);
+    }
+    /*endif*/
+}
+
+static void GetFontAttribute(char *rec, XICAttribute *list, int need_swap)
+{
+    FrameMgr fm;
+    extern XimFrameRec fontset_fr[];
+    char *base_name = (char *) list->value;
+    unsigned char *recp = (unsigned char *) rec;
+
+    GetAttrHeader (recp, list, need_swap);
+    recp += sizeof (CARD16)*2;
+
+    fm = FrameMgrInit (fontset_fr, (char *)recp, need_swap);
+    /* put data */
+    FrameMgrSetSize (fm, list->value_length);
+    FrameMgrPutToken (fm, list->value_length);
+    FrameMgrPutToken (fm, base_name);
+    FrameMgrFree (fm);
+}
+
+static void GetRectAttribute (char *rec, XICAttribute *list, int need_swap)
+{
+    FrameMgr fm;
+    extern XimFrameRec xrectangle_fr[];
+    XRectangle *rect = (XRectangle *) list->value;
+    unsigned char *recp = (unsigned char *) rec;
+
+    GetAttrHeader (recp, list, need_swap);
+    recp += sizeof(CARD16)*2;
+
+    fm = FrameMgrInit (xrectangle_fr, (char *) recp, need_swap);
+    /* put data */
+    FrameMgrPutToken (fm, rect->x);
+    FrameMgrPutToken (fm, rect->y);
+    FrameMgrPutToken (fm, rect->width);
+    FrameMgrPutToken (fm, rect->height);
+    FrameMgrFree (fm);
+}
+
+static void GetPointAttribute (char *rec, XICAttribute *list, int need_swap)
+{
+    FrameMgr fm;
+    extern XimFrameRec xpoint_fr[];
+    XPoint *rect = (XPoint *) list->value;
+    unsigned char *recp = (unsigned char *) rec;
+
+    GetAttrHeader (recp, list, need_swap);
+    recp += sizeof(CARD16)*2;
+
+    fm = FrameMgrInit (xpoint_fr, (char *) recp, need_swap);
+    /* put data */
+    FrameMgrPutToken (fm, rect->x);
+    FrameMgrPutToken (fm, rect->y);
+    FrameMgrFree (fm);
+}
+
+static int ReadICValue (Xi18n i18n_core,
+                        CARD16 icvalue_id,
+                        int value_length,
+                        void *p,
+                        XICAttribute *value_ret,
+                        CARD16 *number_ret,
+                        int need_swap,
+                        void **value_buf)
+{
+    XICAttr *ic_attr = i18n_core->address.xic_attr;
+    int i;
+
+    *number_ret = (CARD16) 0;
+
+    for (i = 0;  i < i18n_core->address.ic_attr_num;  i++, ic_attr++)
+    {
+        if (ic_attr->attribute_id == icvalue_id)
+            break;
+        /*endif*/
+    }
+    /*endfor*/
+    switch (ic_attr->type)
+    {
+    case XimType_NEST:
+        {
+            int total_length = 0;
+            CARD16 attribute_ID;
+            INT16 attribute_length;
+            unsigned char *p1 = (unsigned char *) p;
+            CARD16 ic_len = 0;
+            CARD16 number;
+            FrameMgr fm;
+            extern XimFrameRec attr_head_fr[];
+
+            while (total_length < value_length)
+            {
+                fm = FrameMgrInit (attr_head_fr, (char *) p1, need_swap);
+                /* get data */
+                FrameMgrGetToken (fm, attribute_ID);
+                FrameMgrGetToken (fm, attribute_length);
+                FrameMgrFree (fm);
+                p1 += sizeof (CARD16)*2;
+                ReadICValue (i18n_core,
+                             attribute_ID,
+                             attribute_length,
+                             p1,
+                             (value_ret + ic_len),
+                             &number,
+                             need_swap,
+                             value_buf);
+                ic_len++;
+                *number_ret += number;
+                p1 += attribute_length;
+                p1 += IMPAD (attribute_length);
+                total_length += (CARD16) sizeof(CARD16)*2
+                                + (INT16) attribute_length
+                                + IMPAD (attribute_length);
+            }
+           /*endwhile*/
+            return ic_len;
+        }
+
+    case XimType_CARD8:
+    case XimType_CARD16:
+    case XimType_CARD32:
+    case XimType_Window:
+        SetCardAttribute (value_ret, p, ic_attr, value_length, need_swap, value_buf);
+        *number_ret = (CARD16) 1;
+        return *number_ret;
+
+    case XimType_XFontSet:
+        SetFontAttribute (value_ret, p, ic_attr, value_length, need_swap, value_buf);
+        *number_ret = (CARD16) 1;
+        return *number_ret;
+
+    case XimType_XRectangle:
+        SetRectAttribute (value_ret, p, ic_attr, value_length, need_swap, value_buf);
+        *number_ret = (CARD16) 1;
+        return *number_ret;
+
+    case XimType_XPoint:
+        SetPointAttribute(value_ret, p, ic_attr, value_length, need_swap, value_buf);
+        *number_ret = (CARD16) 1;
+        return *number_ret;
+
+#if 0
+    case XimType_XIMHotKeyTriggers:
+        SetHotKeyAttribute (value_ret, p, ic_attr, value_length, need_swap, value_buf);
+       *number_ret = (CARD16) 1;
+       return *number_ret;
+#endif
+    }
+    /*endswitch*/
+    return 0;
+}
+
+static XICAttribute *CreateNestedList (CARD16 attr_id,
+                                       XICAttribute *list,
+                                       int number,
+                                       int need_swap)
+{
+    XICAttribute *nest_list = NULL;
+    register int i;
+    char *values = NULL;
+    char *valuesp;
+    int value_length = 0;
+
+    if (number == 0)
+        return NULL;
+    /*endif*/
+    for (i = 0;  i < number;  i++)
+    {
+        value_length += sizeof (CARD16)*2;
+        value_length += list[i].value_length;
+        value_length += IMPAD (list[i].value_length);
+    }
+    /*endfor*/
+    if ((values = (char *) malloc (value_length)) == NULL)
+        return NULL;
+    /*endif*/
+    memset (values, 0, value_length);
+
+    valuesp = values;
+    for (i = 0;  i < number;  i++)
+    {
+        switch (list[i].type)
+        {
+        case XimType_CARD8:
+        case XimType_CARD16:
+        case XimType_CARD32:
+        case XimType_Window:
+            GetCardAttribute (valuesp, &list[i], need_swap);
+            break;
+
+        case XimType_XFontSet:
+            GetFontAttribute (valuesp, &list[i], need_swap);
+            break;
+
+        case XimType_XRectangle:
+            GetRectAttribute (valuesp, &list[i], need_swap);
+            break;
+
+        case XimType_XPoint:
+            GetPointAttribute (valuesp, &list[i], need_swap);
+            break;
+
+#if 0
+        case XimType_XIMHotKeyTriggers:
+            GetHotKeyAttribute (valuesp, &list[i], need_swap);
+            break;
+#endif
+        }
+        /*endswitch*/
+        valuesp += sizeof (CARD16)*2;
+        valuesp += list[i].value_length;
+        valuesp += IMPAD(list[i].value_length);
+    }
+    /*endfor*/
+    
+    nest_list = (XICAttribute *) malloc (sizeof (XICAttribute));
+    if (nest_list == NULL)
+        return NULL;
+    /*endif*/
+    memset (nest_list, 0, sizeof (XICAttribute));
+    nest_list->value = (void *) malloc (value_length);
+    if (nest_list->value == NULL)
+        return NULL;
+    /*endif*/
+    memset (nest_list->value, 0, sizeof (value_length));
+
+    nest_list->attribute_id = attr_id;
+    nest_list->value_length = value_length;
+    memmove (nest_list->value, values, value_length);
+
+    XFree (values);
+    return nest_list;
+}
+
+static Bool IsNestedList (Xi18n i18n_core, CARD16 icvalue_id)
+{
+    XICAttr *ic_attr = i18n_core->address.xic_attr;
+    int i;
+
+    for (i = 0;  i < i18n_core->address.ic_attr_num;  i++, ic_attr++)
+    {
+        if (ic_attr->attribute_id == icvalue_id)
+        {
+            if (ic_attr->type == XimType_NEST)
+                return True;
+            /*endif*/
+            return False;
+        }
+        /*endif*/
+    }
+    /*endfor*/
+    return False;
+}
+
+static Bool IsSeparator (Xi18n i18n_core, CARD16 icvalue_id)
+{
+    return (i18n_core->address.separatorAttr_id == icvalue_id);
+}
+
+static int GetICValue (Xi18n i18n_core,
+                       XICAttribute *attr_ret,
+                       CARD16 *id_list,
+                       int list_num)
+{
+    XICAttr *xic_attr = i18n_core->address.xic_attr;
+    register int i;
+    register int j;
+    register int n;
+
+    i =
+    n = 0;
+    if (IsNestedList (i18n_core, id_list[i]))
+    {
+        i++;
+        while (i < list_num  &&  !IsSeparator (i18n_core, id_list[i]))
+        {
+            for (j = 0;  j < i18n_core->address.ic_attr_num;  j++)
+            {
+                if (xic_attr[j].attribute_id == id_list[i])
+                {
+                    attr_ret[n].attribute_id = xic_attr[j].attribute_id;
+                    attr_ret[n].name_length = xic_attr[j].length;
+                    attr_ret[n].name = malloc (xic_attr[j].length + 1);
+                   strcpy(attr_ret[n].name, xic_attr[j].name);
+                    attr_ret[n].type = xic_attr[j].type;
+                    n++;
+                    i++;
+                    break;
+                }
+                /*endif*/
+            }
+            /*endfor*/
+        }
+        /*endwhile*/
+    }
+    else
+    {
+        for (j = 0;  j < i18n_core->address.ic_attr_num;  j++)
+        {
+            if (xic_attr[j].attribute_id == id_list[i])
+            {
+                attr_ret[n].attribute_id = xic_attr[j].attribute_id;
+                attr_ret[n].name_length = xic_attr[j].length;
+                attr_ret[n].name = malloc (xic_attr[j].length + 1);
+               strcpy(attr_ret[n].name, xic_attr[j].name);
+                attr_ret[n].type = xic_attr[j].type;
+                n++;
+                break;
+            }
+            /*endif*/
+        }
+        /*endfor*/
+    }
+    /*endif*/
+    return n;
+}
+
+static void SwapAttributes (XICAttribute *list,
+                          int number){
+    FrameMgr fm;
+    CARD16 c16;
+    extern XimFrameRec short_fr[];
+    CARD32 c32;
+    extern XimFrameRec long_fr[];
+    XPoint xpoint;
+    extern XimFrameRec xpoint_fr[];
+    XRectangle xrect;
+    extern XimFrameRec xrectangle_fr[];
+    int i;
+
+    for (i = 0; i < number; ++i, ++list) {
+       if (list->value == NULL)
+           continue;
+       switch (list->type) {
+       case XimType_CARD16:
+           fm = FrameMgrInit (short_fr, (char *)list->value, 1);
+           FrameMgrGetToken (fm, c16);
+           memmove(list->value, &c16, sizeof(CARD16));
+           FrameMgrFree (fm);
+           break;
+       case XimType_CARD32:
+       case XimType_Window:
+           fm = FrameMgrInit (long_fr, (char *)list->value, 1);
+           FrameMgrGetToken (fm, c32);
+           memmove(list->value, &c32, sizeof(CARD32));
+           FrameMgrFree (fm);
+           break;
+       case XimType_XRectangle:
+           fm = FrameMgrInit (xrectangle_fr, (char *)list->value, 1);
+           FrameMgrGetToken (fm, xrect);
+           memmove(list->value, &xrect, sizeof(XRectangle));
+           FrameMgrFree (fm);
+           break;
+       case XimType_XPoint:
+           fm = FrameMgrInit (xpoint_fr, (char *)list->value, 1);
+           FrameMgrGetToken (fm, xpoint);
+           memmove(list->value, &xpoint, sizeof(XPoint));
+           FrameMgrFree (fm);
+           break;
+       default:
+           break;
+       }
+    }
+}
+
+/* called from CreateICMessageProc and SetICValueMessageProc */
+void _Xi18nChangeIC (XIMS ims,
+                     IMProtocol *call_data,
+                     unsigned char *p,
+                     int create_flag)
+{
+    Xi18n i18n_core = ims->protocol;
+    FrameMgr fm;
+    FmStatus status;
+    CARD16 byte_length;
+    register int total_size;
+    unsigned char *reply = NULL;
+    register int i;
+    register int attrib_num;
+    XICAttribute *attrib_list;
+    XICAttribute pre_attr[IC_SIZE];
+    XICAttribute sts_attr[IC_SIZE];
+    XICAttribute ic_attr[IC_SIZE];
+    CARD16 preedit_ic_num = 0;
+    CARD16 status_ic_num = 0;
+    CARD16 ic_num = 0;
+    CARD16 connect_id = call_data->any.connect_id;
+    IMChangeICStruct *changeic = (IMChangeICStruct *) &call_data->changeic;
+    extern XimFrameRec create_ic_fr[];
+    extern XimFrameRec create_ic_reply_fr[];
+    extern XimFrameRec set_ic_values_fr[];
+    extern XimFrameRec set_ic_values_reply_fr[];
+    CARD16 input_method_ID;
+    void *value_buf = NULL;
+    void *value_buf_ptr;
+
+    register int total_value_length = 0;
+
+    memset (pre_attr, 0, sizeof (XICAttribute)*IC_SIZE);
+    memset (sts_attr, 0, sizeof (XICAttribute)*IC_SIZE);
+    memset (ic_attr, 0, sizeof (XICAttribute)*IC_SIZE);
+
+    if (create_flag == True)
+    {
+        fm = FrameMgrInit (create_ic_fr,
+                           (char *) p,
+                           _Xi18nNeedSwap (i18n_core, connect_id));
+        /* get data */
+        FrameMgrGetToken (fm, input_method_ID);
+        FrameMgrGetToken (fm, byte_length);
+    }
+    else
+    {
+        fm = FrameMgrInit (set_ic_values_fr,
+                           (char *) p,
+                           _Xi18nNeedSwap (i18n_core, connect_id));
+        /* get data */
+        FrameMgrGetToken (fm, input_method_ID);
+        FrameMgrGetToken (fm, changeic->icid);
+        FrameMgrGetToken (fm, byte_length);
+    }
+    /*endif*/
+    attrib_list = (XICAttribute *) malloc (sizeof (XICAttribute)*IC_SIZE);
+    if (!attrib_list)
+    {
+        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
+        return;
+    }
+    /*endif*/
+    memset (attrib_list, 0, sizeof(XICAttribute)*IC_SIZE);
+
+    attrib_num = 0;
+    while (FrameMgrIsIterLoopEnd (fm, &status) == False)
+    {
+        void *value;
+        int value_length;
+        
+        FrameMgrGetToken (fm, attrib_list[attrib_num].attribute_id);
+        FrameMgrGetToken (fm, value_length);
+        FrameMgrSetSize (fm, value_length);
+        attrib_list[attrib_num].value_length = value_length;
+        FrameMgrGetToken (fm, value);
+        attrib_list[attrib_num].value = (void *) malloc (value_length + 1);
+        memmove (attrib_list[attrib_num].value, value, value_length);
+       ((char *)attrib_list[attrib_num].value)[value_length] = '\0';
+        attrib_num++;
+        total_value_length += (value_length + 1);
+    }
+    /*endwhile*/
+
+    value_buf = (void *) malloc (total_value_length);
+    value_buf_ptr = value_buf;
+
+    if (!value_buf)
+    {
+        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
+        for (i = 0;  i < attrib_num;  i++)
+            XFree (attrib_list[i].value);
+        /*endfor*/
+        XFree (attrib_list);
+        return;
+    }
+    /*endif*/
+
+    for (i = 0;  i < attrib_num;  i++)
+    {
+        CARD16 number;
+        
+        if (IsNestedList (i18n_core, attrib_list[i].attribute_id))
+        {
+            if (attrib_list[i].attribute_id
+                == i18n_core->address.preeditAttr_id)
+            {
+                ReadICValue (i18n_core,
+                             attrib_list[i].attribute_id,
+                             attrib_list[i].value_length,
+                             attrib_list[i].value,
+                             &pre_attr[preedit_ic_num],
+                             &number,
+                             _Xi18nNeedSwap(i18n_core, connect_id),
+                             &value_buf_ptr);
+                preedit_ic_num += number;
+            }
+            else if (attrib_list[i].attribute_id == i18n_core->address.statusAttr_id)
+            {
+                ReadICValue (i18n_core,
+                             attrib_list[i].attribute_id,
+                             attrib_list[i].value_length,
+                             attrib_list[i].value,
+                             &sts_attr[status_ic_num],
+                             &number,
+                             _Xi18nNeedSwap (i18n_core, connect_id),
+                             &value_buf_ptr);
+                status_ic_num += number;
+            }
+            else
+            {
+                /* another nested list.. possible? */
+            }
+            /*endif*/
+        }
+        else
+        {
+            ReadICValue (i18n_core,
+                         attrib_list[i].attribute_id,
+                         attrib_list[i].value_length,
+                         attrib_list[i].value,
+                         &ic_attr[ic_num],
+                         &number,
+                         _Xi18nNeedSwap (i18n_core, connect_id),
+                         &value_buf_ptr);
+            ic_num += number;
+        }
+        /*endif*/
+    }
+    /*endfor*/
+    for (i = 0;  i < attrib_num;  i++)
+        XFree (attrib_list[i].value);
+    /*endfor*/
+    XFree (attrib_list);
+
+    FrameMgrFree (fm);
+
+    changeic->preedit_attr_num = preedit_ic_num;
+    changeic->status_attr_num = status_ic_num;
+    changeic->ic_attr_num = ic_num;
+    changeic->preedit_attr = pre_attr;
+    changeic->status_attr = sts_attr;
+    changeic->ic_attr = ic_attr;
+
+    if (i18n_core->address.improto)
+    {
+        if (!(i18n_core->address.improto(ims, call_data))) {
+            XFree (value_buf);
+            return;
+        }
+        /*endif*/
+    }
+
+    XFree (value_buf);
+
+    /*endif*/
+    if (create_flag == True)
+    {
+        fm = FrameMgrInit (create_ic_reply_fr,
+                           NULL,
+                           _Xi18nNeedSwap (i18n_core, connect_id));
+    }
+    else
+    {
+        fm = FrameMgrInit (set_ic_values_reply_fr,
+                           NULL,
+                           _Xi18nNeedSwap (i18n_core, connect_id));
+    }
+    /*endif*/
+    total_size = FrameMgrGetTotalSize (fm);
+    reply = (unsigned char *) malloc (total_size);
+    
+    if (!reply)
+    {
+        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
+        return;
+    }
+    /*endif*/
+    memset (reply, 0, total_size);
+    FrameMgrSetBuffer (fm, reply);
+
+    FrameMgrPutToken (fm, input_method_ID);
+    FrameMgrPutToken (fm, changeic->icid);
+
+    if (create_flag == True)
+    {
+        _Xi18nSendMessage (ims,
+                           connect_id,
+                           XIM_CREATE_IC_REPLY,
+                           0,
+                           reply,
+                           total_size);
+    }
+    else
+    {
+        _Xi18nSendMessage (ims,
+                           connect_id,
+                           XIM_SET_IC_VALUES_REPLY,
+                           0,
+                           reply,
+                           total_size);
+    }
+    /*endif*/
+    if (create_flag == True)
+    {
+        int on_key_num = i18n_core->address.on_keys.count_keys;
+        int off_key_num = i18n_core->address.off_keys.count_keys;
+
+        if (on_key_num == 0  &&  off_key_num == 0)
+        {
+            long mask;
+
+            if (i18n_core->address.imvalue_mask & I18N_FILTERMASK)
+                mask = i18n_core->address.filterevent_mask;
+            else
+                mask = DEFAULT_FILTER_MASK;
+            /*endif*/
+            /* static event flow is default */
+            _Xi18nSetEventMask (ims,
+                                connect_id,
+                                input_method_ID,
+                                changeic->icid,
+                                mask,
+                                ~mask);
+        }
+        /*endif*/
+    }
+    /*endif*/
+    FrameMgrFree (fm);
+    XFree(reply);
+}
+
+/* called from GetICValueMessageProc */
+void _Xi18nGetIC (XIMS ims, IMProtocol *call_data, unsigned char *p)
+{
+    Xi18n i18n_core = ims->protocol;
+    FrameMgr fm;
+    FmStatus status;
+    extern XimFrameRec get_ic_values_fr[];
+    extern XimFrameRec get_ic_values_reply_fr[];
+    CARD16 byte_length;
+    register int total_size;
+    unsigned char *reply = NULL;
+    XICAttribute *preedit_ret = NULL;
+    XICAttribute *status_ret = NULL;
+    register int i;
+    register int number;
+    int iter_count;
+    CARD16 *attrID_list;
+    XICAttribute pre_attr[IC_SIZE];
+    XICAttribute sts_attr[IC_SIZE];
+    XICAttribute ic_attr[IC_SIZE];
+    CARD16 pre_count = 0;
+    CARD16 sts_count = 0;
+    CARD16 ic_count = 0;
+    IMChangeICStruct *getic = (IMChangeICStruct *) &call_data->changeic;
+    CARD16 connect_id = call_data->any.connect_id;
+    CARD16 input_method_ID;
+
+    memset (pre_attr, 0, sizeof (XICAttribute)*IC_SIZE);
+    memset (sts_attr, 0, sizeof (XICAttribute)*IC_SIZE);
+    memset (ic_attr, 0, sizeof (XICAttribute)*IC_SIZE);
+
+    fm = FrameMgrInit (get_ic_values_fr,
+                       (char *) p,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+
+    /* get data */
+    FrameMgrGetToken (fm, input_method_ID);
+    FrameMgrGetToken (fm, getic->icid);
+    FrameMgrGetToken (fm, byte_length);
+
+    attrID_list = (CARD16 *) malloc (sizeof (CARD16)*IC_SIZE);  /* bogus */
+    memset (attrID_list, 0, sizeof (CARD16)*IC_SIZE);
+
+    number = 0;
+    while (FrameMgrIsIterLoopEnd (fm, &status) == False)
+        FrameMgrGetToken (fm, attrID_list[number++]);
+    /*endwhile*/
+    FrameMgrFree (fm);
+
+    i = 0;
+    while (i < number)
+    {
+        int read_number;
+        
+        if (IsNestedList (i18n_core, attrID_list[i]))
+        {
+            if (attrID_list[i] == i18n_core->address.preeditAttr_id)
+            {
+                read_number = GetICValue (i18n_core,
+                                          &pre_attr[pre_count],
+                                          &attrID_list[i],
+                                          number);
+                i += read_number + 1;
+                pre_count += read_number;
+            }
+            else if (attrID_list[i] == i18n_core->address.statusAttr_id)
+            {
+                read_number = GetICValue (i18n_core,
+                                          &sts_attr[sts_count],
+                                          &attrID_list[i],
+                                          number);
+                i += read_number + 1;
+                sts_count += read_number;
+            }
+            else
+            {
+                /* another nested list.. possible? */
+            }
+            /*endif*/
+        }
+        else
+        {
+            read_number = GetICValue (i18n_core,
+                                      &ic_attr[ic_count],
+                                      &attrID_list[i],
+                                      number);
+            i += read_number;
+            ic_count += read_number;
+        }
+        /*endif*/
+    }
+    /*endwhile*/
+    getic->preedit_attr_num = pre_count;
+    getic->status_attr_num = sts_count;
+    getic->ic_attr_num = ic_count;
+    getic->preedit_attr = pre_attr;
+    getic->status_attr = sts_attr;
+    getic->ic_attr = ic_attr;
+    if (i18n_core->address.improto)
+    {
+        if (!(i18n_core->address.improto (ims, call_data)))
+            return;
+        /*endif*/
+       if (_Xi18nNeedSwap (i18n_core, connect_id))
+         SwapAttributes(getic->ic_attr, getic->ic_attr_num);
+    }
+    /*endif*/
+    iter_count = getic->ic_attr_num;
+
+    preedit_ret = CreateNestedList (i18n_core->address.preeditAttr_id,
+                                    getic->preedit_attr,
+                                    getic->preedit_attr_num,
+                                    _Xi18nNeedSwap (i18n_core, connect_id));
+    if (preedit_ret)
+        iter_count++;
+    /*endif*/
+    status_ret = CreateNestedList (i18n_core->address.statusAttr_id,
+                                   getic->status_attr,
+                                   getic->status_attr_num,
+                                   _Xi18nNeedSwap (i18n_core, connect_id));
+    if (status_ret)
+        iter_count++;
+    /*endif*/
+
+    fm = FrameMgrInit (get_ic_values_reply_fr,
+                       NULL,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+
+    /* set iteration count for list of ic_attribute */
+    FrameMgrSetIterCount (fm, iter_count);
+
+    /* set length of BARRAY item in xicattribute_fr */
+    for (i = 0;  i < (int) getic->ic_attr_num;  i++)
+        FrameMgrSetSize (fm, ic_attr[i].value_length);
+    /*endfor*/
+    
+    if (preedit_ret)
+        FrameMgrSetSize (fm, preedit_ret->value_length);
+    /*endif*/
+    if (status_ret)
+        FrameMgrSetSize (fm, status_ret->value_length);
+    /*endif*/
+    total_size = FrameMgrGetTotalSize (fm);
+    reply = (unsigned char *) malloc (total_size);
+    if (reply == NULL)
+    {
+        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
+        return;
+    }
+    /*endif*/
+    memset (reply, 0, total_size);
+    FrameMgrSetBuffer (fm, reply);
+
+    FrameMgrPutToken (fm, input_method_ID);
+    FrameMgrPutToken (fm, getic->icid);
+
+    for (i = 0;  i < (int) getic->ic_attr_num;  i++)
+    {
+        FrameMgrPutToken (fm, ic_attr[i].attribute_id);
+        FrameMgrPutToken (fm, ic_attr[i].value_length);
+        FrameMgrPutToken (fm, ic_attr[i].value);
+    }
+    /*endfor*/
+    if (preedit_ret)
+    {
+        FrameMgrPutToken (fm, preedit_ret->attribute_id);
+        FrameMgrPutToken (fm, preedit_ret->value_length);
+        FrameMgrPutToken (fm, preedit_ret->value);
+    }
+    /*endif*/
+    if (status_ret)
+    {
+        FrameMgrPutToken (fm, status_ret->attribute_id);
+        FrameMgrPutToken (fm, status_ret->value_length);
+        FrameMgrPutToken (fm, status_ret->value);
+    }
+    /*endif*/
+    _Xi18nSendMessage (ims,
+                       connect_id,
+                       XIM_GET_IC_VALUES_REPLY,
+                       0,
+                       reply,
+                       total_size);
+    XFree (reply);
+    XFree (attrID_list);
+
+    for (i = 0;  i < (int) getic->ic_attr_num;  i++)
+    {
+       if (getic->ic_attr[i].name)
+           XFree (getic->ic_attr[i].name);
+       /*endif*/
+        if (getic->ic_attr[i].value)
+            XFree (getic->ic_attr[i].value);
+        /*endif*/
+    }
+    /*endfor*/
+    for (i = 0;  i < (int) getic->preedit_attr_num;  i++)
+    {
+       if (getic->preedit_attr[i].name)
+           XFree (getic->preedit_attr[i].name);
+       /*endif*/
+       if (getic->preedit_attr[i].value)
+           XFree (getic->preedit_attr[i].value);
+       /*endif*/
+    }
+    /*endfor*/
+    for (i = 0;  i < (int) getic->status_attr_num;  i++)
+    {
+       if (getic->status_attr[i].name)
+           XFree (getic->status_attr[i].name);
+       /*endif*/
+       if (getic->status_attr[i].value)
+           XFree (getic->status_attr[i].value);
+       /*endif*/
+    }
+    /*endfor*/
+    
+    if (preedit_ret)
+    {
+        XFree (preedit_ret->value);
+        XFree (preedit_ret);
+    }
+    /*endif*/
+    if (status_ret)
+    {
+        XFree (status_ret->value);
+        XFree (status_ret);
+    }
+    /*endif*/
+    FrameMgrFree (fm);
+}
diff --git a/client/x11/IMdkit/i18nMethod.c b/client/x11/IMdkit/i18nMethod.c
new file mode 100644 (file)
index 0000000..203f831
--- /dev/null
@@ -0,0 +1,1150 @@
+/******************************************************************
+         Copyright 1994, 1995 by Sun Microsystems, Inc.
+         Copyright 1993, 1994 by Hewlett-Packard Company
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear
+in supporting documentation, and that the name of Sun Microsystems, Inc.
+and Hewlett-Packard not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior permission.
+Sun Microsystems, Inc. and Hewlett-Packard make no representations about
+the suitability of this software for any purpose.  It is provided "as is"
+without express or implied warranty.
+SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL
+WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+  Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
+
+    This version tidied and debugged by Steve Underwood May 1999
+******************************************************************/
+
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+#ifndef NEED_EVENTS
+#define NEED_EVENTS
+#endif
+#include <X11/Xproto.h>
+#undef NEED_EVENTS
+#include "FrameMgr.h"
+#include "IMdkit.h"
+#include "Xi18n.h"
+#include "XimFunc.h"
+
+extern Xi18nClient *_Xi18nFindClient (Xi18n, CARD16);
+
+static void *xi18n_setup (Display *, XIMArg *);
+static Status xi18n_openIM (XIMS);
+static Status xi18n_closeIM (XIMS);
+static char *xi18n_setIMValues (XIMS, XIMArg *);
+static char *xi18n_getIMValues (XIMS, XIMArg *);
+static Status xi18n_forwardEvent (XIMS, XPointer);
+static Status xi18n_commit (XIMS, XPointer);
+static int xi18n_callCallback (XIMS, XPointer);
+static int xi18n_preeditStart (XIMS, XPointer);
+static int xi18n_preeditEnd (XIMS, XPointer);
+static int xi18n_syncXlib (XIMS, XPointer);
+
+#ifndef XIM_SERVERS
+#define XIM_SERVERS "XIM_SERVERS"
+#endif
+static Atom XIM_Servers = None;
+
+
+IMMethodsRec Xi18n_im_methods =
+{
+    xi18n_setup,
+    xi18n_openIM,
+    xi18n_closeIM,
+    xi18n_setIMValues,
+    xi18n_getIMValues,
+    xi18n_forwardEvent,
+    xi18n_commit,
+    xi18n_callCallback,
+    xi18n_preeditStart,
+    xi18n_preeditEnd,
+    xi18n_syncXlib,
+};
+
+extern Bool _Xi18nCheckXAddress (Xi18n, TransportSW *, char *);
+extern Bool _Xi18nCheckTransAddress (Xi18n, TransportSW *, char *);
+
+TransportSW _TransR[] =
+{
+    {"X",               1, _Xi18nCheckXAddress},
+#ifdef TCPCONN
+    {"tcp",             3, _Xi18nCheckTransAddress},
+    {"local",           5, _Xi18nCheckTransAddress},
+#endif
+#ifdef DNETCONN
+    {"decnet",          6, _Xi18nCheckTransAddress},
+#endif
+    {(char *) NULL,     0, (Bool (*) ()) NULL}
+};
+
+static Bool GetInputStyles (Xi18n i18n_core, XIMStyles **p_style)
+{
+    Xi18nAddressRec *address = (Xi18nAddressRec *) &i18n_core->address;
+    XIMStyles *p;
+    int        i;
+
+    p = &address->input_styles;
+    if ((*p_style = (XIMStyles *) malloc (sizeof (XIMStyles)
+                                          + p->count_styles*sizeof (XIMStyle)))
+        == NULL)
+    {
+        return False;
+    }
+    /*endif*/
+    (*p_style)->count_styles = p->count_styles;
+    (*p_style)->supported_styles = (XIMStyle *) ((XPointer) *p_style + sizeof (XIMStyles));
+    for (i = 0;  i < (int) p->count_styles;  i++)
+        (*p_style)->supported_styles[i] = p->supported_styles[i];
+    /*endfor*/
+    return True;
+}
+
+static Bool GetOnOffKeys (Xi18n i18n_core, long mask, XIMTriggerKeys **p_key)
+{
+    Xi18nAddressRec *address = (Xi18nAddressRec *) &i18n_core->address;
+    XIMTriggerKeys *p;
+    int        i;
+
+    if (mask & I18N_ON_KEYS)
+        p = &address->on_keys;
+    else
+        p = &address->off_keys;
+    /*endif*/
+    if ((*p_key = (XIMTriggerKeys *) malloc (sizeof(XIMTriggerKeys)
+                                             + p->count_keys*sizeof(XIMTriggerKey)))
+        == NULL)
+    {
+        return False;
+    }
+    /*endif*/
+    (*p_key)->count_keys = p->count_keys;
+    (*p_key)->keylist =
+        (XIMTriggerKey *) ((XPointer) *p_key + sizeof(XIMTriggerKeys));
+    for (i = 0;  i < (int) p->count_keys;  i++)
+    {
+        (*p_key)->keylist[i].keysym = p->keylist[i].keysym;
+        (*p_key)->keylist[i].modifier = p->keylist[i].modifier;
+        (*p_key)->keylist[i].modifier_mask = p->keylist[i].modifier_mask;
+    }
+    /*endfor*/
+    return True;
+}
+
+static Bool GetEncodings(Xi18n i18n_core, XIMEncodings **p_encoding)
+{
+    Xi18nAddressRec *address = (Xi18nAddressRec *) &i18n_core->address;
+    XIMEncodings *p;
+    int        i;
+
+    p = &address->encoding_list;
+
+    if ((*p_encoding = (XIMEncodings *) malloc (sizeof (XIMEncodings)
+                                              + p->count_encodings*sizeof(XIMEncoding))) == NULL)
+    {
+        return False;
+    }
+    /*endif*/
+    (*p_encoding)->count_encodings = p->count_encodings;
+    (*p_encoding)->supported_encodings =
+        (XIMEncoding *) ((XPointer)*p_encoding + sizeof (XIMEncodings));
+    for (i = 0;  i < (int) p->count_encodings;  i++)
+    {
+        (*p_encoding)->supported_encodings[i]
+            = (char *) malloc (strlen (p->supported_encodings[i]) + 1);
+        strcpy ((*p_encoding)->supported_encodings[i],
+                p->supported_encodings[i]);
+    }
+    /*endif*/
+    return True;
+}
+
+static char *ParseArgs (Xi18n i18n_core, int mode, XIMArg *args)
+{
+    Xi18nAddressRec *address = (Xi18nAddressRec *) &i18n_core->address;
+    XIMArg *p;
+
+    if (mode == I18N_OPEN  ||  mode == I18N_SET)
+    {
+        for (p = args;  p->name != NULL;  p++)
+        {
+            if (strcmp (p->name, IMLocale) == 0)
+            {
+                if (address->imvalue_mask & I18N_IM_LOCALE)
+                    return IMLocale;
+                /*endif*/
+                address->im_locale = (char *) malloc (strlen (p->value) + 1);
+                if (!address->im_locale)
+                    return IMLocale;
+                /*endif*/
+                strcpy (address->im_locale, p->value);
+                address->imvalue_mask |= I18N_IM_LOCALE;
+            }
+            else if (strcmp (p->name, IMServerTransport) == 0)
+            {
+                if (address->imvalue_mask & I18N_IM_ADDRESS)
+                    return IMServerTransport;
+                /*endif*/
+                address->im_addr = (char *) malloc (strlen (p->value) + 1);
+                if (!address->im_addr)
+                    return IMServerTransport;
+                /*endif*/
+                strcpy(address->im_addr, p->value);
+                address->imvalue_mask |= I18N_IM_ADDRESS;
+            }
+            else if (strcmp (p->name, IMServerName) == 0)
+            {
+                if (address->imvalue_mask & I18N_IM_NAME)
+                    return IMServerName;
+                /*endif*/
+                address->im_name = (char *) malloc (strlen (p->value) + 1);
+                if (!address->im_name)
+                    return IMServerName;
+                /*endif*/
+                strcpy (address->im_name, p->value);
+                address->imvalue_mask |= I18N_IM_NAME;
+            }
+            else if (strcmp (p->name, IMServerWindow) == 0)
+            {
+                if (address->imvalue_mask & I18N_IMSERVER_WIN)
+                    return IMServerWindow;
+                /*endif*/
+                address->im_window = (Window) p->value;
+                address->imvalue_mask |= I18N_IMSERVER_WIN;
+            }
+            else if (strcmp (p->name, IMInputStyles) == 0)
+            {
+                if (address->imvalue_mask & I18N_INPUT_STYLES)
+                    return IMInputStyles;
+                /*endif*/
+                address->input_styles.count_styles =
+                    ((XIMStyles*)p->value)->count_styles;
+                address->input_styles.supported_styles =
+                    (XIMStyle *) malloc (sizeof (XIMStyle)*address->input_styles.count_styles);
+                if (address->input_styles.supported_styles == (XIMStyle *) NULL)
+                    return IMInputStyles;
+                /*endif*/
+                memmove (address->input_styles.supported_styles,
+                         ((XIMStyles *) p->value)->supported_styles,
+                         sizeof (XIMStyle)*address->input_styles.count_styles);
+                address->imvalue_mask |= I18N_INPUT_STYLES;
+            }
+            else if (strcmp (p->name, IMProtocolHandler) == 0)
+            {
+                address->improto = (IMProtoHandler) p->value;
+                address->imvalue_mask |= I18N_IM_HANDLER;
+            }
+            else if (strcmp (p->name, IMOnKeysList) == 0)
+            {
+                if (address->imvalue_mask & I18N_ON_KEYS)
+                    return IMOnKeysList;
+                /*endif*/
+                address->on_keys.count_keys =
+                    ((XIMTriggerKeys *) p->value)->count_keys;
+                address->on_keys.keylist =
+                    (XIMTriggerKey *) malloc (sizeof (XIMTriggerKey)*address->on_keys.count_keys);
+                if (address->on_keys.keylist == (XIMTriggerKey *) NULL)
+                    return IMOnKeysList;
+                /*endif*/
+                memmove (address->on_keys.keylist,
+                         ((XIMTriggerKeys *) p->value)->keylist,
+                         sizeof (XIMTriggerKey)*address->on_keys.count_keys);
+                address->imvalue_mask |= I18N_ON_KEYS;
+            }
+            else if (strcmp (p->name, IMOffKeysList) == 0)
+            {
+                if (address->imvalue_mask & I18N_OFF_KEYS)
+                    return IMOffKeysList;
+                /*endif*/
+                address->off_keys.count_keys =
+                    ((XIMTriggerKeys *) p->value)->count_keys;
+                address->off_keys.keylist =
+                    (XIMTriggerKey *) malloc (sizeof (XIMTriggerKey)*address->off_keys.count_keys);
+                if (address->off_keys.keylist == (XIMTriggerKey *) NULL)
+                    return IMOffKeysList;
+                /*endif*/
+                memmove (address->off_keys.keylist,
+                         ((XIMTriggerKeys *) p->value)->keylist,
+                         sizeof (XIMTriggerKey)*address->off_keys.count_keys);
+                address->imvalue_mask |= I18N_OFF_KEYS;
+            }
+            else if (strcmp (p->name, IMEncodingList) == 0)
+            {
+                if (address->imvalue_mask & I18N_ENCODINGS)
+                    return IMEncodingList;
+                /*endif*/
+                address->encoding_list.count_encodings =
+                    ((XIMEncodings *) p->value)->count_encodings;
+                address->encoding_list.supported_encodings =
+                    (XIMEncoding *) malloc (sizeof (XIMEncoding)*address->encoding_list.count_encodings);
+                if (address->encoding_list.supported_encodings
+                    == (XIMEncoding *) NULL)
+                {
+                    return IMEncodingList;
+                }
+                /*endif*/
+                memmove (address->encoding_list.supported_encodings,
+                         ((XIMEncodings *) p->value)->supported_encodings,
+                         sizeof (XIMEncoding)*address->encoding_list.count_encodings);
+                address->imvalue_mask |= I18N_ENCODINGS;
+            }
+            else if (strcmp (p->name, IMFilterEventMask) == 0)
+            {
+                if (address->imvalue_mask & I18N_FILTERMASK)
+                    return IMFilterEventMask;
+                /*endif*/
+                address->filterevent_mask = (long) p->value;
+                address->imvalue_mask |= I18N_FILTERMASK;
+            }
+            /*endif*/
+        }
+        /*endfor*/
+        if (mode == I18N_OPEN)
+        {
+            /* check mandatory IM values */
+            if (!(address->imvalue_mask & I18N_IM_LOCALE))
+            {
+                /* locales must be set in IMOpenIM */
+                return IMLocale;
+            }
+            /*endif*/
+            if (!(address->imvalue_mask & I18N_IM_ADDRESS))
+            {
+                /* address must be set in IMOpenIM */
+                return IMServerTransport;
+            }
+            /*endif*/
+        }
+        /*endif*/
+    }
+    else if (mode == I18N_GET)
+    {
+        for (p = args;  p->name != NULL;  p++)
+        {
+            if (strcmp (p->name, IMLocale) == 0)
+            {
+                p->value = (char *) malloc (strlen (address->im_locale) + 1);
+                if (!p->value)
+                    return IMLocale;
+                /*endif*/
+                strcpy (p->value, address->im_locale);
+            }
+            else if (strcmp (p->name, IMServerTransport) == 0)
+            {
+                p->value = (char *) malloc (strlen (address->im_addr) + 1);
+                if (!p->value)
+                    return IMServerTransport;
+                /*endif*/
+                strcpy (p->value, address->im_addr);
+            }
+            else if (strcmp (p->name, IMServerName) == 0)
+            {
+                if (address->imvalue_mask & I18N_IM_NAME)
+                {
+                    p->value = (char *) malloc (strlen (address->im_name) + 1);
+                    if (!p->value)
+                        return IMServerName;
+                    /*endif*/
+                    strcpy (p->value, address->im_name);
+                }
+                else
+                {
+                    return IMServerName;
+                }
+                /*endif*/
+            }
+            else if (strcmp (p->name, IMServerWindow) == 0)
+            {
+                if (address->imvalue_mask & I18N_IMSERVER_WIN)
+                    *((Window *) (p->value)) = address->im_window;
+                else
+                    return IMServerWindow;
+                /*endif*/
+            }
+            else if (strcmp (p->name, IMInputStyles) == 0)
+            {
+                if (GetInputStyles (i18n_core,
+                                    (XIMStyles **) p->value) == False)
+                {
+                    return IMInputStyles;
+                }
+                /*endif*/
+            }
+            else if (strcmp (p->name, IMProtocolHandler) == 0)
+            {
+                if (address->imvalue_mask & I18N_IM_HANDLER)
+                    *((IMProtoHandler *) (p->value)) = address->improto;
+                else
+                    return IMProtocolHandler;
+                /*endif*/
+            }
+            else if (strcmp (p->name, IMOnKeysList) == 0)
+            {
+                if (address->imvalue_mask & I18N_ON_KEYS)
+                {
+                    if (GetOnOffKeys (i18n_core,
+                                      I18N_ON_KEYS,
+                                      (XIMTriggerKeys **) p->value) == False)
+                    {
+                        return IMOnKeysList;
+                    }
+                    /*endif*/
+                }
+                else
+                {
+                    return IMOnKeysList;
+                }
+                /*endif*/
+            }
+            else if (strcmp (p->name, IMOffKeysList) == 0)
+            {
+                if (address->imvalue_mask & I18N_OFF_KEYS)
+                {
+                    if (GetOnOffKeys (i18n_core,
+                                      I18N_OFF_KEYS,
+                                      (XIMTriggerKeys **) p->value) == False)
+                    {
+                        return IMOffKeysList;
+                    }
+                    /*endif*/
+                }
+                else
+                {
+                    return IMOffKeysList;
+                }
+                /*endif*/
+            }
+            else if (strcmp (p->name, IMEncodingList) == 0)
+            {
+                if (address->imvalue_mask & I18N_ENCODINGS)
+                {
+                    if (GetEncodings (i18n_core,
+                                      (XIMEncodings **) p->value) == False)
+                    {
+                        return IMEncodingList;
+                    }
+                    /*endif*/
+                }
+                else
+                {
+                    return IMEncodingList;
+                }
+                /*endif*/
+            }
+            else if (strcmp (p->name, IMFilterEventMask) == 0)
+            {
+                if (address->imvalue_mask & I18N_FILTERMASK)
+                    *((long *) (p->value)) = address->filterevent_mask;
+                else
+                    return IMFilterEventMask;
+                /*endif*/
+            }
+            /*endif*/
+        }
+        /*endfor*/
+    }
+    /*endif*/
+    return NULL;
+}
+
+static int CheckIMName (Xi18n i18n_core)
+{
+    char *address = i18n_core->address.im_addr;
+    int i;
+
+    for (i = 0;  _TransR[i].transportname;  i++)
+    {
+        while (*address == ' '  ||  *address == '\t')
+            address++;
+        /*endwhile*/
+        if (strncmp (address,
+                     _TransR[i].transportname,
+                     _TransR[i].namelen) == 0
+            &&
+            address[_TransR[i].namelen] == '/')
+        {
+            if (_TransR[i].checkAddr (i18n_core,
+                                      &_TransR[i],
+                                      address + _TransR[i].namelen + 1) == True)
+            {
+                return True;
+            }
+            /*endif*/
+            return False;
+        }
+        /*endif*/
+    }
+    /*endfor*/
+    return False;
+}
+
+static int SetXi18nSelectionOwner(Xi18n i18n_core)
+{
+    Display *dpy = i18n_core->address.dpy;
+    Window ims_win = i18n_core->address.im_window;
+    Window root = RootWindow (dpy, DefaultScreen (dpy));
+    Atom realtype;
+    int realformat;
+    unsigned long bytesafter;
+    long *data=NULL;
+    unsigned long length;
+    Atom atom;
+    int i;
+    int found;
+    int forse = False;
+    char buf[256];
+
+    (void)snprintf(buf, 256, "@server=%s", i18n_core->address.im_name);
+    if ((atom = XInternAtom(dpy, buf, False)) == 0)
+        return False;
+    i18n_core->address.selection = atom;
+
+    if (XIM_Servers == None)
+        XIM_Servers = XInternAtom (dpy, XIM_SERVERS, False);
+    /*endif*/
+    XGetWindowProperty (dpy,
+                        root,
+                        XIM_Servers,
+                        0L,
+                        1000000L,
+                        False,
+                        XA_ATOM,
+                        &realtype,
+                        &realformat,
+                        &length,
+                        &bytesafter,
+                        (unsigned char **) (&data));
+    if (realtype != None && (realtype != XA_ATOM || realformat != 32)) {
+        if (data != NULL)
+            XFree ((char *) data);
+        return False;
+    }
+
+    found = False;
+    for (i = 0; i < length; i++) {
+        if (data[i] == atom) {
+            Window owner;
+            found = True;
+            if ((owner = XGetSelectionOwner (dpy, atom)) != ims_win) {
+                if (owner == None  ||  forse == True)
+                    XSetSelectionOwner (dpy, atom, ims_win, CurrentTime);
+                else
+                    return False;
+            }
+            break;
+        }
+    }
+
+    if (found == False) {
+        XSetSelectionOwner (dpy, atom, ims_win, CurrentTime);
+        XChangeProperty (dpy,
+                         root,
+                         XIM_Servers,
+                         XA_ATOM,
+                         32,
+                         PropModePrepend,
+                         (unsigned char *) &atom,
+                         1);
+    }
+    else {
+       /* 
+        * We always need to generate the PropertyNotify to the Root Window 
+        */
+        XChangeProperty (dpy,
+                         root,
+                         XIM_Servers,
+                         XA_ATOM,
+                         32,
+                         PropModePrepend,
+                         (unsigned char *) data,
+                         0);
+    }
+    if (data != NULL)
+        XFree ((char *) data);
+    
+    /* Intern "LOCALES" and "TRANSOPORT" Target Atoms */
+    i18n_core->address.Localename = XInternAtom (dpy, LOCALES, False);
+    i18n_core->address.Transportname = XInternAtom (dpy, TRANSPORT, False);
+    return (XGetSelectionOwner (dpy, atom) == ims_win);
+}
+
+static int DeleteXi18nAtom(Xi18n i18n_core)
+{
+    Display *dpy = i18n_core->address.dpy;
+    Window root = RootWindow (dpy, DefaultScreen (dpy));
+    Atom realtype;
+    int realformat;
+    unsigned long bytesafter;
+    long *data=NULL;
+    unsigned long length;
+    Atom atom;
+    int i, ret;
+    int found;
+    char buf[256];
+
+    (void)snprintf(buf, 256, "@server=%s", i18n_core->address.im_name);
+    if ((atom = XInternAtom(dpy, buf, False)) == 0)
+        return False;
+    i18n_core->address.selection = atom;
+
+    if (XIM_Servers == None)
+        XIM_Servers = XInternAtom (dpy, XIM_SERVERS, False);
+    XGetWindowProperty (dpy,
+                        root,
+                        XIM_Servers,
+                        0L,
+                        1000000L,
+                        False,
+                        XA_ATOM,
+                        &realtype,
+                        &realformat,
+                        &length,
+                        &bytesafter,
+                        (unsigned char **) (&data));
+    if (realtype != XA_ATOM || realformat != 32) {
+        if (data != NULL)
+            XFree ((char *) data);
+        return False;
+    }
+
+    found = False;
+    for (i = 0; i < length; i++) {
+        if (data[i] == atom) {
+            found = True;
+            break;
+        }
+    }
+
+    if (found == True) {
+        for (i=i+1; i<length; i++)
+            data[i-1] = data[i];
+        XChangeProperty (dpy,
+                         root,
+                         XIM_Servers,
+                         XA_ATOM,
+                         32,
+                         PropModeReplace,
+                         (unsigned char *)data,
+                         length-1);
+        ret = True;
+    }
+    else {
+        XChangeProperty (dpy,
+                         root,
+                         XIM_Servers,
+                         XA_ATOM,
+                         32,
+                         PropModePrepend,
+                         (unsigned char *)data,
+                         0);
+        ret = False;
+    }
+    if (data != NULL)
+        XFree ((char *) data);
+    return ret;
+}
+
+
+/* XIM protocol methods */
+static void *xi18n_setup (Display *dpy, XIMArg *args)
+{
+    Xi18n i18n_core;
+    CARD16 endian = 1;
+
+    if ((i18n_core = (Xi18n) malloc (sizeof (Xi18nCore))) == (Xi18n) NULL)
+        return NULL;
+    /*endif*/
+    
+    memset (i18n_core, 0, sizeof (Xi18nCore));
+
+    i18n_core->address.dpy = dpy;
+
+    if (ParseArgs (i18n_core, I18N_OPEN, args) != NULL)
+    {
+        XFree (i18n_core);
+        return NULL;
+    }
+    /*endif*/
+    if (*(char *) &endian)
+        i18n_core->address.im_byteOrder = 'l';
+    else
+        i18n_core->address.im_byteOrder = 'B';
+    /*endif*/
+    
+    /* install IMAttr and ICAttr list in i18n_core */
+    _Xi18nInitAttrList (i18n_core);
+
+    /* install IMExtension list in i18n_core */
+    _Xi18nInitExtension (i18n_core);
+
+    return i18n_core;
+}
+
+static void ReturnSelectionNotify (Xi18n i18n_core, XSelectionRequestEvent *ev)
+{
+    XEvent event;
+    Display *dpy = i18n_core->address.dpy;
+    char buf[4096];
+
+    event.type = SelectionNotify;
+    event.xselection.requestor = ev->requestor;
+    event.xselection.selection = ev->selection;
+    event.xselection.target = ev->target;
+    event.xselection.time = ev->time;
+    event.xselection.property = ev->property;
+    if (ev->target == i18n_core->address.Localename)
+    {
+        snprintf (buf, 4096, "@locale=%s", i18n_core->address.im_locale);
+    }
+    else if (ev->target == i18n_core->address.Transportname)
+    {
+        snprintf (buf, 4096, "@transport=%s", i18n_core->address.im_addr);
+    }
+    /*endif*/
+    XChangeProperty (dpy,
+                     event.xselection.requestor,
+                     ev->target,
+                     ev->target,
+                     8,
+                     PropModeReplace,
+                     (unsigned char *) buf,
+                     strlen (buf));
+    XSendEvent (dpy, event.xselection.requestor, False, NoEventMask, &event);
+    XFlush (i18n_core->address.dpy);
+}
+
+static Bool WaitXSelectionRequest (Display *dpy,
+                                   Window win,
+                                   XEvent *ev,
+                                   XPointer client_data)
+{
+    XIMS ims = (XIMS) client_data;
+    Xi18n i18n_core = ims->protocol;
+
+    if (((XSelectionRequestEvent *) ev)->selection
+        == i18n_core->address.selection)
+    {
+        ReturnSelectionNotify (i18n_core, (XSelectionRequestEvent *) ev);
+        return True;
+    }
+    /*endif*/
+    return False;
+}
+
+static Status xi18n_openIM(XIMS ims)
+{
+    Xi18n i18n_core = ims->protocol;
+    Display *dpy = i18n_core->address.dpy;
+
+    if (!CheckIMName (i18n_core)
+        ||
+        !SetXi18nSelectionOwner (i18n_core)
+        ||
+        !i18n_core->methods.begin (ims))
+    {
+        XFree (i18n_core->address.im_name);
+        XFree (i18n_core->address.im_locale);
+        XFree (i18n_core->address.im_addr);
+        XFree (i18n_core);
+        return False;
+    }
+    /*endif*/
+
+    _XRegisterFilterByType (dpy,
+                            i18n_core->address.im_window,
+                            SelectionRequest,
+                            SelectionRequest,
+                            WaitXSelectionRequest,
+                            (XPointer)ims);
+    XFlush(dpy);
+    return True;
+}
+
+static Status xi18n_closeIM(XIMS ims)
+{
+    Xi18n i18n_core = ims->protocol;
+    Display *dpy = i18n_core->address.dpy;
+
+    DeleteXi18nAtom(i18n_core);
+    if (!i18n_core->methods.end (ims))
+        return False;
+    
+    _XUnregisterFilter (dpy,
+                        i18n_core->address.im_window,
+                        WaitXSelectionRequest,
+                        (XPointer)ims);
+    XFree (i18n_core->address.im_name);
+    XFree (i18n_core->address.im_locale);
+    XFree (i18n_core->address.im_addr);
+    XFree (i18n_core);
+    return True;
+}
+
+static char *xi18n_setIMValues (XIMS ims, XIMArg *args)
+{
+    Xi18n i18n_core = ims->protocol;
+    char *ret;
+
+    if ((ret = ParseArgs (i18n_core, I18N_SET, args)) != NULL)
+        return ret;
+    /*endif*/
+    return NULL;
+}
+
+static char *xi18n_getIMValues (XIMS ims, XIMArg *args)
+{
+    Xi18n i18n_core = ims->protocol;
+    char *ret;
+
+    if ((ret = ParseArgs (i18n_core, I18N_GET, args)) != NULL)
+        return ret;
+    /*endif*/
+    return NULL;
+}
+
+static void EventToWireEvent (XEvent *ev, xEvent *event,
+                             CARD16 *serial, Bool byte_swap)
+{
+    FrameMgr fm;
+    extern XimFrameRec wire_keyevent_fr[];
+    extern XimFrameRec short_fr[];
+    BYTE b;
+    CARD16 c16;
+    CARD32 c32;
+
+    *serial = (CARD16)(ev->xany.serial >> 16);
+    switch (ev->type) {
+      case KeyPress:
+      case KeyRelease:
+       {
+           XKeyEvent *kev = (XKeyEvent*)ev;
+           /* create FrameMgr */
+           fm = FrameMgrInit(wire_keyevent_fr, (char *)(&(event->u)), byte_swap);
+
+           /* set values */
+           b = (BYTE)kev->type;          FrameMgrPutToken(fm, b);
+           b = (BYTE)kev->keycode;       FrameMgrPutToken(fm, b);
+           c16 = (CARD16)(kev->serial & (unsigned long)0xffff);
+                                         FrameMgrPutToken(fm, c16);
+           c32 = (CARD32)kev->time;      FrameMgrPutToken(fm, c32);
+           c32 = (CARD32)kev->root;      FrameMgrPutToken(fm, c32);
+           c32 = (CARD32)kev->window;    FrameMgrPutToken(fm, c32);
+           c32 = (CARD32)kev->subwindow; FrameMgrPutToken(fm, c32);
+           c16 = (CARD16)kev->x_root;    FrameMgrPutToken(fm, c16);
+           c16 = (CARD16)kev->y_root;    FrameMgrPutToken(fm, c16);
+           c16 = (CARD16)kev->x;         FrameMgrPutToken(fm, c16);
+           c16 = (CARD16)kev->y;         FrameMgrPutToken(fm, c16);
+           c16 = (CARD16)kev->state;     FrameMgrPutToken(fm, c16);
+           b = (BYTE)kev->same_screen;   FrameMgrPutToken(fm, b);
+       }
+       break;
+      default:
+         /* create FrameMgr */
+         fm = FrameMgrInit(short_fr, (char *)(&(event->u.u.sequenceNumber)),
+                           byte_swap);
+         c16 = (CARD16)(ev->xany.serial & (unsigned long)0xffff);
+         FrameMgrPutToken(fm, c16);
+         break;
+    }
+    /* free FrameMgr */
+    FrameMgrFree(fm);
+}
+
+static Status xi18n_forwardEvent (XIMS ims, XPointer xp)
+{
+    Xi18n i18n_core = ims->protocol;
+    IMForwardEventStruct *call_data = (IMForwardEventStruct *)xp;
+    FrameMgr fm;
+    extern XimFrameRec forward_event_fr[];
+    register int total_size;
+    unsigned char *reply = NULL;
+    unsigned char *replyp;
+    CARD16 serial;
+    int event_size;
+    Xi18nClient *client;
+
+    client = (Xi18nClient *) _Xi18nFindClient (i18n_core, call_data->connect_id);
+
+    /* create FrameMgr */
+    fm = FrameMgrInit (forward_event_fr,
+                       NULL,
+                       _Xi18nNeedSwap (i18n_core, call_data->connect_id));
+
+    total_size = FrameMgrGetTotalSize (fm);
+    event_size = sizeof (xEvent);
+    reply = (unsigned char *) malloc (total_size + event_size);
+    if (!reply)
+    {
+        _Xi18nSendMessage (ims,
+                           call_data->connect_id,
+                           XIM_ERROR,
+                           0,
+                           0,
+                           0);
+        return False;
+    }
+    /*endif*/
+    memset (reply, 0, total_size + event_size);
+    FrameMgrSetBuffer (fm, reply);
+    replyp = reply;
+
+    call_data->sync_bit = 1;   /* always sync */
+    client->sync = True;
+
+    FrameMgrPutToken (fm, call_data->connect_id);
+    FrameMgrPutToken (fm, call_data->icid);
+    FrameMgrPutToken (fm, call_data->sync_bit);
+
+    replyp += total_size;
+    EventToWireEvent (&(call_data->event),
+                      (xEvent *) replyp,
+                      &serial,
+                      _Xi18nNeedSwap (i18n_core, call_data->connect_id));
+
+    FrameMgrPutToken (fm, serial);
+
+    _Xi18nSendMessage (ims,
+                       call_data->connect_id,
+                       XIM_FORWARD_EVENT,
+                       0,
+                       reply,
+                       total_size + event_size);
+
+    XFree (reply);
+    FrameMgrFree (fm);
+
+    return True;
+}
+
+static Status xi18n_commit (XIMS ims, XPointer xp)
+{
+    Xi18n i18n_core = ims->protocol;
+    IMCommitStruct *call_data = (IMCommitStruct *)xp;
+    FrameMgr fm;
+    extern XimFrameRec commit_chars_fr[];
+    extern XimFrameRec commit_both_fr[];
+    register int total_size;
+    unsigned char *reply = NULL;
+    CARD16 str_length;
+
+    call_data->flag |= XimSYNCHRONUS;  /* always sync */
+
+    if (!(call_data->flag & XimLookupKeySym)
+        &&
+        (call_data->flag & XimLookupChars))
+    {
+        fm = FrameMgrInit (commit_chars_fr,
+                           NULL,
+                           _Xi18nNeedSwap (i18n_core, call_data->connect_id));
+
+        /* set length of STRING8 */
+        str_length = strlen (call_data->commit_string);
+        FrameMgrSetSize (fm, str_length);
+        total_size = FrameMgrGetTotalSize (fm);
+        reply = (unsigned char *) malloc (total_size);
+        if (!reply)
+        {
+            _Xi18nSendMessage (ims,
+                               call_data->connect_id,
+                               XIM_ERROR,
+                               0,
+                               0,
+                               0);
+            return False;
+        }
+        /*endif*/
+        memset (reply, 0, total_size);
+        FrameMgrSetBuffer (fm, reply);
+
+        str_length = FrameMgrGetSize (fm);
+        FrameMgrPutToken (fm, call_data->connect_id);
+        FrameMgrPutToken (fm, call_data->icid);
+        FrameMgrPutToken (fm, call_data->flag);
+        FrameMgrPutToken (fm, str_length);
+        FrameMgrPutToken (fm, call_data->commit_string);
+    }
+    else
+    {
+        fm = FrameMgrInit (commit_both_fr,
+                           NULL,
+                           _Xi18nNeedSwap (i18n_core, call_data->connect_id));
+        /* set length of STRING8 */
+        str_length = strlen (call_data->commit_string);
+        if (str_length > 0)
+            FrameMgrSetSize (fm, str_length);
+        /*endif*/
+        total_size = FrameMgrGetTotalSize (fm);
+        reply = (unsigned char *) malloc (total_size);
+        if (!reply)
+        {
+            _Xi18nSendMessage (ims,
+                               call_data->connect_id,
+                               XIM_ERROR,
+                               0,
+                               0,
+                               0);
+            return False;
+        }
+        /*endif*/
+        FrameMgrSetBuffer (fm, reply);
+        FrameMgrPutToken (fm, call_data->connect_id);
+        FrameMgrPutToken (fm, call_data->icid);
+        FrameMgrPutToken (fm, call_data->flag);
+        FrameMgrPutToken (fm, call_data->keysym);
+        if (str_length > 0)
+        {
+            str_length = FrameMgrGetSize (fm);
+            FrameMgrPutToken (fm, str_length);
+            FrameMgrPutToken (fm, call_data->commit_string);
+        }
+        /*endif*/
+    }
+    /*endif*/
+    _Xi18nSendMessage (ims,
+                       call_data->connect_id,
+                       XIM_COMMIT,
+                       0,
+                       reply,
+                       total_size);
+    FrameMgrFree (fm);
+    XFree (reply);
+
+    return True;
+}
+
+static int xi18n_callCallback (XIMS ims, XPointer xp)
+{
+    IMProtocol *call_data = (IMProtocol *)xp;
+    switch (call_data->major_code)
+    {
+    case XIM_GEOMETRY:
+        return _Xi18nGeometryCallback (ims, call_data);
+
+    case XIM_PREEDIT_START:
+        return _Xi18nPreeditStartCallback (ims, call_data);
+
+    case XIM_PREEDIT_DRAW:
+        return _Xi18nPreeditDrawCallback (ims, call_data);
+
+    case XIM_PREEDIT_CARET:
+        return _Xi18nPreeditCaretCallback (ims, call_data);
+
+    case XIM_PREEDIT_DONE:
+        return _Xi18nPreeditDoneCallback (ims, call_data);
+
+    case XIM_STATUS_START:
+        return _Xi18nStatusStartCallback (ims, call_data);
+
+    case XIM_STATUS_DRAW:
+        return _Xi18nStatusDrawCallback (ims, call_data);
+
+    case XIM_STATUS_DONE:
+        return _Xi18nStatusDoneCallback (ims, call_data);
+
+    case XIM_STR_CONVERSION:
+        return _Xi18nStringConversionCallback (ims, call_data);
+    }
+    /*endswitch*/
+    return False;
+}
+
+/* preeditStart and preeditEnd are used only for Dynamic Event Flow. */
+static int xi18n_preeditStart (XIMS ims, XPointer xp)
+{
+    IMProtocol *call_data = (IMProtocol *)xp;
+    Xi18n i18n_core = ims->protocol;
+    IMPreeditStateStruct *preedit_state =
+        (IMPreeditStateStruct *) &call_data->preedit_state;
+    long mask;
+    int on_key_num = i18n_core->address.on_keys.count_keys;
+    int off_key_num = i18n_core->address.off_keys.count_keys;
+
+    if (on_key_num == 0  &&  off_key_num == 0)
+        return False;
+    /*endif*/
+    if (i18n_core->address.imvalue_mask & I18N_FILTERMASK)
+        mask = i18n_core->address.filterevent_mask;
+    else
+        mask = DEFAULT_FILTER_MASK;
+    /*endif*/
+    _Xi18nSetEventMask (ims,
+                        preedit_state->connect_id,
+                        preedit_state->connect_id,
+                        preedit_state->icid,
+                        mask,
+                        ~mask);
+    return True;
+}
+
+static int xi18n_preeditEnd (XIMS ims, XPointer xp)
+{
+    IMProtocol *call_data = (IMProtocol *)xp;
+    Xi18n i18n_core = ims->protocol;
+    int on_key_num = i18n_core->address.on_keys.count_keys;
+    int off_key_num = i18n_core->address.off_keys.count_keys;
+    IMPreeditStateStruct *preedit_state;
+
+    preedit_state = (IMPreeditStateStruct *) &call_data->preedit_state;
+
+    if (on_key_num == 0  &&  off_key_num == 0)
+        return False;
+    /*endif*/
+    
+    _Xi18nSetEventMask (ims,
+                        preedit_state->connect_id,
+                        preedit_state->connect_id,
+                        preedit_state->icid,
+                        0,
+                        0);
+    return True;
+}
+
+static int xi18n_syncXlib (XIMS ims, XPointer xp)
+{
+    IMProtocol *call_data = (IMProtocol *)xp;
+    Xi18n i18n_core = ims->protocol;
+    IMSyncXlibStruct *sync_xlib;
+
+    extern XimFrameRec sync_fr[];
+    FrameMgr fm;
+    CARD16 connect_id = call_data->any.connect_id;
+    int total_size;
+    unsigned char *reply;
+
+    sync_xlib = (IMSyncXlibStruct *) &call_data->sync_xlib;
+    fm = FrameMgrInit (sync_fr, NULL,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+    total_size = FrameMgrGetTotalSize(fm);
+    reply = (unsigned char *) malloc (total_size);
+    if (!reply) {
+        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
+        return False;
+    }
+    memset (reply, 0, total_size);
+    FrameMgrSetBuffer (fm, reply);
+
+    /* input input-method ID */
+    FrameMgrPutToken (fm, connect_id);
+    /* input input-context ID */
+    FrameMgrPutToken (fm, sync_xlib->icid);
+    _Xi18nSendMessage (ims, connect_id, XIM_SYNC, 0, reply, total_size);
+
+    FrameMgrFree (fm);
+    XFree(reply);
+    return True;
+}
+
diff --git a/client/x11/IMdkit/i18nPtHdr.c b/client/x11/IMdkit/i18nPtHdr.c
new file mode 100644 (file)
index 0000000..d350354
--- /dev/null
@@ -0,0 +1,1848 @@
+/******************************************************************
+         Copyright 1994, 1995 by Sun Microsystems, Inc.
+         Copyright 1993, 1994 by Hewlett-Packard Company
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear
+in supporting documentation, and that the name of Sun Microsystems, Inc.
+and Hewlett-Packard not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior permission.
+Sun Microsystems, Inc. and Hewlett-Packard make no representations about
+the suitability of this software for any purpose.  It is provided "as is"
+without express or implied warranty.
+SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL
+WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+  Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
+
+    This version tidied and debugged by Steve Underwood May 1999
+******************************************************************/
+
+#include <stdlib.h>
+#include <sys/param.h>
+#include <X11/Xlib.h>
+#ifndef NEED_EVENTS
+#define NEED_EVENTS
+#endif
+#include <X11/Xproto.h>
+#undef NEED_EVENTS
+#include "FrameMgr.h"
+#include "IMdkit.h"
+#include "Xi18n.h"
+#include "XimFunc.h"
+
+#ifdef XIM_DEBUG
+#include <stdio.h>
+
+static void    DebugLog(char * msg)
+{
+       fprintf(stderr, msg);
+}
+#endif
+
+extern Xi18nClient *_Xi18nFindClient (Xi18n, CARD16);
+
+static void GetProtocolVersion (CARD16 client_major,
+                                CARD16 client_minor,
+                                CARD16 *server_major,
+                                CARD16 *server_minor)
+{
+    *server_major = client_major;
+    *server_minor = client_minor;
+}
+
+static void ConnectMessageProc (XIMS ims,
+                                IMProtocol *call_data,
+                                unsigned char *p)
+{
+    Xi18n i18n_core = ims->protocol;
+    FrameMgr fm;
+    extern XimFrameRec connect_fr[], connect_reply_fr[];
+    register int total_size;
+    CARD16 server_major_version, server_minor_version;
+    unsigned char *reply = NULL;
+    IMConnectStruct *imconnect =
+        (IMConnectStruct*) &call_data->imconnect;
+    CARD16 connect_id = call_data->any.connect_id;
+
+    fm = FrameMgrInit (connect_fr,
+                       (char *) p,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+
+    /* get data */
+    FrameMgrGetToken (fm, imconnect->byte_order);
+    FrameMgrGetToken (fm, imconnect->major_version);
+    FrameMgrGetToken (fm, imconnect->minor_version);
+
+    FrameMgrFree (fm);
+
+    GetProtocolVersion (imconnect->major_version,
+                        imconnect->minor_version,
+                        &server_major_version,
+                        &server_minor_version);
+#ifdef PROTOCOL_RICH
+    if (i18n_core->address.improto)
+    {
+        if (!(i18n_core->address.improto(ims, call_data)))
+            return;
+        /*endif*/
+    }
+    /*endif*/
+#endif  /* PROTOCOL_RICH */
+
+    fm = FrameMgrInit (connect_reply_fr,
+                       NULL,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+
+    total_size = FrameMgrGetTotalSize (fm);
+    reply = (unsigned char *) malloc (total_size);
+    if (!reply)
+    {
+        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
+        return;
+    }
+    /*endif*/
+    memset (reply, 0, total_size);
+    FrameMgrSetBuffer (fm, reply);
+
+    FrameMgrPutToken (fm, server_major_version);
+    FrameMgrPutToken (fm, server_minor_version);
+
+    _Xi18nSendMessage (ims,
+                       connect_id,
+                       XIM_CONNECT_REPLY,
+                       0,
+                       reply,
+                       total_size);
+
+    FrameMgrFree (fm);
+    XFree (reply);
+}
+
+static void DisConnectMessageProc (XIMS ims, IMProtocol *call_data)
+{
+    Xi18n i18n_core = ims->protocol;
+    unsigned char *reply = NULL;
+    CARD16 connect_id = call_data->any.connect_id;
+
+#ifdef PROTOCOL_RICH
+    if (i18n_core->address.improto)
+    {
+        if (!(i18n_core->address.improto (ims, call_data)))
+            return;
+        /*endif*/
+    }
+    /*endif*/
+#endif  /* PROTOCOL_RICH */
+
+    _Xi18nSendMessage (ims,
+                       connect_id,
+                       XIM_DISCONNECT_REPLY,
+                       0,
+                       reply,
+                       0);
+
+    i18n_core->methods.disconnect (ims, connect_id);
+}
+
+static void OpenMessageProc(XIMS ims, IMProtocol *call_data, unsigned char *p)
+{
+    Xi18n i18n_core = ims->protocol;
+    FrameMgr fm;
+    extern XimFrameRec open_fr[];
+    extern XimFrameRec open_reply_fr[];
+    unsigned char *reply = NULL;
+    int str_size;
+    register int i, total_size;
+    CARD16 connect_id = call_data->any.connect_id;
+    int str_length;
+    char *name;
+    IMOpenStruct *imopen = (IMOpenStruct *) &call_data->imopen;
+
+    fm = FrameMgrInit (open_fr,
+                       (char *) p,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+
+    /* get data */
+    FrameMgrGetToken (fm, str_length);
+    FrameMgrSetSize (fm, str_length);
+    FrameMgrGetToken (fm, name);
+    imopen->lang.length = str_length;
+    imopen->lang.name = malloc (str_length + 1);
+    strncpy (imopen->lang.name, name, str_length);
+    imopen->lang.name[str_length] = (char) 0;
+
+    FrameMgrFree (fm);
+
+    if (i18n_core->address.improto)
+    {
+        if (!(i18n_core->address.improto(ims, call_data)))
+            return;
+        /*endif*/
+    }
+    /*endif*/
+    if ((i18n_core->address.imvalue_mask & I18N_ON_KEYS)
+        ||
+        (i18n_core->address.imvalue_mask & I18N_OFF_KEYS))
+    {
+        _Xi18nSendTriggerKey (ims, connect_id);
+    }
+    /*endif*/
+    XFree (imopen->lang.name);
+
+    fm = FrameMgrInit (open_reply_fr,
+                       NULL,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+
+    /* set iteration count for list of imattr */
+    FrameMgrSetIterCount (fm, i18n_core->address.im_attr_num);
+
+    /* set length of BARRAY item in ximattr_fr */
+    for (i = 0;  i < i18n_core->address.im_attr_num;  i++)
+    {
+        str_size = strlen (i18n_core->address.xim_attr[i].name);
+        FrameMgrSetSize (fm, str_size);
+    }
+    /*endfor*/
+    /* set iteration count for list of icattr */
+    FrameMgrSetIterCount (fm, i18n_core->address.ic_attr_num);
+    /* set length of BARRAY item in xicattr_fr */
+    for (i = 0;  i < i18n_core->address.ic_attr_num;  i++)
+    {
+        str_size = strlen (i18n_core->address.xic_attr[i].name);
+        FrameMgrSetSize (fm, str_size);
+    }
+    /*endfor*/
+
+    total_size = FrameMgrGetTotalSize (fm);
+    reply = (unsigned char *) malloc (total_size);
+    if (!reply)
+    {
+        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
+        return;
+    }
+    /*endif*/
+    memset (reply, 0, total_size);
+    FrameMgrSetBuffer (fm, reply);
+
+    /* input input-method ID */
+    FrameMgrPutToken (fm, connect_id);
+
+    for (i = 0;  i < i18n_core->address.im_attr_num;  i++)
+    {
+        str_size = FrameMgrGetSize (fm);
+        FrameMgrPutToken (fm, i18n_core->address.xim_attr[i].attribute_id);
+        FrameMgrPutToken (fm, i18n_core->address.xim_attr[i].type);
+        FrameMgrPutToken (fm, str_size);
+        FrameMgrPutToken (fm, i18n_core->address.xim_attr[i].name);
+    }
+    /*endfor*/
+    for (i = 0;  i < i18n_core->address.ic_attr_num;  i++)
+    {
+        str_size = FrameMgrGetSize (fm);
+        FrameMgrPutToken (fm, i18n_core->address.xic_attr[i].attribute_id);
+        FrameMgrPutToken (fm, i18n_core->address.xic_attr[i].type);
+        FrameMgrPutToken (fm, str_size);
+        FrameMgrPutToken (fm, i18n_core->address.xic_attr[i].name);
+    }
+    /*endfor*/
+
+    _Xi18nSendMessage (ims,
+                       connect_id,
+                       XIM_OPEN_REPLY,
+                       0,
+                       reply,
+                       total_size);
+
+    FrameMgrFree (fm);
+    XFree (reply);
+}
+
+static void CloseMessageProc (XIMS ims,
+                              IMProtocol *call_data,
+                              unsigned char *p)
+{
+    Xi18n i18n_core = ims->protocol;
+    FrameMgr fm;
+    extern XimFrameRec close_fr[];
+    extern XimFrameRec close_reply_fr[];
+    unsigned char *reply = NULL;
+    register int total_size;
+    CARD16 connect_id = call_data->any.connect_id;
+    CARD16 input_method_ID;
+
+    fm = FrameMgrInit (close_fr,
+                       (char *) p,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+
+    FrameMgrGetToken (fm, input_method_ID);
+
+    FrameMgrFree (fm);
+
+    if (i18n_core->address.improto)
+    {
+        if (!(i18n_core->address.improto (ims, call_data)))
+            return;
+        /*endif*/
+    }
+    /*endif*/
+
+    fm = FrameMgrInit (close_reply_fr,
+                       NULL,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+
+    total_size = FrameMgrGetTotalSize (fm);
+    reply = (unsigned char *) malloc (total_size);
+    if (!reply)
+    {
+        _Xi18nSendMessage (ims,
+                           connect_id,
+                           XIM_ERROR,
+                           0,
+                           0,
+                           0);
+        return;
+    }
+    /*endif*/
+    memset (reply, 0, total_size);
+    FrameMgrSetBuffer (fm, reply);
+
+    FrameMgrPutToken (fm, input_method_ID);
+
+    _Xi18nSendMessage (ims,
+                       connect_id,
+                       XIM_CLOSE_REPLY,
+                       0,
+                       reply,
+                       total_size);
+
+    FrameMgrFree (fm);
+    XFree (reply);
+}
+
+static XIMExt *MakeExtensionList (Xi18n i18n_core,
+                                  XIMStr *lib_extension,
+                                  int number,
+                                  int *reply_number)
+{
+    XIMExt *ext_list;
+    XIMExt *im_ext = (XIMExt *) i18n_core->address.extension;
+    int im_ext_len = i18n_core->address.ext_num;
+    int i;
+    int j;
+
+    *reply_number = 0;
+
+    if (number == 0)
+    {
+        /* query all extensions */
+        *reply_number = im_ext_len;
+    }
+    else
+    {
+        for (i = 0;  i < im_ext_len;  i++)
+        {
+            for (j = 0;  j < (int) number;  j++)
+            {
+                if (strcmp (lib_extension[j].name, im_ext[i].name) == 0)
+                {
+                    (*reply_number)++;
+                    break;
+                }
+                /*endif*/
+            }
+            /*endfor*/
+        }
+        /*endfor*/
+    }
+    /*endif*/
+
+    if (!(*reply_number))
+        return NULL;
+    /*endif*/
+    ext_list = (XIMExt *) malloc (sizeof (XIMExt)*(*reply_number));
+    if (!ext_list)
+        return NULL;
+    /*endif*/
+    memset (ext_list, 0, sizeof (XIMExt)*(*reply_number));
+
+    if (number == 0)
+    {
+        /* query all extensions */
+        for (i = 0;  i < im_ext_len;  i++)
+        {
+            ext_list[i].major_opcode = im_ext[i].major_opcode;
+            ext_list[i].minor_opcode = im_ext[i].minor_opcode;
+            ext_list[i].length = im_ext[i].length;
+            ext_list[i].name = malloc (im_ext[i].length + 1);
+            strcpy (ext_list[i].name, im_ext[i].name);
+        }
+        /*endfor*/
+    }
+    else
+    {
+        int n = 0;
+
+        for (i = 0;  i < im_ext_len;  i++)
+        {
+            for (j = 0;  j < (int)number;  j++)
+            {
+                if (strcmp (lib_extension[j].name, im_ext[i].name) == 0)
+                {
+                    ext_list[n].major_opcode = im_ext[i].major_opcode;
+                    ext_list[n].minor_opcode = im_ext[i].minor_opcode;
+                    ext_list[n].length = im_ext[i].length;
+                    ext_list[n].name = malloc (im_ext[i].length + 1);
+                    strcpy (ext_list[n].name, im_ext[i].name);
+                    n++;
+                    break;
+                }
+                /*endif*/
+            }
+            /*endfor*/
+        }
+        /*endfor*/
+    }
+    /*endif*/
+    return ext_list;
+}
+
+static void QueryExtensionMessageProc (XIMS ims,
+                                       IMProtocol *call_data,
+                                       unsigned char *p)
+{
+    Xi18n i18n_core = ims->protocol;
+    FrameMgr fm;
+    FmStatus status;
+    extern XimFrameRec query_extension_fr[];
+    extern XimFrameRec query_extension_reply_fr[];
+    unsigned char *reply = NULL;
+    int str_size;
+    register int i;
+    register int number;
+    register int total_size;
+    int byte_length;
+    int reply_number = 0;
+    XIMExt *ext_list;
+    IMQueryExtensionStruct *query_ext =
+        (IMQueryExtensionStruct *) &call_data->queryext;
+    CARD16 connect_id = call_data->any.connect_id;
+    CARD16 input_method_ID;
+
+    fm = FrameMgrInit (query_extension_fr,
+                       (char *) p,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+
+    FrameMgrGetToken (fm, input_method_ID);
+    FrameMgrGetToken (fm, byte_length);
+    query_ext->extension = (XIMStr *) malloc (sizeof (XIMStr)*10);
+    memset (query_ext->extension, 0, sizeof (XIMStr)*10);
+    number = 0;
+    while (FrameMgrIsIterLoopEnd (fm, &status) == False)
+    {
+        char *name;
+        int str_length;
+        
+        FrameMgrGetToken (fm, str_length);
+        FrameMgrSetSize (fm, str_length);
+        query_ext->extension[number].length = str_length;
+        FrameMgrGetToken (fm, name);
+        query_ext->extension[number].name = malloc (str_length + 1);
+        strncpy (query_ext->extension[number].name, name, str_length);
+        query_ext->extension[number].name[str_length] = (char) 0;
+        number++;
+    }
+    /*endwhile*/
+    query_ext->number = number;
+
+#ifdef PROTOCOL_RICH
+    if (i18n_core->address.improto)
+    {
+        if (!(i18n_core->address.improto(ims, call_data)))
+            return;
+        /*endif*/
+    }
+    /*endif*/
+#endif  /* PROTOCOL_RICH */
+
+    FrameMgrFree (fm);
+
+    ext_list = MakeExtensionList (i18n_core,
+                                  query_ext->extension,
+                                  number,
+                                  &reply_number);
+
+    for (i = 0;  i < number;  i++)
+        XFree (query_ext->extension[i].name);
+    /*endfor*/
+    XFree (query_ext->extension);
+
+    fm = FrameMgrInit (query_extension_reply_fr,
+                       NULL,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+
+    /* set iteration count for list of extensions */
+    FrameMgrSetIterCount (fm, reply_number);
+
+    /* set length of BARRAY item in ext_fr */
+    for (i = 0;  i < reply_number;  i++)
+    {
+        str_size = strlen (ext_list[i].name);
+        FrameMgrSetSize (fm, str_size);
+    }
+    /*endfor*/
+
+    total_size = FrameMgrGetTotalSize (fm);
+    reply = (unsigned char *) malloc (total_size);
+    if (!reply)
+    {
+        _Xi18nSendMessage (ims,
+                           connect_id,
+                           XIM_ERROR,
+                           0,
+                           0,
+                           0);
+        return;
+    }
+    /*endif*/
+    memset (reply, 0, total_size);
+    FrameMgrSetBuffer (fm, reply);
+
+    FrameMgrPutToken (fm, input_method_ID);
+
+    for (i = 0;  i < reply_number;  i++)
+    {
+        str_size = FrameMgrGetSize (fm);
+        FrameMgrPutToken (fm, ext_list[i].major_opcode);
+        FrameMgrPutToken (fm, ext_list[i].minor_opcode);
+        FrameMgrPutToken (fm, str_size);
+        FrameMgrPutToken (fm, ext_list[i].name);
+    }
+    /*endfor*/
+    _Xi18nSendMessage (ims,
+                       connect_id,
+                       XIM_QUERY_EXTENSION_REPLY,
+                       0,
+                       reply,
+                       total_size);
+    FrameMgrFree (fm);
+    XFree (reply);
+
+    for (i = 0;  i < reply_number;  i++)
+        XFree (ext_list[i].name);
+    /*endfor*/
+    XFree ((char *) ext_list);
+}
+
+static void SyncReplyMessageProc (XIMS ims,
+                                  IMProtocol *call_data,
+                                  unsigned char *p)
+{
+    Xi18n i18n_core = ims->protocol;
+    FrameMgr fm;
+    extern XimFrameRec sync_reply_fr[];
+    CARD16 connect_id = call_data->any.connect_id;
+    Xi18nClient *client;
+    CARD16 input_method_ID;
+    CARD16 input_context_ID;
+
+    client = (Xi18nClient *)_Xi18nFindClient (i18n_core, connect_id);
+    fm = FrameMgrInit (sync_reply_fr,
+                       (char *) p,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+    FrameMgrGetToken (fm, input_method_ID);
+    FrameMgrGetToken (fm, input_context_ID);
+    FrameMgrFree (fm);
+
+    client->sync = False;
+
+    if (ims->sync == True) {
+       ims->sync = False;
+       if (i18n_core->address.improto) {
+           call_data->sync_xlib.major_code = XIM_SYNC_REPLY;
+           call_data->sync_xlib.minor_code = 0;
+           call_data->sync_xlib.connect_id = input_method_ID;
+           call_data->sync_xlib.icid = input_context_ID;
+           i18n_core->address.improto(ims, call_data);
+       }
+    }
+}
+
+static void GetIMValueFromName (Xi18n i18n_core,
+                                CARD16 connect_id,
+                                char *buf,
+                                char *name,
+                                int *length)
+{
+    register int i;
+
+    if (strcmp (name, XNQueryInputStyle) == 0)
+    {
+        XIMStyles *styles = (XIMStyles *) &i18n_core->address.input_styles;
+
+        *length = sizeof (CARD16)*2;   /* count_styles, unused */
+        *length += styles->count_styles*sizeof (CARD32);
+
+        if (buf != NULL)
+        {
+            FrameMgr fm;
+            extern XimFrameRec input_styles_fr[];
+            unsigned char *data = NULL;
+            int total_size;
+            
+            fm = FrameMgrInit (input_styles_fr,
+                               NULL,
+                               _Xi18nNeedSwap (i18n_core, connect_id));
+
+            /* set iteration count for list of input_style */
+            FrameMgrSetIterCount (fm, styles->count_styles);
+
+            total_size = FrameMgrGetTotalSize (fm);
+            data = (unsigned char *) malloc (total_size);
+            if (!data)
+                return;
+            /*endif*/
+            memset (data, 0, total_size);
+            FrameMgrSetBuffer (fm, data);
+
+            FrameMgrPutToken (fm, styles->count_styles);
+            for (i = 0;  i < (int) styles->count_styles;  i++)
+                FrameMgrPutToken (fm, styles->supported_styles[i]);
+            /*endfor*/
+            memmove (buf, data, total_size);
+            FrameMgrFree (fm);
+
+            /* ADDED BY SUZHE */
+            free (data);
+            /* ADDED BY SUZHE */
+        }
+        /*endif*/
+    }
+    /*endif*/
+
+    else if (strcmp (name, XNQueryIMValuesList) == 0) {
+    }
+}
+
+static XIMAttribute *MakeIMAttributeList (Xi18n i18n_core,
+                                          CARD16 connect_id,
+                                          CARD16 *list,
+                                          int *number,
+                                          int *length)
+{
+    XIMAttribute *attrib_list;
+    int list_num;
+    XIMAttr *attr = i18n_core->address.xim_attr;
+    int list_len = i18n_core->address.im_attr_num;
+    register int i;
+    register int j;
+    int value_length;
+    int number_ret = 0;
+
+    *length = 0;
+    list_num = 0;
+    for (i = 0;  i < *number;  i++)
+    {
+        for (j = 0;  j < list_len;  j++)
+        {
+            if (attr[j].attribute_id == list[i])
+            {
+                list_num++;
+                break;
+            }
+            /*endif*/
+        }
+        /*endfor*/
+    }
+    /*endfor*/
+    attrib_list = (XIMAttribute *) malloc (sizeof (XIMAttribute)*list_num);
+    if (!attrib_list)
+        return NULL;
+    /*endif*/
+    memset (attrib_list, 0, sizeof (XIMAttribute)*list_num);
+    number_ret = list_num;
+    list_num = 0;
+    for (i = 0;  i < *number;  i++)
+    {
+        for (j = 0;  j < list_len;  j++)
+        {
+            if (attr[j].attribute_id == list[i])
+            {
+                attrib_list[list_num].attribute_id = attr[j].attribute_id;
+                attrib_list[list_num].name_length = attr[j].length;
+                attrib_list[list_num].name = attr[j].name;
+                attrib_list[list_num].type = attr[j].type;
+                GetIMValueFromName (i18n_core,
+                                    connect_id,
+                                    NULL,
+                                    attr[j].name,
+                                    &value_length);
+                attrib_list[list_num].value_length = value_length;
+                attrib_list[list_num].value = (void *) malloc (value_length);
+                memset(attrib_list[list_num].value, 0, value_length);
+                GetIMValueFromName (i18n_core,
+                                    connect_id,
+                                    attrib_list[list_num].value,
+                                    attr[j].name,
+                                    &value_length);
+                *length += sizeof (CARD16)*2;
+                *length += value_length;
+                *length += IMPAD (value_length);
+                list_num++;
+                break;
+            }
+            /*endif*/
+        }
+        /*endfor*/
+    }
+    /*endfor*/
+    *number = number_ret;
+    return attrib_list;
+}
+
+static void GetIMValuesMessageProc (XIMS ims,
+                                    IMProtocol *call_data,
+                                    unsigned char *p)
+{
+    Xi18n i18n_core = ims->protocol;
+    FrameMgr fm;
+    FmStatus status;
+    extern XimFrameRec get_im_values_fr[];
+    extern XimFrameRec get_im_values_reply_fr[];
+    CARD16 byte_length;
+    int list_len, total_size;
+    unsigned char *reply = NULL;
+    int iter_count;
+    register int i;
+    register int j;
+    int number;
+    CARD16 *im_attrID_list;
+    char **name_list;
+    CARD16 name_number;
+    XIMAttribute *im_attribute_list;
+    IMGetIMValuesStruct *getim = (IMGetIMValuesStruct *)&call_data->getim;
+    CARD16 connect_id = call_data->any.connect_id;
+    CARD16 input_method_ID;
+
+    /* create FrameMgr */
+    fm = FrameMgrInit (get_im_values_fr,
+                       (char *) p,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+
+    FrameMgrGetToken (fm, input_method_ID);
+    FrameMgrGetToken (fm, byte_length);
+    im_attrID_list = (CARD16 *) malloc (sizeof (CARD16)*20);
+    memset (im_attrID_list, 0, sizeof (CARD16)*20);
+    name_list = (char **)malloc(sizeof(char *) * 20);
+    memset(name_list, 0, sizeof(char *) * 20);
+    number = 0;
+    while (FrameMgrIsIterLoopEnd (fm, &status) == False)
+    {
+        FrameMgrGetToken (fm, im_attrID_list[number]);
+        number++;
+    }
+    FrameMgrFree (fm);
+
+    name_number = 0;
+    for (i = 0;  i < number;  i++) {
+        for (j = 0;  j < i18n_core->address.im_attr_num;  j++) {
+            if (i18n_core->address.xim_attr[j].attribute_id ==
+                    im_attrID_list[i]) {
+                name_list[name_number++] = 
+                       i18n_core->address.xim_attr[j].name;
+                break;
+            }
+        }
+    }
+    getim->number = name_number;
+    getim->im_attr_list = name_list;
+    XFree (name_list);
+
+
+#ifdef PROTOCOL_RICH
+    if (i18n_core->address.improto) {
+        if (!(i18n_core->address.improto (ims, call_data)))
+            return;
+    }
+#endif  /* PROTOCOL_RICH */
+
+    im_attribute_list = MakeIMAttributeList (i18n_core,
+                                             connect_id,
+                                             im_attrID_list,
+                                             &number,
+                                             &list_len);
+    if (im_attrID_list)
+        XFree (im_attrID_list);
+    /*endif*/
+
+    fm = FrameMgrInit (get_im_values_reply_fr,
+                       NULL,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+
+    iter_count = number;
+
+    /* set iteration count for list of im_attribute */
+    FrameMgrSetIterCount (fm, iter_count);
+
+    /* set length of BARRAY item in ximattribute_fr */
+    for (i = 0;  i < iter_count;  i++)
+        FrameMgrSetSize (fm, im_attribute_list[i].value_length);
+    /*endfor*/
+    
+    total_size = FrameMgrGetTotalSize (fm);
+    reply = (unsigned char *) malloc (total_size);
+    if (!reply)
+    {
+        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
+        return;
+    }
+    /*endif*/
+    memset (reply, 0, total_size);
+    FrameMgrSetBuffer (fm, reply);
+
+    FrameMgrPutToken (fm, input_method_ID);
+
+    for (i = 0;  i < iter_count;  i++)
+    {
+        FrameMgrPutToken (fm, im_attribute_list[i].attribute_id);
+        FrameMgrPutToken (fm, im_attribute_list[i].value_length);
+        FrameMgrPutToken (fm, im_attribute_list[i].value);
+    }
+    /*endfor*/
+    _Xi18nSendMessage (ims,
+                       connect_id,
+                       XIM_GET_IM_VALUES_REPLY,
+                       0,
+                       reply,
+                       total_size);
+    FrameMgrFree (fm);
+    XFree (reply);
+
+    for (i = 0; i < iter_count; i++)
+        XFree(im_attribute_list[i].value);
+    XFree (im_attribute_list);
+}
+
+static void CreateICMessageProc (XIMS ims,
+                                 IMProtocol *call_data,
+                                 unsigned char *p)
+{
+    _Xi18nChangeIC (ims, call_data, p, True);
+}
+
+static void SetICValuesMessageProc (XIMS ims,
+                                    IMProtocol *call_data,
+                                    unsigned char *p)
+{
+    _Xi18nChangeIC (ims, call_data, p, False);
+}
+
+static void GetICValuesMessageProc (XIMS ims,
+                                    IMProtocol *call_data,
+                                    unsigned char *p)
+{
+    _Xi18nGetIC (ims, call_data, p);
+}
+
+static void SetICFocusMessageProc (XIMS ims,
+                                   IMProtocol *call_data,
+                                   unsigned char *p)
+{
+    Xi18n i18n_core = ims->protocol;
+    FrameMgr fm;
+    extern XimFrameRec set_ic_focus_fr[];
+    IMChangeFocusStruct *setfocus;
+    CARD16 connect_id = call_data->any.connect_id;
+    CARD16 input_method_ID;
+
+    setfocus = (IMChangeFocusStruct *) &call_data->changefocus;
+
+    fm = FrameMgrInit (set_ic_focus_fr,
+                       (char *) p,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+
+    /* get data */
+    FrameMgrGetToken (fm, input_method_ID);
+    FrameMgrGetToken (fm, setfocus->icid);
+
+    FrameMgrFree (fm);
+
+    if (i18n_core->address.improto)
+    {
+        if (!(i18n_core->address.improto (ims, call_data)))
+            return;
+        /*endif*/
+    }
+    /*endif*/
+}
+
+static void UnsetICFocusMessageProc (XIMS ims,
+                                     IMProtocol *call_data,
+                                     unsigned char *p)
+{
+    Xi18n i18n_core = ims->protocol;
+    FrameMgr fm;
+    extern XimFrameRec unset_ic_focus_fr[];
+    IMChangeFocusStruct *unsetfocus;
+    CARD16 connect_id = call_data->any.connect_id;
+    CARD16 input_method_ID;
+
+    unsetfocus = (IMChangeFocusStruct *) &call_data->changefocus;
+
+    fm = FrameMgrInit (unset_ic_focus_fr,
+                       (char *) p,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+
+    /* get data */
+    FrameMgrGetToken (fm, input_method_ID);
+    FrameMgrGetToken (fm, unsetfocus->icid);
+
+    FrameMgrFree (fm);
+
+    if (i18n_core->address.improto)
+    {
+        if (!(i18n_core->address.improto (ims, call_data)))
+            return;
+        /*endif*/
+    }
+    /*endif*/
+}
+
+static void DestroyICMessageProc (XIMS ims,
+                                  IMProtocol *call_data,
+                                  unsigned char *p)
+{
+    Xi18n i18n_core = ims->protocol;
+    FrameMgr fm;
+    extern XimFrameRec destroy_ic_fr[];
+    extern XimFrameRec destroy_ic_reply_fr[];
+    register int total_size;
+    unsigned char *reply = NULL;
+    IMDestroyICStruct *destroy =
+        (IMDestroyICStruct *) &call_data->destroyic;
+    CARD16 connect_id = call_data->any.connect_id;
+    CARD16 input_method_ID;
+
+    fm = FrameMgrInit (destroy_ic_fr,
+                       (char *) p,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+
+    /* get data */
+    FrameMgrGetToken (fm, input_method_ID);
+    FrameMgrGetToken (fm, destroy->icid);
+
+    FrameMgrFree (fm);
+
+    if (i18n_core->address.improto)
+    {
+        if (!(i18n_core->address.improto (ims, call_data)))
+            return;
+        /*endif*/
+    }
+    /*endif*/
+    
+    fm = FrameMgrInit (destroy_ic_reply_fr,
+                       NULL,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+
+    total_size = FrameMgrGetTotalSize (fm);
+    reply = (unsigned char *) malloc (total_size);
+    if (!reply)
+    {
+        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
+        return;
+    }
+    /*endif*/
+    memset (reply, 0, total_size);
+    FrameMgrSetBuffer (fm, reply);
+
+    FrameMgrPutToken (fm, input_method_ID);
+    FrameMgrPutToken (fm, destroy->icid);
+
+    _Xi18nSendMessage (ims,
+                       connect_id,
+                       XIM_DESTROY_IC_REPLY,
+                       0,
+                       reply,
+                       total_size);
+    XFree(reply);
+    FrameMgrFree (fm);
+}
+
+static void ResetICMessageProc (XIMS ims,
+                                IMProtocol *call_data,
+                                unsigned char *p)
+{
+    Xi18n i18n_core = ims->protocol;
+    FrameMgr fm;
+    extern XimFrameRec reset_ic_fr[];
+    extern XimFrameRec reset_ic_reply_fr[];
+    register int total_size;
+    unsigned char *reply = NULL;
+    IMResetICStruct *resetic =
+        (IMResetICStruct *) &call_data->resetic;
+    CARD16 connect_id = call_data->any.connect_id;
+    CARD16 input_method_ID;
+
+    fm = FrameMgrInit (reset_ic_fr,
+                       (char *) p,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+
+    /* get data */
+    FrameMgrGetToken (fm, input_method_ID);
+    FrameMgrGetToken (fm, resetic->icid);
+
+    FrameMgrFree (fm);
+
+    if (i18n_core->address.improto)
+    {
+        if (!(i18n_core->address.improto(ims, call_data)))
+            return;
+        /*endif*/
+    }
+    /*endif*/
+    
+    /* create FrameMgr */
+    fm = FrameMgrInit (reset_ic_reply_fr,
+                       NULL,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+
+    /* set length of STRING8 */
+    FrameMgrSetSize (fm, resetic->length);
+
+    total_size = FrameMgrGetTotalSize (fm);
+    reply = (unsigned char *) malloc (total_size);
+    if (!reply)
+    {
+        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
+        return;
+    }
+    /*endif*/
+    memset (reply, 0, total_size);
+    FrameMgrSetBuffer (fm, reply);
+
+    FrameMgrPutToken (fm, input_method_ID);
+    FrameMgrPutToken (fm, resetic->icid);
+    FrameMgrPutToken(fm, resetic->length);
+    FrameMgrPutToken (fm, resetic->commit_string);
+
+    _Xi18nSendMessage (ims,
+                       connect_id,
+                       XIM_RESET_IC_REPLY,
+                       0,
+                       reply,
+                       total_size);
+    FrameMgrFree (fm);
+    XFree(reply);
+}
+
+static int WireEventToEvent (Xi18n i18n_core,
+                             xEvent *event,
+                             CARD16 serial,
+                             XEvent *ev,
+                             Bool byte_swap)
+{
+    FrameMgr fm;
+    extern XimFrameRec wire_keyevent_fr[];
+    BYTE b;
+    CARD16 c16;
+    CARD32 c32;
+    int ret = False;
+
+    /* create FrameMgr */
+    fm = FrameMgrInit(wire_keyevent_fr, (char *)(&(event->u)), byte_swap);
+
+
+    /* get & set type */
+    FrameMgrGetToken(fm, b);
+    ev->type = (unsigned int)b;
+    /* get detail */
+    FrameMgrGetToken(fm, b);
+    /* get & set serial */
+    FrameMgrGetToken(fm, c16);
+    ev->xany.serial = (unsigned long)c16;
+    ev->xany.serial |= serial << 16;
+    ev->xany.send_event = False;
+    ev->xany.display = i18n_core->address.dpy;
+
+    /* Remove SendEvent flag from event type to emulate KeyPress/Release */
+    ev->type &= 0x7F;
+
+    switch (ev->type) {
+      case KeyPress:
+      case KeyRelease:
+      {
+          XKeyEvent *kev = (XKeyEvent*)ev;
+
+          /* set keycode (detail) */
+          kev->keycode = (unsigned int)b;
+
+          /* get & set values */
+          FrameMgrGetToken(fm, c32); kev->time = (Time)c32;
+          FrameMgrGetToken(fm, c32); kev->root = (Window)c32;
+          FrameMgrGetToken(fm, c32); kev->window = (Window)c32;
+          FrameMgrGetToken(fm, c32); kev->subwindow = (Window)c32;
+          FrameMgrGetToken(fm, c16); kev->x_root = (int)c16;
+          FrameMgrGetToken(fm, c16); kev->y_root = (int)c16;
+          FrameMgrGetToken(fm, c16); kev->x = (int)c16;
+          FrameMgrGetToken(fm, c16); kev->y = (int)c16;
+          FrameMgrGetToken(fm, c16); kev->state = (unsigned int)c16;
+          FrameMgrGetToken(fm, b);   kev->same_screen = (Bool)b;
+      }
+      ret = True;
+      break;
+      default:
+      break;
+    }
+    /* free FrameMgr */
+    FrameMgrFree(fm);
+    return ret;
+}
+
+static void ForwardEventMessageProc (XIMS ims,
+                                     IMProtocol *call_data,
+                                     unsigned char *p)
+{
+    Xi18n i18n_core = ims->protocol;
+    FrameMgr fm;
+    extern XimFrameRec forward_event_fr[];
+    xEvent wire_event;
+    IMForwardEventStruct *forward =
+        (IMForwardEventStruct*) &call_data->forwardevent;
+    CARD16 connect_id = call_data->any.connect_id;
+    CARD16 input_method_ID;
+
+    fm = FrameMgrInit (forward_event_fr,
+                       (char *) p,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+    /* get data */
+    FrameMgrGetToken (fm, input_method_ID);
+    FrameMgrGetToken (fm, forward->icid);
+    FrameMgrGetToken (fm, forward->sync_bit);
+    FrameMgrGetToken (fm, forward->serial_number);
+    p += sizeof (CARD16)*4;
+    memmove (&wire_event, p, sizeof (xEvent));
+
+    FrameMgrFree (fm);
+
+    if (WireEventToEvent (i18n_core,
+                          &wire_event,
+                          forward->serial_number,
+                          &forward->event,
+                         _Xi18nNeedSwap (i18n_core, connect_id)) == True)
+    {
+        if (i18n_core->address.improto)
+        {
+            if (!(i18n_core->address.improto(ims, call_data)))
+                return;
+            /*endif*/
+        }
+        /*endif*/
+    }
+    /*endif*/
+}
+
+static void ExtForwardKeyEventMessageProc (XIMS ims,
+                                           IMProtocol *call_data,
+                                           unsigned char *p)
+{
+    Xi18n i18n_core = ims->protocol;
+    FrameMgr fm;
+    extern XimFrameRec ext_forward_keyevent_fr[];
+    CARD8 type, keycode;
+    CARD16 state;
+    CARD32 ev_time, window;
+    IMForwardEventStruct *forward =
+        (IMForwardEventStruct *) &call_data->forwardevent;
+    XEvent *ev = (XEvent *) &forward->event;
+    CARD16 connect_id = call_data->any.connect_id;
+    CARD16 input_method_ID;
+
+    fm = FrameMgrInit (ext_forward_keyevent_fr,
+                       (char *) p,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+    /* get data */
+    FrameMgrGetToken (fm, input_method_ID);
+    FrameMgrGetToken (fm, forward->icid);
+    FrameMgrGetToken (fm, forward->sync_bit);
+    FrameMgrGetToken (fm, forward->serial_number);
+    FrameMgrGetToken (fm, type);
+    FrameMgrGetToken (fm, keycode);
+    FrameMgrGetToken (fm, state);
+    FrameMgrGetToken (fm, ev_time);
+    FrameMgrGetToken (fm, window);
+
+    FrameMgrFree (fm);
+
+    if (type != KeyPress)
+    {
+        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
+        return;
+    }
+    /*endif*/
+    
+    /* make a faked keypress event */
+    ev->type = (int)type;
+    ev->xany.send_event = True;
+    ev->xany.display = i18n_core->address.dpy;
+    ev->xany.serial = (unsigned long) forward->serial_number;
+    ((XKeyEvent *) ev)->keycode = (unsigned int) keycode;
+    ((XKeyEvent *) ev)->state = (unsigned int) state;
+    ((XKeyEvent *) ev)->time = (Time) ev_time;
+    ((XKeyEvent *) ev)->window = (Window) window;
+    ((XKeyEvent *) ev)->root = DefaultRootWindow (ev->xany.display);
+    ((XKeyEvent *) ev)->x = 0;
+    ((XKeyEvent *) ev)->y = 0;
+    ((XKeyEvent *) ev)->x_root = 0;
+    ((XKeyEvent *) ev)->y_root = 0;
+
+    if (i18n_core->address.improto)
+    {
+        if (!(i18n_core->address.improto (ims, call_data)))
+            return;
+        /*endif*/
+    }
+    /*endif*/
+}
+
+static void ExtMoveMessageProc (XIMS ims,
+                                IMProtocol *call_data,
+                                unsigned char *p)
+{
+    Xi18n i18n_core = ims->protocol;
+    FrameMgr fm;
+    extern XimFrameRec ext_move_fr[];
+    IMMoveStruct *extmove =
+        (IMMoveStruct*) & call_data->extmove;
+    CARD16 connect_id = call_data->any.connect_id;
+    CARD16 input_method_ID;
+
+    fm = FrameMgrInit (ext_move_fr,
+                       (char *) p,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+    /* get data */
+    FrameMgrGetToken (fm, input_method_ID);
+    FrameMgrGetToken (fm, extmove->icid);
+    FrameMgrGetToken (fm, extmove->x);
+    FrameMgrGetToken (fm, extmove->y);
+
+    FrameMgrFree (fm);
+
+    if (i18n_core->address.improto)
+    {
+        if (!(i18n_core->address.improto (ims, call_data)))
+            return;
+        /*endif*/
+    }
+    /*endif*/
+}
+
+static void ExtensionMessageProc (XIMS ims,
+                                  IMProtocol *call_data,
+                                  unsigned char *p)
+{
+    switch (call_data->any.minor_code)
+    {
+    case XIM_EXT_FORWARD_KEYEVENT:
+        ExtForwardKeyEventMessageProc (ims, call_data, p);
+        break;
+
+    case XIM_EXT_MOVE:
+        ExtMoveMessageProc (ims, call_data, p);
+        break;
+    }
+    /*endswitch*/
+}
+
+static void TriggerNotifyMessageProc (XIMS ims,
+                                      IMProtocol *call_data,
+                                      unsigned char *p)
+{
+    Xi18n i18n_core = ims->protocol;
+    FrameMgr fm;
+    extern XimFrameRec trigger_notify_fr[], trigger_notify_reply_fr[];
+    register int total_size;
+    unsigned char *reply = NULL;
+    IMTriggerNotifyStruct *trigger =
+        (IMTriggerNotifyStruct *) &call_data->triggernotify;
+    CARD16 connect_id = call_data->any.connect_id;
+    CARD16 input_method_ID;
+    CARD32 flag;
+
+    fm = FrameMgrInit (trigger_notify_fr,
+                       (char *) p,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+    /* get data */
+    FrameMgrGetToken (fm, input_method_ID);
+    FrameMgrGetToken (fm, trigger->icid);
+    FrameMgrGetToken (fm, trigger->flag);
+    FrameMgrGetToken (fm, trigger->key_index);
+    FrameMgrGetToken (fm, trigger->event_mask);
+    /*
+      In order to support Front End Method, this event_mask must be saved
+      per clients so that it should be restored by an XIM_EXT_SET_EVENT_MASK
+      call when preediting mode is reset to off.
+     */
+
+    flag = trigger->flag;
+
+    FrameMgrFree (fm);
+
+    fm = FrameMgrInit (trigger_notify_reply_fr,
+                       NULL,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+    total_size = FrameMgrGetTotalSize (fm);
+    reply = (unsigned char *) malloc (total_size);
+    if (!reply)
+    {
+        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
+        return;
+    }
+    /*endif*/
+    memset (reply, 0, total_size);
+    FrameMgrSetBuffer (fm, reply);
+
+    FrameMgrPutToken (fm, input_method_ID);
+    FrameMgrPutToken (fm, trigger->icid);
+
+    /* NOTE:
+       XIM_TRIGGER_NOTIFY_REPLY should be sent before XIM_SET_EVENT_MASK
+       in case of XIM_TRIGGER_NOTIFY(flag == ON), while it should be
+       sent after XIM_SET_EVENT_MASK in case of
+       XIM_TRIGGER_NOTIFY(flag == OFF).
+       */
+    if (flag == 0)
+    {
+        /* on key */
+        _Xi18nSendMessage (ims,
+                           connect_id,
+                           XIM_TRIGGER_NOTIFY_REPLY,
+                           0,
+                           reply,
+                           total_size);
+        IMPreeditStart (ims, (XPointer)call_data);
+    }
+    /*endif*/
+    if (i18n_core->address.improto)
+    {
+        if (!(i18n_core->address.improto(ims, call_data)))
+            return;
+        /*endif*/
+    }
+    /*endif*/
+
+    if (flag == 1)
+    {
+        /* off key */
+        IMPreeditEnd (ims, (XPointer) call_data);
+        _Xi18nSendMessage (ims,
+                           connect_id,
+                           XIM_TRIGGER_NOTIFY_REPLY,
+                           0,
+                           reply,
+                           total_size);
+    }
+    /*endif*/
+    FrameMgrFree (fm);
+    XFree (reply);
+}
+
+static INT16 ChooseEncoding (Xi18n i18n_core,
+                             IMEncodingNegotiationStruct *enc_nego)
+{
+    Xi18nAddressRec *address = (Xi18nAddressRec *) & i18n_core->address;
+    XIMEncodings *p;
+    int i, j;
+    int enc_index=0;
+
+    p = (XIMEncodings *) &address->encoding_list;
+    for (i = 0;  i < (int) p->count_encodings;  i++)
+    {
+        for (j = 0;  j < (int) enc_nego->encoding_number;  j++)
+        {
+            if (strcmp (p->supported_encodings[i],
+                        enc_nego->encoding[j].name) == 0)
+            {
+                enc_index = j;
+                break;
+            }
+            /*endif*/
+        }
+        /*endfor*/
+    }
+    /*endfor*/
+
+    return (INT16) enc_index;
+#if 0
+    return (INT16) XIM_Default_Encoding_IDX;
+#endif
+}
+
+static void EncodingNegotiatonMessageProc (XIMS ims,
+                                           IMProtocol *call_data,
+                                           unsigned char *p)
+{
+    Xi18n i18n_core = ims->protocol;
+    FrameMgr fm;
+    FmStatus status;
+    CARD16 byte_length;
+    extern XimFrameRec encoding_negotiation_fr[];
+    extern XimFrameRec encoding_negotiation_reply_fr[];
+    register int i, total_size;
+    unsigned char *reply = NULL;
+    IMEncodingNegotiationStruct *enc_nego =
+        (IMEncodingNegotiationStruct *) &call_data->encodingnego;
+    CARD16 connect_id = call_data->any.connect_id;
+    CARD16 input_method_ID;
+
+    fm = FrameMgrInit (encoding_negotiation_fr,
+                       (char *) p,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+
+    FrameMgrGetToken (fm, input_method_ID);
+
+    /* get ENCODING STR field */
+    FrameMgrGetToken (fm, byte_length);
+    if (byte_length > 0)
+    {
+        enc_nego->encoding = (XIMStr *) malloc (sizeof (XIMStr)*10);
+        memset (enc_nego->encoding, 0, sizeof (XIMStr)*10);
+        i = 0;
+        while (FrameMgrIsIterLoopEnd (fm, &status) == False)
+        {
+            char *name;
+            int str_length;
+            
+            FrameMgrGetToken (fm, str_length);
+            FrameMgrSetSize (fm, str_length);
+            enc_nego->encoding[i].length = str_length;
+            FrameMgrGetToken (fm, name);
+            enc_nego->encoding[i].name = malloc (str_length + 1);
+            strncpy (enc_nego->encoding[i].name, name, str_length);
+            enc_nego->encoding[i].name[str_length] = '\0';
+            i++;
+        }
+        /*endwhile*/
+        enc_nego->encoding_number = i;
+    }
+    /*endif*/
+    /* get ENCODING INFO field */
+    FrameMgrGetToken (fm, byte_length);
+    if (byte_length > 0)
+    {
+        enc_nego->encodinginfo = (XIMStr *) malloc (sizeof (XIMStr)*10);
+        memset (enc_nego->encoding, 0, sizeof (XIMStr)*10);
+        i = 0;
+        while (FrameMgrIsIterLoopEnd (fm, &status) == False)
+        {
+            char *name;
+            int str_length;
+            
+            FrameMgrGetToken (fm, str_length);
+            FrameMgrSetSize (fm, str_length);
+            enc_nego->encodinginfo[i].length = str_length;
+            FrameMgrGetToken (fm, name);
+            enc_nego->encodinginfo[i].name = malloc (str_length + 1);
+            strncpy (enc_nego->encodinginfo[i].name, name, str_length);
+            enc_nego->encodinginfo[i].name[str_length] = '\0';
+            i++;
+        }
+        /*endwhile*/
+        enc_nego->encoding_info_number = i;
+    }
+    /*endif*/
+
+    enc_nego->enc_index = ChooseEncoding (i18n_core, enc_nego);
+    enc_nego->category = 0;
+
+#ifdef PROTOCOL_RICH
+    if (i18n_core->address.improto)
+    {
+        if (!(i18n_core->address.improto(ims, call_data)))
+            return;
+        /*endif*/
+    }
+    /*endif*/
+#endif  /* PROTOCOL_RICH */
+
+    FrameMgrFree (fm);
+
+    fm = FrameMgrInit (encoding_negotiation_reply_fr,
+                       NULL,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+
+    total_size = FrameMgrGetTotalSize (fm);
+    reply = (unsigned char *) malloc (total_size);
+    if (!reply)
+    {
+        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
+        return;
+    }
+    /*endif*/
+    memset (reply, 0, total_size);
+    FrameMgrSetBuffer (fm, reply);
+
+    FrameMgrPutToken (fm, input_method_ID);
+    FrameMgrPutToken (fm, enc_nego->category);
+    FrameMgrPutToken (fm, enc_nego->enc_index);
+
+    _Xi18nSendMessage (ims,
+                       connect_id,
+                       XIM_ENCODING_NEGOTIATION_REPLY,
+                       0,
+                       reply,
+                       total_size);
+    XFree (reply);
+
+    /* free data for encoding list */
+    if (enc_nego->encoding)
+    {
+        for (i = 0;  i < (int) enc_nego->encoding_number;  i++)
+            XFree (enc_nego->encoding[i].name);
+        /*endfor*/
+        XFree (enc_nego->encoding);
+    }
+    /*endif*/
+    if (enc_nego->encodinginfo)
+    {
+        for (i = 0;  i < (int) enc_nego->encoding_info_number;  i++)
+            XFree (enc_nego->encodinginfo[i].name);
+        /*endfor*/
+        XFree (enc_nego->encodinginfo);
+    }
+    /*endif*/
+    FrameMgrFree (fm);
+}
+
+void PreeditStartReplyMessageProc (XIMS ims,
+                                   IMProtocol *call_data,
+                                   unsigned char *p)
+{
+    Xi18n i18n_core = ims->protocol;
+    FrameMgr fm;
+    extern XimFrameRec preedit_start_reply_fr[];
+    IMPreeditCBStruct *preedit_CB =
+        (IMPreeditCBStruct *) &call_data->preedit_callback;
+    CARD16 connect_id = call_data->any.connect_id;
+    CARD16 input_method_ID;
+
+    fm = FrameMgrInit (preedit_start_reply_fr,
+                       (char *) p,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+    /* get data */
+    FrameMgrGetToken (fm, input_method_ID);
+    FrameMgrGetToken (fm, preedit_CB->icid);
+    FrameMgrGetToken (fm, preedit_CB->todo.return_value);
+
+    FrameMgrFree (fm);
+
+    if (i18n_core->address.improto)
+    {
+        if (!(i18n_core->address.improto (ims, call_data)))
+            return;
+        /*endif*/
+    }
+    /*endif*/
+}
+
+void PreeditCaretReplyMessageProc (XIMS ims,
+                                   IMProtocol *call_data,
+                                   unsigned char *p)
+{
+    Xi18n i18n_core = ims->protocol;
+    FrameMgr fm;
+    extern XimFrameRec preedit_caret_reply_fr[];
+    IMPreeditCBStruct *preedit_CB =
+        (IMPreeditCBStruct *) &call_data->preedit_callback;
+    XIMPreeditCaretCallbackStruct *caret =
+        (XIMPreeditCaretCallbackStruct *) & preedit_CB->todo.caret;
+    CARD16 connect_id = call_data->any.connect_id;
+    CARD16 input_method_ID;
+
+    fm = FrameMgrInit (preedit_caret_reply_fr,
+                       (char *) p,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+    /* get data */
+    FrameMgrGetToken (fm, input_method_ID);
+    FrameMgrGetToken (fm, preedit_CB->icid);
+    FrameMgrGetToken (fm, caret->position);
+
+    FrameMgrFree (fm);
+
+    if (i18n_core->address.improto)
+    {
+        if (!(i18n_core->address.improto(ims, call_data)))
+            return;
+        /*endif*/
+    }
+    /*endif*/
+}
+
+void StrConvReplyMessageProc (XIMS ims,
+                              IMProtocol *call_data,
+                              unsigned char *p)
+{
+    return;
+}
+
+static void AddQueue (Xi18nClient *client, unsigned char *p)
+{
+    XIMPending *new;
+    XIMPending *last;
+
+    if ((new = (XIMPending *) malloc (sizeof (XIMPending))) == NULL)
+        return;
+    /*endif*/
+    new->p = p;
+    new->next = (XIMPending *) NULL;
+    if (!client->pending)
+    {
+        client->pending = new;
+    }
+    else
+    {
+        for (last = client->pending;  last->next;  last = last->next)
+            ;
+        /*endfor*/
+        last->next = new;
+    }
+    /*endif*/
+    return;
+}
+
+static void ProcessQueue (XIMS ims, CARD16 connect_id)
+{
+    Xi18n i18n_core = ims->protocol;
+    Xi18nClient *client = (Xi18nClient *) _Xi18nFindClient (i18n_core,
+                                                            connect_id);
+
+    while (client->sync == False  &&  client->pending)
+    {
+        XimProtoHdr *hdr = (XimProtoHdr *) client->pending->p;
+        unsigned char *p1 = (unsigned char *) (hdr + 1);
+        IMProtocol call_data;
+
+        call_data.major_code = hdr->major_opcode;
+        call_data.any.minor_code = hdr->minor_opcode;
+        call_data.any.connect_id = connect_id;
+
+        switch (hdr->major_opcode)
+        {
+        case XIM_FORWARD_EVENT:
+            ForwardEventMessageProc(ims, &call_data, p1);
+            break;
+        }
+        /*endswitch*/
+        XFree (hdr);
+        {
+            XIMPending *old = client->pending;
+
+            client->pending = old->next;
+            XFree (old);
+        }
+    }
+    /*endwhile*/
+    return;
+}
+
+
+void _Xi18nMessageHandler (XIMS ims,
+                           CARD16 connect_id,
+                           unsigned char *p,
+                           Bool *delete)
+{
+    XimProtoHdr        *hdr = (XimProtoHdr *)p;
+    unsigned char *p1 = (unsigned char *)(hdr + 1);
+    IMProtocol call_data;
+    Xi18n i18n_core = ims->protocol;
+    Xi18nClient *client;
+
+    client = (Xi18nClient *) _Xi18nFindClient (i18n_core, connect_id);
+    if (hdr == (XimProtoHdr *) NULL)
+        return;
+    /*endif*/
+    
+    memset (&call_data, 0, sizeof(IMProtocol));
+
+    call_data.major_code = hdr->major_opcode;
+    call_data.any.minor_code = hdr->minor_opcode;
+    call_data.any.connect_id = connect_id;
+
+    switch (call_data.major_code)
+    {
+    case XIM_CONNECT:
+#ifdef XIM_DEBUG
+       DebugLog("-- XIM_CONNECT\n");
+#endif
+        ConnectMessageProc (ims, &call_data, p1);
+        break;
+
+    case XIM_DISCONNECT:
+#ifdef XIM_DEBUG
+       DebugLog("-- XIM_DISCONNECT\n");
+#endif
+        DisConnectMessageProc (ims, &call_data);
+        break;
+
+    case XIM_OPEN:
+#ifdef XIM_DEBUG
+       DebugLog("-- XIM_OPEN\n");
+#endif
+        OpenMessageProc (ims, &call_data, p1);
+        break;
+
+    case XIM_CLOSE:
+#ifdef XIM_DEBUG
+       DebugLog("-- XIM_CLOSE\n");
+#endif
+        CloseMessageProc (ims, &call_data, p1);
+        break;
+
+    case XIM_QUERY_EXTENSION:
+#ifdef XIM_DEBUG
+       DebugLog("-- XIM_QUERY_EXTENSION\n");
+#endif
+        QueryExtensionMessageProc (ims, &call_data, p1);
+        break;
+
+    case XIM_GET_IM_VALUES:
+#ifdef XIM_DEBUG
+       DebugLog("-- XIM_GET_IM_VALUES\n");
+#endif
+        GetIMValuesMessageProc (ims, &call_data, p1);
+        break;
+
+    case XIM_CREATE_IC:
+#ifdef XIM_DEBUG
+       DebugLog("-- XIM_CREATE_IC\n");
+#endif
+        CreateICMessageProc (ims, &call_data, p1);
+        break;
+
+    case XIM_SET_IC_VALUES:
+#ifdef XIM_DEBUG
+       DebugLog("-- XIM_SET_IC_VALUES\n");
+#endif
+        SetICValuesMessageProc (ims, &call_data, p1);
+        break;
+
+    case XIM_GET_IC_VALUES:
+#ifdef XIM_DEBUG
+       DebugLog("-- XIM_GET_IC_VALUES\n");
+#endif
+        GetICValuesMessageProc (ims, &call_data, p1);
+        break;
+
+    case XIM_SET_IC_FOCUS:
+#ifdef XIM_DEBUG
+       DebugLog("-- XIM_SET_IC_FOCUS\n");
+#endif
+        SetICFocusMessageProc (ims, &call_data, p1);
+        break;
+
+    case XIM_UNSET_IC_FOCUS:
+#ifdef XIM_DEBUG
+       DebugLog("-- XIM_UNSET_IC_FOCUS\n");
+#endif
+        UnsetICFocusMessageProc (ims, &call_data, p1);
+        break;
+
+    case XIM_DESTROY_IC:
+#ifdef XIM_DEBUG
+       DebugLog("-- XIM_DESTROY_IC\n");
+#endif
+        DestroyICMessageProc (ims, &call_data, p1);
+        break;
+
+    case XIM_RESET_IC:
+#ifdef XIM_DEBUG
+       DebugLog("-- XIM_RESET_IC\n");
+#endif
+        ResetICMessageProc (ims, &call_data, p1);
+        break;
+
+    case XIM_FORWARD_EVENT:
+#ifdef XIM_DEBUG
+       DebugLog("-- XIM_FORWARD_EVENT\n");
+#endif
+        if (client->sync == True)
+        {
+            AddQueue (client, p);
+            *delete = False;
+        }
+        else
+        {
+            ForwardEventMessageProc (ims, &call_data, p1);
+        }
+        break;
+
+    case XIM_EXTENSION:
+#ifdef XIM_DEBUG
+       DebugLog("-- XIM_EXTENSION\n");
+#endif
+        ExtensionMessageProc (ims, &call_data, p1);
+        break;
+
+    case XIM_SYNC:
+#ifdef XIM_DEBUG
+       DebugLog("-- XIM_SYNC\n");
+#endif
+        break;
+
+    case XIM_SYNC_REPLY:
+#ifdef XIM_DEBUG
+       DebugLog("-- XIM_SYNC_REPLY\n");
+#endif
+        SyncReplyMessageProc (ims, &call_data, p1);
+        ProcessQueue (ims, connect_id);
+        break;
+
+    case XIM_TRIGGER_NOTIFY:
+#ifdef XIM_DEBUG
+       DebugLog("-- XIM_TRIGGER_NOTIFY\n");
+#endif
+        TriggerNotifyMessageProc (ims, &call_data, p1);
+        break;
+
+    case XIM_ENCODING_NEGOTIATION:
+#ifdef XIM_DEBUG
+       DebugLog("-- XIM_ENCODING_NEGOTIATION\n");
+#endif
+        EncodingNegotiatonMessageProc (ims, &call_data, p1);
+        break;
+
+    case XIM_PREEDIT_START_REPLY:
+#ifdef XIM_DEBUG
+       DebugLog("-- XIM_PREEDIT_START_REPLY\n");
+#endif
+        PreeditStartReplyMessageProc (ims, &call_data, p1);
+        break;
+
+    case XIM_PREEDIT_CARET_REPLY:
+#ifdef XIM_DEBUG
+       DebugLog("-- XIM_PREEDIT_CARET_REPLY\n");
+#endif
+        PreeditCaretReplyMessageProc (ims, &call_data, p1);
+        break;
+
+    case XIM_STR_CONVERSION_REPLY:
+#ifdef XIM_DEBUG
+       DebugLog("-- XIM_STR_CONVERSION_REPLY\n");
+#endif
+        StrConvReplyMessageProc (ims, &call_data, p1);
+        break;
+    }
+    /*endswitch*/
+}
diff --git a/client/x11/IMdkit/i18nUtil.c b/client/x11/IMdkit/i18nUtil.c
new file mode 100644 (file)
index 0000000..22a2376
--- /dev/null
@@ -0,0 +1,276 @@
+/******************************************************************
+         Copyright 1994, 1995 by Sun Microsystems, Inc.
+         Copyright 1993, 1994 by Hewlett-Packard Company
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear
+in supporting documentation, and that the name of Sun Microsystems, Inc.
+and Hewlett-Packard not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior permission.
+Sun Microsystems, Inc. and Hewlett-Packard make no representations about
+the suitability of this software for any purpose.  It is provided "as is"
+without express or implied warranty.
+SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL
+WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+  Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
+
+    This version tidied and debugged by Steve Underwood May 1999
+******************************************************************/
+
+#include <X11/Xlib.h>
+#include "IMdkit.h"
+#include "Xi18n.h"
+#include "FrameMgr.h"
+#include "XimFunc.h"
+
+Xi18nClient *_Xi18nFindClient (Xi18n, CARD16);
+
+int
+_Xi18nNeedSwap (Xi18n i18n_core, CARD16 connect_id)
+{
+    CARD8 im_byteOrder = i18n_core->address.im_byteOrder;
+    Xi18nClient *client = _Xi18nFindClient (i18n_core, connect_id);
+
+    return (client->byte_order != im_byteOrder);
+}
+
+Xi18nClient *_Xi18nNewClient(Xi18n i18n_core)
+{
+    static CARD16 connect_id = 0;
+    int new_connect_id;
+    Xi18nClient *client;
+
+    if (i18n_core->address.free_clients)
+    {
+        client = i18n_core->address.free_clients;
+        i18n_core->address.free_clients = client->next;
+       new_connect_id = client->connect_id;
+    }
+    else
+    {
+        client = (Xi18nClient *) malloc (sizeof (Xi18nClient));
+       new_connect_id = ++connect_id;
+    }
+    /*endif*/
+    memset (client, 0, sizeof (Xi18nClient));
+    client->connect_id = new_connect_id;
+    client->pending = (XIMPending *) NULL;
+    client->sync = False;
+    client->byte_order = '?';  /* initial value */
+    memset (&client->pending, 0, sizeof (XIMPending *));
+    client->next = i18n_core->address.clients;
+    i18n_core->address.clients = client;
+
+    return (Xi18nClient *) client;
+}
+
+Xi18nClient *_Xi18nFindClient (Xi18n i18n_core, CARD16 connect_id)
+{
+    Xi18nClient *client = i18n_core->address.clients;
+
+    while (client)
+    {
+        if (client->connect_id == connect_id)
+            return client;
+        /*endif*/
+        client = client->next;
+    }
+    /*endwhile*/
+    return NULL;
+}
+
+void _Xi18nDeleteClient (Xi18n i18n_core, CARD16 connect_id)
+{
+    Xi18nClient *target = _Xi18nFindClient (i18n_core, connect_id);
+    Xi18nClient *ccp;
+    Xi18nClient *ccp0;
+
+    for (ccp = i18n_core->address.clients, ccp0 = NULL;
+         ccp != NULL;
+         ccp0 = ccp, ccp = ccp->next)
+    {
+        if (ccp == target)
+        {
+            if (ccp0 == NULL)
+                i18n_core->address.clients = ccp->next;
+            else
+                ccp0->next = ccp->next;
+            /*endif*/
+            /* put it back to free list */
+            target->next = i18n_core->address.free_clients;
+            i18n_core->address.free_clients = target;
+            return;
+        }
+        /*endif*/
+    }
+    /*endfor*/
+}
+
+void _Xi18nSendMessage (XIMS ims,
+                        CARD16 connect_id,
+                        CARD8 major_opcode,
+                        CARD8 minor_opcode,
+                        unsigned char *data,
+                        long length)
+{
+    Xi18n i18n_core = ims->protocol;
+    FrameMgr fm;
+    extern XimFrameRec packet_header_fr[];
+    unsigned char *reply_hdr = NULL;
+    int header_size;
+    unsigned char *reply = NULL;
+    unsigned char *replyp;
+    int reply_length;
+    long p_len = length/4;
+
+    fm = FrameMgrInit (packet_header_fr,
+                       NULL,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+
+    header_size = FrameMgrGetTotalSize (fm);
+    reply_hdr = (unsigned char *) malloc (header_size);
+    if (reply_hdr == NULL)
+    {
+        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
+        return;
+    }
+    /*endif*/
+    FrameMgrSetBuffer (fm, reply_hdr);
+
+    /* put data */
+    FrameMgrPutToken (fm, major_opcode);
+    FrameMgrPutToken (fm, minor_opcode);
+    FrameMgrPutToken (fm, p_len);
+
+    reply_length = header_size + length;
+    reply = (unsigned char *) malloc (reply_length);
+    replyp = reply;
+    memmove (reply, reply_hdr, header_size);
+    replyp += header_size;
+    memmove (replyp, data, length);
+
+    i18n_core->methods.send (ims, connect_id, reply, reply_length);
+
+    XFree (reply);
+    XFree (reply_hdr);
+    FrameMgrFree (fm);
+}
+
+void _Xi18nSendTriggerKey (XIMS ims, CARD16 connect_id)
+{
+    Xi18n i18n_core = ims->protocol;
+    FrameMgr fm;
+    extern XimFrameRec register_triggerkeys_fr[];
+    XIMTriggerKey *on_keys = i18n_core->address.on_keys.keylist;
+    XIMTriggerKey *off_keys = i18n_core->address.off_keys.keylist;
+    int on_key_num = i18n_core->address.on_keys.count_keys;
+    int off_key_num = i18n_core->address.off_keys.count_keys;
+    unsigned char *reply = NULL;
+    register int i, total_size;
+    CARD16 im_id;
+
+    if (on_key_num == 0  &&  off_key_num == 0)
+        return;
+    /*endif*/
+    
+    fm = FrameMgrInit (register_triggerkeys_fr,
+                       NULL,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+
+    /* set iteration count for on-keys list */
+    FrameMgrSetIterCount (fm, on_key_num);
+    /* set iteration count for off-keys list */
+    FrameMgrSetIterCount (fm, off_key_num);
+
+    /* get total_size */
+    total_size = FrameMgrGetTotalSize (fm);
+
+    reply = (unsigned char *) malloc (total_size);
+    if (!reply)
+        return;
+    /*endif*/
+    memset (reply, 0, total_size);
+    FrameMgrSetBuffer (fm, reply);
+
+    /* Right now XIM_OPEN_REPLY hasn't been sent to this new client, so
+       the input-method-id is still invalid, and should be set to zero...
+       Reter to $(XC)/lib/X11/imDefLkup.c:_XimRegisterTriggerKeysCallback
+     */
+    im_id = 0;
+    FrameMgrPutToken (fm, im_id);  /* input-method-id */
+    for (i = 0;  i < on_key_num;  i++)
+    {
+        FrameMgrPutToken (fm, on_keys[i].keysym);
+        FrameMgrPutToken (fm, on_keys[i].modifier);
+        FrameMgrPutToken (fm, on_keys[i].modifier_mask);
+    }
+    /*endfor*/
+    for (i = 0;  i < off_key_num;  i++)
+    {
+        FrameMgrPutToken (fm, off_keys[i].keysym);
+        FrameMgrPutToken (fm, off_keys[i].modifier);
+        FrameMgrPutToken (fm, off_keys[i].modifier_mask);
+    }
+    /*endfor*/
+    _Xi18nSendMessage (ims,
+                       connect_id,
+                       XIM_REGISTER_TRIGGERKEYS,
+                       0,
+                       reply,
+                       total_size);
+    FrameMgrFree (fm);
+    XFree(reply);
+}
+
+void _Xi18nSetEventMask (XIMS ims,
+                         CARD16 connect_id,
+                         CARD16 im_id,
+                         CARD16 ic_id,
+                         CARD32 forward_mask,
+                         CARD32 sync_mask)
+{
+    Xi18n i18n_core = ims->protocol;
+    FrameMgr fm;
+    extern XimFrameRec set_event_mask_fr[];
+    unsigned char *reply = NULL;
+    register int total_size;
+
+    fm = FrameMgrInit (set_event_mask_fr,
+                       NULL,
+                       _Xi18nNeedSwap (i18n_core, connect_id));
+
+    total_size = FrameMgrGetTotalSize (fm);
+    reply = (unsigned char *) malloc (total_size);
+    if (!reply)
+        return;
+    /*endif*/
+    memset (reply, 0, total_size);
+    FrameMgrSetBuffer (fm, reply);
+
+    FrameMgrPutToken (fm, im_id);      /* input-method-id */
+    FrameMgrPutToken (fm, ic_id);      /* input-context-id */
+    FrameMgrPutToken (fm, forward_mask);
+    FrameMgrPutToken (fm, sync_mask);
+
+    _Xi18nSendMessage (ims,
+                       connect_id,
+                       XIM_SET_EVENT_MASK,
+                       0,
+                       reply,
+                       total_size);
+
+    FrameMgrFree (fm);
+    XFree(reply);
+}
diff --git a/client/x11/IMdkit/i18nX.c b/client/x11/IMdkit/i18nX.c
new file mode 100644 (file)
index 0000000..a5ba080
--- /dev/null
@@ -0,0 +1,497 @@
+/******************************************************************
+         Copyright 1994, 1995 by Sun Microsystems, Inc.
+         Copyright 1993, 1994 by Hewlett-Packard Company
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear
+in supporting documentation, and that the name of Sun Microsystems, Inc.
+and Hewlett-Packard not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior permission.
+Sun Microsystems, Inc. and Hewlett-Packard make no representations about
+the suitability of this software for any purpose.  It is provided "as is"
+without express or implied warranty.
+SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL
+WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+  Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
+
+    This version tidied and debugged by Steve Underwood May 1999
+******************************************************************/
+
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+#include "FrameMgr.h"
+#include "IMdkit.h"
+#include "Xi18n.h"
+#include "Xi18nX.h"
+#include "XimFunc.h"
+
+extern Xi18nClient *_Xi18nFindClient(Xi18n, CARD16);
+extern Xi18nClient *_Xi18nNewClient(Xi18n);
+extern void _Xi18nDeleteClient(Xi18n, CARD16);
+static Bool WaitXConnectMessage(Display*, Window,
+                                XEvent*, XPointer);
+static Bool WaitXIMProtocol(Display*, Window, XEvent*, XPointer);
+
+static XClient *NewXClient (Xi18n i18n_core, Window new_client)
+{
+    Display *dpy = i18n_core->address.dpy;
+    Xi18nClient *client = _Xi18nNewClient (i18n_core);
+    XClient *x_client;
+
+    x_client = (XClient *) malloc (sizeof (XClient));
+    x_client->client_win = new_client;
+    x_client->accept_win = XCreateSimpleWindow (dpy,
+                                                DefaultRootWindow(dpy),
+                                                0,
+                                                0,
+                                                1,
+                                                1,
+                                                1,
+                                                0,
+                                                0);
+    client->trans_rec = x_client;
+    return ((XClient *) x_client);
+}
+
+static unsigned char *ReadXIMMessage (XIMS ims,
+                                      XClientMessageEvent *ev,
+                                      int *connect_id)
+{
+    Xi18n i18n_core = ims->protocol;
+    Xi18nClient *client = i18n_core->address.clients;
+    XClient *x_client = NULL;
+    FrameMgr fm;
+    extern XimFrameRec packet_header_fr[];
+    unsigned char *p = NULL;
+    unsigned char *p1;
+
+    while (client != NULL) {
+        x_client = (XClient *) client->trans_rec;
+        if (x_client->accept_win == ev->window) {
+            *connect_id = client->connect_id;
+            break;
+        }
+        client = client->next;
+    }
+
+    if (ev->format == 8) {
+        /* ClientMessage only */
+        XimProtoHdr *hdr = (XimProtoHdr *) ev->data.b;
+        unsigned char *rec = (unsigned char *) (hdr + 1);
+        register int total_size;
+        CARD8 major_opcode;
+        CARD8 minor_opcode;
+        CARD16 length;
+        extern int _Xi18nNeedSwap (Xi18n, CARD16);
+
+        if (client->byte_order == '?')
+        {
+            if (hdr->major_opcode != XIM_CONNECT)
+                return (unsigned char *) NULL;         /* can do nothing */
+            client->byte_order = (CARD8) rec[0];
+        }
+
+        fm = FrameMgrInit (packet_header_fr,
+                           (char *) hdr,
+                           _Xi18nNeedSwap (i18n_core, *connect_id));
+        total_size = FrameMgrGetTotalSize (fm);
+        /* get data */
+        FrameMgrGetToken (fm, major_opcode);
+        FrameMgrGetToken (fm, minor_opcode);
+        FrameMgrGetToken (fm, length);
+        FrameMgrFree (fm);
+
+        if ((p = (unsigned char *) malloc (total_size + length * 4)) == NULL)
+            return (unsigned char *) NULL;
+
+        p1 = p;
+        memmove (p1, &major_opcode, sizeof (CARD8));
+        p1 += sizeof (CARD8);
+        memmove (p1, &minor_opcode, sizeof (CARD8));
+        p1 += sizeof (CARD8);
+        memmove (p1, &length, sizeof (CARD16));
+        p1 += sizeof (CARD16);
+        memmove (p1, rec, length * 4);
+    }
+    else if (ev->format == 32) {
+        /* ClientMessage and WindowProperty */
+        unsigned long length = (unsigned long) ev->data.l[0];
+        Atom atom = (Atom) ev->data.l[1];
+        int    return_code;
+        Atom   actual_type_ret;
+        int    actual_format_ret;
+        unsigned long bytes_after_ret;
+        unsigned char *prop;
+        unsigned long nitems;
+
+        return_code = XGetWindowProperty (i18n_core->address.dpy,
+                                          x_client->accept_win,
+                                          atom,
+                                          0L,
+                                          length,
+                                          True,
+                                          AnyPropertyType,
+                                          &actual_type_ret,
+                                          &actual_format_ret,
+                                          &nitems,
+                                          &bytes_after_ret,
+                                          &prop);
+        if (return_code != Success || actual_format_ret == 0 || nitems == 0) {
+            if (return_code == Success)
+                XFree (prop);
+            return (unsigned char *) NULL;
+        }
+        if (length != nitems)
+            length = nitems;
+       if (actual_format_ret == 16)
+           length *= 2;
+       else if (actual_format_ret == 32)
+           length *= 4;
+
+        /* if hit, it might be an error */
+        if ((p = (unsigned char *) malloc (length)) == NULL)
+            return (unsigned char *) NULL;
+
+        memmove (p, prop, length);
+        XFree (prop);
+    }
+    return (unsigned char *) p;
+}
+
+static void ReadXConnectMessage (XIMS ims, XClientMessageEvent *ev)
+{
+    Xi18n i18n_core = ims->protocol;
+    XSpecRec *spec = (XSpecRec *) i18n_core->address.connect_addr;
+    XEvent event;
+    Display *dpy = i18n_core->address.dpy;
+    Window new_client = ev->data.l[0];
+    CARD32 major_version = ev->data.l[1];
+    CARD32 minor_version = ev->data.l[2];
+    XClient *x_client = NewXClient (i18n_core, new_client);
+
+    if (ev->window != i18n_core->address.im_window)
+        return;                        /* incorrect connection request */
+    /*endif*/
+    if (major_version != 0  ||  minor_version != 0)
+    {
+        major_version =
+        minor_version = 0;
+        /* Only supporting only-CM & Property-with-CM method */
+    }
+    /*endif*/
+    _XRegisterFilterByType (dpy,
+                            x_client->accept_win,
+                            ClientMessage,
+                            ClientMessage,
+                            WaitXIMProtocol,
+                            (XPointer)ims);
+    event.xclient.type = ClientMessage;
+    event.xclient.display = dpy;
+    event.xclient.window = new_client;
+    event.xclient.message_type = spec->connect_request;
+    event.xclient.format = 32;
+    event.xclient.data.l[0] = x_client->accept_win;
+    event.xclient.data.l[1] = major_version;
+    event.xclient.data.l[2] = minor_version;
+    event.xclient.data.l[3] = XCM_DATA_LIMIT;
+
+    XSendEvent (dpy,
+                new_client,
+                False,
+                NoEventMask,
+                &event);
+    XFlush (dpy);
+}
+
+static Bool Xi18nXBegin (XIMS ims)
+{
+    Xi18n i18n_core = ims->protocol;
+    Display *dpy = i18n_core->address.dpy;
+    XSpecRec *spec = (XSpecRec *) i18n_core->address.connect_addr;
+
+    spec->xim_request = XInternAtom (i18n_core->address.dpy,
+                                     _XIM_PROTOCOL,
+                                     False);
+    spec->connect_request = XInternAtom (i18n_core->address.dpy,
+                                         _XIM_XCONNECT,
+                                         False);
+
+    _XRegisterFilterByType (dpy,
+                            i18n_core->address.im_window,
+                            ClientMessage,
+                            ClientMessage,
+                            WaitXConnectMessage,
+                            (XPointer)ims);
+    return True;
+}
+
+static Bool Xi18nXEnd(XIMS ims)
+{
+    Xi18n i18n_core = ims->protocol;
+    Display *dpy = i18n_core->address.dpy;
+
+    _XUnregisterFilter (dpy,
+                        i18n_core->address.im_window,
+                        WaitXConnectMessage,
+                        (XPointer)ims);
+    return True;
+}
+
+static char *MakeNewAtom (CARD16 connect_id, char *atomName)
+{
+    static int sequence = 0;
+    
+    sprintf (atomName,
+             "_server%d_%d",
+             connect_id,
+             ((sequence > 20)  ?  (sequence = 0)  :  sequence++));
+    return atomName;
+}
+
+static Bool Xi18nXSend (XIMS ims,
+                        CARD16 connect_id,
+                        unsigned char *reply,
+                        long length)
+{
+    Xi18n i18n_core = ims->protocol;
+    Xi18nClient *client = _Xi18nFindClient (i18n_core, connect_id);
+    XSpecRec *spec = (XSpecRec *) i18n_core->address.connect_addr;
+    XClient *x_client = (XClient *) client->trans_rec;
+    XEvent event;
+
+    event.type = ClientMessage;
+    event.xclient.window = x_client->client_win;
+    event.xclient.message_type = spec->xim_request;
+
+    if (length > XCM_DATA_LIMIT)
+    {
+        Atom atom;
+        char atomName[16];
+        Atom actual_type_ret;
+        int actual_format_ret;
+        int return_code;
+        unsigned long nitems_ret;
+        unsigned long bytes_after_ret;
+        unsigned char *win_data;
+
+        event.xclient.format = 32;
+        atom = XInternAtom (i18n_core->address.dpy,
+                            MakeNewAtom (connect_id, atomName),
+                            False);
+        return_code = XGetWindowProperty (i18n_core->address.dpy,
+                                          x_client->client_win,
+                                          atom,
+                                          0L,
+                                          10000L,
+                                          False,
+                                          XA_STRING,
+                                          &actual_type_ret,
+                                          &actual_format_ret,
+                                          &nitems_ret,
+                                          &bytes_after_ret,
+                                          &win_data);
+        if (return_code != Success)
+            return False;
+        /*endif*/
+        if (win_data)
+            XFree ((char *) win_data);
+        /*endif*/
+        XChangeProperty (i18n_core->address.dpy,
+                         x_client->client_win,
+                         atom,
+                         XA_STRING,
+                         8,
+                         PropModeAppend,
+                         (unsigned char *) reply,
+                         length);
+        event.xclient.data.l[0] = length;
+        event.xclient.data.l[1] = atom;
+    }
+    else
+    {
+        unsigned char buffer[XCM_DATA_LIMIT];
+        int i;
+
+        event.xclient.format = 8;
+
+        /* Clear unused field with NULL */
+        memmove(buffer, reply, length);
+        for (i = length; i < XCM_DATA_LIMIT; i++)
+            buffer[i] = (char) 0;
+        /*endfor*/
+        length = XCM_DATA_LIMIT;
+        memmove (event.xclient.data.b, buffer, length);
+    }
+    XSendEvent (i18n_core->address.dpy,
+                x_client->client_win,
+                False,
+                NoEventMask,
+                &event);
+    XFlush (i18n_core->address.dpy);
+    return True;
+}
+
+static Bool CheckCMEvent (Display *display, XEvent *event, XPointer xi18n_core)
+{
+    Xi18n i18n_core = (Xi18n) ((void *) xi18n_core);
+    XSpecRec *spec = (XSpecRec *) i18n_core->address.connect_addr;
+
+    if ((event->type == ClientMessage)
+        &&
+        (event->xclient.message_type == spec->xim_request))
+    {
+        return  True;
+    }
+    /*endif*/
+    return  False;
+}
+
+static Bool Xi18nXWait (XIMS ims,
+                        CARD16 connect_id,
+                        CARD8 major_opcode,
+                        CARD8 minor_opcode)
+{
+    Xi18n i18n_core = ims->protocol;
+    XEvent event;
+    Xi18nClient *client = _Xi18nFindClient (i18n_core, connect_id);
+    XClient *x_client = (XClient *) client->trans_rec;
+
+    for (;;)
+    {
+        unsigned char *packet;
+        XimProtoHdr *hdr;
+        int connect_id_ret;
+
+        XIfEvent (i18n_core->address.dpy,
+                  &event,
+                  CheckCMEvent,
+                  (XPointer) i18n_core);
+        if (event.xclient.window == x_client->accept_win)
+        {
+            if ((packet = ReadXIMMessage (ims,
+                                          (XClientMessageEvent *) & event,
+                                          &connect_id_ret))
+                == (unsigned char*) NULL)
+            {
+                return False;
+            }
+            /*endif*/
+            hdr = (XimProtoHdr *)packet;
+
+            if ((hdr->major_opcode == major_opcode)
+                &&
+                (hdr->minor_opcode == minor_opcode))
+            {
+                return True;
+            }
+            else if (hdr->major_opcode == XIM_ERROR)
+            {
+                return False;
+            }
+            /*endif*/
+        }
+        /*endif*/
+    }
+    /*endfor*/
+}
+
+static Bool Xi18nXDisconnect (XIMS ims, CARD16 connect_id)
+{
+    Xi18n i18n_core = ims->protocol;
+    Display *dpy = i18n_core->address.dpy;
+    Xi18nClient *client = _Xi18nFindClient (i18n_core, connect_id);
+    XClient *x_client = (XClient *) client->trans_rec;
+
+    XDestroyWindow (dpy, x_client->accept_win);
+    _XUnregisterFilter (dpy,
+                       x_client->accept_win,
+                        WaitXIMProtocol,
+                       (XPointer)ims);
+    XFree (x_client);
+    _Xi18nDeleteClient (i18n_core, connect_id);
+    return True;
+}
+
+Bool _Xi18nCheckXAddress (Xi18n i18n_core,
+                          TransportSW *transSW,
+                          char *address)
+{
+    XSpecRec *spec;
+
+    if (!(spec = (XSpecRec *) malloc (sizeof (XSpecRec))))
+        return False;
+    /*endif*/
+    
+    i18n_core->address.connect_addr = (XSpecRec *) spec;
+    i18n_core->methods.begin = Xi18nXBegin;
+    i18n_core->methods.end = Xi18nXEnd;
+    i18n_core->methods.send = Xi18nXSend;
+    i18n_core->methods.wait = Xi18nXWait;
+    i18n_core->methods.disconnect = Xi18nXDisconnect;
+    return True;
+}
+
+static Bool WaitXConnectMessage (Display *dpy,
+                                 Window win,
+                                 XEvent *ev,
+                                 XPointer client_data)
+{
+    XIMS ims = (XIMS)client_data;
+    Xi18n i18n_core = ims->protocol;
+    XSpecRec *spec = (XSpecRec *) i18n_core->address.connect_addr;
+
+    if (((XClientMessageEvent *) ev)->message_type
+        == spec->connect_request)
+    {
+        ReadXConnectMessage (ims, (XClientMessageEvent *) ev);
+        return True;
+    }
+    /*endif*/
+    return False;
+}
+
+static Bool WaitXIMProtocol (Display *dpy,
+                             Window win,
+                             XEvent *ev,
+                             XPointer client_data)
+{
+    extern void _Xi18nMessageHandler (XIMS, CARD16, unsigned char *, Bool *);
+    XIMS ims = (XIMS) client_data;
+    Xi18n i18n_core = ims->protocol;
+    XSpecRec *spec = (XSpecRec *) i18n_core->address.connect_addr;
+    Bool delete = True;
+    unsigned char *packet;
+    int connect_id;
+
+    if (((XClientMessageEvent *) ev)->message_type
+        == spec->xim_request)
+    {
+        if ((packet = ReadXIMMessage (ims,
+                                      (XClientMessageEvent *) ev,
+                                      &connect_id))
+            == (unsigned char *)  NULL)
+        {
+            return False;
+        }
+        /*endif*/
+        _Xi18nMessageHandler (ims, connect_id, packet, &delete);
+        if (delete == True)
+            XFree (packet);
+        /*endif*/
+        return True;
+    }
+    /*endif*/
+    return False;
+}
diff --git a/client/x11/Makefile.am b/client/x11/Makefile.am
new file mode 100644 (file)
index 0000000..25517cb
--- /dev/null
@@ -0,0 +1,60 @@
+# vim:set noet ts=4:
+#
+# ibus - The Input Bus
+#
+# Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this program; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+# Boston, MA  02111-1307  USA
+
+
+IMdkit = $(builddir)/IMdkit/libIMdkit.la
+libibus_gtk = $(top_builddir)/gtk2/libibus-gtk.la
+
+bin_PROGRAMS = ibus-x11
+
+ibus_x11_SOURCES = \
+       main.c \
+       gdk-private.c \
+       $(NULL)
+
+ibus_x11_DEPENDENCIES = \
+       $(IMdkit) \
+       $(libibus_gtk) \
+       $(NULL)
+
+ibus_x11_LDADD = \
+       @GTK2_LIBS@ \
+       $(IMdkit) \
+       $(libibus_gtk) \
+       $(NULL)
+
+ibus_x11_CFLAGS = \
+       @GTK2_CFLAGS@ \
+       -I$(srcdir)/IMdkit \
+       -I$(top_srcdir)/gtk2 \
+       $(NULL)
+
+noinst_HEADERS = \
+       gdk-private.h \
+       $(NULL)
+
+$(IMdkit):
+       (cd $(builddir)/IMdkit; make)
+
+$(libibus_gtk):
+       (cd $(top_builddir)/gtk2; make)
+
+SUBDIRS = IMdkit 
diff --git a/client/x11/gdk-private.c b/client/x11/gdk-private.c
new file mode 100644 (file)
index 0000000..e3d5522
--- /dev/null
@@ -0,0 +1,116 @@
+/* ibus
+ * Copyright (C) 2008 Huang Peng <shawn.p.huang@gmail.com>
+ *
+ * gdk-private.c: Copied some code from gtk2
+ *
+ * This tool is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include <gtk/gtk.h>
+#include <gdk/gdkx.h>
+#include <gdk/gdkkeysyms.h>
+
+void
+translate_key_event (GdkDisplay *display,
+                    GdkEvent   *event,
+                    XEvent     *xevent)
+{
+  GdkKeymap *keymap = gdk_keymap_get_for_display (display);
+  gunichar c = 0;
+  gchar buf[7];
+
+  event->key.type = xevent->xany.type == KeyPress ? GDK_KEY_PRESS : GDK_KEY_RELEASE;
+  event->key.time = xevent->xkey.time;
+
+  event->key.state = (GdkModifierType) xevent->xkey.state;
+  //event->key.group = _gdk_x11_get_group_for_state (display, xevent->xkey.state);
+  event->key.group = 0;
+  event->key.hardware_keycode = xevent->xkey.keycode;
+
+  event->key.keyval = GDK_VoidSymbol;
+
+  gdk_keymap_translate_keyboard_state (keymap,
+                                      event->key.hardware_keycode,
+                                      event->key.state,
+                                      event->key.group,
+                                      &event->key.keyval,
+                                      NULL, NULL, NULL);
+
+  //_gdk_keymap_add_virtual_modifiers (keymap, &event->key.state);
+  event->key.is_modifier = 
+       (event->key.state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) != 0;
+//  event->key.is_modifier = _gdk_keymap_key_is_modifier (keymap, event->key.hardware_keycode);
+
+  /* Fill in event->string crudely, since various programs
+   * depend on it.
+   */
+  event->key.string = NULL;
+  
+  if (event->key.keyval != GDK_VoidSymbol)
+    c = gdk_keyval_to_unicode (event->key.keyval);
+
+  if (c)
+    {
+      gsize bytes_written;
+      gint len;
+
+      /* Apply the control key - Taken from Xlib
+       */
+      if (event->key.state & GDK_CONTROL_MASK)
+       {
+         if ((c >= '@' && c < '\177') || c == ' ') c &= 0x1F;
+         else if (c == '2')
+           {
+             event->key.string = g_memdup ("\0\0", 2);
+             event->key.length = 1;
+             buf[0] = '\0';
+             goto out;
+           }
+         else if (c >= '3' && c <= '7') c -= ('3' - '\033');
+         else if (c == '8') c = '\177';
+         else if (c == '/') c = '_' & 0x1F;
+       }
+      
+      len = g_unichar_to_utf8 (c, buf);
+      buf[len] = '\0';
+      
+      event->key.string = g_locale_from_utf8 (buf, len,
+                                             NULL, &bytes_written,
+                                             NULL);
+      if (event->key.string)
+       event->key.length = bytes_written;
+    }
+  else if (event->key.keyval == GDK_Escape)
+    {
+      event->key.length = 1;
+      event->key.string = g_strdup ("\033");
+    }
+  else if (event->key.keyval == GDK_Return ||
+         event->key.keyval == GDK_KP_Enter)
+    {
+      event->key.length = 1;
+      event->key.string = g_strdup ("\r");
+    }
+
+  if (!event->key.string)
+    {
+      event->key.length = 0;
+      event->key.string = g_strdup ("");
+    }
+  
+ out:
+  return;
+}
+
diff --git a/client/x11/gdk-private.h b/client/x11/gdk-private.h
new file mode 100644 (file)
index 0000000..bd918ab
--- /dev/null
@@ -0,0 +1,28 @@
+/* ibus
+ * Copyright (C) 2008 Huang Peng <shawn.p.huang@gmail.com>
+ *
+ * gdk-private.h:
+ *
+ * This tool is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#ifndef __GTK_PRIVATE_H_
+#define __GTK_PRIVATE_H_
+
+void
+translate_key_event (GdkDisplay *display,
+                    GdkEvent   *event,
+                    XEvent     *xevent);
+#endif
diff --git a/client/x11/main.c b/client/x11/main.c
new file mode 100644 (file)
index 0000000..cb361a2
--- /dev/null
@@ -0,0 +1,761 @@
+/* vim:set et ts=4: */
+/* ibus
+ * Copyright (C) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
+ *
+ * main.c:
+ *
+ * This tool is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include <X11/Xproto.h>
+#include <X11/Xlib.h>
+#include <X11/keysym.h>
+#include <X11/Xutil.h>
+#include <XimProto.h>
+#include <IMdkit.h>
+#include <Xi18n.h>
+#include <stdio.h>
+#include <gtk/gtk.h>
+#include <gdk/gdkx.h>
+#include <gdk/gdkkeysyms.h>
+#include <langinfo.h>
+#include <locale.h>
+#include <iconv.h>
+#include <signal.h>
+#include <stdlib.h>
+
+#define _GNU_SOURCES
+#include <getopt.h>
+
+#define LOG(level, fmt, args...) \
+    if (g_debug_level >= (level)) { \
+        g_debug (fmt, args); \
+    }
+
+#include <ibusimclient.h>
+#include "gdk-private.h"
+
+struct _X11ICONN {
+    GList        *clients;
+};
+typedef struct _X11ICONN    X11ICONN;
+
+struct _X11IC {
+    GtkIMContext *context;
+    GdkWindow     *client_window;
+    GdkWindow     *focus_window;
+    gint32        input_style;
+    X11ICONN    *conn;
+    gint        icid;
+    gint        connect_id;
+    gchar        *lang;
+    GdkRectangle    preedit_area;
+};
+typedef struct _X11IC    X11IC;
+
+
+
+static void _xim_commit_cb (GtkIMContext *context, gchar *arg, gpointer data);
+
+static GHashTable     *_clients = NULL;
+static GHashTable     *_connections = NULL;
+static XIMS _xims = NULL;
+static gchar _server_name[128] = "ibus";
+static gchar _locale[1024] =
+    "aa,af,am,an,ar,as,az,be,bg,bn,br,bs,"
+    "ca,cs,cy,da,de,dz,el,en,es,et,eu,"
+    "fa,fi,fo,fr,fy,ga,gd,gl,gu,gv,"
+    "he,hi,hr,hu,hy,id,is,it,iw,ja,"
+    "ka,kk,kl,km,kn,ko,ku,kw,ky,lg,lo,lt,lv,"
+    "mg,mi,mk,ml,mn,mr,ms,mt,nb,ne,nl,nn,no,nr,"
+    "oc,om,or,pa,pl,pt,ro,ru,rw,"
+    "se,si,sk,sl,so,sq,sr,ss,st,sv,"
+    "ta,te,tg,th,ti,tl,tn,tr,ts,tt,"
+    "uk,ur,uz,ve,vi,wa,xh,yi,zh,zu";
+
+static gboolean _kill_daemon = FALSE;
+static gint        g_debug_level = 0;
+
+IBusIMClient *_client = NULL;
+
+#if 0
+static void
+_xim_preedit_start (XIMS xims, int icid, int connect_id)
+{
+    IMPreeditStateStruct ips;
+    ips.major_code = 0;
+    ips.minor_code = 0;
+    ips.icid = icid;
+    ips.connect_id = connect_id;
+    IMPreeditStart (xims, (XPointer)&ips);
+}
+
+static void
+_xim_preedit_end (XIMS xims, int icid, int connect_id)
+{
+    IMPreeditStateStruct ips;
+    ips.major_code = 0;
+    ips.minor_code = 0;
+    ips.icid = icid;
+    ips.connect_id = connect_id;
+    IMPreeditEnd (xims, (XPointer)&ips);
+}
+#endif
+
+int
+_xim_store_ic_values (X11IC *ic, IMChangeICStruct *call_data)
+{
+    XICAttribute *ic_attr = call_data->ic_attr;
+    XICAttribute *pre_attr = call_data->preedit_attr;
+    XICAttribute *sts_attr = call_data->status_attr;
+
+    gint i;
+    guint32 attrs = 1;
+
+    if (ic == NULL) {
+        return 0;
+    }
+#define _is_attr(a, b)    (strcmp(a, b->name) == 0)
+    for (i=0; i< (int) call_data->ic_attr_num; ++i, ++ic_attr) {
+        if (_is_attr (XNInputStyle, ic_attr)) {
+            ic->input_style = *(gint32 *) ic_attr->value;
+        }
+        else if (_is_attr (XNClientWindow, ic_attr)) {
+            Window w;
+
+            if (ic->client_window != NULL) {
+                g_object_unref (ic->client_window);
+                ic->client_window = NULL;
+            }
+
+            w =  *(Window *) call_data->ic_attr[i].value;
+            if (w) {
+                ic->client_window = gdk_window_foreign_new (w);
+                if (ic->client_window)
+                    g_object_set_data (G_OBJECT (ic->client_window), "IBUS_IC", ic);
+            }
+        }
+        else if (_is_attr (XNFocusWindow, ic_attr)) {
+            Window w;
+
+            if (ic->focus_window != NULL) {
+                g_object_unref (ic->focus_window);
+                ic->focus_window = NULL;
+            }
+
+            w =  *(Window *) call_data->ic_attr[i].value;
+            if (w) {
+                ic->focus_window = gdk_window_foreign_new (w);
+                if (ic->focus_window)
+                    g_object_set_data (G_OBJECT (ic->focus_window), "IBUS_IC", ic);
+            }
+        }
+        else {
+            // fprintf (stderr, "Unknown attr: %s\n", ic_attr->name);
+        }
+    }
+
+    for (i=0; i< (int) call_data->preedit_attr_num; ++i, ++pre_attr) {
+        if (_is_attr (XNSpotLocation, pre_attr)) {
+            ic->preedit_area.x = ((XPoint *)pre_attr->value)->x;
+            ic->preedit_area.y = ((XPoint *)pre_attr->value)->y;
+        }
+        else {
+            // fprintf (stderr, "Unknown attr: %s\n", pre_attr->name);
+        }
+    }
+
+    for (i=0; i< (int) call_data->status_attr_num; ++i, ++sts_attr) {
+        // printf ("set status: %s\n", sts_attr->name);
+    }
+
+#undef _is_attr
+
+    return attrs;
+
+}
+
+
+static void
+_xim_commit_cb (GtkIMContext *context, gchar *arg, gpointer data)
+{
+    char *clist[1];
+    XTextProperty tp;
+    IMCommitStruct cms;
+
+    X11IC *ic = (X11IC *)data;
+
+    clist[0] = arg;
+    Xutf8TextListToTextProperty (GDK_DISPLAY (), clist, 1, XCompoundTextStyle, &tp);
+
+    memset (&cms, 0, sizeof (cms));
+    cms.major_code = XIM_COMMIT;
+    cms.icid = ic->icid;
+    cms.connect_id = ic->connect_id;
+    cms.flag = XimLookupChars;
+    cms.commit_string = (char *)tp.value;
+    IMCommitString (_xims, (XPointer) & cms);
+
+    XFree (tp.value);
+
+}
+
+int
+xim_create_ic (XIMS xims, IMChangeICStruct *call_data)
+{
+    static int base_icid = 1;
+    X11IC *ic;
+    int i;
+
+    LOG (1, "XIM_CREATE_IC ic=%d, connect_id=%d", call_data->icid, call_data->connect_id);
+
+    call_data->icid = base_icid ++;
+
+    ic = g_new0 (X11IC, 1);
+    ic->icid = call_data->icid;
+    ic->connect_id = call_data->connect_id;
+    ic->conn = (X11ICONN *)g_hash_table_lookup (_connections,
+                        (gconstpointer)(unsigned long)call_data->connect_id);
+
+    i = _xim_store_ic_values (ic, call_data);
+
+    ic->context = (GtkIMContext *)ibus_im_client_create_im_context (_client);
+
+    if (ic->focus_window)
+        gtk_im_context_set_client_window (ic->context, ic->focus_window);
+    else
+        gtk_im_context_set_client_window (ic->context, ic->client_window);
+
+    gtk_im_context_set_use_preedit (ic->context, FALSE);
+    g_signal_connect (ic->context,
+            "commit",
+            G_CALLBACK (_xim_commit_cb),
+            (gpointer)ic);
+#if 0
+    g_signal_connect (ic->context,
+            "preedit-changed",
+            G_CALLBACK (_xim_preedit_changed_cb),
+            (gpointer)ic);
+#endif
+
+    g_hash_table_insert (_clients, (gpointer)ic->icid, (gpointer) ic);
+    ic->conn->clients = g_list_append (ic->conn->clients, (gpointer) ic);
+
+    return 1;
+}
+
+
+int
+xim_destroy_ic (XIMS xims, IMChangeICStruct *call_data)
+{
+    X11IC *ic;
+
+    LOG (1, "XIM_DESTROY_IC ic=%d, connect_id=%d", call_data->icid, call_data->connect_id);
+
+    ic = (X11IC *)g_hash_table_lookup (_clients,
+                (gconstpointer)(unsigned long)call_data->icid);
+    g_object_unref (ic->context);
+    ic->conn->clients = g_list_remove (ic->conn->clients, (gconstpointer)ic);
+    g_hash_table_remove (_clients,
+                (gconstpointer)(unsigned long)call_data->icid);
+
+    if (ic->client_window)
+        g_object_unref (ic->client_window);
+    if (ic->focus_window)
+        g_object_unref (ic->focus_window);
+
+    g_free (ic);
+
+    return 1;
+}
+
+int
+xim_set_ic_focus (XIMS xims, IMChangeFocusStruct *call_data)
+{
+    X11IC *ic;
+
+    LOG (1, "XIM_SET_IC_FOCUS ic=%d, connect_id=%d", call_data->icid, call_data->connect_id);
+
+    ic = (X11IC *)g_hash_table_lookup (_clients,
+                (gconstpointer)(unsigned long)call_data->icid);
+
+    gtk_im_context_focus_in (ic->context);
+
+    return 1;
+
+}
+
+int
+xim_unset_ic_focus (XIMS xims, IMChangeFocusStruct *call_data)
+{
+    X11IC *ic;
+
+    LOG (1, "XIM_UNSET_IC_FOCUS ic=%d, connect_id=%d", call_data->icid, call_data->connect_id);
+
+    ic = (X11IC *)g_hash_table_lookup (_clients,
+            (gconstpointer)(unsigned long)call_data->icid);
+
+    gtk_im_context_focus_out (ic->context);
+
+    return 1;
+
+}
+
+int
+xim_forward_event (XIMS xims, IMForwardEventStruct *call_data)
+{
+
+    X11IC *ic;
+    XKeyEvent *xevent;
+    GdkEventKey event;
+    GdkWindow *window;
+
+    LOG (1, "XIM_FORWARD_EVENT ic=%d, connect_id=%d", call_data->icid, call_data->connect_id);
+    ic = (X11IC *)g_hash_table_lookup (_clients,
+                (gconstpointer)(unsigned long)call_data->icid);
+
+    g_return_val_if_fail (ic != NULL, 1);
+
+    xevent = (XKeyEvent*) &(call_data->event);
+    window = gdk_window_foreign_new (xevent->window);
+
+    translate_key_event (gdk_drawable_get_display (window),
+        (GdkEvent *)&event, (XEvent *)xevent);
+
+    event.send_event = xevent->send_event;
+    event.window = window;
+
+    g_debug ("send_event = %d", event.send_event);
+
+    if (gtk_im_context_filter_keypress (ic->context, &event)) {
+        g_object_unref (window);
+        return 1;
+    }
+    g_object_unref (window);
+
+    IMForwardEventStruct fe;
+    memset (&fe, 0, sizeof (fe));
+
+    fe.major_code = XIM_FORWARD_EVENT;
+    fe.icid = ic->icid;
+    fe.connect_id = ic->connect_id;
+    fe.sync_bit = 0;
+    fe.serial_number = 0L;
+    fe.event = call_data->event;
+
+    IMForwardEvent (_xims, (XPointer) & fe);
+
+    return 1;
+}
+
+
+int
+xim_open (XIMS xims, IMOpenStruct *call_data)
+{
+    X11ICONN *conn;
+
+    LOG (1, "XIM_OPEN connect_id=%d", call_data->connect_id);
+
+    conn = (X11ICONN *)g_hash_table_lookup (_connections,
+                (gconstpointer)(unsigned long)call_data->connect_id);
+
+    g_return_val_if_fail (conn == NULL, 1);
+
+    conn = g_new0(X11ICONN, 1);
+
+    g_hash_table_insert (_connections,
+        (gpointer)(unsigned long)call_data->connect_id,
+        (gpointer) conn);
+
+    return 1;
+}
+
+static void
+_free_ic (gpointer data, gpointer user_data)
+{
+    X11IC *ic = (X11IC *) data;
+
+    g_return_if_fail (ic != NULL);
+
+    g_object_unref (ic->context);
+
+    /* Remove the IC from g_client dictionary */
+    g_hash_table_remove (_clients,
+                (gconstpointer)(unsigned long)ic->icid);
+
+    g_free (ic);
+}
+
+int
+xim_close (XIMS ims, IMCloseStruct *call_data)
+{
+    X11ICONN *conn;
+
+    LOG (1, "XIM_CLOSE connect_id=%d", call_data->connect_id);
+
+    conn = (X11ICONN *)g_hash_table_lookup (_connections,
+                (gconstpointer)(unsigned long)call_data->connect_id);
+
+    g_return_val_if_fail (conn != NULL, 1);
+
+    g_list_foreach (conn->clients, _free_ic, NULL);
+
+    g_list_free (conn->clients);
+
+    // g_object_unref (conn->context);
+
+    g_hash_table_remove (_connections, (gconstpointer)(unsigned long)call_data->connect_id);
+
+    g_free (conn);
+
+    return 1;
+}
+
+
+
+int
+xim_set_ic_values (XIMS xims, IMChangeICStruct *call_data)
+{
+    X11IC *ic;
+    gint i;
+
+    LOG (1, "XIM_SET_IC_VALUES ic=%d connect_id=%d", call_data->icid, call_data->connect_id);
+
+    ic = (X11IC *)g_hash_table_lookup (_clients,
+                (gconstpointer)(unsigned long)call_data->icid);
+
+    g_return_val_if_fail (ic != NULL, 1);
+
+    i = _xim_store_ic_values (ic, call_data);
+
+    if (i) {
+        gtk_im_context_set_cursor_location (ic->context, &ic->preedit_area);
+    }
+
+    return i;
+}
+
+
+int
+xim_reset_ic (XIMS xims, IMResetICStruct *call_data)
+{
+    X11IC *ic;
+
+    LOG (1, "XIM_RESET_IC ic=%d connect_id=%d", call_data->icid, call_data->connect_id);
+
+    ic = (X11IC *)g_hash_table_lookup (_clients,
+                (gconstpointer)(unsigned long)call_data->icid);
+
+    g_return_val_if_fail (ic != NULL, 1);
+
+    gtk_im_context_reset (ic->context);
+
+    return 1;
+}
+
+int
+ims_protocol_handler (XIMS xims, IMProtocol *call_data)
+{
+    g_return_val_if_fail (xims != NULL, 1);
+    g_return_val_if_fail (call_data != NULL, 1);
+
+    switch (call_data->major_code) {
+    case XIM_OPEN:
+        return xim_open (xims, (IMOpenStruct *)call_data);
+    case XIM_CLOSE:
+        return xim_close (xims, (IMCloseStruct *)call_data);
+    case XIM_CREATE_IC:
+        return xim_create_ic (xims, (IMChangeICStruct *)call_data);
+    case XIM_DESTROY_IC:
+        return xim_destroy_ic (xims, (IMChangeICStruct *)call_data);
+    case XIM_SET_IC_VALUES:
+        return xim_set_ic_values (xims, (IMChangeICStruct *)call_data);
+    case XIM_GET_IC_VALUES:
+        return 1;
+    case XIM_FORWARD_EVENT:
+        return xim_forward_event (xims, (IMForwardEventStruct *)call_data);
+    case XIM_SET_IC_FOCUS:
+        return xim_set_ic_focus (xims, (IMChangeFocusStruct *)call_data);
+    case XIM_UNSET_IC_FOCUS:
+        return xim_unset_ic_focus (xims, (IMChangeFocusStruct *)call_data);
+    case XIM_RESET_IC:
+        return xim_reset_ic (xims, (IMResetICStruct *)call_data);
+    case XIM_TRIGGER_NOTIFY:
+    case XIM_PREEDIT_START_REPLY:
+    case XIM_PREEDIT_CARET_REPLY:
+    case XIM_SYNC_REPLY:
+        return 1;
+    default:
+        break;
+    }
+    return 1;
+}
+
+
+static void
+_xim_forward_gdk_event (GdkEventKey *event)
+{
+    X11IC *ic;
+    ic = (X11IC *)g_object_get_data (G_OBJECT (event->window), "IBUS_IC");
+    if (ic == NULL)
+        return;
+    IMForwardEventStruct fe;
+    XEvent xkp;
+    memset (&xkp, 0, sizeof (xkp));
+    memset (&fe, 0, sizeof (fe));
+
+    xkp.xkey.type = (event->type == GDK_KEY_PRESS) ? KeyPress : KeyRelease;
+    xkp.xkey.serial = 0L;
+    xkp.xkey.send_event = False;
+    xkp.xkey.same_screen = False;
+    xkp.xkey.display = GDK_WINDOW_XDISPLAY (event->window);
+    xkp.xkey.window = GDK_WINDOW_XWINDOW (event->window);
+    xkp.xkey.subwindow = None;
+    xkp.xkey.root = DefaultRootWindow (GDK_WINDOW_XDISPLAY (event->window));
+    xkp.xkey.time = event->time;
+    xkp.xkey.state = event->state;
+    xkp.xkey.keycode = event->hardware_keycode;
+
+    fe.major_code = XIM_FORWARD_EVENT;
+    fe.icid = ic->icid;
+    fe.connect_id = ic->connect_id;
+    fe.sync_bit = 0;
+    fe.serial_number = 0L;
+    fe.event = xkp;
+    IMForwardEvent (_xims, (XPointer) & fe);
+
+}
+
+static void
+_xim_event_cb (GdkEvent *event, gpointer data)
+{
+    g_debug ("xim event");
+    switch (event->type) {
+    case GDK_KEY_PRESS:
+    case GDK_KEY_RELEASE:
+        _xim_forward_gdk_event ((GdkEventKey *)event);
+        break;
+    default:
+        gtk_main_do_event (event);
+        break;
+    }
+}
+
+static void
+_xim_event_destroy_cb (gpointer data)
+{
+}
+
+static void
+_xim_client_disconnected_cb (IBusIMClient *client, gpointer data)
+{
+    gtk_main_quit ();
+}
+
+static void
+_xim_init_IMdkit ()
+{
+#if 0
+    XIMStyle ims_styles_overspot [] = {
+        XIMPreeditPosition  | XIMStatusNothing,
+        XIMPreeditNothing   | XIMStatusNothing,
+        XIMPreeditPosition  | XIMStatusCallbacks,
+        XIMPreeditNothing   | XIMStatusCallbacks,
+        0
+    };
+#endif
+
+    XIMStyle ims_styles_onspot [] = {
+        XIMPreeditPosition  | XIMStatusNothing,
+        XIMPreeditCallbacks | XIMStatusNothing,
+        XIMPreeditNothing   | XIMStatusNothing,
+        XIMPreeditPosition  | XIMStatusCallbacks,
+        XIMPreeditCallbacks | XIMStatusCallbacks,
+        XIMPreeditNothing   | XIMStatusCallbacks,
+        0
+    };
+
+    XIMEncoding ims_encodings[] = {
+        "COMPOUND_TEXT",
+        0
+    };
+
+    GdkWindowAttr window_attr = {
+        title :     "ibus-xim",
+        event_mask :     GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
+        wclass:        GDK_INPUT_OUTPUT,
+        window_type:    GDK_WINDOW_TOPLEVEL,
+        override_redirect: 1,
+    };
+
+    XIMStyles styles;
+    XIMEncodings encodings;
+
+    GdkWindow *win;
+
+    win = gdk_window_new (NULL, &window_attr, GDK_WA_TITLE);
+
+    styles.count_styles =
+        sizeof (ims_styles_onspot)/sizeof (XIMStyle) - 1;
+    styles.supported_styles = ims_styles_onspot;
+
+    encodings.count_encodings =
+        sizeof (ims_encodings)/sizeof (XIMEncoding) - 1;
+    encodings.supported_encodings = ims_encodings;
+
+    _xims = IMOpenIM(GDK_DISPLAY(),
+        IMModifiers, "Xi18n",
+        IMServerWindow, GDK_WINDOW_XWINDOW(win),
+        IMServerName, _server_name,
+        IMLocale, _locale,
+        IMServerTransport, "X/",
+        IMInputStyles, &styles,
+        IMEncodingList, &encodings,
+        IMProtocolHandler, ims_protocol_handler,
+        IMFilterEventMask, KeyPressMask | KeyReleaseMask,
+        NULL);
+
+    gdk_event_handler_set (_xim_event_cb, NULL,
+        _xim_event_destroy_cb);
+
+    ibus_im_client_register_type (NULL);
+    ibus_im_context_register_type (NULL);
+    _client = ibus_im_client_new ();
+
+    if (!ibus_im_client_get_connected (_client)) {
+        g_warning ("Can not connect to ibus daemon");
+        exit (1);
+    }
+
+    g_signal_connect (G_OBJECT (_client),
+        "disconnected",
+        G_CALLBACK (_xim_client_disconnected_cb),
+        NULL);
+
+}
+
+static void
+_xim_kill_daemon ()
+{
+    ibus_im_client_kill_daemon(_client);
+}
+
+static void
+_xim_sighandler (int sig)
+{
+    exit(EXIT_FAILURE);
+}
+
+static void
+print_usage (FILE *fp, gchar *name)
+{
+    fprintf (fp,
+        "Usage:\n"
+        " %s --help               Show this message\n"
+        "    --server-name= -n    Setup xim sevrer name\n"
+        "    --locale= -l         Setup support locale\n"
+        "    --kill-daemon -k     Kill ibus daemon when exit\n"
+        "    --debug= -v          Setup debug level\n",
+        name);
+}
+
+int error_handler (Display *dpy, XErrorEvent *e)
+{
+    g_debug (
+        "XError: "
+        "serial=%d error_code=%d request_code=%d minor_code=%d resourceid=%d",
+        e->serial, e->error_code, e->request_code, e->minor_code, e->resourceid);
+    return 1;
+}
+
+int main (int argc, char **argv)
+{
+    gint option_index = 0;
+    gint c;
+
+
+    gtk_init (&argc, &argv);
+    XSetErrorHandler (error_handler);
+
+    while (1) {
+        static struct option long_options [] = {
+            {"debug", 1, 0, 0},
+            {"server-name", 1, 0, 0},
+            {"locale", 1, 0, 0},
+            {"help", 0, 0, 0},
+            {"kill-daemon", 0, 0, 0},
+            {0, 0, 0, 0},
+        };
+
+        c = getopt_long (argc, argv, "v:n:l:k",
+            long_options, &option_index);
+
+        if (c == -1) break;
+
+        switch (c) {
+        case 0:
+            if (strcmp (long_options[option_index].name, "debug") == 0) {
+                g_debug_level = atoi (optarg);
+            }
+            else if (strcmp (long_options[option_index].name, "server-name") == 0) {
+                strncpy (_server_name, optarg, sizeof (_server_name));
+            }
+            else if (strcmp (long_options[option_index].name, "locale") == 0) {
+                strncpy (_locale, optarg, sizeof (_locale));
+            }
+            else if (strcmp (long_options[option_index].name, "help") == 0) {
+                print_usage (stdout, argv[0]);
+                exit (EXIT_SUCCESS);
+            }
+            else if (strcmp (long_options[option_index].name, "kill-daemon") == 0) {
+                _kill_daemon = TRUE;
+            }
+            break;
+        case 'v':
+            g_debug_level = atoi (optarg);
+            break;
+        case 'n':
+            strncpy (_server_name, optarg, sizeof (_server_name));
+            break;
+        case 'l':
+            strncpy (_locale, optarg, sizeof (_locale));
+            break;
+        case 'k':
+            _kill_daemon = TRUE;
+            break;
+        case '?':
+        default:
+            print_usage (stderr, argv[0]);
+            exit (EXIT_FAILURE);
+        }
+    }
+
+    _clients = g_hash_table_new (g_direct_hash, g_direct_equal);
+    _connections = g_hash_table_new (g_direct_hash, g_direct_equal);
+
+    signal (SIGINT, _xim_sighandler);
+    signal (SIGTERM, _xim_sighandler);
+
+    if (_kill_daemon)
+        g_atexit (_xim_kill_daemon);
+
+    _xim_init_IMdkit ();
+    gtk_main();
+
+    exit (EXIT_SUCCESS);
+}
+
+
+
index 2c04a25015af5281cb44e763b95906050db267ce..ac94eb37f47622a301c73199ad4911d3161039e3 100644 (file)
@@ -175,10 +175,13 @@ panel/ibus-panel
 gconf/Makefile
 gconf/ibus-gconf
 engine/Makefile
-gtk2/Makefile
-qt4/Makefile
-x11/Makefile
-x11/IMdkit/Makefile
+lib/Makefile
+lib/gtk2/Makefile
+client/Makefile
+client/gtk2/Makefile
+client/qt4/Makefile
+client/x11/Makefile
+client/x11/IMdkit/Makefile
 setup/Makefile
 setup/ibus-setup
 setup/ibus-setup.desktop
diff --git a/gtk2/Makefile.am b/gtk2/Makefile.am
deleted file mode 100644 (file)
index 399544a..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-# vim:set noet ts=4:
-#
-# ibus - The Input Bus
-#
-# Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this program; if not, write to the
-# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
-# Boston, MA  02111-1307  USA
-
-INCLUDES = \
-       -I$(top_srcdir) \
-       $(NULL)
-
-lib_LTLIBRARIES = libibus-gtk.la
-libibus_gtk_la_SOURCES = \
-       ibusimcontext.c \
-       ibusimcontext.h \
-       ibusimclient.c \
-       ibusimclient.h \
-       ibusmarshalers.c \
-       ibusmarshalers.h \
-       $(NULL)
-libibus_gtk_la_CFLAGS = \
-       @GTK2_CFLAGS@ \
-       @DBUS_CFLAGS@ \
-       -DG_LOG_DOMAIN=\"IBUS\" \
-       $(NULL)
-libibus_gtk_la_LDFLAGS = \
-       @GTK2_LIBS@ \
-       @DBUS_LIBS@ \
-       $(NULL)
-
-immoduledir = @GTK_IM_MODULEDIR@
-# $(libdir)/gtk-2.0/immodules
-immodule_LTLIBRARIES = im-ibus.la
-im_ibus_la_DEPENDENCIES = libibus-gtk.la
-im_ibus_la_SOURCES = \
-       ibusim.c \
-       $(NULL)
-im_ibus_la_CFLAGS = \
-       @GTK2_CFLAGS@ \
-       @DBUS_CFLAGS@ \
-       -DG_LOG_DOMAIN=\"IBUS\" \
-       $(NULL)
-im_ibus_la_LDFLAGS = \
-       @GTK2_LIBS@ \
-       @DBUS_LIBS@ \
-       $(builddir)/libibus-gtk.la \
-       -avoid-version \
-       -module \
-       $(NULL)
-
-
-# gen marshal
-ibusmarshalers.h: stamp-ibusmarshalers.h
-       @true
-stamp-ibusmarshalers.h: ibusmarshalers.list
-       $(GLIB_GENMARSHAL) --prefix=ibus_marshal $(srcdir)/ibusmarshalers.list --header >> xgen-gmh \
-       && (cmp -s xgen-gmh ibusmarshalers.h || cp xgen-gmh ibusmarshalers.h) \
-       && rm -f xgen-gmh \
-       && echo timestamp > $(@F)
-ibusmarshalers.c: ibusmarshalers.list
-       (echo "#include \"ibusmarshalers.h\""; \
-        $(GLIB_GENMARSHAL) --prefix=ibus_marshal $(srcdir)/ibusmarshalers.list --body; \
-        echo ) >> xgen-gmc \
-       && cp xgen-gmc ibusmarshalers.c \
-       && rm -f xgen-gmc
-
-EXTRA_DIST = \
-       ibusmarshalers.list \
-       $(NULL)
-
-test: all
-       GTK_IM_MODULE=ibus gedit
diff --git a/gtk2/ibusim.c b/gtk2/ibusim.c
deleted file mode 100644 (file)
index d0a5773..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-/* vim:set et ts=4: */
-/* IBus - The Input Bus
- * Copyright (C) 2008-2009 Huang Peng <shawn.p.huang@gmail.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-#include <gtk/gtk.h>
-#include <gtk/gtkimmodule.h>
-#include <string.h>
-#include <stdio.h>
-#include "ibusimclient.h"
-#include "ibusimcontext.h"
-
-#define IBUS_LOCALDIR ""
-
-IBusIMClient *_client = NULL;
-static const GtkIMContextInfo ibus_im_info = {
-    "ibus",
-    "The Input Bus",
-    "ibus",
-    IBUS_LOCALDIR,
-    ""
-};
-
-static const GtkIMContextInfo * info_list[] = {
-    &ibus_im_info
-};
-
-
-void
-im_module_init (GTypeModule *type_module)
-{
-    ibus_im_client_register_type(type_module);
-    ibus_im_context_register_type(type_module);
-
-    _client = ibus_im_client_new ();
-}
-
-void
-im_module_exit (void)
-{
-    g_object_unref (_client);
-}
-
-GtkIMContext *
-im_module_create (const gchar *context_id)
-{
-    if (strcmp (context_id, "ibus") == 0) {
-        gchar *ic;
-        IBusIMContext *context;
-        ic = ibus_im_client_create_im_context (_client);
-        return GTK_IM_CONTEXT(context);
-    }
-    return NULL;
-}
-
-void
-im_module_list (const GtkIMContextInfo ***contexts,
-                int                      *n_contexts)
-{
-    *contexts = info_list;
-    *n_contexts = G_N_ELEMENTS (info_list);
-}
-
diff --git a/gtk2/ibusimclient.c b/gtk2/ibusimclient.c
deleted file mode 100644 (file)
index d2576d1..0000000
+++ /dev/null
@@ -1,1324 +0,0 @@
-/* vim:set et ts=4: */
-/* IBus - The Input Bus
- * Copyright (C) 2008-2009 Huang Peng <shawn.p.huang@gmail.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-#include <config.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <sys/un.h>
-#include <string.h>
-#include <stdarg.h>
-#include <glib/gstdio.h>
-#include <gdk/gdkkeysyms.h>
-#include <gdk/gdkx.h>
-#include <dbus/dbus.h>
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
-
-#ifdef HAVE_SYS_INOTIFY_H
-#define HAVE_INOTIFY
-#  include <sys/inotify.h>
-#endif
-#include "ibusmarshalers.h"
-#include "ibusimclient.h"
-
-enum {
-    CONNECTED,
-    DISCONNECTED,
-    FORWARD_EVENT,
-    COMMIT_STRING,
-    UPDATE_PREEDIT,
-    SHOW_PREEDIT,
-    HIDE_PREEDIT,
-    ENABLED,
-    DISABLED,
-    LAST_SIGNAL,
-};
-
-#define IBUS_NAME  "org.freedesktop.IBus"
-#define IBUS_IFACE "org.freedesktop.IBus"
-#define IBUS_PATH  "/org/freedesktop/IBus"
-
-#define I_(string) g_intern_static_string (string)
-
-/* IBusIMClientPriv */
-struct _IBusIMClientPrivate {
-#if USE_DBUS_SESSION_BUS
-    DBusConnection  *dbus;
-#endif
-
-#ifdef HAVE_INOTIFY
-    /* inotify */
-    gint            inotify_wd;
-    GIOChannel     *inotify_channel;
-    guint           inotify_source;
-#endif
-
-    DBusConnection *ibus;
-
-};
-
-/* variables */
-static guint            client_signals[LAST_SIGNAL] = { 0 };
-
-/* functions prototype */
-static void     ibus_im_client_class_init   (IBusIMClientClass  *klass);
-static void     ibus_im_client_init         (IBusIMClient       *client);
-static void     ibus_im_client_finalize     (GObject            *obj);
-
-
-static void     ibus_im_client_connected    (IBusIMClient       *client);
-static void     ibus_im_client_disconnected (IBusIMClient       *client);
-
-static const gchar *
-                _ibus_im_client_create_input_context
-                                            (IBusIMClient       *client);
-static void     _ibus_im_client_ibus_open   (IBusIMClient       *client);
-static void     _ibus_im_client_ibus_close  (IBusIMClient       *client);
-
-static gboolean _ibus_call_with_reply_and_block
-                                           (DBusConnection      *connection,
-                                            const gchar         *method,
-                                            int                 first_arg_type,
-                                                                ...);
-static gboolean _ibus_call_with_reply      (DBusConnection      *connection,
-                                            const gchar         *method,
-                                            DBusPendingCallNotifyFunction
-                                                                function,
-                                            void                *data,
-                                            DBusFreeFunction    free_function,
-                                            int                 first_arg_type,
-                                                                ...);
-static gboolean _dbus_call_with_reply_and_block
-                                           (DBusConnection      *connection,
-                                            const gchar         *dest,
-                                            const gchar         *path,
-                                            const gchar         *iface,
-                                            const char          *method,
-                                            int                 first_arg_type,
-                                                                ...);
-
-/* callback functions */
-static DBusHandlerResult
-                _ibus_im_client_message_filter_cb
-                                           (DBusConnection      *connection,
-                                            DBusMessage         *message,
-                                            void                *user_data);
-
-static GType ibus_type_im_client = 0;
-static GtkObjectClass *parent_class = NULL;
-
-
-GType
-ibus_im_client_get_type (void)
-{
-    if (ibus_type_im_client == 0) {
-        ibus_im_client_register_type (NULL);
-    }
-
-    g_assert (ibus_type_im_client != 0);
-    return ibus_type_im_client;
-}
-
-void
-ibus_im_client_register_type (GTypeModule *type_module)
-{
-    static const GTypeInfo ibus_im_client_info = {
-        sizeof (IBusIMClientClass),
-        (GBaseInitFunc)     NULL,
-        (GBaseFinalizeFunc) NULL,
-        (GClassInitFunc)    ibus_im_client_class_init,
-        NULL,               /* class finialize */
-        NULL,               /* class data */
-        sizeof (IBusIMClient),
-        0,
-        (GInstanceInitFunc) ibus_im_client_init,
-    };
-
-    if (! ibus_type_im_client ) {
-        if (type_module) {
-            ibus_type_im_client =
-                g_type_module_register_type (type_module,
-                    GTK_TYPE_OBJECT,
-                    "IBusIMClient",
-                    &ibus_im_client_info,
-                    (GTypeFlags)0);
-        }
-        else {
-            ibus_type_im_client =
-                g_type_register_static (GTK_TYPE_OBJECT,
-                    "IBusIMClient",
-                    &ibus_im_client_info,
-                    (GTypeFlags)0);
-        }
-    }
-}
-
-IBusIMClient *
-ibus_im_client_new (void)
-{
-    IBusIMClient *client;
-
-    client = IBUS_IM_CLIENT(g_object_new (IBUS_TYPE_IM_CLIENT, NULL));
-
-    return client;
-}
-
-static void
-ibus_im_client_class_init     (IBusIMClientClass *klass)
-{
-    /* GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass); */
-    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-
-    parent_class = (GtkObjectClass *) g_type_class_peek_parent (klass);
-
-    g_type_class_add_private (klass, sizeof (IBusIMClientPrivate));
-
-    gobject_class->finalize = ibus_im_client_finalize;
-
-    client_signals[CONNECTED] =
-        g_signal_new (I_("connected"),
-            G_TYPE_FROM_CLASS (gobject_class),
-            G_SIGNAL_RUN_FIRST,
-            G_STRUCT_OFFSET (IBusIMClientClass, connected),
-            NULL, NULL,
-            ibus_marshal_VOID__VOID,
-            G_TYPE_NONE, 0);
-
-    client_signals[DISCONNECTED] =
-        g_signal_new (I_("disconnected"),
-            G_TYPE_FROM_CLASS (gobject_class),
-            G_SIGNAL_RUN_FIRST,
-            G_STRUCT_OFFSET (IBusIMClientClass, disconnected),
-            NULL, NULL,
-            ibus_marshal_VOID__VOID,
-            G_TYPE_NONE, 0);
-
-    client_signals[FORWARD_EVENT] =
-        g_signal_new (I_("forward-event"),
-            G_TYPE_FROM_CLASS (gobject_class),
-            G_SIGNAL_RUN_FIRST,
-            G_STRUCT_OFFSET (IBusIMClientClass, commit_string),
-            NULL, NULL,
-            ibus_marshal_VOID__STRING_POINTER,
-            G_TYPE_NONE, 2,
-            G_TYPE_STRING,
-            G_TYPE_POINTER);
-
-
-    client_signals[COMMIT_STRING] =
-        g_signal_new (I_("commit-string"),
-            G_TYPE_FROM_CLASS (gobject_class),
-            G_SIGNAL_RUN_FIRST,
-            G_STRUCT_OFFSET (IBusIMClientClass, commit_string),
-            NULL, NULL,
-            ibus_marshal_VOID__STRING_STRING,
-            G_TYPE_NONE, 2,
-            G_TYPE_STRING,
-            G_TYPE_STRING);
-
-    client_signals[UPDATE_PREEDIT] =
-        g_signal_new (I_("update-preedit"),
-            G_TYPE_FROM_CLASS (gobject_class),
-            G_SIGNAL_RUN_FIRST,
-            G_STRUCT_OFFSET (IBusIMClientClass, update_preedit),
-            NULL, NULL,
-            ibus_marshal_VOID__STRING_STRING_POINTER_INT_BOOLEAN,
-            G_TYPE_NONE, 5,
-            G_TYPE_STRING,
-            G_TYPE_STRING,
-            G_TYPE_POINTER,
-            G_TYPE_INT,
-            G_TYPE_BOOLEAN
-            );
-
-    client_signals[SHOW_PREEDIT] =
-        g_signal_new (I_("show-preedit"),
-            G_TYPE_FROM_CLASS (gobject_class),
-            G_SIGNAL_RUN_FIRST,
-            G_STRUCT_OFFSET (IBusIMClientClass, show_preedit),
-            NULL, NULL,
-            ibus_marshal_VOID__STRING,
-            G_TYPE_NONE, 1,
-            G_TYPE_STRING);
-
-    client_signals[HIDE_PREEDIT] =
-        g_signal_new (I_("hide-preedit"),
-            G_TYPE_FROM_CLASS (gobject_class),
-            G_SIGNAL_RUN_FIRST,
-            G_STRUCT_OFFSET (IBusIMClientClass, hide_preedit),
-            NULL, NULL,
-            ibus_marshal_VOID__STRING,
-            G_TYPE_NONE, 1,
-            G_TYPE_STRING);
-
-    client_signals[ENABLED] =
-        g_signal_new (I_("enabled"),
-            G_TYPE_FROM_CLASS (gobject_class),
-            G_SIGNAL_RUN_FIRST,
-            G_STRUCT_OFFSET (IBusIMClientClass, enabled),
-            NULL, NULL,
-            ibus_marshal_VOID__STRING,
-            G_TYPE_NONE, 1,
-            G_TYPE_STRING);
-
-    client_signals[DISABLED] =
-        g_signal_new (I_("disabled"),
-            G_TYPE_FROM_CLASS (gobject_class),
-            G_SIGNAL_RUN_FIRST,
-            G_STRUCT_OFFSET (IBusIMClientClass, disabled),
-            NULL, NULL,
-            ibus_marshal_VOID__STRING,
-            G_TYPE_NONE, 1,
-            G_TYPE_STRING);
-
-}
-
-/*
- * open ibus connection
- */
-static void
-_ibus_im_client_ibus_open (IBusIMClient *client)
-{
-    gchar *ibus_addr = NULL;
-    DBusError error;
-
-    IBusIMClientPrivate *priv = client->priv;
-
-    if (priv->ibus != NULL)
-        return;
-
-#if USE_DBUS_SESSION_BUS
-    dbus_connection_setup_with_g_main (priv->dbus, NULL);
-    if (!_dbus_call_with_reply_and_block (priv->dbus,
-                        IBUS_NAME, IBUS_PATH, IBUS_IFACE,
-                        "GetIBusAddress",
-                        DBUS_TYPE_INVALID,
-                        DBUS_TYPE_STRING, &ibus_addr,
-                        DBUS_TYPE_INVALID
-                        )) {
-        g_warning ("Can not get ibus address");
-        return;
-    }
-#endif
-    if (ibus_addr == NULL) {
-        gchar *display;
-        gchar *hostname = "";
-        gchar *displaynumber = "0";
-        gchar *screennumber = "0";
-        gchar *username = NULL;
-        gchar *p;
-
-        display = g_strdup (g_getenv ("DISPLAY"));
-        if (display == NULL) {
-            g_warning ("DISPLAY is empty! We use default DISPLAY (:0.0)");
-        }
-        else {
-            p = display;
-            hostname = display;
-            for (; *p != ':' && *p != '\0'; p++);
-
-            if (*p == ':') {
-                *p = '\0';
-                p++;
-                displaynumber = p;
-            }
-
-            for (; *p != '.' && *p != '\0'; p++);
-
-            if (*p == '.') {
-                *p = '\0';
-                p++;
-                screennumber = p;
-            }
-        }
-
-        username = g_strdup (getlogin());
-        if (username == NULL)
-            username = g_strdup (g_getenv("LOGNAME"));
-        if (username == NULL)
-            username = g_strdup (g_getenv("USER"));
-        if (username == NULL)
-            username = g_strdup (g_getenv("LNAME"));
-        if (username == NULL)
-            username = g_strdup (g_getenv("USERNAME"));
-
-        ibus_addr = g_strdup_printf (
-            "unix:path=/tmp/ibus-%s/ibus-%s-%s.%s",
-            username, hostname, displaynumber, screennumber);
-
-        g_free (display);
-        g_free (username);
-    }
-
-    /*
-     * Init ibus and proxy object
-     */
-    dbus_error_init (&error);
-    priv->ibus = dbus_connection_open_private (ibus_addr, &error);
-    g_free (ibus_addr);
-    if (priv->ibus == NULL) {
-        g_warning ("Error: %s", error.message);
-        dbus_error_free (&error);
-        return;
-    }
-
-    if (!dbus_connection_add_filter (priv->ibus,
-            _ibus_im_client_message_filter_cb,
-            client, NULL)) {
-        g_warning ("Out of memory");
-        return;
-    }
-
-    dbus_connection_setup_with_g_main (priv->ibus, NULL);
-
-    g_signal_emit (client, client_signals[CONNECTED], 0);
-
-}
-
-/*
- * close ibus connection
- */
-static void
-_ibus_im_client_ibus_close (IBusIMClient *client)
-{
-    IBusIMClientPrivate *priv = client->priv;
-
-    if (priv->ibus) {
-        dbus_connection_close (priv->ibus);
-        dbus_connection_unref (priv->ibus);
-        priv->ibus = NULL;
-        g_signal_emit (client, client_signals[DISCONNECTED], 0);
-    }
-}
-
-/*
- * create an im context
- */
-const char *
-ibus_im_client_create_im_context (IBusIMClient *client)
-{
-    return _ibus_im_client_create_input_context (client);
-}
-
-/*
- * create a ibus input context
- */
-static const gchar *
-_ibus_im_client_create_input_context (IBusIMClient *client)
-{
-    IBusIMClientPrivate *priv = client->priv;
-
-    if (priv->ibus == NULL)
-        return NULL;
-
-    const gchar *app_name = g_get_application_name ();
-    gchar *ic = NULL;
-    _ibus_call_with_reply_and_block (priv->ibus, "CreateInputContext",
-                DBUS_TYPE_STRING, &app_name,
-                DBUS_TYPE_INVALID,
-                DBUS_TYPE_STRING, &ic,
-                DBUS_TYPE_INVALID);
-    return ic;
-}
-
-#ifdef HAVE_INOTIFY
-static gboolean
-_ibus_im_client_inotify_cb (GIOChannel *source, GIOCondition condition, IBusIMClient *client)
-{
-    struct inotify_event *p = NULL;
-    gchar *name;
-    gsize n;
-
-    if ((condition & G_IO_IN) == 0)
-        return TRUE;
-
-    p = g_malloc0 (sizeof (struct inotify_event) + 1024);
-
-    g_io_channel_read_chars (source, (gchar *) p, sizeof (struct inotify_event),  &n, NULL);
-    g_io_channel_read_chars (source, ((gchar *)p) + sizeof (struct inotify_event), p->len,  &n, NULL);
-
-    name = g_strdup_printf ("ibus-%s", g_getenv ("DISPLAY"));
-    for (n = 0; name[n] != 0; n++) {
-        if (name[n] != ':')
-            continue;
-        name[n] = '-';
-        break;
-    }
-
-    if (g_strcmp0 (p->name, name) == 0) {
-        if (p->mask & IN_CREATE) {
-            g_usleep (1000);
-            _ibus_im_client_ibus_open (client);
-        }
-    }
-    g_free (name);
-    g_free (p);
-
-    return TRUE;
-}
-#endif
-
-static void
-ibus_im_client_init (IBusIMClient *obj)
-{
-    DEBUG_FUNCTION_IN;
-
-    IBusIMClient *client = IBUS_IM_CLIENT (obj);
-    IBusIMClientPrivate *priv;
-
-    gchar *watch_path;
-    struct stat stat_buf;
-
-#ifdef HAVE_INOTIFY
-    gint inotify_fd = inotify_init ();
-#endif
-
-    priv = G_TYPE_INSTANCE_GET_PRIVATE (client, IBUS_TYPE_IM_CLIENT, IBusIMClientPrivate);
-    client->priv = priv;
-
-    watch_path = g_strdup_printf ("/tmp/ibus-%s", g_get_user_name ());
-
-    if (g_stat (watch_path, &stat_buf) != 0) {
-        g_mkdir (watch_path, 0750);
-    }
-
-#ifdef HAVE_INOTIFY
-    /* init inotify */
-    priv->inotify_wd = inotify_add_watch (inotify_fd, watch_path, IN_CREATE | IN_DELETE);
-    priv->inotify_channel = g_io_channel_unix_new (inotify_fd);
-    g_io_channel_set_close_on_unref (priv->inotify_channel, TRUE);
-    priv->inotify_source = g_io_add_watch (priv->inotify_channel,
-                                    G_IO_IN,
-                                    (GIOFunc)_ibus_im_client_inotify_cb,
-                                    (gpointer)client);
-#endif
-    g_free (watch_path);
-
-#if USE_DBUS_SESSION_BUS
-    /*
-     * Init dbus
-     */
-    dbus_error_init (&error);
-    priv->dbus = dbus_bus_get (DBUS_BUS_SESSION, &error);
-    if (priv->dbus == NULL) {
-        g_warning ("Error: %s", error.message);
-        dbus_error_free (&error);
-        return;
-    }
-#endif
-
-    _ibus_im_client_ibus_open (client);
-
-#if USE_DBUS_SESSION_BUS
-    if (!dbus_connection_add_filter (priv->dbus,
-            _ibus_im_client_message_filter_cb,
-            client, NULL)) {
-        g_warning ("Out of memory");
-        return;
-    }
-
-    gchar *rule =
-            "type='signal',"
-            "sender='" DBUS_SERVICE_DBUS "',"
-            "interface='" DBUS_INTERFACE_DBUS "',"
-            "member='NameOwnerChanged',"
-            "path='" DBUS_PATH_DBUS "',"
-            "arg0='" IBUS_NAME "'";
-
-    if (!_dbus_call_with_reply_and_block (priv->dbus,
-                        DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS,
-                        "AddMatch",
-                        DBUS_TYPE_STRING, &rule,
-                        DBUS_TYPE_INVALID,
-                        DBUS_TYPE_INVALID
-                        )) {
-        g_warning ("Can not get ibus address");
-        return;
-    }
-#endif
-#if 0
-    /* get dbus proxy */
-    priv->dbus = dbus_g_proxy_new_for_name (priv->ibus,
-                                DBUS_SERVICE_DBUS,
-                                DBUS_PATH_DBUS,
-                                DBUS_INTERFACE_DBUS);
-    g_assert (priv->dbus != NULL);
-
-    /* connect NameOwnerChanged signal */
-    dbus_g_proxy_add_signal (priv->dbus, "NameOwnerChanged",
-                                G_TYPE_STRING,
-                                G_TYPE_STRING,
-                                G_TYPE_STRING,
-                                G_TYPE_INVALID);
-
-    dbus_g_proxy_connect_signal (priv->dbus, "NameOwnerChanged",
-                                G_CALLBACK (_dbus_name_owner_changed_cb),
-                                (gpointer)client, NULL);
-    dbus_bus_add_match ((DBusConnection *)dbus_g_connection_get_connection (priv->ibus),
-                        "type='signal',"
-                        "sender='" DBUS_SERVICE_DBUS
-                        "',interface='" DBUS_INTERFACE_DBUS
-                        "',path='" DBUS_PATH_DBUS
-                        "',member='NameOwnerChanged',"
-                        "arg0='" IBUS_DBUS_SERVICE "'",
-                        &dbus_error);
-
-     _ibus_im_client_reinit_imm (client);
-#endif
-
-}
-
-
-static void
-ibus_im_client_finalize (GObject *obj)
-{
-    DEBUG_FUNCTION_IN;
-
-    IBusIMClient *client = IBUS_IM_CLIENT (obj);
-    IBusIMClientPrivate *priv = client->priv;
-
-    g_assert (client == _client);
-
-#ifdef HAVE_INOTIFY
-    g_source_remove (priv->inotify_source);
-    g_io_channel_unref (priv->inotify_channel);
-#endif
-
-#if USE_DBUS_SESSION_BUS
-    if (priv->dbus) {
-        dbus_connection_unref (priv->dbus);
-    }
-#endif
-    _ibus_im_client_ibus_close (client);
-
-    G_OBJECT_CLASS(parent_class)->finalize (obj);
-
-    _client = NULL;
-}
-
-static void
-_ibus_signal_commit_string_handler (DBusConnection *connection, DBusMessage *message, IBusIMClient *client)
-{
-    /* Handle CommitString signal */
-    DBusError error = {0};
-    gchar *ic = NULL;
-    gchar *string = NULL;
-
-    if (!dbus_message_get_args (message, &error,
-            DBUS_TYPE_STRING, &ic,
-            DBUS_TYPE_STRING, &string,
-            DBUS_TYPE_INVALID)) {
-        g_warning ("%s", error.message);
-        dbus_error_free (&error);
-    }
-    else {
-        g_signal_emit (client, client_signals[COMMIT_STRING], 0, ic, string);
-    }
-}
-
-static void
-_ibus_signal_update_preedit_handler (DBusConnection *connection, DBusMessage *message, IBusIMClient *client)
-{
-    /* Handle UpdatePreedit signal */
-    DBusMessageIter iter, sub_iter;
-    int type, sub_type;
-
-    gchar *ic = NULL;
-    gchar *string = NULL;
-    PangoAttrList *attrs = NULL;
-    int cursor = 0;
-    gboolean visible = False;
-
-    if (!dbus_message_iter_init (message, &iter)) {
-        g_warning ("The UpdatePreedit signal does have args!");
-        return;
-    }
-
-    type = dbus_message_iter_get_arg_type (&iter);
-    if (type != DBUS_TYPE_STRING) {
-        g_warning ("The 1st argument of UpdatePreedit signal must be a String");
-        return;
-    }
-    dbus_message_iter_get_basic (&iter, &ic);
-    dbus_message_iter_next (&iter);
-
-    type = dbus_message_iter_get_arg_type (&iter);
-    if (type != DBUS_TYPE_STRING) {
-        g_warning ("The 2nd argument of UpdatePreedit signal must be a String");
-        return;
-    }
-    dbus_message_iter_get_basic (&iter, &string);
-    dbus_message_iter_next (&iter);
-
-
-    type = dbus_message_iter_get_arg_type (&iter);
-    if (type != DBUS_TYPE_ARRAY) {
-        g_warning ("The 3rd argument of UpdatePreedit signal must be a Struct Array");
-        return;
-    }
-
-    dbus_message_iter_recurse (&iter, &sub_iter);
-
-    if (dbus_message_iter_get_arg_type (&sub_iter) != DBUS_TYPE_INVALID) {
-        if (dbus_message_iter_get_arg_type (&sub_iter) != DBUS_TYPE_ARRAY ||
-            dbus_message_iter_get_element_type (&sub_iter) != DBUS_TYPE_UINT32 ) {
-            g_warning ("The 3rd argument of UpdatePreedit signal must be a Struct Array");
-            return;
-        }
-
-        attrs = pango_attr_list_new ();
-
-        while ((sub_type = dbus_message_iter_get_arg_type (&sub_iter) != DBUS_TYPE_INVALID)) {
-            PangoAttribute *attr;
-            DBusMessageIter sub_sub_iter;
-            guint *values = NULL;
-            gint length = 0;
-            dbus_message_iter_recurse (&sub_iter, &sub_sub_iter);
-            dbus_message_iter_get_fixed_array (&sub_sub_iter, &values, &length);
-
-            if (length <= 0) {
-                g_warning ("The element of the 3rd argument of UpdatePreedit should not be a empty array");
-                continue;
-            }
-
-            switch (values[0]) {
-            case 1: /* Underline */
-                attr = pango_attr_underline_new (values[1]);
-                attr->start_index = g_utf8_offset_to_pointer (string, values[2]) - string;
-                attr->end_index = g_utf8_offset_to_pointer (string, values[3]) - string;
-                pango_attr_list_insert (attrs, attr);
-                break;
-
-            case 2: /* Foreground Color */
-                attr = pango_attr_foreground_new (
-                                (values[1] & 0xff0000) >> 8,
-                                (values[1] & 0x00ff00),
-                                (values[1] & 0x0000ff) << 8
-                                );
-                attr->start_index = g_utf8_offset_to_pointer (string, values[2]) - string;
-                attr->end_index = g_utf8_offset_to_pointer (string, values[3]) - string;
-                pango_attr_list_insert (attrs, attr);
-                break;
-            case 3: /* Background Color */
-                attr = pango_attr_background_new (
-                                (values[1] & 0xff0000) >> 8,
-                                (values[1] & 0x00ff00),
-                                (values[1] & 0x0000ff) << 8
-                                );
-                attr->start_index = g_utf8_offset_to_pointer (string, values[2]) - string;
-                attr->end_index = g_utf8_offset_to_pointer (string, values[3]) - string;
-                pango_attr_list_insert (attrs, attr);
-                break;
-            default:
-                g_warning ("Unkown type attribute type = %d", values[0]);
-
-            }
-
-            dbus_message_iter_next (&sub_iter);
-
-        }
-    }
-    dbus_message_iter_next (&iter);
-
-    type = dbus_message_iter_get_arg_type (&iter);
-    if (type != DBUS_TYPE_INT32) {
-        g_warning ("The 4th argument of UpdatePreedit signal must be an Int32 %c", type);
-        pango_attr_list_unref (attrs);
-        return;
-    }
-    dbus_message_iter_get_basic (&iter, &cursor);
-    dbus_message_iter_next (&iter);
-
-    type = dbus_message_iter_get_arg_type (&iter);
-    if (type != DBUS_TYPE_BOOLEAN) {
-        g_warning ("The 4th argument of UpdatePreedit signal must be an Int32 %c", type);
-        pango_attr_list_unref (attrs);
-        return;
-    }
-    dbus_message_iter_get_basic (&iter, &visible);
-    dbus_message_iter_next (&iter);
-
-    {
-        g_signal_emit (client, client_signals[UPDATE_PREEDIT], 0,
-                ic, string, attrs, cursor, visible);
-    }
-    pango_attr_list_unref (attrs);
-
-}
-
-static void
-_ibus_signal_show_preedit_handler (DBusConnection *connection, DBusMessage *message, IBusIMClient *client)
-{
-    /* Handle CommitString signal */
-    DBusError error = {0};
-    gchar *ic = NULL;
-
-    if (!dbus_message_get_args (message, &error,
-            DBUS_TYPE_STRING, &ic,
-            DBUS_TYPE_INVALID)) {
-        g_warning ("%s", error.message);
-        dbus_error_free (&error);
-    }
-    else {
-        g_signal_emit (client, client_signals[SHOW_PREEDIT], 0, ic);
-    }
-}
-
-static void
-_ibus_signal_hide_preedit_handler (DBusConnection *connection, DBusMessage *message, IBusIMClient *client)
-{
-    /* Handle CommitString signal */
-    DBusError error = {0};
-    gchar *ic = NULL;
-
-    if (!dbus_message_get_args (message, &error,
-            DBUS_TYPE_STRING, &ic,
-            DBUS_TYPE_INVALID)) {
-        g_warning ("%s", error.message);
-        dbus_error_free (&error);
-    }
-    else {
-        g_signal_emit (client, client_signals[HIDE_PREEDIT], 0, ic);
-    }
-}
-
-#ifdef USE_DBUS_SESSION_BUS
-static void
-_ibus_signal_name_owner_changed_handler (DBusConnection *connection, DBusMessage *message, IBusIMClient *client)
-{
-    gchar *name = NULL;
-    gchar *old_name = NULL;
-    gchar *new_name = NULL;
-    DBusError error = {0};
-
-    if (!dbus_message_get_args (message, &error,
-            DBUS_TYPE_STRING, &name,
-            DBUS_TYPE_STRING, &old_name,
-            DBUS_TYPE_STRING, &new_name,
-            DBUS_TYPE_INVALID)) {
-        g_warning ("%s", error.message);
-        dbus_error_free (&error);
-    }
-
-    g_return_if_fail (strcmp (name, IBUS_NAME) == 0);
-
-    if (g_strcmp0 (new_name, "") == 0) {
-        _ibus_im_client_ibus_close (client);
-        priv->enable = FALSE;
-    }
-    else {
-        _ibus_im_client_ibus_open (client);
-        priv->enable = TRUE;
-    }
-}
-#endif
-
-static void
-_ibus_signal_disconnected_handler (DBusConnection *connection, DBusMessage *message, IBusIMClient *client)
-{
-    _ibus_im_client_ibus_close (client);
-}
-
-static void
-_ibus_signal_enabled_handler (DBusConnection *connection, DBusMessage *message, IBusIMClient *client)
-{
-    DEBUG_FUNCTION_IN;
-    /* Handle CommitString signal */
-    DBusError error = {0};
-    gchar *ic = NULL;
-
-    if (!dbus_message_get_args (message, &error,
-            DBUS_TYPE_STRING, &ic,
-            DBUS_TYPE_INVALID)) {
-        g_warning ("%s", error.message);
-        dbus_error_free (&error);
-    }
-    else {
-        g_signal_emit (client, client_signals[ENABLED], 0, ic);
-    }
-}
-
-
-static void
-_ibus_signal_disabled_handler (DBusConnection *connection, DBusMessage *message, IBusIMClient *client)
-{
-    DEBUG_FUNCTION_IN;
-    /* Handle CommitString signal */
-    DBusError error = {0};
-    gchar *ic = NULL;
-
-    if (!dbus_message_get_args (message, &error,
-            DBUS_TYPE_STRING, &ic,
-            DBUS_TYPE_INVALID)) {
-        g_warning ("%s", error.message);
-        dbus_error_free (&error);
-    }
-    else {
-        g_signal_emit (client, client_signals[DISABLED], 0, ic);
-    }
-}
-
-
-static DBusHandlerResult
-_ibus_im_client_message_filter_cb (DBusConnection *connection, DBusMessage *message, void *user_data)
-{
-    IBusIMClient *client = (IBusIMClient *) user_data;
-
-    static struct SIGNAL_HANDLER {
-        const gchar *iface;
-        const gchar *name;
-        void (* handler) (DBusConnection *, DBusMessage *, IBusIMClient *);
-    } handlers[] = {
-#ifdef USE_DBUS_SESSION_BUS
-        { DBUS_INTERFACE_DBUS, "NameOwnerChanged", _ibus_signal_name_owner_changed_handler },
-#endif
-        { DBUS_INTERFACE_LOCAL, "Disconnected", _ibus_signal_disconnected_handler },
-        { IBUS_IFACE, "CommitString", _ibus_signal_commit_string_handler },
-        { IBUS_IFACE, "UpdatePreedit", _ibus_signal_update_preedit_handler },
-        { IBUS_IFACE, "ShowPreedit", _ibus_signal_show_preedit_handler },
-        { IBUS_IFACE, "HidePreedit", _ibus_signal_hide_preedit_handler },
-        { IBUS_IFACE, "Enabled", _ibus_signal_enabled_handler },
-        { IBUS_IFACE, "Disabled", _ibus_signal_disabled_handler },
-        {0},
-    };
-
-    gint i;
-    for (i = 0; handlers[i].iface != NULL; i++) {
-        if (dbus_message_is_signal (message, handlers[i].iface, handlers[i].name)) {
-            handlers[i].handler (connection, message, client);
-            return DBUS_HANDLER_RESULT_HANDLED;
-        }
-    }
-    g_debug ("Unknown message %s", dbus_message_get_member (message));
-    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-}
-
-inline static gboolean
-_dbus_call_with_reply_and_block_valist (DBusConnection *connection,
-    const gchar *dest, const gchar *path, const gchar* iface, const char *method,
-    int first_arg_type, va_list args)
-{
-
-    DBusMessage *message, *reply;
-    DBusError error = {0};
-    int type;
-    va_list tmp;
-
-    if (connection == NULL)
-        return FALSE;
-
-    message = dbus_message_new_method_call (dest,
-                                    path, iface, method);
-    if (!message) {
-        g_warning ("Out of memory!");
-        return FALSE;
-    }
-
-    va_copy (tmp, args);
-    if (!dbus_message_append_args_valist (message, first_arg_type, tmp)) {
-        dbus_message_unref (message);
-        g_warning ("Can not create call message");
-        return FALSE;
-    }
-
-    reply = dbus_connection_send_with_reply_and_block (connection,
-                        message, -1, &error);
-
-    dbus_message_unref (message);
-
-    if (!reply) {
-        g_warning ("%s", error.message);
-        dbus_error_free (&error);
-        return FALSE;
-    }
-
-    type = first_arg_type;
-    while (type != DBUS_TYPE_INVALID) {
-        if (type == DBUS_TYPE_ARRAY) {
-            va_arg (args, int);
-            va_arg (args, void *);
-            va_arg (args, int);
-        }
-        else {
-            va_arg (args, void *);
-        }
-        type = va_arg (args, int);
-    }
-
-    type = va_arg (args, int);
-    if (!dbus_message_get_args_valist (reply, &error, type, args)) {
-        g_warning ("%s", error.message);
-        dbus_error_free (&error);
-        dbus_message_unref (reply);
-        return FALSE;
-    }
-    dbus_message_unref (reply);
-
-    return TRUE;
-
-}
-
-inline static gboolean
-_dbus_call_with_reply_and_block (DBusConnection *connection,
-    const gchar *dest, const gchar *path, const gchar* iface, const char *method,
-    gint first_arg_type, ...)
-{
-    va_list args;
-    gboolean retval;
-
-    if (connection == NULL)
-        return FALSE;
-
-    va_start (args, first_arg_type);
-    retval = _dbus_call_with_reply_and_block_valist (connection,
-                    dest, path, iface, method, first_arg_type, args);
-    va_end (args);
-
-    return TRUE;
-
-}
-
-static gboolean
-_ibus_call_with_reply_and_block (DBusConnection *connection, const gchar *method, int first_arg_type, ...)
-{
-    va_list args;
-    gboolean retval;
-
-    if (connection == NULL)
-        return FALSE;
-
-    va_start (args, first_arg_type);
-    retval = _dbus_call_with_reply_and_block_valist (connection,
-                    IBUS_NAME, IBUS_PATH, IBUS_IFACE, method, first_arg_type, args);
-    va_end (args);
-
-    return retval;
-
-}
-
-
-inline static gboolean
-_dbus_call_with_reply_valist (DBusConnection *connection,
-    const gchar *dest, const gchar *path, const gchar* iface, const char *method,
-    DBusPendingCallNotifyFunction notify_function,
-    void *user_data, DBusFreeFunction free_function,
-    gint first_arg_type, va_list args)
-{
-    DBusMessage *message = NULL;
-    DBusPendingCall *pendingcall = NULL;
-
-    if (connection == NULL) {
-        goto error;
-    }
-
-    message = dbus_message_new_method_call (dest,
-                                    path, iface, method);
-    if (!message) {
-        g_warning ("Out of memory!");
-        goto error;
-    }
-
-    if (!dbus_message_append_args_valist (message, first_arg_type, args)) {
-        g_warning ("Can not create call message");
-        goto error;
-    }
-
-    if (!dbus_connection_send_with_reply (connection,
-                        message, &pendingcall, -1)) {
-        g_warning ("Out of memory!");
-        goto error;
-    }
-
-    if (!dbus_pending_call_set_notify (pendingcall, notify_function,
-            user_data, free_function)) {
-        g_warning ("Out of memory!");
-        goto error;
-    }
-
-    dbus_message_unref (message);
-    return TRUE;
-
-error:
-    if (message)
-        dbus_message_unref (message);
-    if (pendingcall)
-        dbus_pending_call_cancel (pendingcall);
-    if (user_data && free_function)
-        free_function (user_data);
-    return False;
-}
-
-inline static gboolean
-_dbus_call_with_reply (DBusConnection *connection,
-    const gchar *dest, const gchar *path, const gchar* iface, const char *method,
-    DBusPendingCallNotifyFunction notify_function,
-    void *user_data, DBusFreeFunction free_function,
-    gint first_arg_type, ...)
-{
-    va_list args;
-    gboolean retval;
-
-    if (connection == NULL)
-        return FALSE;
-
-    va_start (args, first_arg_type);
-    retval = _dbus_call_with_reply_valist (connection,
-                    dest, path, iface, method,
-                    notify_function,
-                    user_data, free_function,
-                    first_arg_type, args);
-    va_end (args);
-
-    return TRUE;
-
-}
-
-
-
-static gboolean
-_ibus_call_with_reply (DBusConnection *connection, const gchar *method,
-       DBusPendingCallNotifyFunction notify_function,
-       void *user_data, DBusFreeFunction free_function,
-       int first_arg_type, ...)
-{
-    va_list args;
-    gboolean retval;
-
-    if (connection == NULL)
-        return FALSE;
-
-    va_start (args, first_arg_type);
-    retval = _dbus_call_with_reply_valist (connection,
-                    IBUS_NAME, IBUS_PATH, IBUS_IFACE,
-                    method, notify_function,
-                    user_data, free_function,
-                    first_arg_type, args);
-    va_end (args);
-
-    return retval;
-}
-
-typedef struct {
-    IBusIMClient *client;
-    gchar *ic;
-    GdkEvent event;
-}KeyPressCallData;
-
-static KeyPressCallData *
-_key_press_call_data_new (IBusIMClient *client, const gchar *ic, GdkEvent *event)
-{
-    KeyPressCallData *p = g_new (KeyPressCallData, 1);
-    p->client = g_object_ref (client);
-    p->ic = g_strdup (ic);
-    p->event = *event;
-    return p;
-}
-
-static void
-_key_press_call_data_free (KeyPressCallData *p)
-{
-    if (p) {
-        g_object_unref (p->client);
-        g_free (p->ic);
-    }
-    g_free (p);
-}
-
-static void
-_ibus_filter_keypress_reply_cb (DBusPendingCall *pending, void *user_data)
-{
-    DBusMessage *reply;
-    DBusError error = {0};
-    KeyPressCallData *call_data = (KeyPressCallData *) user_data;
-    gboolean retval;
-
-
-    reply = dbus_pending_call_steal_reply (pending);
-    dbus_pending_call_unref (pending);
-
-    if (dbus_set_error_from_message (&error, reply)) {
-        g_warning ("%s", error.message);
-        dbus_error_free (&error);
-        retval = FALSE;
-    }
-    else {
-        if (!dbus_message_get_args (reply, &error,
-                DBUS_TYPE_BOOLEAN, &retval, DBUS_TYPE_INVALID)) {
-            g_warning ("%s", error.message);
-            dbus_error_free (&error);
-            retval = FALSE;
-        }
-    }
-
-    if (!retval) {
-        g_signal_emit (call_data->client, client_signals[FORWARD_EVENT], 0,
-                call_data->ic, &(call_data->event));
-    }
-}
-
-gboolean
-ibus_im_client_filter_keypress (IBusIMClient *client, const gchar *ic, GdkEventKey *event)
-{
-    g_return_val_if_fail (IBUS_IS_IM_CLIENT(client), FALSE);
-    g_return_val_if_fail (ic != NULL, FALSE);
-    g_return_val_if_fail (event != NULL, FALSE);
-
-    IBusIMClientPrivate *priv = client->priv;
-
-    guint state = event->state & GDK_MODIFIER_MASK;
-    gboolean is_press = event->type == GDK_KEY_PRESS;
-
-    if (event->send_event) {
-        return FALSE;
-    }
-
-    /* Call IBus ProcessKeyEvent method */
-    if (!_ibus_call_with_reply (priv->ibus,
-            "ProcessKeyEvent",
-            _ibus_filter_keypress_reply_cb,
-            _key_press_call_data_new (client, ic, (GdkEvent *)event),
-            (DBusFreeFunction)_key_press_call_data_free,
-            DBUS_TYPE_STRING, &ic,
-            DBUS_TYPE_UINT32, &event->keyval,
-            DBUS_TYPE_BOOLEAN, &is_press,
-            DBUS_TYPE_UINT32, &state,
-            DBUS_TYPE_INVALID))
-        return FALSE;
-
-    return TRUE;
-}
-
-
-void
-ibus_im_client_focus_in (IBusIMClient *client, const gchar *ic)
-{
-    g_return_if_fail (IBUS_IS_IM_CLIENT(client));
-    g_return_if_fail (ic != NULL);
-
-    IBusIMClientPrivate *priv = client->priv;
-
-    /* Call IBus FocusIn method */
-     _ibus_call_with_reply_and_block (priv->ibus,
-            "FocusIn",
-            DBUS_TYPE_STRING, &ic,
-            DBUS_TYPE_INVALID,
-            DBUS_TYPE_INVALID);
-}
-
-void
-ibus_im_client_focus_out (IBusIMClient *client, const gchar *ic)
-{
-    g_return_if_fail (IBUS_IS_IM_CLIENT(client));
-    g_return_if_fail (ic != NULL);
-
-    IBusIMClientPrivate *priv = client->priv;
-
-    /* Call IBus FocusOut method */
-    _ibus_call_with_reply_and_block (priv->ibus,
-            "FocusOut",
-            DBUS_TYPE_STRING, &ic,
-            DBUS_TYPE_INVALID,
-            DBUS_TYPE_INVALID);
-
-}
-
-void
-ibus_im_client_reset (IBusIMClient *client, const gchar *ic)
-{
-    g_return_if_fail (IBUS_IS_IM_CLIENT(client));
-    g_return_if_fail (ic != NULL);
-
-    IBusIMClientPrivate *priv = client->priv;
-
-    /* Call IBus Reset method */
-    _ibus_call_with_reply_and_block (priv->ibus,
-            "Reset",
-            DBUS_TYPE_STRING, &ic,
-            DBUS_TYPE_INVALID,
-            DBUS_TYPE_INVALID);
-
-}
-
-void
-ibus_im_client_set_cursor_location (IBusIMClient *client, const gchar *ic, GdkRectangle *area)
-{
-    g_return_if_fail (IBUS_IS_IM_CLIENT(client));
-    g_return_if_fail (ic != NULL);
-    g_return_if_fail (area != NULL);
-
-    _ibus_call_with_reply_and_block (client->priv->ibus,
-            "SetCursorLocation",
-            DBUS_TYPE_STRING, &ic,
-            DBUS_TYPE_INT32, &area->x,
-            DBUS_TYPE_INT32, &area->y,
-            DBUS_TYPE_INT32, &area->width,
-            DBUS_TYPE_INT32, &area->height,
-            DBUS_TYPE_INVALID,
-            DBUS_TYPE_INVALID);
-}
-
-void
-ibus_im_client_set_use_preedit (IBusIMClient *client, const gchar *ic, gboolean use_preedit)
-{
-    g_return_if_fail (IBUS_IS_IM_CLIENT(client));
-    g_return_if_fail (ic != NULL);
-
-    _ibus_call_with_reply_and_block (client->priv->ibus,
-            "SetCapabilities",
-            DBUS_TYPE_STRING, &ic,
-            DBUS_TYPE_INT32, &use_preedit,
-            DBUS_TYPE_INVALID,
-            DBUS_TYPE_INVALID);
-}
-
-void
-ibus_im_client_release_im_context (IBusIMClient *client, const gchar *ic)
-{
-    g_return_if_fail (IBUS_IS_IM_CLIENT(client));
-    g_return_if_fail (ic != NULL);
-
-    IBusIMClientPrivate *priv = client->priv;
-
-    _ibus_call_with_reply_and_block (priv->ibus, "ReleaseInputContext",
-                DBUS_TYPE_STRING, &ic,
-                DBUS_TYPE_INVALID,
-                DBUS_TYPE_INVALID);
-
-}
-
-void
-ibus_im_client_kill_daemon (IBusIMClient *client)
-{
-    IBusIMClientPrivate *priv = client->priv;
-    _ibus_call_with_reply_and_block (priv->ibus, "Kill",
-                DBUS_TYPE_INVALID,
-                DBUS_TYPE_INVALID);
-}
-
-
-gboolean
-ibus_im_client_get_connected (IBusIMClient *client)
-{
-    IBusIMClientPrivate *priv = client->priv;
-    if (priv->ibus == NULL)
-        return FALSE;
-    return dbus_connection_get_is_connected (priv->ibus);
-}
diff --git a/gtk2/ibusimclient.h b/gtk2/ibusimclient.h
deleted file mode 100644 (file)
index 4e51fb8..0000000
+++ /dev/null
@@ -1,123 +0,0 @@
-/* vim:set et ts=4: */
-/* IBus - The Input Bus
- * Copyright (C) 2008-2009 Huang Peng <shawn.p.huang@gmail.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-#ifndef __IBUS_IM_CLIENT_H_
-#define __IBUS_IM_CLIENT_H_
-
-#include <gtk/gtk.h>
-/*
- * Type macros.
- */
-
-/* define GOBJECT macros */
-#define IBUS_TYPE_IM_CLIENT             \
-    (ibus_im_client_get_type ())
-#define IBUS_IM_CLIENT(obj)             \
-    (GTK_CHECK_CAST ((obj), IBUS_TYPE_IM_CLIENT, IBusIMClient))
-#define IBUS_IM_CLIENT_CLASS(klass)     \
-    (GTK_CHECK_CLASS_CAST ((klass), IBUS_TYPE_IM_CLIENT, IBusIMClientClass))
-#define IBUS_IS_IM_CLIENT(obj)          \
-    (GTK_CHECK_TYPE ((obj), IBUS_TYPE_IM_CLIENT))
-#define IBUS_IS_IM_CLIENT_CLASS(klass)  \
-    (GTK_CHECK_CLASS_TYPE ((klass), IBUS_TYPE_IM_CLIENT))
-#define IBUS_IM_CLIENT_GET_CLASS(obj)   \
-    (GTK_CHECK_GET_CLASS ((obj), IBUS_TYPE_IM_CLIENT, IBusIMClientClass))
-
-#if 0
-#define DEBUG_FUNCTION_IN   g_debug("%s IN", __FUNCTION__);
-#define DEBUG_FUNCTION_OUT  g_debug("%s OUT", __FUNCTION__);
-#else
-#define DEBUG_FUNCTION_IN
-#define DEBUG_FUNCTION_OUT
-#endif
-
-
-
-#define IBUS_DBUS_SERVICE    "org.freedesktop.ibus"
-#define IBUS_DBUS_INTERFACE  "org.freedesktop.ibus.Manager"
-#define IBUS_DBUS_PATH       "/org/freedesktop/ibus/Manager"
-
-G_BEGIN_DECLS
-typedef struct _IBusIMClient IBusIMClient;
-typedef struct _IBusIMClientClass IBusIMClientClass;
-typedef struct _IBusIMClientPrivate IBusIMClientPrivate;
-
-struct _IBusIMClient {
-  GtkObject parent;
-  /* instance members */
-  IBusIMClientPrivate *priv;
-};
-
-struct _IBusIMClientClass {
-  GtkObjectClass parent;
-  /* class members */
-  void (* connected)        (IBusIMClient   *client);
-  void (* disconnected)     (IBusIMClient   *client);
-  void (* commit_string)    (IBusIMClient   *client,
-                             const gchar    *ic,
-                             const gchar    *text);
-  void (* update_preedit)   (IBusIMClient   *client,
-                             const gchar    *ic,
-                             const gchar    *text,
-                             gpointer       *attrs,
-                             gint            cursor_pos,
-                             gboolean        visible);
-  void (* show_preedit)     (IBusIMClient   *client,
-                             const gchar    *ic);
-  void (* hide_preedit)     (IBusIMClient   *client,
-                             const gchar    *ic);
-  void (* enabled)          (IBusIMClient   *client,
-                             const gchar    *ic);
-  void (* disabled)         (IBusIMClient   *client,
-                             const gchar    *ic);
-};
-
-extern IBusIMClient                *_client;
-
-GType           ibus_im_client_get_type          (void);
-void            ibus_im_client_register_type     (GTypeModule     *type_module);
-IBusIMClient   *ibus_im_client_new               (void);
-const gchar    *ibus_im_client_create_im_context (IBusIMClient    *client);
-void            ibus_im_client_shutdown          (void);
-void            ibus_im_client_focus_in          (IBusIMClient    *client,
-                                                  const gchar     *ic);
-void            ibus_im_client_focus_out         (IBusIMClient    *client,
-                                                  const gchar     *ic);
-void            ibus_im_client_reset             (IBusIMClient    *client,
-                                                  const gchar     *ic);
-gboolean        ibus_im_client_filter_keypress   (IBusIMClient    *client,
-                                                  const gchar     *ic,
-                                                  GdkEventKey     *key);
-void            ibus_im_client_set_cursor_location
-                                                 (IBusIMClient    *client,
-                                                  const gchar     *ic,
-                                                  GdkRectangle    *area);
-void            ibus_im_client_set_use_preedit   (IBusIMClient    *client,
-                                                  const gchar     *ic,
-                                                  gboolean         use_preedit);
-gboolean        ibus_im_client_is_enabled        (IBusIMClient    *client);
-void            ibus_im_client_release_im_context(IBusIMClient    *client,
-                                                  const gchar     *ic);
-void            ibus_im_client_kill_daemon       (IBusIMClient    *client);
-gboolean        ibus_im_client_get_connected     (IBusIMClient    *client);
-
-
-G_END_DECLS
-#endif
-
diff --git a/gtk2/ibusimcontext.c b/gtk2/ibusimcontext.c
deleted file mode 100644 (file)
index 1a14564..0000000
+++ /dev/null
@@ -1,534 +0,0 @@
-/* vim:set et ts=4: */
-/* IBus - The Input Bus
- * Copyright (C) 2008-2009 Huang Peng <shawn.p.huang@gmail.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-#include <gdk/gdkkeysyms.h>
-#include <gdk/gdkx.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <sys/un.h>
-#include "ibusimcontext.h"
-#include "ibusimclient.h"
-
-/* IBusIMContextPriv */
-struct _IBusIMContextPrivate {
-    GtkIMContext *slave;
-    GdkWindow *client_window;
-
-    /* enabled */
-    gboolean        enable;
-    gchar           *ic;
-
-    /* preedit status */
-    gchar           *preedit_string;
-    PangoAttrList   *preedit_attrs;
-    gint             preedit_cursor_pos;
-    gboolean         preedit_visible;
-
-    GdkRectangle     cursor_area;
-    gboolean         has_focus;
-};
-
-
-/* functions prototype */
-static void     ibus_im_context_class_init   (IBusIMContextClass  *klass);
-static void     ibus_im_context_init         (IBusIMContext       *obj);
-static void     ibus_im_context_finalize     (GObject            *obj);
-static void     ibus_im_context_reset        (GtkIMContext       *context);
-static gboolean ibus_im_context_filter_keypress
-                                            (GtkIMContext       *context,
-                                             GdkEventKey        *key);
-static void     ibus_im_context_focus_in     (GtkIMContext       *context);
-static void     ibus_im_context_focus_out    (GtkIMContext       *context);
-static void     ibus_im_context_get_preedit_string
-                                            (GtkIMContext       *context,
-                                             gchar              **str,
-                                             PangoAttrList      **attrs,
-                                             gint               *cursor_pos);
-static void     ibus_im_context_set_client_window
-                                            (GtkIMContext       *context,
-                                             GdkWindow          *client);
-static void     ibus_im_context_set_cursor_location
-                                            (GtkIMContext       *context,
-                                             GdkRectangle       *area);
-static void     ibus_im_context_set_use_preedit
-                                            (GtkIMContext       *context,
-                                             gboolean           use_preedit);
-
-/* callback functions for slave context */
-static void     _slave_commit_cb            (GtkIMContext       *slave,
-                                             gchar              *string,
-                                             IBusIMContext       *context);
-static void     _slave_preedit_changed_cb   (GtkIMContext       *slave,
-                                             IBusIMContext       *context);
-static void     _slave_preedit_start_cb     (GtkIMContext       *slave,
-                                             IBusIMContext       *context);
-static void     _slave_preedit_end_cb       (GtkIMContext       *slave,
-                                             IBusIMContext       *context);
-static void     _slave_retrieve_surrounding_cb
-                                            (GtkIMContext       *slave,
-                                             IBusIMContext       *context);
-static void     _slave_delete_surrounding_cb
-                                            (GtkIMContext       *slave,
-                                             gint               arg1,
-                                             gint               arg2,
-                                             IBusIMContext       *context);
-
-
-
-static GType                _ibus_type_im_context = 0;
-static GtkIMContextClass    *parent_class = NULL;
-
-void
-ibus_im_context_register_type (GTypeModule *type_module)
-{
-    static const GTypeInfo ibus_im_context_info = {
-        sizeof (IBusIMContextClass),
-        (GBaseInitFunc)        NULL,
-        (GBaseFinalizeFunc)     NULL,
-        (GClassInitFunc)     ibus_im_context_class_init,
-        NULL,            /* class finialize */
-        NULL,            /* class data */
-        sizeof (IBusIMContext),
-        0,
-        (GInstanceInitFunc)    ibus_im_context_init,
-    };
-
-    if (! _ibus_type_im_context ) {
-        if (type_module) {
-            _ibus_type_im_context =
-                g_type_module_register_type (type_module,
-                    GTK_TYPE_IM_CONTEXT,
-                    "IBusIMContext",
-                    &ibus_im_context_info,
-                    (GTypeFlags)0);
-        }
-        else {
-            _ibus_type_im_context =
-                g_type_register_static (GTK_TYPE_IM_CONTEXT,
-                    "IBusIMContext",
-                    &ibus_im_context_info,
-                    (GTypeFlags)0);
-        }
-    }
-}
-
-int
-ibus_im_context_get_type (void)
-{
-    if (_ibus_type_im_context == 0) {
-        ibus_im_context_register_type (NULL);
-    }
-
-    g_assert (_ibus_type_im_context != 0);
-    return _ibus_type_im_context;
-}
-
-GtkIMContext *
-ibus_im_context_new (void)
-{
-    IBusIMContext *obj;
-
-    obj = IBUS_IM_CONTEXT(g_object_new (IBUS_TYPE_IM_CONTEXT, NULL));
-
-    return GTK_IM_CONTEXT(obj);
-}
-
-static void
-ibus_im_context_class_init     (IBusIMContextClass *klass)
-{
-    GtkIMContextClass *im_context_class = GTK_IM_CONTEXT_CLASS (klass);
-    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-
-    parent_class = (GtkIMContextClass *) g_type_class_peek_parent (klass);
-
-    g_type_class_add_private (klass, sizeof (IBusIMContextPrivate));
-
-    im_context_class->reset = ibus_im_context_reset;
-    im_context_class->focus_in = ibus_im_context_focus_in;
-    im_context_class->focus_out = ibus_im_context_focus_out;
-    im_context_class->filter_keypress = ibus_im_context_filter_keypress;
-    im_context_class->get_preedit_string = ibus_im_context_get_preedit_string;
-    im_context_class->set_client_window = ibus_im_context_set_client_window;
-    im_context_class->set_cursor_location = ibus_im_context_set_cursor_location;
-    im_context_class->set_use_preedit = ibus_im_context_set_use_preedit;
-    gobject_class->finalize = ibus_im_context_finalize;
-}
-
-static void
-ibus_im_context_init     (IBusIMContext *obj)
-{
-    DEBUG_FUNCTION_IN;
-
-    IBusIMContext *ibus = IBUS_IM_CONTEXT (obj);
-    IBusIMContextPrivate *priv = ibus->priv =
-        G_TYPE_INSTANCE_GET_PRIVATE (ibus, IBUS_TYPE_IM_CONTEXT, IBusIMContextPrivate);
-
-    priv->client_window = NULL;
-
-    // Init ibus status
-    priv->enable = FALSE;
-
-    // Init preedit status
-    priv->preedit_string = NULL;
-    priv->preedit_attrs = NULL;
-    priv->preedit_cursor_pos = 0;
-    priv->preedit_visible = FALSE;
-
-    // Init cursor area
-    priv->cursor_area.x = 0;
-    priv->cursor_area.y = 0;
-    priv->cursor_area.width = 0;
-    priv->cursor_area.height = 0;
-
-    priv->has_focus = FALSE;
-
-
-    // Create slave im context
-    ibus->priv->slave = gtk_im_context_simple_new ();
-    g_signal_connect (ibus->priv->slave,
-                "commit", G_CALLBACK (_slave_commit_cb), obj);
-    g_signal_connect (ibus->priv->slave,
-                "preedit-start", G_CALLBACK (_slave_preedit_start_cb), obj);
-    g_signal_connect (ibus->priv->slave,
-                "preedit-end", G_CALLBACK (_slave_preedit_end_cb), obj);
-    g_signal_connect (ibus->priv->slave,
-                "preedit-changed", G_CALLBACK (_slave_preedit_changed_cb), obj);
-    g_signal_connect (ibus->priv->slave,
-                "retrieve-surrounding", G_CALLBACK (_slave_retrieve_surrounding_cb), obj);
-    g_signal_connect (ibus->priv->slave,
-                "delete-surrounding", G_CALLBACK (_slave_delete_surrounding_cb), obj);
-}
-
-static void
-ibus_im_context_finalize (GObject *obj)
-{
-    DEBUG_FUNCTION_IN;
-
-    IBusIMContext *ibus = IBUS_IM_CONTEXT (obj);
-    IBusIMContextPrivate *priv = ibus->priv;
-
-    ibus_im_client_release_im_context (_client, ibus);
-
-    g_object_unref (priv->slave);
-
-    if (priv->client_window) g_object_unref (priv->client_window);
-    // release preedit
-    if (priv->preedit_string) g_free (priv->preedit_string);
-    if (priv->preedit_attrs) pango_attr_list_unref (priv->preedit_attrs);
-
-    G_OBJECT_CLASS(parent_class)->finalize (obj);
-}
-
-static gboolean
-ibus_im_context_filter_keypress (GtkIMContext *context,
-                GdkEventKey  *event)
-{
-    DEBUG_FUNCTION_IN;
-
-    IBusIMContext *ibus = IBUS_IM_CONTEXT (context);
-    IBusIMContextPrivate *priv = ibus->priv;
-
-    if (ibus_im_client_filter_keypress (_client, ibus, event))
-        return TRUE;
-    else
-        return gtk_im_context_filter_keypress (priv->slave, event);
-}
-
-static void
-ibus_im_context_focus_in (GtkIMContext *context)
-{
-    DEBUG_FUNCTION_IN;
-
-    IBusIMContext *ibus = IBUS_IM_CONTEXT (context);
-    IBusIMContextPrivate *priv = ibus->priv;
-
-    priv->has_focus = TRUE;
-    ibus_im_client_focus_in (_client, ibus);
-    gtk_im_context_focus_in (priv->slave);
-
-    ibus_im_context_set_cursor_location(context, &priv->cursor_area);
-}
-
-static void
-ibus_im_context_focus_out (GtkIMContext *context)
-{
-    DEBUG_FUNCTION_IN;
-
-    IBusIMContext *ibus = IBUS_IM_CONTEXT (context);
-    IBusIMContextPrivate *priv = ibus->priv;
-
-    priv->has_focus = FALSE;
-    ibus_im_client_focus_out (_client, ibus);
-    gtk_im_context_focus_out (priv->slave);
-}
-
-static void
-ibus_im_context_reset (GtkIMContext *context)
-{
-    DEBUG_FUNCTION_IN;
-
-    IBusIMContext *ibus = IBUS_IM_CONTEXT (context);
-    IBusIMContextPrivate *priv = ibus->priv;
-
-    ibus_im_client_reset (_client, ibus);
-    gtk_im_context_reset (priv->slave);
-}
-
-
-static void
-ibus_im_context_get_preedit_string (GtkIMContext   *context,
-                   gchar         **str,
-                   PangoAttrList **attrs,
-                   gint           *cursor_pos)
-{
-    DEBUG_FUNCTION_IN;
-
-    IBusIMContext *ibus = IBUS_IM_CONTEXT (context);
-    IBusIMContextPrivate *priv = ibus->priv;
-
-    if (priv->enable) {
-        if (priv->preedit_visible) {
-            if (str) {
-                *str = g_strdup (priv->preedit_string ? priv->preedit_string: "");
-            }
-
-            if (attrs) {
-                *attrs = priv->preedit_attrs ?
-                            pango_attr_list_ref (priv->preedit_attrs):
-                            pango_attr_list_new ();
-            }
-
-            if (cursor_pos) {
-                *cursor_pos = priv->preedit_cursor_pos;
-            }
-        }
-        else {
-            if (str) *str = g_strdup ("");
-            if (attrs) *attrs = pango_attr_list_new ();
-            if (cursor_pos) *cursor_pos = 0;
-        }
-    }
-    else {
-        gtk_im_context_get_preedit_string (priv->slave, str, attrs, cursor_pos);
-    }
-}
-
-
-static void
-ibus_im_context_set_client_window  (GtkIMContext *context, GdkWindow *client)
-{
-    DEBUG_FUNCTION_IN;
-
-    IBusIMContext *ibus = IBUS_IM_CONTEXT (context);
-    IBusIMContextPrivate *priv = ibus->priv;
-
-    if (priv->client_window)
-        g_object_unref (priv->client_window);
-    if (client)
-        g_object_ref (client);
-    priv->client_window = client;
-    gtk_im_context_set_client_window (priv->slave, client);
-}
-
-static void
-ibus_im_context_set_cursor_location (GtkIMContext *context, GdkRectangle *area)
-{
-    DEBUG_FUNCTION_IN;
-
-    IBusIMContext *ibus = IBUS_IM_CONTEXT (context);
-    IBusIMContextPrivate *priv = ibus->priv;
-    gint x, y;
-
-    priv->cursor_area = *area;
-
-    if(priv->client_window) {
-        gdk_window_get_origin (priv->client_window, &x, &y);
-        area->x += x;
-        area->y += y;
-    }
-    ibus_im_client_set_cursor_location (_client, ibus, area);
-    gtk_im_context_set_cursor_location (priv->slave, area);
-}
-
-static void
-ibus_im_context_set_use_preedit (GtkIMContext *context, gboolean use_preedit)
-{
-    DEBUG_FUNCTION_IN;
-
-    IBusIMContext *ibus = IBUS_IM_CONTEXT (context);
-    IBusIMContextPrivate *priv = ibus->priv;
-
-    ibus_im_client_set_use_preedit (_client, ibus, use_preedit);
-    gtk_im_context_set_use_preedit (priv->slave, use_preedit);
-}
-
-
-/* Callback functions for slave context */
-static void
-_slave_commit_cb (GtkIMContext *slave, gchar *string, IBusIMContext *context)
-{
-    DEBUG_FUNCTION_IN;
-
-    /* IBusIMContextPrivate *priv = context->priv; */
-#if 0
-    if ((GtkIMContext *)context == CURRENT_CONTEXT && ibus_im_client_is_enabled (_client))
-        return;
-#endif
-    g_signal_emit_by_name (context, "commit", string);
-}
-
-static void
-_slave_preedit_changed_cb (GtkIMContext *slave, IBusIMContext *context)
-{
-    DEBUG_FUNCTION_IN;
-    IBusIMContextPrivate *priv = context->priv;
-
-    if (priv->enable && priv->ic)
-        return;
-
-    g_signal_emit_by_name (context, "preedit-changed");
-}
-
-static void
-_slave_preedit_start_cb (GtkIMContext *slave, IBusIMContext *context)
-{
-    DEBUG_FUNCTION_IN;
-    IBusIMContextPrivate *priv = context->priv;
-
-    if (priv->enable && priv->ic)
-        return;
-    g_signal_emit_by_name (context, "preedit-start");
-}
-
-static void
-_slave_preedit_end_cb (GtkIMContext *slave, IBusIMContext *context)
-{
-    DEBUG_FUNCTION_IN;
-    IBusIMContextPrivate *priv = context->priv;
-
-    if (priv->enable && priv->ic)
-        return;
-    g_signal_emit_by_name (context, "preedit-end");
-}
-
-static void
-_slave_retrieve_surrounding_cb (GtkIMContext *slave, IBusIMContext *context)
-{
-    DEBUG_FUNCTION_IN;
-    IBusIMContextPrivate *priv = context->priv;
-
-    if (priv->enable && priv->ic)
-        return;
-    g_signal_emit_by_name (context, "retrieve-surrounding");
-}
-
-static void
-_slave_delete_surrounding_cb (GtkIMContext *slave, gint a1, gint a2, IBusIMContext *context)
-{
-    DEBUG_FUNCTION_IN;
-    IBusIMContextPrivate *priv = context->priv;
-
-    if (priv->enable && priv->ic)
-        return;
-    g_signal_emit_by_name (context, "delete-surrounding", a1, a2);
-}
-
-gchar *
-ibus_im_context_get_ic (IBusIMContext *context)
-{
-    IBusIMContextPrivate *priv = context->priv;
-    return priv->ic;
-}
-
-void
-ibus_im_context_set_ic (IBusIMContext *context, const gchar *ic)
-{
-    IBusIMContextPrivate *priv = context->priv;
-    g_free (priv->ic);
-
-    priv->ic = g_strdup (ic);
-
-    if (priv->ic == NULL) {
-        priv->enable = FALSE;
-    }
-    else if (priv->has_focus) {
-        ibus_im_context_focus_in (GTK_IM_CONTEXT (context));
-    }
-}
-
-void
-ibus_im_context_enable (IBusIMContext *context)
-{
-    IBusIMContextPrivate *priv = context->priv;
-    priv->enable = TRUE;
-}
-
-void
-ibus_im_context_disable (IBusIMContext *context)
-{
-    IBusIMContextPrivate *priv = context->priv;
-    priv->enable = FALSE;
-}
-
-
-void
-ibus_im_context_commit_string (IBusIMContext  *context, const gchar *string)
-{
-    g_signal_emit_by_name (context, "commit", string);
-}
-
-void
-ibus_im_context_update_preedit (IBusIMContext *context, const gchar *string,
-        PangoAttrList *attrs, gint cursor_pos, gboolean visible)
-{
-    IBusIMContextPrivate *priv = context->priv;
-
-    priv->preedit_string = g_strdup (string);
-    priv->preedit_attrs = pango_attr_list_ref (attrs);
-    priv->preedit_cursor_pos = cursor_pos;
-    priv->preedit_visible = visible;
-
-    g_signal_emit_by_name (context, "preedit-changed");
-}
-
-void
-ibus_im_context_show_preedit (IBusIMContext *context)
-{
-    IBusIMContextPrivate *priv = context->priv;
-    if (priv->preedit_visible)
-        return;
-
-    priv->preedit_visible = TRUE;
-
-    g_signal_emit_by_name (context, "preedit-changed");
-}
-
-void
-ibus_im_context_hide_preedit (IBusIMContext *context)
-{
-    IBusIMContextPrivate *priv = context->priv;
-
-    if (!priv->preedit_visible)
-        return;
-
-    priv->preedit_visible = FALSE;
-
-    g_signal_emit_by_name (context, "preedit-changed");
-}
diff --git a/gtk2/ibusimcontext.h b/gtk2/ibusimcontext.h
deleted file mode 100644 (file)
index 934a022..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-/* vim:set et ts=4: */
-/* IBus - The Input Bus
- * Copyright (C) 2008-2009 Huang Peng <shawn.p.huang@gmail.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-#ifndef __IBUS_IM_CONTEXT_H_
-#define __IBUS_IM_CONTEXT_H_
-
-#include <gtk/gtk.h>
-
-/*
- * Type macros.
- */
-#define IBUS_TYPE_IM_CONTEXT             \
-    (ibus_im_context_get_type ())
-#define IBUS_IM_CONTEXT(obj)             \
-    (GTK_CHECK_CAST ((obj), IBUS_TYPE_IM_CONTEXT, IBusIMContext))
-#define IBUS_IM_CONTEXT_CLASS(klass)     \
-    (GTK_CHECK_CLASS_CAST ((klass), IBUS_TYPE_IM_CONTEXT, IBusIMContextClass))
-#define IBUS_IS_IM_CONTEXT(obj)          \
-    (GTK_CHECK_TYPE ((obj), IBUS_TYPE_IM_CONTEXT))
-#define IBUS_IS_IM_CONTEXT_CLASS(klass)  \
-    (GTK_CHECK_CLASS_TYPE ((klass), IBUS_TYPE_IM_CONTEXT))
-#define IBUS_IM_CONTEXT_GET_CLASS(obj)   \
-    (GTK_CHECK_GET_CLASS ((obj), IBUS_TYPE_IM_CONTEXT, IBusIMContextClass))
-
-G_BEGIN_DECLS
-typedef struct _IBusIMContext IBusIMContext;
-typedef struct _IBusIMContextClass IBusIMContextClass;
-typedef struct _IBusIMContextPrivate IBusIMContextPrivate;
-
-struct _IBusIMContext {
-  GtkIMContext parent;
-  /* instance members */
-  IBusIMContextPrivate *priv;
-};
-
-struct _IBusIMContextClass {
-  GtkIMContextClass parent;
-  /* class members */
-};
-
-int     ibus_im_context_get_type(void);
-GtkIMContext
-        *ibus_im_context_new    (void);
-void    ibus_im_context_register_type
-                                (GTypeModule    *type_module);
-void    ibus_im_context_shutdown
-                                (void);
-gchar   *ibus_im_context_get_ic (IBusIMContext  *context);
-void    ibus_im_context_set_ic  (IBusIMContext  *context,
-                                 const gchar    *ic);
-void    ibus_im_context_enable  (IBusIMContext  *context);
-void    ibus_im_context_disable (IBusIMContext  *context);
-void    ibus_im_context_commit_string
-                                (IBusIMContext  *context,
-                                const gchar     *string);
-void    ibus_im_context_update_preedit
-                                (IBusIMContext  *context,
-                                const gchar     *string,
-                                PangoAttrList   *attrs,
-                                gint            cursor_pos,
-                                gboolean        visible);
-void    ibus_im_context_show_preedit
-                                (IBusIMContext  *context);
-void    ibus_im_context_hide_preedit
-                                (IBusIMContext  *context);
-G_END_DECLS
-#endif
-
diff --git a/gtk2/ibusmarshalers.list b/gtk2/ibusmarshalers.list
deleted file mode 100644 (file)
index 89c4f76..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-NONE:NONE
-NONE:STRING
-NONE:STRING,STRING
-NONE:STRING,POINTER
-NONE:STRING,STRING,POINTER,INT,BOOL
diff --git a/lib/Makefile.am b/lib/Makefile.am
new file mode 100644 (file)
index 0000000..19d7bc3
--- /dev/null
@@ -0,0 +1,24 @@
+# vim:set noet ts=4:
+#
+# ibus - The Input Bus
+#
+# Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this program; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+# Boston, MA  02111-1307  USA
+
+SUBDIRS = \
+       gtk2 \
+       $(NULL)
diff --git a/lib/gtk2/Makefile.am b/lib/gtk2/Makefile.am
new file mode 100644 (file)
index 0000000..4f86420
--- /dev/null
@@ -0,0 +1,61 @@
+# vim:set noet ts=4:
+#
+# ibus - The Input Bus
+#
+# Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this program; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+# Boston, MA  02111-1307  USA
+
+INCLUDES = \
+       -I$(top_srcdir) \
+       $(NULL)
+
+lib_LTLIBRARIES = libibus-gtk.la
+libibus_gtk_la_SOURCES = \
+       ibusmarshalers.h \
+       ibusmarshalers.c \
+       ibusimclient.h \
+       ibusimclient.c \
+       $(NULL)
+libibus_gtk_la_CFLAGS = \
+       @GTK2_CFLAGS@ \
+       @DBUS_CFLAGS@ \
+       -DG_LOG_DOMAIN=\"IBUS\" \
+       $(NULL)
+libibus_gtk_la_LDFLAGS = \
+       @GTK2_LIBS@ \
+       @DBUS_LIBS@ \
+       $(NULL)
+
+# gen marshal
+ibusmarshalers.h: stamp-ibusmarshalers.h
+       @true
+stamp-ibusmarshalers.h: ibusmarshalers.list
+       $(GLIB_GENMARSHAL) --prefix=ibus_marshal $(srcdir)/ibusmarshalers.list --header >> xgen-gmh \
+       && (cmp -s xgen-gmh ibusmarshalers.h || cp xgen-gmh ibusmarshalers.h) \
+       && rm -f xgen-gmh \
+       && echo timestamp > $(@F)
+ibusmarshalers.c: ibusmarshalers.list
+       (echo "#include \"ibusmarshalers.h\""; \
+        $(GLIB_GENMARSHAL) --prefix=ibus_marshal $(srcdir)/ibusmarshalers.list --body; \
+        echo ) >> xgen-gmc \
+       && cp xgen-gmc ibusmarshalers.c \
+       && rm -f xgen-gmc
+
+EXTRA_DIST = \
+       ibusmarshalers.list \
+       $(NULL)
+
diff --git a/lib/gtk2/ibusimclient.c b/lib/gtk2/ibusimclient.c
new file mode 100644 (file)
index 0000000..c1535b7
--- /dev/null
@@ -0,0 +1,1308 @@
+/* vim:set et ts=4: */
+/* IBus - The Input Bus
+ * Copyright (C) 2008-2009 Huang Peng <shawn.p.huang@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include <config.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <sys/un.h>
+#include <string.h>
+#include <stdarg.h>
+#include <glib/gstdio.h>
+#include <gdk/gdkkeysyms.h>
+#include <gdk/gdkx.h>
+#include <dbus/dbus.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+
+#ifdef HAVE_SYS_INOTIFY_H
+#define HAVE_INOTIFY
+#  include <sys/inotify.h>
+#endif
+#include "ibusmarshalers.h"
+#include "ibusimclient.h"
+
+enum {
+    CONNECTED,
+    DISCONNECTED,
+    FORWARD_EVENT,
+    COMMIT_STRING,
+    UPDATE_PREEDIT,
+    SHOW_PREEDIT,
+    HIDE_PREEDIT,
+    ENABLED,
+    DISABLED,
+    LAST_SIGNAL,
+};
+
+#define IBUS_NAME  "org.freedesktop.IBus"
+#define IBUS_IFACE "org.freedesktop.IBus"
+#define IBUS_PATH  "/org/freedesktop/IBus"
+
+#define I_(string) g_intern_static_string (string)
+
+/* IBusIMClientPriv */
+struct _IBusIMClientPrivate {
+#if USE_DBUS_SESSION_BUS
+    DBusConnection  *dbus;
+#endif
+
+#ifdef HAVE_INOTIFY
+    /* inotify */
+    gint            inotify_wd;
+    GIOChannel     *inotify_channel;
+    guint           inotify_source;
+#endif
+
+    DBusConnection *ibus;
+
+};
+
+/* variables */
+static guint            client_signals[LAST_SIGNAL] = { 0 };
+
+/* functions prototype */
+static void     ibus_im_client_class_init   (IBusIMClientClass  *klass);
+static void     ibus_im_client_init         (IBusIMClient       *client);
+static void     ibus_im_client_finalize     (GObject            *obj);
+
+static void     _ibus_im_client_ibus_open   (IBusIMClient       *client);
+static void     _ibus_im_client_ibus_close  (IBusIMClient       *client);
+
+static gboolean _ibus_call_with_reply_and_block
+                                           (DBusConnection      *connection,
+                                            const gchar         *method,
+                                            int                 first_arg_type,
+                                                                ...);
+static gboolean _ibus_call_with_reply      (DBusConnection      *connection,
+                                            const gchar         *method,
+                                            DBusPendingCallNotifyFunction
+                                                                function,
+                                            void                *data,
+                                            DBusFreeFunction    free_function,
+                                            int                 first_arg_type,
+                                                                ...);
+static gboolean _dbus_call_with_reply_and_block
+                                           (DBusConnection      *connection,
+                                            const gchar         *dest,
+                                            const gchar         *path,
+                                            const gchar         *iface,
+                                            const char          *method,
+                                            int                 first_arg_type,
+                                                                ...);
+
+/* callback functions */
+static DBusHandlerResult
+                _ibus_im_client_message_filter_cb
+                                           (DBusConnection      *connection,
+                                            DBusMessage         *message,
+                                            void                *user_data);
+
+static GType ibus_type_im_client = 0;
+static GtkObjectClass *parent_class = NULL;
+
+
+GType
+ibus_im_client_get_type (void)
+{
+    if (ibus_type_im_client == 0) {
+        ibus_im_client_register_type (NULL);
+    }
+
+    g_assert (ibus_type_im_client != 0);
+    return ibus_type_im_client;
+}
+
+void
+ibus_im_client_register_type (GTypeModule *type_module)
+{
+    static const GTypeInfo ibus_im_client_info = {
+        sizeof (IBusIMClientClass),
+        (GBaseInitFunc)     NULL,
+        (GBaseFinalizeFunc) NULL,
+        (GClassInitFunc)    ibus_im_client_class_init,
+        NULL,               /* class finialize */
+        NULL,               /* class data */
+        sizeof (IBusIMClient),
+        0,
+        (GInstanceInitFunc) ibus_im_client_init,
+    };
+
+    if (! ibus_type_im_client ) {
+        if (type_module) {
+            ibus_type_im_client =
+                g_type_module_register_type (type_module,
+                    GTK_TYPE_OBJECT,
+                    "IBusIMClient",
+                    &ibus_im_client_info,
+                    (GTypeFlags)0);
+        }
+        else {
+            ibus_type_im_client =
+                g_type_register_static (GTK_TYPE_OBJECT,
+                    "IBusIMClient",
+                    &ibus_im_client_info,
+                    (GTypeFlags)0);
+        }
+    }
+}
+
+IBusIMClient *
+ibus_im_client_new (void)
+{
+    IBusIMClient *client;
+
+    client = IBUS_IM_CLIENT(g_object_new (IBUS_TYPE_IM_CLIENT, NULL));
+
+    return client;
+}
+
+static void
+ibus_im_client_class_init     (IBusIMClientClass *klass)
+{
+    /* GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass); */
+    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+    parent_class = (GtkObjectClass *) g_type_class_peek_parent (klass);
+
+    g_type_class_add_private (klass, sizeof (IBusIMClientPrivate));
+
+    gobject_class->finalize = ibus_im_client_finalize;
+
+    client_signals[CONNECTED] =
+        g_signal_new (I_("connected"),
+            G_TYPE_FROM_CLASS (gobject_class),
+            G_SIGNAL_RUN_FIRST,
+            G_STRUCT_OFFSET (IBusIMClientClass, connected),
+            NULL, NULL,
+            ibus_marshal_VOID__VOID,
+            G_TYPE_NONE, 0);
+
+    client_signals[DISCONNECTED] =
+        g_signal_new (I_("disconnected"),
+            G_TYPE_FROM_CLASS (gobject_class),
+            G_SIGNAL_RUN_FIRST,
+            G_STRUCT_OFFSET (IBusIMClientClass, disconnected),
+            NULL, NULL,
+            ibus_marshal_VOID__VOID,
+            G_TYPE_NONE, 0);
+
+    client_signals[FORWARD_EVENT] =
+        g_signal_new (I_("forward-event"),
+            G_TYPE_FROM_CLASS (gobject_class),
+            G_SIGNAL_RUN_FIRST,
+            G_STRUCT_OFFSET (IBusIMClientClass, commit_string),
+            NULL, NULL,
+            ibus_marshal_VOID__STRING_POINTER,
+            G_TYPE_NONE, 2,
+            G_TYPE_STRING,
+            G_TYPE_POINTER);
+
+
+    client_signals[COMMIT_STRING] =
+        g_signal_new (I_("commit-string"),
+            G_TYPE_FROM_CLASS (gobject_class),
+            G_SIGNAL_RUN_FIRST,
+            G_STRUCT_OFFSET (IBusIMClientClass, commit_string),
+            NULL, NULL,
+            ibus_marshal_VOID__STRING_STRING,
+            G_TYPE_NONE, 2,
+            G_TYPE_STRING,
+            G_TYPE_STRING);
+
+    client_signals[UPDATE_PREEDIT] =
+        g_signal_new (I_("update-preedit"),
+            G_TYPE_FROM_CLASS (gobject_class),
+            G_SIGNAL_RUN_FIRST,
+            G_STRUCT_OFFSET (IBusIMClientClass, update_preedit),
+            NULL, NULL,
+            ibus_marshal_VOID__STRING_STRING_POINTER_INT_BOOLEAN,
+            G_TYPE_NONE, 5,
+            G_TYPE_STRING,
+            G_TYPE_STRING,
+            G_TYPE_POINTER,
+            G_TYPE_INT,
+            G_TYPE_BOOLEAN
+            );
+
+    client_signals[SHOW_PREEDIT] =
+        g_signal_new (I_("show-preedit"),
+            G_TYPE_FROM_CLASS (gobject_class),
+            G_SIGNAL_RUN_FIRST,
+            G_STRUCT_OFFSET (IBusIMClientClass, show_preedit),
+            NULL, NULL,
+            ibus_marshal_VOID__STRING,
+            G_TYPE_NONE, 1,
+            G_TYPE_STRING);
+
+    client_signals[HIDE_PREEDIT] =
+        g_signal_new (I_("hide-preedit"),
+            G_TYPE_FROM_CLASS (gobject_class),
+            G_SIGNAL_RUN_FIRST,
+            G_STRUCT_OFFSET (IBusIMClientClass, hide_preedit),
+            NULL, NULL,
+            ibus_marshal_VOID__STRING,
+            G_TYPE_NONE, 1,
+            G_TYPE_STRING);
+
+    client_signals[ENABLED] =
+        g_signal_new (I_("enabled"),
+            G_TYPE_FROM_CLASS (gobject_class),
+            G_SIGNAL_RUN_FIRST,
+            G_STRUCT_OFFSET (IBusIMClientClass, enabled),
+            NULL, NULL,
+            ibus_marshal_VOID__STRING,
+            G_TYPE_NONE, 1,
+            G_TYPE_STRING);
+
+    client_signals[DISABLED] =
+        g_signal_new (I_("disabled"),
+            G_TYPE_FROM_CLASS (gobject_class),
+            G_SIGNAL_RUN_FIRST,
+            G_STRUCT_OFFSET (IBusIMClientClass, disabled),
+            NULL, NULL,
+            ibus_marshal_VOID__STRING,
+            G_TYPE_NONE, 1,
+            G_TYPE_STRING);
+
+}
+
+/*
+ * open ibus connection
+ */
+static void
+_ibus_im_client_ibus_open (IBusIMClient *client)
+{
+    gchar *ibus_addr = NULL;
+    DBusError error;
+
+    IBusIMClientPrivate *priv = client->priv;
+
+    if (priv->ibus != NULL)
+        return;
+
+#if USE_DBUS_SESSION_BUS
+    dbus_connection_setup_with_g_main (priv->dbus, NULL);
+    if (!_dbus_call_with_reply_and_block (priv->dbus,
+                        IBUS_NAME, IBUS_PATH, IBUS_IFACE,
+                        "GetIBusAddress",
+                        DBUS_TYPE_INVALID,
+                        DBUS_TYPE_STRING, &ibus_addr,
+                        DBUS_TYPE_INVALID
+                        )) {
+        g_warning ("Can not get ibus address");
+        return;
+    }
+#endif
+    if (ibus_addr == NULL) {
+        gchar *display;
+        gchar *hostname = "";
+        gchar *displaynumber = "0";
+        gchar *screennumber = "0";
+        gchar *username = NULL;
+        gchar *p;
+
+        display = g_strdup (g_getenv ("DISPLAY"));
+        if (display == NULL) {
+            g_warning ("DISPLAY is empty! We use default DISPLAY (:0.0)");
+        }
+        else {
+            p = display;
+            hostname = display;
+            for (; *p != ':' && *p != '\0'; p++);
+
+            if (*p == ':') {
+                *p = '\0';
+                p++;
+                displaynumber = p;
+            }
+
+            for (; *p != '.' && *p != '\0'; p++);
+
+            if (*p == '.') {
+                *p = '\0';
+                p++;
+                screennumber = p;
+            }
+        }
+
+        username = g_strdup (getlogin());
+        if (username == NULL)
+            username = g_strdup (g_getenv("LOGNAME"));
+        if (username == NULL)
+            username = g_strdup (g_getenv("USER"));
+        if (username == NULL)
+            username = g_strdup (g_getenv("LNAME"));
+        if (username == NULL)
+            username = g_strdup (g_getenv("USERNAME"));
+
+        ibus_addr = g_strdup_printf (
+            "unix:path=/tmp/ibus-%s/ibus-%s-%s.%s",
+            username, hostname, displaynumber, screennumber);
+
+        g_free (display);
+        g_free (username);
+    }
+
+    /*
+     * Init ibus and proxy object
+     */
+    dbus_error_init (&error);
+    priv->ibus = dbus_connection_open_private (ibus_addr, &error);
+    g_free (ibus_addr);
+    if (priv->ibus == NULL) {
+        g_warning ("Error: %s", error.message);
+        dbus_error_free (&error);
+        return;
+    }
+
+    if (!dbus_connection_add_filter (priv->ibus,
+            _ibus_im_client_message_filter_cb,
+            client, NULL)) {
+        g_warning ("Out of memory");
+        return;
+    }
+
+    dbus_connection_setup_with_g_main (priv->ibus, NULL);
+
+    g_signal_emit (client, client_signals[CONNECTED], 0);
+
+}
+
+/*
+ * close ibus connection
+ */
+static void
+_ibus_im_client_ibus_close (IBusIMClient *client)
+{
+    IBusIMClientPrivate *priv = client->priv;
+
+    if (priv->ibus) {
+        dbus_connection_close (priv->ibus);
+        dbus_connection_unref (priv->ibus);
+        priv->ibus = NULL;
+        g_signal_emit (client, client_signals[DISCONNECTED], 0);
+    }
+}
+
+/*
+ * create a ibus input context
+ */
+const gchar *
+ibus_im_client_create_input_context (IBusIMClient *client)
+{
+    IBusIMClientPrivate *priv = client->priv;
+
+    if (priv->ibus == NULL)
+        return NULL;
+
+    const gchar *app_name = g_get_application_name ();
+    gchar *ic = NULL;
+    _ibus_call_with_reply_and_block (priv->ibus, "CreateInputContext",
+                DBUS_TYPE_STRING, &app_name,
+                DBUS_TYPE_INVALID,
+                DBUS_TYPE_STRING, &ic,
+                DBUS_TYPE_INVALID);
+    return ic;
+}
+
+#ifdef HAVE_INOTIFY
+static gboolean
+_ibus_im_client_inotify_cb (GIOChannel *source, GIOCondition condition, IBusIMClient *client)
+{
+    struct inotify_event *p = NULL;
+    gchar *name;
+    gsize n;
+
+    if ((condition & G_IO_IN) == 0)
+        return TRUE;
+
+    p = g_malloc0 (sizeof (struct inotify_event) + 1024);
+
+    g_io_channel_read_chars (source, (gchar *) p, sizeof (struct inotify_event),  &n, NULL);
+    g_io_channel_read_chars (source, ((gchar *)p) + sizeof (struct inotify_event), p->len,  &n, NULL);
+
+    name = g_strdup_printf ("ibus-%s", g_getenv ("DISPLAY"));
+    for (n = 0; name[n] != 0; n++) {
+        if (name[n] != ':')
+            continue;
+        name[n] = '-';
+        break;
+    }
+
+    if (g_strcmp0 (p->name, name) == 0) {
+        if (p->mask & IN_CREATE) {
+            g_usleep (1000);
+            _ibus_im_client_ibus_open (client);
+        }
+    }
+    g_free (name);
+    g_free (p);
+
+    return TRUE;
+}
+#endif
+
+static void
+ibus_im_client_init (IBusIMClient *obj)
+{
+    DEBUG_FUNCTION_IN;
+
+    IBusIMClient *client = IBUS_IM_CLIENT (obj);
+    IBusIMClientPrivate *priv;
+
+    gchar *watch_path;
+    struct stat stat_buf;
+
+#ifdef HAVE_INOTIFY
+    gint inotify_fd = inotify_init ();
+#endif
+
+    priv = G_TYPE_INSTANCE_GET_PRIVATE (client, IBUS_TYPE_IM_CLIENT, IBusIMClientPrivate);
+    client->priv = priv;
+
+    watch_path = g_strdup_printf ("/tmp/ibus-%s", g_get_user_name ());
+
+    if (g_stat (watch_path, &stat_buf) != 0) {
+        g_mkdir (watch_path, 0750);
+    }
+
+#ifdef HAVE_INOTIFY
+    /* init inotify */
+    priv->inotify_wd = inotify_add_watch (inotify_fd, watch_path, IN_CREATE | IN_DELETE);
+    priv->inotify_channel = g_io_channel_unix_new (inotify_fd);
+    g_io_channel_set_close_on_unref (priv->inotify_channel, TRUE);
+    priv->inotify_source = g_io_add_watch (priv->inotify_channel,
+                                    G_IO_IN,
+                                    (GIOFunc)_ibus_im_client_inotify_cb,
+                                    (gpointer)client);
+#endif
+    g_free (watch_path);
+
+#if USE_DBUS_SESSION_BUS
+    /*
+     * Init dbus
+     */
+    dbus_error_init (&error);
+    priv->dbus = dbus_bus_get (DBUS_BUS_SESSION, &error);
+    if (priv->dbus == NULL) {
+        g_warning ("Error: %s", error.message);
+        dbus_error_free (&error);
+        return;
+    }
+#endif
+
+    _ibus_im_client_ibus_open (client);
+
+#if USE_DBUS_SESSION_BUS
+    if (!dbus_connection_add_filter (priv->dbus,
+            _ibus_im_client_message_filter_cb,
+            client, NULL)) {
+        g_warning ("Out of memory");
+        return;
+    }
+
+    gchar *rule =
+            "type='signal',"
+            "sender='" DBUS_SERVICE_DBUS "',"
+            "interface='" DBUS_INTERFACE_DBUS "',"
+            "member='NameOwnerChanged',"
+            "path='" DBUS_PATH_DBUS "',"
+            "arg0='" IBUS_NAME "'";
+
+    if (!_dbus_call_with_reply_and_block (priv->dbus,
+                        DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS,
+                        "AddMatch",
+                        DBUS_TYPE_STRING, &rule,
+                        DBUS_TYPE_INVALID,
+                        DBUS_TYPE_INVALID
+                        )) {
+        g_warning ("Can not get ibus address");
+        return;
+    }
+#endif
+#if 0
+    /* get dbus proxy */
+    priv->dbus = dbus_g_proxy_new_for_name (priv->ibus,
+                                DBUS_SERVICE_DBUS,
+                                DBUS_PATH_DBUS,
+                                DBUS_INTERFACE_DBUS);
+    g_assert (priv->dbus != NULL);
+
+    /* connect NameOwnerChanged signal */
+    dbus_g_proxy_add_signal (priv->dbus, "NameOwnerChanged",
+                                G_TYPE_STRING,
+                                G_TYPE_STRING,
+                                G_TYPE_STRING,
+                                G_TYPE_INVALID);
+
+    dbus_g_proxy_connect_signal (priv->dbus, "NameOwnerChanged",
+                                G_CALLBACK (_dbus_name_owner_changed_cb),
+                                (gpointer)client, NULL);
+    dbus_bus_add_match ((DBusConnection *)dbus_g_connection_get_connection (priv->ibus),
+                        "type='signal',"
+                        "sender='" DBUS_SERVICE_DBUS
+                        "',interface='" DBUS_INTERFACE_DBUS
+                        "',path='" DBUS_PATH_DBUS
+                        "',member='NameOwnerChanged',"
+                        "arg0='" IBUS_DBUS_SERVICE "'",
+                        &dbus_error);
+
+     _ibus_im_client_reinit_imm (client);
+#endif
+
+}
+
+
+static void
+ibus_im_client_finalize (GObject *obj)
+{
+    DEBUG_FUNCTION_IN;
+
+    IBusIMClient *client = IBUS_IM_CLIENT (obj);
+    IBusIMClientPrivate *priv = client->priv;
+
+    g_assert (client == _client);
+
+#ifdef HAVE_INOTIFY
+    g_source_remove (priv->inotify_source);
+    g_io_channel_unref (priv->inotify_channel);
+#endif
+
+#if USE_DBUS_SESSION_BUS
+    if (priv->dbus) {
+        dbus_connection_unref (priv->dbus);
+    }
+#endif
+    _ibus_im_client_ibus_close (client);
+
+    G_OBJECT_CLASS(parent_class)->finalize (obj);
+
+    _client = NULL;
+}
+
+static void
+_ibus_signal_commit_string_handler (DBusConnection *connection, DBusMessage *message, IBusIMClient *client)
+{
+    /* Handle CommitString signal */
+    DBusError error = {0};
+    gchar *ic = NULL;
+    gchar *string = NULL;
+
+    if (!dbus_message_get_args (message, &error,
+            DBUS_TYPE_STRING, &ic,
+            DBUS_TYPE_STRING, &string,
+            DBUS_TYPE_INVALID)) {
+        g_warning ("%s", error.message);
+        dbus_error_free (&error);
+    }
+    else {
+        g_signal_emit (client, client_signals[COMMIT_STRING], 0, ic, string);
+    }
+}
+
+static void
+_ibus_signal_update_preedit_handler (DBusConnection *connection, DBusMessage *message, IBusIMClient *client)
+{
+    /* Handle UpdatePreedit signal */
+    DBusMessageIter iter, sub_iter;
+    int type, sub_type;
+
+    gchar *ic = NULL;
+    gchar *string = NULL;
+    PangoAttrList *attrs = NULL;
+    int cursor = 0;
+    gboolean visible = False;
+
+    if (!dbus_message_iter_init (message, &iter)) {
+        g_warning ("The UpdatePreedit signal does have args!");
+        return;
+    }
+
+    type = dbus_message_iter_get_arg_type (&iter);
+    if (type != DBUS_TYPE_STRING) {
+        g_warning ("The 1st argument of UpdatePreedit signal must be a String");
+        return;
+    }
+    dbus_message_iter_get_basic (&iter, &ic);
+    dbus_message_iter_next (&iter);
+
+    type = dbus_message_iter_get_arg_type (&iter);
+    if (type != DBUS_TYPE_STRING) {
+        g_warning ("The 2nd argument of UpdatePreedit signal must be a String");
+        return;
+    }
+    dbus_message_iter_get_basic (&iter, &string);
+    dbus_message_iter_next (&iter);
+
+
+    type = dbus_message_iter_get_arg_type (&iter);
+    if (type != DBUS_TYPE_ARRAY) {
+        g_warning ("The 3rd argument of UpdatePreedit signal must be a Struct Array");
+        return;
+    }
+
+    dbus_message_iter_recurse (&iter, &sub_iter);
+
+    if (dbus_message_iter_get_arg_type (&sub_iter) != DBUS_TYPE_INVALID) {
+        if (dbus_message_iter_get_arg_type (&sub_iter) != DBUS_TYPE_ARRAY ||
+            dbus_message_iter_get_element_type (&sub_iter) != DBUS_TYPE_UINT32 ) {
+            g_warning ("The 3rd argument of UpdatePreedit signal must be a Struct Array");
+            return;
+        }
+
+        attrs = pango_attr_list_new ();
+
+        while ((sub_type = dbus_message_iter_get_arg_type (&sub_iter) != DBUS_TYPE_INVALID)) {
+            PangoAttribute *attr;
+            DBusMessageIter sub_sub_iter;
+            guint *values = NULL;
+            gint length = 0;
+            dbus_message_iter_recurse (&sub_iter, &sub_sub_iter);
+            dbus_message_iter_get_fixed_array (&sub_sub_iter, &values, &length);
+
+            if (length <= 0) {
+                g_warning ("The element of the 3rd argument of UpdatePreedit should not be a empty array");
+                continue;
+            }
+
+            switch (values[0]) {
+            case 1: /* Underline */
+                attr = pango_attr_underline_new (values[1]);
+                attr->start_index = g_utf8_offset_to_pointer (string, values[2]) - string;
+                attr->end_index = g_utf8_offset_to_pointer (string, values[3]) - string;
+                pango_attr_list_insert (attrs, attr);
+                break;
+
+            case 2: /* Foreground Color */
+                attr = pango_attr_foreground_new (
+                                (values[1] & 0xff0000) >> 8,
+                                (values[1] & 0x00ff00),
+                                (values[1] & 0x0000ff) << 8
+                                );
+                attr->start_index = g_utf8_offset_to_pointer (string, values[2]) - string;
+                attr->end_index = g_utf8_offset_to_pointer (string, values[3]) - string;
+                pango_attr_list_insert (attrs, attr);
+                break;
+            case 3: /* Background Color */
+                attr = pango_attr_background_new (
+                                (values[1] & 0xff0000) >> 8,
+                                (values[1] & 0x00ff00),
+                                (values[1] & 0x0000ff) << 8
+                                );
+                attr->start_index = g_utf8_offset_to_pointer (string, values[2]) - string;
+                attr->end_index = g_utf8_offset_to_pointer (string, values[3]) - string;
+                pango_attr_list_insert (attrs, attr);
+                break;
+            default:
+                g_warning ("Unkown type attribute type = %d", values[0]);
+
+            }
+
+            dbus_message_iter_next (&sub_iter);
+
+        }
+    }
+    dbus_message_iter_next (&iter);
+
+    type = dbus_message_iter_get_arg_type (&iter);
+    if (type != DBUS_TYPE_INT32) {
+        g_warning ("The 4th argument of UpdatePreedit signal must be an Int32 %c", type);
+        pango_attr_list_unref (attrs);
+        return;
+    }
+    dbus_message_iter_get_basic (&iter, &cursor);
+    dbus_message_iter_next (&iter);
+
+    type = dbus_message_iter_get_arg_type (&iter);
+    if (type != DBUS_TYPE_BOOLEAN) {
+        g_warning ("The 4th argument of UpdatePreedit signal must be an Int32 %c", type);
+        pango_attr_list_unref (attrs);
+        return;
+    }
+    dbus_message_iter_get_basic (&iter, &visible);
+    dbus_message_iter_next (&iter);
+
+    {
+        g_signal_emit (client, client_signals[UPDATE_PREEDIT], 0,
+                ic, string, attrs, cursor, visible);
+    }
+    pango_attr_list_unref (attrs);
+
+}
+
+static void
+_ibus_signal_show_preedit_handler (DBusConnection *connection, DBusMessage *message, IBusIMClient *client)
+{
+    /* Handle CommitString signal */
+    DBusError error = {0};
+    gchar *ic = NULL;
+
+    if (!dbus_message_get_args (message, &error,
+            DBUS_TYPE_STRING, &ic,
+            DBUS_TYPE_INVALID)) {
+        g_warning ("%s", error.message);
+        dbus_error_free (&error);
+    }
+    else {
+        g_signal_emit (client, client_signals[SHOW_PREEDIT], 0, ic);
+    }
+}
+
+static void
+_ibus_signal_hide_preedit_handler (DBusConnection *connection, DBusMessage *message, IBusIMClient *client)
+{
+    /* Handle CommitString signal */
+    DBusError error = {0};
+    gchar *ic = NULL;
+
+    if (!dbus_message_get_args (message, &error,
+            DBUS_TYPE_STRING, &ic,
+            DBUS_TYPE_INVALID)) {
+        g_warning ("%s", error.message);
+        dbus_error_free (&error);
+    }
+    else {
+        g_signal_emit (client, client_signals[HIDE_PREEDIT], 0, ic);
+    }
+}
+
+#ifdef USE_DBUS_SESSION_BUS
+static void
+_ibus_signal_name_owner_changed_handler (DBusConnection *connection, DBusMessage *message, IBusIMClient *client)
+{
+    gchar *name = NULL;
+    gchar *old_name = NULL;
+    gchar *new_name = NULL;
+    DBusError error = {0};
+
+    if (!dbus_message_get_args (message, &error,
+            DBUS_TYPE_STRING, &name,
+            DBUS_TYPE_STRING, &old_name,
+            DBUS_TYPE_STRING, &new_name,
+            DBUS_TYPE_INVALID)) {
+        g_warning ("%s", error.message);
+        dbus_error_free (&error);
+    }
+
+    g_return_if_fail (strcmp (name, IBUS_NAME) == 0);
+
+    if (g_strcmp0 (new_name, "") == 0) {
+        _ibus_im_client_ibus_close (client);
+        priv->enable = FALSE;
+    }
+    else {
+        _ibus_im_client_ibus_open (client);
+        priv->enable = TRUE;
+    }
+}
+#endif
+
+static void
+_ibus_signal_disconnected_handler (DBusConnection *connection, DBusMessage *message, IBusIMClient *client)
+{
+    _ibus_im_client_ibus_close (client);
+}
+
+static void
+_ibus_signal_enabled_handler (DBusConnection *connection, DBusMessage *message, IBusIMClient *client)
+{
+    DEBUG_FUNCTION_IN;
+    /* Handle CommitString signal */
+    DBusError error = {0};
+    gchar *ic = NULL;
+
+    if (!dbus_message_get_args (message, &error,
+            DBUS_TYPE_STRING, &ic,
+            DBUS_TYPE_INVALID)) {
+        g_warning ("%s", error.message);
+        dbus_error_free (&error);
+    }
+    else {
+        g_signal_emit (client, client_signals[ENABLED], 0, ic);
+    }
+}
+
+
+static void
+_ibus_signal_disabled_handler (DBusConnection *connection, DBusMessage *message, IBusIMClient *client)
+{
+    DEBUG_FUNCTION_IN;
+    /* Handle CommitString signal */
+    DBusError error = {0};
+    gchar *ic = NULL;
+
+    if (!dbus_message_get_args (message, &error,
+            DBUS_TYPE_STRING, &ic,
+            DBUS_TYPE_INVALID)) {
+        g_warning ("%s", error.message);
+        dbus_error_free (&error);
+    }
+    else {
+        g_signal_emit (client, client_signals[DISABLED], 0, ic);
+    }
+}
+
+
+static DBusHandlerResult
+_ibus_im_client_message_filter_cb (DBusConnection *connection, DBusMessage *message, void *user_data)
+{
+    IBusIMClient *client = (IBusIMClient *) user_data;
+
+    static struct SIGNAL_HANDLER {
+        const gchar *iface;
+        const gchar *name;
+        void (* handler) (DBusConnection *, DBusMessage *, IBusIMClient *);
+    } handlers[] = {
+#ifdef USE_DBUS_SESSION_BUS
+        { DBUS_INTERFACE_DBUS, "NameOwnerChanged", _ibus_signal_name_owner_changed_handler },
+#endif
+        { DBUS_INTERFACE_LOCAL, "Disconnected", _ibus_signal_disconnected_handler },
+        { IBUS_IFACE, "CommitString", _ibus_signal_commit_string_handler },
+        { IBUS_IFACE, "UpdatePreedit", _ibus_signal_update_preedit_handler },
+        { IBUS_IFACE, "ShowPreedit", _ibus_signal_show_preedit_handler },
+        { IBUS_IFACE, "HidePreedit", _ibus_signal_hide_preedit_handler },
+        { IBUS_IFACE, "Enabled", _ibus_signal_enabled_handler },
+        { IBUS_IFACE, "Disabled", _ibus_signal_disabled_handler },
+        {0},
+    };
+
+    gint i;
+    for (i = 0; handlers[i].iface != NULL; i++) {
+        if (dbus_message_is_signal (message, handlers[i].iface, handlers[i].name)) {
+            handlers[i].handler (connection, message, client);
+            return DBUS_HANDLER_RESULT_HANDLED;
+        }
+    }
+    g_debug ("Unknown message %s", dbus_message_get_member (message));
+    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+inline static gboolean
+_dbus_call_with_reply_and_block_valist (DBusConnection *connection,
+    const gchar *dest, const gchar *path, const gchar* iface, const char *method,
+    int first_arg_type, va_list args)
+{
+
+    DBusMessage *message, *reply;
+    DBusError error = {0};
+    int type;
+    va_list tmp;
+
+    if (connection == NULL)
+        return FALSE;
+
+    message = dbus_message_new_method_call (dest,
+                                    path, iface, method);
+    if (!message) {
+        g_warning ("Out of memory!");
+        return FALSE;
+    }
+
+    va_copy (tmp, args);
+    if (!dbus_message_append_args_valist (message, first_arg_type, tmp)) {
+        dbus_message_unref (message);
+        g_warning ("Can not create call message");
+        return FALSE;
+    }
+
+    reply = dbus_connection_send_with_reply_and_block (connection,
+                        message, -1, &error);
+
+    dbus_message_unref (message);
+
+    if (!reply) {
+        g_warning ("%s", error.message);
+        dbus_error_free (&error);
+        return FALSE;
+    }
+
+    type = first_arg_type;
+    while (type != DBUS_TYPE_INVALID) {
+        if (type == DBUS_TYPE_ARRAY) {
+            va_arg (args, int);
+            va_arg (args, void *);
+            va_arg (args, int);
+        }
+        else {
+            va_arg (args, void *);
+        }
+        type = va_arg (args, int);
+    }
+
+    type = va_arg (args, int);
+    if (!dbus_message_get_args_valist (reply, &error, type, args)) {
+        g_warning ("%s", error.message);
+        dbus_error_free (&error);
+        dbus_message_unref (reply);
+        return FALSE;
+    }
+    dbus_message_unref (reply);
+
+    return TRUE;
+
+}
+
+inline static gboolean
+_dbus_call_with_reply_and_block (DBusConnection *connection,
+    const gchar *dest, const gchar *path, const gchar* iface, const char *method,
+    gint first_arg_type, ...)
+{
+    va_list args;
+    gboolean retval;
+
+    if (connection == NULL)
+        return FALSE;
+
+    va_start (args, first_arg_type);
+    retval = _dbus_call_with_reply_and_block_valist (connection,
+                    dest, path, iface, method, first_arg_type, args);
+    va_end (args);
+
+    return TRUE;
+
+}
+
+static gboolean
+_ibus_call_with_reply_and_block (DBusConnection *connection, const gchar *method, int first_arg_type, ...)
+{
+    va_list args;
+    gboolean retval;
+
+    if (connection == NULL)
+        return FALSE;
+
+    va_start (args, first_arg_type);
+    retval = _dbus_call_with_reply_and_block_valist (connection,
+                    IBUS_NAME, IBUS_PATH, IBUS_IFACE, method, first_arg_type, args);
+    va_end (args);
+
+    return retval;
+
+}
+
+
+inline static gboolean
+_dbus_call_with_reply_valist (DBusConnection *connection,
+    const gchar *dest, const gchar *path, const gchar* iface, const char *method,
+    DBusPendingCallNotifyFunction notify_function,
+    void *user_data, DBusFreeFunction free_function,
+    gint first_arg_type, va_list args)
+{
+    DBusMessage *message = NULL;
+    DBusPendingCall *pendingcall = NULL;
+
+    if (connection == NULL) {
+        goto error;
+    }
+
+    message = dbus_message_new_method_call (dest,
+                                    path, iface, method);
+    if (!message) {
+        g_warning ("Out of memory!");
+        goto error;
+    }
+
+    if (!dbus_message_append_args_valist (message, first_arg_type, args)) {
+        g_warning ("Can not create call message");
+        goto error;
+    }
+
+    if (!dbus_connection_send_with_reply (connection,
+                        message, &pendingcall, -1)) {
+        g_warning ("Out of memory!");
+        goto error;
+    }
+
+    if (!dbus_pending_call_set_notify (pendingcall, notify_function,
+            user_data, free_function)) {
+        g_warning ("Out of memory!");
+        goto error;
+    }
+
+    dbus_message_unref (message);
+    return TRUE;
+
+error:
+    if (message)
+        dbus_message_unref (message);
+    if (pendingcall)
+        dbus_pending_call_cancel (pendingcall);
+    if (user_data && free_function)
+        free_function (user_data);
+    return False;
+}
+
+inline static gboolean
+_dbus_call_with_reply (DBusConnection *connection,
+    const gchar *dest, const gchar *path, const gchar* iface, const char *method,
+    DBusPendingCallNotifyFunction notify_function,
+    void *user_data, DBusFreeFunction free_function,
+    gint first_arg_type, ...)
+{
+    va_list args;
+    gboolean retval;
+
+    if (connection == NULL)
+        return FALSE;
+
+    va_start (args, first_arg_type);
+    retval = _dbus_call_with_reply_valist (connection,
+                    dest, path, iface, method,
+                    notify_function,
+                    user_data, free_function,
+                    first_arg_type, args);
+    va_end (args);
+
+    return TRUE;
+
+}
+
+
+
+static gboolean
+_ibus_call_with_reply (DBusConnection *connection, const gchar *method,
+       DBusPendingCallNotifyFunction notify_function,
+       void *user_data, DBusFreeFunction free_function,
+       int first_arg_type, ...)
+{
+    va_list args;
+    gboolean retval;
+
+    if (connection == NULL)
+        return FALSE;
+
+    va_start (args, first_arg_type);
+    retval = _dbus_call_with_reply_valist (connection,
+                    IBUS_NAME, IBUS_PATH, IBUS_IFACE,
+                    method, notify_function,
+                    user_data, free_function,
+                    first_arg_type, args);
+    va_end (args);
+
+    return retval;
+}
+
+typedef struct {
+    IBusIMClient *client;
+    gchar *ic;
+    GdkEvent event;
+}KeyPressCallData;
+
+static KeyPressCallData *
+_key_press_call_data_new (IBusIMClient *client, const gchar *ic, GdkEvent *event)
+{
+    KeyPressCallData *p = g_new (KeyPressCallData, 1);
+    p->client = g_object_ref (client);
+    p->ic = g_strdup (ic);
+    p->event = *event;
+    return p;
+}
+
+static void
+_key_press_call_data_free (KeyPressCallData *p)
+{
+    if (p) {
+        g_object_unref (p->client);
+        g_free (p->ic);
+    }
+    g_free (p);
+}
+
+static void
+_ibus_filter_keypress_reply_cb (DBusPendingCall *pending, void *user_data)
+{
+    DBusMessage *reply;
+    DBusError error = {0};
+    KeyPressCallData *call_data = (KeyPressCallData *) user_data;
+    gboolean retval;
+
+
+    reply = dbus_pending_call_steal_reply (pending);
+    dbus_pending_call_unref (pending);
+
+    if (dbus_set_error_from_message (&error, reply)) {
+        g_warning ("%s", error.message);
+        dbus_error_free (&error);
+        retval = FALSE;
+    }
+    else {
+        if (!dbus_message_get_args (reply, &error,
+                DBUS_TYPE_BOOLEAN, &retval, DBUS_TYPE_INVALID)) {
+            g_warning ("%s", error.message);
+            dbus_error_free (&error);
+            retval = FALSE;
+        }
+    }
+
+    if (!retval) {
+        g_signal_emit (call_data->client, client_signals[FORWARD_EVENT], 0,
+                call_data->ic, &(call_data->event));
+    }
+}
+
+gboolean
+ibus_im_client_filter_keypress (IBusIMClient *client, const gchar *ic, GdkEventKey *event)
+{
+    g_return_val_if_fail (IBUS_IS_IM_CLIENT(client), FALSE);
+    g_return_val_if_fail (ic != NULL, FALSE);
+    g_return_val_if_fail (event != NULL, FALSE);
+
+    IBusIMClientPrivate *priv = client->priv;
+
+    guint state = event->state & GDK_MODIFIER_MASK;
+    gboolean is_press = event->type == GDK_KEY_PRESS;
+
+    if (event->send_event) {
+        return FALSE;
+    }
+
+    /* Call IBus ProcessKeyEvent method */
+    if (!_ibus_call_with_reply (priv->ibus,
+            "ProcessKeyEvent",
+            _ibus_filter_keypress_reply_cb,
+            _key_press_call_data_new (client, ic, (GdkEvent *)event),
+            (DBusFreeFunction)_key_press_call_data_free,
+            DBUS_TYPE_STRING, &ic,
+            DBUS_TYPE_UINT32, &event->keyval,
+            DBUS_TYPE_BOOLEAN, &is_press,
+            DBUS_TYPE_UINT32, &state,
+            DBUS_TYPE_INVALID))
+        return FALSE;
+
+    return TRUE;
+}
+
+
+void
+ibus_im_client_focus_in (IBusIMClient *client, const gchar *ic)
+{
+    g_return_if_fail (IBUS_IS_IM_CLIENT(client));
+    g_return_if_fail (ic != NULL);
+
+    IBusIMClientPrivate *priv = client->priv;
+
+    /* Call IBus FocusIn method */
+     _ibus_call_with_reply_and_block (priv->ibus,
+            "FocusIn",
+            DBUS_TYPE_STRING, &ic,
+            DBUS_TYPE_INVALID,
+            DBUS_TYPE_INVALID);
+}
+
+void
+ibus_im_client_focus_out (IBusIMClient *client, const gchar *ic)
+{
+    g_return_if_fail (IBUS_IS_IM_CLIENT(client));
+    g_return_if_fail (ic != NULL);
+
+    IBusIMClientPrivate *priv = client->priv;
+
+    /* Call IBus FocusOut method */
+    _ibus_call_with_reply_and_block (priv->ibus,
+            "FocusOut",
+            DBUS_TYPE_STRING, &ic,
+            DBUS_TYPE_INVALID,
+            DBUS_TYPE_INVALID);
+
+}
+
+void
+ibus_im_client_reset (IBusIMClient *client, const gchar *ic)
+{
+    g_return_if_fail (IBUS_IS_IM_CLIENT(client));
+    g_return_if_fail (ic != NULL);
+
+    IBusIMClientPrivate *priv = client->priv;
+
+    /* Call IBus Reset method */
+    _ibus_call_with_reply_and_block (priv->ibus,
+            "Reset",
+            DBUS_TYPE_STRING, &ic,
+            DBUS_TYPE_INVALID,
+            DBUS_TYPE_INVALID);
+
+}
+
+void
+ibus_im_client_set_cursor_location (IBusIMClient *client, const gchar *ic, GdkRectangle *area)
+{
+    g_return_if_fail (IBUS_IS_IM_CLIENT(client));
+    g_return_if_fail (ic != NULL);
+    g_return_if_fail (area != NULL);
+
+    _ibus_call_with_reply_and_block (client->priv->ibus,
+            "SetCursorLocation",
+            DBUS_TYPE_STRING, &ic,
+            DBUS_TYPE_INT32, &area->x,
+            DBUS_TYPE_INT32, &area->y,
+            DBUS_TYPE_INT32, &area->width,
+            DBUS_TYPE_INT32, &area->height,
+            DBUS_TYPE_INVALID,
+            DBUS_TYPE_INVALID);
+}
+
+void
+ibus_im_client_set_use_preedit (IBusIMClient *client, const gchar *ic, gboolean use_preedit)
+{
+    g_return_if_fail (IBUS_IS_IM_CLIENT(client));
+    g_return_if_fail (ic != NULL);
+
+    _ibus_call_with_reply_and_block (client->priv->ibus,
+            "SetCapabilities",
+            DBUS_TYPE_STRING, &ic,
+            DBUS_TYPE_INT32, &use_preedit,
+            DBUS_TYPE_INVALID,
+            DBUS_TYPE_INVALID);
+}
+
+void
+ibus_im_client_release_input_context (IBusIMClient *client, const gchar *ic)
+{
+    g_return_if_fail (IBUS_IS_IM_CLIENT(client));
+    g_return_if_fail (ic != NULL);
+
+    IBusIMClientPrivate *priv = client->priv;
+
+    _ibus_call_with_reply_and_block (priv->ibus, "ReleaseInputContext",
+                DBUS_TYPE_STRING, &ic,
+                DBUS_TYPE_INVALID,
+                DBUS_TYPE_INVALID);
+
+}
+
+void
+ibus_im_client_kill_daemon (IBusIMClient *client)
+{
+    IBusIMClientPrivate *priv = client->priv;
+    _ibus_call_with_reply_and_block (priv->ibus, "Kill",
+                DBUS_TYPE_INVALID,
+                DBUS_TYPE_INVALID);
+}
+
+
+gboolean
+ibus_im_client_get_connected (IBusIMClient *client)
+{
+    IBusIMClientPrivate *priv = client->priv;
+    if (priv->ibus == NULL)
+        return FALSE;
+    return dbus_connection_get_is_connected (priv->ibus);
+}
diff --git a/lib/gtk2/ibusimclient.h b/lib/gtk2/ibusimclient.h
new file mode 100644 (file)
index 0000000..a0e4f75
--- /dev/null
@@ -0,0 +1,125 @@
+/* vim:set et ts=4: */
+/* IBus - The Input Bus
+ * Copyright (C) 2008-2009 Huang Peng <shawn.p.huang@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#ifndef __IBUS_IM_CLIENT_H_
+#define __IBUS_IM_CLIENT_H_
+
+#include <gtk/gtk.h>
+/*
+ * Type macros.
+ */
+
+/* define GOBJECT macros */
+#define IBUS_TYPE_IM_CLIENT             \
+    (ibus_im_client_get_type ())
+#define IBUS_IM_CLIENT(obj)             \
+    (GTK_CHECK_CAST ((obj), IBUS_TYPE_IM_CLIENT, IBusIMClient))
+#define IBUS_IM_CLIENT_CLASS(klass)     \
+    (GTK_CHECK_CLASS_CAST ((klass), IBUS_TYPE_IM_CLIENT, IBusIMClientClass))
+#define IBUS_IS_IM_CLIENT(obj)          \
+    (GTK_CHECK_TYPE ((obj), IBUS_TYPE_IM_CLIENT))
+#define IBUS_IS_IM_CLIENT_CLASS(klass)  \
+    (GTK_CHECK_CLASS_TYPE ((klass), IBUS_TYPE_IM_CLIENT))
+#define IBUS_IM_CLIENT_GET_CLASS(obj)   \
+    (GTK_CHECK_GET_CLASS ((obj), IBUS_TYPE_IM_CLIENT, IBusIMClientClass))
+
+#if 0
+#define DEBUG_FUNCTION_IN   g_debug("%s IN", __FUNCTION__);
+#define DEBUG_FUNCTION_OUT  g_debug("%s OUT", __FUNCTION__);
+#else
+#define DEBUG_FUNCTION_IN
+#define DEBUG_FUNCTION_OUT
+#endif
+
+
+
+#define IBUS_DBUS_SERVICE    "org.freedesktop.ibus"
+#define IBUS_DBUS_INTERFACE  "org.freedesktop.ibus.Manager"
+#define IBUS_DBUS_PATH       "/org/freedesktop/ibus/Manager"
+
+G_BEGIN_DECLS
+typedef struct _IBusIMClient IBusIMClient;
+typedef struct _IBusIMClientClass IBusIMClientClass;
+typedef struct _IBusIMClientPrivate IBusIMClientPrivate;
+
+struct _IBusIMClient {
+  GtkObject parent;
+  /* instance members */
+  IBusIMClientPrivate *priv;
+};
+
+struct _IBusIMClientClass {
+  GtkObjectClass parent;
+  /* class members */
+  void (* connected)        (IBusIMClient   *client);
+  void (* disconnected)     (IBusIMClient   *client);
+  void (* commit_string)    (IBusIMClient   *client,
+                             const gchar    *ic,
+                             const gchar    *text);
+  void (* update_preedit)   (IBusIMClient   *client,
+                             const gchar    *ic,
+                             const gchar    *text,
+                             gpointer       *attrs,
+                             gint            cursor_pos,
+                             gboolean        visible);
+  void (* show_preedit)     (IBusIMClient   *client,
+                             const gchar    *ic);
+  void (* hide_preedit)     (IBusIMClient   *client,
+                             const gchar    *ic);
+  void (* enabled)          (IBusIMClient   *client,
+                             const gchar    *ic);
+  void (* disabled)         (IBusIMClient   *client,
+                             const gchar    *ic);
+};
+
+extern IBusIMClient                *_client;
+
+GType           ibus_im_client_get_type          (void);
+void            ibus_im_client_register_type     (GTypeModule     *type_module);
+IBusIMClient   *ibus_im_client_new               (void);
+const gchar    *ibus_im_client_create_input_context
+                                                 (IBusIMClient    *client);
+void            ibus_im_client_shutdown          (void);
+void            ibus_im_client_focus_in          (IBusIMClient    *client,
+                                                  const gchar     *ic);
+void            ibus_im_client_focus_out         (IBusIMClient    *client,
+                                                  const gchar     *ic);
+void            ibus_im_client_reset             (IBusIMClient    *client,
+                                                  const gchar     *ic);
+gboolean        ibus_im_client_filter_keypress   (IBusIMClient    *client,
+                                                  const gchar     *ic,
+                                                  GdkEventKey     *key);
+void            ibus_im_client_set_cursor_location
+                                                 (IBusIMClient    *client,
+                                                  const gchar     *ic,
+                                                  GdkRectangle    *area);
+void            ibus_im_client_set_use_preedit   (IBusIMClient    *client,
+                                                  const gchar     *ic,
+                                                  gboolean         use_preedit);
+gboolean        ibus_im_client_is_enabled        (IBusIMClient    *client);
+void            ibus_im_client_release_input_context
+                                                 (IBusIMClient    *client,
+                                                  const gchar     *ic);
+void            ibus_im_client_kill_daemon       (IBusIMClient    *client);
+gboolean        ibus_im_client_get_connected     (IBusIMClient    *client);
+
+
+G_END_DECLS
+#endif
+
diff --git a/lib/gtk2/ibusmarshalers.list b/lib/gtk2/ibusmarshalers.list
new file mode 100644 (file)
index 0000000..89c4f76
--- /dev/null
@@ -0,0 +1,5 @@
+NONE:NONE
+NONE:STRING
+NONE:STRING,STRING
+NONE:STRING,POINTER
+NONE:STRING,STRING,POINTER,INT,BOOL
diff --git a/qt4/.gitignore b/qt4/.gitignore
deleted file mode 100644 (file)
index 52bae9b..0000000
+++ /dev/null
@@ -1 +0,0 @@
-moc*.cpp
diff --git a/qt4/Makefile.am b/qt4/Makefile.am
deleted file mode 100644 (file)
index 012a6b0..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-# vim:set noet ts=4:
-#
-# ibus - The Input Bus
-#
-# Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this program; if not, write to the
-# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
-# Boston, MA  02111-1307  USA
-
-EXTRA_DIST = \
-       ibus-client.cpp \
-       ibus-client.h \
-       ibus-input-context.cpp \
-       ibus-input-context.h \
-       ibus.pro \
-       im-ibus-qt.cpp \
-       $(NULL)
-
-if IBUS_BUILD_QT4
-Makefile.qmake: ibus.pro
-       $(QMAKE) -makefile -o Makefile.qmake $(srcdir)/ibus.pro
-
-all-local: Makefile.qmake
-       $(MAKE) -f Makefile.qmake $(AM_MAKEFLAGS) all 
-
-check-local: Makefile.qmake
-
-clean-local: Makefile.qmake
-       $(MAKE) -f Makefile.qmake $(AM_MAKEFLAGS) clean
-
-distclean-local: Makefile.qmake
-       $(MAKE) -f Makefile.qmake $(AM_MAKEFLAGS) distclean
-
-install-exec-local: Makefile.qmake
-       $(MAKE) -f Makefile.qmake $(AM_MAKEFLAGS) INSTALL_ROOT=$(DESTDIR) install
-
-uninstall-local: Makefile.qmake
-       $(MAKE) -f Makefile.qmake $(AM_MAKEFLAGS) INSTALL_ROOT=$(DESTDIR) uninstall
-
-test: all
-       QT_IM_MODULE=ibus kwrite
-endif
-
diff --git a/qt4/ibus-client.cpp b/qt4/ibus-client.cpp
deleted file mode 100644 (file)
index cb37b1b..0000000
+++ /dev/null
@@ -1,548 +0,0 @@
-/* vim:set noet ts=4: */
-/*
- * ibus - The Input Bus
- *
- * Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA  02111-1307  USA
- */
-#include <QtDebug>
-#include <QFile>
-#include <QDBusConnection>
-#include <QCoreApplication>
-#include <QDBusMessage>
-#include <QDBusArgument>
-
-#include "ibus-client.h"
-#include "ibus-input-context.h"
-
-#ifdef Q_WS_X11
-# include <QX11Info>
-# include <X11/Xlib.h>
-# include <X11/keysym.h>
-# include <X11/Xutil.h>
-#endif
-
-#define IBUS_NAME      "org.freedesktop.IBus"
-#define IBUS_PATH      "/org/freedesktop/IBus"
-#define IBUS_INTERFACE "org.freedesktop.IBus"
-
-
-IBusClient::IBusClient ()
-       : ibus (NULL), focused_context (NULL)
-{
-       username = getlogin ();
-       if (username.isNull ())
-               username = getenv ("LOGNAME");
-       if (username.isNull ())
-               username = getenv ("USER");
-       if (username.isNull ())
-               username = getenv ("LNAME");
-       if (username.isNull ())
-               username = getenv ("USERNAME");
-
-       session = getenv ("DISPLAY");
-       session.replace (":", "-");
-
-       ibus_addr = QString("unix:path=/tmp/ibus-%1/ibus-%2").arg (username, session);
-       connectToBus ();
-
-       QObject::connect (
-               &watcher,
-               SIGNAL(directoryChanged(const QString &)),
-               this,
-               SLOT(slotDirectoryChanged(const QString &)));
-
-       QString ibus_dir;
-
-       ibus_dir = QString ("/tmp/ibus-%1/").arg (username);
-       watcher.addPath (ibus_dir);
-}
-
-IBusClient::~IBusClient ()
-{
-       if (ibus)
-               delete ibus;
-}
-
-QString
-IBusClient::createInputContextRemote ()
-{
-       QString ic;
-       if (ibus) {
-               QDBusMessage message = QDBusMessage::createMethodCall (
-                                                               IBUS_NAME,
-                                                               IBUS_PATH,
-                                                               IBUS_INTERFACE,
-                                                               "CreateInputContext");
-               message << QCoreApplication::applicationName ();
-               message = ibus->call (message);
-
-               if (message.type () == QDBusMessage::ErrorMessage) {
-                       qWarning() << message.errorMessage ();
-               }
-               else if (message.type () == QDBusMessage::ReplyMessage) {
-                       ic = message.arguments () [0].toString ();
-               }
-       }
-       return ic;
-}
-
-QInputContext *
-IBusClient::createInputContext ()
-{
-       IBusInputContext *ctx;
-       QString ic;
-
-       ic = createInputContextRemote ();
-
-       ctx = new IBusInputContext (0, this, ic);
-       context_list.append (ctx);
-
-       if (! ic.isEmpty ()) {
-               context_dict[ic] = ctx;
-       }
-
-       return (QInputContext *) ctx;
-}
-
-void
-IBusClient::releaseInputContext (IBusInputContext *ctx)
-{
-       Q_ASSERT (ctx);
-
-       QString ic = ctx->getIC ();
-
-       if (ibus && !ic.isEmpty ()) {
-               QDBusMessage message = QDBusMessage::createMethodCall (
-                                                               IBUS_NAME,
-                                                               IBUS_PATH,
-                                                               IBUS_INTERFACE,
-                                                               "ReleaseInputContext");
-               message << ctx->getIC ();
-               message = ibus->call (message);
-
-               if (message.type () == QDBusMessage::ErrorMessage) {
-                       qWarning() << message.errorMessage ();
-               }
-               context_dict.remove (ic);
-       }
-       context_list.removeAll (ctx);
-}
-
-#ifndef Q_WS_X11
-static void
-translate_key_event (const QKeyEvent *event, quint32 *keyval, bool *is_press, quint32 *state)
-{
-       Q_ASSERT (event);
-       Q_ASSERT (keyval);
-       Q_ASSERT (is_press);
-       Q_ASSERT (state);
-
-       *keyval = event->key ();
-       *is_press = (event->type() == QEvent::KeyPress);
-
-       Qt::KeyboardModifiers modifiers = event->modifiers ();
-       *state = 0;
-       if (modifiers & Qt::ShiftModifier) {
-               *state |= (1<< 0);
-       }
-       if (modifiers & Qt::ControlModifier) {
-               *state |= (1<< 2);
-       }
-       if (modifiers & Qt::AltModifier) {
-               *state |= (1<< 3);
-       }
-       if (modifiers & Qt::MetaModifier) {
-               *state |= (1<< 28);
-       }
-       if (modifiers & Qt::KeypadModifier) {
-               // *state |= (1<< 28);
-       }
-       if (modifiers & Qt::GroupSwitchModifier) {
-               // *state |= (1<< 28);
-       }
-}
-
-bool
-IBusClient::filterEvent (IBusInputContext *ctx, QEvent *event)
-{
-       return true;
-}
-#endif
-
-#ifdef Q_WS_X11
-static inline bool
-translate_x_key_event (XEvent *xevent, quint32 *keyval, bool *is_press, quint32 *state)
-{
-       Q_ASSERT (xevent);
-       Q_ASSERT (keyval);
-       Q_ASSERT (state);
-       Q_ASSERT (is_press);
-
-       if (xevent->type != KeyPress && xevent->type != KeyRelease)
-               return false;
-
-       *is_press = (xevent->type == KeyPress);
-       *state = xevent->xkey.state;
-
-       char key_str[64];
-
-       if (XLookupString (&xevent->xkey, key_str, sizeof (key_str), (KeySym *)keyval, 0) <= 0) {
-               *keyval = (quint32) XLookupKeysym (&xevent->xkey, 0);
-       }
-
-       return true;
-
-}
-
-bool
-IBusClient::x11FilterEvent (IBusInputContext *ctx, QWidget * /* keywidget */, XEvent *xevent)
-{
-       Q_ASSERT (ctx);
-       Q_ASSERT (keywidget);
-       Q_ASSERT (xevent);
-
-       quint32 keyval;
-       quint32 state;
-       bool is_press;
-
-       if (focused_context != ctx) {
-               focusIn (ctx);
-       }
-
-       if (ibus == NULL || !ibus->isConnected () || ctx->getIC().isEmpty ())
-               return false;
-
-       if (!translate_x_key_event (xevent, &keyval, &is_press, &state))
-               return false;
-       QDBusMessage message = QDBusMessage::createMethodCall (
-                                                       IBUS_NAME,
-                                                       IBUS_PATH,
-                                                       IBUS_INTERFACE,
-                                                       "ProcessKeyEvent");
-       message << ctx->getIC ();
-       message << keyval;
-       message << is_press;
-       message << state;
-
-       message = ibus->call (message);
-
-       if (message.type() == QDBusMessage::ErrorMessage) {
-               qWarning() << message.errorMessage ();
-               return false;
-       }
-       else
-               return message.arguments ()[0].toBool ();
-}
-#endif
-
-void
-IBusClient::mouseHandler (IBusInputContext * /*ctx */, int /* x */, QMouseEvent * /* event */)
-{
-       return;
-}
-
-void
-IBusClient::setCursorLocation (IBusInputContext *ctx, QRect &rect)
-{
-       Q_ASSERT (ctx);
-
-       if (focused_context != ctx) {
-               focusIn (ctx);
-       }
-
-       if (ibus == NULL || !ibus->isConnected () || ctx->getIC().isEmpty ())
-               return;
-
-       QDBusMessage message = QDBusMessage::createMethodCall (
-                                                       IBUS_NAME,
-                                                       IBUS_PATH,
-                                                       IBUS_INTERFACE,
-                                                       "SetCursorLocation");
-       message << ctx->getIC ();
-       message << rect.x ();
-       message << rect.y ();
-       message << rect.width ();
-       message << rect.height ();
-       message = ibus->call (message);
-       if (message.type() == QDBusMessage::ErrorMessage) {
-               qWarning() << message.errorMessage ();
-       }
-}
-
-void
-IBusClient::reset (IBusInputContext *ctx)
-{
-       Q_ASSERT (ctx);
-
-       if (ibus == NULL || !ibus->isConnected () || ctx->getIC().isEmpty ())
-               return;
-       QDBusMessage message = QDBusMessage::createMethodCall (
-                                                       IBUS_NAME,
-                                                       IBUS_PATH,
-                                                       IBUS_INTERFACE,
-                                                       "Reset");
-       message << ctx->getIC ();
-       message = ibus->call (message);
-       if (message.type() == QDBusMessage::ErrorMessage) {
-               qWarning() << message.errorMessage ();
-       }
-}
-
-void
-IBusClient::focusIn (IBusInputContext *ctx)
-{
-       Q_ASSERT (ctx);
-       if (focused_context != ctx && focused_context != NULL)
-               focusOut (focused_context);
-       focused_context = ctx;
-
-       if (ibus == NULL || !ibus->isConnected () || ctx->getIC().isEmpty ())
-               return;
-       QDBusMessage message = QDBusMessage::createMethodCall (
-                                                       IBUS_NAME,
-                                                       IBUS_PATH,
-                                                       IBUS_INTERFACE,
-                                                       "FocusIn");
-       message << ctx->getIC ();
-       message = ibus->call (message);
-       if (message.type() == QDBusMessage::ErrorMessage) {
-               qWarning() << message.errorMessage ();
-       }
-
-}
-
-void
-IBusClient::focusOut (IBusInputContext *ctx)
-{
-       Q_ASSERT (ctx);
-
-       if (focused_context != ctx)
-               return;
-
-       focused_context = NULL;
-
-       if (ibus == NULL || !ibus->isConnected () || ctx->getIC().isEmpty ())
-               return;
-
-       QDBusMessage message = QDBusMessage::createMethodCall (
-                                                       IBUS_NAME,
-                                                       IBUS_PATH,
-                                                       IBUS_INTERFACE,
-                                                       "FocusOut");
-       message << ctx->getIC ();
-       message = ibus->call (message);
-       if (message.type() == QDBusMessage::ErrorMessage) {
-               qWarning() << message.errorMessage ();
-       }
-}
-void
-IBusClient::widgetDestroyed (IBusInputContext * /* ctx */, QWidget * /* widget */)
-{
-}
-
-bool
-IBusClient::connectToBus ()
-{
-       QDBusConnection *connection = NULL;
-
-       if (ibus != NULL)
-               return false;
-
-       connection = new QDBusConnection (
-               QDBusConnection::connectToBus (
-                       ibus_addr,
-                       QString ("ibus")));
-
-       if (!connection->isConnected ()) {
-               delete connection;
-               QDBusConnection::disconnectFromBus ("ibus");
-               return false;
-       }
-
-       if (!connection->connect ("",
-                       "",
-                       "org.freedesktop.DBus.Local",
-                       "Disconnected",
-                       this, SLOT (slotIBusDisconnected()))) {
-               qWarning () << "Can not connect Disconnected signal";
-               delete connection;
-               QDBusConnection::disconnectFromBus ("ibus");
-               return false;
-       }
-
-       if (!connection->connect ("",
-                       IBUS_PATH,
-                       IBUS_INTERFACE,
-                       "CommitString",
-                       this, SLOT (slotCommitString(QString, QString)))) {
-               qWarning () << "Can not connect CommitString signal";
-               delete connection;
-               QDBusConnection::disconnectFromBus ("ibus");
-               return false;
-       }
-
-       if (!connection->connect ("",
-                       IBUS_PATH,
-                       IBUS_INTERFACE,
-                       "UpdatePreedit",
-                       this, SLOT (slotUpdatePreedit(QDBusMessage)))) {
-               qWarning () << "Can not connect UpdatePreedit signal";
-               delete connection;
-               QDBusConnection::disconnectFromBus ("ibus");
-               return false;
-       }
-
-       if (!connection->connect ("",
-                       IBUS_PATH,
-                       IBUS_INTERFACE,
-                       "ShowPreedit",
-                       this, SLOT (slotShowPreedit(QDBusMessage)))) {
-               qWarning () << "Can not connect ShowPreedit signal";
-               delete connection;
-               QDBusConnection::disconnectFromBus ("ibus");
-               return false;
-       }
-
-       if (!connection->connect ("",
-                       IBUS_PATH,
-                       IBUS_INTERFACE,
-                       "HidePreedit",
-                       this, SLOT (slotHidePreedit(QDBusMessage)))) {
-               qWarning () << "Can not connect ShowPreedit signal";
-               delete connection;
-               QDBusConnection::disconnectFromBus ("ibus");
-               return false;
-       }
-
-       ibus = connection;
-
-       QList <IBusInputContext *>::iterator i;
-       for (i = context_list.begin (); i != context_list.end (); ++i ) {
-               QString ic = createInputContextRemote ();
-               (*i)->setIC (ic);
-               context_dict[ic] = *i;
-       }
-
-       return true;
-}
-
-void
-IBusClient::disconnectFromBus ()
-{
-       if (ibus) {
-               delete ibus;
-               ibus = NULL;
-               QDBusConnection::disconnectFromBus ("ibus");
-               QList <IBusInputContext *>::iterator i;
-               for (i = context_list.begin (); i != context_list.end (); ++i ) {
-                       (*i)->setIC ("");
-               }
-               context_dict.clear ();
-       }
-}
-
-void
-IBusClient::slotDirectoryChanged (const QString & /*path*/)
-{
-       if (ibus && !ibus->isConnected ())
-               disconnectFromBus ();
-
-       if (ibus == NULL ) {
-               if (QFile::exists (ibus_addr)) {
-                       usleep (500);
-                       connectToBus ();
-               }
-       }
-}
-
-void
-IBusClient::slotIBusDisconnected ()
-{
-       disconnectFromBus ();
-}
-
-
-void
-IBusClient::slotCommitString (QString ic, QString text)
-{
-       IBusInputContext *ctx = context_dict[ic];
-       ctx->commitString (text);
-}
-
-void
-IBusClient::slotUpdatePreedit (QDBusMessage message)
-{
-       QString ic;
-       QString text;
-       QVariant attrs;
-       int cursor_pos;
-       bool visible;
-
-       QList<QVariant> args = message.arguments ();
-
-       ic = args[0].toString ();
-       text = args[1].toString ();
-       attrs = args[2];
-       cursor_pos = args[3].toInt ();
-       visible = args[4].toBool ();
-       QList <QList <quint32> > attr_list;
-       const QDBusArgument arg = attrs.value <QDBusArgument> ();
-       arg.beginArray ();
-       while ( !arg.atEnd ()) {
-               quint32 type, value, start_index, end_index;
-
-               arg.beginArray ();
-               arg >> type >> value >> start_index >> end_index;
-               arg.endArray ();
-               QList <quint32> attr;
-               attr.append (type);
-               attr.append (value);
-               attr.append (start_index);
-               attr.append (end_index);
-               attr_list.append (attr);
-       }
-       arg.endArray ();
-
-       IBusInputContext *ctx = context_dict[ic];
-       ctx->updatePreedit (text, attr_list, cursor_pos, visible);
-}
-
-void
-IBusClient::slotShowPreedit (QDBusMessage message)
-{
-       QString ic;
-
-       QList<QVariant> args = message.arguments ();
-
-       ic = args[0].toString ();
-       IBusInputContext *ctx = context_dict[ic];
-       ctx->showPreedit ();
-}
-
-void
-IBusClient::slotHidePreedit (QDBusMessage message)
-{
-       QString ic;
-
-       QList<QVariant> args = message.arguments ();
-
-       ic = args[0].toString ();
-       IBusInputContext *ctx = context_dict[ic];
-       ctx->hidePreedit ();
-}
-
diff --git a/qt4/ibus-client.h b/qt4/ibus-client.h
deleted file mode 100644 (file)
index 285d633..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-/* vim:set noet ts=4: */
-/*
- * ibus - The Input Bus
- *
- * Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA  02111-1307  USA
- */
-#ifndef __IBUS_CLIENT_H_
-#define __IBUS_CLIENT_H_
-#include <QObject>
-#include <QList>
-#include <QHash>
-#include <QInputContext>
-#include <QFileSystemWatcher>
-#include <QDBusMessage>
-
-class QDBusConnection;
-class IBusInputContext;
-
-class IBusClient : public QObject {
-       Q_OBJECT
-public:
-       IBusClient ();
-       ~IBusClient ();
-
-public:
-
-#ifndef Q_WS_X11
-    bool filterEvent (IBusInputContext *ctx, const QEvent *event);
-#endif
-
-       bool isComposing (IBusInputContext const *ctx);
-       void mouseHandler (IBusInputContext *ctx, int x, QMouseEvent *event);
-       void widgetDestroyed (IBusInputContext *ctx, QWidget *widget);
-
-#ifdef Q_WS_X11
-       bool x11FilterEvent (IBusInputContext *ctx, QWidget *keywidget, XEvent *xevent);
-#endif
-
-public:
-       QInputContext *createInputContext ();
-       void releaseInputContext (IBusInputContext *ctx);
-       void setCursorLocation (IBusInputContext *ctx, QRect &rect);
-       void focusIn (IBusInputContext *ctx);
-       void focusOut (IBusInputContext *ctx);
-       void reset (IBusInputContext *ctx);
-
-private slots:
-       void slotDirectoryChanged (const QString &path);
-       void slotFileChanged (const QString &path);
-       void slotIBusDisconnected ();
-       void slotCommitString (QString ic, QString text);
-       //void slotUpdatePreedit (QString ic, QString text, QVariant attrs, int cursor_pos, bool show);
-       void slotUpdatePreedit (QDBusMessage message);
-       void slotShowPreedit (QDBusMessage message);
-       void slotHidePreedit (QDBusMessage message);
-
-private:
-       bool connectToBus ();
-       void disconnectFromBus ();
-       QString createInputContextRemote ();
-
-       QDBusConnection *ibus;
-       QFileSystemWatcher watcher;
-       QList <IBusInputContext *> context_list;
-       QHash <QString, IBusInputContext *>context_dict;
-       IBusInputContext *focused_context;
-       QString username;
-       QString session;
-       QString ibus_addr;
-};
-
-#endif // __IBUS_CLIENT_H_
diff --git a/qt4/ibus-input-context.cpp b/qt4/ibus-input-context.cpp
deleted file mode 100644 (file)
index 692fecb..0000000
+++ /dev/null
@@ -1,243 +0,0 @@
-/* vim:set noet ts=4: */
-/*
- * ibus - The Input Bus
- *
- * Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA  02111-1307  USA
- */
-#include "ibus-input-context.h"
-#include "ibus-client.h"
-#include <QtDebug>
-#include <QInputMethodEvent>
-#include <QTextCharFormat>
-
-typedef QInputMethodEvent::Attribute QAttribute;
-
-IBusInputContext::IBusInputContext (QObject *parent, IBusClient *client, QString &ic)
-       : QInputContext (parent), client (client), ic (ic), preedit_visible (false)
-{
-}
-
-IBusInputContext::~IBusInputContext ()
-{
-       client->releaseInputContext (this);
-}
-
-bool
-IBusInputContext::filterEvent (const QEvent *event)
-{
-#ifndef Q_WS_X11
-       if (client->filterEvent (this, event))
-               return true;
-       return QInputContext::filterEvent (event);
-#else
-       return QInputContext::filterEvent (event);
-#endif
-}
-
-QFont
-IBusInputContext::font () const
-{
-       return QInputContext::font ();
-}
-
-QString
-IBusInputContext::identifierName ()
-{
-       return QString ("ibus");
-}
-
-QString
-IBusInputContext::language()
-{
-       return QString ("");
-}
-
-void
-IBusInputContext::mouseHandler (int x, QMouseEvent *event)
-{
-       client->mouseHandler (this, x, event);
-       QInputContext::mouseHandler (x, event);
-}
-
-void
-IBusInputContext::reset()
-{
-       client->reset (this);
-}
-
-void
-IBusInputContext::update ()
-{
-       QWidget *widget;
-
-       if ((widget = focusWidget ()) == NULL)
-               return;
-
-       QRect rect = widget->inputMethodQuery(Qt::ImMicroFocus).toRect ();
-
-#if 0
-       QFont font = widget->inputMethodQuery(Qt::ImFont).value <QFont> ();
-       qDebug () << rect << preedit_string << preedit_cursor_pos;
-
-       QFontMetrics fm(font);
-       int textWidth = fm.width (preedit_string.left (preedit_cursor_pos));
-       rect.translate (textWidth, 0);
-#endif
-
-       QPoint topleft = widget->mapToGlobal(QPoint(0,0));
-       rect.translate (topleft);
-       if (cursor_location != rect ) {
-               client->setCursorLocation (this, rect);
-               cursor_location = rect;
-       }
-
-#if 0
-       QVariant value;
-       value = widget->inputMethodQuery(Qt::ImMicroFocus);
-       qDebug () << value;
-       value = widget->inputMethodQuery(Qt::ImFont);
-       qDebug () << value;
-       value = widget->inputMethodQuery(Qt::ImCursorPosition);
-       qDebug () << value;
-       value = widget->inputMethodQuery(Qt::ImSurroundingText);
-       qDebug () << value;
-       value = widget->inputMethodQuery(Qt::ImCurrentSelection);
-       qDebug () << value;
-#endif
-}
-
-bool
-IBusInputContext::isComposing() const
-{
-       return (!preedit_string.isEmpty ()) && preedit_visible;
-}
-
-void
-IBusInputContext::setFocusWidget (QWidget *widget)
-{
-       // qDebug () << "setFocusWidget (" << widget << ")";
-       QInputContext::setFocusWidget (widget);
-       update ();
-}
-
-void
-IBusInputContext::widgetDestroyed (QWidget *widget)
-{
-       QInputContext::widgetDestroyed (widget);
-       update ();
-}
-
-#ifdef Q_WS_X11
-bool
-IBusInputContext::x11FilterEvent (QWidget *keywidget, XEvent *xevent)
-{
-       if (client->x11FilterEvent (this, keywidget, xevent))
-               return true;
-       return QInputContext::x11FilterEvent (keywidget, xevent);
-}
-#endif
-
-void
-IBusInputContext::setIC (QString ic)
-{
-       this->ic = ic;
-}
-
-QString
-IBusInputContext::getIC ()
-{
-       return ic;
-}
-
-void
-IBusInputContext::commitString (QString text)
-{
-       QInputMethodEvent event;
-       event.setCommitString (text);
-       sendEvent (event);
-       update ();
-}
-
-void
-IBusInputContext::updatePreedit (QString text, QList <QList <quint32> > attr_list, int cursor_pos, bool visible)
-{
-       // qDebug () << text << cursor_pos << show;
-       QList <QAttribute> qattrs;
-
-       if (visible) {
-               // append cursor pos
-               qattrs.append (QAttribute (QInputMethodEvent::Cursor, cursor_pos, true, 0));
-
-               // append attributes
-               for (QList <QList <quint32> >::iterator it = attr_list.begin (); it != attr_list.end(); ++ it) {
-
-                       QList <quint32> attr = *it;
-                       QTextCharFormat format;
-
-                       switch (attr[0]) {
-                       case 1: // underline
-                               format.setUnderlineStyle (QTextCharFormat::SingleUnderline);
-                               break;
-                       case 2: // foreground
-                               format.setForeground (QBrush (QColor (attr[1])));
-                               break;
-                       case 3: // background
-                               format.setBackground (QBrush (QColor (attr[1])));
-                               break;
-                       default:
-                               break;
-                       }
-
-                       qattrs.append (QAttribute (QInputMethodEvent::TextFormat, attr[2], attr[3] - attr[2], QVariant (format)));
-                       // qDebug () << attr[0] << attr[2] << attr[3] - attr[2];
-               }
-       }
-       else {
-               qattrs.append (QAttribute (QInputMethodEvent::Cursor, 0, true, 0));
-               text = "";
-               cursor_pos = 0;
-       }
-
-       preedit_string = text;
-       preedit_visible = visible;
-       preedit_attrs = attr_list;
-       preedit_cursor_pos = cursor_pos;
-
-       QInputMethodEvent event (text, qattrs);
-       sendEvent (event);
-       update ();
-}
-
-void
-IBusInputContext::showPreedit ()
-{
-       if (preedit_visible)
-               return;
-
-       updatePreedit (preedit_string, preedit_attrs, preedit_cursor_pos, TRUE);
-}
-
-void
-IBusInputContext::hidePreedit ()
-{
-       if (!preedit_visible)
-               return;
-
-       updatePreedit (preedit_string, preedit_attrs, preedit_cursor_pos, FALSE);
-}
-
diff --git a/qt4/ibus-input-context.h b/qt4/ibus-input-context.h
deleted file mode 100644 (file)
index 317c876..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/* vim:set noet ts=4: */
-/*
- * ibus - The Input Bus
- *
- * Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA  02111-1307  USA
- */
-#ifndef __IBUS_INPUT_CONTEXT_H_
-#define __IBUS_INPUT_CONTEXT_H_
-#include <QInputContext>
-#include <QList>
-#include "ibus-client.h"
-
-class IBusClient;
-
-class IBusInputContext : public QInputContext  {
-       Q_OBJECT
-public:
-       IBusInputContext (QObject *parent, IBusClient *client, QString &ic);
-       ~IBusInputContext ();
-
-public:
-       bool filterEvent (const QEvent *event);
-       QFont font () const;
-       QString identifierName ();
-       bool isComposing() const;
-       QString language();
-       void mouseHandler (int x, QMouseEvent *event);
-       void reset();
-       void update ();
-       void setFocusWidget (QWidget *widget );
-       void widgetDestroyed (QWidget *widget);
-#ifdef Q_WS_X11
-       bool x11FilterEvent (QWidget *keywidget, XEvent *event);
-#endif
-       void setIC (QString ic);
-       QString getIC ();
-
-       void commitString (QString text);
-       void updatePreedit (QString text, QList <QList <quint32> > attr_list, int cursor_pos, bool visible);
-       void showPreedit ();
-       void hidePreedit ();
-
-
-private:
-       IBusClient *client;
-       QString ic;
-       QString preedit_string;
-       bool preedit_visible;
-       int preedit_cursor_pos;
-       QList <QList <quint32> > preedit_attrs;
-       QRect cursor_location;
-};
-
-#endif //__IBUS_INPUT_CONTEXT_H_
diff --git a/qt4/ibus.pro b/qt4/ibus.pro
deleted file mode 100644 (file)
index 1c308a2..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-# vim:set noet ts=4:
-#
-# ibus - The Input Bus
-#
-# Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this program; if not, write to the
-# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
-# Boston, MA  02111-1307  USA
-
-TEMPLATE = lib
-TARGET = ibus
-DEPENDPATH += . 
-INCLUDEPATH += .
-
-CONFIG += qt qdbus plugin
-
-# Input
-HEADERS += \
-       ibus-client.h \
-       ibus-input-context.h
-
-SOURCES += \
-       ibus-client.cpp \
-       ibus-input-context.cpp \
-       im-ibus-qt.cpp
-
-target.path += $$[QT_INSTALL_PLUGINS]/inputmethods
-INSTALLS    += target
diff --git a/qt4/im-ibus-qt.cpp b/qt4/im-ibus-qt.cpp
deleted file mode 100644 (file)
index 0d6944b..0000000
+++ /dev/null
@@ -1,136 +0,0 @@
-/* vim:set noet ts=4: */
-/*
- * ibus - The Input Bus
- *
- * Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA  02111-1307  USA
- */
-#include <cassert>
-#include <Qt>
-#include <QInputContextPlugin>
-#include "ibus-client.h"
-
-using namespace Qt;
-
-#define IBUS_IDENTIFIER_NAME "ibus"
-
-static IBusClient *client;
-
-/* The class Definition */
-class IBusInputContextPlugin: public QInputContextPlugin
-{
-
-    private:
-
-        /**
-         * The language list for SCIM.
-         */
-        static QStringList ibus_languages;
-
-    public:
-
-               IBusInputContextPlugin (QObject *parent = 0);
-
-        ~IBusInputContextPlugin ();
-
-        QStringList keys () const;
-
-        QStringList languages (const QString &key);
-
-        QString description (const QString &key);
-        
-        QInputContext *create (const QString &key);
-
-        QString displayName (const QString &key);
-
-};
-
-
-/* Implementations */
-QStringList IBusInputContextPlugin::ibus_languages;
-
-
-IBusInputContextPlugin::IBusInputContextPlugin (QObject *parent)
-       :QInputContextPlugin (parent)
-{
-}
-
-
-IBusInputContextPlugin::~IBusInputContextPlugin ()
-{
-       if (client != NULL) {
-               delete client;
-               client = NULL;
-       }
-}
-
-QStringList 
-IBusInputContextPlugin::keys () const 
-{
-    QStringList identifiers;
-    identifiers.push_back (IBUS_IDENTIFIER_NAME);
-    return identifiers;
-}
-
-
-QStringList
-IBusInputContextPlugin::languages (const QString & key)
-{
-       if (key.toLower () != IBUS_IDENTIFIER_NAME)
-               return QStringList ();
-
-    if (ibus_languages.empty ()) {
-        ibus_languages.push_back ("zh_CN");
-        ibus_languages.push_back ("zh_TW");
-        ibus_languages.push_back ("zh_HK");
-        ibus_languages.push_back ("ja");
-        ibus_languages.push_back ("ko");
-    }
-    return ibus_languages;
-}
-
-
-QString
-IBusInputContextPlugin::description (const QString &key)
-{
-       if (key.toLower () != IBUS_IDENTIFIER_NAME)
-               return QString ("");
-    
-       return QString::fromUtf8 ("Qt immodule plugin for IBus");
-}
-
-
-QInputContext *
-IBusInputContextPlugin::create (const QString &key)
-{
-    if (key.toLower () != IBUS_IDENTIFIER_NAME) {
-        return NULL;
-    } else {
-               if (client == NULL) {
-                       client = new IBusClient ();
-               }
-        return client->createInputContext ();
-    }
-}
-
-
-QString IBusInputContextPlugin::displayName (const QString &key)
-{
-    return key;
-}
-
-Q_EXPORT_PLUGIN2 (IBusInputContextPlugin, IBusInputContextPlugin)
diff --git a/x11/IMdkit/FrameMgr.c b/x11/IMdkit/FrameMgr.c
deleted file mode 100644 (file)
index 9b49794..0000000
+++ /dev/null
@@ -1,2466 +0,0 @@
-/******************************************************************
-Copyright 1993, 1994 by Digital Equipment Corporation, Maynard, Massachusetts,
-                        All Rights Reserved
-Permission to use, copy, modify, and distribute this software and its 
-documentation for any purpose and without fee is hereby granted, 
-provided that the above copyright notice appear in all copies and that
-both that copyright notice and this permission notice appear in 
-supporting documentation, and that the names of Digital or MIT not be
-used in advertising or publicity pertaining to distribution of the
-software without specific, written prior permission.  
-DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
-ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
-ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
-WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
-SOFTWARE.
-  Author: Hiroyuki Miyamoto  Digital Equipment Corporation
-                             miyamoto@jrd.dec.com
-
-    This version tidied and debugged by Steve Underwood May 1999
-
-******************************************************************/
-
-#include <X11/Xlibint.h>
-#include <stdlib.h>
-#include "FrameMgr.h"
-
-/* Convenient macro */
-
-#define _UNIT(n)   ((int)(n) & 0xFF)
-#define _NUMBER(n) (((int)(n) >> 8) & 0xFF)
-
-/* For byte swapping */
-
-#define Swap16(p, n) ((p)->byte_swap ?       \
-(((n) << 8 & 0xFF00) | \
- ((n) >> 8 & 0xFF)     \
-) : n)
-#define Swap32(p, n) ((p)->byte_swap ?            \
-        (((n) << 24 & 0xFF000000) | \
-         ((n) <<  8 & 0xFF0000) |   \
-         ((n) >>  8 & 0xFF00) |     \
-         ((n) >> 24 & 0xFF)         \
-        ) : n)
-#define Swap64(p, n) ((p)->byte_swap ?            \
-        (((n) << 56 & 0xFF00000000000000) | \
-         ((n) << 40 & 0xFF000000000000) |   \
-         ((n) << 24 & 0xFF0000000000) |     \
-         ((n) <<  8 & 0xFF00000000) |       \
-         ((n) >>  8 & 0xFF000000) |         \
-         ((n) >> 24 & 0xFF0000) |           \
-         ((n) >> 40 & 0xFF00) |             \
-         ((n) >> 56 & 0xFF)                 \
-        ) : n)
-
-/* Type definition */
-
-typedef struct _Iter *Iter;
-
-typedef struct _FrameInst *FrameInst;
-
-typedef union
-{
-    int num;           /* For BARRAY */
-    FrameInst fi;      /* For POINTER */
-    Iter iter;                 /* For ITER */
-} ExtraDataRec, *ExtraData;
-
-typedef struct _Chain
-{
-    ExtraDataRec d;
-    int frame_no;
-    struct _Chain *next;
-} ChainRec, *Chain;
-
-typedef struct _ChainMgr
-{
-    Chain top;
-    Chain tail;
-} ChainMgrRec, *ChainMgr;
-
-typedef struct _ChainIter
-{
-    Chain cur;
-} ChainIterRec, *ChainIter;
-
-typedef struct _FrameIter
-{
-    Iter iter;
-    Bool counting;
-    unsigned int counter;
-    int end;
-    struct _FrameIter* next;
-} FrameIterRec, *FrameIter;
-
-typedef struct _FrameInst
-{
-    XimFrame template;
-    ChainMgrRec cm;
-    int cur_no;
-} FrameInstRec;
-
-typedef void (*IterStartWatchProc) (Iter it, void *client_data);
-
-typedef struct _Iter
-{
-    XimFrame template;
-    int max_count;
-    Bool allow_expansion;
-    ChainMgrRec cm;
-    int cur_no;
-    IterStartWatchProc start_watch_proc;
-    void *client_data;
-    Bool start_counter;
-} IterRec;
-
-typedef struct _FrameMgr
-{
-    XimFrame frame;
-    FrameInst fi;
-    char *area;
-    int idx;
-    Bool byte_swap;
-    int total_size;
-    FrameIter iters;
-} FrameMgrRec;
-
-typedef union
-{
-    int num;           /* For BARRAY and PAD */
-    struct
-    {          /* For COUNTER_* */
-        Iter iter;
-        Bool is_byte_len;
-    } counter;
-} XimFrameTypeInfoRec, *XimFrameTypeInfo;
-
-/* Special values */
-#define NO_VALUE -1
-#define NO_VALID_FIELD -2
-
-static FrameInst FrameInstInit(XimFrame frame);
-static void FrameInstFree(FrameInst fi);
-static XimFrameType FrameInstGetNextType(FrameInst fi, XimFrameTypeInfo info);
-static XimFrameType FrameInstPeekNextType(FrameInst fi, XimFrameTypeInfo info);
-static FmStatus FrameInstSetSize(FrameInst fi, int num);
-static FmStatus FrameInstSetIterCount(FrameInst fi, int num);
-static int FrameInstGetTotalSize(FrameInst fi);
-static void FrameInstReset(FrameInst fi);
-
-static Iter IterInit(XimFrame frame, int count);
-static void IterFree(Iter it);
-static int FrameInstGetSize(FrameInst fi);
-static int IterGetSize(Iter it);
-static XimFrameType IterGetNextType(Iter it, XimFrameTypeInfo info);
-static XimFrameType IterPeekNextType(Iter it, XimFrameTypeInfo info);
-static FmStatus IterSetSize(Iter it, int num);
-static FmStatus IterSetIterCount(Iter it, int num);
-static int IterGetTotalSize(Iter it);
-static void IterReset(Iter it);
-static Bool IterIsLoopEnd(Iter it, Bool* myself);
-static void IterSetStartWatch(Iter it, IterStartWatchProc proc, void* client_data);
-static void _IterStartWatch(Iter it, void* client_data);
-
-static ExtraData ChainMgrGetExtraData(ChainMgr cm, int frame_no);
-static ExtraData ChainMgrSetData(ChainMgr cm, int frame_no,
-                                 ExtraDataRec data);
-static Bool ChainIterGetNext(ChainIter ci, int* frame_no, ExtraData d);
-static int _FrameInstIncrement(XimFrame frame, int count);
-static int _FrameInstDecrement(XimFrame frame, int count);
-static int _FrameInstGetItemSize(FrameInst fi, int cur_no);
-static Bool FrameInstIsIterLoopEnd(FrameInst fi);
-
-static FrameIter _FrameMgrAppendIter(FrameMgr fm, Iter it, int end);
-static FrameIter _FrameIterCounterIncr(FrameIter fitr, int i);
-static void _FrameMgrRemoveIter(FrameMgr fm, FrameIter it);
-static Bool _FrameMgrIsIterLoopEnd(FrameMgr fm);
-static Bool _FrameMgrProcessPadding(FrameMgr fm, FmStatus* status);
-
-#define IterGetIterCount(it) ((it)->allow_expansion ? \
-NO_VALUE : (it)->max_count)
-
-#define IterFixIteration(it) ((it)->allow_expansion = False)
-
-#define IterSetStarter(it) ((it)->start_counter = True)
-
-#define ChainMgrInit(cm) (cm)->top = (cm)->tail = NULL
-#define ChainMgrFree(cm)                \
-{                                       \
-    Chain tmp;                          \
-    Chain cur = (cm)->top;              \
-                                       \
-    while (cur)                         \
-    {                                   \
-        tmp = cur->next;                \
-        Xfree (cur);                    \
-       cur = tmp;                      \
-    }                                   \
-}
-
-#define ChainIterInit(ci, cm)           \
-{                                       \
-    (ci)->cur = (cm)->top;              \
-}
-
-/* ChainIterFree has nothing to do. */
-#define ChainIterFree(ci)
-
-#define FrameInstIsEnd(fi) ((fi)->template[(fi)->cur_no].type == EOL)
-
-FrameMgr FrameMgrInit (XimFrame frame, char* area, Bool byte_swap)
-{
-    FrameMgr fm;
-
-    fm = (FrameMgr) Xmalloc (sizeof (FrameMgrRec));
-
-    fm->frame = frame;
-    fm->fi = FrameInstInit (frame);
-    fm->area = (char *) area;
-    fm->idx = 0;
-    fm->byte_swap = byte_swap;
-    fm->total_size = NO_VALUE;
-    fm->iters = NULL;
-
-    return fm;
-}
-
-void FrameMgrInitWithData (FrameMgr fm,
-                           XimFrame frame,
-                           void * area,
-                           Bool byte_swap)
-{
-    fm->frame = frame;
-    fm->fi = FrameInstInit (frame);
-    fm->area = (char *) area;
-    fm->idx = 0;
-    fm->byte_swap = byte_swap;
-    fm->total_size = NO_VALUE;
-}
-
-void FrameMgrFree (FrameMgr fm)
-{
-    FrameIter p, cur;
-
-    p = fm->iters;
-    cur = p;
-
-    while (p)
-    {
-        p = p->next;
-        Xfree (cur);
-        cur = p;
-    }
-    /*endwhile*/
-
-    FrameInstFree (fm->fi);
-    Xfree (fm);
-}
-
-FmStatus FrameMgrSetBuffer (FrameMgr fm, void* area)
-{
-    if (fm->area)
-        return FmBufExist;
-    fm->area = (char *) area;
-    return FmSuccess;
-}
-
-FmStatus _FrameMgrPutToken (FrameMgr fm, void *data, int data_size)
-{
-    XimFrameType type;
-    XimFrameTypeInfoRec info;
-
-    if (fm->total_size != NO_VALUE  &&  fm->idx >= fm->total_size)
-        return FmNoMoreData;
-    /*endif*/
-    
-    type = FrameInstGetNextType(fm->fi, &info);
-
-    if (type & COUNTER_MASK)
-    {
-        unsigned long input_length;
-
-        if (info.counter.is_byte_len)
-        {
-            if ((input_length = IterGetTotalSize (info.counter.iter))
-                    == NO_VALUE)
-            {
-                return FmCannotCalc;
-            }
-            /*endif*/
-        }
-        else
-        {
-            if ((input_length = IterGetIterCount (info.counter.iter))
-                == NO_VALUE)
-            {
-                return FmCannotCalc;
-            }
-            /*endif*/
-        }
-        /*endif*/
-        switch (type)
-        {
-        case COUNTER_BIT8:
-            *(CARD8 *) (fm->area + fm->idx) = input_length;
-            fm->idx++;
-            break;
-        
-        case COUNTER_BIT16:
-            *(CARD16 *) (fm->area + fm->idx) = Swap16 (fm, input_length);
-            fm->idx += 2;
-            break;
-            
-        case COUNTER_BIT32:
-            *(CARD32 *) (fm->area + fm->idx) = Swap32 (fm, input_length);
-            fm->idx += 4;
-            break;
-
-#if defined(_NEED64BIT)
-        case COUNTER_BIT64:
-            *(CARD64 *) (fm->area + fm->idx) = Swap64 (fm, input_length);
-            fm->idx += 8;
-            break;
-#endif
-       default:
-           break;
-        }
-        /*endswitch*/
-        _FrameMgrPutToken(fm, data, data_size);
-        return FmSuccess;
-    }
-    /*endif*/
-
-    switch (type)
-    {
-    case BIT8:
-        if (data_size == sizeof (unsigned char))
-        {
-            unsigned long num = *(unsigned char *) data;
-            *(CARD8 *) (fm->area + fm->idx) = num;
-        }
-        else if (data_size == sizeof (unsigned short))
-        {
-            unsigned long num = *(unsigned short *) data;
-            *(CARD8 *) (fm->area + fm->idx) = num;
-        }
-        else if (data_size == sizeof (unsigned int))
-        {
-            unsigned long num = *(unsigned int *) data;
-            *(CARD8 *) (fm->area + fm->idx) = num;
-        }
-        else if (data_size == sizeof (unsigned long))
-        {
-            unsigned long num = *(unsigned long *) data;
-            *(CARD8 *) (fm->area + fm->idx) = num;
-        }
-        else
-        {
-            ; /* Should never be reached */
-        }
-        /*endif*/
-        fm->idx++;
-        return FmSuccess;
-
-    case BIT16:
-        if (data_size == sizeof (unsigned char))
-        {
-            unsigned long num = *(unsigned char *) data;
-            *(CARD16*)(fm->area + fm->idx) = Swap16 (fm, num);
-        }
-        else if (data_size == sizeof (unsigned short))
-        {
-            unsigned long num = *(unsigned short *) data;
-            *(CARD16 *) (fm->area + fm->idx) = Swap16 (fm, num);
-        }
-        else if (data_size == sizeof (unsigned int))
-        {
-            unsigned long num = *(unsigned int *) data;
-            *(CARD16 *) (fm->area + fm->idx) = Swap16 (fm, num);
-        }
-        else if (data_size == sizeof (unsigned long))
-        {
-            unsigned long num = *(unsigned long *) data;
-            *(CARD16 *) (fm->area + fm->idx) = Swap16 (fm, num);
-        }
-        else
-        {
-            ; /* Should never reached */
-        }
-        /*endif*/
-        fm->idx += 2;
-        return FmSuccess;
-
-    case BIT32:
-        if (data_size == sizeof (unsigned char))
-        {
-            unsigned long num = *(unsigned char *) data;
-            *(CARD32 *) (fm->area + fm->idx) = Swap32 (fm, num);
-        }
-        else if (data_size == sizeof (unsigned short))
-        {
-            unsigned long num = *(unsigned short *) data;
-            *(CARD32 *) (fm->area + fm->idx) = Swap32 (fm, num);
-        }
-        else if (data_size == sizeof (unsigned int))
-        {
-            unsigned long num = *(unsigned int *) data;
-            *(CARD32 *) (fm->area + fm->idx) = Swap32 (fm, num);
-        }
-        else if (data_size == sizeof (unsigned long))
-        {
-            unsigned long num = *(unsigned long *) data;
-            *(CARD32 *) (fm->area + fm->idx) = Swap32 (fm, num);
-        }
-        else
-        {
-            ; /* Should never reached */
-        }
-        /*endif*/
-        fm->idx += 4;
-        return FmSuccess;
-
-#if defined(_NEED64BIT)
-    case BIT64:
-        if (data_size == sizeof (unsigned char))
-        {
-            unsigned long num = *(unsigned char *) data;
-            *(CARD64 *) (fm->area + fm->idx) = Swap64 (fm, num);
-        }
-        else if (data_size == sizeof (unsigned short))
-        {
-            unsigned long num = *(unsigned short *) data;
-            *(CARD64 *) (fm->area + fm->idx) = Swap64 (fm, num);
-        }
-        else if (data_size == sizeof (unsigned int))
-        {
-            unsigned long num = *(unsigned int *) data;
-            *(CARD64 *) (fm->area + fm->idx) = Swap64 (fm, num);
-        }
-        else if (data_size == sizeof (unsigned long))
-        {
-            unsigned long num = *(unsigned long *) data;
-            *(CARD64 *) (fm->area + fm->idx) = Swap64 (fm, num);
-        }
-        else
-        {
-            ; /* Should never reached */
-        }
-        /*endif*/
-        fm->idx += 4;
-        return FmSuccess;
-#endif
-
-    case BARRAY:
-        if (info.num == NO_VALUE)
-            return FmInvalidCall;
-        /*endif*/
-        if (info.num > 0)
-        {
-            bcopy (*(char **) data, fm->area + fm->idx, info.num);
-            fm->idx += info.num;
-        }
-        /*endif*/
-        return FmSuccess;
-
-    case PADDING:
-        if (info.num == NO_VALUE)
-            return FmInvalidCall;
-        /*endif*/
-        fm->idx += info.num;
-        return _FrameMgrPutToken(fm, data, data_size);
-
-    case ITER:
-        return FmInvalidCall;
-        
-    case EOL:
-        return FmEOD;
-    default:
-       break;
-    }
-    /*endswitch*/
-    return (FmStatus) NULL;  /* Should never be reached */
-}
-
-FmStatus _FrameMgrGetToken (FrameMgr fm , void* data, int data_size)
-{
-    XimFrameType type;
-    static XimFrameTypeInfoRec info;  /* memory */
-    FrameIter fitr;
-
-    if (fm->total_size != NO_VALUE  &&  fm->idx >= fm->total_size)
-        return FmNoMoreData;
-    /*endif*/
-    
-    type = FrameInstGetNextType(fm->fi, &info);
-
-    if (type & COUNTER_MASK)
-    {
-        int end=0;
-        FrameIter client_data;
-
-        type &= ~COUNTER_MASK;
-        switch (type)
-        {
-        case BIT8:
-            end = *(CARD8 *) (fm->area + fm->idx);
-            break;
-        
-        case BIT16:
-            end = Swap16 (fm, *(CARD16 *) (fm->area + fm->idx));
-            break;
-        
-        case BIT32:
-            end = Swap32 (fm, *(CARD32 *) (fm->area + fm->idx));
-            break;
-
-#if defined(_NEED64BIT)        
-        case BIT64:
-            end = Swap64 (fm, *(CARD64 *) (fm->area + fm->idx));
-            break;
-#endif
-       default:
-           break;
-        }
-        /*endswitch*/
-        
-        if ((client_data = _FrameMgrAppendIter (fm, info.counter.iter, end)))
-        {
-            IterSetStarter (info.counter.iter);
-            IterSetStartWatch (info.counter.iter,
-                               _IterStartWatch,
-                               (void *) client_data);
-        }
-        /*endif*/
-    }
-    /*endif*/
-
-    type &= ~COUNTER_MASK;
-    switch (type)
-    {
-    case BIT8:
-        if (data_size == sizeof (unsigned char))
-        {
-            *(unsigned char*) data = *(CARD8 *) (fm->area + fm->idx);
-        }
-        else if (data_size == sizeof (unsigned short))
-        {
-            *(unsigned short *) data = *(CARD8 *) (fm->area + fm->idx);
-        }
-        else if (data_size == sizeof (unsigned int))
-        {
-            *(unsigned int *) data = *(CARD8 *) (fm->area + fm->idx);
-        }
-        else if (data_size == sizeof (unsigned long))
-        {
-            *(unsigned long *) data = *(CARD8 *) (fm->area + fm->idx);
-        }
-        else
-        {
-            ; /* Should never reached */
-        }
-        /*endif*/
-        fm->idx++;
-        if ((fitr = _FrameIterCounterIncr (fm->iters, 1/*BIT8*/)))
-            _FrameMgrRemoveIter (fm, fitr);
-        /*endif*/
-        return FmSuccess;
-
-    case BIT16:
-        if (data_size == sizeof (unsigned char))
-        {
-            *(unsigned char *) data =
-                Swap16 (fm, *(CARD16 *) (fm->area + fm->idx));
-        }
-        else if (data_size == sizeof (unsigned short))
-        {
-            *(unsigned short *) data =
-                Swap16 (fm, *(CARD16 *) (fm->area + fm->idx));
-        }
-        else if (data_size == sizeof (unsigned int))
-        {
-            *(unsigned int *) data =
-                Swap16 (fm, *(CARD16 *) (fm->area + fm->idx));
-        }
-        else if (data_size == sizeof (unsigned long))
-        {
-            *(unsigned long *) data =
-                Swap16 (fm, *(CARD16 *) (fm->area + fm->idx));
-        }
-        else
-        {
-            ; /* Should never reached */
-        }
-        /*endif*/
-        fm->idx += 2;
-        if ((fitr = _FrameIterCounterIncr (fm->iters, 2/*BIT16*/)))
-            _FrameMgrRemoveIter(fm, fitr);
-        /*endif*/
-        return FmSuccess;
-
-    case BIT32:
-        if (data_size == sizeof (unsigned char))
-        {
-            *(unsigned char *) data =
-                Swap32 (fm, *(CARD32 *) (fm->area + fm->idx));
-        }
-        else if (data_size == sizeof (unsigned short))
-        {
-            *(unsigned short *) data =
-                Swap32 (fm, *(CARD32 *) (fm->area + fm->idx));
-        }
-        else if (data_size == sizeof (unsigned int))
-        {
-            *(unsigned int *) data =
-                Swap32 (fm, *(CARD32 *) (fm->area + fm->idx));
-        }
-        else if (data_size == sizeof (unsigned long))
-        {
-            *(unsigned long *) data =
-                Swap32 (fm, *(CARD32 *) (fm->area + fm->idx));
-        }
-        else
-        {
-            ; /* Should never reached */
-        }
-        /*endif*/
-        fm->idx += 4;
-        if ((fitr = _FrameIterCounterIncr (fm->iters, 4/*BIT32*/)))
-            _FrameMgrRemoveIter (fm, fitr);
-        /*endif*/
-        return FmSuccess;
-
-#if defined(_NEED64BIT)    
-    case BIT64:
-        if (data_size == sizeof (unsigned char))
-        {
-            *(unsigned char *) data =
-                Swap64 (fm, *(CARD64 *) (fm->area + fm->idx));
-        }
-        else if (data_size == sizeof (unsigned short))
-        {
-            *(unsigned short *) data =
-                Swap64 (fm, *(CARD64 *) (fm->area + fm->idx));
-        }
-        else if (data_size == sizeof (unsigned int))
-        {
-            *(unsigned int *) data =
-                Swap64 (fm, *(CARD64 *) (fm->area + fm->idx));
-        }
-        else if (data_size == sizeof (unsigned long))
-        {
-            *(unsigned long *) data =
-                Swap64 (fm, *(CARD64 *) (fm->area + fm->idx));
-        }
-        else
-        {
-            ; /* Should never reached */
-        }
-        /*endif*/
-        fm->idx += 8;
-        if ((fitr = _FrameIterCounterIncr (fm->iters, 8/*BIT64*/)))
-            _FrameMgrRemoveIter (fm, fitr);
-        /*endif*/
-        return FmSuccess;
-#endif
-
-    case BARRAY:
-        if (info.num == NO_VALUE)
-            return FmInvalidCall;
-        /*endif*/
-        if (info.num > 0)
-        {
-            *(char **) data = fm->area + fm->idx;
-            
-            fm->idx += info.num;
-            if ((fitr = _FrameIterCounterIncr (fm->iters, info.num)))
-                _FrameMgrRemoveIter (fm, fitr);
-            /*endif*/
-        }
-        else
-        {
-            *(char **) data = NULL;
-        }
-        /*endif*/
-        return FmSuccess;
-
-    case PADDING:
-        if (info.num == NO_VALUE)
-            return FmInvalidCall;
-        /*endif*/
-        fm->idx += info.num;
-        if ((fitr = _FrameIterCounterIncr (fm->iters, info.num)))
-            _FrameMgrRemoveIter (fm, fitr);
-        /*endif*/
-        return _FrameMgrGetToken (fm, data, data_size);
-
-    case ITER:
-        return FmInvalidCall;  /* if comes here, it's a bug! */
-
-    case EOL:
-        return FmEOD;
-    default:
-       break;
-    }
-    /*endswitch*/
-    return (FmStatus) NULL;  /* Should never be reached */
-}
-
-FmStatus FrameMgrSetSize (FrameMgr fm, int barray_size)
-{
-    if (FrameInstSetSize (fm->fi, barray_size) == FmSuccess)
-        return FmSuccess;
-    /*endif*/
-    return FmNoMoreData;
-}
-
-FmStatus FrameMgrSetIterCount (FrameMgr fm, int count)
-{
-    if (FrameInstSetIterCount (fm->fi, count) == FmSuccess)
-        return FmSuccess;
-    /*endif*/
-    return FmNoMoreData;
-}
-
-FmStatus FrameMgrSetTotalSize (FrameMgr fm, int total_size)
-{
-    fm->total_size = total_size;
-    return FmSuccess;
-}
-
-int FrameMgrGetTotalSize (FrameMgr fm)
-{
-    return FrameInstGetTotalSize (fm->fi);
-}
-
-int FrameMgrGetSize (FrameMgr fm)
-{
-    register int ret_size;
-
-    ret_size = FrameInstGetSize (fm->fi);
-    if (ret_size == NO_VALID_FIELD)
-        return NO_VALUE;
-    /*endif*/
-    return ret_size;
-}
-
-FmStatus FrameMgrSkipToken (FrameMgr fm, int skip_count)
-{
-    XimFrameType type;
-    XimFrameTypeInfoRec info;
-    register int i;
-
-    if (fm->total_size != NO_VALUE  &&  fm->idx >= fm->total_size)
-        return FmNoMoreData;
-    /*endif*/
-    for (i = 0;  i < skip_count;  i++)
-    {
-        type = FrameInstGetNextType (fm->fi, &info);
-        type &= ~COUNTER_MASK;
-
-        switch (type)
-        {
-        case BIT8:
-            fm->idx++;
-            break;
-            
-        case BIT16:
-            fm->idx += 2;
-            break;
-            
-        case BIT32:
-            fm->idx += 4;
-            break;
-            
-        case BIT64:
-            fm->idx += 8;
-            break;
-            
-        case BARRAY:
-            if (info.num == NO_VALUE)
-                return FmInvalidCall;
-            /*endif*/
-            fm->idx += info.num;
-            break;
-            
-        case PADDING:
-            if (info.num == NO_VALUE)
-                return FmInvalidCall;
-            /*endif*/
-            fm->idx += info.num;
-            return FrameMgrSkipToken (fm, skip_count);
-            
-        case ITER:
-            return FmInvalidCall;
-            
-        case EOL:
-            return FmEOD;
-       default:
-           break;
-        }
-        /*endswitch*/
-    }
-    /*endfor*/
-    return FmSuccess;
-}
-
-void FrameMgrReset (FrameMgr fm)
-{
-    fm->idx = 0;
-    FrameInstReset (fm->fi);
-}
-
-Bool FrameMgrIsIterLoopEnd (FrameMgr fm, FmStatus* status)
-{
-    do
-    {
-        if (_FrameMgrIsIterLoopEnd (fm))
-            return  True;
-        /*endif*/
-    }
-    while (_FrameMgrProcessPadding (fm, status));
-
-    return False;
-}
-
-
-/* Internal routines */
-
-static Bool _FrameMgrIsIterLoopEnd (FrameMgr fm)
-{
-    return FrameInstIsIterLoopEnd (fm->fi);
-}
-
-static Bool _FrameMgrProcessPadding (FrameMgr fm, FmStatus* status)
-{
-    XimFrameTypeInfoRec info;
-    XimFrameType next_type = FrameInstPeekNextType (fm->fi, &info);
-    FrameIter fitr;
-
-    if (next_type == PADDING)
-    {
-        if (info.num == NO_VALUE)
-        {
-            *status = FmInvalidCall;
-            return True;
-        }
-        /*endif*/
-        next_type = FrameInstGetNextType (fm->fi, &info);
-        fm->idx += info.num;
-        if ((fitr = _FrameIterCounterIncr (fm->iters, info.num)))
-            _FrameMgrRemoveIter (fm, fitr);
-        /*endif*/
-        *status = FmSuccess;
-        return True;
-    }
-    /*endif*/
-    *status = FmSuccess;
-    return False;
-}
-
-static FrameInst FrameInstInit (XimFrame frame)
-{
-    FrameInst fi;
-
-    fi = (FrameInst) Xmalloc (sizeof (FrameInstRec));
-
-    fi->template = frame;
-    fi->cur_no = 0;
-    ChainMgrInit (&fi->cm);
-    return fi;
-}
-
-static void FrameInstFree (FrameInst fi)
-{
-    ChainIterRec ci;
-    int frame_no;
-    ExtraDataRec d;
-
-    ChainIterInit (&ci, &fi->cm);
-
-    while (ChainIterGetNext (&ci, &frame_no, &d))
-    {
-        register XimFrameType type;
-        type = fi->template[frame_no].type;
-        if (type == ITER)
-        {
-            if (d.iter)
-                IterFree (d.iter);
-            /*endif*/
-        }
-        else if (type == POINTER)
-        {
-            if (d.fi)
-                FrameInstFree (d.fi);
-            /*endif*/
-        }
-        /*endif*/
-    }
-    /*endwhile*/
-    ChainIterFree (&ci);
-    ChainMgrFree (&fi->cm);
-    Xfree (fi);
-}
-
-static XimFrameType FrameInstGetNextType(FrameInst fi, XimFrameTypeInfo info)
-{
-    XimFrameType ret_type;
-
-    ret_type = fi->template[fi->cur_no].type;
-
-    switch (ret_type)
-    {
-    case BIT8:
-    case BIT16:
-    case BIT32:
-    case BIT64:
-    case EOL:
-        fi->cur_no = _FrameInstIncrement(fi->template, fi->cur_no);
-        break;
-
-    case COUNTER_BIT8:
-    case COUNTER_BIT16:
-    case COUNTER_BIT32:
-    case COUNTER_BIT64:
-        if (info)
-        {
-            register int offset, iter_idx;
-
-            info->counter.is_byte_len =
-                (((long) fi->template[fi->cur_no].data & 0xFF)) == FmCounterByte;
-            offset = ((long) fi->template[fi->cur_no].data) >> 8;
-            iter_idx = fi->cur_no + offset;
-            if (fi->template[iter_idx].type == ITER)
-            {
-                ExtraData d;
-                ExtraDataRec dr;
-
-                if ((d = ChainMgrGetExtraData (&fi->cm, iter_idx)) == NULL)
-                {
-                    dr.iter = IterInit (&fi->template[iter_idx + 1], NO_VALUE);
-                    d = ChainMgrSetData (&fi->cm, iter_idx, dr);
-                }
-                /*endif*/
-                info->counter.iter = d->iter;
-            }
-            else
-            {
-                /* Should never reach here */
-            }
-            /*endif*/
-        }
-        /*endif*/
-        fi->cur_no = _FrameInstIncrement (fi->template, fi->cur_no);
-        break;
-
-    case BARRAY:
-        if (info)
-        {
-            ExtraData d;
-
-            if ((d = ChainMgrGetExtraData (&fi->cm, fi->cur_no)) == NULL)
-                info->num = NO_VALUE;
-            else
-                info->num = d->num;
-            /*endif*/
-        }
-        /*endif*/
-        fi->cur_no = _FrameInstIncrement (fi->template, fi->cur_no);
-        break;
-
-    case PADDING:
-        if (info)
-        {
-            register int unit;
-            register int number;
-            register int size;
-            register int i;
-
-            unit = _UNIT ((long) fi->template[fi->cur_no].data);
-            number = _NUMBER ((long) fi->template[fi->cur_no].data);
-
-            i = fi->cur_no;
-            size = 0;
-            while (number > 0)
-            {
-                i = _FrameInstDecrement (fi->template, i);
-                size += _FrameInstGetItemSize (fi, i);
-                number--;
-            }
-            /*endwhile*/
-            info->num = (unit - (size%unit))%unit;
-        }
-        /*endif*/
-        fi->cur_no = _FrameInstIncrement (fi->template, fi->cur_no);
-        break;
-
-    case ITER:
-        {
-            ExtraData d;
-            ExtraDataRec dr;
-            XimFrameType sub_type;
-
-
-            if ((d = ChainMgrGetExtraData (&fi->cm, fi->cur_no)) == NULL)
-            {
-                dr.iter = IterInit (&fi->template[fi->cur_no + 1], NO_VALUE);
-                d = ChainMgrSetData (&fi->cm, fi->cur_no, dr);
-            }
-            /*endif*/
-            sub_type = IterGetNextType (d->iter, info);
-            if (sub_type == EOL)
-            {
-                fi->cur_no = _FrameInstIncrement (fi->template, fi->cur_no);
-                ret_type = FrameInstGetNextType (fi, info);
-            }
-            else
-            {
-                ret_type = sub_type;
-            }
-            /*endif*/
-        }
-        break;
-
-    case POINTER:
-        {
-            ExtraData d;
-            ExtraDataRec dr;
-            XimFrameType sub_type;
-
-            if ((d = ChainMgrGetExtraData (&fi->cm, fi->cur_no)) == NULL)
-            {
-                dr.fi = FrameInstInit (fi->template[fi->cur_no + 1].data);
-                d = ChainMgrSetData (&fi->cm, fi->cur_no, dr);
-            }
-            /*endif*/
-            sub_type = FrameInstGetNextType (d->fi, info);
-            if (sub_type == EOL)
-            {
-                fi->cur_no = _FrameInstIncrement (fi->template, fi->cur_no);
-                ret_type = FrameInstGetNextType (fi, info);
-            }
-            else
-            {
-                ret_type = sub_type;
-            }
-            /*endif*/
-        }
-        break;
-    default:
-       break;
-    }
-    /*endswitch*/
-    return ret_type;
-}
-
-static XimFrameType FrameInstPeekNextType (FrameInst fi, XimFrameTypeInfo info)
-{
-    XimFrameType ret_type;
-
-    ret_type = fi->template[fi->cur_no].type;
-
-    switch (ret_type)
-    {
-    case BIT8:
-    case BIT16:
-    case BIT32:
-    case BIT64:
-    case EOL:
-        break;
-
-    case COUNTER_BIT8:
-    case COUNTER_BIT16:
-    case COUNTER_BIT32:
-    case COUNTER_BIT64:
-        if (info)
-        {
-            register int offset;
-           register int iter_idx;
-
-            info->counter.is_byte_len =
-                (((long) fi->template[fi->cur_no].data) & 0xFF) == FmCounterByte;
-            offset = ((long)fi->template[fi->cur_no].data) >> 8;
-            iter_idx = fi->cur_no + offset;
-            if (fi->template[iter_idx].type == ITER)
-            {
-                ExtraData d;
-                ExtraDataRec dr;
-
-                if ((d = ChainMgrGetExtraData (&fi->cm, iter_idx)) == NULL)
-                {
-                    dr.iter = IterInit (&fi->template[iter_idx + 1], NO_VALUE);
-                    d = ChainMgrSetData (&fi->cm, iter_idx, dr);
-                }
-                /*endif*/
-                info->counter.iter = d->iter;
-            }
-            else
-            {
-                /* Should not be reached here */
-            }
-            /*endif*/
-        }
-        /*endif*/
-        break;
-
-    case BARRAY:
-        if (info)
-        {
-            ExtraData d;
-
-            if ((d = ChainMgrGetExtraData (&fi->cm, fi->cur_no)) == NULL)
-                info->num = NO_VALUE;
-            else
-                info->num = d->num;
-            /*endif*/
-        }
-        /*endif*/
-        break;
-
-    case PADDING:
-        if (info)
-        {
-            register int unit;
-            register int number;
-            register int size;
-            register int i;
-
-            unit = _UNIT ((long) fi->template[fi->cur_no].data);
-            number = _NUMBER ((long) fi->template[fi->cur_no].data);
-
-            i = fi->cur_no;
-            size = 0;
-            while (number > 0)
-            {
-                i = _FrameInstDecrement (fi->template, i);
-                size += _FrameInstGetItemSize (fi, i);
-                number--;
-            }
-            /*endwhile*/
-            info->num = (unit - (size%unit))%unit;
-        }
-        /*endif*/
-        break;
-
-    case ITER:
-        {
-            ExtraData d;
-            ExtraDataRec dr;
-            XimFrameType sub_type;
-
-            if ((d = ChainMgrGetExtraData (&fi->cm, fi->cur_no)) == NULL)
-            {
-                dr.iter = IterInit (&fi->template[fi->cur_no + 1], NO_VALUE);
-                d = ChainMgrSetData (&fi->cm, fi->cur_no, dr);
-            }
-            /*endif*/
-            sub_type = IterPeekNextType (d->iter, info);
-            if (sub_type == EOL)
-                ret_type = FrameInstPeekNextType (fi, info);
-            else
-                ret_type = sub_type;
-            /*endif*/
-        }
-        break;
-
-    case POINTER:
-        {
-            ExtraData d;
-            ExtraDataRec dr;
-            XimFrameType sub_type;
-
-            if ((d = ChainMgrGetExtraData (&fi->cm, fi->cur_no)) == NULL)
-            {
-                dr.fi = FrameInstInit (fi->template[fi->cur_no + 1].data);
-                d = ChainMgrSetData (&fi->cm, fi->cur_no, dr);
-            }
-            /*endif*/
-            sub_type = FrameInstPeekNextType (d->fi, info);
-            if (sub_type == EOL)
-                ret_type = FrameInstPeekNextType (fi, info);
-            else
-                ret_type = sub_type;
-            /*endif*/
-       default:
-           break;
-        }
-        break;
-    }
-    /*endswitch*/
-    return ret_type;
-}
-
-static Bool FrameInstIsIterLoopEnd (FrameInst fi)
-{
-    Bool ret = False;
-
-    if (fi->template[fi->cur_no].type == ITER)
-    {
-        ExtraData d = ChainMgrGetExtraData (&fi->cm, fi->cur_no);
-        Bool yourself;
-
-        if (d)
-        {
-            ret = IterIsLoopEnd (d->iter, &yourself);
-            if (ret  &&  yourself)
-                fi->cur_no = _FrameInstIncrement (fi->template, fi->cur_no);
-            /*endif*/
-        }
-        /*endif*/
-    }
-    /*endif*/
-    return (ret);
-}
-
-static FrameIter _FrameMgrAppendIter (FrameMgr fm, Iter it, int end)
-{
-    FrameIter p = fm->iters;
-
-    while (p  &&  p->next)
-        p = p->next;
-    /*endwhile*/
-    
-    if (!p)
-    {
-        fm->iters =
-        p = (FrameIter) Xmalloc (sizeof (FrameIterRec));
-    }
-    else
-    {
-        p->next = (FrameIter) Xmalloc (sizeof (FrameIterRec));
-        p = p->next;
-    }
-    /*endif*/
-    if (p)
-    {
-        p->iter = it;
-        p->counting = False;
-        p->counter = 0;
-        p->end = end;
-        p->next = NULL;
-    }
-    /*endif*/
-    return (p);
-}
-
-static void _FrameMgrRemoveIter (FrameMgr fm, FrameIter it)
-{
-    FrameIter prev;
-    FrameIter p;
-
-    prev = NULL;
-    p = fm->iters;
-    while (p)
-    {
-        if (p == it)
-        {
-            if (prev)
-                prev->next = p->next;
-            else
-                fm->iters = p->next;
-            /*endif*/
-            Xfree (p);
-            break;
-        }
-        /*endif*/
-        prev = p;
-        p = p->next;
-    }
-    /*endwhile*/
-}
-
-static FrameIter _FrameIterCounterIncr (FrameIter fitr, int i)
-{
-    FrameIter p = fitr;
-
-    while (p)
-    {
-        if (p->counting)
-        {
-            p->counter += i;
-            if (p->counter >= p->end)
-            {
-                IterFixIteration (p->iter);
-                return (p);
-            }
-            /*endif*/
-        }
-        /*endif*/
-        p = p->next;
-    }
-    /*endwhile*/
-    return (NULL);
-}
-
-static void _IterStartWatch (Iter it, void *client_data)
-{
-    FrameIter p = (FrameIter) client_data;
-    p->counting = True;
-}
-
-static FmStatus FrameInstSetSize (FrameInst fi, int num)
-{
-    ExtraData d;
-    ExtraDataRec dr;
-    XimFrameType type;
-    register int i;
-
-    i = 0;
-    while ((type = fi->template[i].type) != EOL)
-    {
-        switch (type)
-        {
-        case BARRAY:
-            if ((d = ChainMgrGetExtraData (&fi->cm, i)) == NULL)
-            {
-                dr.num = -1;
-                d = ChainMgrSetData (&fi->cm, i, dr);
-            }
-            /*endif*/
-            if (d->num == NO_VALUE)
-            {
-                d->num = num;
-                return FmSuccess;
-            }
-            /*endif*/
-            break;
-        case ITER:
-            if ((d = ChainMgrGetExtraData (&fi->cm, i)) == NULL)
-            {
-                dr.iter = IterInit (&fi->template[i + 1], NO_VALUE);
-                d = ChainMgrSetData (&fi->cm, i, dr);
-            }
-            /*endif*/
-            if (IterSetSize (d->iter, num) == FmSuccess)
-                return FmSuccess;
-            /*endif*/
-            break;
-            
-        case POINTER:
-            if ((d = ChainMgrGetExtraData(&fi->cm, i)) == NULL)
-            {
-                dr.fi = FrameInstInit(fi->template[i + 1].data);
-                d = ChainMgrSetData(&fi->cm, i, dr);
-            }
-            /*endif*/
-            if (FrameInstSetSize(d->fi, num) == FmSuccess)
-                return FmSuccess;
-            /*endif*/
-            break;
-       default:
-           break;
-        }
-        /*endswitch*/
-        i = _FrameInstIncrement(fi->template, i);
-    }
-    /*endwhile*/
-    return FmNoMoreData;
-}
-
-static int FrameInstGetSize (FrameInst fi)
-{
-    XimFrameType type;
-    register int i;
-    ExtraData d;
-    ExtraDataRec dr;
-    int ret_size;
-
-    i = fi->cur_no;
-    while ((type = fi->template[i].type) != EOL)
-    {
-        switch (type)
-        {
-        case BARRAY:
-            if ((d = ChainMgrGetExtraData (&fi->cm, i)) == NULL)
-                return NO_VALUE;
-            /*endif*/
-            return d->num;
-
-        case ITER:
-            if ((d = ChainMgrGetExtraData (&fi->cm, i)) == NULL)
-            {
-                dr.iter = IterInit (&fi->template[i + 1], NO_VALUE);
-                d = ChainMgrSetData (&fi->cm, i, dr);
-            }
-            /*endif*/
-            ret_size = IterGetSize(d->iter);
-            if (ret_size != NO_VALID_FIELD)
-                return ret_size;
-            /*endif*/
-            break;
-            
-        case POINTER:
-            if ((d = ChainMgrGetExtraData (&fi->cm, i)) == NULL)
-            {
-                dr.fi = FrameInstInit (fi->template[i + 1].data);
-                d = ChainMgrSetData (&fi->cm, i, dr);
-            }
-            /*endif*/
-            ret_size = FrameInstGetSize (d->fi);
-            if (ret_size != NO_VALID_FIELD)
-                return ret_size;
-            /*endif*/
-            break;
-       default:
-           break;
-        }
-        /*endswitch*/
-        i = _FrameInstIncrement (fi->template, i);
-    }
-    /*endwhile*/
-    return NO_VALID_FIELD;
-}
-
-static FmStatus FrameInstSetIterCount (FrameInst fi, int num)
-{
-    ExtraData d;
-    ExtraDataRec dr;
-    register int i;
-    XimFrameType type;
-
-    i = 0;
-    while ((type = fi->template[i].type) != EOL)
-    {
-        switch (type)
-        {
-        case ITER:
-            if ((d = ChainMgrGetExtraData (&fi->cm, i)) == NULL)
-            {
-                dr.iter = IterInit (&fi->template[i + 1], num);
-                (void)ChainMgrSetData (&fi->cm, i, dr);
-                return FmSuccess;
-            }
-            /*endif*/
-            if (IterSetIterCount (d->iter, num) == FmSuccess)
-                return FmSuccess;
-            /*endif*/
-            break;
-            
-        case POINTER:
-            if ((d = ChainMgrGetExtraData (&fi->cm, i)) == NULL)
-            {
-                dr.fi = FrameInstInit (fi->template[i + 1].data);
-                d = ChainMgrSetData (&fi->cm, i, dr);
-            }
-            /*endif*/
-            if (FrameInstSetIterCount (d->fi, num) == FmSuccess)
-                return FmSuccess;
-            /*endif*/
-            break;
-
-       default:
-           break;
-        }
-        /*endswitch*/
-        i = _FrameInstIncrement (fi->template, i);
-    }
-    /*endwhile*/
-    return FmNoMoreData;
-}
-
-static int FrameInstGetTotalSize (FrameInst fi)
-{
-    register int size;
-    register int i;
-
-    size = 0;
-    i = 0;
-
-    while (fi->template[i].type != EOL)
-    {
-        size += _FrameInstGetItemSize (fi, i);
-        i = _FrameInstIncrement (fi->template, i);
-    }
-    /*endwhile*/
-    return size;
-}
-
-static void FrameInstReset (FrameInst fi)
-{
-    ChainIterRec ci;
-    int frame_no;
-    ExtraDataRec d;
-
-    ChainIterInit (&ci, &fi->cm);
-
-    while (ChainIterGetNext (&ci, &frame_no, &d))
-    {
-        register XimFrameType type;
-        type = fi->template[frame_no].type;
-        if (type == ITER)
-        {
-            if (d.iter)
-                IterReset (d.iter);
-            /*endif*/
-        }
-        else if (type == POINTER)
-        {
-            if (d.fi)
-                FrameInstReset (d.fi);
-            /*endif*/
-        }
-        /*endif*/
-    }
-    /*endwhile*/
-    ChainIterFree (&ci);
-
-    fi->cur_no = 0;
-}
-
-static Iter IterInit (XimFrame frame, int count)
-{
-    Iter it;
-    register XimFrameType type;
-
-    it = (Iter) Xmalloc (sizeof (IterRec));
-    it->template = frame;
-    it->max_count = (count == NO_VALUE)  ?  0  :  count;
-    it->allow_expansion = (count == NO_VALUE);
-    it->cur_no = 0;
-    it->start_watch_proc = NULL;
-    it->client_data = NULL;
-    it->start_counter = False;
-
-    type = frame->type;
-    if (type & COUNTER_MASK)
-    {
-        /* COUNTER_XXX cannot be an item of a ITER */
-        Xfree (it);
-        return NULL;
-    }
-    /*endif*/
-
-    switch (type)
-    {
-    case BIT8:
-    case BIT16:
-    case BIT32:
-    case BIT64:
-        /* Do nothing */
-        break;
-        
-    case BARRAY:
-    case ITER:
-    case POINTER:
-        ChainMgrInit (&it->cm);
-        break;
-        
-    default:
-        Xfree (it);
-        return NULL; /* This should never occur */
-    }
-    /*endswitch*/
-    return it;
-}
-
-static void IterFree (Iter it)
-{
-    switch (it->template->type)
-    {
-    case BARRAY:
-        ChainMgrFree (&it->cm);
-        break;
-    
-    case ITER:
-        {
-            ChainIterRec ci;
-            int count;
-            ExtraDataRec d;
-
-            ChainIterInit (&ci, &it->cm);
-            while (ChainIterGetNext (&ci, &count, &d))
-                IterFree (d.iter);
-            /*endwhile*/
-            ChainIterFree (&ci);
-            ChainMgrFree (&it->cm);
-        }
-        break;
-    
-    case POINTER:
-        {
-            ChainIterRec ci;
-            int count;
-            ExtraDataRec dr;
-    
-            ChainIterInit (&ci, &it->cm);
-            while (ChainIterGetNext (&ci, &count, &dr))
-                FrameInstFree (dr.fi);
-            /*endwhile*/
-            ChainIterFree (&ci);
-            ChainMgrFree (&it->cm);
-        }
-        break;
-
-    default:
-       break;
-    }
-    /*endswitch*/
-    Xfree (it);
-}
-
-static Bool IterIsLoopEnd (Iter it, Bool *myself)
-{
-    Bool ret = False;
-    *myself = False;
-
-    if (!it->allow_expansion  &&  (it->cur_no == it->max_count))
-    {
-        *myself = True;
-        return True;
-    }
-    /*endif*/
-    
-    if (it->template->type == POINTER)
-    {
-        ExtraData d = ChainMgrGetExtraData (&it->cm, it->cur_no);
-        if (d)
-        {
-            if (FrameInstIsIterLoopEnd (d->fi))
-            {
-                ret = True;
-            }
-            else
-            {
-                if (FrameInstIsEnd (d->fi))
-                {
-                    it->cur_no++;
-                    if (!it->allow_expansion  &&  it->cur_no == it->max_count)
-                    {
-                        *myself = True;
-                        ret = True;
-                    }
-                    /*endif*/
-                }
-                /*endif*/
-            }
-            /*endif*/
-        }
-        /*endif*/
-    }
-    else if (it->template->type == ITER)
-    {
-        ExtraData d = ChainMgrGetExtraData (&it->cm, it->cur_no);
-        if (d)
-        {
-            Bool yourself;
-            
-            if (IterIsLoopEnd (d->iter, &yourself))
-                ret = True;
-            /*endif*/
-        }
-        /*endif*/
-    }
-    /*endif*/
-
-    return ret;
-}
-
-static XimFrameType IterGetNextType (Iter it, XimFrameTypeInfo info)
-{
-    XimFrameType type = it->template->type;
-
-    if (it->start_counter)
-    {
-        (*it->start_watch_proc) (it, it->client_data);
-        it->start_counter = False;
-    }
-    /*endif*/
-    if (it->cur_no >= it->max_count)
-    {
-        if (it->allow_expansion)
-            it->max_count = it->cur_no + 1;
-        else
-            return EOL;
-        /*endif*/
-    }
-    /*endif*/
-
-    switch (type)
-    {
-    case BIT8:
-    case BIT16:
-    case BIT32:
-    case BIT64:
-        it->cur_no++;
-        return type;
-
-    case BARRAY:
-        if (info)
-        {
-            ExtraData d;
-    
-            if ((d = ChainMgrGetExtraData (&it->cm, it->cur_no)) == NULL)
-                info->num = NO_VALUE;
-            else
-                info->num = d->num;
-            /*endif*/
-        }
-        /*endif*/
-        it->cur_no++;
-        return BARRAY;
-
-    case ITER:
-        {
-            XimFrameType ret_type;
-            ExtraData d;
-            ExtraDataRec dr;
-
-            if ((d = ChainMgrGetExtraData (&it->cm, it->cur_no)) == NULL)
-            {
-                dr.iter = IterInit (it->template + 1, NO_VALUE);
-                d = ChainMgrSetData (&it->cm, it->cur_no, dr);
-            }
-            /*endif*/
-
-            ret_type = IterGetNextType (d->iter, info);
-            if (ret_type == EOL)
-            {
-                it->cur_no++;
-                ret_type = IterGetNextType (it, info);
-            }
-            /*endif*/
-           return ret_type;
-        }
-
-    case POINTER:
-        {
-            XimFrameType ret_type;
-            ExtraData d;
-            ExtraDataRec dr;
-
-            if ((d = ChainMgrGetExtraData (&it->cm, it->cur_no)) == NULL)
-            {
-                dr.fi = FrameInstInit (it->template[1].data);
-                d = ChainMgrSetData (&it->cm, it->cur_no, dr);
-            }
-            /*endif*/
-
-            ret_type = FrameInstGetNextType (d->fi, info);
-            if (ret_type == EOL)
-            {
-                it->cur_no++;
-                ret_type = IterGetNextType (it, info);
-            }
-            /*endif*/
-           return ret_type;
-        }
-
-    default:
-       return (XimFrameType) NULL;
-    }
-    /*endswitch*/
-    return (XimFrameType) NULL;  /* This should never occur */
-}
-
-static XimFrameType IterPeekNextType (Iter it, XimFrameTypeInfo info)
-{
-    XimFrameType type = it->template->type;
-
-    if (!it->allow_expansion  &&  it->cur_no >= it->max_count)
-        return (EOL);
-    /*endif*/
-    
-    switch (type)
-    {
-    case BIT8:
-    case BIT16:
-    case BIT32:
-    case BIT64:
-        return type;
-
-    case BARRAY:
-        if (info)
-        {
-            ExtraData d;
-
-            if ((d = ChainMgrGetExtraData (&it->cm, it->cur_no)) == NULL)
-                info->num = NO_VALUE;
-            else
-                info->num = d->num;
-            /*endif*/
-        }
-        /*endif*/
-        return BARRAY;
-    
-    case ITER:
-        {
-            XimFrameType ret_type;
-            ExtraData d;
-            ExtraDataRec dr;
-
-            if ((d = ChainMgrGetExtraData (&it->cm, it->cur_no)) == NULL)
-            {
-                dr.iter = IterInit (it->template + 1, NO_VALUE);
-                d = ChainMgrSetData (&it->cm, it->cur_no, dr);
-            }
-            /*endif*/
-
-            ret_type = IterPeekNextType (d->iter, info);
-            if (ret_type == EOL)
-                ret_type = IterPeekNextType (it, info);
-            /*endif*/
-            return ret_type;
-        }
-        
-    case POINTER:
-        {
-            XimFrameType ret_type;
-            ExtraData d;
-            ExtraDataRec dr;
-
-            if ((d = ChainMgrGetExtraData (&it->cm, it->cur_no)) == NULL)
-            {
-                dr.fi = FrameInstInit (it->template[1].data);
-                d = ChainMgrSetData (&it->cm, it->cur_no, dr);
-            }
-            /*endif*/
-
-            ret_type = FrameInstPeekNextType (d->fi, info);
-            if (ret_type == EOL)
-                ret_type = IterPeekNextType (it, info);
-            /*endif*/
-            return (ret_type);
-        }
-
-    default:
-       break;
-    }
-    /*endswitch*/
-    /* Reaching here is a bug! */
-    return (XimFrameType) NULL;
-}
-
-static FmStatus IterSetSize (Iter it, int num)
-{
-    XimFrameType type;
-    register int i;
-
-    if (!it->allow_expansion  &&  it->max_count == 0)
-        return FmNoMoreData;
-    /*endif*/
-    
-    type = it->template->type;
-    switch (type)
-    {
-    case BARRAY:
-        {
-            ExtraData d;
-            ExtraDataRec dr;
-
-            for (i = 0;  i < it->max_count;  i++)
-            {
-                if ((d = ChainMgrGetExtraData (&it->cm, i)) == NULL)
-                {
-                    dr.num = NO_VALUE;
-                    d = ChainMgrSetData (&it->cm, i, dr);
-                }
-                /*endif*/
-                if (d->num == NO_VALUE)
-                {
-                    d->num = num;
-                    return FmSuccess;
-                }
-                /*endif*/
-            }
-            /*endfor*/
-            if (it->allow_expansion)
-            {
-                ExtraDataRec dr;
-                
-                dr.num = num;
-                ChainMgrSetData (&it->cm, it->max_count, dr);
-                it->max_count++;
-    
-                return FmSuccess;
-            }
-            /*endif*/
-        }   
-        return FmNoMoreData;
-
-    case ITER:
-        {
-            ExtraData d;
-            ExtraDataRec dr;
-
-            for (i = 0;  i < it->max_count;  i++)
-            {
-                if ((d = ChainMgrGetExtraData (&it->cm, i)) == NULL)
-                {
-                    dr.iter = IterInit (it->template + 1, NO_VALUE);
-                    d = ChainMgrSetData (&it->cm, i, dr);
-                }
-                /*endif*/
-                if (IterSetSize (d->iter, num) == FmSuccess)
-                    return FmSuccess;
-                /*endif*/
-            }
-            /*endfor*/
-            if (it->allow_expansion)
-            {
-                ExtraDataRec dr;
-
-                dr.iter = IterInit (it->template + 1, NO_VALUE);
-                ChainMgrSetData (&it->cm, it->max_count, dr);
-                it->max_count++;
-
-                if (IterSetSize(dr.iter, num) == FmSuccess)
-                    return FmSuccess;
-                /*endif*/
-            }
-            /*endif*/
-        }
-        return FmNoMoreData;
-
-    case POINTER:
-        {
-            ExtraData d;
-            ExtraDataRec dr;
-
-            for (i = 0;  i < it->max_count;  i++)
-            {
-                if ((d = ChainMgrGetExtraData (&it->cm, i)) == NULL)
-                {
-                    dr.fi = FrameInstInit (it->template[1].data);
-                    d = ChainMgrSetData (&it->cm, i, dr);
-                }
-                /*endif*/
-                if (FrameInstSetSize (d->fi, num) == FmSuccess)
-                    return FmSuccess;
-                /*endif*/
-            }
-            /*endfor*/
-            if (it->allow_expansion)
-            {
-                ExtraDataRec dr;
-
-                dr.fi = FrameInstInit (it->template[1].data);
-                ChainMgrSetData (&it->cm, it->max_count, dr);
-                it->max_count++;
-
-                if (FrameInstSetSize (dr.fi, num) == FmSuccess)
-                    return FmSuccess;
-                /*endif*/
-            }
-            /*endif*/
-        }
-        return FmNoMoreData;
-
-    default:
-       break;
-    }
-    /*endswitch*/
-    return FmNoMoreData;
-}
-
-static int IterGetSize (Iter it)
-{
-    register int i;
-    ExtraData d;
-    ExtraDataRec dr;
-
-    if (it->cur_no >= it->max_count)
-        return NO_VALID_FIELD;
-    /*endif*/
-    
-    switch (it->template->type)
-    {
-    case BARRAY:
-        if ((d = ChainMgrGetExtraData (&it->cm, it->cur_no)) == NULL)
-            return NO_VALUE;
-        /*endif*/
-        return d->num;
-
-    case ITER:
-        for (i = it->cur_no; i < it->max_count; i++)
-        {
-            int ret_size;
-
-            if ((d = ChainMgrGetExtraData (&it->cm, i)) == NULL)
-            {
-                dr.iter = IterInit (it->template + 1, NO_VALUE);
-                d = ChainMgrSetData (&it->cm, i, dr);
-            }
-            /*endif*/
-            ret_size = IterGetSize (d->iter);
-            if (ret_size != NO_VALID_FIELD)
-                return ret_size;
-            /*endif*/
-        }
-        /*endfor*/
-        return NO_VALID_FIELD;
-    
-    case POINTER:
-        for (i = it->cur_no;  i < it->max_count;  i++)
-        {
-            int ret_size;
-            
-            if ((d = ChainMgrGetExtraData (&it->cm, i)) == NULL)
-            {
-                dr.fi = FrameInstInit (it->template[1].data);
-                d = ChainMgrSetData (&it->cm, i, dr);
-            }
-            /*endif*/
-            ret_size = FrameInstGetSize (d->fi);
-            if (ret_size != NO_VALID_FIELD)
-                return ret_size;
-            /*endif*/
-        }
-        /*endfor*/
-        return NO_VALID_FIELD;
-
-    default:
-       break;
-    }
-    /*endswitch*/
-    return NO_VALID_FIELD;
-}
-
-static FmStatus IterSetIterCount (Iter it, int num)
-{
-    register int i;
-
-    if (it->allow_expansion)
-    {
-        it->max_count = num;
-        it->allow_expansion = False;
-        return FmSuccess;
-    }
-    /*endif*/
-
-    if (it->max_count == 0)
-        return FmNoMoreData;
-    /*endif*/
-
-    switch (it->template->type)
-    {
-    case ITER:
-        for (i = 0;  i < it->max_count;  i++)
-        {
-            ExtraData d;
-            ExtraDataRec dr;
-
-            if ((d = ChainMgrGetExtraData(&it->cm, i)) == NULL)
-            {
-                dr.iter = IterInit(it->template + 1, num);
-                (void)ChainMgrSetData(&it->cm, i, dr);
-                return FmSuccess;
-            }
-            /*endif*/
-            if (IterSetIterCount(d->iter, num) == FmSuccess)
-                return FmSuccess;
-            /*endif*/
-        }
-        /*endfor*/
-        if (it->allow_expansion)
-        {
-            ExtraDataRec dr;
-
-            dr.iter = IterInit (it->template + 1, num);
-            ChainMgrSetData (&it->cm, it->max_count, dr);
-            it->max_count++;
-
-            return FmSuccess;
-        }
-        /*endif*/
-        break;
-    
-    case POINTER:
-        for (i = 0;  i < it->max_count;  i++)
-        {
-            ExtraData d;
-            ExtraDataRec dr;
-            
-            if ((d = ChainMgrGetExtraData (&it->cm, i)) == NULL)
-            {
-                dr.fi = FrameInstInit (it->template[1].data);
-                d = ChainMgrSetData (&it->cm, i, dr);
-            }
-            /*endif*/
-            if (FrameInstSetIterCount (d->fi, num) == FmSuccess)
-                return FmSuccess;
-            /*endif*/
-        }
-        /*endfor*/
-        if (it->allow_expansion)
-        {
-            ExtraDataRec dr;
-            
-            dr.fi = FrameInstInit (it->template[1].data);
-            ChainMgrSetData (&it->cm, it->max_count, dr);
-            it->max_count++;
-
-            if (FrameInstSetIterCount (dr.fi, num) == FmSuccess)
-                return FmSuccess;
-            /*endif*/
-        }
-        /*endif*/
-        break;
-
-    default:
-       break;
-    }
-    /*endswitch*/
-    return FmNoMoreData;
-}
-
-static int IterGetTotalSize (Iter it)
-{
-    register int size, i;
-    XimFrameType type;
-
-    if (it->allow_expansion)
-        return NO_VALUE;
-    /*endif*/
-    if (it->max_count == 0)
-        return 0;
-    /*endif*/
-
-    size = 0;
-    type = it->template->type;
-
-    switch (type)
-    {
-    case BIT8:
-        size = it->max_count;
-        break;
-
-    case BIT16:
-        size = it->max_count*2;
-        break;
-
-    case BIT32:
-        size = it->max_count*4;
-        break;
-
-    case BIT64:
-        size = it->max_count*8;
-        break;
-
-    case BARRAY:
-        for (i = 0;  i < it->max_count;  i++)
-        {
-            register int num;
-            ExtraData d;
-            
-            if ((d = ChainMgrGetExtraData (&it->cm, i)) == NULL)
-                return  NO_VALUE;
-            /*endif*/
-            if ((num = d->num) == NO_VALUE)
-                return  NO_VALUE;
-            /*endif*/
-            size += num;
-        }
-        /*endfor*/
-        break;
-        
-    case ITER:
-        for (i = 0;  i < it->max_count;  i++)
-        {
-            register int num;
-            ExtraData d;
-            
-            if ((d = ChainMgrGetExtraData (&it->cm, i)) == NULL)
-                return  NO_VALUE;
-            /*endif*/
-            if ((num = IterGetTotalSize (d->iter)) == NO_VALUE)
-                return  NO_VALUE;
-            /*endif*/
-            size += num;
-        }
-        /*endfor*/
-        break;
-        
-    case POINTER:
-        for (i = 0;  i < it->max_count;  i++)
-        {
-            register int num;
-            ExtraData d;
-            ExtraDataRec dr;
-            
-            if ((d = ChainMgrGetExtraData (&it->cm, i)) == NULL)
-            {
-                dr.fi = FrameInstInit (it->template[1].data);
-                d = ChainMgrSetData (&it->cm, i, dr);
-            }
-            /*endif*/
-            if ((num = FrameInstGetTotalSize (d->fi)) == NO_VALUE)
-                return NO_VALUE;
-            /*endif*/
-            size += num;
-        }
-        /*endfor*/
-        break;
-
-    default:
-       break;
-    }
-    /*endswitch*/
-    return  size;
-}
-
-static void IterReset (Iter it)
-{
-    ChainIterRec ci;
-    int count;
-    ExtraDataRec d;
-
-    switch (it->template->type)
-    {
-    case ITER:
-        ChainIterInit (&ci, &it->cm);
-        while (ChainIterGetNext (&ci, &count, &d))
-            IterReset (d.iter);
-        /*endwhile*/
-        ChainIterFree (&ci);
-        break;
-  
-    case POINTER:
-        ChainIterInit (&ci, &it->cm);
-        while (ChainIterGetNext (&ci, &count, &d))
-            FrameInstReset (d.fi);
-        /*endwhile*/
-        ChainIterFree (&ci);
-        break;
-
-    default:
-       break;
-    }
-    /*endswitch*/
-    it->cur_no = 0;
-}
-
-static void IterSetStartWatch (Iter it,
-                               IterStartWatchProc proc,
-                               void *client_data)
-{
-    it->start_watch_proc = proc;
-    it->client_data = client_data;
-}
-
-static ExtraData ChainMgrSetData (ChainMgr cm,
-                                  int frame_no,
-                                  ExtraDataRec data)
-{
-    Chain cur = (Chain) Xmalloc (sizeof (ChainRec));
-
-    cur->frame_no = frame_no;
-    cur->d = data;
-    cur->next = NULL;
-
-    if (cm->top == NULL)
-    {
-        cm->top = cm->tail = cur;
-    }
-    else
-    {
-        cm->tail->next = cur;
-        cm->tail = cur;
-    }
-    /*endif*/
-    return &cur->d;
-}
-
-static ExtraData ChainMgrGetExtraData (ChainMgr cm, int frame_no)
-{
-    Chain cur;
-
-    cur = cm->top;
-
-    while (cur)
-    {
-        if (cur->frame_no == frame_no)
-            return &cur->d;
-        /*endif*/
-        cur = cur->next;
-    }
-    /*endwhile*/
-    return NULL;
-}
-
-static Bool ChainIterGetNext (ChainIter ci, int *frame_no, ExtraData d)
-{
-    if (ci->cur == NULL)
-        return False;
-    /*endif*/
-    
-    *frame_no = ci->cur->frame_no;
-    *d = ci->cur->d;
-
-    ci->cur = ci->cur->next;
-
-    return True;
-}
-
-static int _FrameInstIncrement (XimFrame frame, int count)
-{
-    XimFrameType type;
-
-    type = frame[count].type;
-    type &= ~COUNTER_MASK;
-
-    switch (type)
-    {
-    case BIT8:
-    case BIT16:
-    case BIT32:
-    case BIT64:
-    case BARRAY:
-    case PADDING:
-        return count + 1;
-        
-    case POINTER:
-        return count + 2;
-        
-    case ITER:
-        return _FrameInstIncrement (frame, count + 1);
-    default:
-       break;
-    }
-    /*endswitch*/
-    return - 1;    /* Error */
-}
-
-static int _FrameInstDecrement (XimFrame frame, int count)
-{
-    register int i;
-    XimFrameType type;
-
-    if (count == 0)
-        return - 1;    /* cannot decrement */
-    /*endif*/
-    
-    if (count == 1)
-        return 0;     /* BOGUS - It should check the contents of data */
-    /*endif*/
-    
-    type = frame[count - 2].type;
-    type &= ~COUNTER_MASK;
-
-    switch (type)
-    {
-    case BIT8:
-    case BIT16:
-    case BIT32:
-    case BIT64:
-    case BARRAY:
-    case PADDING:
-    case PTR_ITEM:
-        return count - 1;
-
-    case POINTER:
-    case ITER:
-        i = count - 3;
-        while (i >= 0)
-        {
-            if (frame[i].type != ITER)
-                return i + 1;
-            /*endif*/
-            i--;
-        }
-        /*endwhile*/
-        return 0;
-    default:
-       break;
-    }
-    /*enswitch*/
-    return - 1;    /* Error */
-}
-
-static int _FrameInstGetItemSize (FrameInst fi, int cur_no)
-{
-    XimFrameType type;
-
-    type = fi->template[cur_no].type;
-    type &= ~COUNTER_MASK;
-
-    switch (type)
-    {
-    case BIT8:
-        return 1;
-
-    case BIT16:
-        return 2;
-
-    case BIT32:
-        return 4;
-
-    case BIT64:
-        return 8;
-
-    case BARRAY:
-        {
-            ExtraData d;
-
-            if ((d = ChainMgrGetExtraData (&fi->cm, cur_no)) == NULL)
-                return NO_VALUE;
-            /*endif*/
-            if (d->num == NO_VALUE)
-                return NO_VALUE;
-            /*endif*/
-            return d->num;
-        }
-
-    case PADDING:
-        {
-            register int unit;
-            register int number;
-            register int size;
-            register int i;
-
-            unit = _UNIT ((long) fi->template[cur_no].data);
-            number = _NUMBER ((long) fi->template[cur_no].data);
-
-            i = cur_no;
-            size = 0;
-            while (number > 0)
-            {
-                i = _FrameInstDecrement (fi->template, i);
-                size += _FrameInstGetItemSize (fi, i);
-                number--;
-            }
-            /*endwhile*/
-            size = (unit - (size%unit))%unit;
-            return size;
-        }
-
-    case ITER:
-        {
-            ExtraData d;
-            int sub_size;
-
-            if ((d = ChainMgrGetExtraData (&fi->cm, cur_no)) == NULL)
-                return NO_VALUE;
-            /*endif*/
-            sub_size = IterGetTotalSize (d->iter);
-            if (sub_size == NO_VALUE)
-                return NO_VALUE;
-            /*endif*/
-            return sub_size;
-        }
-
-    case POINTER:
-        {
-            ExtraData d;
-            int sub_size;
-
-            if ((d = ChainMgrGetExtraData (&fi->cm, cur_no)) == NULL)
-                return NO_VALUE;
-            /*endif*/
-            sub_size = FrameInstGetTotalSize (d->fi);
-            if (sub_size == NO_VALUE)
-                return NO_VALUE;
-            /*endif*/
-            return sub_size;
-        }
-
-    default:
-       break;
-    }
-    /*endswitch*/
-    return NO_VALUE;
-}
diff --git a/x11/IMdkit/FrameMgr.h b/x11/IMdkit/FrameMgr.h
deleted file mode 100644 (file)
index ce7ed50..0000000
+++ /dev/null
@@ -1,131 +0,0 @@
-/******************************************************************
-Copyright 1993, 1994 by Digital Equipment Corporation, Maynard, Massachusetts,
-
-                        All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and its 
-documentation for any purpose and without fee is hereby granted, 
-provided that the above copyright notice appear in all copies and that
-both that copyright notice and this permission notice appear in 
-supporting documentation, and that the names of Digital or MIT not be
-used in advertising or publicity pertaining to distribution of the
-software without specific, written prior permission.  
-
-DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
-ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
-ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
-WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
-SOFTWARE.
-
-  Author: Hiroyuki Miyamoto  Digital Equipment Corporation
-                             miyamoto@jrd.dec.com
-
-    This version tidied and debugged by Steve Underwood May 1999
-
-******************************************************************/
-
-#ifndef FRAMEMGR_H
-#define FRAMEMGR_H
-
-#include <X11/Xmd.h>
-#include <X11/Xlib.h>
-#include <stdio.h>
-
-#if defined(VAXC) && !defined(__DECC)
-#define xim_externalref globalref
-#define xim_externaldef globaldef
-#else
-#define xim_externalref extern
-#define xim_externaldef
-#endif
-
-/* Definitions for FrameMgr */
-
-#define COUNTER_MASK 0x10
-
-typedef enum
-{
-    BIT8     = 0x1,       /* {CARD8* | INT8*}   */
-    BIT16    = 0x2,       /* {CARD16* | INT16*} */
-    BIT32    = 0x3,       /* {CARD32* | INT32*} */
-    BIT64    = 0x4,      /* {CARD64* | INT64*} */
-    BARRAY   = 0x5,       /* int*, void*        */
-    ITER     = 0x6,       /* int*               */
-    POINTER  = 0x7,       /* specifies next item is a PTR_ITEM */
-    PTR_ITEM = 0x8,       /* specifies the item has a pointer */
-    /* BOGUS - POINTER and PTR_ITEM
-     *   In the current implementation, PTR_ITEM should be lead by
-     *   POINTER.  But actually, it's just redundant logically.  Someone 
-     *   may remove this redundancy and POINTER from the enum member but he
-     *   should also modify the logic in FrameMgr program.
-     */
-    PADDING  = 0x9,       /* specifies that a padding is needed.
-                          * This requires extra data in data field.
-                          */
-    EOL      = 0xA,       /* specifies the end of list */
-
-    COUNTER_BIT8  = COUNTER_MASK | 0x1,
-    COUNTER_BIT16 = COUNTER_MASK | 0x2,
-    COUNTER_BIT32 = COUNTER_MASK | 0x3,
-    COUNTER_BIT64 = COUNTER_MASK | 0x4
-} XimFrameType;
-
-/* Convenient macro */
-#define _FRAME(a) {a, NULL}
-#define _PTR(p)   {PTR_ITEM, (void *)p}
-/* PADDING's usage of data field
- * B15-B8  : Shows the number of effective items.
- * B7-B0   : Shows padding unit.  ex) 04 shows 4 unit padding.
- */
-#define _PAD2(n)   {PADDING, (void*)((n)<<8|2)}
-#define _PAD4(n)   {PADDING, (void*)((n)<<8|4)}
-
-#define FmCounterByte 0
-#define FmCounterNumber 1
-    
-#define _BYTE_COUNTER(type, offset) \
-               {(COUNTER_MASK|type), (void*)((offset)<<8|FmCounterByte)}
-
-#define _NUMBER_COUNTER(type, offset) \
-               {(COUNTER_MASK|type), (void*)((offset)<<8|FmCounterNumber)}
-
-typedef struct _XimFrame
-{
-    XimFrameType type;
-    void* data;       /* For PTR_ITEM and PADDING */
-} XimFrameRec, *XimFrame;
-
-typedef enum
-{
-    FmSuccess, 
-    FmEOD,
-    FmInvalidCall,
-    FmBufExist,
-    FmCannotCalc,
-    FmNoMoreData
-} FmStatus;
-
-typedef struct _FrameMgr *FrameMgr;
-
-FrameMgr FrameMgrInit(XimFrame frame, char* area, Bool byte_swap);
-void FrameMgrInitWithData(FrameMgr fm, XimFrame frame, void* area,
-                         Bool byte_swap);
-void FrameMgrFree(FrameMgr fm);
-FmStatus FrameMgrSetBuffer(FrameMgr, void*);
-FmStatus _FrameMgrPutToken(FrameMgr, void*, int);
-FmStatus _FrameMgrGetToken(FrameMgr, void*, int);
-FmStatus FrameMgrSetSize(FrameMgr, int);
-FmStatus FrameMgrSetIterCount(FrameMgr, int);
-FmStatus FrameMgrSetTotalSize(FrameMgr, int);
-int FrameMgrGetTotalSize(FrameMgr);
-int FrameMgrGetSize(FrameMgr);
-FmStatus FrameMgrSkipToken(FrameMgr, int);
-void FrameMgrReset(FrameMgr);
-Bool FrameMgrIsIterLoopEnd(FrameMgr, FmStatus*);
-
-#define FrameMgrPutToken(fm, obj) _FrameMgrPutToken((fm), &(obj), sizeof(obj))
-#define FrameMgrGetToken(fm, obj) _FrameMgrGetToken((fm), &(obj), sizeof(obj))
-
-#endif /* FRAMEMGR_H */
diff --git a/x11/IMdkit/IMConn.c b/x11/IMdkit/IMConn.c
deleted file mode 100644 (file)
index 6d36589..0000000
+++ /dev/null
@@ -1,176 +0,0 @@
-/******************************************************************
-         Copyright 1994, 1995 by Sun Microsystems, Inc.
-         Copyright 1993, 1994 by Hewlett-Packard Company
-Permission to use, copy, modify, distribute, and sell this software
-and its documentation for any purpose is hereby granted without fee,
-provided that the above copyright notice appear in all copies and
-that both that copyright notice and this permission notice appear
-in supporting documentation, and that the name of Sun Microsystems, Inc.
-and Hewlett-Packard not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior permission.
-Sun Microsystems, Inc. and Hewlett-Packard make no representations about
-the suitability of this software for any purpose.  It is provided "as is"
-without express or implied warranty.
-SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL
-WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
-RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
-CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
-IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-  Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
-
-    This version tidied and debugged by Steve Underwood May 1999
-******************************************************************/
-
-#include <X11/Xlib.h>
-#include <stdlib.h>
-#include <string.h>
-#include "IMdkit.h"
-#include <stdarg.h>
-
-#define Va_start(a,b) va_start(a,b)
-
-static void _IMCountVaList(va_list var, int *total_count)
-{
-    char *attr;
-
-    *total_count = 0;
-
-    for (attr = va_arg (var, char*);  attr;  attr = va_arg (var, char*))
-    {
-       (void)va_arg (var, XIMArg *);
-       ++(*total_count);
-    }
-    /*endfor*/
-}
-
-static void _IMVaToNestedList(va_list var, int max_count, XIMArg **args_return)
-{
-    XIMArg *args;
-    char   *attr;
-
-    if (max_count <= 0)
-    {
-       *args_return = (XIMArg *) NULL;
-       return;
-    }
-    /*endif*/
-
-    args = (XIMArg *) malloc ((unsigned) (max_count + 1)*sizeof (XIMArg));
-    *args_return = args;
-    if (!args)
-        return;
-    /*endif*/
-
-    for (attr = va_arg (var, char*);  attr;  attr = va_arg (var, char *))
-    {
-       args->name = attr;
-       args->value = va_arg (var, XPointer);
-       args++;
-    }
-    /*endfor*/
-    args->name = (char*)NULL;
-}
-
-static char *_FindModifiers (XIMArg *args)
-{
-    char *modifiers;
-
-    while (args->name)
-    {
-       if (strcmp (args->name, IMModifiers) == 0)
-       {
-           modifiers = args->value;
-           return modifiers;
-       }
-       else
-       {
-           args++;
-       }
-       /*endif*/
-    }
-    /*endwhile*/
-    return NULL;
-}
-
-XIMS _GetIMS (char *modifiers)
-{
-    XIMS ims;
-    extern IMMethodsRec Xi18n_im_methods;
-
-    if ((ims = (XIMS) malloc (sizeof (XIMProtocolRec))) == (XIMS) NULL)
-       return ((XIMS) NULL);
-    /*endif*/
-    memset ((void *) ims, 0, sizeof (XIMProtocolRec));
-
-    if (modifiers == NULL
-       ||
-       modifiers[0] == '\0'
-       ||
-       strcmp (modifiers, "Xi18n") == 0)
-    {
-       ims->methods = &Xi18n_im_methods;
-       return ims;
-    }
-    /*endif*/
-    XFree (ims);
-    return (XIMS) NULL;
-}
-
-XIMS IMOpenIM (Display *display, ...)
-{
-    va_list var;
-    int total_count;
-    XIMArg *args;
-    XIMS ims;
-    char *modifiers;
-    Status ret;
-
-    Va_start (var, display);
-    _IMCountVaList (var, &total_count);
-    va_end (var);
-
-    Va_start (var, display);
-    _IMVaToNestedList (var, total_count, &args);
-    va_end (var);
-
-    modifiers = _FindModifiers (args);
-
-    ims = _GetIMS (modifiers);
-    if (ims == (XIMS) NULL)
-        return (XIMS) NULL;
-    /*endif*/
-    
-    ims->core.display = display;
-
-    ims->protocol = (*ims->methods->setup) (display, args);
-    XFree (args);
-    if (ims->protocol == (void *) NULL)
-    {
-       XFree (ims);
-       return (XIMS) NULL;
-    }
-    /*endif*/
-    ret = (ims->methods->openIM) (ims);
-    if (ret == False)
-    {
-       XFree (ims);
-       return (XIMS) NULL;
-    }
-    /*endif*/
-    return (XIMS) ims;
-}
-
-Status IMCloseIM (XIMS ims)
-{
-    (ims->methods->closeIM) (ims);
-    XFree (ims);
-    return True;
-}
diff --git a/x11/IMdkit/IMMethod.c b/x11/IMdkit/IMMethod.c
deleted file mode 100644 (file)
index 5a33878..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/******************************************************************
-         Copyright 1994, 1995 by Sun Microsystems, Inc.
-         Copyright 1993, 1994 by Hewlett-Packard Company
-Permission to use, copy, modify, distribute, and sell this software
-and its documentation for any purpose is hereby granted without fee,
-provided that the above copyright notice appear in all copies and
-that both that copyright notice and this permission notice appear
-in supporting documentation, and that the name of Sun Microsystems, Inc.
-and Hewlett-Packard not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior permission.
-Sun Microsystems, Inc. and Hewlett-Packard make no representations about
-the suitability of this software for any purpose.  It is provided "as is"
-without express or implied warranty.
-SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL
-WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
-RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
-CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
-IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-  Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
-
-    This version tidied and debugged by Steve Underwood May 1999
-******************************************************************/
-
-#include <X11/Xlib.h>
-#include "IMdkit.h"
-
-/* Public Function */
-void IMForwardEvent (XIMS ims, XPointer call_data)
-{
-    (ims->methods->forwardEvent) (ims, call_data);
-}
-
-void IMCommitString (XIMS ims, XPointer call_data)
-{
-    (ims->methods->commitString) (ims, call_data);
-}
-
-int IMCallCallback (XIMS ims, XPointer call_data)
-{
-    return (ims->methods->callCallback) (ims, call_data);
-}
-
-int IMPreeditStart (XIMS ims, XPointer call_data)
-{
-    return (ims->methods->preeditStart) (ims, call_data);
-}
-
-int IMPreeditEnd (XIMS ims, XPointer call_data)
-{
-    return (ims->methods->preeditEnd) (ims, call_data);
-}
-
-int IMSyncXlib(XIMS ims, XPointer call_data)
-{
-    ims->sync = True;
-    return (ims->methods->syncXlib) (ims, call_data);
-}
diff --git a/x11/IMdkit/IMValues.c b/x11/IMdkit/IMValues.c
deleted file mode 100644 (file)
index 687014a..0000000
+++ /dev/null
@@ -1,124 +0,0 @@
-/******************************************************************
-         Copyright 1994, 1995 by Sun Microsystems, Inc.
-         Copyright 1993, 1994 by Hewlett-Packard Company
-Permission to use, copy, modify, distribute, and sell this software
-and its documentation for any purpose is hereby granted without fee,
-provided that the above copyright notice appear in all copies and
-that both that copyright notice and this permission notice appear
-in supporting documentation, and that the name of Sun Microsystems, Inc.
-and Hewlett-Packard not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior permission.
-Sun Microsystems, Inc. and Hewlett-Packard make no representations about
-the suitability of this software for any purpose.  It is provided "as is"
-without express or implied warranty.
-SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL
-WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
-RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
-CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
-IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-  Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
-
-    This version tidied and debugged by Steve Underwood May 1999
-******************************************************************/
-
-#include <stdlib.h>
-#include <X11/Xlib.h>
-#include "IMdkit.h"
-#include <stdarg.h>
-
-#define Va_start(a,b) va_start(a,b)
-
-static void _IMCountVaList (va_list var, int *total_count)
-{
-    char *attr;
-
-    *total_count = 0;
-
-    for (attr = va_arg (var, char *);  attr;  attr = va_arg (var, char *))
-    {
-       (void)va_arg (var, XIMArg *);
-       ++(*total_count);
-    }
-    /*endfor*/
-}
-
-static void _IMVaToNestedList (va_list var, int max_count, XIMArg **args_return)
-{
-    XIMArg *args;
-    char   *attr;
-
-    if (max_count <= 0)
-    {
-       *args_return = (XIMArg *) NULL;
-       return;
-    }
-    /*endif*/
-
-    args = (XIMArg *) malloc ((unsigned) (max_count + 1)*sizeof (XIMArg));
-    *args_return = args;
-    if (!args)
-        return;
-    /*endif*/
-    for (attr = va_arg (var, char *);  attr;  attr = va_arg (var, char *))
-    {
-       args->name = attr;
-       args->value = va_arg (var, XPointer);
-       args++;
-    }
-    /*endfor*/
-    args->name = (char *) NULL;
-}
-
-char *IMGetIMValues (XIMS ims, ...)
-{
-    va_list var;
-    int total_count;
-    XIMArg *args;
-    char *ret;
-
-    Va_start (var, ims);
-    _IMCountVaList (var, &total_count);
-    va_end (var);
-
-    Va_start (var, ims);
-    _IMVaToNestedList (var, total_count, &args);
-    va_end (var);
-
-    ret = (*ims->methods->getIMValues) (ims, args);
-
-    if (args)
-        XFree ((char *) args);
-    /*endif*/
-    return ret;
-}
-
-char *IMSetIMValues (XIMS ims, ...)
-{
-    va_list var;
-    int total_count;
-    XIMArg *args;
-    char *ret;  
-
-    Va_start (var, ims);
-    _IMCountVaList (var, &total_count);
-    va_end (var);
-
-    Va_start (var, ims);
-    _IMVaToNestedList (var, total_count, &args);
-    va_end (var);
-
-    ret = (*ims->methods->setIMValues) (ims, args);
-
-    if (args)
-        XFree ((char *) args);
-    /*endif*/
-    return ret;
-}
diff --git a/x11/IMdkit/IMdkit.h b/x11/IMdkit/IMdkit.h
deleted file mode 100644 (file)
index 6f8d673..0000000
+++ /dev/null
@@ -1,144 +0,0 @@
-/******************************************************************
-         Copyright 1994, 1995 by Sun Microsystems, Inc.
-         Copyright 1993, 1994 by Hewlett-Packard Company
-Permission to use, copy, modify, distribute, and sell this software
-and its documentation for any purpose is hereby granted without fee,
-provided that the above copyright notice appear in all copies and
-that both that copyright notice and this permission notice appear
-in supporting documentation, and that the name of Sun Microsystems, Inc.
-and Hewlett-Packard not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior permission.
-Sun Microsystems, Inc. and Hewlett-Packard make no representations about
-the suitability of this software for any purpose.  It is provided "as is"
-without express or implied warranty.
-SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL
-WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
-RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
-CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
-IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-  Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
-
-    This version tidied and debugged by Steve Underwood May 1999
-******************************************************************/
-
-#ifndef _IMdkit_h
-#define _IMdkit_h
-
-#include <X11/Xmd.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* IM Attributes Name */
-#define IMModifiers            "modifiers"
-#define IMServerWindow         "serverWindow"
-#define IMServerName           "serverName"
-#define IMServerTransport      "serverTransport"
-#define IMLocale               "locale"
-#define IMInputStyles          "inputStyles"
-#define IMProtocolHandler      "protocolHandler"
-#define IMOnKeysList           "onKeysList"
-#define IMOffKeysList          "offKeysList"
-#define IMEncodingList         "encodingList"
-#define IMFilterEventMask      "filterEventMask"
-#define IMProtocolDepend       "protocolDepend"
-
-/* Masks for IM Attributes Name */
-#define I18N_IMSERVER_WIN      0x0001 /* IMServerWindow */
-#define I18N_IM_NAME           0x0002 /* IMServerName */
-#define I18N_IM_LOCALE         0x0004 /* IMLocale */
-#define I18N_IM_ADDRESS                0x0008 /* IMServerTransport */
-#define I18N_INPUT_STYLES      0x0010 /* IMInputStyles */
-#define I18N_ON_KEYS           0x0020 /* IMOnKeysList */
-#define I18N_OFF_KEYS          0x0040 /* IMOffKeysList */
-#define I18N_IM_HANDLER                0x0080 /* IMProtocolHander */
-#define I18N_ENCODINGS         0x0100 /* IMEncodingList */
-#define I18N_FILTERMASK                0x0200 /* IMFilterEventMask */
-#define I18N_PROTO_DEPEND      0x0400 /* IMProtoDepend */
-
-typedef struct
-{
-    char       *name;
-    XPointer   value;
-} XIMArg;
-
-typedef struct
-{
-    CARD32     keysym;
-    CARD32     modifier;
-    CARD32     modifier_mask;
-} XIMTriggerKey;
-
-typedef struct
-{
-    unsigned short count_keys;
-    XIMTriggerKey *keylist;
-} XIMTriggerKeys;
-
-typedef char *XIMEncoding;
-
-typedef struct
-{
-    unsigned short count_encodings;
-    XIMEncoding *supported_encodings;
-} XIMEncodings;
-
-typedef struct _XIMS *XIMS;
-
-typedef struct
-{
-    void*      (*setup) (Display *, XIMArg *);
-    Status     (*openIM) (XIMS);
-    Status     (*closeIM) (XIMS);
-    char*      (*setIMValues) (XIMS, XIMArg *);
-    char*      (*getIMValues) (XIMS, XIMArg *);
-    Status     (*forwardEvent) (XIMS, XPointer);
-    Status     (*commitString) (XIMS, XPointer);
-    int                (*callCallback) (XIMS, XPointer);
-    int                (*preeditStart) (XIMS, XPointer);
-    int                (*preeditEnd) (XIMS, XPointer);
-    int                (*syncXlib) (XIMS, XPointer);
-} IMMethodsRec, *IMMethods;
-
-typedef struct
-{
-    Display    *display;
-    int                screen;
-} IMCoreRec, *IMCore;
-
-typedef struct _XIMS
-{
-    IMMethods  methods;
-    IMCoreRec  core;
-    Bool       sync;
-    void       *protocol;
-} XIMProtocolRec;
-
-/* 
- * X function declarations.
- */
-extern XIMS IMOpenIM (Display *, ...);
-extern Status IMCloseIM (XIMS);
-extern char *IMSetIMValues (XIMS, ...);
-extern char *IMGetIMValues (XIMS, ...);
-void IMForwardEvent (XIMS, XPointer);
-void IMCommitString (XIMS, XPointer);
-int IMCallCallback (XIMS, XPointer);
-int IMPreeditStart (XIMS, XPointer);
-int IMPreeditEnd (XIMS, XPointer);
-int IMSyncXlib (XIMS, XPointer);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* IMdkit_h */
diff --git a/x11/IMdkit/Makefile.am b/x11/IMdkit/Makefile.am
deleted file mode 100644 (file)
index b567d9d..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-noinst_LTLIBRARIES = libIMdkit.la
-
-libIMdkit_la_SOURCES = \
-       FrameMgr.c \
-       i18nAttr.c \
-       i18nClbk.c \
-       i18nIc.c \
-       i18nIMProto.c \
-       i18nMethod.c \
-       i18nPtHdr.c \
-       i18nUtil.c \
-       i18nX.c \
-       IMConn.c \
-       IMMethod.c \
-       IMValues.c \
-       $(NULL)
-
-noinst_HEADERS = \
-       FrameMgr.h \
-       IMdkit.h \
-       Xi18n.h \
-       Xi18nX.h \
-       XimFunc.h \
-       XimProto.h \
-       Xtrans.h \
-       $(NULL)
-
diff --git a/x11/IMdkit/Xi18n.h b/x11/IMdkit/Xi18n.h
deleted file mode 100644 (file)
index aaf7768..0000000
+++ /dev/null
@@ -1,505 +0,0 @@
-/******************************************************************
-         Copyright 1994, 1995 by Sun Microsystems, Inc.
-         Copyright 1993, 1994 by Hewlett-Packard Company
-Permission to use, copy, modify, distribute, and sell this software
-and its documentation for any purpose is hereby granted without fee,
-provided that the above copyright notice appear in all copies and
-that both that copyright notice and this permission notice appear
-in supporting documentation, and that the name of Sun Microsystems, Inc.
-and Hewlett-Packard not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior permission.
-Sun Microsystems, Inc. and Hewlett-Packard make no representations about
-the suitability of this software for any purpose.  It is provided "as is"
-without express or implied warranty.
-SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL
-WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
-RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
-CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
-IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-  Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
-
-    This version tidied and debugged by Steve Underwood May 1999
-******************************************************************/
-
-#ifndef _Xi18n_h
-#define _Xi18n_h
-#include <X11/Xlib.h>
-#include <X11/Xfuncs.h>
-#include <X11/Xos.h>
-#include "XimProto.h"
-
-/*
- * Minor Protocol Number for Extension Protocol 
- */
-#define XIM_EXTENSION                          128
-#define XIM_EXT_SET_EVENT_MASK                 (0x30)
-#define        XIM_EXT_FORWARD_KEYEVENT                (0x32)
-#define        XIM_EXT_MOVE                            (0x33)
-#define COMMON_EXTENSIONS_NUM                  3
-
-#include <stdlib.h>
-#include "IMdkit.h"
-
-/* XI18N Valid Attribute Name Definition */
-#define ExtForwardKeyEvent     "extForwardKeyEvent"
-#define ExtMove                        "extMove"
-#define ExtSetEventMask                "extSetEventMask"
-
-/*
- * Padding macro
- */
-#define        IMPAD(length) ((4 - ((length)%4))%4)
-
-/*
- * Target Atom for Transport Connection
- */
-#define LOCALES                "LOCALES"
-#define TRANSPORT      "TRANSPORT"
-
-#define I18N_OPEN      0
-#define I18N_SET       1
-#define I18N_GET       2
-
-typedef struct
-{
-    char        *transportname;
-    int         namelen;
-    Bool        (*checkAddr) ();
-} TransportSW;
-
-typedef struct _XIMPending
-{
-    unsigned    char *p;
-    struct _XIMPending *next;
-} XIMPending;
-
-typedef struct _XimProtoHdr
-{
-    CARD8      major_opcode;
-    CARD8      minor_opcode;
-    CARD16     length;
-} XimProtoHdr;
-
-typedef struct
-{
-    CARD16     attribute_id;
-    CARD16     type;
-    CARD16     length;
-    char       *name;
-} XIMAttr;
-
-typedef struct
-{
-    CARD16     attribute_id;
-    CARD16     type;
-    CARD16     length;
-    char       *name;
-} XICAttr;
-
-typedef struct
-{
-    int                attribute_id;
-    CARD16     name_length; 
-    char       *name;
-    int                value_length;
-    void       *value;
-    int                type;
-} XIMAttribute;
-
-typedef struct
-{
-    int                attribute_id;
-    CARD16     name_length;
-    char       *name;
-    int                value_length;
-    void       *value;
-    int                type;
-} XICAttribute;
-
-typedef struct
-{
-    int                length;
-    char       *name;
-} XIMStr;
-
-typedef struct
-{
-    CARD16     major_opcode;
-    CARD16     minor_opcode;
-    CARD16     length;
-    char       *name;
-} XIMExt;
-
-typedef struct _Xi18nClient
-{
-    int                connect_id;
-    CARD8      byte_order;
-    /*
-       '?': initial value
-       'B': for Big-Endian
-       'l': for little-endian
-     */
-    int                sync;
-    XIMPending  *pending;
-    void *trans_rec;           /* contains transport specific data  */
-    struct _Xi18nClient *next;
-} Xi18nClient;
-
-typedef struct _Xi18nCore *Xi18n;
-
-/*
- * Callback Struct for XIM Protocol
- */
-typedef struct
-{
-    int                major_code;
-    int                minor_code;
-    CARD16     connect_id;
-} IMAnyStruct;
-
-typedef struct
-{
-    int                major_code;
-    int                minor_code;
-    CARD16     connect_id;
-    CARD8      byte_order;
-    CARD16     major_version;
-    CARD16     minor_version;
-} IMConnectStruct;
-
-typedef struct
-{
-    int                major_code;
-    int                minor_code;
-    CARD16     connect_id;
-} IMDisConnectStruct;
-
-typedef struct
-{
-    int                major_code;
-    int                minor_code;
-    CARD16     connect_id;
-    XIMStr     lang;
-} IMOpenStruct;
-
-typedef struct
-{
-    int                major_code;
-    int                minor_code;
-    CARD16     connect_id;
-} IMCloseStruct;
-
-typedef struct
-{
-    int                major_code;
-    int                minor_code;
-    CARD16     connect_id;
-    CARD16     number;
-    XIMStr     *extension;
-} IMQueryExtensionStruct;
-
-typedef struct
-{
-    int                major_code;
-    int                minor_code;
-    CARD16     connect_id;
-    CARD16     number;
-    char       **im_attr_list;
-} IMGetIMValuesStruct;
-
-typedef struct
-{
-    int                major_code;
-    int                minor_code;
-    CARD16     connect_id;
-    CARD16     icid;
-    CARD16     preedit_attr_num;
-    CARD16     status_attr_num;
-    CARD16     ic_attr_num;
-    XICAttribute *preedit_attr;
-    XICAttribute *status_attr;
-    XICAttribute *ic_attr;
-} IMChangeICStruct;
-
-typedef struct
-{
-    int                major_code;
-    int                minor_code;
-    CARD16     connect_id;
-    CARD16     icid;
-} IMDestroyICStruct;
-
-typedef struct
-{
-    int                major_code;
-    int                minor_code;
-    CARD16     connect_id;
-    CARD16     icid;
-    CARD16     length;
-    char       *commit_string;
-} IMResetICStruct;
-
-typedef struct
-{
-    int                major_code;
-    int                minor_code;
-    CARD16     connect_id;
-    CARD16     icid;
-} IMChangeFocusStruct;
-
-typedef struct
-{
-    int                major_code;
-    int                minor_code;
-    CARD16     connect_id;
-    CARD16     icid;
-    BITMASK16  sync_bit;
-    CARD16     serial_number;
-    XEvent     event;
-} IMForwardEventStruct;
-
-typedef struct
-{
-    int                major_code;
-    int                minor_code;
-    CARD16     connect_id;
-    CARD16     icid;
-    CARD16     flag;
-    KeySym     keysym;
-    char       *commit_string;
-} IMCommitStruct;
-
-typedef struct
-{
-    int                major_code;
-    int                minor_code;
-    CARD16     connect_id;
-    CARD16     icid;
-    CARD32     flag;
-    CARD32     key_index;
-    CARD32     event_mask;
-} IMTriggerNotifyStruct;
-
-typedef struct
-{
-    int                major_code;
-    int                minor_code;
-    CARD16     connect_id;
-    CARD16     encoding_number;
-    XIMStr     *encoding;      /* name information */
-    CARD16     encoding_info_number;
-    XIMStr     *encodinginfo;  /* detailed information */
-    CARD16     category;       /* #0 for name, #1 for detail */
-    INT16      enc_index;      /* index of the encoding determined */
-} IMEncodingNegotiationStruct;
-
-typedef struct
-{
-    int                major_code;
-    int                minor_code;
-    CARD16     connect_id;
-    CARD16     icid;
-    CARD32     flag;
-    CARD32     forward_event_mask;
-    CARD32     sync_event_mask;
-} IMSetEventMaskStruct;
-
-typedef struct
-{
-    int                major_code;
-    int                minor_code;
-    CARD16     connect_id;
-    CARD16     icid;
-    CARD32     filter_event_mask;
-    CARD32     intercept_event_mask;
-    CARD32     select_event_mask;
-    CARD32     forward_event_mask;
-    CARD32     sync_event_mask;
-} IMExtSetEventMaskStruct;
-
-typedef struct
-{
-    int                major_code;
-    int                minor_code;
-    CARD16     connect_id;
-    CARD16     icid;
-    CARD16     x;
-    CARD16     y;
-} IMMoveStruct;
-
-typedef struct
-{
-    int                major_code;
-    int                minor_code;
-    CARD16     connect_id;
-    CARD16     icid;
-    BITMASK16  flag;
-    CARD16     error_code;
-    CARD16     str_length;
-    CARD16     error_type;
-    char       *error_detail;
-} IMErrorStruct;
-
-typedef struct
-{
-    int                major_code;
-    int                minor_code;
-    CARD16     connect_id;
-    CARD16     icid;
-} IMPreeditStateStruct;
-
-/* Callbacks */
-typedef struct
-{
-    int                major_code;
-    int                minor_code;
-    CARD16     connect_id;
-    CARD16     icid;
-} IMGeometryCBStruct;
-
-typedef struct
-{
-    int                major_code;
-    int                minor_code;
-    CARD16     connect_id;
-    CARD16     icid;
-    union
-    {
-       int return_value;                       /* PreeditStart */
-       XIMPreeditDrawCallbackStruct draw;      /* PreeditDraw */
-       XIMPreeditCaretCallbackStruct caret;    /* PreeditCaret */
-    } todo;
-} IMPreeditCBStruct;
-
-typedef struct
-{
-    int                major_code;
-    int                minor_code;
-    CARD16     connect_id;
-    CARD16     icid;
-    union
-    {
-       XIMStatusDrawCallbackStruct draw;       /* StatusDraw */
-    } todo;
-} IMStatusCBStruct;
-
-typedef struct
-{
-    int                major_code;
-    int                minor_code;
-    CARD16     connect_id;
-    CARD16     icid;
-    XIMStringConversionCallbackStruct strconv;
-} IMStrConvCBStruct;
-
-typedef struct
-{
-    int                major_code;
-    int                minor_code;
-    CARD16     connect_id;
-    CARD16     icid;
-} IMSyncXlibStruct;
-
-typedef union _IMProtocol
-{
-    int        major_code;
-    IMAnyStruct any;
-    IMConnectStruct imconnect;
-    IMDisConnectStruct imdisconnect;
-    IMOpenStruct imopen;
-    IMCloseStruct imclose;
-    IMQueryExtensionStruct queryext;
-    IMGetIMValuesStruct getim;
-    IMEncodingNegotiationStruct encodingnego;
-    IMExtSetEventMaskStruct extsetevent;
-    IMMoveStruct extmove;
-    IMSetEventMaskStruct setevent;
-    IMChangeICStruct changeic;
-    IMDestroyICStruct destroyic;
-    IMResetICStruct resetic;
-    IMChangeFocusStruct changefocus;
-    IMCommitStruct commitstring;
-    IMForwardEventStruct forwardevent;
-    IMTriggerNotifyStruct triggernotify;
-    IMPreeditStateStruct preedit_state;
-    IMErrorStruct imerror;
-    IMGeometryCBStruct geometry_callback;
-    IMPreeditCBStruct preedit_callback;
-    IMStatusCBStruct status_callback;
-    IMStrConvCBStruct strconv_callback;
-    IMSyncXlibStruct sync_xlib;
-    long pad[32];
-} IMProtocol;
-
-typedef int (*IMProtoHandler) (XIMS, IMProtocol*);
-
-#define DEFAULT_FILTER_MASK    (KeyPressMask)
-
-/* Xi18nAddressRec structure */
-typedef struct _Xi18nAddressRec
-{
-    Display    *dpy;
-    CARD8      im_byteOrder;   /* byte order 'B' or 'l' */
-    /* IM Values */
-    long       imvalue_mask;
-    Window     im_window;      /* IMServerWindow */
-    char       *im_name;       /* IMServerName */
-    char       *im_locale;     /* IMLocale */
-    char       *im_addr;       /* IMServerTransport */
-    XIMStyles  input_styles;   /* IMInputStyles */
-    XIMTriggerKeys on_keys;    /* IMOnKeysList */
-    XIMTriggerKeys off_keys;   /* IMOffKeysList */
-    XIMEncodings encoding_list; /* IMEncodingList */
-    IMProtoHandler improto;    /* IMProtocolHander */
-    long       filterevent_mask; /* IMFilterEventMask */
-    /* XIM_SERVERS target Atoms */
-    Atom       selection;
-    Atom       Localename;
-    Atom       Transportname;
-    /* XIM/XIC Attr */
-    int                im_attr_num;
-    XIMAttr    *xim_attr;
-    int                ic_attr_num;
-    XICAttr    *xic_attr;
-    CARD16     preeditAttr_id;
-    CARD16     statusAttr_id;
-    CARD16     separatorAttr_id;
-    /* XIMExtension List */
-    int                ext_num;
-    XIMExt     extension[COMMON_EXTENSIONS_NUM];
-    /* transport specific connection address */
-    void       *connect_addr;
-    /* actual data is defined:
-       XSpecRec in Xi18nX.h for X-based connection.
-       TransSpecRec in Xi18nTr.h for Socket-based connection.
-     */
-    /* clients table */
-    Xi18nClient *clients;
-    Xi18nClient *free_clients;
-} Xi18nAddressRec;
-
-typedef struct _Xi18nMethodsRec
-{
-    Bool (*begin) (XIMS);
-    Bool (*end) (XIMS);
-    Bool (*send) (XIMS, CARD16, unsigned char*, long);
-    Bool (*wait) (XIMS, CARD16, CARD8, CARD8);
-    Bool (*disconnect) (XIMS, CARD16);
-} Xi18nMethodsRec;
-
-typedef struct _Xi18nCore
-{
-    Xi18nAddressRec address;
-    Xi18nMethodsRec methods;
-} Xi18nCore;
-
-#endif
-
diff --git a/x11/IMdkit/Xi18nX.h b/x11/IMdkit/Xi18nX.h
deleted file mode 100644 (file)
index ff91b1a..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/******************************************************************
-         Copyright 1994, 1995 by Sun Microsystems, Inc.
-         Copyright 1993, 1994 by Hewlett-Packard Company
-Permission to use, copy, modify, distribute, and sell this software
-and its documentation for any purpose is hereby granted without fee,
-provided that the above copyright notice appear in all copies and
-that both that copyright notice and this permission notice appear
-in supporting documentation, and that the name of Sun Microsystems, Inc.
-and Hewlett-Packard not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior permission.
-Sun Microsystems, Inc. and Hewlett-Packard make no representations about
-the suitability of this software for any purpose.  It is provided "as is"
-without express or implied warranty.
-SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL
-WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
-RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
-CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
-IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-  Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
-
-    This version tidied and debugged by Steve Underwood May 1999
-******************************************************************/
-
-#ifndef _Xi18nTrX_h
-#define _Xi18nTrX_h
-
-#define _XIM_PROTOCOL           "_XIM_PROTOCOL"
-#define _XIM_XCONNECT           "_XIM_XCONNECT"
-
-#define XCM_DATA_LIMIT         20
-
-typedef struct _XClient
-{
-    Window     client_win;     /* client window */
-    Window     accept_win;     /* accept window */
-} XClient;
-
-typedef struct
-{
-    Atom       xim_request;
-    Atom       connect_request;
-} XSpecRec;
-
-#endif
diff --git a/x11/IMdkit/XimFunc.h b/x11/IMdkit/XimFunc.h
deleted file mode 100644 (file)
index a9f4a04..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-/******************************************************************
-         Copyright 1994, 1995 by Sun Microsystems, Inc.
-         Copyright 1993, 1994 by Hewlett-Packard Company
-Permission to use, copy, modify, distribute, and sell this software
-and its documentation for any purpose is hereby granted without fee,
-provided that the above copyright notice appear in all copies and
-that both that copyright notice and this permission notice appear
-in supporting documentation, and that the name of Sun Microsystems, Inc.
-and Hewlett-Packard not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior permission.
-Sun Microsystems, Inc. and Hewlett-Packard make no representations about
-the suitability of this software for any purpose.  It is provided "as is"
-without express or implied warranty.
-SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL
-WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
-RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
-CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
-IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-  Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
-
-    This version tidied and debugged by Steve Underwood May 1999
-******************************************************************/
-
-#ifndef _XimFunc_h
-#define _XimFunc_h
-
-/* i18nAttr.c */
-void _Xi18nInitAttrList (Xi18n i18n_core);
-void _Xi18nInitExtension(Xi18n i18n_core);
-
-/* i18nClbk.c */
-int _Xi18nGeometryCallback (XIMS ims, IMProtocol *call_data);
-int _Xi18nPreeditStartCallback (XIMS ims, IMProtocol *call_data);
-int _Xi18nPreeditDrawCallback (XIMS ims, IMProtocol *call_data);
-int _Xi18nPreeditCaretCallback (XIMS ims, IMProtocol *call_data);
-int _Xi18nPreeditDoneCallback (XIMS ims, IMProtocol *call_data);
-int _Xi18nStatusStartCallback (XIMS ims, IMProtocol *call_data);
-int _Xi18nStatusDrawCallback (XIMS ims, IMProtocol *call_data);
-int _Xi18nStatusDoneCallback (XIMS ims, IMProtocol *call_data);
-int _Xi18nStringConversionCallback (XIMS ims, IMProtocol *call_data);
-
-/* i18nIc.c */
-void _Xi18nChangeIC (XIMS ims, IMProtocol *call_data, unsigned char *p,
-                     int create_flag);
-void _Xi18nGetIC (XIMS ims, IMProtocol *call_data, unsigned char *p);
-
-/* i18nUtil.c */
-int _Xi18nNeedSwap (Xi18n i18n_core, CARD16 connect_id);
-Xi18nClient *_Xi18nNewClient(Xi18n i18n_core);
-Xi18nClient *_Xi18nFindClient (Xi18n i18n_core, CARD16 connect_id);
-void _Xi18nDeleteClient (Xi18n i18n_core, CARD16 connect_id);
-void _Xi18nSendMessage (XIMS ims, CARD16 connect_id, CARD8 major_opcode,
-                        CARD8 minor_opcode, unsigned char *data, long length);
-void _Xi18nSendTriggerKey (XIMS ims, CARD16 connect_id);
-void _Xi18nSetEventMask (XIMS ims, CARD16 connect_id, CARD16 im_id,
-                         CARD16 ic_id, CARD32 forward_mask, CARD32 sync_mask);
-
-/* Xlib internal */
-void _XRegisterFilterByType(Display*, Window, int, int,
-               Bool (*filter)(Display*, Window, XEvent*, XPointer), XPointer);
-void _XUnregisterFilter(Display*, Window, 
-               Bool (*filter)(Display*, Window, XEvent*, XPointer), XPointer);
-
-#endif
diff --git a/x11/IMdkit/XimProto.h b/x11/IMdkit/XimProto.h
deleted file mode 100644 (file)
index e3ed168..0000000
+++ /dev/null
@@ -1,230 +0,0 @@
-/* $XConsortium: XimProto.h,v 1.2 94/01/20 18:02:24 rws Exp $ */
-/******************************************************************
-
-           Copyright 1992, 1993, 1994 by FUJITSU LIMITED
-
-Permission to use, copy, modify, distribute, and sell this software
-and its documentation for any purpose is hereby granted without fee,
-provided that the above copyright notice appear in all copies and
-that both that copyright notice and this permission notice appear
-in supporting documentation, and that the name of FUJITSU LIMITED
-not be used in advertising or publicity pertaining to distribution
-of the software without specific, written prior permission.
-FUJITSU LIMITED makes no representations about the suitability of
-this software for any purpose. 
-It is provided "as is" without express or implied warranty.
-
-FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
-EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
-CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
-USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
-OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-PERFORMANCE OF THIS SOFTWARE.
-
-  Author: Takashi Fujiwara     FUJITSU LIMITED 
-                               fujiwara@a80.tech.yk.fujitsu.co.jp
-
-    This version tidied and debugged by Steve Underwood May 1999
-
-******************************************************************/
-
-#ifndef _XIMPROTO_H
-#define _XIMPROTO_H
-
-/*
- * Default Preconnection selection target
- */
-#define XIM_SERVERS            "XIM_SERVERS"
-#define XIM_LOCALES            "LOCALES"
-#define XIM_TRANSPORT          "TRANSPORT"
-
-/*
- * categories in XIM_SERVERS
- */
-#define XIM_SERVER_CATEGORY    "@server="
-#define XIM_LOCAL_CATEGORY     "@locale="
-#define XIM_TRANSPORT_CATEGORY "@transport="
-
-/*
- * Xim implementation revision
- */
-#define PROTOCOLMAJORVERSION           0
-#define PROTOCOLMINORVERSION           0
-
-/*
- * Major Protocol number
- */
-#define        XIM_CONNECT                       1
-#define        XIM_CONNECT_REPLY                 2
-#define        XIM_DISCONNECT                    3
-#define        XIM_DISCONNECT_REPLY              4
-
-#define XIM_AUTH_REQUIRED               10
-#define XIM_AUTH_REPLY                  11
-#define XIM_AUTH_NEXT                   12
-#define XIM_AUTH_SETUP                  13
-#define XIM_AUTH_NG                     14
-
-#define        XIM_ERROR                        20
-
-#define        XIM_OPEN                         30
-#define        XIM_OPEN_REPLY                   31
-#define        XIM_CLOSE                        32
-#define        XIM_CLOSE_REPLY                  33
-#define        XIM_REGISTER_TRIGGERKEYS         34
-#define        XIM_TRIGGER_NOTIFY               35
-#define        XIM_TRIGGER_NOTIFY_REPLY         36
-#define        XIM_SET_EVENT_MASK               37
-#define        XIM_ENCODING_NEGOTIATION         38
-#define        XIM_ENCODING_NEGOTIATION_REPLY   39
-#define        XIM_QUERY_EXTENSION              40
-#define        XIM_QUERY_EXTENSION_REPLY        41
-#define        XIM_SET_IM_VALUES                42
-#define        XIM_SET_IM_VALUES_REPLY          43
-#define        XIM_GET_IM_VALUES                44
-#define        XIM_GET_IM_VALUES_REPLY          45
-
-#define XIM_CREATE_IC                   50
-#define        XIM_CREATE_IC_REPLY              51
-#define        XIM_DESTROY_IC                   52
-#define        XIM_DESTROY_IC_REPLY             53
-#define XIM_SET_IC_VALUES               54
-#define        XIM_SET_IC_VALUES_REPLY          55
-#define XIM_GET_IC_VALUES               56
-#define XIM_GET_IC_VALUES_REPLY                 57
-#define        XIM_SET_IC_FOCUS                 58
-#define        XIM_UNSET_IC_FOCUS               59
-#define        XIM_FORWARD_EVENT                60
-#define        XIM_SYNC                         61
-#define        XIM_SYNC_REPLY                   62
-#define        XIM_COMMIT                       63
-#define        XIM_RESET_IC                     64
-#define        XIM_RESET_IC_REPLY               65
-
-#define        XIM_GEOMETRY                     70
-#define        XIM_STR_CONVERSION               71
-#define        XIM_STR_CONVERSION_REPLY         72
-#define        XIM_PREEDIT_START                73
-#define        XIM_PREEDIT_START_REPLY          74
-#define        XIM_PREEDIT_DRAW                 75
-#define        XIM_PREEDIT_CARET                76
-#define XIM_PREEDIT_CARET_REPLY                 77
-#define        XIM_PREEDIT_DONE                 78
-#define        XIM_STATUS_START                 79
-#define        XIM_STATUS_DRAW                  80
-#define        XIM_STATUS_DONE                  81
-
-/*
- * values for the flag of XIM_ERROR
- */
-#define        XIM_IMID_VALID                  0x0001
-#define        XIM_ICID_VALID                  0x0002
-
-/*
- * XIM Error Code
- */
-#define XIM_BadAlloc                   1
-#define XIM_BadStyle                   2
-#define XIM_BadClientWindow            3
-#define XIM_BadFocusWindow             4
-#define XIM_BadArea                    5
-#define XIM_BadSpotLocation            6
-#define XIM_BadColormap                        7
-#define XIM_BadAtom                    8
-#define XIM_BadPixel                   9
-#define XIM_BadPixmap                  10
-#define XIM_BadName                    11
-#define XIM_BadCursor                  12
-#define XIM_BadProtocol                        13
-#define XIM_BadForeground              14
-#define XIM_BadBackground              15
-#define XIM_LocaleNotSupported         16
-#define XIM_BadSomething               999
-
-/*
- * byte order
- */
-#define BIGENDIAN      (CARD8) 0x42    /* MSB first */
-#define LITTLEENDIAN   (CARD8) 0x6c    /* LSB first */
-
-/*
- * values for the type of XIMATTR & XICATTR
- */
-#define        XimType_SeparatorOfNestedList   0
-#define        XimType_CARD8                   1
-#define        XimType_CARD16                  2
-#define        XimType_CARD32                  3
-#define        XimType_STRING8                 4
-#define        XimType_Window                  5
-#define        XimType_XIMStyles               10
-#define        XimType_XRectangle              11
-#define        XimType_XPoint                  12
-#define XimType_XFontSet               13
-#define XimType_XIMOptions             14
-#define XimType_XIMHotKeyTriggers      15
-#define XimType_XIMHotKeyState         16
-#define XimType_XIMStringConversion    17
-#define XimType_XIMValuesList          18
-#define        XimType_NEST                    0x7FFF
-
-/*
- * values for the category of XIM_ENCODING_NEGOTIATON_REPLY
- */
-#define        XIM_Encoding_NameCategory       0
-#define        XIM_Encoding_DetailCategory     1
-
-/*
- * value for the index of XIM_ENCODING_NEGOTIATON_REPLY
- */
-#define        XIM_Default_Encoding_IDX        -1
-
-/*
- * value for the flag of XIM_FORWARD_EVENT, XIM_COMMIT
- */
-#define XimSYNCHRONUS            0x0001
-#define XimLookupChars           0x0002
-#define XimLookupKeySym                  0x0004
-#define XimLookupBoth            0x0006
-
-/*
- * request packet header size
- */
-#define XIM_HEADER_SIZE                                                \
-         sizeof(CARD8)         /* sizeof mejor-opcode */       \
-       + sizeof(CARD8)         /* sizeof minor-opcode */       \
-       + sizeof(INT16)         /* sizeof length */
-
-/*
- * Client Message data size
- */
-#define        XIM_CM_DATA_SIZE        20
-
-/*
- * XIM data structure
- */
-typedef CARD16 BITMASK16;
-typedef CARD32 BITMASK32;
-typedef CARD32 EVENTMASK;
-
-typedef CARD16 XIMID;          /* Input Method ID */
-typedef CARD16 XICID;          /* Input Context ID */
-
-/*
- * Padding macro
- */
-#define        XIM_PAD(length) ((4 - ((length) % 4)) % 4)
-
-#define XIM_SET_PAD(ptr, length)                                       \
-    {                                                                  \
-       register int     Counter = XIM_PAD((int)length);                \
-       if (Counter) {                                                  \
-           register char       *Ptr = (char *)(ptr) + (length);        \
-           length += Counter;                                          \
-           for (; Counter; --Counter, ++Ptr)                           \
-               *Ptr = '\0';                                            \
-       }                                                               \
-    }
-
-#endif
-
diff --git a/x11/IMdkit/Xtrans.h b/x11/IMdkit/Xtrans.h
deleted file mode 100644 (file)
index cae691c..0000000
+++ /dev/null
@@ -1,470 +0,0 @@
-/* $XConsortium: Xtrans.h,v 1.24 94/05/02 10:45:32 mor Exp $ */
-/*
-
-Copyright (c) 1993, 1994  X Consortium
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be included
-in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
-OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of the X Consortium shall
-not be used in advertising or otherwise to promote the sale, use or
-other dealings in this Software without prior written authorization
-from the X Consortium.
-
-*/
-
-/* Copyright (c) 1993, 1994 NCR Corporation - Dayton, Ohio, USA
- *
- * All Rights Reserved
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name NCR not be used in advertising
- * or publicity pertaining to distribution of the software without specific,
- * written prior permission.  NCR makes no representations about the
- * suitability of this software for any purpose.  It is provided "as is"
- * without express or implied warranty.
- *
- * NCR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
- * NO EVENT SHALL NCR BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
- * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
- * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#ifndef _XTRANS_H_
-#define _XTRANS_H_
-
-#include <X11/Xfuncproto.h>
-#include <X11/Xos.h>
-
-
-/*
- * Set the functions names according to where this code is being compiled.
- */
-
-#ifdef X11_t
-#if (__STDC__ && !defined(UNIXCPP)) || defined(ANSICPP)
-#define TRANS(func) _X11Trans##func
-#else
-#define TRANS(func) _X11Trans/**/func
-#endif
-#endif /* X11_t */
-
-#ifdef XSERV_t
-#if (__STDC__ && !defined(UNIXCPP)) || defined(ANSICPP)
-#define TRANS(func) _XSERVTrans##func
-#else
-#define TRANS(func) _XSERVTrans/**/func
-#endif
-#define X11_t
-#endif /* X11_t */
-
-#ifdef XIM_t
-#if (__STDC__ && !defined(UNIXCPP)) || defined(ANSICPP)
-#define TRANS(func) _XimdXTrans##func
-#else
-#define TRANS(func) _XimdXTrans/**/func
-#endif
-#endif /* XIM_t */
-
-#ifdef FS_t
-#if (__STDC__ && !defined(UNIXCPP)) || defined(ANSICPP)
-#define TRANS(func) _FSTrans##func
-#else
-#define TRANS(func) _FSTrans/**/func
-#endif
-#endif /* FS_t */
-
-#ifdef FONT_t
-#if (__STDC__ && !defined(UNIXCPP)) || defined(ANSICPP)
-#define TRANS(func) _FontTrans##func
-#else
-#define TRANS(func) _FontTrans/**/func
-#endif
-#endif /* FONT_t */
-
-#ifdef ICE_t
-#if (__STDC__ && !defined(UNIXCPP)) || defined(ANSICPP)
-#define TRANS(func) _IceTrans##func
-#else
-#define TRANS(func) _IceTrans/**/func
-#endif
-#endif /* ICE_t */
-
-#ifdef TEST_t
-#if (__STDC__ && !defined(UNIXCPP)) || defined(ANSICPP)
-#define TRANS(func) _TESTTrans##func
-#else
-#define TRANS(func) _TESTTrans/**/func
-#endif
-#endif /* TEST_t */
-
-#if !defined(TRANS)
-#if (__STDC__ && !defined(UNIXCPP)) || defined(ANSICPP)
-#define TRANS(func) _XTrans##func
-#else
-#define TRANS(func) _XTrans/**/func
-#endif
-#endif /* !TRANS */
-
-
-/*
- * Create a single address structure that can be used wherever
- * an address structure is needed. struct sockaddr is not big enough
- * to hold a sockadd_un, so we create this definition to have a single
- * structure that is big enough for all the structures we might need.
- *
- * This structure needs to be independent of the socket/TLI interface used.
- */
-
-#define XTRANS_MAX_ADDR_LEN    128     /* large enough to hold sun_path */
-
-typedef        struct {
-    unsigned char      addr[XTRANS_MAX_ADDR_LEN];
-} Xtransaddr;
-
-
-#ifdef LONG64
-typedef int BytesReadable_t;
-#else
-typedef long BytesReadable_t;
-#endif
-
-
-#if defined(WIN32) || (defined(USG) && !defined(CRAY) && !defined(umips) && !defined(MOTOROLA) && !defined(uniosu) && !defined(__sxg__))
-
-/*
- *      TRANS(Readv) and TRANS(Writev) use struct iovec, normally found
- *      in Berkeley systems in <sys/uio.h>.  See the readv(2) and writev(2)
- *      manual pages for details.
- */
-
-struct iovec {
-    caddr_t iov_base;
-    int iov_len;
-};
-
-#else
-#include <sys/uio.h>
-#endif
-
-typedef struct _XtransConnInfo *XtransConnInfo;
-
-
-/*
- * Transport Option definitions
- */
-
-#define TRANS_NONBLOCKING      1
-#define        TRANS_CLOSEONEXEC       2
-
-
-/*
- * Return values of Connect (0 is success)
- */
-
-#define TRANS_CONNECT_FAILED   -1
-#define TRANS_TRY_CONNECT_AGAIN -2
-
-
-/*
- * Return values of Accept (0 is success)
- */
-
-#define TRANS_ACCEPT_BAD_MALLOC                        -1
-#define TRANS_ACCEPT_FAILED                    -2
-#define TRANS_ACCEPT_MISC_ERROR                        -3
-
-
-/*
- * ResetListener return values
- */
-
-#define TRANS_RESET_NOOP       1
-#define TRANS_RESET_NEW_FD     2
-#define TRANS_RESET_FAILURE    3
-
-
-/*
- * Function prototypes for the exposed interface
- */
-
-#ifdef TRANS_CLIENT
-
-XtransConnInfo TRANS(OpenCOTSClient)(
-#if NeedFunctionPrototypes
-    char *             /* address */
-#endif
-);
-
-#endif /* TRANS_CLIENT */
-
-#ifdef TRANS_SERVER
-
-XtransConnInfo TRANS(OpenCOTSServer)(
-#if NeedFunctionPrototypes
-    char *             /* address */
-#endif
-);
-
-#endif /* TRANS_SERVER */
-
-#ifdef TRANS_CLIENT
-
-XtransConnInfo TRANS(OpenCLTSClient)(
-#if NeedFunctionPrototypes
-    char *             /* address */
-#endif
-);
-
-#endif /* TRANS_CLIENT */
-
-#ifdef TRANS_SERVER
-
-XtransConnInfo TRANS(OpenCLTSServer)(
-#if NeedFunctionPrototypes
-    char *             /* address */
-#endif
-);
-
-#endif /* TRANS_SERVER */
-
-#ifdef TRANS_REOPEN
-
-XtransConnInfo TRANS(ReopenCOTSServer)(
-#if NeedFunctionPrototypes
-    int,               /* trans_id */
-    int,               /* fd */
-    char *             /* port */
-#endif
-);
-
-XtransConnInfo TRANS(ReopenCLTSServer)(
-#if NeedFunctionPrototypes
-    int,               /* trans_id */
-    int,               /* fd */
-    char *             /* port */
-#endif
-);
-
-int TRANS(GetReopenInfo)(
-#if NeedFunctionPrototypes
-    XtransConnInfo,    /* ciptr */
-    int *,             /* trans_id */
-    int *,             /* fd */
-    char **            /* port */
-#endif
-);
-
-#endif /* TRANS_REOPEN */
-
-
-int TRANS(SetOption)(
-#if NeedFunctionPrototypes
-    XtransConnInfo,    /* ciptr */
-    int,               /* option */
-    int                        /* arg */
-#endif
-);
-
-#ifdef TRANS_SERVER
-
-int TRANS(CreateListener)(
-#if NeedFunctionPrototypes
-    XtransConnInfo,    /* ciptr */
-    char *             /* port */
-#endif
-);
-
-int TRANS(ResetListener)(
-#if NeedFunctionPrototypes
-    XtransConnInfo     /* ciptr */
-#endif
-);
-
-XtransConnInfo TRANS(Accept)(
-#if NeedFunctionPrototypes
-    XtransConnInfo,    /* ciptr */
-    int *              /* status */
-#endif
-);
-
-#endif /* TRANS_SERVER */
-
-#ifdef TRANS_CLIENT
-
-int TRANS(Connect)(
-#if NeedFunctionPrototypes
-    XtransConnInfo,    /* ciptr */
-    char *             /* address */
-#endif
-);
-
-#endif /* TRANS_CLIENT */
-
-int TRANS(BytesReadable)(
-#if NeedFunctionPrototypes
-    XtransConnInfo,    /* ciptr */
-    BytesReadable_t *  /* pend */
-#endif
-);
-
-int TRANS(Read)(
-#if NeedFunctionPrototypes
-    XtransConnInfo,    /* ciptr */
-    char *,            /* buf */
-    int                        /* size */
-#endif
-);
-
-int TRANS(Write)(
-#if NeedFunctionPrototypes
-    XtransConnInfo,    /* ciptr */
-    char *,            /* buf */
-    int                        /* size */
-#endif
-);
-
-int TRANS(Readv)(
-#if NeedFunctionPrototypes
-    XtransConnInfo,    /* ciptr */
-    struct iovec *,    /* buf */
-    int                        /* size */
-#endif
-);
-
-int TRANS(Writev)(
-#if NeedFunctionPrototypes
-    XtransConnInfo,    /* ciptr */
-    struct iovec *,    /* buf */
-    int                        /* size */
-#endif
-);
-
-int TRANS(Disconnect)(
-#if NeedFunctionPrototypes
-    XtransConnInfo     /* ciptr */
-#endif
-);
-
-int TRANS(Close)(
-#if NeedFunctionPrototypes
-    XtransConnInfo     /* ciptr */
-#endif
-);
-
-int TRANS(CloseForCloning)(
-#if NeedFunctionPrototypes
-    XtransConnInfo     /* ciptr */
-#endif
-);
-
-int TRANS(IsLocal)(
-#if NeedFunctionPrototypes
-    XtransConnInfo     /* ciptr */
-#endif
-);
-
-int TRANS(GetMyAddr)(
-#if NeedFunctionPrototypes
-    XtransConnInfo,    /* ciptr */
-    int *,             /* familyp */
-    int *,             /* addrlenp */
-    Xtransaddr **      /* addrp */
-#endif
-);
-
-int TRANS(GetPeerAddr)(
-#if NeedFunctionPrototypes
-    XtransConnInfo,    /* ciptr */
-    int *,             /* familyp */
-    int *,             /* addrlenp */
-    Xtransaddr **      /* addrp */
-#endif
-);
-
-int TRANS(GetConnectionNumber)(
-#if NeedFunctionPrototypes
-    XtransConnInfo     /* ciptr */
-#endif
-);
-
-#ifdef TRANS_SERVER
-
-int TRANS(MakeAllCOTSServerListeners)(
-#if NeedFunctionPrototypes
-    char *,            /* port */
-    int *,             /* partial */
-    int *,             /* count_ret */
-    XtransConnInfo **  /* ciptrs_ret */
-#endif
-);
-
-int TRANS(MakeAllCLTSServerListeners)(
-#if NeedFunctionPrototypes
-    char *,            /* port */
-    int *,             /* partial */
-    int *,             /* count_ret */
-    XtransConnInfo **  /* ciptrs_ret */
-#endif
-);
-
-#endif /* TRANS_SERVER */
-
-
-/*
- * Function Prototypes for Utility Functions.
- */
-
-#ifdef X11_t
-
-int TRANS(ConvertAddress)(
-#if NeedFunctionPrototypes
-    int *,             /* familyp */
-    int *,             /* addrlenp */
-    Xtransaddr *       /* addrp */
-#endif
-);
-
-#endif /* X11_t */
-
-#ifdef ICE_t
-
-char *
-TRANS(GetMyNetworkId)(
-#if NeedFunctionPrototypes
-    XtransConnInfo     /* ciptr */
-#endif
-);
-
-char *
-TRANS(GetPeerNetworkId)(
-#if NeedFunctionPrototypes
-    XtransConnInfo     /* ciptr */
-#endif
-);
-
-#endif /* ICE_t */
-
-#endif /* _XTRANS_H_ */
diff --git a/x11/IMdkit/i18nAttr.c b/x11/IMdkit/i18nAttr.c
deleted file mode 100644 (file)
index a52370b..0000000
+++ /dev/null
@@ -1,175 +0,0 @@
-/******************************************************************
-         Copyright 1994, 1995 by Sun Microsystems, Inc.
-         Copyright 1993, 1994 by Hewlett-Packard Company
-Permission to use, copy, modify, distribute, and sell this software
-and its documentation for any purpose is hereby granted without fee,
-provided that the above copyright notice appear in all copies and
-that both that copyright notice and this permission notice appear
-in supporting documentation, and that the name of Sun Microsystems, Inc.
-and Hewlett-Packard not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior permission.
-Sun Microsystems, Inc. and Hewlett-Packard make no representations about
-the suitability of this software for any purpose.  It is provided "as is"
-without express or implied warranty.
-SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL
-WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
-RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
-CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
-IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-  Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
-
-    This version tidied and debugged by Steve Underwood May 1999
-******************************************************************/
-
-#include <X11/Xlib.h>
-#include <X11/Xresource.h>
-#include "IMdkit.h"
-#include "Xi18n.h"
-#include "XimFunc.h"
-
-typedef struct 
-{
-    char *name;
-    CARD16 type;
-} IMListOfAttr;
-
-typedef struct
-{
-    char *name;
-    CARD8 major_opcode;
-    CARD8 minor_opcode;
-} IMExtList;
-
-IMListOfAttr Default_IMattr[] =
-{
-    {XNQueryInputStyle,   XimType_XIMStyles},
-/*    {XNQueryIMValuesList, XimType_XIMValuesList},    */
-    {(char *) NULL, (CARD16) 0}
-};
-
-IMListOfAttr Default_ICattr[] =
-{
-    {XNInputStyle,              XimType_CARD32},
-    {XNClientWindow,            XimType_Window},
-    {XNFocusWindow,             XimType_Window},
-    {XNFilterEvents,            XimType_CARD32},
-    {XNPreeditAttributes,       XimType_NEST},
-    {XNStatusAttributes,        XimType_NEST},
-    {XNFontSet,                 XimType_XFontSet},
-    {XNArea,                    XimType_XRectangle},
-    {XNAreaNeeded,              XimType_XRectangle},
-    {XNColormap,                XimType_CARD32},
-    {XNStdColormap,             XimType_CARD32},
-    {XNForeground,              XimType_CARD32},
-    {XNBackground,              XimType_CARD32},
-    {XNBackgroundPixmap,        XimType_CARD32},
-    {XNSpotLocation,            XimType_XPoint},
-    {XNLineSpace,               XimType_CARD32},
-    {XNPreeditState,            XimType_CARD32},
-    {XNSeparatorofNestedList,   XimType_SeparatorOfNestedList},
-    {(char *) NULL, 0}
-};
-
-IMExtList Default_Extension[] =
-{
-    {"XIM_EXT_MOVE", XIM_EXTENSION, XIM_EXT_MOVE},
-    {"XIM_EXT_SET_EVENT_MASK", XIM_EXTENSION, XIM_EXT_SET_EVENT_MASK},
-    {"XIM_EXT_FORWARD_KEYEVENT", XIM_EXTENSION, XIM_EXT_FORWARD_KEYEVENT},
-    {(char *) NULL, 0, 0}
-};
-
-static void CountAttrList(IMListOfAttr *attr, int *total_count)
-{
-    *total_count = 0;
-
-    while (attr->name != NULL)
-    {
-        attr++;
-        ++(*total_count);
-    }
-}
-
-static XIMAttr *CreateAttrList (Xi18n i18n_core,
-                                IMListOfAttr *attr,
-                                int *total_count)
-{
-    XIMAttr *args, *p;
-    unsigned int buf_size;
-
-    CountAttrList(attr, total_count);
-
-    buf_size = (unsigned) (*total_count + 1)*sizeof (XIMAttr);
-    args = (XIMAttr *) malloc (buf_size);
-    if (!args)
-        return (XIMAttr *) NULL;
-    /*endif*/
-    memset (args, 0, buf_size);
-
-    for (p = args;  attr->name != NULL;  attr++, p++)
-    {
-        p->name = attr->name;
-        p->length = strlen (attr->name);
-        p->type = (CARD16) attr->type;
-        p->attribute_id = XrmStringToQuark (p->name);
-        if (strcmp (p->name, XNPreeditAttributes) == 0)
-            i18n_core->address.preeditAttr_id = p->attribute_id;
-        else if (strcmp (p->name, XNStatusAttributes) == 0)
-            i18n_core->address.statusAttr_id = p->attribute_id;
-        else if (strcmp (p->name, XNSeparatorofNestedList) == 0)
-            i18n_core->address.separatorAttr_id = p->attribute_id;
-        /*endif*/
-    }
-    /*endfor*/
-    p->name = (char *) NULL;
-
-    return args;
-}
-
-void _Xi18nInitAttrList (Xi18n i18n_core)
-{
-    XIMAttr *args;
-    int        total_count;
-
-    /* init IMAttr list */
-    if (i18n_core->address.xim_attr)
-        XFree ((char *)i18n_core->address.xim_attr);
-    /*endif*/
-    args = CreateAttrList (i18n_core, Default_IMattr, &total_count);
-
-    i18n_core->address.im_attr_num = total_count;
-    i18n_core->address.xim_attr = (XIMAttr *)args;
-
-    /* init ICAttr list */
-    if (i18n_core->address.xic_attr)
-        XFree ((char *) i18n_core->address.xic_attr);
-    /*endif*/
-    args = CreateAttrList (i18n_core, Default_ICattr, &total_count);
-
-    i18n_core->address.ic_attr_num = total_count;
-    i18n_core->address.xic_attr = (XICAttr *) args;
-}
-
-void _Xi18nInitExtension(Xi18n i18n_core)
-{
-    register int i;
-    IMExtList *extensions = (IMExtList *) Default_Extension;
-    XIMExt *ext_list = (XIMExt *) i18n_core->address.extension;
-
-    for (i = 0;  extensions->name;  i++, ext_list++, extensions++)
-    {
-        ext_list->major_opcode = extensions->major_opcode;
-        ext_list->minor_opcode = extensions->minor_opcode;
-        ext_list->name = extensions->name;
-        ext_list->length = strlen(ext_list->name);
-    }
-    /*endfor*/
-    i18n_core->address.ext_num = i;
-}
diff --git a/x11/IMdkit/i18nClbk.c b/x11/IMdkit/i18nClbk.c
deleted file mode 100644 (file)
index b3edf3a..0000000
+++ /dev/null
@@ -1,513 +0,0 @@
-/******************************************************************
-         Copyright 1994, 1995 by Sun Microsystems, Inc.
-         Copyright 1993, 1994 by Hewlett-Packard Company
-Permission to use, copy, modify, distribute, and sell this software
-and its documentation for any purpose is hereby granted without fee,
-provided that the above copyright notice appear in all copies and
-that both that copyright notice and this permission notice appear
-in supporting documentation, and that the name of Sun Microsystems, Inc.
-and Hewlett-Packard not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior permission.
-Sun Microsystems, Inc. and Hewlett-Packard make no representations about
-the suitability of this software for any purpose.  It is provided "as is"
-without express or implied warranty.
-SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL
-WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
-RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
-CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
-IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-  Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
-
-    This version tidied and debugged by Steve Underwood May 1999
-******************************************************************/
-
-#include <X11/Xlib.h>
-#include "IMdkit.h"
-#include "Xi18n.h"
-#include "FrameMgr.h"
-#include "XimFunc.h"
-
-int _Xi18nGeometryCallback (XIMS ims, IMProtocol *call_data)
-{
-    Xi18n i18n_core = ims->protocol;
-    FrameMgr fm;
-    extern XimFrameRec geometry_fr[];
-    register int total_size;
-    unsigned char *reply = NULL;
-    IMGeometryCBStruct *geometry_CB =
-        (IMGeometryCBStruct *) &call_data->geometry_callback;
-    CARD16 connect_id = call_data->any.connect_id;
-
-    fm = FrameMgrInit (geometry_fr,
-                       NULL,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-
-    total_size = FrameMgrGetTotalSize (fm);
-    reply = (unsigned char *) malloc (total_size);
-    if (!reply)
-    {
-        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
-        return False;
-    }
-    /*endif*/
-    memset (reply, 0, total_size);
-    FrameMgrSetBuffer (fm, reply);
-
-    FrameMgrPutToken (fm, connect_id);
-    FrameMgrPutToken (fm, geometry_CB->icid);
-
-    _Xi18nSendMessage (ims,
-                       connect_id,
-                       XIM_GEOMETRY,
-                       0,
-                       reply,
-                       total_size);
-    FrameMgrFree (fm);
-    XFree (reply);
-
-    /* XIM_GEOMETRY is an asyncronous protocol,
-       so return immediately. */
-    return True;
-}
-
-int _Xi18nPreeditStartCallback (XIMS ims, IMProtocol *call_data)
-{
-    Xi18n i18n_core = ims->protocol;
-    FrameMgr fm;
-    extern XimFrameRec preedit_start_fr[];
-    register int total_size;
-    unsigned char *reply = NULL;
-    IMPreeditCBStruct *preedit_CB =
-        (IMPreeditCBStruct*) &call_data->preedit_callback;
-    CARD16 connect_id = call_data->any.connect_id;
-
-    fm = FrameMgrInit (preedit_start_fr,
-                       NULL,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-    total_size = FrameMgrGetTotalSize (fm);
-    reply = (unsigned char *) malloc (total_size);
-    if (!reply)
-    {
-        _Xi18nSendMessage(ims, connect_id, XIM_ERROR, 0, 0, 0);
-        return False;
-    }
-    /*endif*/
-    memset (reply, 0, total_size);
-    FrameMgrSetBuffer (fm, reply);
-
-    FrameMgrPutToken (fm, connect_id);
-    FrameMgrPutToken (fm, preedit_CB->icid);
-
-    _Xi18nSendMessage (ims,
-                       connect_id,
-                       XIM_PREEDIT_START,
-                       0,
-                       reply,
-                       total_size);
-    FrameMgrFree (fm);
-    XFree (reply);
-
-    return True;
-}
-
-int _Xi18nPreeditDrawCallback (XIMS ims, IMProtocol *call_data)
-{
-    Xi18n i18n_core = ims->protocol;
-    FrameMgr fm;
-    extern XimFrameRec preedit_draw_fr[];
-    register int total_size;
-    unsigned char *reply = NULL;
-    IMPreeditCBStruct *preedit_CB =
-        (IMPreeditCBStruct *) &call_data->preedit_callback;
-    XIMPreeditDrawCallbackStruct *draw =
-        (XIMPreeditDrawCallbackStruct *) &preedit_CB->todo.draw;
-    CARD16 connect_id = call_data->any.connect_id;
-    register int feedback_count;
-    register int i;
-    BITMASK32 status = 0x0;
-
-    if (draw->text->length == 0)
-        status = 0x00000001;
-    else if (draw->text->feedback[0] == 0)
-        status = 0x00000002;
-    /*endif*/
-
-    fm = FrameMgrInit (preedit_draw_fr,
-                       NULL,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-
-    /* set length of preedit string */
-    FrameMgrSetSize (fm, draw->text->length);
-
-    /* set iteration count for list of feedback */
-    for (i = 0;  draw->text->feedback[i] != 0;  i++)
-        ;
-    /*endfor*/
-    feedback_count = i;
-    FrameMgrSetIterCount (fm, feedback_count);
-
-    total_size = FrameMgrGetTotalSize (fm);
-    reply = (unsigned char *) malloc (total_size);
-    if (!reply)
-    {
-        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
-        return False;
-    }
-    /*endif*/
-    memset (reply, 0, total_size);
-    FrameMgrSetBuffer (fm, reply);
-
-    FrameMgrPutToken (fm, connect_id);
-    FrameMgrPutToken (fm, preedit_CB->icid);
-    FrameMgrPutToken (fm, draw->caret);
-    FrameMgrPutToken (fm, draw->chg_first);
-    FrameMgrPutToken (fm, draw->chg_length);
-    FrameMgrPutToken (fm, status);
-    FrameMgrPutToken (fm, draw->text->length);
-    FrameMgrPutToken (fm, draw->text->string);
-    for (i = 0;  i < feedback_count;  i++)
-        FrameMgrPutToken (fm, draw->text->feedback[i]);
-    /*endfor*/
-    
-    _Xi18nSendMessage (ims,
-                       connect_id,
-                       XIM_PREEDIT_DRAW,
-                       0,
-                       reply,
-                       total_size);
-    FrameMgrFree (fm);
-    XFree (reply);
-
-    /* XIM_PREEDIT_DRAW is an asyncronous protocol, so return immediately. */
-    return True;
-}
-
-int _Xi18nPreeditCaretCallback (XIMS ims, IMProtocol *call_data)
-{
-    Xi18n i18n_core = ims->protocol;
-    FrameMgr fm;
-    extern XimFrameRec preedit_caret_fr[];
-    register int total_size;
-    unsigned char *reply = NULL;
-    IMPreeditCBStruct *preedit_CB =
-        (IMPreeditCBStruct*) &call_data->preedit_callback;
-    XIMPreeditCaretCallbackStruct *caret =
-        (XIMPreeditCaretCallbackStruct *) &preedit_CB->todo.caret;
-    CARD16 connect_id = call_data->any.connect_id;
-
-    fm = FrameMgrInit (preedit_caret_fr,
-                       NULL,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-
-    total_size = FrameMgrGetTotalSize (fm);
-    reply = (unsigned char *) malloc (total_size);
-    if (!reply)
-    {
-        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
-        return False;
-    }
-    /*endif*/
-    memset (reply, 0, total_size);
-    FrameMgrSetBuffer (fm, reply);
-
-    FrameMgrPutToken (fm, connect_id);
-    FrameMgrPutToken (fm, preedit_CB->icid);
-    FrameMgrPutToken (fm, caret->position);
-    FrameMgrPutToken (fm, caret->direction);
-    FrameMgrPutToken (fm, caret->style);
-
-    _Xi18nSendMessage (ims,
-                       connect_id,
-                       XIM_PREEDIT_CARET,
-                       0,
-                       reply,
-                       total_size);
-    FrameMgrFree (fm);
-    XFree (reply);
-
-    return True;
-}
-
-int _Xi18nPreeditDoneCallback (XIMS ims, IMProtocol *call_data)
-{
-    Xi18n i18n_core = ims->protocol;
-    FrameMgr fm;
-    extern XimFrameRec preedit_done_fr[];
-    register int total_size;
-    unsigned char *reply = NULL;
-    IMPreeditCBStruct *preedit_CB =
-        (IMPreeditCBStruct *) &call_data->preedit_callback;
-    CARD16 connect_id = call_data->any.connect_id;
-
-    fm = FrameMgrInit (preedit_done_fr,
-                       NULL,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-
-    total_size = FrameMgrGetTotalSize (fm);
-    reply = (unsigned char *) malloc (total_size);
-    if (!reply)
-    {
-        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
-        return False;
-    }
-    /*endif*/
-    memset (reply, 0, total_size);
-    FrameMgrSetBuffer (fm, reply);
-
-    FrameMgrPutToken (fm, connect_id);
-    FrameMgrPutToken (fm, preedit_CB->icid);
-
-    _Xi18nSendMessage (ims,
-                       connect_id,
-                       XIM_PREEDIT_DONE,
-                       0,
-                       reply,
-                       total_size);
-    FrameMgrFree (fm);
-    XFree (reply);
-
-    /* XIM_PREEDIT_DONE is an asyncronous protocol, so return immediately. */
-    return True;
-}
-
-int _Xi18nStatusStartCallback (XIMS ims, IMProtocol *call_data)
-{
-    Xi18n i18n_core = ims->protocol;
-    FrameMgr fm;
-    extern XimFrameRec status_start_fr[];
-    register int total_size;
-    unsigned char *reply = NULL;
-    IMStatusCBStruct *status_CB =
-        (IMStatusCBStruct*) &call_data->status_callback;
-    CARD16 connect_id = call_data->any.connect_id;
-
-    fm = FrameMgrInit (status_start_fr,
-                       NULL,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-    total_size = FrameMgrGetTotalSize (fm);
-    reply = (unsigned char *) malloc (total_size);
-    if (!reply)
-    {
-        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
-        return False;
-    }
-    /*endif*/
-    memset (reply, 0, total_size);
-    FrameMgrSetBuffer (fm, reply);
-
-    FrameMgrPutToken (fm, connect_id);
-    FrameMgrPutToken (fm, status_CB->icid);
-
-    _Xi18nSendMessage (ims,
-                       connect_id,
-                       XIM_STATUS_START,
-                       0,
-                       reply,
-                       total_size);
-    FrameMgrFree (fm);
-    XFree (reply);
-
-    /* XIM_STATUS_START is an asyncronous protocol, so return immediately. */
-    return True;
-}
-
-int _Xi18nStatusDrawCallback (XIMS ims, IMProtocol *call_data)
-{
-    Xi18n i18n_core = ims->protocol;
-    FrameMgr fm = (FrameMgr)0;
-    extern XimFrameRec status_draw_text_fr[];
-    extern XimFrameRec status_draw_bitmap_fr[];
-    register int total_size = 0;
-    unsigned char *reply = NULL;
-    IMStatusCBStruct *status_CB =
-        (IMStatusCBStruct *) &call_data->status_callback;
-    XIMStatusDrawCallbackStruct *draw =
-        (XIMStatusDrawCallbackStruct *) &status_CB->todo.draw;
-    CARD16 connect_id = call_data->any.connect_id;
-    register int feedback_count;
-    register int i;
-    BITMASK32 status = 0x0;
-
-    switch (draw->type)
-    {
-    case XIMTextType:
-        fm = FrameMgrInit (status_draw_text_fr,
-                           NULL,
-                           _Xi18nNeedSwap (i18n_core, connect_id));
-
-        if (draw->data.text->length == 0)
-            status = 0x00000001;
-        else if (draw->data.text->feedback[0] == 0)
-            status = 0x00000002;
-        /*endif*/
-        
-        /* set length of status string */
-        FrameMgrSetSize(fm, draw->data.text->length);
-        /* set iteration count for list of feedback */
-        for (i = 0;  draw->data.text->feedback[i] != 0;  i++)
-            ;
-        /*endfor*/
-        feedback_count = i;
-        FrameMgrSetIterCount (fm, feedback_count);
-
-        total_size = FrameMgrGetTotalSize (fm);
-        reply = (unsigned char *) malloc (total_size);
-        if (!reply)
-        {
-            _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
-            return False;
-        }
-        /*endif*/
-        memset (reply, 0, total_size);
-        FrameMgrSetBuffer (fm, reply);
-
-        FrameMgrPutToken (fm, connect_id);
-        FrameMgrPutToken (fm, status_CB->icid);
-        FrameMgrPutToken (fm, draw->type);
-        FrameMgrPutToken (fm, status);
-        FrameMgrPutToken (fm, draw->data.text->length);
-        FrameMgrPutToken (fm, draw->data.text->string);
-        for (i = 0;  i < feedback_count;  i++)
-            FrameMgrPutToken (fm, draw->data.text->feedback[i]);
-        /*endfor*/
-        break;
-
-    case XIMBitmapType:
-        fm = FrameMgrInit (status_draw_bitmap_fr,
-                           NULL,
-                           _Xi18nNeedSwap (i18n_core, connect_id));
-
-        total_size = FrameMgrGetTotalSize (fm);
-        reply = (unsigned char *) malloc (total_size);
-        if (!reply)
-        {
-            _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
-            return False;
-        }
-        /*endif*/
-        memset (reply, 0, total_size);
-        FrameMgrSetBuffer (fm, reply);
-
-        FrameMgrPutToken (fm, connect_id);
-        FrameMgrPutToken (fm, status_CB->icid);
-        FrameMgrPutToken (fm, draw->data.bitmap);
-        break;
-    }
-    /*endswitch*/
-    _Xi18nSendMessage (ims,
-                       connect_id,
-                       XIM_STATUS_DRAW,
-                       0,
-                       reply,
-                       total_size);
-    FrameMgrFree (fm);
-    XFree (reply);
-
-    /* XIM_STATUS_DRAW is an asyncronous protocol, so return immediately. */
-    return True;
-}
-
-int _Xi18nStatusDoneCallback (XIMS ims, IMProtocol *call_data)
-{
-    Xi18n i18n_core = ims->protocol;
-    FrameMgr fm;
-    extern XimFrameRec status_done_fr[];
-    register int total_size;
-    unsigned char *reply = NULL;
-    IMStatusCBStruct *status_CB =
-        (IMStatusCBStruct *) &call_data->status_callback;
-    CARD16 connect_id = call_data->any.connect_id;
-
-    fm = FrameMgrInit (status_done_fr,
-                       NULL,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-
-    total_size = FrameMgrGetTotalSize (fm);
-    reply = (unsigned char *) malloc (total_size);
-    if (!reply)
-    {
-        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
-        return False;
-    }
-    /*endif*/
-    memset (reply, 0, total_size);
-    FrameMgrSetBuffer (fm, reply);
-
-    FrameMgrPutToken (fm, connect_id);
-    FrameMgrPutToken (fm, status_CB->icid);
-
-    _Xi18nSendMessage (ims,
-                       connect_id,
-                       XIM_STATUS_DONE,
-                       0,
-                       reply,
-                       total_size);
-    FrameMgrFree (fm);
-    XFree (reply);
-
-    /* XIM_STATUS_DONE is an asyncronous protocol, so return immediately. */
-    return True;
-}
-
-int _Xi18nStringConversionCallback (XIMS ims, IMProtocol *call_data)
-{
-    Xi18n i18n_core = ims->protocol;
-    FrameMgr fm;
-    extern XimFrameRec str_conversion_fr[];
-    register int total_size;
-    unsigned char *reply = NULL;
-    IMStrConvCBStruct *call_back =
-        (IMStrConvCBStruct *) &call_data->strconv_callback;
-    XIMStringConversionCallbackStruct *strconv =
-        (XIMStringConversionCallbackStruct *) &call_back->strconv;
-    CARD16 connect_id = call_data->any.connect_id;
-
-    fm = FrameMgrInit (str_conversion_fr,
-                       NULL,
-                      _Xi18nNeedSwap (i18n_core, connect_id));
-
-    total_size = FrameMgrGetTotalSize (fm);
-    reply = (unsigned char *) malloc (total_size);
-    if (!reply)
-    {
-        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
-        return False;
-    }
-    /*endif*/
-    memset (reply, 0, total_size);
-    FrameMgrSetBuffer (fm, reply);
-
-    FrameMgrPutToken (fm, connect_id);
-    FrameMgrPutToken (fm, call_back->icid);
-    FrameMgrPutToken (fm, strconv->position);
-    FrameMgrPutToken (fm, strconv->direction);
-    FrameMgrPutToken (fm, strconv->operation);
-
-    _Xi18nSendMessage (ims, connect_id,
-                       XIM_STR_CONVERSION,
-                       0,
-                       reply,
-                       total_size);
-    FrameMgrFree (fm);
-    XFree (reply);
-
-    /* XIM_STR_CONVERSION is a syncronous protocol,
-       so should wait here for XIM_STR_CONVERSION_REPLY. */
-    if (i18n_core->methods.wait (ims,
-                                 connect_id,
-                                 XIM_STR_CONVERSION_REPLY,
-                                 0) == False)
-    {
-        return False;
-    }
-    /*endif*/
-    return True;
-}
diff --git a/x11/IMdkit/i18nIMProto.c b/x11/IMdkit/i18nIMProto.c
deleted file mode 100644 (file)
index 618da9d..0000000
+++ /dev/null
@@ -1,773 +0,0 @@
-/******************************************************************
-Copyright 1993, 1994 by Digital Equipment Corporation, Maynard, Massachusetts,
-Copyright 1993, 1994 by Hewlett-Packard Company
-Copyright 1994, 1995 by Sun Microsystems, Inc.
-                        All Rights Reserved
-Permission to use, copy, modify, and distribute this software and its 
-documentation for any purpose and without fee is hereby granted, 
-provided that the above copyright notice appear in all copies and that
-both that copyright notice and this permission notice appear in 
-supporting documentation, and that the names of Digital or MIT not be
-used in advertising or publicity pertaining to distribution of the
-software without specific, written prior permission.  
-DIGITAL AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL WARRANTIES WITH REGARD
-TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
-FITNESS, IN NO EVENT SHALL DIGITAL AND HEWLETT-PACKARD COMPANY BE LIABLE
-FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
-RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
-CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
-CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-  Author: Hiroyuki Miyamoto  Digital Equipment Corporation
-                             miyamoto@jrd.dec.com
-         Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
-
-    This version tidied and debugged by Steve Underwood May 1999
-******************************************************************/
-
-/* Protocol Packet frames */
-
-#include "FrameMgr.h"
-
-/* Data type definitions */
-
-static XimFrameRec ximattr_fr[] =
-{
-    _FRAME(BIT16),             /* attribute ID */
-    _FRAME(BIT16),             /* type of the value */
-    _FRAME(BIT16),             /* length of im-attribute */
-    _FRAME(BARRAY),            /* im-attribute */
-    _PAD4(2),
-    _FRAME(EOL),
-};
-
-static XimFrameRec xicattr_fr[] =
-{
-    _FRAME(BIT16),             /* attribute ID */
-    _FRAME(BIT16),             /* type of the value */
-    _FRAME(BIT16),             /* length of ic-attribute */
-    _FRAME(BARRAY),            /* ic-attribute */
-    _PAD4(2),
-    _FRAME(EOL),
-};
-
-static XimFrameRec ximattribute_fr[] =
-{
-    _FRAME(BIT16),             /* attribute ID */
-    _FRAME(BIT16),             /* value length */
-    _FRAME(BARRAY),             /* value */
-    _PAD4(1),
-    _FRAME(EOL),
-};
-
-static XimFrameRec xicattribute_fr[] =
-{
-    _FRAME(BIT16),             /* attribute ID */
-    _FRAME(BIT16),             /* value length */
-    _FRAME(BARRAY),             /* value */
-    _PAD4(1),
-    _FRAME(EOL),
-};
-
-static XimFrameRec ximtriggerkey_fr[] =
-{
-    _FRAME(BIT32),             /* keysym */
-    _FRAME(BIT32),             /* modifier */
-    _FRAME(BIT32),             /* modifier mask */
-    _FRAME(EOL),
-};
-
-static XimFrameRec encodinginfo_fr[] =
-{
-    _FRAME(BIT16),             /* length of encoding info */
-    _FRAME(BARRAY),            /* encoding info */
-    _PAD4(2),
-    _FRAME(EOL),
-};
-
-static XimFrameRec str_fr[] =
-{
-    _FRAME(BIT8),              /* number of byte */
-    _FRAME(BARRAY),            /* string */
-    _FRAME(EOL),
-};
-
-static XimFrameRec xpcs_fr[] =
-{
-    _FRAME(BIT16),             /* length of string in bytes */
-    _FRAME(BARRAY),            /* string */
-    _PAD4(2),
-};
-
-static XimFrameRec ext_fr[] =
-{
-    _FRAME(BIT8),              /* extension major-opcode */
-    _FRAME(BIT8),              /* extension minor-opcode */
-    _FRAME(BIT16),             /* length of extension name */
-    _FRAME(BARRAY),            /* extension name */
-    _PAD4(1),
-    _FRAME(EOL),
-};
-
-static XimFrameRec inputstyle_fr[] =
-{
-    _FRAME(BIT32),             /* inputstyle */
-    _FRAME(EOL),
-};
-/* Protocol definitions */
-
-xim_externaldef XimFrameRec attr_head_fr[] =
-{
-    _FRAME(BIT16),     /* attribute id */
-    _FRAME(BIT16),     /* attribute length */
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec short_fr[] =
-{
-    _FRAME(BIT16),     /* value */
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec long_fr[] =
-{
-    _FRAME(BIT32),     /* value */
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec xrectangle_fr[] =
-{
-    _FRAME(BIT16),     /* x */
-    _FRAME(BIT16),     /* y */
-    _FRAME(BIT16),     /* width */
-    _FRAME(BIT16),     /* height */
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec xpoint_fr[] =
-{
-    _FRAME(BIT16),     /* x */
-    _FRAME(BIT16),     /* y */
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec fontset_fr[] =
-{
-    _FRAME(BIT16),     /* length of base font name */
-    _FRAME(BARRAY),    /* base font name list */
-    _PAD4(2),          /* unused */
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec input_styles_fr[] =
-{
-    _FRAME(BIT16),             /* number of list */
-    _PAD4(1),                  /* unused */
-    _FRAME(ITER),              /* XIMStyle list */
-    _FRAME(POINTER),
-    _PTR(inputstyle_fr),
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec packet_header_fr[] =
-{
-    _FRAME(BIT8),              /* major-opcode */
-    _FRAME(BIT8),              /* minor-opcode */
-    _FRAME(BIT16),             /* length */
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec error_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _FRAME(BIT16),             /* flag */
-    _FRAME(BIT16),             /* Error Code */
-    _FRAME(BIT16),             /* length of error detail */
-    _FRAME(BIT16),             /* type of error detail */
-    _FRAME(BARRAY),            /* error detail */
-    _PAD4(1),
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec connect_fr[] =
-{
-    _FRAME(BIT8),              /* byte order */
-    _PAD2(1),                  /* unused */
-    _FRAME(BIT16),             /* client-major-protocol-version */
-    _FRAME(BIT16),             /* client-minor-protocol-version */
-    _BYTE_COUNTER(BIT16, 1),   /* length of client-auth-protocol-names */
-    _FRAME(ITER),              /* client-auth-protocol-names */
-    _FRAME(POINTER),
-    _PTR(xpcs_fr),
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec connect_reply_fr[] =
-{
-    _FRAME(BIT16),             /* server-major-protocol-version */
-    _FRAME(BIT16),             /* server-minor-protocol-version */
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec auth_required_fr[] =
-{
-    _FRAME(BIT8),              /* auth-protocol-index */
-    _FRAME(BIT8),              /* auth-data1 */
-    _FRAME(BARRAY),            /* auth-data2 */
-    _PAD4(3),
-    _FRAME(EOL),
-};
-
-
-xim_externaldef XimFrameRec auth_reply_fr[] =
-{
-    _FRAME(BIT8),
-    _FRAME(BARRAY),
-    _PAD4(2),
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec auth_next_fr[] =
-{
-    _FRAME(BIT8),              /* auth-data1 */
-    _FRAME(BARRAY),            /* auth-data2 */
-    _PAD4(2),
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec auth_setup_fr[] =
-{
-    _BYTE_COUNTER(BIT16, 2),   /* number of client-auth-protocol-names */
-    _PAD4(1),                  /* unused */
-    _FRAME(ITER),              /* server-auth-protocol-names */
-    _FRAME(POINTER),
-    _PTR(xpcs_fr),
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec auth_ng_fr[] =
-{
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec disconnect_fr[] =
-{
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec disconnect_reply_fr[] =
-{
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec open_fr[] =
-{
-    _FRAME(POINTER),           /* locale name */
-    _PTR(str_fr),
-    _PAD4(1),
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec open_reply_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _BYTE_COUNTER(BIT16, 1),   /* byte length of IM attributes supported */
-    _FRAME(ITER),              /* IM attribute supported */
-    _FRAME(POINTER),
-    _PTR(ximattr_fr),
-    _BYTE_COUNTER(BIT16, 2),   /* number of IC attribute supported */
-    _PAD4(1),                  /* unused */
-    _FRAME(ITER),              /* IC attribute supported */
-    _FRAME(POINTER),
-    _PTR(xicattr_fr),
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec close_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _PAD4(1),                  /* unused */
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec close_reply_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _PAD4(1),                  /* unused */
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec register_triggerkeys_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _PAD4(1),                  /* unused */
-    _BYTE_COUNTER(BIT32, 1),    /* byte length of on-keys */
-    _FRAME(ITER),              /* on-keys list */
-    _FRAME(POINTER),
-    _PTR(ximtriggerkey_fr),
-    _BYTE_COUNTER(BIT32, 1),   /* byte length of off-keys */
-    _FRAME(ITER),              /* off-keys list */
-    _FRAME(POINTER),
-    _PTR(ximtriggerkey_fr),
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec trigger_notify_fr[] =
-{
-    _FRAME(BIT16),             /* input-mehotd-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _FRAME(BIT32),             /* flag */
-    _FRAME(BIT32),             /* index of keys list */
-    _FRAME(BIT32),             /* client-select-event-mask */
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec trigger_notify_reply_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec set_event_mask_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _FRAME(BIT32),             /* forward-event-mask */
-    _FRAME(BIT32),             /* synchronous-event-mask */
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec encoding_negotiation_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _BYTE_COUNTER(BIT16, 1),   /* byte length of encodings listed by name */
-    _FRAME(ITER),              /* supported list of encoding in IM library */
-    _FRAME(POINTER),
-    _PTR(str_fr),
-    _PAD4(1),
-    _BYTE_COUNTER(BIT16, 2),   /* byte length of encodings listed by
-                                       detailed data */
-    _PAD4(1),
-    _FRAME(ITER),              /* list of encodings supported in the
-                                  IM library */
-    _FRAME(POINTER),
-    _PTR(encodinginfo_fr),
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec encoding_negotiation_reply_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* category of the encoding determined */
-    _FRAME(BIT16),             /* index of the encoding dterminated */
-    _PAD4(1),
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec query_extension_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _BYTE_COUNTER(BIT16, 1),   /* byte length of extensions supported
-                                  by the IM library */
-    _FRAME(ITER),              /* extensions supported by the IM library */
-    _FRAME(POINTER),
-    _PTR(str_fr),
-    _PAD4(1),
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec query_extension_reply_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _BYTE_COUNTER(BIT16, 1),   /* byte length of extensions supported
-                                  by the IM server */
-    _FRAME(ITER),              /* list of extensions supported by the
-                                  IM server */
-    _FRAME(POINTER),
-    _PTR(ext_fr),
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec get_im_values_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _BYTE_COUNTER(BIT16, 1),   /* byte length of im-attribute-id */
-    _FRAME(ITER),              /* im-attribute-id */
-    _FRAME(BIT16),
-    _PAD4(1),
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec get_im_values_reply_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _BYTE_COUNTER(BIT16, 1),   /* byte length of im-attribute returned */
-    _FRAME(ITER),              /* im-attribute returned */
-    _FRAME(POINTER),
-    _PTR(ximattribute_fr),
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec create_ic_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _BYTE_COUNTER(BIT16, 1),   /* byte length of ic-attributes */
-    _FRAME(ITER),              /* ic-attributes */
-    _FRAME(POINTER),
-    _PTR(xicattribute_fr),
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec create_ic_reply_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec destroy_ic_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec destroy_ic_reply_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec set_ic_values_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _BYTE_COUNTER(BIT16, 2),   /* byte length of ic-attributes */
-    _PAD4(1),
-    _FRAME(ITER),              /* ic-attribute */
-    _FRAME(POINTER),
-    _PTR(xicattribute_fr),
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec set_ic_values_reply_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec get_ic_values_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _BYTE_COUNTER(BIT16, 1),   /* byte length of ic-attribute-id */
-    _FRAME(ITER),              /* ic-attribute */
-    _FRAME(BIT16),
-    _PAD4(2),
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec get_ic_values_reply_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _BYTE_COUNTER(BIT16, 2),   /* byte length of ic-attribute */
-    _PAD4(1),
-    _FRAME(ITER),              /* ic-attribute */
-    _FRAME(POINTER),
-    _PTR(xicattribute_fr),
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec set_ic_focus_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec unset_ic_focus_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec forward_event_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _FRAME(BIT16),             /* flag */
-    _FRAME(BIT16),             /* sequence number */
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec wire_keyevent_fr[] = {
-    _FRAME(BIT8),              /* type */
-    _FRAME(BIT8),              /* detail */
-    _FRAME(BIT16),             /* serial number */
-    _FRAME(BIT32),             /* time */
-    _FRAME(BIT32),             /* root */
-    _FRAME(BIT32),             /* window */
-    _FRAME(BIT32),             /* subwindow */
-    _FRAME(BIT16),             /* rootX */
-    _FRAME(BIT16),             /* rootY */
-    _FRAME(BIT16),             /* X */
-    _FRAME(BIT16),             /* Y */
-    _FRAME(BIT16),             /* state */
-    _FRAME(BIT8),              /* sameScreen */
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec sync_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec sync_reply_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _FRAME(EOL),
-};
-
-#if 0
-xim_externaldef XimFrameRec commit_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _FRAME(BIT16),             /* flag */
-    _FRAME(BIT16),             /* byte length of committed string */
-    _FRAME(BARRAY),            /* committed string */
-    _PAD4(1),
-    _BYTE_COUNTER(BIT16, 1),   /* byte length of keysym */
-    _FRAME(ITER),              /* keysym */
-    _FRAME(BIT32),
-    _PAD4(1),
-    _FRAME(EOL),
-};
-#endif
-
-xim_externaldef XimFrameRec commit_chars_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _FRAME(BIT16),             /* flag */
-    _FRAME(BIT16),             /* byte length of committed string */
-    _FRAME(BARRAY),            /* committed string */
-    _PAD4(1),
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec commit_both_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _FRAME(BIT16),             /* flag */
-    _PAD4(1),                  /* unused */
-    _FRAME(BIT32),             /* keysym */
-    _FRAME(BIT16),             /* byte length of committed string */
-    _FRAME(BARRAY),            /* committed string */
-    _PAD4(2),
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec reset_ic_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec reset_ic_reply_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _FRAME(BIT16),             /* byte length of committed string */
-    _FRAME(BARRAY),            /* committed string */
-    _PAD4(2),
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec geometry_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec str_conversion_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _FRAME(BIT32),             /* XIMStringConversionPosition */
-    _FRAME(BIT32),             /* XIMStringConversionType */
-    _FRAME(BIT32),             /* XIMStringConversionOperation */
-    _FRAME(BIT16),             /* length to multiply the
-                                  XIMStringConversionType */
-    _FRAME(BIT16),             /* length of the string to be
-                                  substituted */
-#if 0
-    _FRAME(BARRAY),            /* string */
-    _PAD4(1),
-#endif
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec str_conversion_reply_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _FRAME(BIT32),             /* XIMStringConversionFeedback */
-    _FRAME(BIT16),             /* length of the retrieved string */
-    _FRAME(BARRAY),            /* retrieved string */
-    _PAD4(2),
-    _BYTE_COUNTER(BIT16, 2),   /* number of feedback array */
-    _PAD4(1),
-    _FRAME(ITER),              /* feedback array */
-    _FRAME(BIT32),
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec preedit_start_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec preedit_start_reply_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _FRAME(BIT32),             /* return value */
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec preedit_draw_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _FRAME(BIT32),             /* caret */
-    _FRAME(BIT32),             /* chg_first */
-    _FRAME(BIT32),             /* chg_length */
-    _FRAME(BIT32),             /* status */
-    _FRAME(BIT16),             /* length of preedit string */
-    _FRAME(BARRAY),            /* preedit string */
-    _PAD4(2),
-    _BYTE_COUNTER(BIT16, 2),   /* number of feedback array */
-    _PAD4(1),
-    _FRAME(ITER),              /* feedback array */
-    _FRAME(BIT32),
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec preedit_caret_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _FRAME(BIT32),             /* position */
-    _FRAME(BIT32),             /* direction */
-    _FRAME(BIT32),             /* style */
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec preedit_caret_reply_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _FRAME(BIT32),             /* position */
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec preedit_done_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec status_start_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec status_draw_text_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _FRAME(BIT32),             /* type */
-    _FRAME(BIT32),             /* status */
-    _FRAME(BIT16),             /* length of status string */
-    _FRAME(BARRAY),            /* status string */
-    _PAD4(2),
-    _BYTE_COUNTER(BIT16, 2),   /* number of feedback array */
-    _PAD4(1),
-    _FRAME(ITER),              /* feedback array */
-    _FRAME(BIT32),
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec status_draw_bitmap_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _FRAME(BIT32),             /* type */
-    _FRAME(BIT32),             /* pixmap data */
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec status_done_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec ext_set_event_mask_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _FRAME(BIT32),             /* filter-event-mask */
-    _FRAME(BIT32),             /* intercept-event-mask */
-    _FRAME(BIT32),             /* select-event-mask */
-    _FRAME(BIT32),             /* forward-event-mask */
-    _FRAME(BIT32),             /* synchronous-event-mask */
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec ext_forward_keyevent_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _FRAME(BIT16),             /* flag */
-    _FRAME(BIT16),             /* sequence number */
-    _FRAME(BIT8),              /* xEvent.u.u.type */
-    _FRAME(BIT8),              /* keycode */
-    _FRAME(BIT16),             /* state */
-    _FRAME(BIT32),             /* time */
-    _FRAME(BIT32),             /* window */
-    _FRAME(EOL),
-};
-
-xim_externaldef XimFrameRec ext_move_fr[] =
-{
-    _FRAME(BIT16),             /* input-method-ID */
-    _FRAME(BIT16),             /* input-context-ID */
-    _FRAME(BIT16),             /* X */
-    _FRAME(BIT16),             /* Y */
-    _FRAME(EOL),
-};
diff --git a/x11/IMdkit/i18nIc.c b/x11/IMdkit/i18nIc.c
deleted file mode 100644 (file)
index 61b576f..0000000
+++ /dev/null
@@ -1,1106 +0,0 @@
-/******************************************************************
-         Copyright 1994, 1995 by Sun Microsystems, Inc.
-         Copyright 1993, 1994 by Hewlett-Packard Company
-Permission to use, copy, modify, distribute, and sell this software
-and its documentation for any purpose is hereby granted without fee,
-provided that the above copyright notice appear in all copies and
-that both that copyright notice and this permission notice appear
-in supporting documentation, and that the name of Sun Microsystems, Inc.
-and Hewlett-Packard not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior permission.
-Sun Microsystems, Inc. and Hewlett-Packard make no representations about
-the suitability of this software for any purpose.  It is provided "as is"
-without express or implied warranty.
-SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL
-WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
-RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
-CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
-IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-  Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
-
-    This version tidied and debugged by Steve Underwood May 1999
-******************************************************************/
-
-#include <X11/Xlib.h>
-#include "IMdkit.h"
-#include "Xi18n.h"
-#include "FrameMgr.h"
-#include "XimFunc.h"
-
-#define IC_SIZE 64
-
-/* Set IC values */
-static void SetCardAttribute (XICAttribute *value_ret,
-                              char *p,
-                              XICAttr *ic_attr,
-                              int value_length,
-                              int need_swap,
-                              void **value_buf)
-{
-    FrameMgr fm;
-
-    /*endif*/
-    if (value_length == sizeof (CARD8))
-    {
-        memmove (*value_buf, p, value_length);
-    }
-    else if (value_length == sizeof (CARD16))
-    {
-        INT16 value;
-        extern XimFrameRec short_fr[];
-
-        fm = FrameMgrInit (short_fr, (char *) p, need_swap);
-        /* get data */
-        FrameMgrGetToken (fm, value);
-        FrameMgrFree (fm);
-        memmove (*value_buf, &value, value_length);
-    }
-    else if (value_length == sizeof(CARD32))
-    {
-        INT32 value;
-        extern XimFrameRec long_fr[];
-        
-        fm = FrameMgrInit (long_fr, (char *) p, need_swap);
-        /* get data */
-        FrameMgrGetToken (fm, value);
-        FrameMgrFree (fm);
-        memmove (*value_buf, &value, value_length);
-    }
-    /*endif*/
-    value_ret->attribute_id = ic_attr->attribute_id;
-    value_ret->name = ic_attr->name;
-    value_ret->name_length = ic_attr->length;
-    value_ret->type = ic_attr->type;
-    value_ret->value_length = value_length;
-    value_ret->value = *value_buf;
-    *value_buf += value_length;
-}
-
-static void SetFontAttribute (XICAttribute *value_ret,
-                              char *p,
-                              XICAttr *ic_attr,
-                              int value_length,
-                              int need_swap,
-                              void **value_buf)
-{
-    char *base_name;
-    CARD16 base_length;
-    FrameMgr fm;
-    extern XimFrameRec fontset_fr[];
-
-    fm = FrameMgrInit (fontset_fr, (char *) p, need_swap);
-    /* get data */
-    FrameMgrGetToken (fm, base_length);
-    FrameMgrSetSize (fm, base_length);
-
-    /*endif*/
-    FrameMgrGetToken (fm, base_name);
-    FrameMgrFree(fm);
-    strncpy ((char *) (*value_buf), base_name, base_length);
-    ((char *) *value_buf)[base_length] = (char) 0;
-
-    value_ret->attribute_id = ic_attr->attribute_id;
-    value_ret->name = ic_attr->name;
-    value_ret->name_length = ic_attr->length;
-    value_ret->type = ic_attr->type;
-    value_ret->value_length = value_length;
-    value_ret->value = *value_buf;
-
-    *value_buf += (base_length + 1);
-}
-
-static void SetPointAttribute (XICAttribute *value_ret,
-                               char *p,
-                               XICAttr *ic_attr,
-                               int value_length,
-                               int need_swap,
-                               void **value_buf)
-{
-    XPoint *buf;
-    FrameMgr fm;
-    extern XimFrameRec xpoint_fr[];
-
-    buf = (XPoint *) (*value_buf);
-
-    fm = FrameMgrInit (xpoint_fr, (char *) p, need_swap);
-    /* get data */
-    FrameMgrGetToken (fm, buf->x);
-    FrameMgrGetToken (fm, buf->y);
-    FrameMgrFree (fm);
-
-    value_ret->attribute_id = ic_attr->attribute_id;
-    value_ret->name = ic_attr->name;
-    value_ret->name_length = ic_attr->length;
-    value_ret->type = ic_attr->type;
-    value_ret->value_length = value_length;
-    value_ret->value = (char *) buf;
-
-    *value_buf += value_length;
-}
-
-static void SetRectAttribute (XICAttribute *value_ret,
-                              char *p,
-                              XICAttr *ic_attr,
-                              int value_length,
-                              int need_swap,
-                              void **value_buf)
-{
-    XRectangle *buf;
-    FrameMgr fm;
-    extern XimFrameRec xrectangle_fr[];
-
-    buf = (XRectangle *) (*value_buf);
-    fm = FrameMgrInit (xrectangle_fr, (char *) p, need_swap);
-    /* get data */
-    FrameMgrGetToken (fm, buf->x);
-    FrameMgrGetToken (fm, buf->y);
-    FrameMgrGetToken (fm, buf->width);
-    FrameMgrGetToken (fm, buf->height);
-    FrameMgrFree (fm);
-
-    value_ret->attribute_id = ic_attr->attribute_id;
-    value_ret->name = ic_attr->name;
-    value_ret->name_length = ic_attr->length;
-    value_ret->type = ic_attr->type;
-    value_ret->value_length = value_length;
-    value_ret->value = (char *) buf;
-
-    *value_buf += value_length;
-}
-
-#if 0
-static void SetHotKeyAttribute (XICAttribute *value_ret,
-                                char *p,
-                                XICAttr *ic_attr,
-                                int value_length,
-                                int need_swap,
-                                void **value_buf)
-{
-    INT32 list_number;
-    XIMTriggerKey *hotkeys;
-
-    memmove (&list_number, p, sizeof(INT32)); p += sizeof(INT32);
-
-    hotkeys = (XIMTriggerKey *) (*value_buf);
-
-    memmove (hotkeys, p, list_number*sizeof (XIMTriggerKey));
-
-    value_ret->attribute_id = ic_attr->attribute_id;
-    value_ret->name = ic_attr->name;
-    value_ret->name_length = ic_attr->length;
-    value_ret->type = ic_attr->type;
-    value_ret->value_length = value_length;
-    value_ret->value = (char *) hotkeys;
-
-    *value_buf += value_length;
-}
-#endif
-
-/* get IC values */
-static void GetAttrHeader (unsigned char *rec,
-                           XICAttribute *list,
-                           int need_swap)
-{
-    FrameMgr fm;
-    extern XimFrameRec attr_head_fr[];
-
-    fm = FrameMgrInit (attr_head_fr, (char *) rec, need_swap);
-    /* put data */
-    FrameMgrPutToken (fm, list->attribute_id);
-    FrameMgrPutToken (fm, list->value_length);
-    FrameMgrFree (fm);
-}
-
-static void GetCardAttribute (char *rec, XICAttribute *list, int need_swap)
-{
-    FrameMgr fm;
-    unsigned char *recp = (unsigned char *) rec;
-
-    GetAttrHeader (recp, list, need_swap);
-    recp += sizeof (CARD16)*2;
-
-    if (list->value_length == sizeof (CARD8))
-    {
-        memmove (recp, list->value, list->value_length);
-    }
-    else if (list->value_length == sizeof (CARD16))
-    {
-        INT16 *value = (INT16 *) list->value;
-        extern XimFrameRec short_fr[];
-
-        fm = FrameMgrInit (short_fr, (char *) recp, need_swap);
-        /* put data */
-        FrameMgrPutToken (fm, *value);
-        FrameMgrFree (fm);
-    }
-    else if (list->value_length == sizeof (CARD32))
-    {
-        INT32 *value = (INT32 *) list->value;
-        extern XimFrameRec long_fr[];
-
-        fm = FrameMgrInit (long_fr, (char *) recp, need_swap);
-        /* put data */
-        FrameMgrPutToken (fm, *value);
-        FrameMgrFree (fm);
-    }
-    /*endif*/
-}
-
-static void GetFontAttribute(char *rec, XICAttribute *list, int need_swap)
-{
-    FrameMgr fm;
-    extern XimFrameRec fontset_fr[];
-    char *base_name = (char *) list->value;
-    unsigned char *recp = (unsigned char *) rec;
-
-    GetAttrHeader (recp, list, need_swap);
-    recp += sizeof (CARD16)*2;
-
-    fm = FrameMgrInit (fontset_fr, (char *)recp, need_swap);
-    /* put data */
-    FrameMgrSetSize (fm, list->value_length);
-    FrameMgrPutToken (fm, list->value_length);
-    FrameMgrPutToken (fm, base_name);
-    FrameMgrFree (fm);
-}
-
-static void GetRectAttribute (char *rec, XICAttribute *list, int need_swap)
-{
-    FrameMgr fm;
-    extern XimFrameRec xrectangle_fr[];
-    XRectangle *rect = (XRectangle *) list->value;
-    unsigned char *recp = (unsigned char *) rec;
-
-    GetAttrHeader (recp, list, need_swap);
-    recp += sizeof(CARD16)*2;
-
-    fm = FrameMgrInit (xrectangle_fr, (char *) recp, need_swap);
-    /* put data */
-    FrameMgrPutToken (fm, rect->x);
-    FrameMgrPutToken (fm, rect->y);
-    FrameMgrPutToken (fm, rect->width);
-    FrameMgrPutToken (fm, rect->height);
-    FrameMgrFree (fm);
-}
-
-static void GetPointAttribute (char *rec, XICAttribute *list, int need_swap)
-{
-    FrameMgr fm;
-    extern XimFrameRec xpoint_fr[];
-    XPoint *rect = (XPoint *) list->value;
-    unsigned char *recp = (unsigned char *) rec;
-
-    GetAttrHeader (recp, list, need_swap);
-    recp += sizeof(CARD16)*2;
-
-    fm = FrameMgrInit (xpoint_fr, (char *) recp, need_swap);
-    /* put data */
-    FrameMgrPutToken (fm, rect->x);
-    FrameMgrPutToken (fm, rect->y);
-    FrameMgrFree (fm);
-}
-
-static int ReadICValue (Xi18n i18n_core,
-                        CARD16 icvalue_id,
-                        int value_length,
-                        void *p,
-                        XICAttribute *value_ret,
-                        CARD16 *number_ret,
-                        int need_swap,
-                        void **value_buf)
-{
-    XICAttr *ic_attr = i18n_core->address.xic_attr;
-    int i;
-
-    *number_ret = (CARD16) 0;
-
-    for (i = 0;  i < i18n_core->address.ic_attr_num;  i++, ic_attr++)
-    {
-        if (ic_attr->attribute_id == icvalue_id)
-            break;
-        /*endif*/
-    }
-    /*endfor*/
-    switch (ic_attr->type)
-    {
-    case XimType_NEST:
-        {
-            int total_length = 0;
-            CARD16 attribute_ID;
-            INT16 attribute_length;
-            unsigned char *p1 = (unsigned char *) p;
-            CARD16 ic_len = 0;
-            CARD16 number;
-            FrameMgr fm;
-            extern XimFrameRec attr_head_fr[];
-
-            while (total_length < value_length)
-            {
-                fm = FrameMgrInit (attr_head_fr, (char *) p1, need_swap);
-                /* get data */
-                FrameMgrGetToken (fm, attribute_ID);
-                FrameMgrGetToken (fm, attribute_length);
-                FrameMgrFree (fm);
-                p1 += sizeof (CARD16)*2;
-                ReadICValue (i18n_core,
-                             attribute_ID,
-                             attribute_length,
-                             p1,
-                             (value_ret + ic_len),
-                             &number,
-                             need_swap,
-                             value_buf);
-                ic_len++;
-                *number_ret += number;
-                p1 += attribute_length;
-                p1 += IMPAD (attribute_length);
-                total_length += (CARD16) sizeof(CARD16)*2
-                                + (INT16) attribute_length
-                                + IMPAD (attribute_length);
-            }
-           /*endwhile*/
-            return ic_len;
-        }
-
-    case XimType_CARD8:
-    case XimType_CARD16:
-    case XimType_CARD32:
-    case XimType_Window:
-        SetCardAttribute (value_ret, p, ic_attr, value_length, need_swap, value_buf);
-        *number_ret = (CARD16) 1;
-        return *number_ret;
-
-    case XimType_XFontSet:
-        SetFontAttribute (value_ret, p, ic_attr, value_length, need_swap, value_buf);
-        *number_ret = (CARD16) 1;
-        return *number_ret;
-
-    case XimType_XRectangle:
-        SetRectAttribute (value_ret, p, ic_attr, value_length, need_swap, value_buf);
-        *number_ret = (CARD16) 1;
-        return *number_ret;
-
-    case XimType_XPoint:
-        SetPointAttribute(value_ret, p, ic_attr, value_length, need_swap, value_buf);
-        *number_ret = (CARD16) 1;
-        return *number_ret;
-
-#if 0
-    case XimType_XIMHotKeyTriggers:
-        SetHotKeyAttribute (value_ret, p, ic_attr, value_length, need_swap, value_buf);
-       *number_ret = (CARD16) 1;
-       return *number_ret;
-#endif
-    }
-    /*endswitch*/
-    return 0;
-}
-
-static XICAttribute *CreateNestedList (CARD16 attr_id,
-                                       XICAttribute *list,
-                                       int number,
-                                       int need_swap)
-{
-    XICAttribute *nest_list = NULL;
-    register int i;
-    char *values = NULL;
-    char *valuesp;
-    int value_length = 0;
-
-    if (number == 0)
-        return NULL;
-    /*endif*/
-    for (i = 0;  i < number;  i++)
-    {
-        value_length += sizeof (CARD16)*2;
-        value_length += list[i].value_length;
-        value_length += IMPAD (list[i].value_length);
-    }
-    /*endfor*/
-    if ((values = (char *) malloc (value_length)) == NULL)
-        return NULL;
-    /*endif*/
-    memset (values, 0, value_length);
-
-    valuesp = values;
-    for (i = 0;  i < number;  i++)
-    {
-        switch (list[i].type)
-        {
-        case XimType_CARD8:
-        case XimType_CARD16:
-        case XimType_CARD32:
-        case XimType_Window:
-            GetCardAttribute (valuesp, &list[i], need_swap);
-            break;
-
-        case XimType_XFontSet:
-            GetFontAttribute (valuesp, &list[i], need_swap);
-            break;
-
-        case XimType_XRectangle:
-            GetRectAttribute (valuesp, &list[i], need_swap);
-            break;
-
-        case XimType_XPoint:
-            GetPointAttribute (valuesp, &list[i], need_swap);
-            break;
-
-#if 0
-        case XimType_XIMHotKeyTriggers:
-            GetHotKeyAttribute (valuesp, &list[i], need_swap);
-            break;
-#endif
-        }
-        /*endswitch*/
-        valuesp += sizeof (CARD16)*2;
-        valuesp += list[i].value_length;
-        valuesp += IMPAD(list[i].value_length);
-    }
-    /*endfor*/
-    
-    nest_list = (XICAttribute *) malloc (sizeof (XICAttribute));
-    if (nest_list == NULL)
-        return NULL;
-    /*endif*/
-    memset (nest_list, 0, sizeof (XICAttribute));
-    nest_list->value = (void *) malloc (value_length);
-    if (nest_list->value == NULL)
-        return NULL;
-    /*endif*/
-    memset (nest_list->value, 0, sizeof (value_length));
-
-    nest_list->attribute_id = attr_id;
-    nest_list->value_length = value_length;
-    memmove (nest_list->value, values, value_length);
-
-    XFree (values);
-    return nest_list;
-}
-
-static Bool IsNestedList (Xi18n i18n_core, CARD16 icvalue_id)
-{
-    XICAttr *ic_attr = i18n_core->address.xic_attr;
-    int i;
-
-    for (i = 0;  i < i18n_core->address.ic_attr_num;  i++, ic_attr++)
-    {
-        if (ic_attr->attribute_id == icvalue_id)
-        {
-            if (ic_attr->type == XimType_NEST)
-                return True;
-            /*endif*/
-            return False;
-        }
-        /*endif*/
-    }
-    /*endfor*/
-    return False;
-}
-
-static Bool IsSeparator (Xi18n i18n_core, CARD16 icvalue_id)
-{
-    return (i18n_core->address.separatorAttr_id == icvalue_id);
-}
-
-static int GetICValue (Xi18n i18n_core,
-                       XICAttribute *attr_ret,
-                       CARD16 *id_list,
-                       int list_num)
-{
-    XICAttr *xic_attr = i18n_core->address.xic_attr;
-    register int i;
-    register int j;
-    register int n;
-
-    i =
-    n = 0;
-    if (IsNestedList (i18n_core, id_list[i]))
-    {
-        i++;
-        while (i < list_num  &&  !IsSeparator (i18n_core, id_list[i]))
-        {
-            for (j = 0;  j < i18n_core->address.ic_attr_num;  j++)
-            {
-                if (xic_attr[j].attribute_id == id_list[i])
-                {
-                    attr_ret[n].attribute_id = xic_attr[j].attribute_id;
-                    attr_ret[n].name_length = xic_attr[j].length;
-                    attr_ret[n].name = malloc (xic_attr[j].length + 1);
-                   strcpy(attr_ret[n].name, xic_attr[j].name);
-                    attr_ret[n].type = xic_attr[j].type;
-                    n++;
-                    i++;
-                    break;
-                }
-                /*endif*/
-            }
-            /*endfor*/
-        }
-        /*endwhile*/
-    }
-    else
-    {
-        for (j = 0;  j < i18n_core->address.ic_attr_num;  j++)
-        {
-            if (xic_attr[j].attribute_id == id_list[i])
-            {
-                attr_ret[n].attribute_id = xic_attr[j].attribute_id;
-                attr_ret[n].name_length = xic_attr[j].length;
-                attr_ret[n].name = malloc (xic_attr[j].length + 1);
-               strcpy(attr_ret[n].name, xic_attr[j].name);
-                attr_ret[n].type = xic_attr[j].type;
-                n++;
-                break;
-            }
-            /*endif*/
-        }
-        /*endfor*/
-    }
-    /*endif*/
-    return n;
-}
-
-static void SwapAttributes (XICAttribute *list,
-                          int number){
-    FrameMgr fm;
-    CARD16 c16;
-    extern XimFrameRec short_fr[];
-    CARD32 c32;
-    extern XimFrameRec long_fr[];
-    XPoint xpoint;
-    extern XimFrameRec xpoint_fr[];
-    XRectangle xrect;
-    extern XimFrameRec xrectangle_fr[];
-    int i;
-
-    for (i = 0; i < number; ++i, ++list) {
-       if (list->value == NULL)
-           continue;
-       switch (list->type) {
-       case XimType_CARD16:
-           fm = FrameMgrInit (short_fr, (char *)list->value, 1);
-           FrameMgrGetToken (fm, c16);
-           memmove(list->value, &c16, sizeof(CARD16));
-           FrameMgrFree (fm);
-           break;
-       case XimType_CARD32:
-       case XimType_Window:
-           fm = FrameMgrInit (long_fr, (char *)list->value, 1);
-           FrameMgrGetToken (fm, c32);
-           memmove(list->value, &c32, sizeof(CARD32));
-           FrameMgrFree (fm);
-           break;
-       case XimType_XRectangle:
-           fm = FrameMgrInit (xrectangle_fr, (char *)list->value, 1);
-           FrameMgrGetToken (fm, xrect);
-           memmove(list->value, &xrect, sizeof(XRectangle));
-           FrameMgrFree (fm);
-           break;
-       case XimType_XPoint:
-           fm = FrameMgrInit (xpoint_fr, (char *)list->value, 1);
-           FrameMgrGetToken (fm, xpoint);
-           memmove(list->value, &xpoint, sizeof(XPoint));
-           FrameMgrFree (fm);
-           break;
-       default:
-           break;
-       }
-    }
-}
-
-/* called from CreateICMessageProc and SetICValueMessageProc */
-void _Xi18nChangeIC (XIMS ims,
-                     IMProtocol *call_data,
-                     unsigned char *p,
-                     int create_flag)
-{
-    Xi18n i18n_core = ims->protocol;
-    FrameMgr fm;
-    FmStatus status;
-    CARD16 byte_length;
-    register int total_size;
-    unsigned char *reply = NULL;
-    register int i;
-    register int attrib_num;
-    XICAttribute *attrib_list;
-    XICAttribute pre_attr[IC_SIZE];
-    XICAttribute sts_attr[IC_SIZE];
-    XICAttribute ic_attr[IC_SIZE];
-    CARD16 preedit_ic_num = 0;
-    CARD16 status_ic_num = 0;
-    CARD16 ic_num = 0;
-    CARD16 connect_id = call_data->any.connect_id;
-    IMChangeICStruct *changeic = (IMChangeICStruct *) &call_data->changeic;
-    extern XimFrameRec create_ic_fr[];
-    extern XimFrameRec create_ic_reply_fr[];
-    extern XimFrameRec set_ic_values_fr[];
-    extern XimFrameRec set_ic_values_reply_fr[];
-    CARD16 input_method_ID;
-    void *value_buf = NULL;
-    void *value_buf_ptr;
-
-    register int total_value_length = 0;
-
-    memset (pre_attr, 0, sizeof (XICAttribute)*IC_SIZE);
-    memset (sts_attr, 0, sizeof (XICAttribute)*IC_SIZE);
-    memset (ic_attr, 0, sizeof (XICAttribute)*IC_SIZE);
-
-    if (create_flag == True)
-    {
-        fm = FrameMgrInit (create_ic_fr,
-                           (char *) p,
-                           _Xi18nNeedSwap (i18n_core, connect_id));
-        /* get data */
-        FrameMgrGetToken (fm, input_method_ID);
-        FrameMgrGetToken (fm, byte_length);
-    }
-    else
-    {
-        fm = FrameMgrInit (set_ic_values_fr,
-                           (char *) p,
-                           _Xi18nNeedSwap (i18n_core, connect_id));
-        /* get data */
-        FrameMgrGetToken (fm, input_method_ID);
-        FrameMgrGetToken (fm, changeic->icid);
-        FrameMgrGetToken (fm, byte_length);
-    }
-    /*endif*/
-    attrib_list = (XICAttribute *) malloc (sizeof (XICAttribute)*IC_SIZE);
-    if (!attrib_list)
-    {
-        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
-        return;
-    }
-    /*endif*/
-    memset (attrib_list, 0, sizeof(XICAttribute)*IC_SIZE);
-
-    attrib_num = 0;
-    while (FrameMgrIsIterLoopEnd (fm, &status) == False)
-    {
-        void *value;
-        int value_length;
-        
-        FrameMgrGetToken (fm, attrib_list[attrib_num].attribute_id);
-        FrameMgrGetToken (fm, value_length);
-        FrameMgrSetSize (fm, value_length);
-        attrib_list[attrib_num].value_length = value_length;
-        FrameMgrGetToken (fm, value);
-        attrib_list[attrib_num].value = (void *) malloc (value_length + 1);
-        memmove (attrib_list[attrib_num].value, value, value_length);
-       ((char *)attrib_list[attrib_num].value)[value_length] = '\0';
-        attrib_num++;
-        total_value_length += (value_length + 1);
-    }
-    /*endwhile*/
-
-    value_buf = (void *) malloc (total_value_length);
-    value_buf_ptr = value_buf;
-
-    if (!value_buf)
-    {
-        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
-        for (i = 0;  i < attrib_num;  i++)
-            XFree (attrib_list[i].value);
-        /*endfor*/
-        XFree (attrib_list);
-        return;
-    }
-    /*endif*/
-
-    for (i = 0;  i < attrib_num;  i++)
-    {
-        CARD16 number;
-        
-        if (IsNestedList (i18n_core, attrib_list[i].attribute_id))
-        {
-            if (attrib_list[i].attribute_id
-                == i18n_core->address.preeditAttr_id)
-            {
-                ReadICValue (i18n_core,
-                             attrib_list[i].attribute_id,
-                             attrib_list[i].value_length,
-                             attrib_list[i].value,
-                             &pre_attr[preedit_ic_num],
-                             &number,
-                             _Xi18nNeedSwap(i18n_core, connect_id),
-                             &value_buf_ptr);
-                preedit_ic_num += number;
-            }
-            else if (attrib_list[i].attribute_id == i18n_core->address.statusAttr_id)
-            {
-                ReadICValue (i18n_core,
-                             attrib_list[i].attribute_id,
-                             attrib_list[i].value_length,
-                             attrib_list[i].value,
-                             &sts_attr[status_ic_num],
-                             &number,
-                             _Xi18nNeedSwap (i18n_core, connect_id),
-                             &value_buf_ptr);
-                status_ic_num += number;
-            }
-            else
-            {
-                /* another nested list.. possible? */
-            }
-            /*endif*/
-        }
-        else
-        {
-            ReadICValue (i18n_core,
-                         attrib_list[i].attribute_id,
-                         attrib_list[i].value_length,
-                         attrib_list[i].value,
-                         &ic_attr[ic_num],
-                         &number,
-                         _Xi18nNeedSwap (i18n_core, connect_id),
-                         &value_buf_ptr);
-            ic_num += number;
-        }
-        /*endif*/
-    }
-    /*endfor*/
-    for (i = 0;  i < attrib_num;  i++)
-        XFree (attrib_list[i].value);
-    /*endfor*/
-    XFree (attrib_list);
-
-    FrameMgrFree (fm);
-
-    changeic->preedit_attr_num = preedit_ic_num;
-    changeic->status_attr_num = status_ic_num;
-    changeic->ic_attr_num = ic_num;
-    changeic->preedit_attr = pre_attr;
-    changeic->status_attr = sts_attr;
-    changeic->ic_attr = ic_attr;
-
-    if (i18n_core->address.improto)
-    {
-        if (!(i18n_core->address.improto(ims, call_data))) {
-            XFree (value_buf);
-            return;
-        }
-        /*endif*/
-    }
-
-    XFree (value_buf);
-
-    /*endif*/
-    if (create_flag == True)
-    {
-        fm = FrameMgrInit (create_ic_reply_fr,
-                           NULL,
-                           _Xi18nNeedSwap (i18n_core, connect_id));
-    }
-    else
-    {
-        fm = FrameMgrInit (set_ic_values_reply_fr,
-                           NULL,
-                           _Xi18nNeedSwap (i18n_core, connect_id));
-    }
-    /*endif*/
-    total_size = FrameMgrGetTotalSize (fm);
-    reply = (unsigned char *) malloc (total_size);
-    
-    if (!reply)
-    {
-        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
-        return;
-    }
-    /*endif*/
-    memset (reply, 0, total_size);
-    FrameMgrSetBuffer (fm, reply);
-
-    FrameMgrPutToken (fm, input_method_ID);
-    FrameMgrPutToken (fm, changeic->icid);
-
-    if (create_flag == True)
-    {
-        _Xi18nSendMessage (ims,
-                           connect_id,
-                           XIM_CREATE_IC_REPLY,
-                           0,
-                           reply,
-                           total_size);
-    }
-    else
-    {
-        _Xi18nSendMessage (ims,
-                           connect_id,
-                           XIM_SET_IC_VALUES_REPLY,
-                           0,
-                           reply,
-                           total_size);
-    }
-    /*endif*/
-    if (create_flag == True)
-    {
-        int on_key_num = i18n_core->address.on_keys.count_keys;
-        int off_key_num = i18n_core->address.off_keys.count_keys;
-
-        if (on_key_num == 0  &&  off_key_num == 0)
-        {
-            long mask;
-
-            if (i18n_core->address.imvalue_mask & I18N_FILTERMASK)
-                mask = i18n_core->address.filterevent_mask;
-            else
-                mask = DEFAULT_FILTER_MASK;
-            /*endif*/
-            /* static event flow is default */
-            _Xi18nSetEventMask (ims,
-                                connect_id,
-                                input_method_ID,
-                                changeic->icid,
-                                mask,
-                                ~mask);
-        }
-        /*endif*/
-    }
-    /*endif*/
-    FrameMgrFree (fm);
-    XFree(reply);
-}
-
-/* called from GetICValueMessageProc */
-void _Xi18nGetIC (XIMS ims, IMProtocol *call_data, unsigned char *p)
-{
-    Xi18n i18n_core = ims->protocol;
-    FrameMgr fm;
-    FmStatus status;
-    extern XimFrameRec get_ic_values_fr[];
-    extern XimFrameRec get_ic_values_reply_fr[];
-    CARD16 byte_length;
-    register int total_size;
-    unsigned char *reply = NULL;
-    XICAttribute *preedit_ret = NULL;
-    XICAttribute *status_ret = NULL;
-    register int i;
-    register int number;
-    int iter_count;
-    CARD16 *attrID_list;
-    XICAttribute pre_attr[IC_SIZE];
-    XICAttribute sts_attr[IC_SIZE];
-    XICAttribute ic_attr[IC_SIZE];
-    CARD16 pre_count = 0;
-    CARD16 sts_count = 0;
-    CARD16 ic_count = 0;
-    IMChangeICStruct *getic = (IMChangeICStruct *) &call_data->changeic;
-    CARD16 connect_id = call_data->any.connect_id;
-    CARD16 input_method_ID;
-
-    memset (pre_attr, 0, sizeof (XICAttribute)*IC_SIZE);
-    memset (sts_attr, 0, sizeof (XICAttribute)*IC_SIZE);
-    memset (ic_attr, 0, sizeof (XICAttribute)*IC_SIZE);
-
-    fm = FrameMgrInit (get_ic_values_fr,
-                       (char *) p,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-
-    /* get data */
-    FrameMgrGetToken (fm, input_method_ID);
-    FrameMgrGetToken (fm, getic->icid);
-    FrameMgrGetToken (fm, byte_length);
-
-    attrID_list = (CARD16 *) malloc (sizeof (CARD16)*IC_SIZE);  /* bogus */
-    memset (attrID_list, 0, sizeof (CARD16)*IC_SIZE);
-
-    number = 0;
-    while (FrameMgrIsIterLoopEnd (fm, &status) == False)
-        FrameMgrGetToken (fm, attrID_list[number++]);
-    /*endwhile*/
-    FrameMgrFree (fm);
-
-    i = 0;
-    while (i < number)
-    {
-        int read_number;
-        
-        if (IsNestedList (i18n_core, attrID_list[i]))
-        {
-            if (attrID_list[i] == i18n_core->address.preeditAttr_id)
-            {
-                read_number = GetICValue (i18n_core,
-                                          &pre_attr[pre_count],
-                                          &attrID_list[i],
-                                          number);
-                i += read_number + 1;
-                pre_count += read_number;
-            }
-            else if (attrID_list[i] == i18n_core->address.statusAttr_id)
-            {
-                read_number = GetICValue (i18n_core,
-                                          &sts_attr[sts_count],
-                                          &attrID_list[i],
-                                          number);
-                i += read_number + 1;
-                sts_count += read_number;
-            }
-            else
-            {
-                /* another nested list.. possible? */
-            }
-            /*endif*/
-        }
-        else
-        {
-            read_number = GetICValue (i18n_core,
-                                      &ic_attr[ic_count],
-                                      &attrID_list[i],
-                                      number);
-            i += read_number;
-            ic_count += read_number;
-        }
-        /*endif*/
-    }
-    /*endwhile*/
-    getic->preedit_attr_num = pre_count;
-    getic->status_attr_num = sts_count;
-    getic->ic_attr_num = ic_count;
-    getic->preedit_attr = pre_attr;
-    getic->status_attr = sts_attr;
-    getic->ic_attr = ic_attr;
-    if (i18n_core->address.improto)
-    {
-        if (!(i18n_core->address.improto (ims, call_data)))
-            return;
-        /*endif*/
-       if (_Xi18nNeedSwap (i18n_core, connect_id))
-         SwapAttributes(getic->ic_attr, getic->ic_attr_num);
-    }
-    /*endif*/
-    iter_count = getic->ic_attr_num;
-
-    preedit_ret = CreateNestedList (i18n_core->address.preeditAttr_id,
-                                    getic->preedit_attr,
-                                    getic->preedit_attr_num,
-                                    _Xi18nNeedSwap (i18n_core, connect_id));
-    if (preedit_ret)
-        iter_count++;
-    /*endif*/
-    status_ret = CreateNestedList (i18n_core->address.statusAttr_id,
-                                   getic->status_attr,
-                                   getic->status_attr_num,
-                                   _Xi18nNeedSwap (i18n_core, connect_id));
-    if (status_ret)
-        iter_count++;
-    /*endif*/
-
-    fm = FrameMgrInit (get_ic_values_reply_fr,
-                       NULL,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-
-    /* set iteration count for list of ic_attribute */
-    FrameMgrSetIterCount (fm, iter_count);
-
-    /* set length of BARRAY item in xicattribute_fr */
-    for (i = 0;  i < (int) getic->ic_attr_num;  i++)
-        FrameMgrSetSize (fm, ic_attr[i].value_length);
-    /*endfor*/
-    
-    if (preedit_ret)
-        FrameMgrSetSize (fm, preedit_ret->value_length);
-    /*endif*/
-    if (status_ret)
-        FrameMgrSetSize (fm, status_ret->value_length);
-    /*endif*/
-    total_size = FrameMgrGetTotalSize (fm);
-    reply = (unsigned char *) malloc (total_size);
-    if (reply == NULL)
-    {
-        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
-        return;
-    }
-    /*endif*/
-    memset (reply, 0, total_size);
-    FrameMgrSetBuffer (fm, reply);
-
-    FrameMgrPutToken (fm, input_method_ID);
-    FrameMgrPutToken (fm, getic->icid);
-
-    for (i = 0;  i < (int) getic->ic_attr_num;  i++)
-    {
-        FrameMgrPutToken (fm, ic_attr[i].attribute_id);
-        FrameMgrPutToken (fm, ic_attr[i].value_length);
-        FrameMgrPutToken (fm, ic_attr[i].value);
-    }
-    /*endfor*/
-    if (preedit_ret)
-    {
-        FrameMgrPutToken (fm, preedit_ret->attribute_id);
-        FrameMgrPutToken (fm, preedit_ret->value_length);
-        FrameMgrPutToken (fm, preedit_ret->value);
-    }
-    /*endif*/
-    if (status_ret)
-    {
-        FrameMgrPutToken (fm, status_ret->attribute_id);
-        FrameMgrPutToken (fm, status_ret->value_length);
-        FrameMgrPutToken (fm, status_ret->value);
-    }
-    /*endif*/
-    _Xi18nSendMessage (ims,
-                       connect_id,
-                       XIM_GET_IC_VALUES_REPLY,
-                       0,
-                       reply,
-                       total_size);
-    XFree (reply);
-    XFree (attrID_list);
-
-    for (i = 0;  i < (int) getic->ic_attr_num;  i++)
-    {
-       if (getic->ic_attr[i].name)
-           XFree (getic->ic_attr[i].name);
-       /*endif*/
-        if (getic->ic_attr[i].value)
-            XFree (getic->ic_attr[i].value);
-        /*endif*/
-    }
-    /*endfor*/
-    for (i = 0;  i < (int) getic->preedit_attr_num;  i++)
-    {
-       if (getic->preedit_attr[i].name)
-           XFree (getic->preedit_attr[i].name);
-       /*endif*/
-       if (getic->preedit_attr[i].value)
-           XFree (getic->preedit_attr[i].value);
-       /*endif*/
-    }
-    /*endfor*/
-    for (i = 0;  i < (int) getic->status_attr_num;  i++)
-    {
-       if (getic->status_attr[i].name)
-           XFree (getic->status_attr[i].name);
-       /*endif*/
-       if (getic->status_attr[i].value)
-           XFree (getic->status_attr[i].value);
-       /*endif*/
-    }
-    /*endfor*/
-    
-    if (preedit_ret)
-    {
-        XFree (preedit_ret->value);
-        XFree (preedit_ret);
-    }
-    /*endif*/
-    if (status_ret)
-    {
-        XFree (status_ret->value);
-        XFree (status_ret);
-    }
-    /*endif*/
-    FrameMgrFree (fm);
-}
diff --git a/x11/IMdkit/i18nMethod.c b/x11/IMdkit/i18nMethod.c
deleted file mode 100644 (file)
index 203f831..0000000
+++ /dev/null
@@ -1,1150 +0,0 @@
-/******************************************************************
-         Copyright 1994, 1995 by Sun Microsystems, Inc.
-         Copyright 1993, 1994 by Hewlett-Packard Company
-Permission to use, copy, modify, distribute, and sell this software
-and its documentation for any purpose is hereby granted without fee,
-provided that the above copyright notice appear in all copies and
-that both that copyright notice and this permission notice appear
-in supporting documentation, and that the name of Sun Microsystems, Inc.
-and Hewlett-Packard not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior permission.
-Sun Microsystems, Inc. and Hewlett-Packard make no representations about
-the suitability of this software for any purpose.  It is provided "as is"
-without express or implied warranty.
-SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL
-WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
-RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
-CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
-IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-  Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
-
-    This version tidied and debugged by Steve Underwood May 1999
-******************************************************************/
-
-#include <X11/Xlib.h>
-#include <X11/Xatom.h>
-#ifndef NEED_EVENTS
-#define NEED_EVENTS
-#endif
-#include <X11/Xproto.h>
-#undef NEED_EVENTS
-#include "FrameMgr.h"
-#include "IMdkit.h"
-#include "Xi18n.h"
-#include "XimFunc.h"
-
-extern Xi18nClient *_Xi18nFindClient (Xi18n, CARD16);
-
-static void *xi18n_setup (Display *, XIMArg *);
-static Status xi18n_openIM (XIMS);
-static Status xi18n_closeIM (XIMS);
-static char *xi18n_setIMValues (XIMS, XIMArg *);
-static char *xi18n_getIMValues (XIMS, XIMArg *);
-static Status xi18n_forwardEvent (XIMS, XPointer);
-static Status xi18n_commit (XIMS, XPointer);
-static int xi18n_callCallback (XIMS, XPointer);
-static int xi18n_preeditStart (XIMS, XPointer);
-static int xi18n_preeditEnd (XIMS, XPointer);
-static int xi18n_syncXlib (XIMS, XPointer);
-
-#ifndef XIM_SERVERS
-#define XIM_SERVERS "XIM_SERVERS"
-#endif
-static Atom XIM_Servers = None;
-
-
-IMMethodsRec Xi18n_im_methods =
-{
-    xi18n_setup,
-    xi18n_openIM,
-    xi18n_closeIM,
-    xi18n_setIMValues,
-    xi18n_getIMValues,
-    xi18n_forwardEvent,
-    xi18n_commit,
-    xi18n_callCallback,
-    xi18n_preeditStart,
-    xi18n_preeditEnd,
-    xi18n_syncXlib,
-};
-
-extern Bool _Xi18nCheckXAddress (Xi18n, TransportSW *, char *);
-extern Bool _Xi18nCheckTransAddress (Xi18n, TransportSW *, char *);
-
-TransportSW _TransR[] =
-{
-    {"X",               1, _Xi18nCheckXAddress},
-#ifdef TCPCONN
-    {"tcp",             3, _Xi18nCheckTransAddress},
-    {"local",           5, _Xi18nCheckTransAddress},
-#endif
-#ifdef DNETCONN
-    {"decnet",          6, _Xi18nCheckTransAddress},
-#endif
-    {(char *) NULL,     0, (Bool (*) ()) NULL}
-};
-
-static Bool GetInputStyles (Xi18n i18n_core, XIMStyles **p_style)
-{
-    Xi18nAddressRec *address = (Xi18nAddressRec *) &i18n_core->address;
-    XIMStyles *p;
-    int        i;
-
-    p = &address->input_styles;
-    if ((*p_style = (XIMStyles *) malloc (sizeof (XIMStyles)
-                                          + p->count_styles*sizeof (XIMStyle)))
-        == NULL)
-    {
-        return False;
-    }
-    /*endif*/
-    (*p_style)->count_styles = p->count_styles;
-    (*p_style)->supported_styles = (XIMStyle *) ((XPointer) *p_style + sizeof (XIMStyles));
-    for (i = 0;  i < (int) p->count_styles;  i++)
-        (*p_style)->supported_styles[i] = p->supported_styles[i];
-    /*endfor*/
-    return True;
-}
-
-static Bool GetOnOffKeys (Xi18n i18n_core, long mask, XIMTriggerKeys **p_key)
-{
-    Xi18nAddressRec *address = (Xi18nAddressRec *) &i18n_core->address;
-    XIMTriggerKeys *p;
-    int        i;
-
-    if (mask & I18N_ON_KEYS)
-        p = &address->on_keys;
-    else
-        p = &address->off_keys;
-    /*endif*/
-    if ((*p_key = (XIMTriggerKeys *) malloc (sizeof(XIMTriggerKeys)
-                                             + p->count_keys*sizeof(XIMTriggerKey)))
-        == NULL)
-    {
-        return False;
-    }
-    /*endif*/
-    (*p_key)->count_keys = p->count_keys;
-    (*p_key)->keylist =
-        (XIMTriggerKey *) ((XPointer) *p_key + sizeof(XIMTriggerKeys));
-    for (i = 0;  i < (int) p->count_keys;  i++)
-    {
-        (*p_key)->keylist[i].keysym = p->keylist[i].keysym;
-        (*p_key)->keylist[i].modifier = p->keylist[i].modifier;
-        (*p_key)->keylist[i].modifier_mask = p->keylist[i].modifier_mask;
-    }
-    /*endfor*/
-    return True;
-}
-
-static Bool GetEncodings(Xi18n i18n_core, XIMEncodings **p_encoding)
-{
-    Xi18nAddressRec *address = (Xi18nAddressRec *) &i18n_core->address;
-    XIMEncodings *p;
-    int        i;
-
-    p = &address->encoding_list;
-
-    if ((*p_encoding = (XIMEncodings *) malloc (sizeof (XIMEncodings)
-                                              + p->count_encodings*sizeof(XIMEncoding))) == NULL)
-    {
-        return False;
-    }
-    /*endif*/
-    (*p_encoding)->count_encodings = p->count_encodings;
-    (*p_encoding)->supported_encodings =
-        (XIMEncoding *) ((XPointer)*p_encoding + sizeof (XIMEncodings));
-    for (i = 0;  i < (int) p->count_encodings;  i++)
-    {
-        (*p_encoding)->supported_encodings[i]
-            = (char *) malloc (strlen (p->supported_encodings[i]) + 1);
-        strcpy ((*p_encoding)->supported_encodings[i],
-                p->supported_encodings[i]);
-    }
-    /*endif*/
-    return True;
-}
-
-static char *ParseArgs (Xi18n i18n_core, int mode, XIMArg *args)
-{
-    Xi18nAddressRec *address = (Xi18nAddressRec *) &i18n_core->address;
-    XIMArg *p;
-
-    if (mode == I18N_OPEN  ||  mode == I18N_SET)
-    {
-        for (p = args;  p->name != NULL;  p++)
-        {
-            if (strcmp (p->name, IMLocale) == 0)
-            {
-                if (address->imvalue_mask & I18N_IM_LOCALE)
-                    return IMLocale;
-                /*endif*/
-                address->im_locale = (char *) malloc (strlen (p->value) + 1);
-                if (!address->im_locale)
-                    return IMLocale;
-                /*endif*/
-                strcpy (address->im_locale, p->value);
-                address->imvalue_mask |= I18N_IM_LOCALE;
-            }
-            else if (strcmp (p->name, IMServerTransport) == 0)
-            {
-                if (address->imvalue_mask & I18N_IM_ADDRESS)
-                    return IMServerTransport;
-                /*endif*/
-                address->im_addr = (char *) malloc (strlen (p->value) + 1);
-                if (!address->im_addr)
-                    return IMServerTransport;
-                /*endif*/
-                strcpy(address->im_addr, p->value);
-                address->imvalue_mask |= I18N_IM_ADDRESS;
-            }
-            else if (strcmp (p->name, IMServerName) == 0)
-            {
-                if (address->imvalue_mask & I18N_IM_NAME)
-                    return IMServerName;
-                /*endif*/
-                address->im_name = (char *) malloc (strlen (p->value) + 1);
-                if (!address->im_name)
-                    return IMServerName;
-                /*endif*/
-                strcpy (address->im_name, p->value);
-                address->imvalue_mask |= I18N_IM_NAME;
-            }
-            else if (strcmp (p->name, IMServerWindow) == 0)
-            {
-                if (address->imvalue_mask & I18N_IMSERVER_WIN)
-                    return IMServerWindow;
-                /*endif*/
-                address->im_window = (Window) p->value;
-                address->imvalue_mask |= I18N_IMSERVER_WIN;
-            }
-            else if (strcmp (p->name, IMInputStyles) == 0)
-            {
-                if (address->imvalue_mask & I18N_INPUT_STYLES)
-                    return IMInputStyles;
-                /*endif*/
-                address->input_styles.count_styles =
-                    ((XIMStyles*)p->value)->count_styles;
-                address->input_styles.supported_styles =
-                    (XIMStyle *) malloc (sizeof (XIMStyle)*address->input_styles.count_styles);
-                if (address->input_styles.supported_styles == (XIMStyle *) NULL)
-                    return IMInputStyles;
-                /*endif*/
-                memmove (address->input_styles.supported_styles,
-                         ((XIMStyles *) p->value)->supported_styles,
-                         sizeof (XIMStyle)*address->input_styles.count_styles);
-                address->imvalue_mask |= I18N_INPUT_STYLES;
-            }
-            else if (strcmp (p->name, IMProtocolHandler) == 0)
-            {
-                address->improto = (IMProtoHandler) p->value;
-                address->imvalue_mask |= I18N_IM_HANDLER;
-            }
-            else if (strcmp (p->name, IMOnKeysList) == 0)
-            {
-                if (address->imvalue_mask & I18N_ON_KEYS)
-                    return IMOnKeysList;
-                /*endif*/
-                address->on_keys.count_keys =
-                    ((XIMTriggerKeys *) p->value)->count_keys;
-                address->on_keys.keylist =
-                    (XIMTriggerKey *) malloc (sizeof (XIMTriggerKey)*address->on_keys.count_keys);
-                if (address->on_keys.keylist == (XIMTriggerKey *) NULL)
-                    return IMOnKeysList;
-                /*endif*/
-                memmove (address->on_keys.keylist,
-                         ((XIMTriggerKeys *) p->value)->keylist,
-                         sizeof (XIMTriggerKey)*address->on_keys.count_keys);
-                address->imvalue_mask |= I18N_ON_KEYS;
-            }
-            else if (strcmp (p->name, IMOffKeysList) == 0)
-            {
-                if (address->imvalue_mask & I18N_OFF_KEYS)
-                    return IMOffKeysList;
-                /*endif*/
-                address->off_keys.count_keys =
-                    ((XIMTriggerKeys *) p->value)->count_keys;
-                address->off_keys.keylist =
-                    (XIMTriggerKey *) malloc (sizeof (XIMTriggerKey)*address->off_keys.count_keys);
-                if (address->off_keys.keylist == (XIMTriggerKey *) NULL)
-                    return IMOffKeysList;
-                /*endif*/
-                memmove (address->off_keys.keylist,
-                         ((XIMTriggerKeys *) p->value)->keylist,
-                         sizeof (XIMTriggerKey)*address->off_keys.count_keys);
-                address->imvalue_mask |= I18N_OFF_KEYS;
-            }
-            else if (strcmp (p->name, IMEncodingList) == 0)
-            {
-                if (address->imvalue_mask & I18N_ENCODINGS)
-                    return IMEncodingList;
-                /*endif*/
-                address->encoding_list.count_encodings =
-                    ((XIMEncodings *) p->value)->count_encodings;
-                address->encoding_list.supported_encodings =
-                    (XIMEncoding *) malloc (sizeof (XIMEncoding)*address->encoding_list.count_encodings);
-                if (address->encoding_list.supported_encodings
-                    == (XIMEncoding *) NULL)
-                {
-                    return IMEncodingList;
-                }
-                /*endif*/
-                memmove (address->encoding_list.supported_encodings,
-                         ((XIMEncodings *) p->value)->supported_encodings,
-                         sizeof (XIMEncoding)*address->encoding_list.count_encodings);
-                address->imvalue_mask |= I18N_ENCODINGS;
-            }
-            else if (strcmp (p->name, IMFilterEventMask) == 0)
-            {
-                if (address->imvalue_mask & I18N_FILTERMASK)
-                    return IMFilterEventMask;
-                /*endif*/
-                address->filterevent_mask = (long) p->value;
-                address->imvalue_mask |= I18N_FILTERMASK;
-            }
-            /*endif*/
-        }
-        /*endfor*/
-        if (mode == I18N_OPEN)
-        {
-            /* check mandatory IM values */
-            if (!(address->imvalue_mask & I18N_IM_LOCALE))
-            {
-                /* locales must be set in IMOpenIM */
-                return IMLocale;
-            }
-            /*endif*/
-            if (!(address->imvalue_mask & I18N_IM_ADDRESS))
-            {
-                /* address must be set in IMOpenIM */
-                return IMServerTransport;
-            }
-            /*endif*/
-        }
-        /*endif*/
-    }
-    else if (mode == I18N_GET)
-    {
-        for (p = args;  p->name != NULL;  p++)
-        {
-            if (strcmp (p->name, IMLocale) == 0)
-            {
-                p->value = (char *) malloc (strlen (address->im_locale) + 1);
-                if (!p->value)
-                    return IMLocale;
-                /*endif*/
-                strcpy (p->value, address->im_locale);
-            }
-            else if (strcmp (p->name, IMServerTransport) == 0)
-            {
-                p->value = (char *) malloc (strlen (address->im_addr) + 1);
-                if (!p->value)
-                    return IMServerTransport;
-                /*endif*/
-                strcpy (p->value, address->im_addr);
-            }
-            else if (strcmp (p->name, IMServerName) == 0)
-            {
-                if (address->imvalue_mask & I18N_IM_NAME)
-                {
-                    p->value = (char *) malloc (strlen (address->im_name) + 1);
-                    if (!p->value)
-                        return IMServerName;
-                    /*endif*/
-                    strcpy (p->value, address->im_name);
-                }
-                else
-                {
-                    return IMServerName;
-                }
-                /*endif*/
-            }
-            else if (strcmp (p->name, IMServerWindow) == 0)
-            {
-                if (address->imvalue_mask & I18N_IMSERVER_WIN)
-                    *((Window *) (p->value)) = address->im_window;
-                else
-                    return IMServerWindow;
-                /*endif*/
-            }
-            else if (strcmp (p->name, IMInputStyles) == 0)
-            {
-                if (GetInputStyles (i18n_core,
-                                    (XIMStyles **) p->value) == False)
-                {
-                    return IMInputStyles;
-                }
-                /*endif*/
-            }
-            else if (strcmp (p->name, IMProtocolHandler) == 0)
-            {
-                if (address->imvalue_mask & I18N_IM_HANDLER)
-                    *((IMProtoHandler *) (p->value)) = address->improto;
-                else
-                    return IMProtocolHandler;
-                /*endif*/
-            }
-            else if (strcmp (p->name, IMOnKeysList) == 0)
-            {
-                if (address->imvalue_mask & I18N_ON_KEYS)
-                {
-                    if (GetOnOffKeys (i18n_core,
-                                      I18N_ON_KEYS,
-                                      (XIMTriggerKeys **) p->value) == False)
-                    {
-                        return IMOnKeysList;
-                    }
-                    /*endif*/
-                }
-                else
-                {
-                    return IMOnKeysList;
-                }
-                /*endif*/
-            }
-            else if (strcmp (p->name, IMOffKeysList) == 0)
-            {
-                if (address->imvalue_mask & I18N_OFF_KEYS)
-                {
-                    if (GetOnOffKeys (i18n_core,
-                                      I18N_OFF_KEYS,
-                                      (XIMTriggerKeys **) p->value) == False)
-                    {
-                        return IMOffKeysList;
-                    }
-                    /*endif*/
-                }
-                else
-                {
-                    return IMOffKeysList;
-                }
-                /*endif*/
-            }
-            else if (strcmp (p->name, IMEncodingList) == 0)
-            {
-                if (address->imvalue_mask & I18N_ENCODINGS)
-                {
-                    if (GetEncodings (i18n_core,
-                                      (XIMEncodings **) p->value) == False)
-                    {
-                        return IMEncodingList;
-                    }
-                    /*endif*/
-                }
-                else
-                {
-                    return IMEncodingList;
-                }
-                /*endif*/
-            }
-            else if (strcmp (p->name, IMFilterEventMask) == 0)
-            {
-                if (address->imvalue_mask & I18N_FILTERMASK)
-                    *((long *) (p->value)) = address->filterevent_mask;
-                else
-                    return IMFilterEventMask;
-                /*endif*/
-            }
-            /*endif*/
-        }
-        /*endfor*/
-    }
-    /*endif*/
-    return NULL;
-}
-
-static int CheckIMName (Xi18n i18n_core)
-{
-    char *address = i18n_core->address.im_addr;
-    int i;
-
-    for (i = 0;  _TransR[i].transportname;  i++)
-    {
-        while (*address == ' '  ||  *address == '\t')
-            address++;
-        /*endwhile*/
-        if (strncmp (address,
-                     _TransR[i].transportname,
-                     _TransR[i].namelen) == 0
-            &&
-            address[_TransR[i].namelen] == '/')
-        {
-            if (_TransR[i].checkAddr (i18n_core,
-                                      &_TransR[i],
-                                      address + _TransR[i].namelen + 1) == True)
-            {
-                return True;
-            }
-            /*endif*/
-            return False;
-        }
-        /*endif*/
-    }
-    /*endfor*/
-    return False;
-}
-
-static int SetXi18nSelectionOwner(Xi18n i18n_core)
-{
-    Display *dpy = i18n_core->address.dpy;
-    Window ims_win = i18n_core->address.im_window;
-    Window root = RootWindow (dpy, DefaultScreen (dpy));
-    Atom realtype;
-    int realformat;
-    unsigned long bytesafter;
-    long *data=NULL;
-    unsigned long length;
-    Atom atom;
-    int i;
-    int found;
-    int forse = False;
-    char buf[256];
-
-    (void)snprintf(buf, 256, "@server=%s", i18n_core->address.im_name);
-    if ((atom = XInternAtom(dpy, buf, False)) == 0)
-        return False;
-    i18n_core->address.selection = atom;
-
-    if (XIM_Servers == None)
-        XIM_Servers = XInternAtom (dpy, XIM_SERVERS, False);
-    /*endif*/
-    XGetWindowProperty (dpy,
-                        root,
-                        XIM_Servers,
-                        0L,
-                        1000000L,
-                        False,
-                        XA_ATOM,
-                        &realtype,
-                        &realformat,
-                        &length,
-                        &bytesafter,
-                        (unsigned char **) (&data));
-    if (realtype != None && (realtype != XA_ATOM || realformat != 32)) {
-        if (data != NULL)
-            XFree ((char *) data);
-        return False;
-    }
-
-    found = False;
-    for (i = 0; i < length; i++) {
-        if (data[i] == atom) {
-            Window owner;
-            found = True;
-            if ((owner = XGetSelectionOwner (dpy, atom)) != ims_win) {
-                if (owner == None  ||  forse == True)
-                    XSetSelectionOwner (dpy, atom, ims_win, CurrentTime);
-                else
-                    return False;
-            }
-            break;
-        }
-    }
-
-    if (found == False) {
-        XSetSelectionOwner (dpy, atom, ims_win, CurrentTime);
-        XChangeProperty (dpy,
-                         root,
-                         XIM_Servers,
-                         XA_ATOM,
-                         32,
-                         PropModePrepend,
-                         (unsigned char *) &atom,
-                         1);
-    }
-    else {
-       /* 
-        * We always need to generate the PropertyNotify to the Root Window 
-        */
-        XChangeProperty (dpy,
-                         root,
-                         XIM_Servers,
-                         XA_ATOM,
-                         32,
-                         PropModePrepend,
-                         (unsigned char *) data,
-                         0);
-    }
-    if (data != NULL)
-        XFree ((char *) data);
-    
-    /* Intern "LOCALES" and "TRANSOPORT" Target Atoms */
-    i18n_core->address.Localename = XInternAtom (dpy, LOCALES, False);
-    i18n_core->address.Transportname = XInternAtom (dpy, TRANSPORT, False);
-    return (XGetSelectionOwner (dpy, atom) == ims_win);
-}
-
-static int DeleteXi18nAtom(Xi18n i18n_core)
-{
-    Display *dpy = i18n_core->address.dpy;
-    Window root = RootWindow (dpy, DefaultScreen (dpy));
-    Atom realtype;
-    int realformat;
-    unsigned long bytesafter;
-    long *data=NULL;
-    unsigned long length;
-    Atom atom;
-    int i, ret;
-    int found;
-    char buf[256];
-
-    (void)snprintf(buf, 256, "@server=%s", i18n_core->address.im_name);
-    if ((atom = XInternAtom(dpy, buf, False)) == 0)
-        return False;
-    i18n_core->address.selection = atom;
-
-    if (XIM_Servers == None)
-        XIM_Servers = XInternAtom (dpy, XIM_SERVERS, False);
-    XGetWindowProperty (dpy,
-                        root,
-                        XIM_Servers,
-                        0L,
-                        1000000L,
-                        False,
-                        XA_ATOM,
-                        &realtype,
-                        &realformat,
-                        &length,
-                        &bytesafter,
-                        (unsigned char **) (&data));
-    if (realtype != XA_ATOM || realformat != 32) {
-        if (data != NULL)
-            XFree ((char *) data);
-        return False;
-    }
-
-    found = False;
-    for (i = 0; i < length; i++) {
-        if (data[i] == atom) {
-            found = True;
-            break;
-        }
-    }
-
-    if (found == True) {
-        for (i=i+1; i<length; i++)
-            data[i-1] = data[i];
-        XChangeProperty (dpy,
-                         root,
-                         XIM_Servers,
-                         XA_ATOM,
-                         32,
-                         PropModeReplace,
-                         (unsigned char *)data,
-                         length-1);
-        ret = True;
-    }
-    else {
-        XChangeProperty (dpy,
-                         root,
-                         XIM_Servers,
-                         XA_ATOM,
-                         32,
-                         PropModePrepend,
-                         (unsigned char *)data,
-                         0);
-        ret = False;
-    }
-    if (data != NULL)
-        XFree ((char *) data);
-    return ret;
-}
-
-
-/* XIM protocol methods */
-static void *xi18n_setup (Display *dpy, XIMArg *args)
-{
-    Xi18n i18n_core;
-    CARD16 endian = 1;
-
-    if ((i18n_core = (Xi18n) malloc (sizeof (Xi18nCore))) == (Xi18n) NULL)
-        return NULL;
-    /*endif*/
-    
-    memset (i18n_core, 0, sizeof (Xi18nCore));
-
-    i18n_core->address.dpy = dpy;
-
-    if (ParseArgs (i18n_core, I18N_OPEN, args) != NULL)
-    {
-        XFree (i18n_core);
-        return NULL;
-    }
-    /*endif*/
-    if (*(char *) &endian)
-        i18n_core->address.im_byteOrder = 'l';
-    else
-        i18n_core->address.im_byteOrder = 'B';
-    /*endif*/
-    
-    /* install IMAttr and ICAttr list in i18n_core */
-    _Xi18nInitAttrList (i18n_core);
-
-    /* install IMExtension list in i18n_core */
-    _Xi18nInitExtension (i18n_core);
-
-    return i18n_core;
-}
-
-static void ReturnSelectionNotify (Xi18n i18n_core, XSelectionRequestEvent *ev)
-{
-    XEvent event;
-    Display *dpy = i18n_core->address.dpy;
-    char buf[4096];
-
-    event.type = SelectionNotify;
-    event.xselection.requestor = ev->requestor;
-    event.xselection.selection = ev->selection;
-    event.xselection.target = ev->target;
-    event.xselection.time = ev->time;
-    event.xselection.property = ev->property;
-    if (ev->target == i18n_core->address.Localename)
-    {
-        snprintf (buf, 4096, "@locale=%s", i18n_core->address.im_locale);
-    }
-    else if (ev->target == i18n_core->address.Transportname)
-    {
-        snprintf (buf, 4096, "@transport=%s", i18n_core->address.im_addr);
-    }
-    /*endif*/
-    XChangeProperty (dpy,
-                     event.xselection.requestor,
-                     ev->target,
-                     ev->target,
-                     8,
-                     PropModeReplace,
-                     (unsigned char *) buf,
-                     strlen (buf));
-    XSendEvent (dpy, event.xselection.requestor, False, NoEventMask, &event);
-    XFlush (i18n_core->address.dpy);
-}
-
-static Bool WaitXSelectionRequest (Display *dpy,
-                                   Window win,
-                                   XEvent *ev,
-                                   XPointer client_data)
-{
-    XIMS ims = (XIMS) client_data;
-    Xi18n i18n_core = ims->protocol;
-
-    if (((XSelectionRequestEvent *) ev)->selection
-        == i18n_core->address.selection)
-    {
-        ReturnSelectionNotify (i18n_core, (XSelectionRequestEvent *) ev);
-        return True;
-    }
-    /*endif*/
-    return False;
-}
-
-static Status xi18n_openIM(XIMS ims)
-{
-    Xi18n i18n_core = ims->protocol;
-    Display *dpy = i18n_core->address.dpy;
-
-    if (!CheckIMName (i18n_core)
-        ||
-        !SetXi18nSelectionOwner (i18n_core)
-        ||
-        !i18n_core->methods.begin (ims))
-    {
-        XFree (i18n_core->address.im_name);
-        XFree (i18n_core->address.im_locale);
-        XFree (i18n_core->address.im_addr);
-        XFree (i18n_core);
-        return False;
-    }
-    /*endif*/
-
-    _XRegisterFilterByType (dpy,
-                            i18n_core->address.im_window,
-                            SelectionRequest,
-                            SelectionRequest,
-                            WaitXSelectionRequest,
-                            (XPointer)ims);
-    XFlush(dpy);
-    return True;
-}
-
-static Status xi18n_closeIM(XIMS ims)
-{
-    Xi18n i18n_core = ims->protocol;
-    Display *dpy = i18n_core->address.dpy;
-
-    DeleteXi18nAtom(i18n_core);
-    if (!i18n_core->methods.end (ims))
-        return False;
-    
-    _XUnregisterFilter (dpy,
-                        i18n_core->address.im_window,
-                        WaitXSelectionRequest,
-                        (XPointer)ims);
-    XFree (i18n_core->address.im_name);
-    XFree (i18n_core->address.im_locale);
-    XFree (i18n_core->address.im_addr);
-    XFree (i18n_core);
-    return True;
-}
-
-static char *xi18n_setIMValues (XIMS ims, XIMArg *args)
-{
-    Xi18n i18n_core = ims->protocol;
-    char *ret;
-
-    if ((ret = ParseArgs (i18n_core, I18N_SET, args)) != NULL)
-        return ret;
-    /*endif*/
-    return NULL;
-}
-
-static char *xi18n_getIMValues (XIMS ims, XIMArg *args)
-{
-    Xi18n i18n_core = ims->protocol;
-    char *ret;
-
-    if ((ret = ParseArgs (i18n_core, I18N_GET, args)) != NULL)
-        return ret;
-    /*endif*/
-    return NULL;
-}
-
-static void EventToWireEvent (XEvent *ev, xEvent *event,
-                             CARD16 *serial, Bool byte_swap)
-{
-    FrameMgr fm;
-    extern XimFrameRec wire_keyevent_fr[];
-    extern XimFrameRec short_fr[];
-    BYTE b;
-    CARD16 c16;
-    CARD32 c32;
-
-    *serial = (CARD16)(ev->xany.serial >> 16);
-    switch (ev->type) {
-      case KeyPress:
-      case KeyRelease:
-       {
-           XKeyEvent *kev = (XKeyEvent*)ev;
-           /* create FrameMgr */
-           fm = FrameMgrInit(wire_keyevent_fr, (char *)(&(event->u)), byte_swap);
-
-           /* set values */
-           b = (BYTE)kev->type;          FrameMgrPutToken(fm, b);
-           b = (BYTE)kev->keycode;       FrameMgrPutToken(fm, b);
-           c16 = (CARD16)(kev->serial & (unsigned long)0xffff);
-                                         FrameMgrPutToken(fm, c16);
-           c32 = (CARD32)kev->time;      FrameMgrPutToken(fm, c32);
-           c32 = (CARD32)kev->root;      FrameMgrPutToken(fm, c32);
-           c32 = (CARD32)kev->window;    FrameMgrPutToken(fm, c32);
-           c32 = (CARD32)kev->subwindow; FrameMgrPutToken(fm, c32);
-           c16 = (CARD16)kev->x_root;    FrameMgrPutToken(fm, c16);
-           c16 = (CARD16)kev->y_root;    FrameMgrPutToken(fm, c16);
-           c16 = (CARD16)kev->x;         FrameMgrPutToken(fm, c16);
-           c16 = (CARD16)kev->y;         FrameMgrPutToken(fm, c16);
-           c16 = (CARD16)kev->state;     FrameMgrPutToken(fm, c16);
-           b = (BYTE)kev->same_screen;   FrameMgrPutToken(fm, b);
-       }
-       break;
-      default:
-         /* create FrameMgr */
-         fm = FrameMgrInit(short_fr, (char *)(&(event->u.u.sequenceNumber)),
-                           byte_swap);
-         c16 = (CARD16)(ev->xany.serial & (unsigned long)0xffff);
-         FrameMgrPutToken(fm, c16);
-         break;
-    }
-    /* free FrameMgr */
-    FrameMgrFree(fm);
-}
-
-static Status xi18n_forwardEvent (XIMS ims, XPointer xp)
-{
-    Xi18n i18n_core = ims->protocol;
-    IMForwardEventStruct *call_data = (IMForwardEventStruct *)xp;
-    FrameMgr fm;
-    extern XimFrameRec forward_event_fr[];
-    register int total_size;
-    unsigned char *reply = NULL;
-    unsigned char *replyp;
-    CARD16 serial;
-    int event_size;
-    Xi18nClient *client;
-
-    client = (Xi18nClient *) _Xi18nFindClient (i18n_core, call_data->connect_id);
-
-    /* create FrameMgr */
-    fm = FrameMgrInit (forward_event_fr,
-                       NULL,
-                       _Xi18nNeedSwap (i18n_core, call_data->connect_id));
-
-    total_size = FrameMgrGetTotalSize (fm);
-    event_size = sizeof (xEvent);
-    reply = (unsigned char *) malloc (total_size + event_size);
-    if (!reply)
-    {
-        _Xi18nSendMessage (ims,
-                           call_data->connect_id,
-                           XIM_ERROR,
-                           0,
-                           0,
-                           0);
-        return False;
-    }
-    /*endif*/
-    memset (reply, 0, total_size + event_size);
-    FrameMgrSetBuffer (fm, reply);
-    replyp = reply;
-
-    call_data->sync_bit = 1;   /* always sync */
-    client->sync = True;
-
-    FrameMgrPutToken (fm, call_data->connect_id);
-    FrameMgrPutToken (fm, call_data->icid);
-    FrameMgrPutToken (fm, call_data->sync_bit);
-
-    replyp += total_size;
-    EventToWireEvent (&(call_data->event),
-                      (xEvent *) replyp,
-                      &serial,
-                      _Xi18nNeedSwap (i18n_core, call_data->connect_id));
-
-    FrameMgrPutToken (fm, serial);
-
-    _Xi18nSendMessage (ims,
-                       call_data->connect_id,
-                       XIM_FORWARD_EVENT,
-                       0,
-                       reply,
-                       total_size + event_size);
-
-    XFree (reply);
-    FrameMgrFree (fm);
-
-    return True;
-}
-
-static Status xi18n_commit (XIMS ims, XPointer xp)
-{
-    Xi18n i18n_core = ims->protocol;
-    IMCommitStruct *call_data = (IMCommitStruct *)xp;
-    FrameMgr fm;
-    extern XimFrameRec commit_chars_fr[];
-    extern XimFrameRec commit_both_fr[];
-    register int total_size;
-    unsigned char *reply = NULL;
-    CARD16 str_length;
-
-    call_data->flag |= XimSYNCHRONUS;  /* always sync */
-
-    if (!(call_data->flag & XimLookupKeySym)
-        &&
-        (call_data->flag & XimLookupChars))
-    {
-        fm = FrameMgrInit (commit_chars_fr,
-                           NULL,
-                           _Xi18nNeedSwap (i18n_core, call_data->connect_id));
-
-        /* set length of STRING8 */
-        str_length = strlen (call_data->commit_string);
-        FrameMgrSetSize (fm, str_length);
-        total_size = FrameMgrGetTotalSize (fm);
-        reply = (unsigned char *) malloc (total_size);
-        if (!reply)
-        {
-            _Xi18nSendMessage (ims,
-                               call_data->connect_id,
-                               XIM_ERROR,
-                               0,
-                               0,
-                               0);
-            return False;
-        }
-        /*endif*/
-        memset (reply, 0, total_size);
-        FrameMgrSetBuffer (fm, reply);
-
-        str_length = FrameMgrGetSize (fm);
-        FrameMgrPutToken (fm, call_data->connect_id);
-        FrameMgrPutToken (fm, call_data->icid);
-        FrameMgrPutToken (fm, call_data->flag);
-        FrameMgrPutToken (fm, str_length);
-        FrameMgrPutToken (fm, call_data->commit_string);
-    }
-    else
-    {
-        fm = FrameMgrInit (commit_both_fr,
-                           NULL,
-                           _Xi18nNeedSwap (i18n_core, call_data->connect_id));
-        /* set length of STRING8 */
-        str_length = strlen (call_data->commit_string);
-        if (str_length > 0)
-            FrameMgrSetSize (fm, str_length);
-        /*endif*/
-        total_size = FrameMgrGetTotalSize (fm);
-        reply = (unsigned char *) malloc (total_size);
-        if (!reply)
-        {
-            _Xi18nSendMessage (ims,
-                               call_data->connect_id,
-                               XIM_ERROR,
-                               0,
-                               0,
-                               0);
-            return False;
-        }
-        /*endif*/
-        FrameMgrSetBuffer (fm, reply);
-        FrameMgrPutToken (fm, call_data->connect_id);
-        FrameMgrPutToken (fm, call_data->icid);
-        FrameMgrPutToken (fm, call_data->flag);
-        FrameMgrPutToken (fm, call_data->keysym);
-        if (str_length > 0)
-        {
-            str_length = FrameMgrGetSize (fm);
-            FrameMgrPutToken (fm, str_length);
-            FrameMgrPutToken (fm, call_data->commit_string);
-        }
-        /*endif*/
-    }
-    /*endif*/
-    _Xi18nSendMessage (ims,
-                       call_data->connect_id,
-                       XIM_COMMIT,
-                       0,
-                       reply,
-                       total_size);
-    FrameMgrFree (fm);
-    XFree (reply);
-
-    return True;
-}
-
-static int xi18n_callCallback (XIMS ims, XPointer xp)
-{
-    IMProtocol *call_data = (IMProtocol *)xp;
-    switch (call_data->major_code)
-    {
-    case XIM_GEOMETRY:
-        return _Xi18nGeometryCallback (ims, call_data);
-
-    case XIM_PREEDIT_START:
-        return _Xi18nPreeditStartCallback (ims, call_data);
-
-    case XIM_PREEDIT_DRAW:
-        return _Xi18nPreeditDrawCallback (ims, call_data);
-
-    case XIM_PREEDIT_CARET:
-        return _Xi18nPreeditCaretCallback (ims, call_data);
-
-    case XIM_PREEDIT_DONE:
-        return _Xi18nPreeditDoneCallback (ims, call_data);
-
-    case XIM_STATUS_START:
-        return _Xi18nStatusStartCallback (ims, call_data);
-
-    case XIM_STATUS_DRAW:
-        return _Xi18nStatusDrawCallback (ims, call_data);
-
-    case XIM_STATUS_DONE:
-        return _Xi18nStatusDoneCallback (ims, call_data);
-
-    case XIM_STR_CONVERSION:
-        return _Xi18nStringConversionCallback (ims, call_data);
-    }
-    /*endswitch*/
-    return False;
-}
-
-/* preeditStart and preeditEnd are used only for Dynamic Event Flow. */
-static int xi18n_preeditStart (XIMS ims, XPointer xp)
-{
-    IMProtocol *call_data = (IMProtocol *)xp;
-    Xi18n i18n_core = ims->protocol;
-    IMPreeditStateStruct *preedit_state =
-        (IMPreeditStateStruct *) &call_data->preedit_state;
-    long mask;
-    int on_key_num = i18n_core->address.on_keys.count_keys;
-    int off_key_num = i18n_core->address.off_keys.count_keys;
-
-    if (on_key_num == 0  &&  off_key_num == 0)
-        return False;
-    /*endif*/
-    if (i18n_core->address.imvalue_mask & I18N_FILTERMASK)
-        mask = i18n_core->address.filterevent_mask;
-    else
-        mask = DEFAULT_FILTER_MASK;
-    /*endif*/
-    _Xi18nSetEventMask (ims,
-                        preedit_state->connect_id,
-                        preedit_state->connect_id,
-                        preedit_state->icid,
-                        mask,
-                        ~mask);
-    return True;
-}
-
-static int xi18n_preeditEnd (XIMS ims, XPointer xp)
-{
-    IMProtocol *call_data = (IMProtocol *)xp;
-    Xi18n i18n_core = ims->protocol;
-    int on_key_num = i18n_core->address.on_keys.count_keys;
-    int off_key_num = i18n_core->address.off_keys.count_keys;
-    IMPreeditStateStruct *preedit_state;
-
-    preedit_state = (IMPreeditStateStruct *) &call_data->preedit_state;
-
-    if (on_key_num == 0  &&  off_key_num == 0)
-        return False;
-    /*endif*/
-    
-    _Xi18nSetEventMask (ims,
-                        preedit_state->connect_id,
-                        preedit_state->connect_id,
-                        preedit_state->icid,
-                        0,
-                        0);
-    return True;
-}
-
-static int xi18n_syncXlib (XIMS ims, XPointer xp)
-{
-    IMProtocol *call_data = (IMProtocol *)xp;
-    Xi18n i18n_core = ims->protocol;
-    IMSyncXlibStruct *sync_xlib;
-
-    extern XimFrameRec sync_fr[];
-    FrameMgr fm;
-    CARD16 connect_id = call_data->any.connect_id;
-    int total_size;
-    unsigned char *reply;
-
-    sync_xlib = (IMSyncXlibStruct *) &call_data->sync_xlib;
-    fm = FrameMgrInit (sync_fr, NULL,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-    total_size = FrameMgrGetTotalSize(fm);
-    reply = (unsigned char *) malloc (total_size);
-    if (!reply) {
-        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
-        return False;
-    }
-    memset (reply, 0, total_size);
-    FrameMgrSetBuffer (fm, reply);
-
-    /* input input-method ID */
-    FrameMgrPutToken (fm, connect_id);
-    /* input input-context ID */
-    FrameMgrPutToken (fm, sync_xlib->icid);
-    _Xi18nSendMessage (ims, connect_id, XIM_SYNC, 0, reply, total_size);
-
-    FrameMgrFree (fm);
-    XFree(reply);
-    return True;
-}
-
diff --git a/x11/IMdkit/i18nPtHdr.c b/x11/IMdkit/i18nPtHdr.c
deleted file mode 100644 (file)
index d350354..0000000
+++ /dev/null
@@ -1,1848 +0,0 @@
-/******************************************************************
-         Copyright 1994, 1995 by Sun Microsystems, Inc.
-         Copyright 1993, 1994 by Hewlett-Packard Company
-Permission to use, copy, modify, distribute, and sell this software
-and its documentation for any purpose is hereby granted without fee,
-provided that the above copyright notice appear in all copies and
-that both that copyright notice and this permission notice appear
-in supporting documentation, and that the name of Sun Microsystems, Inc.
-and Hewlett-Packard not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior permission.
-Sun Microsystems, Inc. and Hewlett-Packard make no representations about
-the suitability of this software for any purpose.  It is provided "as is"
-without express or implied warranty.
-SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL
-WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
-RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
-CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
-IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-  Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
-
-    This version tidied and debugged by Steve Underwood May 1999
-******************************************************************/
-
-#include <stdlib.h>
-#include <sys/param.h>
-#include <X11/Xlib.h>
-#ifndef NEED_EVENTS
-#define NEED_EVENTS
-#endif
-#include <X11/Xproto.h>
-#undef NEED_EVENTS
-#include "FrameMgr.h"
-#include "IMdkit.h"
-#include "Xi18n.h"
-#include "XimFunc.h"
-
-#ifdef XIM_DEBUG
-#include <stdio.h>
-
-static void    DebugLog(char * msg)
-{
-       fprintf(stderr, msg);
-}
-#endif
-
-extern Xi18nClient *_Xi18nFindClient (Xi18n, CARD16);
-
-static void GetProtocolVersion (CARD16 client_major,
-                                CARD16 client_minor,
-                                CARD16 *server_major,
-                                CARD16 *server_minor)
-{
-    *server_major = client_major;
-    *server_minor = client_minor;
-}
-
-static void ConnectMessageProc (XIMS ims,
-                                IMProtocol *call_data,
-                                unsigned char *p)
-{
-    Xi18n i18n_core = ims->protocol;
-    FrameMgr fm;
-    extern XimFrameRec connect_fr[], connect_reply_fr[];
-    register int total_size;
-    CARD16 server_major_version, server_minor_version;
-    unsigned char *reply = NULL;
-    IMConnectStruct *imconnect =
-        (IMConnectStruct*) &call_data->imconnect;
-    CARD16 connect_id = call_data->any.connect_id;
-
-    fm = FrameMgrInit (connect_fr,
-                       (char *) p,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-
-    /* get data */
-    FrameMgrGetToken (fm, imconnect->byte_order);
-    FrameMgrGetToken (fm, imconnect->major_version);
-    FrameMgrGetToken (fm, imconnect->minor_version);
-
-    FrameMgrFree (fm);
-
-    GetProtocolVersion (imconnect->major_version,
-                        imconnect->minor_version,
-                        &server_major_version,
-                        &server_minor_version);
-#ifdef PROTOCOL_RICH
-    if (i18n_core->address.improto)
-    {
-        if (!(i18n_core->address.improto(ims, call_data)))
-            return;
-        /*endif*/
-    }
-    /*endif*/
-#endif  /* PROTOCOL_RICH */
-
-    fm = FrameMgrInit (connect_reply_fr,
-                       NULL,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-
-    total_size = FrameMgrGetTotalSize (fm);
-    reply = (unsigned char *) malloc (total_size);
-    if (!reply)
-    {
-        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
-        return;
-    }
-    /*endif*/
-    memset (reply, 0, total_size);
-    FrameMgrSetBuffer (fm, reply);
-
-    FrameMgrPutToken (fm, server_major_version);
-    FrameMgrPutToken (fm, server_minor_version);
-
-    _Xi18nSendMessage (ims,
-                       connect_id,
-                       XIM_CONNECT_REPLY,
-                       0,
-                       reply,
-                       total_size);
-
-    FrameMgrFree (fm);
-    XFree (reply);
-}
-
-static void DisConnectMessageProc (XIMS ims, IMProtocol *call_data)
-{
-    Xi18n i18n_core = ims->protocol;
-    unsigned char *reply = NULL;
-    CARD16 connect_id = call_data->any.connect_id;
-
-#ifdef PROTOCOL_RICH
-    if (i18n_core->address.improto)
-    {
-        if (!(i18n_core->address.improto (ims, call_data)))
-            return;
-        /*endif*/
-    }
-    /*endif*/
-#endif  /* PROTOCOL_RICH */
-
-    _Xi18nSendMessage (ims,
-                       connect_id,
-                       XIM_DISCONNECT_REPLY,
-                       0,
-                       reply,
-                       0);
-
-    i18n_core->methods.disconnect (ims, connect_id);
-}
-
-static void OpenMessageProc(XIMS ims, IMProtocol *call_data, unsigned char *p)
-{
-    Xi18n i18n_core = ims->protocol;
-    FrameMgr fm;
-    extern XimFrameRec open_fr[];
-    extern XimFrameRec open_reply_fr[];
-    unsigned char *reply = NULL;
-    int str_size;
-    register int i, total_size;
-    CARD16 connect_id = call_data->any.connect_id;
-    int str_length;
-    char *name;
-    IMOpenStruct *imopen = (IMOpenStruct *) &call_data->imopen;
-
-    fm = FrameMgrInit (open_fr,
-                       (char *) p,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-
-    /* get data */
-    FrameMgrGetToken (fm, str_length);
-    FrameMgrSetSize (fm, str_length);
-    FrameMgrGetToken (fm, name);
-    imopen->lang.length = str_length;
-    imopen->lang.name = malloc (str_length + 1);
-    strncpy (imopen->lang.name, name, str_length);
-    imopen->lang.name[str_length] = (char) 0;
-
-    FrameMgrFree (fm);
-
-    if (i18n_core->address.improto)
-    {
-        if (!(i18n_core->address.improto(ims, call_data)))
-            return;
-        /*endif*/
-    }
-    /*endif*/
-    if ((i18n_core->address.imvalue_mask & I18N_ON_KEYS)
-        ||
-        (i18n_core->address.imvalue_mask & I18N_OFF_KEYS))
-    {
-        _Xi18nSendTriggerKey (ims, connect_id);
-    }
-    /*endif*/
-    XFree (imopen->lang.name);
-
-    fm = FrameMgrInit (open_reply_fr,
-                       NULL,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-
-    /* set iteration count for list of imattr */
-    FrameMgrSetIterCount (fm, i18n_core->address.im_attr_num);
-
-    /* set length of BARRAY item in ximattr_fr */
-    for (i = 0;  i < i18n_core->address.im_attr_num;  i++)
-    {
-        str_size = strlen (i18n_core->address.xim_attr[i].name);
-        FrameMgrSetSize (fm, str_size);
-    }
-    /*endfor*/
-    /* set iteration count for list of icattr */
-    FrameMgrSetIterCount (fm, i18n_core->address.ic_attr_num);
-    /* set length of BARRAY item in xicattr_fr */
-    for (i = 0;  i < i18n_core->address.ic_attr_num;  i++)
-    {
-        str_size = strlen (i18n_core->address.xic_attr[i].name);
-        FrameMgrSetSize (fm, str_size);
-    }
-    /*endfor*/
-
-    total_size = FrameMgrGetTotalSize (fm);
-    reply = (unsigned char *) malloc (total_size);
-    if (!reply)
-    {
-        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
-        return;
-    }
-    /*endif*/
-    memset (reply, 0, total_size);
-    FrameMgrSetBuffer (fm, reply);
-
-    /* input input-method ID */
-    FrameMgrPutToken (fm, connect_id);
-
-    for (i = 0;  i < i18n_core->address.im_attr_num;  i++)
-    {
-        str_size = FrameMgrGetSize (fm);
-        FrameMgrPutToken (fm, i18n_core->address.xim_attr[i].attribute_id);
-        FrameMgrPutToken (fm, i18n_core->address.xim_attr[i].type);
-        FrameMgrPutToken (fm, str_size);
-        FrameMgrPutToken (fm, i18n_core->address.xim_attr[i].name);
-    }
-    /*endfor*/
-    for (i = 0;  i < i18n_core->address.ic_attr_num;  i++)
-    {
-        str_size = FrameMgrGetSize (fm);
-        FrameMgrPutToken (fm, i18n_core->address.xic_attr[i].attribute_id);
-        FrameMgrPutToken (fm, i18n_core->address.xic_attr[i].type);
-        FrameMgrPutToken (fm, str_size);
-        FrameMgrPutToken (fm, i18n_core->address.xic_attr[i].name);
-    }
-    /*endfor*/
-
-    _Xi18nSendMessage (ims,
-                       connect_id,
-                       XIM_OPEN_REPLY,
-                       0,
-                       reply,
-                       total_size);
-
-    FrameMgrFree (fm);
-    XFree (reply);
-}
-
-static void CloseMessageProc (XIMS ims,
-                              IMProtocol *call_data,
-                              unsigned char *p)
-{
-    Xi18n i18n_core = ims->protocol;
-    FrameMgr fm;
-    extern XimFrameRec close_fr[];
-    extern XimFrameRec close_reply_fr[];
-    unsigned char *reply = NULL;
-    register int total_size;
-    CARD16 connect_id = call_data->any.connect_id;
-    CARD16 input_method_ID;
-
-    fm = FrameMgrInit (close_fr,
-                       (char *) p,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-
-    FrameMgrGetToken (fm, input_method_ID);
-
-    FrameMgrFree (fm);
-
-    if (i18n_core->address.improto)
-    {
-        if (!(i18n_core->address.improto (ims, call_data)))
-            return;
-        /*endif*/
-    }
-    /*endif*/
-
-    fm = FrameMgrInit (close_reply_fr,
-                       NULL,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-
-    total_size = FrameMgrGetTotalSize (fm);
-    reply = (unsigned char *) malloc (total_size);
-    if (!reply)
-    {
-        _Xi18nSendMessage (ims,
-                           connect_id,
-                           XIM_ERROR,
-                           0,
-                           0,
-                           0);
-        return;
-    }
-    /*endif*/
-    memset (reply, 0, total_size);
-    FrameMgrSetBuffer (fm, reply);
-
-    FrameMgrPutToken (fm, input_method_ID);
-
-    _Xi18nSendMessage (ims,
-                       connect_id,
-                       XIM_CLOSE_REPLY,
-                       0,
-                       reply,
-                       total_size);
-
-    FrameMgrFree (fm);
-    XFree (reply);
-}
-
-static XIMExt *MakeExtensionList (Xi18n i18n_core,
-                                  XIMStr *lib_extension,
-                                  int number,
-                                  int *reply_number)
-{
-    XIMExt *ext_list;
-    XIMExt *im_ext = (XIMExt *) i18n_core->address.extension;
-    int im_ext_len = i18n_core->address.ext_num;
-    int i;
-    int j;
-
-    *reply_number = 0;
-
-    if (number == 0)
-    {
-        /* query all extensions */
-        *reply_number = im_ext_len;
-    }
-    else
-    {
-        for (i = 0;  i < im_ext_len;  i++)
-        {
-            for (j = 0;  j < (int) number;  j++)
-            {
-                if (strcmp (lib_extension[j].name, im_ext[i].name) == 0)
-                {
-                    (*reply_number)++;
-                    break;
-                }
-                /*endif*/
-            }
-            /*endfor*/
-        }
-        /*endfor*/
-    }
-    /*endif*/
-
-    if (!(*reply_number))
-        return NULL;
-    /*endif*/
-    ext_list = (XIMExt *) malloc (sizeof (XIMExt)*(*reply_number));
-    if (!ext_list)
-        return NULL;
-    /*endif*/
-    memset (ext_list, 0, sizeof (XIMExt)*(*reply_number));
-
-    if (number == 0)
-    {
-        /* query all extensions */
-        for (i = 0;  i < im_ext_len;  i++)
-        {
-            ext_list[i].major_opcode = im_ext[i].major_opcode;
-            ext_list[i].minor_opcode = im_ext[i].minor_opcode;
-            ext_list[i].length = im_ext[i].length;
-            ext_list[i].name = malloc (im_ext[i].length + 1);
-            strcpy (ext_list[i].name, im_ext[i].name);
-        }
-        /*endfor*/
-    }
-    else
-    {
-        int n = 0;
-
-        for (i = 0;  i < im_ext_len;  i++)
-        {
-            for (j = 0;  j < (int)number;  j++)
-            {
-                if (strcmp (lib_extension[j].name, im_ext[i].name) == 0)
-                {
-                    ext_list[n].major_opcode = im_ext[i].major_opcode;
-                    ext_list[n].minor_opcode = im_ext[i].minor_opcode;
-                    ext_list[n].length = im_ext[i].length;
-                    ext_list[n].name = malloc (im_ext[i].length + 1);
-                    strcpy (ext_list[n].name, im_ext[i].name);
-                    n++;
-                    break;
-                }
-                /*endif*/
-            }
-            /*endfor*/
-        }
-        /*endfor*/
-    }
-    /*endif*/
-    return ext_list;
-}
-
-static void QueryExtensionMessageProc (XIMS ims,
-                                       IMProtocol *call_data,
-                                       unsigned char *p)
-{
-    Xi18n i18n_core = ims->protocol;
-    FrameMgr fm;
-    FmStatus status;
-    extern XimFrameRec query_extension_fr[];
-    extern XimFrameRec query_extension_reply_fr[];
-    unsigned char *reply = NULL;
-    int str_size;
-    register int i;
-    register int number;
-    register int total_size;
-    int byte_length;
-    int reply_number = 0;
-    XIMExt *ext_list;
-    IMQueryExtensionStruct *query_ext =
-        (IMQueryExtensionStruct *) &call_data->queryext;
-    CARD16 connect_id = call_data->any.connect_id;
-    CARD16 input_method_ID;
-
-    fm = FrameMgrInit (query_extension_fr,
-                       (char *) p,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-
-    FrameMgrGetToken (fm, input_method_ID);
-    FrameMgrGetToken (fm, byte_length);
-    query_ext->extension = (XIMStr *) malloc (sizeof (XIMStr)*10);
-    memset (query_ext->extension, 0, sizeof (XIMStr)*10);
-    number = 0;
-    while (FrameMgrIsIterLoopEnd (fm, &status) == False)
-    {
-        char *name;
-        int str_length;
-        
-        FrameMgrGetToken (fm, str_length);
-        FrameMgrSetSize (fm, str_length);
-        query_ext->extension[number].length = str_length;
-        FrameMgrGetToken (fm, name);
-        query_ext->extension[number].name = malloc (str_length + 1);
-        strncpy (query_ext->extension[number].name, name, str_length);
-        query_ext->extension[number].name[str_length] = (char) 0;
-        number++;
-    }
-    /*endwhile*/
-    query_ext->number = number;
-
-#ifdef PROTOCOL_RICH
-    if (i18n_core->address.improto)
-    {
-        if (!(i18n_core->address.improto(ims, call_data)))
-            return;
-        /*endif*/
-    }
-    /*endif*/
-#endif  /* PROTOCOL_RICH */
-
-    FrameMgrFree (fm);
-
-    ext_list = MakeExtensionList (i18n_core,
-                                  query_ext->extension,
-                                  number,
-                                  &reply_number);
-
-    for (i = 0;  i < number;  i++)
-        XFree (query_ext->extension[i].name);
-    /*endfor*/
-    XFree (query_ext->extension);
-
-    fm = FrameMgrInit (query_extension_reply_fr,
-                       NULL,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-
-    /* set iteration count for list of extensions */
-    FrameMgrSetIterCount (fm, reply_number);
-
-    /* set length of BARRAY item in ext_fr */
-    for (i = 0;  i < reply_number;  i++)
-    {
-        str_size = strlen (ext_list[i].name);
-        FrameMgrSetSize (fm, str_size);
-    }
-    /*endfor*/
-
-    total_size = FrameMgrGetTotalSize (fm);
-    reply = (unsigned char *) malloc (total_size);
-    if (!reply)
-    {
-        _Xi18nSendMessage (ims,
-                           connect_id,
-                           XIM_ERROR,
-                           0,
-                           0,
-                           0);
-        return;
-    }
-    /*endif*/
-    memset (reply, 0, total_size);
-    FrameMgrSetBuffer (fm, reply);
-
-    FrameMgrPutToken (fm, input_method_ID);
-
-    for (i = 0;  i < reply_number;  i++)
-    {
-        str_size = FrameMgrGetSize (fm);
-        FrameMgrPutToken (fm, ext_list[i].major_opcode);
-        FrameMgrPutToken (fm, ext_list[i].minor_opcode);
-        FrameMgrPutToken (fm, str_size);
-        FrameMgrPutToken (fm, ext_list[i].name);
-    }
-    /*endfor*/
-    _Xi18nSendMessage (ims,
-                       connect_id,
-                       XIM_QUERY_EXTENSION_REPLY,
-                       0,
-                       reply,
-                       total_size);
-    FrameMgrFree (fm);
-    XFree (reply);
-
-    for (i = 0;  i < reply_number;  i++)
-        XFree (ext_list[i].name);
-    /*endfor*/
-    XFree ((char *) ext_list);
-}
-
-static void SyncReplyMessageProc (XIMS ims,
-                                  IMProtocol *call_data,
-                                  unsigned char *p)
-{
-    Xi18n i18n_core = ims->protocol;
-    FrameMgr fm;
-    extern XimFrameRec sync_reply_fr[];
-    CARD16 connect_id = call_data->any.connect_id;
-    Xi18nClient *client;
-    CARD16 input_method_ID;
-    CARD16 input_context_ID;
-
-    client = (Xi18nClient *)_Xi18nFindClient (i18n_core, connect_id);
-    fm = FrameMgrInit (sync_reply_fr,
-                       (char *) p,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-    FrameMgrGetToken (fm, input_method_ID);
-    FrameMgrGetToken (fm, input_context_ID);
-    FrameMgrFree (fm);
-
-    client->sync = False;
-
-    if (ims->sync == True) {
-       ims->sync = False;
-       if (i18n_core->address.improto) {
-           call_data->sync_xlib.major_code = XIM_SYNC_REPLY;
-           call_data->sync_xlib.minor_code = 0;
-           call_data->sync_xlib.connect_id = input_method_ID;
-           call_data->sync_xlib.icid = input_context_ID;
-           i18n_core->address.improto(ims, call_data);
-       }
-    }
-}
-
-static void GetIMValueFromName (Xi18n i18n_core,
-                                CARD16 connect_id,
-                                char *buf,
-                                char *name,
-                                int *length)
-{
-    register int i;
-
-    if (strcmp (name, XNQueryInputStyle) == 0)
-    {
-        XIMStyles *styles = (XIMStyles *) &i18n_core->address.input_styles;
-
-        *length = sizeof (CARD16)*2;   /* count_styles, unused */
-        *length += styles->count_styles*sizeof (CARD32);
-
-        if (buf != NULL)
-        {
-            FrameMgr fm;
-            extern XimFrameRec input_styles_fr[];
-            unsigned char *data = NULL;
-            int total_size;
-            
-            fm = FrameMgrInit (input_styles_fr,
-                               NULL,
-                               _Xi18nNeedSwap (i18n_core, connect_id));
-
-            /* set iteration count for list of input_style */
-            FrameMgrSetIterCount (fm, styles->count_styles);
-
-            total_size = FrameMgrGetTotalSize (fm);
-            data = (unsigned char *) malloc (total_size);
-            if (!data)
-                return;
-            /*endif*/
-            memset (data, 0, total_size);
-            FrameMgrSetBuffer (fm, data);
-
-            FrameMgrPutToken (fm, styles->count_styles);
-            for (i = 0;  i < (int) styles->count_styles;  i++)
-                FrameMgrPutToken (fm, styles->supported_styles[i]);
-            /*endfor*/
-            memmove (buf, data, total_size);
-            FrameMgrFree (fm);
-
-            /* ADDED BY SUZHE */
-            free (data);
-            /* ADDED BY SUZHE */
-        }
-        /*endif*/
-    }
-    /*endif*/
-
-    else if (strcmp (name, XNQueryIMValuesList) == 0) {
-    }
-}
-
-static XIMAttribute *MakeIMAttributeList (Xi18n i18n_core,
-                                          CARD16 connect_id,
-                                          CARD16 *list,
-                                          int *number,
-                                          int *length)
-{
-    XIMAttribute *attrib_list;
-    int list_num;
-    XIMAttr *attr = i18n_core->address.xim_attr;
-    int list_len = i18n_core->address.im_attr_num;
-    register int i;
-    register int j;
-    int value_length;
-    int number_ret = 0;
-
-    *length = 0;
-    list_num = 0;
-    for (i = 0;  i < *number;  i++)
-    {
-        for (j = 0;  j < list_len;  j++)
-        {
-            if (attr[j].attribute_id == list[i])
-            {
-                list_num++;
-                break;
-            }
-            /*endif*/
-        }
-        /*endfor*/
-    }
-    /*endfor*/
-    attrib_list = (XIMAttribute *) malloc (sizeof (XIMAttribute)*list_num);
-    if (!attrib_list)
-        return NULL;
-    /*endif*/
-    memset (attrib_list, 0, sizeof (XIMAttribute)*list_num);
-    number_ret = list_num;
-    list_num = 0;
-    for (i = 0;  i < *number;  i++)
-    {
-        for (j = 0;  j < list_len;  j++)
-        {
-            if (attr[j].attribute_id == list[i])
-            {
-                attrib_list[list_num].attribute_id = attr[j].attribute_id;
-                attrib_list[list_num].name_length = attr[j].length;
-                attrib_list[list_num].name = attr[j].name;
-                attrib_list[list_num].type = attr[j].type;
-                GetIMValueFromName (i18n_core,
-                                    connect_id,
-                                    NULL,
-                                    attr[j].name,
-                                    &value_length);
-                attrib_list[list_num].value_length = value_length;
-                attrib_list[list_num].value = (void *) malloc (value_length);
-                memset(attrib_list[list_num].value, 0, value_length);
-                GetIMValueFromName (i18n_core,
-                                    connect_id,
-                                    attrib_list[list_num].value,
-                                    attr[j].name,
-                                    &value_length);
-                *length += sizeof (CARD16)*2;
-                *length += value_length;
-                *length += IMPAD (value_length);
-                list_num++;
-                break;
-            }
-            /*endif*/
-        }
-        /*endfor*/
-    }
-    /*endfor*/
-    *number = number_ret;
-    return attrib_list;
-}
-
-static void GetIMValuesMessageProc (XIMS ims,
-                                    IMProtocol *call_data,
-                                    unsigned char *p)
-{
-    Xi18n i18n_core = ims->protocol;
-    FrameMgr fm;
-    FmStatus status;
-    extern XimFrameRec get_im_values_fr[];
-    extern XimFrameRec get_im_values_reply_fr[];
-    CARD16 byte_length;
-    int list_len, total_size;
-    unsigned char *reply = NULL;
-    int iter_count;
-    register int i;
-    register int j;
-    int number;
-    CARD16 *im_attrID_list;
-    char **name_list;
-    CARD16 name_number;
-    XIMAttribute *im_attribute_list;
-    IMGetIMValuesStruct *getim = (IMGetIMValuesStruct *)&call_data->getim;
-    CARD16 connect_id = call_data->any.connect_id;
-    CARD16 input_method_ID;
-
-    /* create FrameMgr */
-    fm = FrameMgrInit (get_im_values_fr,
-                       (char *) p,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-
-    FrameMgrGetToken (fm, input_method_ID);
-    FrameMgrGetToken (fm, byte_length);
-    im_attrID_list = (CARD16 *) malloc (sizeof (CARD16)*20);
-    memset (im_attrID_list, 0, sizeof (CARD16)*20);
-    name_list = (char **)malloc(sizeof(char *) * 20);
-    memset(name_list, 0, sizeof(char *) * 20);
-    number = 0;
-    while (FrameMgrIsIterLoopEnd (fm, &status) == False)
-    {
-        FrameMgrGetToken (fm, im_attrID_list[number]);
-        number++;
-    }
-    FrameMgrFree (fm);
-
-    name_number = 0;
-    for (i = 0;  i < number;  i++) {
-        for (j = 0;  j < i18n_core->address.im_attr_num;  j++) {
-            if (i18n_core->address.xim_attr[j].attribute_id ==
-                    im_attrID_list[i]) {
-                name_list[name_number++] = 
-                       i18n_core->address.xim_attr[j].name;
-                break;
-            }
-        }
-    }
-    getim->number = name_number;
-    getim->im_attr_list = name_list;
-    XFree (name_list);
-
-
-#ifdef PROTOCOL_RICH
-    if (i18n_core->address.improto) {
-        if (!(i18n_core->address.improto (ims, call_data)))
-            return;
-    }
-#endif  /* PROTOCOL_RICH */
-
-    im_attribute_list = MakeIMAttributeList (i18n_core,
-                                             connect_id,
-                                             im_attrID_list,
-                                             &number,
-                                             &list_len);
-    if (im_attrID_list)
-        XFree (im_attrID_list);
-    /*endif*/
-
-    fm = FrameMgrInit (get_im_values_reply_fr,
-                       NULL,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-
-    iter_count = number;
-
-    /* set iteration count for list of im_attribute */
-    FrameMgrSetIterCount (fm, iter_count);
-
-    /* set length of BARRAY item in ximattribute_fr */
-    for (i = 0;  i < iter_count;  i++)
-        FrameMgrSetSize (fm, im_attribute_list[i].value_length);
-    /*endfor*/
-    
-    total_size = FrameMgrGetTotalSize (fm);
-    reply = (unsigned char *) malloc (total_size);
-    if (!reply)
-    {
-        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
-        return;
-    }
-    /*endif*/
-    memset (reply, 0, total_size);
-    FrameMgrSetBuffer (fm, reply);
-
-    FrameMgrPutToken (fm, input_method_ID);
-
-    for (i = 0;  i < iter_count;  i++)
-    {
-        FrameMgrPutToken (fm, im_attribute_list[i].attribute_id);
-        FrameMgrPutToken (fm, im_attribute_list[i].value_length);
-        FrameMgrPutToken (fm, im_attribute_list[i].value);
-    }
-    /*endfor*/
-    _Xi18nSendMessage (ims,
-                       connect_id,
-                       XIM_GET_IM_VALUES_REPLY,
-                       0,
-                       reply,
-                       total_size);
-    FrameMgrFree (fm);
-    XFree (reply);
-
-    for (i = 0; i < iter_count; i++)
-        XFree(im_attribute_list[i].value);
-    XFree (im_attribute_list);
-}
-
-static void CreateICMessageProc (XIMS ims,
-                                 IMProtocol *call_data,
-                                 unsigned char *p)
-{
-    _Xi18nChangeIC (ims, call_data, p, True);
-}
-
-static void SetICValuesMessageProc (XIMS ims,
-                                    IMProtocol *call_data,
-                                    unsigned char *p)
-{
-    _Xi18nChangeIC (ims, call_data, p, False);
-}
-
-static void GetICValuesMessageProc (XIMS ims,
-                                    IMProtocol *call_data,
-                                    unsigned char *p)
-{
-    _Xi18nGetIC (ims, call_data, p);
-}
-
-static void SetICFocusMessageProc (XIMS ims,
-                                   IMProtocol *call_data,
-                                   unsigned char *p)
-{
-    Xi18n i18n_core = ims->protocol;
-    FrameMgr fm;
-    extern XimFrameRec set_ic_focus_fr[];
-    IMChangeFocusStruct *setfocus;
-    CARD16 connect_id = call_data->any.connect_id;
-    CARD16 input_method_ID;
-
-    setfocus = (IMChangeFocusStruct *) &call_data->changefocus;
-
-    fm = FrameMgrInit (set_ic_focus_fr,
-                       (char *) p,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-
-    /* get data */
-    FrameMgrGetToken (fm, input_method_ID);
-    FrameMgrGetToken (fm, setfocus->icid);
-
-    FrameMgrFree (fm);
-
-    if (i18n_core->address.improto)
-    {
-        if (!(i18n_core->address.improto (ims, call_data)))
-            return;
-        /*endif*/
-    }
-    /*endif*/
-}
-
-static void UnsetICFocusMessageProc (XIMS ims,
-                                     IMProtocol *call_data,
-                                     unsigned char *p)
-{
-    Xi18n i18n_core = ims->protocol;
-    FrameMgr fm;
-    extern XimFrameRec unset_ic_focus_fr[];
-    IMChangeFocusStruct *unsetfocus;
-    CARD16 connect_id = call_data->any.connect_id;
-    CARD16 input_method_ID;
-
-    unsetfocus = (IMChangeFocusStruct *) &call_data->changefocus;
-
-    fm = FrameMgrInit (unset_ic_focus_fr,
-                       (char *) p,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-
-    /* get data */
-    FrameMgrGetToken (fm, input_method_ID);
-    FrameMgrGetToken (fm, unsetfocus->icid);
-
-    FrameMgrFree (fm);
-
-    if (i18n_core->address.improto)
-    {
-        if (!(i18n_core->address.improto (ims, call_data)))
-            return;
-        /*endif*/
-    }
-    /*endif*/
-}
-
-static void DestroyICMessageProc (XIMS ims,
-                                  IMProtocol *call_data,
-                                  unsigned char *p)
-{
-    Xi18n i18n_core = ims->protocol;
-    FrameMgr fm;
-    extern XimFrameRec destroy_ic_fr[];
-    extern XimFrameRec destroy_ic_reply_fr[];
-    register int total_size;
-    unsigned char *reply = NULL;
-    IMDestroyICStruct *destroy =
-        (IMDestroyICStruct *) &call_data->destroyic;
-    CARD16 connect_id = call_data->any.connect_id;
-    CARD16 input_method_ID;
-
-    fm = FrameMgrInit (destroy_ic_fr,
-                       (char *) p,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-
-    /* get data */
-    FrameMgrGetToken (fm, input_method_ID);
-    FrameMgrGetToken (fm, destroy->icid);
-
-    FrameMgrFree (fm);
-
-    if (i18n_core->address.improto)
-    {
-        if (!(i18n_core->address.improto (ims, call_data)))
-            return;
-        /*endif*/
-    }
-    /*endif*/
-    
-    fm = FrameMgrInit (destroy_ic_reply_fr,
-                       NULL,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-
-    total_size = FrameMgrGetTotalSize (fm);
-    reply = (unsigned char *) malloc (total_size);
-    if (!reply)
-    {
-        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
-        return;
-    }
-    /*endif*/
-    memset (reply, 0, total_size);
-    FrameMgrSetBuffer (fm, reply);
-
-    FrameMgrPutToken (fm, input_method_ID);
-    FrameMgrPutToken (fm, destroy->icid);
-
-    _Xi18nSendMessage (ims,
-                       connect_id,
-                       XIM_DESTROY_IC_REPLY,
-                       0,
-                       reply,
-                       total_size);
-    XFree(reply);
-    FrameMgrFree (fm);
-}
-
-static void ResetICMessageProc (XIMS ims,
-                                IMProtocol *call_data,
-                                unsigned char *p)
-{
-    Xi18n i18n_core = ims->protocol;
-    FrameMgr fm;
-    extern XimFrameRec reset_ic_fr[];
-    extern XimFrameRec reset_ic_reply_fr[];
-    register int total_size;
-    unsigned char *reply = NULL;
-    IMResetICStruct *resetic =
-        (IMResetICStruct *) &call_data->resetic;
-    CARD16 connect_id = call_data->any.connect_id;
-    CARD16 input_method_ID;
-
-    fm = FrameMgrInit (reset_ic_fr,
-                       (char *) p,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-
-    /* get data */
-    FrameMgrGetToken (fm, input_method_ID);
-    FrameMgrGetToken (fm, resetic->icid);
-
-    FrameMgrFree (fm);
-
-    if (i18n_core->address.improto)
-    {
-        if (!(i18n_core->address.improto(ims, call_data)))
-            return;
-        /*endif*/
-    }
-    /*endif*/
-    
-    /* create FrameMgr */
-    fm = FrameMgrInit (reset_ic_reply_fr,
-                       NULL,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-
-    /* set length of STRING8 */
-    FrameMgrSetSize (fm, resetic->length);
-
-    total_size = FrameMgrGetTotalSize (fm);
-    reply = (unsigned char *) malloc (total_size);
-    if (!reply)
-    {
-        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
-        return;
-    }
-    /*endif*/
-    memset (reply, 0, total_size);
-    FrameMgrSetBuffer (fm, reply);
-
-    FrameMgrPutToken (fm, input_method_ID);
-    FrameMgrPutToken (fm, resetic->icid);
-    FrameMgrPutToken(fm, resetic->length);
-    FrameMgrPutToken (fm, resetic->commit_string);
-
-    _Xi18nSendMessage (ims,
-                       connect_id,
-                       XIM_RESET_IC_REPLY,
-                       0,
-                       reply,
-                       total_size);
-    FrameMgrFree (fm);
-    XFree(reply);
-}
-
-static int WireEventToEvent (Xi18n i18n_core,
-                             xEvent *event,
-                             CARD16 serial,
-                             XEvent *ev,
-                             Bool byte_swap)
-{
-    FrameMgr fm;
-    extern XimFrameRec wire_keyevent_fr[];
-    BYTE b;
-    CARD16 c16;
-    CARD32 c32;
-    int ret = False;
-
-    /* create FrameMgr */
-    fm = FrameMgrInit(wire_keyevent_fr, (char *)(&(event->u)), byte_swap);
-
-
-    /* get & set type */
-    FrameMgrGetToken(fm, b);
-    ev->type = (unsigned int)b;
-    /* get detail */
-    FrameMgrGetToken(fm, b);
-    /* get & set serial */
-    FrameMgrGetToken(fm, c16);
-    ev->xany.serial = (unsigned long)c16;
-    ev->xany.serial |= serial << 16;
-    ev->xany.send_event = False;
-    ev->xany.display = i18n_core->address.dpy;
-
-    /* Remove SendEvent flag from event type to emulate KeyPress/Release */
-    ev->type &= 0x7F;
-
-    switch (ev->type) {
-      case KeyPress:
-      case KeyRelease:
-      {
-          XKeyEvent *kev = (XKeyEvent*)ev;
-
-          /* set keycode (detail) */
-          kev->keycode = (unsigned int)b;
-
-          /* get & set values */
-          FrameMgrGetToken(fm, c32); kev->time = (Time)c32;
-          FrameMgrGetToken(fm, c32); kev->root = (Window)c32;
-          FrameMgrGetToken(fm, c32); kev->window = (Window)c32;
-          FrameMgrGetToken(fm, c32); kev->subwindow = (Window)c32;
-          FrameMgrGetToken(fm, c16); kev->x_root = (int)c16;
-          FrameMgrGetToken(fm, c16); kev->y_root = (int)c16;
-          FrameMgrGetToken(fm, c16); kev->x = (int)c16;
-          FrameMgrGetToken(fm, c16); kev->y = (int)c16;
-          FrameMgrGetToken(fm, c16); kev->state = (unsigned int)c16;
-          FrameMgrGetToken(fm, b);   kev->same_screen = (Bool)b;
-      }
-      ret = True;
-      break;
-      default:
-      break;
-    }
-    /* free FrameMgr */
-    FrameMgrFree(fm);
-    return ret;
-}
-
-static void ForwardEventMessageProc (XIMS ims,
-                                     IMProtocol *call_data,
-                                     unsigned char *p)
-{
-    Xi18n i18n_core = ims->protocol;
-    FrameMgr fm;
-    extern XimFrameRec forward_event_fr[];
-    xEvent wire_event;
-    IMForwardEventStruct *forward =
-        (IMForwardEventStruct*) &call_data->forwardevent;
-    CARD16 connect_id = call_data->any.connect_id;
-    CARD16 input_method_ID;
-
-    fm = FrameMgrInit (forward_event_fr,
-                       (char *) p,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-    /* get data */
-    FrameMgrGetToken (fm, input_method_ID);
-    FrameMgrGetToken (fm, forward->icid);
-    FrameMgrGetToken (fm, forward->sync_bit);
-    FrameMgrGetToken (fm, forward->serial_number);
-    p += sizeof (CARD16)*4;
-    memmove (&wire_event, p, sizeof (xEvent));
-
-    FrameMgrFree (fm);
-
-    if (WireEventToEvent (i18n_core,
-                          &wire_event,
-                          forward->serial_number,
-                          &forward->event,
-                         _Xi18nNeedSwap (i18n_core, connect_id)) == True)
-    {
-        if (i18n_core->address.improto)
-        {
-            if (!(i18n_core->address.improto(ims, call_data)))
-                return;
-            /*endif*/
-        }
-        /*endif*/
-    }
-    /*endif*/
-}
-
-static void ExtForwardKeyEventMessageProc (XIMS ims,
-                                           IMProtocol *call_data,
-                                           unsigned char *p)
-{
-    Xi18n i18n_core = ims->protocol;
-    FrameMgr fm;
-    extern XimFrameRec ext_forward_keyevent_fr[];
-    CARD8 type, keycode;
-    CARD16 state;
-    CARD32 ev_time, window;
-    IMForwardEventStruct *forward =
-        (IMForwardEventStruct *) &call_data->forwardevent;
-    XEvent *ev = (XEvent *) &forward->event;
-    CARD16 connect_id = call_data->any.connect_id;
-    CARD16 input_method_ID;
-
-    fm = FrameMgrInit (ext_forward_keyevent_fr,
-                       (char *) p,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-    /* get data */
-    FrameMgrGetToken (fm, input_method_ID);
-    FrameMgrGetToken (fm, forward->icid);
-    FrameMgrGetToken (fm, forward->sync_bit);
-    FrameMgrGetToken (fm, forward->serial_number);
-    FrameMgrGetToken (fm, type);
-    FrameMgrGetToken (fm, keycode);
-    FrameMgrGetToken (fm, state);
-    FrameMgrGetToken (fm, ev_time);
-    FrameMgrGetToken (fm, window);
-
-    FrameMgrFree (fm);
-
-    if (type != KeyPress)
-    {
-        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
-        return;
-    }
-    /*endif*/
-    
-    /* make a faked keypress event */
-    ev->type = (int)type;
-    ev->xany.send_event = True;
-    ev->xany.display = i18n_core->address.dpy;
-    ev->xany.serial = (unsigned long) forward->serial_number;
-    ((XKeyEvent *) ev)->keycode = (unsigned int) keycode;
-    ((XKeyEvent *) ev)->state = (unsigned int) state;
-    ((XKeyEvent *) ev)->time = (Time) ev_time;
-    ((XKeyEvent *) ev)->window = (Window) window;
-    ((XKeyEvent *) ev)->root = DefaultRootWindow (ev->xany.display);
-    ((XKeyEvent *) ev)->x = 0;
-    ((XKeyEvent *) ev)->y = 0;
-    ((XKeyEvent *) ev)->x_root = 0;
-    ((XKeyEvent *) ev)->y_root = 0;
-
-    if (i18n_core->address.improto)
-    {
-        if (!(i18n_core->address.improto (ims, call_data)))
-            return;
-        /*endif*/
-    }
-    /*endif*/
-}
-
-static void ExtMoveMessageProc (XIMS ims,
-                                IMProtocol *call_data,
-                                unsigned char *p)
-{
-    Xi18n i18n_core = ims->protocol;
-    FrameMgr fm;
-    extern XimFrameRec ext_move_fr[];
-    IMMoveStruct *extmove =
-        (IMMoveStruct*) & call_data->extmove;
-    CARD16 connect_id = call_data->any.connect_id;
-    CARD16 input_method_ID;
-
-    fm = FrameMgrInit (ext_move_fr,
-                       (char *) p,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-    /* get data */
-    FrameMgrGetToken (fm, input_method_ID);
-    FrameMgrGetToken (fm, extmove->icid);
-    FrameMgrGetToken (fm, extmove->x);
-    FrameMgrGetToken (fm, extmove->y);
-
-    FrameMgrFree (fm);
-
-    if (i18n_core->address.improto)
-    {
-        if (!(i18n_core->address.improto (ims, call_data)))
-            return;
-        /*endif*/
-    }
-    /*endif*/
-}
-
-static void ExtensionMessageProc (XIMS ims,
-                                  IMProtocol *call_data,
-                                  unsigned char *p)
-{
-    switch (call_data->any.minor_code)
-    {
-    case XIM_EXT_FORWARD_KEYEVENT:
-        ExtForwardKeyEventMessageProc (ims, call_data, p);
-        break;
-
-    case XIM_EXT_MOVE:
-        ExtMoveMessageProc (ims, call_data, p);
-        break;
-    }
-    /*endswitch*/
-}
-
-static void TriggerNotifyMessageProc (XIMS ims,
-                                      IMProtocol *call_data,
-                                      unsigned char *p)
-{
-    Xi18n i18n_core = ims->protocol;
-    FrameMgr fm;
-    extern XimFrameRec trigger_notify_fr[], trigger_notify_reply_fr[];
-    register int total_size;
-    unsigned char *reply = NULL;
-    IMTriggerNotifyStruct *trigger =
-        (IMTriggerNotifyStruct *) &call_data->triggernotify;
-    CARD16 connect_id = call_data->any.connect_id;
-    CARD16 input_method_ID;
-    CARD32 flag;
-
-    fm = FrameMgrInit (trigger_notify_fr,
-                       (char *) p,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-    /* get data */
-    FrameMgrGetToken (fm, input_method_ID);
-    FrameMgrGetToken (fm, trigger->icid);
-    FrameMgrGetToken (fm, trigger->flag);
-    FrameMgrGetToken (fm, trigger->key_index);
-    FrameMgrGetToken (fm, trigger->event_mask);
-    /*
-      In order to support Front End Method, this event_mask must be saved
-      per clients so that it should be restored by an XIM_EXT_SET_EVENT_MASK
-      call when preediting mode is reset to off.
-     */
-
-    flag = trigger->flag;
-
-    FrameMgrFree (fm);
-
-    fm = FrameMgrInit (trigger_notify_reply_fr,
-                       NULL,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-    total_size = FrameMgrGetTotalSize (fm);
-    reply = (unsigned char *) malloc (total_size);
-    if (!reply)
-    {
-        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
-        return;
-    }
-    /*endif*/
-    memset (reply, 0, total_size);
-    FrameMgrSetBuffer (fm, reply);
-
-    FrameMgrPutToken (fm, input_method_ID);
-    FrameMgrPutToken (fm, trigger->icid);
-
-    /* NOTE:
-       XIM_TRIGGER_NOTIFY_REPLY should be sent before XIM_SET_EVENT_MASK
-       in case of XIM_TRIGGER_NOTIFY(flag == ON), while it should be
-       sent after XIM_SET_EVENT_MASK in case of
-       XIM_TRIGGER_NOTIFY(flag == OFF).
-       */
-    if (flag == 0)
-    {
-        /* on key */
-        _Xi18nSendMessage (ims,
-                           connect_id,
-                           XIM_TRIGGER_NOTIFY_REPLY,
-                           0,
-                           reply,
-                           total_size);
-        IMPreeditStart (ims, (XPointer)call_data);
-    }
-    /*endif*/
-    if (i18n_core->address.improto)
-    {
-        if (!(i18n_core->address.improto(ims, call_data)))
-            return;
-        /*endif*/
-    }
-    /*endif*/
-
-    if (flag == 1)
-    {
-        /* off key */
-        IMPreeditEnd (ims, (XPointer) call_data);
-        _Xi18nSendMessage (ims,
-                           connect_id,
-                           XIM_TRIGGER_NOTIFY_REPLY,
-                           0,
-                           reply,
-                           total_size);
-    }
-    /*endif*/
-    FrameMgrFree (fm);
-    XFree (reply);
-}
-
-static INT16 ChooseEncoding (Xi18n i18n_core,
-                             IMEncodingNegotiationStruct *enc_nego)
-{
-    Xi18nAddressRec *address = (Xi18nAddressRec *) & i18n_core->address;
-    XIMEncodings *p;
-    int i, j;
-    int enc_index=0;
-
-    p = (XIMEncodings *) &address->encoding_list;
-    for (i = 0;  i < (int) p->count_encodings;  i++)
-    {
-        for (j = 0;  j < (int) enc_nego->encoding_number;  j++)
-        {
-            if (strcmp (p->supported_encodings[i],
-                        enc_nego->encoding[j].name) == 0)
-            {
-                enc_index = j;
-                break;
-            }
-            /*endif*/
-        }
-        /*endfor*/
-    }
-    /*endfor*/
-
-    return (INT16) enc_index;
-#if 0
-    return (INT16) XIM_Default_Encoding_IDX;
-#endif
-}
-
-static void EncodingNegotiatonMessageProc (XIMS ims,
-                                           IMProtocol *call_data,
-                                           unsigned char *p)
-{
-    Xi18n i18n_core = ims->protocol;
-    FrameMgr fm;
-    FmStatus status;
-    CARD16 byte_length;
-    extern XimFrameRec encoding_negotiation_fr[];
-    extern XimFrameRec encoding_negotiation_reply_fr[];
-    register int i, total_size;
-    unsigned char *reply = NULL;
-    IMEncodingNegotiationStruct *enc_nego =
-        (IMEncodingNegotiationStruct *) &call_data->encodingnego;
-    CARD16 connect_id = call_data->any.connect_id;
-    CARD16 input_method_ID;
-
-    fm = FrameMgrInit (encoding_negotiation_fr,
-                       (char *) p,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-
-    FrameMgrGetToken (fm, input_method_ID);
-
-    /* get ENCODING STR field */
-    FrameMgrGetToken (fm, byte_length);
-    if (byte_length > 0)
-    {
-        enc_nego->encoding = (XIMStr *) malloc (sizeof (XIMStr)*10);
-        memset (enc_nego->encoding, 0, sizeof (XIMStr)*10);
-        i = 0;
-        while (FrameMgrIsIterLoopEnd (fm, &status) == False)
-        {
-            char *name;
-            int str_length;
-            
-            FrameMgrGetToken (fm, str_length);
-            FrameMgrSetSize (fm, str_length);
-            enc_nego->encoding[i].length = str_length;
-            FrameMgrGetToken (fm, name);
-            enc_nego->encoding[i].name = malloc (str_length + 1);
-            strncpy (enc_nego->encoding[i].name, name, str_length);
-            enc_nego->encoding[i].name[str_length] = '\0';
-            i++;
-        }
-        /*endwhile*/
-        enc_nego->encoding_number = i;
-    }
-    /*endif*/
-    /* get ENCODING INFO field */
-    FrameMgrGetToken (fm, byte_length);
-    if (byte_length > 0)
-    {
-        enc_nego->encodinginfo = (XIMStr *) malloc (sizeof (XIMStr)*10);
-        memset (enc_nego->encoding, 0, sizeof (XIMStr)*10);
-        i = 0;
-        while (FrameMgrIsIterLoopEnd (fm, &status) == False)
-        {
-            char *name;
-            int str_length;
-            
-            FrameMgrGetToken (fm, str_length);
-            FrameMgrSetSize (fm, str_length);
-            enc_nego->encodinginfo[i].length = str_length;
-            FrameMgrGetToken (fm, name);
-            enc_nego->encodinginfo[i].name = malloc (str_length + 1);
-            strncpy (enc_nego->encodinginfo[i].name, name, str_length);
-            enc_nego->encodinginfo[i].name[str_length] = '\0';
-            i++;
-        }
-        /*endwhile*/
-        enc_nego->encoding_info_number = i;
-    }
-    /*endif*/
-
-    enc_nego->enc_index = ChooseEncoding (i18n_core, enc_nego);
-    enc_nego->category = 0;
-
-#ifdef PROTOCOL_RICH
-    if (i18n_core->address.improto)
-    {
-        if (!(i18n_core->address.improto(ims, call_data)))
-            return;
-        /*endif*/
-    }
-    /*endif*/
-#endif  /* PROTOCOL_RICH */
-
-    FrameMgrFree (fm);
-
-    fm = FrameMgrInit (encoding_negotiation_reply_fr,
-                       NULL,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-
-    total_size = FrameMgrGetTotalSize (fm);
-    reply = (unsigned char *) malloc (total_size);
-    if (!reply)
-    {
-        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
-        return;
-    }
-    /*endif*/
-    memset (reply, 0, total_size);
-    FrameMgrSetBuffer (fm, reply);
-
-    FrameMgrPutToken (fm, input_method_ID);
-    FrameMgrPutToken (fm, enc_nego->category);
-    FrameMgrPutToken (fm, enc_nego->enc_index);
-
-    _Xi18nSendMessage (ims,
-                       connect_id,
-                       XIM_ENCODING_NEGOTIATION_REPLY,
-                       0,
-                       reply,
-                       total_size);
-    XFree (reply);
-
-    /* free data for encoding list */
-    if (enc_nego->encoding)
-    {
-        for (i = 0;  i < (int) enc_nego->encoding_number;  i++)
-            XFree (enc_nego->encoding[i].name);
-        /*endfor*/
-        XFree (enc_nego->encoding);
-    }
-    /*endif*/
-    if (enc_nego->encodinginfo)
-    {
-        for (i = 0;  i < (int) enc_nego->encoding_info_number;  i++)
-            XFree (enc_nego->encodinginfo[i].name);
-        /*endfor*/
-        XFree (enc_nego->encodinginfo);
-    }
-    /*endif*/
-    FrameMgrFree (fm);
-}
-
-void PreeditStartReplyMessageProc (XIMS ims,
-                                   IMProtocol *call_data,
-                                   unsigned char *p)
-{
-    Xi18n i18n_core = ims->protocol;
-    FrameMgr fm;
-    extern XimFrameRec preedit_start_reply_fr[];
-    IMPreeditCBStruct *preedit_CB =
-        (IMPreeditCBStruct *) &call_data->preedit_callback;
-    CARD16 connect_id = call_data->any.connect_id;
-    CARD16 input_method_ID;
-
-    fm = FrameMgrInit (preedit_start_reply_fr,
-                       (char *) p,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-    /* get data */
-    FrameMgrGetToken (fm, input_method_ID);
-    FrameMgrGetToken (fm, preedit_CB->icid);
-    FrameMgrGetToken (fm, preedit_CB->todo.return_value);
-
-    FrameMgrFree (fm);
-
-    if (i18n_core->address.improto)
-    {
-        if (!(i18n_core->address.improto (ims, call_data)))
-            return;
-        /*endif*/
-    }
-    /*endif*/
-}
-
-void PreeditCaretReplyMessageProc (XIMS ims,
-                                   IMProtocol *call_data,
-                                   unsigned char *p)
-{
-    Xi18n i18n_core = ims->protocol;
-    FrameMgr fm;
-    extern XimFrameRec preedit_caret_reply_fr[];
-    IMPreeditCBStruct *preedit_CB =
-        (IMPreeditCBStruct *) &call_data->preedit_callback;
-    XIMPreeditCaretCallbackStruct *caret =
-        (XIMPreeditCaretCallbackStruct *) & preedit_CB->todo.caret;
-    CARD16 connect_id = call_data->any.connect_id;
-    CARD16 input_method_ID;
-
-    fm = FrameMgrInit (preedit_caret_reply_fr,
-                       (char *) p,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-    /* get data */
-    FrameMgrGetToken (fm, input_method_ID);
-    FrameMgrGetToken (fm, preedit_CB->icid);
-    FrameMgrGetToken (fm, caret->position);
-
-    FrameMgrFree (fm);
-
-    if (i18n_core->address.improto)
-    {
-        if (!(i18n_core->address.improto(ims, call_data)))
-            return;
-        /*endif*/
-    }
-    /*endif*/
-}
-
-void StrConvReplyMessageProc (XIMS ims,
-                              IMProtocol *call_data,
-                              unsigned char *p)
-{
-    return;
-}
-
-static void AddQueue (Xi18nClient *client, unsigned char *p)
-{
-    XIMPending *new;
-    XIMPending *last;
-
-    if ((new = (XIMPending *) malloc (sizeof (XIMPending))) == NULL)
-        return;
-    /*endif*/
-    new->p = p;
-    new->next = (XIMPending *) NULL;
-    if (!client->pending)
-    {
-        client->pending = new;
-    }
-    else
-    {
-        for (last = client->pending;  last->next;  last = last->next)
-            ;
-        /*endfor*/
-        last->next = new;
-    }
-    /*endif*/
-    return;
-}
-
-static void ProcessQueue (XIMS ims, CARD16 connect_id)
-{
-    Xi18n i18n_core = ims->protocol;
-    Xi18nClient *client = (Xi18nClient *) _Xi18nFindClient (i18n_core,
-                                                            connect_id);
-
-    while (client->sync == False  &&  client->pending)
-    {
-        XimProtoHdr *hdr = (XimProtoHdr *) client->pending->p;
-        unsigned char *p1 = (unsigned char *) (hdr + 1);
-        IMProtocol call_data;
-
-        call_data.major_code = hdr->major_opcode;
-        call_data.any.minor_code = hdr->minor_opcode;
-        call_data.any.connect_id = connect_id;
-
-        switch (hdr->major_opcode)
-        {
-        case XIM_FORWARD_EVENT:
-            ForwardEventMessageProc(ims, &call_data, p1);
-            break;
-        }
-        /*endswitch*/
-        XFree (hdr);
-        {
-            XIMPending *old = client->pending;
-
-            client->pending = old->next;
-            XFree (old);
-        }
-    }
-    /*endwhile*/
-    return;
-}
-
-
-void _Xi18nMessageHandler (XIMS ims,
-                           CARD16 connect_id,
-                           unsigned char *p,
-                           Bool *delete)
-{
-    XimProtoHdr        *hdr = (XimProtoHdr *)p;
-    unsigned char *p1 = (unsigned char *)(hdr + 1);
-    IMProtocol call_data;
-    Xi18n i18n_core = ims->protocol;
-    Xi18nClient *client;
-
-    client = (Xi18nClient *) _Xi18nFindClient (i18n_core, connect_id);
-    if (hdr == (XimProtoHdr *) NULL)
-        return;
-    /*endif*/
-    
-    memset (&call_data, 0, sizeof(IMProtocol));
-
-    call_data.major_code = hdr->major_opcode;
-    call_data.any.minor_code = hdr->minor_opcode;
-    call_data.any.connect_id = connect_id;
-
-    switch (call_data.major_code)
-    {
-    case XIM_CONNECT:
-#ifdef XIM_DEBUG
-       DebugLog("-- XIM_CONNECT\n");
-#endif
-        ConnectMessageProc (ims, &call_data, p1);
-        break;
-
-    case XIM_DISCONNECT:
-#ifdef XIM_DEBUG
-       DebugLog("-- XIM_DISCONNECT\n");
-#endif
-        DisConnectMessageProc (ims, &call_data);
-        break;
-
-    case XIM_OPEN:
-#ifdef XIM_DEBUG
-       DebugLog("-- XIM_OPEN\n");
-#endif
-        OpenMessageProc (ims, &call_data, p1);
-        break;
-
-    case XIM_CLOSE:
-#ifdef XIM_DEBUG
-       DebugLog("-- XIM_CLOSE\n");
-#endif
-        CloseMessageProc (ims, &call_data, p1);
-        break;
-
-    case XIM_QUERY_EXTENSION:
-#ifdef XIM_DEBUG
-       DebugLog("-- XIM_QUERY_EXTENSION\n");
-#endif
-        QueryExtensionMessageProc (ims, &call_data, p1);
-        break;
-
-    case XIM_GET_IM_VALUES:
-#ifdef XIM_DEBUG
-       DebugLog("-- XIM_GET_IM_VALUES\n");
-#endif
-        GetIMValuesMessageProc (ims, &call_data, p1);
-        break;
-
-    case XIM_CREATE_IC:
-#ifdef XIM_DEBUG
-       DebugLog("-- XIM_CREATE_IC\n");
-#endif
-        CreateICMessageProc (ims, &call_data, p1);
-        break;
-
-    case XIM_SET_IC_VALUES:
-#ifdef XIM_DEBUG
-       DebugLog("-- XIM_SET_IC_VALUES\n");
-#endif
-        SetICValuesMessageProc (ims, &call_data, p1);
-        break;
-
-    case XIM_GET_IC_VALUES:
-#ifdef XIM_DEBUG
-       DebugLog("-- XIM_GET_IC_VALUES\n");
-#endif
-        GetICValuesMessageProc (ims, &call_data, p1);
-        break;
-
-    case XIM_SET_IC_FOCUS:
-#ifdef XIM_DEBUG
-       DebugLog("-- XIM_SET_IC_FOCUS\n");
-#endif
-        SetICFocusMessageProc (ims, &call_data, p1);
-        break;
-
-    case XIM_UNSET_IC_FOCUS:
-#ifdef XIM_DEBUG
-       DebugLog("-- XIM_UNSET_IC_FOCUS\n");
-#endif
-        UnsetICFocusMessageProc (ims, &call_data, p1);
-        break;
-
-    case XIM_DESTROY_IC:
-#ifdef XIM_DEBUG
-       DebugLog("-- XIM_DESTROY_IC\n");
-#endif
-        DestroyICMessageProc (ims, &call_data, p1);
-        break;
-
-    case XIM_RESET_IC:
-#ifdef XIM_DEBUG
-       DebugLog("-- XIM_RESET_IC\n");
-#endif
-        ResetICMessageProc (ims, &call_data, p1);
-        break;
-
-    case XIM_FORWARD_EVENT:
-#ifdef XIM_DEBUG
-       DebugLog("-- XIM_FORWARD_EVENT\n");
-#endif
-        if (client->sync == True)
-        {
-            AddQueue (client, p);
-            *delete = False;
-        }
-        else
-        {
-            ForwardEventMessageProc (ims, &call_data, p1);
-        }
-        break;
-
-    case XIM_EXTENSION:
-#ifdef XIM_DEBUG
-       DebugLog("-- XIM_EXTENSION\n");
-#endif
-        ExtensionMessageProc (ims, &call_data, p1);
-        break;
-
-    case XIM_SYNC:
-#ifdef XIM_DEBUG
-       DebugLog("-- XIM_SYNC\n");
-#endif
-        break;
-
-    case XIM_SYNC_REPLY:
-#ifdef XIM_DEBUG
-       DebugLog("-- XIM_SYNC_REPLY\n");
-#endif
-        SyncReplyMessageProc (ims, &call_data, p1);
-        ProcessQueue (ims, connect_id);
-        break;
-
-    case XIM_TRIGGER_NOTIFY:
-#ifdef XIM_DEBUG
-       DebugLog("-- XIM_TRIGGER_NOTIFY\n");
-#endif
-        TriggerNotifyMessageProc (ims, &call_data, p1);
-        break;
-
-    case XIM_ENCODING_NEGOTIATION:
-#ifdef XIM_DEBUG
-       DebugLog("-- XIM_ENCODING_NEGOTIATION\n");
-#endif
-        EncodingNegotiatonMessageProc (ims, &call_data, p1);
-        break;
-
-    case XIM_PREEDIT_START_REPLY:
-#ifdef XIM_DEBUG
-       DebugLog("-- XIM_PREEDIT_START_REPLY\n");
-#endif
-        PreeditStartReplyMessageProc (ims, &call_data, p1);
-        break;
-
-    case XIM_PREEDIT_CARET_REPLY:
-#ifdef XIM_DEBUG
-       DebugLog("-- XIM_PREEDIT_CARET_REPLY\n");
-#endif
-        PreeditCaretReplyMessageProc (ims, &call_data, p1);
-        break;
-
-    case XIM_STR_CONVERSION_REPLY:
-#ifdef XIM_DEBUG
-       DebugLog("-- XIM_STR_CONVERSION_REPLY\n");
-#endif
-        StrConvReplyMessageProc (ims, &call_data, p1);
-        break;
-    }
-    /*endswitch*/
-}
diff --git a/x11/IMdkit/i18nUtil.c b/x11/IMdkit/i18nUtil.c
deleted file mode 100644 (file)
index 22a2376..0000000
+++ /dev/null
@@ -1,276 +0,0 @@
-/******************************************************************
-         Copyright 1994, 1995 by Sun Microsystems, Inc.
-         Copyright 1993, 1994 by Hewlett-Packard Company
-Permission to use, copy, modify, distribute, and sell this software
-and its documentation for any purpose is hereby granted without fee,
-provided that the above copyright notice appear in all copies and
-that both that copyright notice and this permission notice appear
-in supporting documentation, and that the name of Sun Microsystems, Inc.
-and Hewlett-Packard not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior permission.
-Sun Microsystems, Inc. and Hewlett-Packard make no representations about
-the suitability of this software for any purpose.  It is provided "as is"
-without express or implied warranty.
-SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL
-WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
-RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
-CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
-IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-  Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
-
-    This version tidied and debugged by Steve Underwood May 1999
-******************************************************************/
-
-#include <X11/Xlib.h>
-#include "IMdkit.h"
-#include "Xi18n.h"
-#include "FrameMgr.h"
-#include "XimFunc.h"
-
-Xi18nClient *_Xi18nFindClient (Xi18n, CARD16);
-
-int
-_Xi18nNeedSwap (Xi18n i18n_core, CARD16 connect_id)
-{
-    CARD8 im_byteOrder = i18n_core->address.im_byteOrder;
-    Xi18nClient *client = _Xi18nFindClient (i18n_core, connect_id);
-
-    return (client->byte_order != im_byteOrder);
-}
-
-Xi18nClient *_Xi18nNewClient(Xi18n i18n_core)
-{
-    static CARD16 connect_id = 0;
-    int new_connect_id;
-    Xi18nClient *client;
-
-    if (i18n_core->address.free_clients)
-    {
-        client = i18n_core->address.free_clients;
-        i18n_core->address.free_clients = client->next;
-       new_connect_id = client->connect_id;
-    }
-    else
-    {
-        client = (Xi18nClient *) malloc (sizeof (Xi18nClient));
-       new_connect_id = ++connect_id;
-    }
-    /*endif*/
-    memset (client, 0, sizeof (Xi18nClient));
-    client->connect_id = new_connect_id;
-    client->pending = (XIMPending *) NULL;
-    client->sync = False;
-    client->byte_order = '?';  /* initial value */
-    memset (&client->pending, 0, sizeof (XIMPending *));
-    client->next = i18n_core->address.clients;
-    i18n_core->address.clients = client;
-
-    return (Xi18nClient *) client;
-}
-
-Xi18nClient *_Xi18nFindClient (Xi18n i18n_core, CARD16 connect_id)
-{
-    Xi18nClient *client = i18n_core->address.clients;
-
-    while (client)
-    {
-        if (client->connect_id == connect_id)
-            return client;
-        /*endif*/
-        client = client->next;
-    }
-    /*endwhile*/
-    return NULL;
-}
-
-void _Xi18nDeleteClient (Xi18n i18n_core, CARD16 connect_id)
-{
-    Xi18nClient *target = _Xi18nFindClient (i18n_core, connect_id);
-    Xi18nClient *ccp;
-    Xi18nClient *ccp0;
-
-    for (ccp = i18n_core->address.clients, ccp0 = NULL;
-         ccp != NULL;
-         ccp0 = ccp, ccp = ccp->next)
-    {
-        if (ccp == target)
-        {
-            if (ccp0 == NULL)
-                i18n_core->address.clients = ccp->next;
-            else
-                ccp0->next = ccp->next;
-            /*endif*/
-            /* put it back to free list */
-            target->next = i18n_core->address.free_clients;
-            i18n_core->address.free_clients = target;
-            return;
-        }
-        /*endif*/
-    }
-    /*endfor*/
-}
-
-void _Xi18nSendMessage (XIMS ims,
-                        CARD16 connect_id,
-                        CARD8 major_opcode,
-                        CARD8 minor_opcode,
-                        unsigned char *data,
-                        long length)
-{
-    Xi18n i18n_core = ims->protocol;
-    FrameMgr fm;
-    extern XimFrameRec packet_header_fr[];
-    unsigned char *reply_hdr = NULL;
-    int header_size;
-    unsigned char *reply = NULL;
-    unsigned char *replyp;
-    int reply_length;
-    long p_len = length/4;
-
-    fm = FrameMgrInit (packet_header_fr,
-                       NULL,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-
-    header_size = FrameMgrGetTotalSize (fm);
-    reply_hdr = (unsigned char *) malloc (header_size);
-    if (reply_hdr == NULL)
-    {
-        _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0);
-        return;
-    }
-    /*endif*/
-    FrameMgrSetBuffer (fm, reply_hdr);
-
-    /* put data */
-    FrameMgrPutToken (fm, major_opcode);
-    FrameMgrPutToken (fm, minor_opcode);
-    FrameMgrPutToken (fm, p_len);
-
-    reply_length = header_size + length;
-    reply = (unsigned char *) malloc (reply_length);
-    replyp = reply;
-    memmove (reply, reply_hdr, header_size);
-    replyp += header_size;
-    memmove (replyp, data, length);
-
-    i18n_core->methods.send (ims, connect_id, reply, reply_length);
-
-    XFree (reply);
-    XFree (reply_hdr);
-    FrameMgrFree (fm);
-}
-
-void _Xi18nSendTriggerKey (XIMS ims, CARD16 connect_id)
-{
-    Xi18n i18n_core = ims->protocol;
-    FrameMgr fm;
-    extern XimFrameRec register_triggerkeys_fr[];
-    XIMTriggerKey *on_keys = i18n_core->address.on_keys.keylist;
-    XIMTriggerKey *off_keys = i18n_core->address.off_keys.keylist;
-    int on_key_num = i18n_core->address.on_keys.count_keys;
-    int off_key_num = i18n_core->address.off_keys.count_keys;
-    unsigned char *reply = NULL;
-    register int i, total_size;
-    CARD16 im_id;
-
-    if (on_key_num == 0  &&  off_key_num == 0)
-        return;
-    /*endif*/
-    
-    fm = FrameMgrInit (register_triggerkeys_fr,
-                       NULL,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-
-    /* set iteration count for on-keys list */
-    FrameMgrSetIterCount (fm, on_key_num);
-    /* set iteration count for off-keys list */
-    FrameMgrSetIterCount (fm, off_key_num);
-
-    /* get total_size */
-    total_size = FrameMgrGetTotalSize (fm);
-
-    reply = (unsigned char *) malloc (total_size);
-    if (!reply)
-        return;
-    /*endif*/
-    memset (reply, 0, total_size);
-    FrameMgrSetBuffer (fm, reply);
-
-    /* Right now XIM_OPEN_REPLY hasn't been sent to this new client, so
-       the input-method-id is still invalid, and should be set to zero...
-       Reter to $(XC)/lib/X11/imDefLkup.c:_XimRegisterTriggerKeysCallback
-     */
-    im_id = 0;
-    FrameMgrPutToken (fm, im_id);  /* input-method-id */
-    for (i = 0;  i < on_key_num;  i++)
-    {
-        FrameMgrPutToken (fm, on_keys[i].keysym);
-        FrameMgrPutToken (fm, on_keys[i].modifier);
-        FrameMgrPutToken (fm, on_keys[i].modifier_mask);
-    }
-    /*endfor*/
-    for (i = 0;  i < off_key_num;  i++)
-    {
-        FrameMgrPutToken (fm, off_keys[i].keysym);
-        FrameMgrPutToken (fm, off_keys[i].modifier);
-        FrameMgrPutToken (fm, off_keys[i].modifier_mask);
-    }
-    /*endfor*/
-    _Xi18nSendMessage (ims,
-                       connect_id,
-                       XIM_REGISTER_TRIGGERKEYS,
-                       0,
-                       reply,
-                       total_size);
-    FrameMgrFree (fm);
-    XFree(reply);
-}
-
-void _Xi18nSetEventMask (XIMS ims,
-                         CARD16 connect_id,
-                         CARD16 im_id,
-                         CARD16 ic_id,
-                         CARD32 forward_mask,
-                         CARD32 sync_mask)
-{
-    Xi18n i18n_core = ims->protocol;
-    FrameMgr fm;
-    extern XimFrameRec set_event_mask_fr[];
-    unsigned char *reply = NULL;
-    register int total_size;
-
-    fm = FrameMgrInit (set_event_mask_fr,
-                       NULL,
-                       _Xi18nNeedSwap (i18n_core, connect_id));
-
-    total_size = FrameMgrGetTotalSize (fm);
-    reply = (unsigned char *) malloc (total_size);
-    if (!reply)
-        return;
-    /*endif*/
-    memset (reply, 0, total_size);
-    FrameMgrSetBuffer (fm, reply);
-
-    FrameMgrPutToken (fm, im_id);      /* input-method-id */
-    FrameMgrPutToken (fm, ic_id);      /* input-context-id */
-    FrameMgrPutToken (fm, forward_mask);
-    FrameMgrPutToken (fm, sync_mask);
-
-    _Xi18nSendMessage (ims,
-                       connect_id,
-                       XIM_SET_EVENT_MASK,
-                       0,
-                       reply,
-                       total_size);
-
-    FrameMgrFree (fm);
-    XFree(reply);
-}
diff --git a/x11/IMdkit/i18nX.c b/x11/IMdkit/i18nX.c
deleted file mode 100644 (file)
index a5ba080..0000000
+++ /dev/null
@@ -1,497 +0,0 @@
-/******************************************************************
-         Copyright 1994, 1995 by Sun Microsystems, Inc.
-         Copyright 1993, 1994 by Hewlett-Packard Company
-Permission to use, copy, modify, distribute, and sell this software
-and its documentation for any purpose is hereby granted without fee,
-provided that the above copyright notice appear in all copies and
-that both that copyright notice and this permission notice appear
-in supporting documentation, and that the name of Sun Microsystems, Inc.
-and Hewlett-Packard not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior permission.
-Sun Microsystems, Inc. and Hewlett-Packard make no representations about
-the suitability of this software for any purpose.  It is provided "as is"
-without express or implied warranty.
-SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL
-WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
-RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
-CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
-IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-  Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
-
-    This version tidied and debugged by Steve Underwood May 1999
-******************************************************************/
-
-#include <X11/Xlib.h>
-#include <X11/Xatom.h>
-#include "FrameMgr.h"
-#include "IMdkit.h"
-#include "Xi18n.h"
-#include "Xi18nX.h"
-#include "XimFunc.h"
-
-extern Xi18nClient *_Xi18nFindClient(Xi18n, CARD16);
-extern Xi18nClient *_Xi18nNewClient(Xi18n);
-extern void _Xi18nDeleteClient(Xi18n, CARD16);
-static Bool WaitXConnectMessage(Display*, Window,
-                                XEvent*, XPointer);
-static Bool WaitXIMProtocol(Display*, Window, XEvent*, XPointer);
-
-static XClient *NewXClient (Xi18n i18n_core, Window new_client)
-{
-    Display *dpy = i18n_core->address.dpy;
-    Xi18nClient *client = _Xi18nNewClient (i18n_core);
-    XClient *x_client;
-
-    x_client = (XClient *) malloc (sizeof (XClient));
-    x_client->client_win = new_client;
-    x_client->accept_win = XCreateSimpleWindow (dpy,
-                                                DefaultRootWindow(dpy),
-                                                0,
-                                                0,
-                                                1,
-                                                1,
-                                                1,
-                                                0,
-                                                0);
-    client->trans_rec = x_client;
-    return ((XClient *) x_client);
-}
-
-static unsigned char *ReadXIMMessage (XIMS ims,
-                                      XClientMessageEvent *ev,
-                                      int *connect_id)
-{
-    Xi18n i18n_core = ims->protocol;
-    Xi18nClient *client = i18n_core->address.clients;
-    XClient *x_client = NULL;
-    FrameMgr fm;
-    extern XimFrameRec packet_header_fr[];
-    unsigned char *p = NULL;
-    unsigned char *p1;
-
-    while (client != NULL) {
-        x_client = (XClient *) client->trans_rec;
-        if (x_client->accept_win == ev->window) {
-            *connect_id = client->connect_id;
-            break;
-        }
-        client = client->next;
-    }
-
-    if (ev->format == 8) {
-        /* ClientMessage only */
-        XimProtoHdr *hdr = (XimProtoHdr *) ev->data.b;
-        unsigned char *rec = (unsigned char *) (hdr + 1);
-        register int total_size;
-        CARD8 major_opcode;
-        CARD8 minor_opcode;
-        CARD16 length;
-        extern int _Xi18nNeedSwap (Xi18n, CARD16);
-
-        if (client->byte_order == '?')
-        {
-            if (hdr->major_opcode != XIM_CONNECT)
-                return (unsigned char *) NULL;         /* can do nothing */
-            client->byte_order = (CARD8) rec[0];
-        }
-
-        fm = FrameMgrInit (packet_header_fr,
-                           (char *) hdr,
-                           _Xi18nNeedSwap (i18n_core, *connect_id));
-        total_size = FrameMgrGetTotalSize (fm);
-        /* get data */
-        FrameMgrGetToken (fm, major_opcode);
-        FrameMgrGetToken (fm, minor_opcode);
-        FrameMgrGetToken (fm, length);
-        FrameMgrFree (fm);
-
-        if ((p = (unsigned char *) malloc (total_size + length * 4)) == NULL)
-            return (unsigned char *) NULL;
-
-        p1 = p;
-        memmove (p1, &major_opcode, sizeof (CARD8));
-        p1 += sizeof (CARD8);
-        memmove (p1, &minor_opcode, sizeof (CARD8));
-        p1 += sizeof (CARD8);
-        memmove (p1, &length, sizeof (CARD16));
-        p1 += sizeof (CARD16);
-        memmove (p1, rec, length * 4);
-    }
-    else if (ev->format == 32) {
-        /* ClientMessage and WindowProperty */
-        unsigned long length = (unsigned long) ev->data.l[0];
-        Atom atom = (Atom) ev->data.l[1];
-        int    return_code;
-        Atom   actual_type_ret;
-        int    actual_format_ret;
-        unsigned long bytes_after_ret;
-        unsigned char *prop;
-        unsigned long nitems;
-
-        return_code = XGetWindowProperty (i18n_core->address.dpy,
-                                          x_client->accept_win,
-                                          atom,
-                                          0L,
-                                          length,
-                                          True,
-                                          AnyPropertyType,
-                                          &actual_type_ret,
-                                          &actual_format_ret,
-                                          &nitems,
-                                          &bytes_after_ret,
-                                          &prop);
-        if (return_code != Success || actual_format_ret == 0 || nitems == 0) {
-            if (return_code == Success)
-                XFree (prop);
-            return (unsigned char *) NULL;
-        }
-        if (length != nitems)
-            length = nitems;
-       if (actual_format_ret == 16)
-           length *= 2;
-       else if (actual_format_ret == 32)
-           length *= 4;
-
-        /* if hit, it might be an error */
-        if ((p = (unsigned char *) malloc (length)) == NULL)
-            return (unsigned char *) NULL;
-
-        memmove (p, prop, length);
-        XFree (prop);
-    }
-    return (unsigned char *) p;
-}
-
-static void ReadXConnectMessage (XIMS ims, XClientMessageEvent *ev)
-{
-    Xi18n i18n_core = ims->protocol;
-    XSpecRec *spec = (XSpecRec *) i18n_core->address.connect_addr;
-    XEvent event;
-    Display *dpy = i18n_core->address.dpy;
-    Window new_client = ev->data.l[0];
-    CARD32 major_version = ev->data.l[1];
-    CARD32 minor_version = ev->data.l[2];
-    XClient *x_client = NewXClient (i18n_core, new_client);
-
-    if (ev->window != i18n_core->address.im_window)
-        return;                        /* incorrect connection request */
-    /*endif*/
-    if (major_version != 0  ||  minor_version != 0)
-    {
-        major_version =
-        minor_version = 0;
-        /* Only supporting only-CM & Property-with-CM method */
-    }
-    /*endif*/
-    _XRegisterFilterByType (dpy,
-                            x_client->accept_win,
-                            ClientMessage,
-                            ClientMessage,
-                            WaitXIMProtocol,
-                            (XPointer)ims);
-    event.xclient.type = ClientMessage;
-    event.xclient.display = dpy;
-    event.xclient.window = new_client;
-    event.xclient.message_type = spec->connect_request;
-    event.xclient.format = 32;
-    event.xclient.data.l[0] = x_client->accept_win;
-    event.xclient.data.l[1] = major_version;
-    event.xclient.data.l[2] = minor_version;
-    event.xclient.data.l[3] = XCM_DATA_LIMIT;
-
-    XSendEvent (dpy,
-                new_client,
-                False,
-                NoEventMask,
-                &event);
-    XFlush (dpy);
-}
-
-static Bool Xi18nXBegin (XIMS ims)
-{
-    Xi18n i18n_core = ims->protocol;
-    Display *dpy = i18n_core->address.dpy;
-    XSpecRec *spec = (XSpecRec *) i18n_core->address.connect_addr;
-
-    spec->xim_request = XInternAtom (i18n_core->address.dpy,
-                                     _XIM_PROTOCOL,
-                                     False);
-    spec->connect_request = XInternAtom (i18n_core->address.dpy,
-                                         _XIM_XCONNECT,
-                                         False);
-
-    _XRegisterFilterByType (dpy,
-                            i18n_core->address.im_window,
-                            ClientMessage,
-                            ClientMessage,
-                            WaitXConnectMessage,
-                            (XPointer)ims);
-    return True;
-}
-
-static Bool Xi18nXEnd(XIMS ims)
-{
-    Xi18n i18n_core = ims->protocol;
-    Display *dpy = i18n_core->address.dpy;
-
-    _XUnregisterFilter (dpy,
-                        i18n_core->address.im_window,
-                        WaitXConnectMessage,
-                        (XPointer)ims);
-    return True;
-}
-
-static char *MakeNewAtom (CARD16 connect_id, char *atomName)
-{
-    static int sequence = 0;
-    
-    sprintf (atomName,
-             "_server%d_%d",
-             connect_id,
-             ((sequence > 20)  ?  (sequence = 0)  :  sequence++));
-    return atomName;
-}
-
-static Bool Xi18nXSend (XIMS ims,
-                        CARD16 connect_id,
-                        unsigned char *reply,
-                        long length)
-{
-    Xi18n i18n_core = ims->protocol;
-    Xi18nClient *client = _Xi18nFindClient (i18n_core, connect_id);
-    XSpecRec *spec = (XSpecRec *) i18n_core->address.connect_addr;
-    XClient *x_client = (XClient *) client->trans_rec;
-    XEvent event;
-
-    event.type = ClientMessage;
-    event.xclient.window = x_client->client_win;
-    event.xclient.message_type = spec->xim_request;
-
-    if (length > XCM_DATA_LIMIT)
-    {
-        Atom atom;
-        char atomName[16];
-        Atom actual_type_ret;
-        int actual_format_ret;
-        int return_code;
-        unsigned long nitems_ret;
-        unsigned long bytes_after_ret;
-        unsigned char *win_data;
-
-        event.xclient.format = 32;
-        atom = XInternAtom (i18n_core->address.dpy,
-                            MakeNewAtom (connect_id, atomName),
-                            False);
-        return_code = XGetWindowProperty (i18n_core->address.dpy,
-                                          x_client->client_win,
-                                          atom,
-                                          0L,
-                                          10000L,
-                                          False,
-                                          XA_STRING,
-                                          &actual_type_ret,
-                                          &actual_format_ret,
-                                          &nitems_ret,
-                                          &bytes_after_ret,
-                                          &win_data);
-        if (return_code != Success)
-            return False;
-        /*endif*/
-        if (win_data)
-            XFree ((char *) win_data);
-        /*endif*/
-        XChangeProperty (i18n_core->address.dpy,
-                         x_client->client_win,
-                         atom,
-                         XA_STRING,
-                         8,
-                         PropModeAppend,
-                         (unsigned char *) reply,
-                         length);
-        event.xclient.data.l[0] = length;
-        event.xclient.data.l[1] = atom;
-    }
-    else
-    {
-        unsigned char buffer[XCM_DATA_LIMIT];
-        int i;
-
-        event.xclient.format = 8;
-
-        /* Clear unused field with NULL */
-        memmove(buffer, reply, length);
-        for (i = length; i < XCM_DATA_LIMIT; i++)
-            buffer[i] = (char) 0;
-        /*endfor*/
-        length = XCM_DATA_LIMIT;
-        memmove (event.xclient.data.b, buffer, length);
-    }
-    XSendEvent (i18n_core->address.dpy,
-                x_client->client_win,
-                False,
-                NoEventMask,
-                &event);
-    XFlush (i18n_core->address.dpy);
-    return True;
-}
-
-static Bool CheckCMEvent (Display *display, XEvent *event, XPointer xi18n_core)
-{
-    Xi18n i18n_core = (Xi18n) ((void *) xi18n_core);
-    XSpecRec *spec = (XSpecRec *) i18n_core->address.connect_addr;
-
-    if ((event->type == ClientMessage)
-        &&
-        (event->xclient.message_type == spec->xim_request))
-    {
-        return  True;
-    }
-    /*endif*/
-    return  False;
-}
-
-static Bool Xi18nXWait (XIMS ims,
-                        CARD16 connect_id,
-                        CARD8 major_opcode,
-                        CARD8 minor_opcode)
-{
-    Xi18n i18n_core = ims->protocol;
-    XEvent event;
-    Xi18nClient *client = _Xi18nFindClient (i18n_core, connect_id);
-    XClient *x_client = (XClient *) client->trans_rec;
-
-    for (;;)
-    {
-        unsigned char *packet;
-        XimProtoHdr *hdr;
-        int connect_id_ret;
-
-        XIfEvent (i18n_core->address.dpy,
-                  &event,
-                  CheckCMEvent,
-                  (XPointer) i18n_core);
-        if (event.xclient.window == x_client->accept_win)
-        {
-            if ((packet = ReadXIMMessage (ims,
-                                          (XClientMessageEvent *) & event,
-                                          &connect_id_ret))
-                == (unsigned char*) NULL)
-            {
-                return False;
-            }
-            /*endif*/
-            hdr = (XimProtoHdr *)packet;
-
-            if ((hdr->major_opcode == major_opcode)
-                &&
-                (hdr->minor_opcode == minor_opcode))
-            {
-                return True;
-            }
-            else if (hdr->major_opcode == XIM_ERROR)
-            {
-                return False;
-            }
-            /*endif*/
-        }
-        /*endif*/
-    }
-    /*endfor*/
-}
-
-static Bool Xi18nXDisconnect (XIMS ims, CARD16 connect_id)
-{
-    Xi18n i18n_core = ims->protocol;
-    Display *dpy = i18n_core->address.dpy;
-    Xi18nClient *client = _Xi18nFindClient (i18n_core, connect_id);
-    XClient *x_client = (XClient *) client->trans_rec;
-
-    XDestroyWindow (dpy, x_client->accept_win);
-    _XUnregisterFilter (dpy,
-                       x_client->accept_win,
-                        WaitXIMProtocol,
-                       (XPointer)ims);
-    XFree (x_client);
-    _Xi18nDeleteClient (i18n_core, connect_id);
-    return True;
-}
-
-Bool _Xi18nCheckXAddress (Xi18n i18n_core,
-                          TransportSW *transSW,
-                          char *address)
-{
-    XSpecRec *spec;
-
-    if (!(spec = (XSpecRec *) malloc (sizeof (XSpecRec))))
-        return False;
-    /*endif*/
-    
-    i18n_core->address.connect_addr = (XSpecRec *) spec;
-    i18n_core->methods.begin = Xi18nXBegin;
-    i18n_core->methods.end = Xi18nXEnd;
-    i18n_core->methods.send = Xi18nXSend;
-    i18n_core->methods.wait = Xi18nXWait;
-    i18n_core->methods.disconnect = Xi18nXDisconnect;
-    return True;
-}
-
-static Bool WaitXConnectMessage (Display *dpy,
-                                 Window win,
-                                 XEvent *ev,
-                                 XPointer client_data)
-{
-    XIMS ims = (XIMS)client_data;
-    Xi18n i18n_core = ims->protocol;
-    XSpecRec *spec = (XSpecRec *) i18n_core->address.connect_addr;
-
-    if (((XClientMessageEvent *) ev)->message_type
-        == spec->connect_request)
-    {
-        ReadXConnectMessage (ims, (XClientMessageEvent *) ev);
-        return True;
-    }
-    /*endif*/
-    return False;
-}
-
-static Bool WaitXIMProtocol (Display *dpy,
-                             Window win,
-                             XEvent *ev,
-                             XPointer client_data)
-{
-    extern void _Xi18nMessageHandler (XIMS, CARD16, unsigned char *, Bool *);
-    XIMS ims = (XIMS) client_data;
-    Xi18n i18n_core = ims->protocol;
-    XSpecRec *spec = (XSpecRec *) i18n_core->address.connect_addr;
-    Bool delete = True;
-    unsigned char *packet;
-    int connect_id;
-
-    if (((XClientMessageEvent *) ev)->message_type
-        == spec->xim_request)
-    {
-        if ((packet = ReadXIMMessage (ims,
-                                      (XClientMessageEvent *) ev,
-                                      &connect_id))
-            == (unsigned char *)  NULL)
-        {
-            return False;
-        }
-        /*endif*/
-        _Xi18nMessageHandler (ims, connect_id, packet, &delete);
-        if (delete == True)
-            XFree (packet);
-        /*endif*/
-        return True;
-    }
-    /*endif*/
-    return False;
-}
diff --git a/x11/Makefile.am b/x11/Makefile.am
deleted file mode 100644 (file)
index 25517cb..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-# vim:set noet ts=4:
-#
-# ibus - The Input Bus
-#
-# Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this program; if not, write to the
-# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
-# Boston, MA  02111-1307  USA
-
-
-IMdkit = $(builddir)/IMdkit/libIMdkit.la
-libibus_gtk = $(top_builddir)/gtk2/libibus-gtk.la
-
-bin_PROGRAMS = ibus-x11
-
-ibus_x11_SOURCES = \
-       main.c \
-       gdk-private.c \
-       $(NULL)
-
-ibus_x11_DEPENDENCIES = \
-       $(IMdkit) \
-       $(libibus_gtk) \
-       $(NULL)
-
-ibus_x11_LDADD = \
-       @GTK2_LIBS@ \
-       $(IMdkit) \
-       $(libibus_gtk) \
-       $(NULL)
-
-ibus_x11_CFLAGS = \
-       @GTK2_CFLAGS@ \
-       -I$(srcdir)/IMdkit \
-       -I$(top_srcdir)/gtk2 \
-       $(NULL)
-
-noinst_HEADERS = \
-       gdk-private.h \
-       $(NULL)
-
-$(IMdkit):
-       (cd $(builddir)/IMdkit; make)
-
-$(libibus_gtk):
-       (cd $(top_builddir)/gtk2; make)
-
-SUBDIRS = IMdkit 
diff --git a/x11/gdk-private.c b/x11/gdk-private.c
deleted file mode 100644 (file)
index e3d5522..0000000
+++ /dev/null
@@ -1,116 +0,0 @@
-/* ibus
- * Copyright (C) 2008 Huang Peng <shawn.p.huang@gmail.com>
- *
- * gdk-private.c: Copied some code from gtk2
- *
- * This tool is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-#include <gtk/gtk.h>
-#include <gdk/gdkx.h>
-#include <gdk/gdkkeysyms.h>
-
-void
-translate_key_event (GdkDisplay *display,
-                    GdkEvent   *event,
-                    XEvent     *xevent)
-{
-  GdkKeymap *keymap = gdk_keymap_get_for_display (display);
-  gunichar c = 0;
-  gchar buf[7];
-
-  event->key.type = xevent->xany.type == KeyPress ? GDK_KEY_PRESS : GDK_KEY_RELEASE;
-  event->key.time = xevent->xkey.time;
-
-  event->key.state = (GdkModifierType) xevent->xkey.state;
-  //event->key.group = _gdk_x11_get_group_for_state (display, xevent->xkey.state);
-  event->key.group = 0;
-  event->key.hardware_keycode = xevent->xkey.keycode;
-
-  event->key.keyval = GDK_VoidSymbol;
-
-  gdk_keymap_translate_keyboard_state (keymap,
-                                      event->key.hardware_keycode,
-                                      event->key.state,
-                                      event->key.group,
-                                      &event->key.keyval,
-                                      NULL, NULL, NULL);
-
-  //_gdk_keymap_add_virtual_modifiers (keymap, &event->key.state);
-  event->key.is_modifier = 
-       (event->key.state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) != 0;
-//  event->key.is_modifier = _gdk_keymap_key_is_modifier (keymap, event->key.hardware_keycode);
-
-  /* Fill in event->string crudely, since various programs
-   * depend on it.
-   */
-  event->key.string = NULL;
-  
-  if (event->key.keyval != GDK_VoidSymbol)
-    c = gdk_keyval_to_unicode (event->key.keyval);
-
-  if (c)
-    {
-      gsize bytes_written;
-      gint len;
-
-      /* Apply the control key - Taken from Xlib
-       */
-      if (event->key.state & GDK_CONTROL_MASK)
-       {
-         if ((c >= '@' && c < '\177') || c == ' ') c &= 0x1F;
-         else if (c == '2')
-           {
-             event->key.string = g_memdup ("\0\0", 2);
-             event->key.length = 1;
-             buf[0] = '\0';
-             goto out;
-           }
-         else if (c >= '3' && c <= '7') c -= ('3' - '\033');
-         else if (c == '8') c = '\177';
-         else if (c == '/') c = '_' & 0x1F;
-       }
-      
-      len = g_unichar_to_utf8 (c, buf);
-      buf[len] = '\0';
-      
-      event->key.string = g_locale_from_utf8 (buf, len,
-                                             NULL, &bytes_written,
-                                             NULL);
-      if (event->key.string)
-       event->key.length = bytes_written;
-    }
-  else if (event->key.keyval == GDK_Escape)
-    {
-      event->key.length = 1;
-      event->key.string = g_strdup ("\033");
-    }
-  else if (event->key.keyval == GDK_Return ||
-         event->key.keyval == GDK_KP_Enter)
-    {
-      event->key.length = 1;
-      event->key.string = g_strdup ("\r");
-    }
-
-  if (!event->key.string)
-    {
-      event->key.length = 0;
-      event->key.string = g_strdup ("");
-    }
-  
- out:
-  return;
-}
-
diff --git a/x11/gdk-private.h b/x11/gdk-private.h
deleted file mode 100644 (file)
index bd918ab..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-/* ibus
- * Copyright (C) 2008 Huang Peng <shawn.p.huang@gmail.com>
- *
- * gdk-private.h:
- *
- * This tool is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-#ifndef __GTK_PRIVATE_H_
-#define __GTK_PRIVATE_H_
-
-void
-translate_key_event (GdkDisplay *display,
-                    GdkEvent   *event,
-                    XEvent     *xevent);
-#endif
diff --git a/x11/main.c b/x11/main.c
deleted file mode 100644 (file)
index cb361a2..0000000
+++ /dev/null
@@ -1,761 +0,0 @@
-/* vim:set et ts=4: */
-/* ibus
- * Copyright (C) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
- *
- * main.c:
- *
- * This tool is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-#include <X11/Xproto.h>
-#include <X11/Xlib.h>
-#include <X11/keysym.h>
-#include <X11/Xutil.h>
-#include <XimProto.h>
-#include <IMdkit.h>
-#include <Xi18n.h>
-#include <stdio.h>
-#include <gtk/gtk.h>
-#include <gdk/gdkx.h>
-#include <gdk/gdkkeysyms.h>
-#include <langinfo.h>
-#include <locale.h>
-#include <iconv.h>
-#include <signal.h>
-#include <stdlib.h>
-
-#define _GNU_SOURCES
-#include <getopt.h>
-
-#define LOG(level, fmt, args...) \
-    if (g_debug_level >= (level)) { \
-        g_debug (fmt, args); \
-    }
-
-#include <ibusimclient.h>
-#include "gdk-private.h"
-
-struct _X11ICONN {
-    GList        *clients;
-};
-typedef struct _X11ICONN    X11ICONN;
-
-struct _X11IC {
-    GtkIMContext *context;
-    GdkWindow     *client_window;
-    GdkWindow     *focus_window;
-    gint32        input_style;
-    X11ICONN    *conn;
-    gint        icid;
-    gint        connect_id;
-    gchar        *lang;
-    GdkRectangle    preedit_area;
-};
-typedef struct _X11IC    X11IC;
-
-
-
-static void _xim_commit_cb (GtkIMContext *context, gchar *arg, gpointer data);
-
-static GHashTable     *_clients = NULL;
-static GHashTable     *_connections = NULL;
-static XIMS _xims = NULL;
-static gchar _server_name[128] = "ibus";
-static gchar _locale[1024] =
-    "aa,af,am,an,ar,as,az,be,bg,bn,br,bs,"
-    "ca,cs,cy,da,de,dz,el,en,es,et,eu,"
-    "fa,fi,fo,fr,fy,ga,gd,gl,gu,gv,"
-    "he,hi,hr,hu,hy,id,is,it,iw,ja,"
-    "ka,kk,kl,km,kn,ko,ku,kw,ky,lg,lo,lt,lv,"
-    "mg,mi,mk,ml,mn,mr,ms,mt,nb,ne,nl,nn,no,nr,"
-    "oc,om,or,pa,pl,pt,ro,ru,rw,"
-    "se,si,sk,sl,so,sq,sr,ss,st,sv,"
-    "ta,te,tg,th,ti,tl,tn,tr,ts,tt,"
-    "uk,ur,uz,ve,vi,wa,xh,yi,zh,zu";
-
-static gboolean _kill_daemon = FALSE;
-static gint        g_debug_level = 0;
-
-IBusIMClient *_client = NULL;
-
-#if 0
-static void
-_xim_preedit_start (XIMS xims, int icid, int connect_id)
-{
-    IMPreeditStateStruct ips;
-    ips.major_code = 0;
-    ips.minor_code = 0;
-    ips.icid = icid;
-    ips.connect_id = connect_id;
-    IMPreeditStart (xims, (XPointer)&ips);
-}
-
-static void
-_xim_preedit_end (XIMS xims, int icid, int connect_id)
-{
-    IMPreeditStateStruct ips;
-    ips.major_code = 0;
-    ips.minor_code = 0;
-    ips.icid = icid;
-    ips.connect_id = connect_id;
-    IMPreeditEnd (xims, (XPointer)&ips);
-}
-#endif
-
-int
-_xim_store_ic_values (X11IC *ic, IMChangeICStruct *call_data)
-{
-    XICAttribute *ic_attr = call_data->ic_attr;
-    XICAttribute *pre_attr = call_data->preedit_attr;
-    XICAttribute *sts_attr = call_data->status_attr;
-
-    gint i;
-    guint32 attrs = 1;
-
-    if (ic == NULL) {
-        return 0;
-    }
-#define _is_attr(a, b)    (strcmp(a, b->name) == 0)
-    for (i=0; i< (int) call_data->ic_attr_num; ++i, ++ic_attr) {
-        if (_is_attr (XNInputStyle, ic_attr)) {
-            ic->input_style = *(gint32 *) ic_attr->value;
-        }
-        else if (_is_attr (XNClientWindow, ic_attr)) {
-            Window w;
-
-            if (ic->client_window != NULL) {
-                g_object_unref (ic->client_window);
-                ic->client_window = NULL;
-            }
-
-            w =  *(Window *) call_data->ic_attr[i].value;
-            if (w) {
-                ic->client_window = gdk_window_foreign_new (w);
-                if (ic->client_window)
-                    g_object_set_data (G_OBJECT (ic->client_window), "IBUS_IC", ic);
-            }
-        }
-        else if (_is_attr (XNFocusWindow, ic_attr)) {
-            Window w;
-
-            if (ic->focus_window != NULL) {
-                g_object_unref (ic->focus_window);
-                ic->focus_window = NULL;
-            }
-
-            w =  *(Window *) call_data->ic_attr[i].value;
-            if (w) {
-                ic->focus_window = gdk_window_foreign_new (w);
-                if (ic->focus_window)
-                    g_object_set_data (G_OBJECT (ic->focus_window), "IBUS_IC", ic);
-            }
-        }
-        else {
-            // fprintf (stderr, "Unknown attr: %s\n", ic_attr->name);
-        }
-    }
-
-    for (i=0; i< (int) call_data->preedit_attr_num; ++i, ++pre_attr) {
-        if (_is_attr (XNSpotLocation, pre_attr)) {
-            ic->preedit_area.x = ((XPoint *)pre_attr->value)->x;
-            ic->preedit_area.y = ((XPoint *)pre_attr->value)->y;
-        }
-        else {
-            // fprintf (stderr, "Unknown attr: %s\n", pre_attr->name);
-        }
-    }
-
-    for (i=0; i< (int) call_data->status_attr_num; ++i, ++sts_attr) {
-        // printf ("set status: %s\n", sts_attr->name);
-    }
-
-#undef _is_attr
-
-    return attrs;
-
-}
-
-
-static void
-_xim_commit_cb (GtkIMContext *context, gchar *arg, gpointer data)
-{
-    char *clist[1];
-    XTextProperty tp;
-    IMCommitStruct cms;
-
-    X11IC *ic = (X11IC *)data;
-
-    clist[0] = arg;
-    Xutf8TextListToTextProperty (GDK_DISPLAY (), clist, 1, XCompoundTextStyle, &tp);
-
-    memset (&cms, 0, sizeof (cms));
-    cms.major_code = XIM_COMMIT;
-    cms.icid = ic->icid;
-    cms.connect_id = ic->connect_id;
-    cms.flag = XimLookupChars;
-    cms.commit_string = (char *)tp.value;
-    IMCommitString (_xims, (XPointer) & cms);
-
-    XFree (tp.value);
-
-}
-
-int
-xim_create_ic (XIMS xims, IMChangeICStruct *call_data)
-{
-    static int base_icid = 1;
-    X11IC *ic;
-    int i;
-
-    LOG (1, "XIM_CREATE_IC ic=%d, connect_id=%d", call_data->icid, call_data->connect_id);
-
-    call_data->icid = base_icid ++;
-
-    ic = g_new0 (X11IC, 1);
-    ic->icid = call_data->icid;
-    ic->connect_id = call_data->connect_id;
-    ic->conn = (X11ICONN *)g_hash_table_lookup (_connections,
-                        (gconstpointer)(unsigned long)call_data->connect_id);
-
-    i = _xim_store_ic_values (ic, call_data);
-
-    ic->context = (GtkIMContext *)ibus_im_client_create_im_context (_client);
-
-    if (ic->focus_window)
-        gtk_im_context_set_client_window (ic->context, ic->focus_window);
-    else
-        gtk_im_context_set_client_window (ic->context, ic->client_window);
-
-    gtk_im_context_set_use_preedit (ic->context, FALSE);
-    g_signal_connect (ic->context,
-            "commit",
-            G_CALLBACK (_xim_commit_cb),
-            (gpointer)ic);
-#if 0
-    g_signal_connect (ic->context,
-            "preedit-changed",
-            G_CALLBACK (_xim_preedit_changed_cb),
-            (gpointer)ic);
-#endif
-
-    g_hash_table_insert (_clients, (gpointer)ic->icid, (gpointer) ic);
-    ic->conn->clients = g_list_append (ic->conn->clients, (gpointer) ic);
-
-    return 1;
-}
-
-
-int
-xim_destroy_ic (XIMS xims, IMChangeICStruct *call_data)
-{
-    X11IC *ic;
-
-    LOG (1, "XIM_DESTROY_IC ic=%d, connect_id=%d", call_data->icid, call_data->connect_id);
-
-    ic = (X11IC *)g_hash_table_lookup (_clients,
-                (gconstpointer)(unsigned long)call_data->icid);
-    g_object_unref (ic->context);
-    ic->conn->clients = g_list_remove (ic->conn->clients, (gconstpointer)ic);
-    g_hash_table_remove (_clients,
-                (gconstpointer)(unsigned long)call_data->icid);
-
-    if (ic->client_window)
-        g_object_unref (ic->client_window);
-    if (ic->focus_window)
-        g_object_unref (ic->focus_window);
-
-    g_free (ic);
-
-    return 1;
-}
-
-int
-xim_set_ic_focus (XIMS xims, IMChangeFocusStruct *call_data)
-{
-    X11IC *ic;
-
-    LOG (1, "XIM_SET_IC_FOCUS ic=%d, connect_id=%d", call_data->icid, call_data->connect_id);
-
-    ic = (X11IC *)g_hash_table_lookup (_clients,
-                (gconstpointer)(unsigned long)call_data->icid);
-
-    gtk_im_context_focus_in (ic->context);
-
-    return 1;
-
-}
-
-int
-xim_unset_ic_focus (XIMS xims, IMChangeFocusStruct *call_data)
-{
-    X11IC *ic;
-
-    LOG (1, "XIM_UNSET_IC_FOCUS ic=%d, connect_id=%d", call_data->icid, call_data->connect_id);
-
-    ic = (X11IC *)g_hash_table_lookup (_clients,
-            (gconstpointer)(unsigned long)call_data->icid);
-
-    gtk_im_context_focus_out (ic->context);
-
-    return 1;
-
-}
-
-int
-xim_forward_event (XIMS xims, IMForwardEventStruct *call_data)
-{
-
-    X11IC *ic;
-    XKeyEvent *xevent;
-    GdkEventKey event;
-    GdkWindow *window;
-
-    LOG (1, "XIM_FORWARD_EVENT ic=%d, connect_id=%d", call_data->icid, call_data->connect_id);
-    ic = (X11IC *)g_hash_table_lookup (_clients,
-                (gconstpointer)(unsigned long)call_data->icid);
-
-    g_return_val_if_fail (ic != NULL, 1);
-
-    xevent = (XKeyEvent*) &(call_data->event);
-    window = gdk_window_foreign_new (xevent->window);
-
-    translate_key_event (gdk_drawable_get_display (window),
-        (GdkEvent *)&event, (XEvent *)xevent);
-
-    event.send_event = xevent->send_event;
-    event.window = window;
-
-    g_debug ("send_event = %d", event.send_event);
-
-    if (gtk_im_context_filter_keypress (ic->context, &event)) {
-        g_object_unref (window);
-        return 1;
-    }
-    g_object_unref (window);
-
-    IMForwardEventStruct fe;
-    memset (&fe, 0, sizeof (fe));
-
-    fe.major_code = XIM_FORWARD_EVENT;
-    fe.icid = ic->icid;
-    fe.connect_id = ic->connect_id;
-    fe.sync_bit = 0;
-    fe.serial_number = 0L;
-    fe.event = call_data->event;
-
-    IMForwardEvent (_xims, (XPointer) & fe);
-
-    return 1;
-}
-
-
-int
-xim_open (XIMS xims, IMOpenStruct *call_data)
-{
-    X11ICONN *conn;
-
-    LOG (1, "XIM_OPEN connect_id=%d", call_data->connect_id);
-
-    conn = (X11ICONN *)g_hash_table_lookup (_connections,
-                (gconstpointer)(unsigned long)call_data->connect_id);
-
-    g_return_val_if_fail (conn == NULL, 1);
-
-    conn = g_new0(X11ICONN, 1);
-
-    g_hash_table_insert (_connections,
-        (gpointer)(unsigned long)call_data->connect_id,
-        (gpointer) conn);
-
-    return 1;
-}
-
-static void
-_free_ic (gpointer data, gpointer user_data)
-{
-    X11IC *ic = (X11IC *) data;
-
-    g_return_if_fail (ic != NULL);
-
-    g_object_unref (ic->context);
-
-    /* Remove the IC from g_client dictionary */
-    g_hash_table_remove (_clients,
-                (gconstpointer)(unsigned long)ic->icid);
-
-    g_free (ic);
-}
-
-int
-xim_close (XIMS ims, IMCloseStruct *call_data)
-{
-    X11ICONN *conn;
-
-    LOG (1, "XIM_CLOSE connect_id=%d", call_data->connect_id);
-
-    conn = (X11ICONN *)g_hash_table_lookup (_connections,
-                (gconstpointer)(unsigned long)call_data->connect_id);
-
-    g_return_val_if_fail (conn != NULL, 1);
-
-    g_list_foreach (conn->clients, _free_ic, NULL);
-
-    g_list_free (conn->clients);
-
-    // g_object_unref (conn->context);
-
-    g_hash_table_remove (_connections, (gconstpointer)(unsigned long)call_data->connect_id);
-
-    g_free (conn);
-
-    return 1;
-}
-
-
-
-int
-xim_set_ic_values (XIMS xims, IMChangeICStruct *call_data)
-{
-    X11IC *ic;
-    gint i;
-
-    LOG (1, "XIM_SET_IC_VALUES ic=%d connect_id=%d", call_data->icid, call_data->connect_id);
-
-    ic = (X11IC *)g_hash_table_lookup (_clients,
-                (gconstpointer)(unsigned long)call_data->icid);
-
-    g_return_val_if_fail (ic != NULL, 1);
-
-    i = _xim_store_ic_values (ic, call_data);
-
-    if (i) {
-        gtk_im_context_set_cursor_location (ic->context, &ic->preedit_area);
-    }
-
-    return i;
-}
-
-
-int
-xim_reset_ic (XIMS xims, IMResetICStruct *call_data)
-{
-    X11IC *ic;
-
-    LOG (1, "XIM_RESET_IC ic=%d connect_id=%d", call_data->icid, call_data->connect_id);
-
-    ic = (X11IC *)g_hash_table_lookup (_clients,
-                (gconstpointer)(unsigned long)call_data->icid);
-
-    g_return_val_if_fail (ic != NULL, 1);
-
-    gtk_im_context_reset (ic->context);
-
-    return 1;
-}
-
-int
-ims_protocol_handler (XIMS xims, IMProtocol *call_data)
-{
-    g_return_val_if_fail (xims != NULL, 1);
-    g_return_val_if_fail (call_data != NULL, 1);
-
-    switch (call_data->major_code) {
-    case XIM_OPEN:
-        return xim_open (xims, (IMOpenStruct *)call_data);
-    case XIM_CLOSE:
-        return xim_close (xims, (IMCloseStruct *)call_data);
-    case XIM_CREATE_IC:
-        return xim_create_ic (xims, (IMChangeICStruct *)call_data);
-    case XIM_DESTROY_IC:
-        return xim_destroy_ic (xims, (IMChangeICStruct *)call_data);
-    case XIM_SET_IC_VALUES:
-        return xim_set_ic_values (xims, (IMChangeICStruct *)call_data);
-    case XIM_GET_IC_VALUES:
-        return 1;
-    case XIM_FORWARD_EVENT:
-        return xim_forward_event (xims, (IMForwardEventStruct *)call_data);
-    case XIM_SET_IC_FOCUS:
-        return xim_set_ic_focus (xims, (IMChangeFocusStruct *)call_data);
-    case XIM_UNSET_IC_FOCUS:
-        return xim_unset_ic_focus (xims, (IMChangeFocusStruct *)call_data);
-    case XIM_RESET_IC:
-        return xim_reset_ic (xims, (IMResetICStruct *)call_data);
-    case XIM_TRIGGER_NOTIFY:
-    case XIM_PREEDIT_START_REPLY:
-    case XIM_PREEDIT_CARET_REPLY:
-    case XIM_SYNC_REPLY:
-        return 1;
-    default:
-        break;
-    }
-    return 1;
-}
-
-
-static void
-_xim_forward_gdk_event (GdkEventKey *event)
-{
-    X11IC *ic;
-    ic = (X11IC *)g_object_get_data (G_OBJECT (event->window), "IBUS_IC");
-    if (ic == NULL)
-        return;
-    IMForwardEventStruct fe;
-    XEvent xkp;
-    memset (&xkp, 0, sizeof (xkp));
-    memset (&fe, 0, sizeof (fe));
-
-    xkp.xkey.type = (event->type == GDK_KEY_PRESS) ? KeyPress : KeyRelease;
-    xkp.xkey.serial = 0L;
-    xkp.xkey.send_event = False;
-    xkp.xkey.same_screen = False;
-    xkp.xkey.display = GDK_WINDOW_XDISPLAY (event->window);
-    xkp.xkey.window = GDK_WINDOW_XWINDOW (event->window);
-    xkp.xkey.subwindow = None;
-    xkp.xkey.root = DefaultRootWindow (GDK_WINDOW_XDISPLAY (event->window));
-    xkp.xkey.time = event->time;
-    xkp.xkey.state = event->state;
-    xkp.xkey.keycode = event->hardware_keycode;
-
-    fe.major_code = XIM_FORWARD_EVENT;
-    fe.icid = ic->icid;
-    fe.connect_id = ic->connect_id;
-    fe.sync_bit = 0;
-    fe.serial_number = 0L;
-    fe.event = xkp;
-    IMForwardEvent (_xims, (XPointer) & fe);
-
-}
-
-static void
-_xim_event_cb (GdkEvent *event, gpointer data)
-{
-    g_debug ("xim event");
-    switch (event->type) {
-    case GDK_KEY_PRESS:
-    case GDK_KEY_RELEASE:
-        _xim_forward_gdk_event ((GdkEventKey *)event);
-        break;
-    default:
-        gtk_main_do_event (event);
-        break;
-    }
-}
-
-static void
-_xim_event_destroy_cb (gpointer data)
-{
-}
-
-static void
-_xim_client_disconnected_cb (IBusIMClient *client, gpointer data)
-{
-    gtk_main_quit ();
-}
-
-static void
-_xim_init_IMdkit ()
-{
-#if 0
-    XIMStyle ims_styles_overspot [] = {
-        XIMPreeditPosition  | XIMStatusNothing,
-        XIMPreeditNothing   | XIMStatusNothing,
-        XIMPreeditPosition  | XIMStatusCallbacks,
-        XIMPreeditNothing   | XIMStatusCallbacks,
-        0
-    };
-#endif
-
-    XIMStyle ims_styles_onspot [] = {
-        XIMPreeditPosition  | XIMStatusNothing,
-        XIMPreeditCallbacks | XIMStatusNothing,
-        XIMPreeditNothing   | XIMStatusNothing,
-        XIMPreeditPosition  | XIMStatusCallbacks,
-        XIMPreeditCallbacks | XIMStatusCallbacks,
-        XIMPreeditNothing   | XIMStatusCallbacks,
-        0
-    };
-
-    XIMEncoding ims_encodings[] = {
-        "COMPOUND_TEXT",
-        0
-    };
-
-    GdkWindowAttr window_attr = {
-        title :     "ibus-xim",
-        event_mask :     GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
-        wclass:        GDK_INPUT_OUTPUT,
-        window_type:    GDK_WINDOW_TOPLEVEL,
-        override_redirect: 1,
-    };
-
-    XIMStyles styles;
-    XIMEncodings encodings;
-
-    GdkWindow *win;
-
-    win = gdk_window_new (NULL, &window_attr, GDK_WA_TITLE);
-
-    styles.count_styles =
-        sizeof (ims_styles_onspot)/sizeof (XIMStyle) - 1;
-    styles.supported_styles = ims_styles_onspot;
-
-    encodings.count_encodings =
-        sizeof (ims_encodings)/sizeof (XIMEncoding) - 1;
-    encodings.supported_encodings = ims_encodings;
-
-    _xims = IMOpenIM(GDK_DISPLAY(),
-        IMModifiers, "Xi18n",
-        IMServerWindow, GDK_WINDOW_XWINDOW(win),
-        IMServerName, _server_name,
-        IMLocale, _locale,
-        IMServerTransport, "X/",
-        IMInputStyles, &styles,
-        IMEncodingList, &encodings,
-        IMProtocolHandler, ims_protocol_handler,
-        IMFilterEventMask, KeyPressMask | KeyReleaseMask,
-        NULL);
-
-    gdk_event_handler_set (_xim_event_cb, NULL,
-        _xim_event_destroy_cb);
-
-    ibus_im_client_register_type (NULL);
-    ibus_im_context_register_type (NULL);
-    _client = ibus_im_client_new ();
-
-    if (!ibus_im_client_get_connected (_client)) {
-        g_warning ("Can not connect to ibus daemon");
-        exit (1);
-    }
-
-    g_signal_connect (G_OBJECT (_client),
-        "disconnected",
-        G_CALLBACK (_xim_client_disconnected_cb),
-        NULL);
-
-}
-
-static void
-_xim_kill_daemon ()
-{
-    ibus_im_client_kill_daemon(_client);
-}
-
-static void
-_xim_sighandler (int sig)
-{
-    exit(EXIT_FAILURE);
-}
-
-static void
-print_usage (FILE *fp, gchar *name)
-{
-    fprintf (fp,
-        "Usage:\n"
-        " %s --help               Show this message\n"
-        "    --server-name= -n    Setup xim sevrer name\n"
-        "    --locale= -l         Setup support locale\n"
-        "    --kill-daemon -k     Kill ibus daemon when exit\n"
-        "    --debug= -v          Setup debug level\n",
-        name);
-}
-
-int error_handler (Display *dpy, XErrorEvent *e)
-{
-    g_debug (
-        "XError: "
-        "serial=%d error_code=%d request_code=%d minor_code=%d resourceid=%d",
-        e->serial, e->error_code, e->request_code, e->minor_code, e->resourceid);
-    return 1;
-}
-
-int main (int argc, char **argv)
-{
-    gint option_index = 0;
-    gint c;
-
-
-    gtk_init (&argc, &argv);
-    XSetErrorHandler (error_handler);
-
-    while (1) {
-        static struct option long_options [] = {
-            {"debug", 1, 0, 0},
-            {"server-name", 1, 0, 0},
-            {"locale", 1, 0, 0},
-            {"help", 0, 0, 0},
-            {"kill-daemon", 0, 0, 0},
-            {0, 0, 0, 0},
-        };
-
-        c = getopt_long (argc, argv, "v:n:l:k",
-            long_options, &option_index);
-
-        if (c == -1) break;
-
-        switch (c) {
-        case 0:
-            if (strcmp (long_options[option_index].name, "debug") == 0) {
-                g_debug_level = atoi (optarg);
-            }
-            else if (strcmp (long_options[option_index].name, "server-name") == 0) {
-                strncpy (_server_name, optarg, sizeof (_server_name));
-            }
-            else if (strcmp (long_options[option_index].name, "locale") == 0) {
-                strncpy (_locale, optarg, sizeof (_locale));
-            }
-            else if (strcmp (long_options[option_index].name, "help") == 0) {
-                print_usage (stdout, argv[0]);
-                exit (EXIT_SUCCESS);
-            }
-            else if (strcmp (long_options[option_index].name, "kill-daemon") == 0) {
-                _kill_daemon = TRUE;
-            }
-            break;
-        case 'v':
-            g_debug_level = atoi (optarg);
-            break;
-        case 'n':
-            strncpy (_server_name, optarg, sizeof (_server_name));
-            break;
-        case 'l':
-            strncpy (_locale, optarg, sizeof (_locale));
-            break;
-        case 'k':
-            _kill_daemon = TRUE;
-            break;
-        case '?':
-        default:
-            print_usage (stderr, argv[0]);
-            exit (EXIT_FAILURE);
-        }
-    }
-
-    _clients = g_hash_table_new (g_direct_hash, g_direct_equal);
-    _connections = g_hash_table_new (g_direct_hash, g_direct_equal);
-
-    signal (SIGINT, _xim_sighandler);
-    signal (SIGTERM, _xim_sighandler);
-
-    if (_kill_daemon)
-        g_atexit (_xim_kill_daemon);
-
-    _xim_init_IMdkit ();
-    gtk_main();
-
-    exit (EXIT_SUCCESS);
-}
-
-
-