Author: ekato
Date: Wed Dec  8 06:11:53 2004
New Revision: 14

Added:
   trunk/xim/helper.cpp
   trunk/xim/helper.h
   trunk/xim/util.cpp
   trunk/xim/util.h
Modified:
   trunk/configure.ac
   trunk/xim/Makefile.am
   trunk/xim/canddisp.cpp
   trunk/xim/connection.h
   trunk/xim/convdisp.cpp
   trunk/xim/locale.cpp
   trunk/xim/main.cpp
   trunk/xim/ximic.cpp
   trunk/xim/ximim.cpp
   trunk/xim/ximpacket.cpp
   trunk/xim/ximserver.cpp
   trunk/xim/ximserver.h
   trunk/xim/ximtrans.cpp

Log:
* configure.ac : Check for asprintf() and vasprintf(), by Konosuke
  Watanabe.

* xim/Makefile.am : Add util.{h,cpp}, helper.{h,cpp} as
  uim_xim_SOURCES.
* xim/util.h : New file.  Move fd dispatch prototypes and misc
  functions from main.c.  Add asprintf() and vasprintf() for
  system which lacks these function.
* xim/util.cpp : Ditto.
* xim/helper.h : New file.  Move check_helper_connection()
  prototype from ximserver.h.
* xim/helper.cpp : Move uim-helper related functions from from
  main.c.
* xim/connection.h : Move connection_setup() prototype from
  main.c.
* xim/main.cpp : Use proper header files.  Move fd dispatch
  definition into util.{h,cpp}.  Move helper related function into
  helper.cpp.
* xim/locale.cpp : Use proper header file.
* xim/ximtrans.cpp : Ditto.
* xim/ximic.cpp : Ditto.
* xim/ximim.cpp : Ditto.
* xim/ximserver.cpp : Ditto.
* xim/convdisp.cpp : Ditto.
* xim/ximpacket.cpp : Ditto.
* xim/canddisp.cpp : Ditto.
* xim/ximserver.h : Ditto.


Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac  (original)
+++ trunk/configure.ac  Wed Dec  8 06:11:53 2004
@@ -105,6 +105,8 @@
 AC_CHECK_FUNCS([forkpty])
 AC_CHECK_FUNCS([cfmakeraw])
 AC_CHECK_FUNCS([wcswidth])
+AC_CHECK_FUNCS(getpeereid)
+AC_CHECK_FUNCS(asprintf vasprintf)
 
 
 GETTEXT_PACKAGE=uim
@@ -288,8 +290,6 @@
 AC_FUNC_REALLOC
 AC_FUNC_SELECT_ARGTYPES
 AC_TYPE_SIGNAL
-
-AC_CHECK_FUNCS(getpeereid)
 
 SRCDIR=$srcdir
 AC_SUBST(SRCDIR)

Modified: trunk/xim/Makefile.am
==============================================================================
--- trunk/xim/Makefile.am       (original)
+++ trunk/xim/Makefile.am       Wed Dec  8 06:11:53 2004
@@ -13,4 +13,6 @@
         locale.cpp connection.h \
        convdisp.h ximserver.h \
        xim.h xdispatch.h ximpn.h \
-       canddisp.cpp canddisp.h
+       canddisp.cpp canddisp.h \
+       util.cpp util.h \
+       helper.cpp helper.h

Modified: trunk/xim/canddisp.cpp
==============================================================================
--- trunk/xim/canddisp.cpp      (original)
+++ trunk/xim/canddisp.cpp      Wed Dec  8 06:11:53 2004
@@ -30,25 +30,29 @@
   SUCH DAMAGE.
 */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <unistd.h>
+
 #include "uim/uim.h"
-#include "uim/uim-helper.h"
 
 #include "ximserver.h"
 #include "xim.h"
 #include "convdisp.h"
 #include "canddisp.h"
-#include <unistd.h>
+#include "util.h"
+
 
 static FILE *candwin_r = NULL, *candwin_w = NULL;
 static int candwin_pid = 0;
 static Canddisp *disp;
 static char *command;
 
-// fd dispatch
-#define READ_OK 1
-extern void add_fd_watch(int fd, int mask, void (*fn)(int, int));
-extern void remove_current_fd_watch(int fd);
 static void candwin_read_cb(int fd, int ev);
 
 static char *candwin_command(void)

Modified: trunk/xim/connection.h
==============================================================================
--- trunk/xim/connection.h      (original)
+++ trunk/xim/connection.h      Wed Dec  8 06:11:53 2004
@@ -36,6 +36,8 @@
 #include "xim.h"
 #include "xdispatch.h"
 
+int connection_setup();
+
 class XConnection: public Connection, public WindowIf {
 public:
     XConnection(XimServer *svr, Window clientWin, Window commWin);

Modified: trunk/xim/convdisp.cpp
==============================================================================
--- trunk/xim/convdisp.cpp      (original)
+++ trunk/xim/convdisp.cpp      Wed Dec  8 06:11:53 2004
@@ -42,6 +42,7 @@
 #include "convdisp.h"
 #include "canddisp.h"
 #include "xdispatch.h"
+#include "util.h"
 
 #define UNDERLINE_HEIGHT       2
 // Temporal hack for flashplayer plugin's broken over-the-spot XIM style

Added: trunk/xim/helper.cpp
==============================================================================
--- (empty file)
+++ trunk/xim/helper.cpp        Wed Dec  8 06:11:53 2004
@@ -0,0 +1,233 @@
+/*
+
+  Copyright (c) 2003,2004 uim Project http://uim.freedesktop.org/
+
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions
+  are met:
+
+  1. Redistributions of source code must retain the above copyright
+     notice, this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright
+     notice, this list of conditions and the following disclaimer in the
+     documentation and/or other materials provided with the distribution.
+  3. Neither the name of authors nor the names of its contributors
+     may be used to endorse or promote products derived from this software
+     without specific prior written permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+  SUCH DAMAGE.
+*/
+
+// uim-helper connection
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+#include "xim.h"
+#include "ximserver.h"
+#include "canddisp.h"
+#include "util.h"
+
+#include "uim/uim-util.h"
+#include "uim/uim-helper.h"
+#include "uim/uim-im-switcher.h"
+
+int lib_uim_fd = -1;
+
+static void
+parse_helper_str_im_change(const char *level, const char *engine) {
+    InputContext *focusedContext = InputContext::focusedContext();
+
+    if (!strcmp(level, "im_change_whole_desktop")) {
+       std::map<Window, XimServer *>::iterator it;
+       for (it = XimServer::gServerMap.begin(); it != 
XimServer::gServerMap.end(); it++) {
+           (*it).second->changeContext(engine);
+       }
+    }
+
+    if (focusedContext) {
+       if (!strcmp(level, "im_change_this_text_area_only"))
+           focusedContext->changeContext(engine);
+       else if (!strcmp(level, "im_change_this_application_only"))
+           
get_im_by_id(focusedContext->get_ic()->get_imid())->changeContext(engine);
+    }
+}
+
+static void
+send_im_list(void)
+{
+    char *buf = NULL, *tmp = NULL;
+    int len;
+    InputContext *focusedContext = InputContext::focusedContext();
+    const char *current_im_name =
+           uim_get_current_im_name(focusedContext->getUC());
+    const char *encoding = focusedContext->get_ic()->get_encoding();
+    const char *client_locale = NULL;
+    
+    if (strcmp(encoding, "UTF-8"))
+       client_locale = focusedContext->get_ic()->get_lang_region();
+
+    asprintf(&buf, "im_list\ncharset=UTF-8\n");
+    if (!buf)
+       return;
+
+    std::list<UIMInfo>::iterator it;
+    for (it = uim_info.begin(); it != uim_info.end(); it++) {
+       if (client_locale) { // context with legacy encodings
+           const char *engine_locales =
+                   compose_localenames_from_im_lang(it->lang);
+           if (!is_locale_included(engine_locales, client_locale))
+               continue;
+       }
+
+       const char *language;
+       language = uim_get_language_name_from_locale(it->lang);
+       asprintf(&tmp, "%s\t%s\t%s\t", it->name,
+                                      language ? language : "",
+                                      it->desc ? it->desc : "");
+       if (!tmp)
+           return;
+       len = strlen(buf) + strlen(tmp);
+       buf = (char *)realloc(buf, sizeof(char) * len + 1);
+       if (!buf)
+           return;
+       strcat(buf, tmp);
+       free(tmp);
+
+       if (!strcmp(it->name, current_im_name)) {
+           asprintf(&tmp, "selected\n");
+           if (!tmp)
+               return;
+           len = strlen(buf) + strlen(tmp);
+           buf = (char *)realloc(buf, sizeof(char) * len + 1);
+           if (!buf)
+               return;
+           strcat(buf, tmp);
+           free(tmp);
+       } else {
+           asprintf(&tmp, "\n");
+           if (!tmp)
+               return;
+           len = strlen(buf) + strlen(tmp);
+           buf = (char *)realloc(buf, sizeof(char) * len + 1);
+           if (!buf)
+               return;
+           strcat(buf, tmp);
+           free(tmp);
+       }
+    }
+    uim_helper_send_message(lib_uim_fd, buf);
+    free(buf);
+}
+
+static void
+helper_str_parse(char *str)
+{
+    InputContext *focusedContext = InputContext::focusedContext();
+    
+    if (focusedContext) {
+       char *line = str;       
+       char *eol = strchr(line, '\n');
+       if (eol != NULL)
+           *eol = '\0';
+
+       if (strcmp("prop_list_get", line) == 0) {
+           uim_prop_list_update(focusedContext->getUC());
+       } else if (strcmp("prop_label_get", line) == 0) {
+           uim_prop_label_update(focusedContext->getUC());
+       } else if (strcmp("prop_activate", line) == 0) {
+           line = eol + 1;
+           eol = strchr(line, '\n');
+           if (eol != NULL) {
+               *eol = '\0';
+           }
+           uim_prop_activate(focusedContext->getUC(), line);
+       } else if (strncmp("focus_in", line, 8) == 0) {
+           InputContext::deletefocusedContext();
+           Canddisp *disp = canddisp_singleton();
+           disp->hide();
+       } else if (strcmp("im_list_get", line) == 0) {
+           send_im_list();
+       } else if (strncmp("im_change_", line, 10) == 0) {
+           char *engine;
+           engine = eol + 1;
+           eol = strchr(engine, '\n');
+           if (eol != NULL) {
+               *eol = '\0';
+           }
+           parse_helper_str_im_change(line, engine);
+       }
+    } else {
+       char *line = str;       
+       char *eol = strchr(line, '\n');
+       if (eol != NULL) {
+           *eol = '\0';
+       }
+
+       if (strncmp("im_change_", line, 10) == 0) {
+           char *engine;
+           engine = eol + 1;
+           eol = strchr(engine, '\n');
+           if (eol != NULL) {
+               *eol = '\0';
+           }
+           parse_helper_str_im_change(line, engine);
+       } else if (strcmp("prop_update_custom", line) == 0) {
+           fprintf(stderr, "prop_update_custom is not implemented yet\n");
+       }
+    }
+}
+
+static void
+helper_read_cb(int fd, int ev)
+{
+    uim_helper_read_proc(fd);
+    char *tmp;
+    while ((tmp = uim_helper_get_message())) {
+       helper_str_parse(tmp);
+       free(tmp);
+    }
+}
+
+static void
+helper_disconnect_cb(void)
+{
+    remove_current_fd_watch(lib_uim_fd);
+    lib_uim_fd = -1;
+}
+
+void
+check_helper_connection(void)
+{
+    if (lib_uim_fd < 0) {
+       lib_uim_fd = uim_helper_init_client_fd(helper_disconnect_cb);
+       if (lib_uim_fd >= 0)
+           add_fd_watch(lib_uim_fd, READ_OK, helper_read_cb);
+    }
+}
+
+/*
+ * Local variables:
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ * End:
+ */

Added: trunk/xim/helper.h
==============================================================================
--- (empty file)
+++ trunk/xim/helper.h  Wed Dec  8 06:11:53 2004
@@ -0,0 +1,45 @@
+/*
+
+  Copyright (c) 2003,2004 uim Project http://uim.freedesktop.org/
+
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions
+  are met:
+
+  1. Redistributions of source code must retain the above copyright
+     notice, this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright
+     notice, this list of conditions and the following disclaimer in the
+     documentation and/or other materials provided with the distribution.
+  3. Neither the name of authors nor the names of its contributors
+     may be used to endorse or promote products derived from this software
+     without specific prior written permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+  SUCH DAMAGE.
+*/
+
+// -*- C++ -*-
+#ifndef _helper_included_
+#define _helper_h_included_
+
+void check_helper_connection();
+
+#endif
+/*
+ * Local variables:
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ * End:
+ */

Modified: trunk/xim/locale.cpp
==============================================================================
--- trunk/xim/locale.cpp        (original)
+++ trunk/xim/locale.cpp        Wed Dec  8 06:11:53 2004
@@ -42,6 +42,7 @@
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 #include "ximserver.h"
+#include "util.h"
 #ifndef __GNUC__
 # ifdef HAVE_ALLOCA_H
 #  include <alloca.h>

Modified: trunk/xim/main.cpp
==============================================================================
--- trunk/xim/main.cpp  (original)
+++ trunk/xim/main.cpp  Wed Dec  8 06:11:53 2004
@@ -40,16 +40,18 @@
 #include <stdio.h>
 #include <string.h>
 #include <locale.h>
-#include <ctype.h>
 #include <stdlib.h>
-#include <pwd.h>
-#include <unistd.h>
 #include <signal.h>
-#include <sys/types.h>
+#include <sys/select.h>
+
 #include "xim.h"
 #include "xdispatch.h"
 #include "ximserver.h"
 #include "canddisp.h"
+#include "connection.h"
+#include "util.h"
+#include "helper.h"
+
 #include "uim/uim-util.h"
 #include "uim/uim-im-switcher.h"
 
@@ -61,8 +63,6 @@
 int scr_width, scr_height;
 int host_byte_order;
 
-int lib_uim_fd = -1;
-
 #define VERSION_NAME "uim-xim under the way! Version "PACKAGE_VERSION"\n"
 const char *version_name=VERSION_NAME;
 const char *usage=
@@ -80,10 +80,6 @@
 static Atom atom_transport;
 Atom xim_servers;
 
-// fd dispatch
-#define READ_OK 1
-#define WRITE_OK 2
-
 struct fd_watch_struct {
     int mask;
     void (*fn)(int, int);
@@ -464,178 +460,6 @@
        host_byte_order = MSB_FIRST;
 }
 
-static void
-parse_helper_str_im_change(const char *level, const char *engine) {
-    InputContext *focusedContext = InputContext::focusedContext();
-
-    if (!strcmp(level, "im_change_whole_desktop")) {
-       std::map<Window, XimServer *>::iterator it;
-       for (it = XimServer::gServerMap.begin(); it != 
XimServer::gServerMap.end(); it++) {
-           (*it).second->changeContext(engine);
-       }
-    }
-
-    if (focusedContext) {
-       if (!strcmp(level, "im_change_this_text_area_only"))
-           focusedContext->changeContext(engine);
-       else if (!strcmp(level, "im_change_this_application_only"))
-           
get_im_by_id(focusedContext->get_ic()->get_imid())->changeContext(engine);
-    }
-}
-
-static void
-send_im_list(void)
-{
-    char *buf = NULL, *tmp = NULL;
-    int len;
-    InputContext *focusedContext = InputContext::focusedContext();
-    const char *current_im_name =
-           uim_get_current_im_name(focusedContext->getUC());
-    const char *encoding = focusedContext->get_ic()->get_encoding();
-    const char *client_locale = NULL;
-    
-    if (strcmp(encoding, "UTF-8"))
-       client_locale = focusedContext->get_ic()->get_lang_region();
-
-    asprintf(&buf, "im_list\ncharset=UTF-8\n");
-    if (!buf)
-       return;
-
-    std::list<UIMInfo>::iterator it;
-    for (it = uim_info.begin(); it != uim_info.end(); it++) {
-       if (client_locale) { // context with legacy encodings
-           const char *engine_locales =
-                   compose_localenames_from_im_lang(it->lang);
-           if (!is_locale_included(engine_locales, client_locale))
-               continue;
-       }
-
-       const char *language;
-       language = uim_get_language_name_from_locale(it->lang);
-       asprintf(&tmp, "%s\t%s\t%s\t", it->name,
-                                      language ? language : "",
-                                      it->desc ? it->desc : "");
-       if (!tmp)
-           return;
-       len = strlen(buf) + strlen(tmp);
-       buf = (char *)realloc(buf, sizeof(char) * len + 1);
-       if (!buf)
-           return;
-       strcat(buf, tmp);
-       free(tmp);
-
-       if (!strcmp(it->name, current_im_name)) {
-           asprintf(&tmp, "selected\n");
-           if (!tmp)
-               return;
-           len = strlen(buf) + strlen(tmp);
-           buf = (char *)realloc(buf, sizeof(char) * len + 1);
-           if (!buf)
-               return;
-           strcat(buf, tmp);
-           free(tmp);
-       } else {
-           asprintf(&tmp, "\n");
-           if (!tmp)
-               return;
-           len = strlen(buf) + strlen(tmp);
-           buf = (char *)realloc(buf, sizeof(char) * len + 1);
-           if (!buf)
-               return;
-           strcat(buf, tmp);
-           free(tmp);
-       }
-    }
-    uim_helper_send_message(lib_uim_fd, buf);
-    free(buf);
-}
-
-static void
-helper_str_parse(char *str)
-{
-    InputContext *focusedContext = InputContext::focusedContext();
-    
-    if (focusedContext) {
-       char *line = str;       
-       char *eol = strchr(line, '\n');
-       if (eol != NULL)
-           *eol = '\0';
-
-       if (strcmp("prop_list_get", line) == 0) {
-           uim_prop_list_update(focusedContext->getUC());
-       } else if (strcmp("prop_label_get", line) == 0) {
-           uim_prop_label_update(focusedContext->getUC());
-       } else if (strcmp("prop_activate", line) == 0) {
-           line = eol + 1;
-           eol = strchr(line, '\n');
-           if (eol != NULL) {
-               *eol = '\0';
-           }
-           uim_prop_activate(focusedContext->getUC(), line);
-       } else if (strncmp("focus_in", line, 8) == 0) {
-           InputContext::deletefocusedContext();
-           Canddisp *disp = canddisp_singleton();
-           disp->hide();
-       } else if (strcmp("im_list_get", line) == 0) {
-           send_im_list();
-       } else if (strncmp("im_change_", line, 10) == 0) {
-           char *engine;
-           engine = eol + 1;
-           eol = strchr(engine, '\n');
-           if (eol != NULL) {
-               *eol = '\0';
-           }
-           parse_helper_str_im_change(line, engine);
-       }
-    } else {
-       char *line = str;       
-       char *eol = strchr(line, '\n');
-       if (eol != NULL) {
-           *eol = '\0';
-       }
-
-       if (strncmp("im_change_", line, 10) == 0) {
-           char *engine;
-           engine = eol + 1;
-           eol = strchr(engine, '\n');
-           if (eol != NULL) {
-               *eol = '\0';
-           }
-           parse_helper_str_im_change(line, engine);
-       } else if (strcmp("prop_update_custom", line) == 0) {
-           fprintf(stderr, "prop_update_custom is not implemented yet\n");
-       }
-    }
-}
-
-static void
-helper_read_cb(int fd, int ev)
-{
-    uim_helper_read_proc(fd);
-    char *tmp;
-    while ((tmp = uim_helper_get_message())) {
-       helper_str_parse(tmp);
-       free(tmp);
-    }
-}
-
-static void
-helper_disconnect_cb(void)
-{
-    remove_current_fd_watch(lib_uim_fd);
-    lib_uim_fd = -1;
-}
-
-void
-check_helper_connection(void)
-{
-    if (lib_uim_fd < 0) {
-       lib_uim_fd = uim_helper_init_client_fd(helper_disconnect_cb);
-       if (lib_uim_fd >= 0)
-           add_fd_watch(lib_uim_fd, READ_OK, helper_read_cb);
-    }
-}
-
 int
 main(int argc, char **argv)
 {
@@ -728,41 +552,6 @@
     return 0;
 }
 
-int
-pad4(int x)
-{
-    return (4 - (x % 4)) % 4;
-}
-
-void
-hex_dump(unsigned char *buf, int len)
-{
-    int i, j;
-    unsigned char c[16];
-    for (i = 0; i < len; i += 16) {
-       printf("%8.8x ", i);
-       for (j = 0; j < 16; j++) {
-           if (i + j < len) {
-               c[j] = buf[i + j];
-               if (j == 7)
-                   printf("%2.2x-", c[j]);
-               else
-                   printf("%2.2x ", c[j]);
-           } else {
-               c[j] = 0;
-               printf("-- ");
-           }
-       }
-       printf(" ");
-       for (j = 0; j < 16; j++) {
-           if (isprint(c[j]))
-               printf("%c", c[j]);
-           else
-               printf(".");
-       }
-       printf("\n");
-    }
-}
 /*
  * Local variables:
  *  c-indent-level: 4

Added: trunk/xim/util.cpp
==============================================================================
--- (empty file)
+++ trunk/xim/util.cpp  Wed Dec  8 06:11:53 2004
@@ -0,0 +1,114 @@
+/*
+
+  Copyright (c) 2003,2004 uim Project http://uim.freedesktop.org/
+
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions
+  are met:
+
+  1. Redistributions of source code must retain the above copyright
+     notice, this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright
+     notice, this list of conditions and the following disclaimer in the
+     documentation and/or other materials provided with the distribution.
+  3. Neither the name of authors nor the names of its contributors
+     may be used to endorse or promote products derived from this software
+     without specific prior written permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+  SUCH DAMAGE.
+*/
+
+// miscellaneous functions
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <ctype.h>
+#include <stdarg.h>
+
+#include "util.h"
+
+int
+pad4(int x)
+{
+    return (4 - (x % 4)) % 4;
+}
+
+void
+hex_dump(unsigned char *buf, int len)
+{
+    int i, j;
+    unsigned char c[16];
+    for (i = 0; i < len; i += 16) {
+       printf("%8.8x ", i);
+       for (j = 0; j < 16; j++) {
+           if (i + j < len) {
+               c[j] = buf[i + j];
+               if (j == 7)
+                   printf("%2.2x-", c[j]);
+               else
+                   printf("%2.2x ", c[j]);
+           } else {
+               c[j] = 0;
+               printf("-- ");
+           }
+       }
+       printf(" ");
+       for (j = 0; j < 16; j++) {
+           if (isprint(c[j]))
+               printf("%c", c[j]);
+           else
+               printf(".");
+       }
+       printf("\n");
+    }
+}
+
+#ifndef HAVE_VASPRINTF
+int vasprintf(char **ret, const char *fmt, va_list ap)
+{
+    int len;
+
+    len = vsnprintf(NULL, 0, fmt, ap);
+    if (len <= 0)
+       return len;
+
+    (*ret) = (char *)malloc(len + 1);
+    if (*ret == NULL)
+       return -1;
+    len = vsnprintf(*ret, len + 1, fmt, ap);
+
+    return len;
+}
+#endif
+
+#ifndef HAVE_ASPRINTF
+int asprintf(char **ret, const char *fmt, ...)
+{
+    int len;
+    va_list ap;
+
+    va_start(ap, fmt);
+    len = vasprintf(ret, fmt, ap);
+    va_end(ap);
+
+    return len;
+}
+#endif
+

Added: trunk/xim/util.h
==============================================================================
--- (empty file)
+++ trunk/xim/util.h    Wed Dec  8 06:11:53 2004
@@ -0,0 +1,57 @@
+/*
+
+  Copyright (c) 2003,2004 uim Project http://uim.freedesktop.org/
+
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions
+  are met:
+
+  1. Redistributions of source code must retain the above copyright
+     notice, this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright
+     notice, this list of conditions and the following disclaimer in the
+     documentation and/or other materials provided with the distribution.
+  3. Neither the name of authors nor the names of its contributors
+     may be used to endorse or promote products derived from this software
+     without specific prior written permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+  SUCH DAMAGE.
+*/
+
+#ifndef _util_h_included_
+#define _util_h_included_
+
+// fd dispatch
+#define READ_OK 1
+#define WRITE_OK 2
+void add_fd_watch(int fd, int mask, void (*fn)(int, int));
+void remove_current_fd_watch(int fd);
+
+// misc
+int pad4(int);
+
+// debug functions
+void hex_dump(unsigned char *buf, int len);
+
+// misc replacement functions
+#ifndef HAV_ASPRINTF
+int asprintf(char **ptr, const char *format, ...);
+#endif
+
+#ifndef HAVE_VASPRINTF
+int vasprintf(char **ptr, const char *fmt, va_list ap);
+#endif
+
+#endif

Modified: trunk/xim/ximic.cpp
==============================================================================
--- trunk/xim/ximic.cpp (original)
+++ trunk/xim/ximic.cpp Wed Dec  8 06:11:53 2004
@@ -38,11 +38,15 @@
 #endif
  
 #include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
 #include <ctype.h>
+
 #include "xim.h"
 #include "convdisp.h"
 #include "ximserver.h"
 #include "connection.h"
+#include "util.h"
  
 #ifndef __GNUC__
 # ifdef HAVE_ALLOCA_H

Modified: trunk/xim/ximim.cpp
==============================================================================
--- trunk/xim/ximim.cpp (original)
+++ trunk/xim/ximim.cpp Wed Dec  8 06:11:53 2004
@@ -36,7 +36,10 @@
 # include "config.h"
 #endif
 
+#include <string.h>
+#include <stdlib.h>
 #include <map>
+
 #include "xim.h"
 #include <X11/Xutil.h>
 #define NEED_EVENTS    // for declaration of xEvent

Modified: trunk/xim/ximpacket.cpp
==============================================================================
--- trunk/xim/ximpacket.cpp     (original)
+++ trunk/xim/ximpacket.cpp     Wed Dec  8 06:11:53 2004
@@ -35,7 +35,11 @@
 #endif
 
 #include <list>
+#include <string.h>
+#include <stdlib.h>
+
 #include "xim.h"
+#include "util.h"
 
 //
 // Routines for byte manipulating

Modified: trunk/xim/ximserver.cpp
==============================================================================
--- trunk/xim/ximserver.cpp     (original)
+++ trunk/xim/ximserver.cpp     Wed Dec  8 06:11:53 2004
@@ -30,15 +30,22 @@
   SUCH DAMAGE.
 */
 
+#include <stdio.h>
 #include <ctype.h>
 #include <locale.h>
 #include <X11/Xlib.h>
 #include <X11/Xatom.h>
 #include <X11/Xutil.h>
+#include <X11/keysymdef.h>
+
 #include "xim.h"
 #include "convdisp.h"
 #include "canddisp.h"
 #include "ximserver.h"
+#include "util.h"
+#include "helper.h"
+
+#include "uim/uim-helper.h"
 
 #ifndef __GNUC__
 # ifdef HAVE_ALLOCA_H
@@ -49,7 +56,6 @@
 extern int lib_uim_fd;
 extern Atom xim_servers;
 InputContext *InputContext::mFocusedContext = NULL;
-extern std::list<UIMInfo> uim_info;
 
 static int check_modifier(std::list<KeySym> list);
 static int gShiftMask, gLockMask, gControlMask, gMod1Mask,

Modified: trunk/xim/ximserver.h
==============================================================================
--- trunk/xim/ximserver.h       (original)
+++ trunk/xim/ximserver.h       Wed Dec  8 06:11:53 2004
@@ -36,17 +36,13 @@
 
 #include <X11/X.h>
 #include <X11/Xlib.h>
-#include <X11/keysymdef.h>
-#include <stdio.h>
+
 #include <list>
 #include <vector>
 #include <map>
-#include "uim/uim.h"
-#include "uim/uim-helper.h"
 
+#include "uim/uim.h"
 
-int connection_setup();
-void check_helper_connection();
 
 // preedit ornament
 #define PE_NORMAL 0
@@ -84,12 +80,6 @@
 void init_convdisp();
 void init_modifier_keys();
 
-// misc
-int pad4(int);
-
-// debug functions
-void hex_dump(unsigned char *buf, int len);
-
 
 // for command line option
 // trace comunication between client
@@ -256,6 +246,7 @@
     Locale *locale;
     const char *desc;
 };
+extern std::list<UIMInfo> uim_info;
 
 const char *get_im_lang_from_engine(const char *engine);
 

Modified: trunk/xim/ximtrans.cpp
==============================================================================
--- trunk/xim/ximtrans.cpp      (original)
+++ trunk/xim/ximtrans.cpp      Wed Dec  8 06:11:53 2004
@@ -37,8 +37,10 @@
 #endif
 
 #include <stdio.h>
+#include <string.h>
 #include <X11/Xos.h>
 #include "xim.h"
+#include "util.h"
 
 #ifndef __GNUC__
 # ifdef HAVE_ALLOCA_H

Reply via email to