[uim-commit] r132 - in trunk: scm uim
omote@freedesktop.org
omote@freedesktop.org
Wed Jan 5 11:52:39 PST 2005
Author: omote
Date: 2005-01-05 11:52:37 -0800 (Wed, 05 Jan 2005)
New Revision: 132
Added:
trunk/scm/plugin.scm
Modified:
trunk/uim/anthy.c
trunk/uim/m17nlib.c
trunk/uim/plugin.c
trunk/uim/plugin.h
trunk/uim/uim-compat-scm.c
trunk/uim/uim-custom.c
trunk/uim/uim.c
Log:
* This commit contains the changes of the searching way of plugins. But due to
not mergeed uim_scm_c_list functions to uim-scm.c and for backward
compatibility, new code is disabled by default. If you want to enable this,
uncomment '#define NEW_UIM_PLUGIN 1' in uim/plugin.h.
* scm/plugin.scm: New file including the default search path of plugins.
* uim/plugin.h:
- Update copyright.
+ (_uim_plugin_info):
- (plugin_instance_init): Change the member's names from plugin_init.
- (plugin_instance_quit): Change the member's names from plugin_quit.
* uim/plugin.c:
- Update copyright.
- (__uim_scm_c_list): New function from uim-custom.c for getting string list
from scheme variable. This code has a difference with original code.
uim_scm_c_list does not work if lists' variables are just a array of
strings.
- (__uim_scm_c_str_failsafe): Ditto.
- (__uim_scm_c_str_list): Ditto.
- (__uim_scm_c_list_free): Ditto.
+ (plugin_load):
- Drop a hardcode of searching path.
- Get search path from scheme variable. 'uim-plugin-lib-load-path' is
for shared libraries and 'uim-plugin-scm-load-path' is for scheme.
+ (uim_init_plugin):
- Drop a hardcode of searching path.
- (uim_plugin_instance_query): New function.
* uim/anthy.c, uim/m17nlib.c:
- #include "plugin.h"
- (uim_plugin_instance_init): New function for replacing plugin_init.
- (uim_plugin_instance_quit): Ditto.
- Update copyright.
* uim/uim.c:
- Update copyright.
- (uim_init_scm): Load "plugin.scm" after "im.scm".
* uim/uim-compat-scm.c: Update copyright.
Added: trunk/scm/plugin.scm
===================================================================
--- trunk/scm/plugin.scm 2005-01-05 19:29:06 UTC (rev 131)
+++ trunk/scm/plugin.scm 2005-01-05 19:52:37 UTC (rev 132)
@@ -0,0 +1,58 @@
+;;;
+;;; $Id:$
+;;;
+;;; plugin.scm: Plugin for uim.
+;;;
+;;; Copyright (c) 2005 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.
+;;;;
+
+(define uim-plugin-lib-load-path
+ (list (string-append (getenv "HOME") "/.uim.d/plugin")
+ "/usr/lib/uim/plugin"))
+(define uim-plugin-scm-load-path
+ (list (string-append (getenv "HOME") "/.uim.d/plugin")
+ "/usr/share/uim/plugin"))
+
+(if (getenv "LIBUIM_PLUGIN_DIR")
+ (set! uim-plugin-lib-load-path
+ (append uim-plugin-lib-load-path
+ (list (getenv "LIBUIM_PLUGIN_DIR")))))
+(if (getenv "LIBUIM_SCM_FILES")
+ (set! uim-plugin-scm-load-path
+ (append uim-plugin-scm-load-path
+ (list (getenv "LIBUIM_SCM_FILES")))))
+
+;;; XXX
+(if (getenv "LD_LIBRARY_PATH")
+ (set! uim-plugin-lib-load-path
+ (append uim-plugin-lib-load-path
+ (string-split (getenv "LD_LIBRARY_PATH") ":"))))
+
+(print uim-plugin-lib-load-path)
+(print uim-plugin-scm-load-path)
Modified: trunk/uim/anthy.c
===================================================================
--- trunk/uim/anthy.c 2005-01-05 19:29:06 UTC (rev 131)
+++ trunk/uim/anthy.c 2005-01-05 19:52:37 UTC (rev 132)
@@ -1,6 +1,6 @@
/*
- Copyright (c) 2003,2004 uim Project http://uim.freedesktop.org/
+ Copyright (c) 2003,2004,2005 uim Project http://uim.freedesktop.org/
All rights reserved.
@@ -36,6 +36,7 @@
#include "uim-compat-scm.h"
#include "siod.h"
#include "context.h"
+#include "plugin.h"
#define MAX_CONTEXT 256
@@ -277,7 +278,11 @@
}
void
+#ifndef NEW_UIM_PLUGIN
plugin_init(void)
+#else
+uim_plugin_instance_init(void)
+#endif
{
uim_scm_init_subr_0("anthy-lib-init", init_anthy_lib);
uim_scm_init_subr_0("anthy-lib-alloc-context", create_context);
@@ -291,7 +296,11 @@
}
void
+#ifndef NEW_UIM_PLUGIN
plugin_quit(void)
+#else
+uim_plugin_instance_quit(void)
+#endif
{
int i;
Modified: trunk/uim/m17nlib.c
===================================================================
--- trunk/uim/m17nlib.c 2005-01-05 19:29:06 UTC (rev 131)
+++ trunk/uim/m17nlib.c 2005-01-05 19:52:37 UTC (rev 132)
@@ -1,6 +1,6 @@
/*
- Copyright (c) 2003,2004 uim Project http://uim.freedesktop.org/
+ Copyright (c) 2003,2004,2005 uim Project http://uim.freedesktop.org/
All rights reserved.
@@ -38,6 +38,7 @@
#include <m17n.h>
#include "uim-scm.h"
#include "context.h"
+#include "plugin.h"
static int m17nlib_ok;
static MConverter *converter;
@@ -743,9 +744,22 @@
uim_scm_init_subr_1("m17nlib-lib-get-candidate-index", get_candidate_index);
}
+
void
+#ifndef NEW_UIM_PLUGIN
plugin_init(void) {
+#else
+uim_plugin_instance_init(void)
+{
+#endif
uim_init_m17nlib();
}
+#ifndef NEW_UIM_PLUGIN
+void
+uim_plugin_instance_quit(void)
+{
+ return;
+}
+#endif
#endif /* HAVE_M17NLIB */
Modified: trunk/uim/plugin.c
===================================================================
--- trunk/uim/plugin.c 2005-01-05 19:29:06 UTC (rev 131)
+++ trunk/uim/plugin.c 2005-01-05 19:52:37 UTC (rev 132)
@@ -1,9 +1,9 @@
/*
$Id:$
- plugin.c:
+ plugin.c: Plugin support for uim.
- Copyright (c) 2004 uim Project http://uim.freedesktop.org/
+ Copyright (c) 2004,2005 uim Project http://uim.freedesktop.org/
All rights reserved.
@@ -55,6 +55,11 @@
#define dlfunc dlsym
#endif
+#ifndef NEW_UIM_PLUGIN
+#define UIM_SYS_PLUGIN_LIB_DIR LIBDIR
+#define UIM_SYS_PLUGIN_SCM_DIR SCM_FILES
+#endif
+
#define PLUGIN_PREFIX "libuim-"
#ifdef __APPLE__
#define PLUGIN_SUFFIX ".dylib"
@@ -65,18 +70,98 @@
static uim_plugin_info_list *uim_plugin_list = NULL;
static void plugin_list_append(uim_plugin_info_list *entry);
+#ifndef NEW_UIM_PLUGIN
static char **plugin_lib_path = NULL;
static char **plugin_scm_path = NULL;
+#else
+/* XXX: this code is got from uim-custom.c with some changes. */
+typedef void *(*__uim_scm_c_list_conv_func)(uim_lisp elem);
+typedef void (*__uim_scm_c_list_free_func)(void *elem);
+static void **__uim_scm_c_list(const char *list_repl, const char *mapper_proc,
+ __uim_scm_c_list_conv_func conv_func);
+static char *__uim_scm_c_str_failsafe(uim_lisp str);
+static char **__uim_scm_c_str_list(const char *list_repl, const char *mapper_proc)
+;
+static void __uim_scm_c_list_free(void **list, __uim_scm_c_list_free_func free_func)
+;
+
+static uim_lisp return_val;
+
+static void **
+__uim_scm_c_list(const char *list_repl, const char *mapper_proc,
+ __uim_scm_c_list_conv_func conv_func)
+{
+ int list_len, i;
+ void **result;
+
+ UIM_EVAL_FSTRING1(NULL, "(length %s)", list_repl);
+ return_val = uim_scm_return_value();
+ list_len = uim_scm_c_int(return_val);
+
+ result = (void **)malloc(sizeof(void *) * (list_len + 1));
+ if (!result)
+ return NULL;
+
+ result[list_len] = NULL;
+ for (i = 0; i < list_len; i++) {
+ UIM_EVAL_FSTRING2(NULL, "(nth %d %s)", i, list_repl);
+ return_val = uim_scm_return_value();
+ result[i] = (*conv_func)(return_val);
+ }
+
+ return result;
+}
+
+static char *
+__uim_scm_c_str_failsafe(uim_lisp str)
+{
+ char *c_str;
+ c_str = uim_scm_c_str(str);
+ return (c_str) ? c_str : strdup("");
+}
+
+static char **
+__uim_scm_c_str_list(const char *list_repl, const char *mapper_proc)
+{
+ void **list;
+
+ list = __uim_scm_c_list(list_repl, mapper_proc,
+ (__uim_scm_c_list_conv_func)__uim_scm_c_str_failsafe);
+
+ return (char **)list;
+}
+
+static void
+__uim_scm_c_list_free(void **list, __uim_scm_c_list_free_func free_func)
+{
+ void *elem;
+ void **p;
+
+ if (!list)
+ return;
+
+ for (p = list; elem = *p; p++) {
+ free_func(elem);
+ }
+ free(list);
+}
+#endif
+
static uim_lisp
plugin_load(uim_lisp _name) {
uim_plugin_info *info;
uim_plugin_info_list *info_list_entry;
char *tmp;
+#ifndef NEW_UIM_PLUGIN
char *module_filename;
char *module_filename_fullpath;
char *module_scm_filename;
char **libpath, **scmpath;
+#else
+ char **plugin_lib_path, **plugin_scm_path, **p;
+ char *plugin_lib_filename, *plugin_scm_filename;
+#endif
int i = 0;
size_t len;
@@ -87,6 +172,7 @@
return uim_scm_f();
}
+#ifndef NEW_UIM_PLUGIN
len = strlen(PLUGIN_PREFIX) + strlen(tmp) + strlen(PLUGIN_SUFFIX) + 1;
module_filename = malloc(sizeof(char) * len);
snprintf(module_filename, len, "%s%s%s", PLUGIN_PREFIX, tmp, PLUGIN_SUFFIX);
@@ -94,61 +180,138 @@
libpath = plugin_lib_path;
scmpath = plugin_scm_path;
- if(module_filename[0] != '/') {
- for(i = 2; i >= 0; i--, libpath--, scmpath--) {
- int fd;
+ for(i = 2; i >= 0; i--, libpath--, scmpath--) {
+ int fd;
- len = strlen(*libpath) + 1 + strlen(module_filename) + 1;
- module_filename_fullpath = malloc(sizeof(char) * len);
- snprintf(module_filename_fullpath, len, "%s/%s",
- *libpath, module_filename);
- fd = open(module_filename_fullpath, O_RDONLY);
- if(fd >= 0) {
+ len = strlen(*libpath) + 1 + strlen(module_filename) + 1;
+ module_filename_fullpath = malloc(sizeof(char) * len);
+ snprintf(module_filename_fullpath, len, "%s/%s",
+ *libpath, module_filename);
+ fd = open(module_filename_fullpath, O_RDONLY);
+ if(fd >= 0) {
close(fd);
break;
- }
+ }
- free(module_filename_fullpath);
- module_filename_fullpath = NULL;
- }
- } else {
- module_filename_fullpath = strdup(module_filename);
+ free(module_filename_fullpath);
+ module_filename_fullpath = NULL;
}
if(module_filename_fullpath == NULL) {
free(tmp);
return uim_scm_f();
}
+#else
+ fprintf(stderr, "uim-plugin-lib-load-path\n");
+ plugin_lib_path =
+ __uim_scm_c_str_list("uim-plugin-lib-load-path", "");
+ fprintf(stderr, "uim-plugin-scm-load-path\n");
+ plugin_scm_path =
+ __uim_scm_c_str_list("uim-plugin-scm-load-path", "");
+ if(plugin_lib_path == NULL || plugin_scm_path == NULL) {
+ return uim_scm_f();
+ }
+
+ for(p = plugin_lib_path; *p != NULL; p++) {
+ int fd;
+ fprintf(stderr, "*p: %s\n", *p);
+ len = strlen(*p) + 1
+ + strlen(PLUGIN_PREFIX) + strlen(tmp)+ strlen(PLUGIN_SUFFIX) + 1;
+ plugin_lib_filename = malloc(sizeof(char) * len);
+ snprintf(plugin_lib_filename, len, "%s/%s%s%s",
+ *p, PLUGIN_PREFIX, tmp, PLUGIN_SUFFIX);
+ fd = open(plugin_lib_filename, O_RDONLY);
+ if(fd >= 0) {
+ close(fd);
+ break;
+ }
+
+ free(plugin_lib_filename);
+ plugin_lib_filename = NULL;
+ }
+
+ for(p = plugin_scm_path; *p != NULL; p++) {
+ int fd;
+
+ len = strlen(*p) + 1 + strlen(tmp) + strlen(".scm") + 1;
+ plugin_scm_filename = malloc(sizeof(char) * len);
+ snprintf(plugin_scm_filename, len, "%s/%s.scm", *p, tmp);
+
+ fd = open(plugin_scm_filename, O_RDONLY);
+ if(fd >= 0) {
+ close(fd);
+ break;
+ }
+ free(plugin_scm_filename);
+ plugin_scm_filename = NULL;
+ }
+
+ __uim_scm_c_list_free((void **)plugin_lib_path,
+ (__uim_scm_c_list_free_func)free);
+ __uim_scm_c_list_free((void **)plugin_scm_path,
+ (__uim_scm_c_list_free_func)free);
+
+ if(plugin_lib_filename == NULL || plugin_scm_filename == NULL) {
+ return uim_scm_f();
+ }
+#endif
+
+#ifndef NEW_UIM_PLUGIN
dlopen(module_filename_fullpath, RTLD_GLOBAL|RTLD_NOW);
-
+#endif
info_list_entry = malloc(sizeof(uim_plugin_info_list));
info = malloc(sizeof(uim_plugin_info));
+#ifndef NEW_UIM_PLUGIN
fprintf(stderr, "load %s\n",module_filename_fullpath);
info->library = dlopen(module_filename_fullpath, RTLD_NOW);
+#else
+ fprintf(stderr, "load %s\n", plugin_lib_filename);
+ info->library = dlopen(plugin_lib_filename, RTLD_NOW);
+ free(plugin_lib_filename);
+#endif
+
if(info->library == NULL) {
fprintf(stderr, "load failed %s\n", dlerror());
return uim_scm_f();
}
+#ifndef NEW_UIM_PLUGIN
free(module_filename_fullpath);
free(module_filename);
+#endif
+#ifndef NEW_UIM_PLUGIN
info->plugin_init = (void (*)(void))dlfunc(info->library, "plugin_init");
-
if(info->plugin_init) {
fprintf(stderr, "plugin init\n");
(info->plugin_init)();
}
+#else
+ info->plugin_instance_init = (void (*)(void))dlfunc(info->library,
+ "uim_plugin_instance_init");
+ info->plugin_instance_quit = (void (*)(void))dlfunc(info->library,
+ "uim_plugin_instance_quit");
+ if(info->plugin_instance_init) {
+ fprintf(stderr, "plugin init\n");
+ (info->plugin_instance_init)();
+ }
+#endif
+
/* plugin_list_append(uim_plugin_entry); */
+#ifndef NEW_UIM_PLUGIN
len = strlen(*scmpath) + 1 + strlen(tmp) + strlen(".scm") + 1;
module_scm_filename = malloc(sizeof(char) * len);
snprintf(module_scm_filename, len, "%s/%s.scm", *scmpath, tmp);
uim_scm_require_file(module_scm_filename);
free(module_scm_filename);
+#else
+ uim_scm_require_file(plugin_scm_filename);
+ free(plugin_scm_filename);
+#endif
return uim_scm_t();
}
@@ -166,7 +329,7 @@
}
static uim_lisp
-plugin_unload(uim_lisp _filename)
+plugin_unload(uim_lisp _name)
{
/* XXX: Dynamic unloading is not supported yet*/
return uim_scm_f();
@@ -185,7 +348,7 @@
uim_scm_init_subr_1("load-plugin", plugin_load);
uim_scm_init_subr_1("unload-plugin", plugin_unload);
-
+#ifndef NEW_UIM_PLUGIN
if(plugin_scm_path != NULL && plugin_scm_path != NULL) {
return;
}
@@ -214,7 +377,7 @@
*plugin_scm_path = malloc(sizeof(char) * len);
snprintf(*plugin_lib_path, len, "%s/.uim.d/plugin", pw->pw_dir);
snprintf(*plugin_scm_path, len, "%s/.uim.d/plugin", pw->pw_dir);
-
+#endif
return;
}
@@ -224,8 +387,18 @@
uim_plugin_info_list *cur;
for(cur = uim_plugin_list; cur != NULL; cur = cur->next)
{
-
+#ifndef NEW_UIM_PLUGIN
(*((cur->plugin)->plugin_quit))();
+#else
+ (*((cur->plugin)->plugin_instance_quit))();
+#endif
dlclose((cur->plugin)->library);
}
}
+
+int
+uim_plugin_instance_query(struct _uim_plugin_info *info)
+{
+ /* XXX: not implemented */
+ return 0;
+}
Modified: trunk/uim/plugin.h
===================================================================
--- trunk/uim/plugin.h 2005-01-05 19:29:06 UTC (rev 131)
+++ trunk/uim/plugin.h 2005-01-05 19:52:37 UTC (rev 132)
@@ -3,7 +3,7 @@
plugin.h:
- Copyright (c) 2004 uim Project http://uim.freedesktop.org/
+ Copyright (c) 2004,2005 uim Project http://uim.freedesktop.org/
All rights reserved.
@@ -35,17 +35,20 @@
#ifndef _uim_plugin_h_included_
#define _uim_plugin_h_included_
-#define UIM_SYS_PLUGIN_LIB_DIR LIBDIR
-#define UIM_SYS_PLUGIN_SCM_DIR SCM_FILES
-/* XXX */
+/* #define NEW_UIM_PLUGIN 1 */
typedef struct _uim_plugin_info {
char *name; /* XXX: should have in scm? */
char *description; /* XXX: should have in scm? */
char *author; /* XXX: should have in scm? */
char *version; /* XXX: should have in scm? */
+#ifndef NEW_UIM_PLUGIN
void (*plugin_init)(void);
void (*plugin_quit)(void);
+#else
+ void (*plugin_instance_init)(void);
+ void (*plugin_instance_quit)(void);
+#endif
void *library;
/* void *plugin_unload; */
/* void *plugin_extra_funcs */
Modified: trunk/uim/uim-compat-scm.c
===================================================================
--- trunk/uim/uim-compat-scm.c 2005-01-05 19:29:06 UTC (rev 131)
+++ trunk/uim/uim-compat-scm.c 2005-01-05 19:52:37 UTC (rev 132)
@@ -1,6 +1,6 @@
/*
- Copyright (c) 2003,2004 uim Project http://uim.freedesktop.org/
+ Copyright (c) 2003,2004,2005 uim Project http://uim.freedesktop.org/
All rights reserved.
Modified: trunk/uim/uim-custom.c
===================================================================
--- trunk/uim/uim-custom.c 2005-01-05 19:29:06 UTC (rev 131)
+++ trunk/uim/uim-custom.c 2005-01-05 19:52:37 UTC (rev 132)
@@ -1,6 +1,6 @@
/*
- Copyright (c) 2003,2004 uim Project http://uim.freedesktop.org/
+ Copyright (c) 2003,2004,2005 uim Project http://uim.freedesktop.org/
All rights reserved.
Modified: trunk/uim/uim.c
===================================================================
--- trunk/uim/uim.c 2005-01-05 19:29:06 UTC (rev 131)
+++ trunk/uim/uim.c 2005-01-05 19:52:37 UTC (rev 132)
@@ -1,6 +1,6 @@
/*
- Copyright (c) 2003,2004 uim Project http://uim.freedesktop.org/
+ Copyright (c) 2003,2004,2005 uim Project http://uim.freedesktop.org/
All rights reserved.
@@ -656,6 +656,7 @@
uim_scm_load_file("custom-rt.scm");
#endif
uim_scm_load_file("im.scm");
+ uim_scm_load_file("plugin.scm");
uim_scm_load_file("loader.scm");
uim_scm_load_file("direct.scm"); /* must be loaded at last of IMs */
#if 1
More information about the Uim-commit
mailing list