Author: iratqq
Date: Mon Dec 24 16:46:00 2007
New Revision: 5061

Added:
  trunk/notify/
  trunk/notify/Makefile.am
  trunk/notify/uim-knotify.cc
  trunk/notify/uim-knotify.h
  trunk/notify/uim-libnotify.c
  trunk/notify/uim-libnotify.h
  trunk/uim/uim-notify.c
  trunk/uim/uim-notify.h
Modified:
  trunk/Makefile.am
  trunk/configure.ac
  trunk/scm/im-custom.scm
  trunk/scm/init.scm
  trunk/uim/Makefile.am
  trunk/uim/bsdlook.c
  trunk/uim/canna.c
  trunk/uim/mana.c
  trunk/uim/plugin.c
  trunk/uim/scim.cpp
  trunk/uim/skk.c
  trunk/uim/uim-error.c
  trunk/uim/uim-helper-server.c
  trunk/uim/uim-helper.c
  trunk/uim/uim-util.c

Log:
        * uim/uim-helper-server.c (write_message):
        * uim/plugin.c (plugin_load):
        * uim/uim-helper.c (uim_helper_check_connection_fd):
        * uim/canna.c (create_context, get_unconv_candidate):
        * uim/skk.c (expand_str, open_skkserv):
        * uim/mana.c (mana_ipc_send_command, mana_init):
        * uim/scim.cpp (init_scim, alloc_id):
        * uim/bsdlook.c (look_print_from): replacement fprintf to 
uim_notify_fatal.

        * notify/uim-knotify.cc: add support KDE notify, but not tested.

        * notify/uim-libnotify.cc: add support 'libnotify'.

        * configure.ac, uim/uim-notify.h, uim/uim-notify.c:
        * uim/uim-error.c:
        * uim/uim-util.c (uim_init_util_subrs):
        * scm/init.scm:
        * scm/im-custom.scm (notify-agent): add notify.


Modified: trunk/Makefile.am
==============================================================================
--- trunk/Makefile.am   (original)
+++ trunk/Makefile.am   Mon Dec 24 16:46:00 2007
@@ -2,7 +2,7 @@
ACLOCAL_AMFLAGS = -I m4

SUBDIRS = m4 doc replace sigscheme uim scm test \
-          gtk helper qt
+          gtk helper qt notify
if QT4_IMMODULE
SUBDIRS += qt4
endif

Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac  (original)
+++ trunk/configure.ac  Mon Dec 24 16:46:00 2007
@@ -1295,6 +1295,85 @@

AM_CONDITIONAL(ENABLE_ANTHY_UTF8_STATIC, test x$build_anthy_utf8_static = xyes)

+# *******************************
+# *** Tests for NOTIFY ***
+# *******************************
+notify_targets='libnotify knotify'
+
+AC_ARG_ENABLE(notify,
+ [ --enable-notify[=mode_list] enable notify module (specify comma separated mode list), HIGHLY EXPERIMENTAL:
+                          libnotify: libnotify
+                          knotify:   KDE notify],
+  [ enable_notify=$enableval
+    have_notify_opt=yes ],
+  [ enable_notify=yes
+    have_notify_opt=no ])
+
+if test "x$enable_notify" != xno; then
+  for i in `echo $enable_notify | sed 's/,/ /g'`; do
+    eval "au_enable_$i=yes"
+  done
+fi
+
+AC_MSG_CHECKING(enable_notify=libnotify)
+if test "x$au_enable_libnotify" = xyes; then
+   AC_MSG_RESULT([yes, configuring libnotify])
+   PKG_CHECK_MODULES(LIBNOTIFY, libnotify >= 0.4, use_libnotify="yes",
+                                              use_libnotify="no")
+   if test "x$use_libnotify" = "xyes"; then
+     AC_DEFINE(ENABLE_LIBNOTIFY, 1, [set notify interface with libnotify])
+     AC_SUBST(LIBNOTIFY_LIBS)
+     AC_SUBST(LIBNOTIFY_CFLAGS)
+     use_notify="libnotify "
+   fi
+else
+   AC_MSG_RESULT(no)
+fi
+
+AC_MSG_CHECKING(enable_notify=knotify)
+if test "x$au_enable_knotify" = xyes; then
+   AC_MSG_RESULT([yes, configuring knotify])
+   if test "x$use_qt" = "xyes"; then
+     if test "x$KDE_CONFIG" != "xno"; then
+       KNOTIFY_PREFIX=`kde-config --prefix`
+       KNOTIFY_LIB_DIR=`kde-config --expandvars --install lib`
+       KNOTIFY_DATA_DIR=`kde-config --expandvars --install data`
+       saved_cppflags="${CPPFLAGS}"
+       CPPFLAGS="-I${KNOTIFY_PREFIX}/include/kde ${CPPFLAGS} ${QT_CXXFLAGS}"
+       AC_LANG_PUSH(C++)
+       AC_CHECK_HEADER([${KNOTIFY_PREFIX}/include/kde/knotifyclient.h],
+ [use_knotify="yes" KNOTIFY_INCLUDE_DIR="${KNOTIFY_PREFIX}/include/kde"], [use_knotify="no"])
+       if test "x$use_knotify" = "xno"; then
+         CPPFLAGS="-I${KNOTIFY_PREFIX}/include ${saved_cppflags} 
${QT_CXXFLAGS}"
+         AC_CHECK_HEADER([${KNOTIFY_PREFIX}/include/knotifyclient.h],
+ [use_knotify="yes" KNOTIFY_INCLUDE_DIR="${KNOTIFY_PREFIX}/include"], [use_knotify="no"])
+       fi
+       CPPFLAGS="${saved_cppflags}"
+       AC_LANG_POP(C++)
+      else
+       use_knotify="no"
+      fi
+    else
+      use_knotify="no"
+    fi
+fi
+if test "x$use_knotify" = "xyes"; then
+  AC_DEFINE(ENABLE_KNOTIFY, 1, [set notify interface with knotify])
+  AC_SUBST(KNOTIFY_PREFIX)
+  AC_SUBST(KNOTIFY_LIB_DIR)
+  AC_SUBST(KNOTIFY_DATA_DIR)
+  AC_SUBST(KNOTIFY_INCLUDE_DIR)
+  use_notify="${use_notify}knotify "
+fi
+
+if test "x$use_notify" = "x"; then
+  use_notify=none
+fi
+
+AM_CONDITIONAL(LIBNOTIFY, test x$use_libnotify = xyes)
+AM_CONDITIONAL(KNOTIFY, test x$use_knotify = xyes)
+
+
AC_DEFINE(UIM_USE_ERROR_GUARD, 1, [Define to 1 if you want to use longjmp-based error handlings])

#
@@ -1427,6 +1506,7 @@
                 pixmaps/Makefile
                 pixmaps/uim-m17nlib-relink-icons
                 replace/Makefile
+                notify/Makefile
                 uim.pc
                 uim.desktop.in
                 uim.spec
@@ -1465,6 +1545,7 @@
   DICT            : ${use_dict}
   EB              : ${use_eb}
   libedit         : ${use_libedit}
+   notify          : ${use_notify}
   Default toolkit : ${default_toolkit}
])


Added: trunk/notify/Makefile.am
==============================================================================
--- (empty file)
+++ trunk/notify/Makefile.am    Mon Dec 24 16:46:00 2007
@@ -0,0 +1,24 @@
+AUTOMAKE_OPTIONS = foreign
+
+uimnotify_plugin_LTLIBRARIES =
+uimnotify_plugindir = $(pkglibdir)/notify
+
+if LIBNOTIFY
+uimnotify_plugin_LTLIBRARIES += libuimnotify-libnotify.la
+libuimnotify_libnotify_la_SOURCES = uim-libnotify.c
+libuimnotify_libnotify_la_CFLAGS = @LIBNOTIFY_CFLAGS@
+libuimnotify_libnotify_la_LDFLAGS  = -avoid-version -module
+libuimnotify_libnotify_la_LIBADD = \
+       $(top_builddir)/uim/libuim.la \
+       @LIBNOTIFY_LIBS@
+endif
+
+if KNOTIFY
+uimnotify_plugin_LTLIBRARIES += libuimnotify-knotify.la
+libuimnotify_knotify_la_SOURCES = uim-knotify.cc
+libuimnotify_knotify_la_CXXFLAGS = [EMAIL PROTECTED]@ $(QT_CXXFLAGS)
+libuimnotify_knotify_la_LDFLAGS = -avoid-version -module [EMAIL PROTECTED]@ $(QT_LDFLAGS)
+libuimnotify_knotify_la_LIBADD = \
+       $(top_builddir)/uim/libuim.la \
+       -lkdeui -lkdecore
+endif

Added: trunk/notify/uim-knotify.cc
==============================================================================
--- (empty file)
+++ trunk/notify/uim-knotify.cc Mon Dec 24 16:46:00 2007
@@ -0,0 +1,91 @@
+/*
+  Copyright (c) 2003-2007 uim Project http://code.google.com/p/uim/
+
+  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 COPYRIGHT HOLDERS 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 COPYRIGHT HOLDERS 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.
+
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <kapplication.h>
+#include <knotifyclient.h>
+
+#include "config.h"
+#include "knotify.h"
+
+int uim_notify_init(void);
+void uim_notify_quit(void);
+int uim_notify_info(const char *, va_list);
+int uim_notify_fatal(const char *, va_list);
+
+int
+uim_knotify_notify_init()
+{
+  KApplication app(argc, argv, "uim"); // XXX
+  return 1;
+}
+
+void
+uim_knotify_notify_quit()
+{
+  return;
+}
+
+int
+uim_knotify_notify_info(int timeout, const char *msg_fmt, va_list ap)
+{
+  char body[BUFSIZ];
+  char body_short[256];
+  char body_fmt[BUFSIZ];
+
+  strlcpy(body_fmt, "uim: ", sizeof(body_fmt));
+  strlcat(body_fmt, msg_fmt, sizeof(body_fmt));
+  vsnprintf(body, sizeof(body), body_fmt, ap);
+  strlcpy(body_short, body, sizeof(body_short));
+
+  KNotifyClient::userEvent(body_short, KNotifyClient::Messagebox);
+  kapp->processEvents();
+}
+
+int
+uim_knotify_notify_fatal(int timeout, const char *msg_fmt, va_list ap)
+{
+  char body[BUFSIZ];
+  char body_short[256];
+  char body_fmt[BUFSIZ];
+
+  strlcpy(body_fmt, "uim: ", sizeof(body_fmt));
+  strlcat(body_fmt, msg_fmt, sizeof(body_fmt));
+  vsnprintf(body, sizeof(body), body_fmt, ap);
+  strlcpy(body_short, body, sizeof(body_short));
+
+  KNotifyClient::userEvent(body_short, KNotifyClient::Messagebox, 
KNotifyClient::Error);
+  kapp->processEvents();
+}

Added: trunk/notify/uim-knotify.h
==============================================================================
--- (empty file)
+++ trunk/notify/uim-knotify.h  Mon Dec 24 16:46:00 2007
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2004 Iwata <[EMAIL PROTECTED]>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, 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 UIM_KNOTIFY_H
+#define UIM_KNOTIFY_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+       
+#ifdef __cplusplus
+};
+#endif
+
+#endif
+

Added: trunk/notify/uim-libnotify.c
==============================================================================
--- (empty file)
+++ trunk/notify/uim-libnotify.c        Mon Dec 24 16:46:00 2007
@@ -0,0 +1,120 @@
+/*
+  Copyright (c) 2003-2007 uim Project http://code.google.com/p/uim/
+
+  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 COPYRIGHT HOLDERS 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 COPYRIGHT HOLDERS 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.
+
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <glib.h>
+#include <libnotify/notify.h>
+
+#include "config.h"
+#include "uim-libnotify.h"
+
+int uim_notify_init(void);
+void uim_notify_quit(void);
+int uim_notify_info(const char *, va_list);
+int uim_notify_fatal(const char *, va_list);
+
+#define UIM_ICON UIM_PIXMAPSDIR "/uim-icon.png"
+
+static int uim_libnotify_timeout = 3000;
+
+static int
+uim_libnotify_notify(int urgency, const char *body_fmt, va_list ap)
+{
+  char body[BUFSIZ];
+  char body_short[256];
+  NotifyNotification *notification;
+  GError *error = NULL;
+  gboolean ret;
+
+  vsnprintf(body, sizeof(body), body_fmt, ap);
+  strlcpy(body_short, body, sizeof(body_short));
+
+  fprintf(stderr, "uim: %s\n", body);
+
+  if (!notify_is_initted()) {
+    fprintf(stderr, "libnotify: libnotify is not initted\n");
+    return 0;
+  }
+
+  notification = notify_notification_new("uim", body_short, UIM_ICON, NULL);
+
+  if (!notification) {
+ fprintf(stderr, "notify_notification_new: can not create notification object\n");
+    return 0;
+  }
+
+  if (0 < uim_libnotify_timeout)
+    notify_notification_set_timeout(notification, uim_libnotify_timeout);
+
+  notify_notification_set_urgency(notification, urgency);
+
+  ret = notify_notification_show(notification, &error);
+  if (error) {
+    fprintf(stderr, "notify_notification_show: %s\n", error->message);
+    return 0;
+  }
+
+  g_object_unref(G_OBJECT(notification));
+
+  return 1;
+}
+
+/*
+  interface
+ */
+int
+uim_notify_init(void)
+{
+  return notify_init("uim");
+}
+
+void
+uim_notify_quit(void)
+{
+  if (notify_is_initted())
+    notify_uninit();
+}
+
+int
+uim_notify_info(const char *msg_fmt, va_list ap)
+{
+  return uim_libnotify_notify(NOTIFY_URGENCY_NORMAL, msg_fmt, ap);
+}
+
+int
+uim_notify_fatal(const char *msg_fmt, va_list ap)
+{
+  return uim_libnotify_notify(NOTIFY_URGENCY_CRITICAL, msg_fmt, ap);
+}

Added: trunk/notify/uim-libnotify.h
==============================================================================
--- (empty file)
+++ trunk/notify/uim-libnotify.h        Mon Dec 24 16:46:00 2007
@@ -0,0 +1,51 @@
+/*
+  Copyright (c) 2003-2007 uim Project http://code.google.com/p/uim/
+
+  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 COPYRIGHT HOLDERS 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 COPYRIGHT HOLDERS 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 UIM_LIBNOTIFY_H
+#define UIM_LIBNOTIFY_H
+
+#include <stdarg.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int uim_libnotify_notify_init(void);
+void uim_libnotify_notify_quit(void);
+int uim_libnotify_notify_info(const char *, va_list);
+int uim_libnotify_notify_fatal(const char *, va_list);
+
+#ifdef __cplusplus
+};
+#endif
+
+#endif

Modified: trunk/scm/im-custom.scm
==============================================================================
--- trunk/scm/im-custom.scm     (original)
+++ trunk/scm/im-custom.scm     Mon Dec 24 16:46:00 2007
@@ -545,5 +545,23 @@
                   uim-xim-use-xft-font?))


+(define-custom-group 'notify
+                    (N_ "Notify")
+                    (N_ "long description will be here."))
+
+(define-custom 'notify-agent 'stderr
+  '(notify)
+  `(choice
+    ,@(map (lambda (str)
+             (list (string->symbol str) str str))
+           (uim-notify-get-plugins)))
+  (N_ "Notify agent name")
+  (N_ "long description will be here."))
+
+(custom-add-hook 'notify-agent
+                'custom-set-hooks
+                (lambda ()
+                  (uim-notify-load (symbol->string notify-agent))))
+
(if custom-full-featured?
    (for-each require-module installed-im-module-list))

Modified: trunk/scm/init.scm
==============================================================================
--- trunk/scm/init.scm  (original)
+++ trunk/scm/init.scm  Mon Dec 24 16:46:00 2007
@@ -123,6 +123,8 @@
(require-custom "im-custom.scm")
(load-modules)

+(uim-notify-load (symbol->string notify-agent))
+
(or (getenv "LIBUIM_VANILLA")
    (load-user-conf)
    (load "default.scm"))

Modified: trunk/uim/Makefile.am
==============================================================================
--- trunk/uim/Makefile.am       (original)
+++ trunk/uim/Makefile.am       Mon Dec 24 16:46:00 2007
@@ -48,7 +48,7 @@
                iconv.c plugin.c \
                uim-ipc.c uim-helper.c uim-helper-client.c \
                gettext.h intl.c \
-               rk.c
+               rk.c uim-notify.c

libuim_custom_la_SOURCES = uim-custom.c

@@ -199,7 +199,7 @@
uim_helper_server_LIBS =
uim_helper_server_CPPFLAGS = $(uim_defs) -I$(top_srcdir)
uim_helper_server_CFLAGS =
-uim_helper_server_SOURCES = uim-helper.c uim-helper-server.c uim-error.c
+uim_helper_server_SOURCES = uim-helper.c uim-helper-server.c uim-error.c uim-notify.c
uim_helper_server_LDADD = $(top_builddir)/replace/libreplace.la

uim_sh_LIBS =

Modified: trunk/uim/bsdlook.c
==============================================================================
--- trunk/uim/bsdlook.c (original)
+++ trunk/uim/bsdlook.c Mon Dec 24 16:46:00 2007
@@ -404,11 +404,11 @@
        for (; front < back && compare(string, front, ctx) == EQUAL; ++front) {
                for (; front < back && *front != '\n'; ++front)
                        if (putchar(*front) == EOF) {
-                               fprintf(stderr, "print_from: stdout");
+                               uim_notify_fatal("bsdlook(print_from): stdout");
                                return;
                        }
                if (putchar('\n') == EOF) {
-                       fprintf(stderr, "print_from: stdout");
+                       uim_notify_fatal("bsdlook(print_from): stdout");
                        return;
                }
        }

Modified: trunk/uim/canna.c
==============================================================================
--- trunk/uim/canna.c   (original)
+++ trunk/uim/canna.c   Mon Dec 24 16:46:00 2007
@@ -165,7 +165,7 @@
  buf = diclist;
  for (i = 0; i < dic_num; i++) {
    if (RkMountDic(cc->rk_context_id, buf, 0) == ERR) {
-      fprintf(stderr, "Failed to mount dictionary %s\n", buf);
+      uim_notify_fatal("uim-canna: Failed to mount dictionary %s", buf);
    }
    buflen = strlen(buf) + sizeof((char)'\0');
    buf += buflen;
@@ -308,7 +308,7 @@
  if (len == ERR)
    uim_fatal_error("RkGetYomi() failed");
#ifdef UIM_CANNA_DEBUG
-  fprintf(stderr, "yomi: %s\n", buf);
+  uim_notify_info("yomi: %s", buf);
#endif
  return MAKE_STR(buf);
}

Modified: trunk/uim/mana.c
==============================================================================
--- trunk/uim/mana.c    (original)
+++ trunk/uim/mana.c    Mon Dec 24 16:46:00 2007
@@ -98,9 +98,9 @@
        fgets(buf, sizeof(buf), *read_fp);
        if (buf != NULL) {
          if (strcmp(buf, "err") == 0)
-            fprintf(stderr, "mana not found\n");
+            uim_notify_fatal("uim-mana: mana not found");
          else
-            fprintf(stderr, "%s", buf);
+            uim_notify_fatal("uim-mana: %s", buf);
        }
      }

@@ -171,7 +171,7 @@
    fclose(mana_r);
    fclose(mana_w);
    mana_r = mana_w = NULL;
-    fprintf(stderr, "mana not found\n");
+    uim_notify_fatal("uim-mana: mana not found");
    return uim_scm_f();
  }


Modified: trunk/uim/plugin.c
==============================================================================
--- trunk/uim/plugin.c  (original)
+++ trunk/uim/plugin.c  Mon Dec 24 16:46:00 2007
@@ -162,7 +162,7 @@
  free(plugin_lib_filename);

  if (library == NULL) {
-    fprintf(stderr, "load failed %s\n", dlerror());
+    uim_notify_fatal("load failed %s", dlerror());
    free(plugin_scm_filename);
    return uim_scm_f();
  }
@@ -172,7 +172,7 @@
  plugin_instance_quit
    = (void (*)(void))(uintptr_t)dlfunc(library, "uim_plugin_instance_quit");
  if (!plugin_instance_init) {
-    fprintf(stderr, "%s plugin init failed\n", plugin_name);
+    uim_notify_fatal("%s plugin init failed", plugin_name);
    free(plugin_scm_filename);
    return uim_scm_f();
  }
@@ -184,7 +184,7 @@

    succeeded = uim_scm_require_file(plugin_scm_filename);
    if (!succeeded) {
-      fprintf(stderr, "%s plugin subsequent %s loading failed\n",
+      uim_notify_fatal("%s plugin subsequent %s loading failed",
              plugin_name, plugin_scm_filename);
      free(plugin_scm_filename);
      return uim_scm_f();

Modified: trunk/uim/scim.cpp
==============================================================================
--- trunk/uim/scim.cpp  (original)
+++ trunk/uim/scim.cpp  Mon Dec 24 16:46:00 2007
@@ -170,7 +170,7 @@
        config_module = new ConfigModule( "simple" );
        if ( !config_module )
        {
-            fprintf(stderr, "Could not create ConfigModule\n");
+            uim_notify_fatal("init_scim: Could not create ConfigModule");
            return uim_scm_f();
        }

@@ -183,14 +183,14 @@
#endif
        if ( config.null() )
        {
-            fprintf(stderr, "create_config failed\n");
+            uim_notify_fatal("init_scim: create_config failed");
            return uim_scm_f();
        }

        be = new CommonBackEnd( config, engine_list );
        if ( be.null() )
        {
-            fprintf(stderr, "create CommonBackEnd failed\n");
+            uim_notify_fatal("init_scim: create CommonBackEnd failed");
            return uim_scm_f();
        }

@@ -311,7 +311,7 @@
    String uuid = search_uuid_by_imname( imname );
    if ( uuid.empty() )
    {
-        fprintf( stderr, "failed to search uuid\n" );
+        uim_notify_fatal( "uim-scim: failed to search uuid" );
        return uim_scm_f();
    }
    context->factory = be->get_factory( uuid );
@@ -323,7 +323,7 @@
context->instance = context->factory->create_instance( "UTF-8", instance_count );
    if ( context->instance.null() )
    {
-        fprintf(stderr, "failed to create IMEngineInstance\n");
+        uim_notify_fatal("uim-scim: failed to create IMEngineInstance");
        return uim_scm_f();
    }


Modified: trunk/uim/skk.c
==============================================================================
--- trunk/uim/skk.c     (original)
+++ trunk/uim/skk.c     Mon Dec 24 16:46:00 2007
@@ -978,7 +978,7 @@
          p++;
          c = *p;
          if (*p == '\0') {
-           fprintf(stderr, "error in expand_str\n");
+           uim_notify_fatal("uim-skk: error in expand_str");
            return NULL;
          }
          if (c >= '0' && c <= '7') {
@@ -993,7 +993,7 @@
      }
    }
    if ((i + 1) >= BUFSIZ) {
-      fprintf(stderr, "expand_str: too long word\n");
+      uim_notify_fatal("uim-skk: too long word");
      return NULL;
    }
    buf[i] = c;
@@ -3576,7 +3576,7 @@
  hints.ai_socktype = SOCK_STREAM;

  if ((error = getaddrinfo(hostname, port, &hints, &aitop))) {
-    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(error));
+    uim_notify_fatal("uim-skk: %s", gai_strerror(error));
    return 0;
  }

@@ -3591,7 +3591,7 @@
    if (connect(sock, ai->ai_addr, ai->ai_addrlen) == 0)
      break;
    else
-      fprintf(stderr, "connect to %s port %s failed\n", hostname, port);
+ uim_notify_fatal("uim-skk: connect to %s port %s failed", hostname, port);
    close(sock);
    sock = -1;
  }  while ((ai = ai->ai_next) != NULL);
@@ -3602,7 +3602,7 @@
    return 0;

#if 0
-  fprintf(stderr, "SKKSERVER=%s\n", hostname);
+  uim_notify_info("uim-skk: SKKSERVER=%s", hostname);
#endif
  skkservsock = sock;
  rserv = fdopen(sock, "r");

Modified: trunk/uim/uim-error.c
==============================================================================
--- trunk/uim/uim-error.c       (original)
+++ trunk/uim/uim-error.c       Mon Dec 24 16:46:00 2007
@@ -43,7 +43,7 @@

#include "uim.h"
#include "uim-internal.h"
-
+#include "uim-notify.h"

#ifndef EX_SOFTWARE
#define EX_SOFTWARE 70
@@ -60,7 +60,6 @@
static int guarded;
static const char *err_msg;

-
void
uim_init_error(void)
{
@@ -74,6 +73,7 @@
print_caught_error(void)
{
  if (err_msg) {
+ uim_notify_fatal(err_msg); /* XXX: stdout messges will be duplicated */
    fputs("libuim: ", stderr);
    if (fatal_errored)
      fputs("fatal error: ", stderr);
@@ -200,3 +200,4 @@

  return copied;
}
+

Modified: trunk/uim/uim-helper-server.c
==============================================================================
--- trunk/uim/uim-helper-server.c       (original)
+++ trunk/uim/uim-helper-server.c       Mon Dec 24 16:46:00 2007
@@ -279,7 +279,7 @@
        fprintf(stderr, "EAGAIN: fd = %d\n", cl->fd);
#endif
      } else {
-       perror("uim-helper_server write(2) failed");
+       uim_notify_fatal("uim-helper-server: %s", strerror(errno));
        if (errno == EPIPE) {
          fprintf(stderr, "fd = %d\n", cl->fd);
          FD_CLR(cl->fd, &s_fdset_read);

Modified: trunk/uim/uim-helper.c
==============================================================================
--- trunk/uim/uim-helper.c      (original)
+++ trunk/uim/uim-helper.c      Mon Dec 24 16:46:00 2007
@@ -202,11 +202,11 @@
  uid_t euid;
  gid_t egid;
  if (getpeereid(fd, &euid, &egid) < 0) {
-    perror("getpeereid failed");
+    uim_notify_fatal("uim_helper: %s", strerror(errno));
    return -1;
  }
  if ((euid != 0) && (euid != getuid())) {
-    fprintf(stderr, "uid mismatch\n");
+    uim_notify_fatal("uim_helper: uid mismatch");
    return -1;
  }
  return 0;

Added: trunk/uim/uim-notify.c
==============================================================================
--- (empty file)
+++ trunk/uim/uim-notify.c      Mon Dec 24 16:46:00 2007
@@ -0,0 +1,202 @@
+/*
+  Copyright (c) 2003-2007 uim Project http://code.google.com/p/uim/
+
+  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 COPYRIGHT HOLDERS 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 COPYRIGHT HOLDERS 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.
+
+*/
+
+#include <config.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <dlfcn.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <pwd.h>
+
+#include "uim.h"
+#include "uim-scm.h"
+#include "uim-scm-abbrev.h"
+#include "uim-internal.h"
+#include "uim-notify.h"
+
+#ifndef HAVE_DLFUNC
+#define dlfunc dlsym
+#endif
+
+static int uim_notify_stderr_init(void);
+static void uim_notify_stderr_quit(void);
+static int uim_notify_stderr_info(const char *, va_list);
+static int uim_notify_stderr_fatal(const char *, va_list);
+
+static int (*uim_notify_init_func)(void) = uim_notify_stderr_init;
+static void (*uim_notify_quit_func)(void) = uim_notify_stderr_quit;
+static int (*uim_notify_info_func)(const char *, va_list) = 
uim_notify_stderr_info;
+static int (*uim_notify_fatal_func)(const char *, va_list) = 
uim_notify_stderr_fatal;
+
+static char notify_agent_name[PATH_MAX];
+
+int
+uim_notify_load(const char *name)
+{
+  if (uim_notify_quit_func == NULL) {
+    fprintf(stderr, "uim-notify: notify module is not loaded\n");
+    return 0;
+  }
+
+  uim_notify_quit_func();
+
+  if (strcmp(name, "stderr") == 0) {
+    uim_notify_init_func  = uim_notify_stderr_init;
+    uim_notify_quit_func  = uim_notify_stderr_quit;
+    uim_notify_info_func  = uim_notify_stderr_info;
+    uim_notify_fatal_func = uim_notify_stderr_fatal;
+  } else if (strcmp(notify_agent_name, name) == 0) {
+    return 1;
+  } else {
+    void *handle;
+    char path[PATH_MAX];
+    const char *str;
+
+ snprintf(path, sizeof(path), "%s/%s%s%s", NOTIFY_PLUGIN_PATH, NOTIFY_PLUGIN_PREFIX, name, NOTIFY_PLUGIN_SUFFIX);
+
+    handle = dlopen(path, RTLD_NOW);
+    if ((str = dlerror()) != NULL) {
+      fprintf(stderr, "uim-notify: load failed %s(%s)\n", path, str);
+      return 0;
+    }
+    uim_notify_init_func  = dlfunc(handle, "uim_notify_init");
+    if (!uim_notify_init_func) {
+ fprintf(stderr, "uim-notify: cannot found 'uim_notify_init()' in %s\n", path);
+      return 0;
+    }
+    uim_notify_quit_func  = dlfunc(handle, "uim_notify_quit");
+    if (!uim_notify_quit_func) {
+ fprintf(stderr, "uim-notify: cannot found 'uim_notify_quit()' in %s\n", path);
+      return 0;
+    }
+    uim_notify_info_func  = dlfunc(handle, "uim_notify_info");
+    if (!uim_notify_info_func) {
+ fprintf(stderr, "uim-notify: cannot found 'uim_notify_info()' in %s\n", path);
+      return 0;
+    }
+    uim_notify_fatal_func = dlfunc(handle, "uim_notify_fatal");
+    if (!uim_notify_fatal_func) {
+ fprintf(stderr, "uim-notify: cannot found 'uim_notify_fatal()' in %s\n", path);
+      return 0;
+    }
+
+    uim_notify_init_func();
+
+    strlcpy(notify_agent_name, name, sizeof(notify_agent_name));
+  }
+  return 1;
+}
+
+int
+uim_notify_init(void)
+{
+  return uim_notify_init_func();
+}
+
+void
+uim_notify_quit(void)
+{
+  uim_notify_quit_func();
+  return;
+}
+
+int
+uim_notify_info(const char *msg_fmt, ...)
+{
+  int ret;
+  va_list ap;
+
+  va_start(ap, msg_fmt);
+  ret = uim_notify_info_func(msg_fmt, ap);
+  va_end(ap);
+
+  return ret;
+}
+
+int
+uim_notify_fatal(const char *msg_fmt, ...)
+{
+  int ret;
+  va_list ap;
+
+  va_start(ap, msg_fmt);
+  ret = uim_notify_fatal_func(msg_fmt, ap);
+  va_end(ap);
+
+  return ret;
+}
+
+
+
+/*
+ * builtin functions
+ */
+static int
+uim_notify_stderr_init(void)
+{
+  return 1;
+}
+
+static void
+uim_notify_stderr_quit(void)
+{
+  return;
+}
+
+static int
+uim_notify_stderr_info(const char *fmt, va_list ap)
+{
+  char buf[BUFSIZ];
+
+  vsnprintf(buf, sizeof(buf), fmt, ap);
+
+  return printf("uim [Info]: %s", buf);
+}
+
+static int
+uim_notify_stderr_fatal(const char *fmt, va_list ap)
+{
+  char buf[BUFSIZ];
+
+  vsnprintf(buf, sizeof(buf), fmt, ap);
+
+  return printf("uim [Fatal]: %s", buf);
+}
+

Added: trunk/uim/uim-notify.h
==============================================================================
--- (empty file)
+++ trunk/uim/uim-notify.h      Mon Dec 24 16:46:00 2007
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2004 Iwata <[EMAIL PROTECTED]>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, 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 UIM_NOTIFY_H
+#define UIM_NOTIFY_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define NOTIFY_PLUGIN_PREFIX "libuimnotify-"
+#define NOTIFY_PLUGIN_SUFFIX ".so"
+
+#define NOTIFY_PLUGIN_PATH LIBDIR "/uim/notify"
+
+int uim_notify_load(const char *);
+int uim_notify_init(void);
+void uim_notify_quit(void);
+int uim_notify_info(const char *, ...);
+int uim_notify_fatal(const char *, ...);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+

Modified: trunk/uim/uim-util.c
==============================================================================
--- trunk/uim/uim-util.c        (original)
+++ trunk/uim/uim-util.c        Mon Dec 24 16:46:00 2007
@@ -39,11 +39,13 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
+#include <dirent.h>

#include "uim-internal.h"
#include "uim-scm.h"
#include "uim-scm-abbrev.h"
#include "uim-util.h"
+#include "uim-notify.h"

static uim_lisp protected;

@@ -283,6 +285,70 @@
  return MAKE_BOOL(uim_issetugid());
}

+static uim_lisp
+uim_scm_notify_get_plugins(void)
+{
+  uim_lisp ret_;
+  DIR *dirp;
+  struct dirent *dp;
+  int plen, slen;
+
+  plen = strlen(NOTIFY_PLUGIN_PREFIX);
+  slen = strlen(NOTIFY_PLUGIN_SUFFIX);
+
+  ret_ = CONS(MAKE_STR("stderr"), uim_scm_null());
+  dirp = opendir(NOTIFY_PLUGIN_PATH);
+  if (dirp) {
+    while ((dp = readdir(dirp)) != NULL) {
+      char name[PATH_MAX];
+      int len = strlen(dp->d_name);
+
+      if ((len < plen + slen) || (sizeof(name) < len) ||
+         (strcmp(dp->d_name, NOTIFY_PLUGIN_PREFIX) <= 0) ||
+         (strcmp(dp->d_name + len - slen, NOTIFY_PLUGIN_SUFFIX) != 0))
+       continue;
+
+      strlcpy(name, dp->d_name + plen, len - plen - slen + 1);
+      ret_ = CONS(MAKE_STR(name), ret_);
+    }
+    (void)closedir(dirp);
+  }
+  return uim_scm_callf("reverse", "o", ret_);
+}
+
+static uim_lisp
+uim_scm_notify_load(uim_lisp name_)
+{
+  const char *name = REFER_C_STR(name_);
+
+  if (uim_notify_load(name))
+    return uim_scm_t();
+  else
+    return uim_scm_f();
+}
+
+static uim_lisp
+uim_scm_notify_info(uim_lisp msg_)
+{
+  const char *msg = REFER_C_STR(msg_);
+
+  if (uim_notify_info("%s", msg))
+    return uim_scm_t();
+  else
+    return uim_scm_f();
+}
+
+static uim_lisp
+uim_scm_notify_fatal(uim_lisp msg_)
+{
+  const char *msg = REFER_C_STR(msg_);
+
+  if (uim_notify_fatal("%s", msg))
+    return uim_scm_t();
+  else
+    return uim_scm_f();
+}
+
void
uim_init_util_subrs(void)
{
@@ -316,4 +382,10 @@

  /* SRFI-43 */
  uim_scm_init_proc1("vector-copy", vector_copy);
+
+  /* notify */
+  uim_scm_init_proc0("uim-notify-get-plugins", uim_scm_notify_get_plugins);
+  uim_scm_init_proc1("uim-notify-load", uim_scm_notify_load);
+  uim_scm_init_proc1("uim-notify-info", uim_scm_notify_info);
+  uim_scm_init_proc1("uim-notify-fatal", uim_scm_notify_fatal);
}

Reply via email to