[uim-commit] r1451 - in trunk: scm uim
ekato at freedesktop.org
ekato at freedesktop.org
Wed Sep 7 07:46:47 PDT 2005
Author: ekato
Date: 2005-09-07 07:46:44 -0700 (Wed, 07 Sep 2005)
New Revision: 1451
Modified:
trunk/scm/Makefile.am
trunk/scm/uim-module-manager.scm
trunk/uim/uim-module-manager.c
Log:
* uim/uim-module-manager.c : Clean up the code for improving
readability.
(get_arguments) : Removed.
(modulenames) : Ditto.
(main) : Stop using global uim_lisp modulenames variable, and use
char *module_names instead.
* scm/uim-module-manager.scm : Follow the changes in
uim/uim-module-mangager.c. Stop using 'modules' file since
it is sufficient to use installed-im-module-list for getting
current information about the modules.
(get-new-registered-module-list) : Rename to
add-modules-to-module-list.
(add-modules-to-module-list) : Renamed from
get-new-registered-module-list.
(remove-unregistered-modules) : Rename to
remove-modules-from-module-list.
(remove-modules-from-module-list) : Renamed from
remove-unregistered-modules).
(register-modules) : Stop using get-arguments and use string
"module-names" from C side instead. Use
installed-im-module-list as a current setting instead of reading
modules file.
(unregister-modules) : Ditto.
(update-modules-installed-modules.scm-loader.scm) : Rename
to update-all-files.
(update-all-files) : Renamed from
update-modules-installed-modules.scm-loader.scm. Don't create
modules file.
(update-modules) : Rename to update-modules-file.
(update-modules-file) : Renamed from update-modules.
* scm/Makefile.am : Create installed-modules.scm and loader.scm using
uim-module-manager.
Modified: trunk/scm/Makefile.am
===================================================================
--- trunk/scm/Makefile.am 2005-09-07 12:14:22 UTC (rev 1450)
+++ trunk/scm/Makefile.am 2005-09-07 14:46:44 UTC (rev 1451)
@@ -35,52 +35,40 @@
endif
module_names = "pyload"
-
if ANTHY
module_names += "anthy"
endif
-
if CANNA
module_names += "canna"
endif
-
if PRIME
module_names += "prime"
endif
-
if SKK
module_names += "skk"
endif
-
module_names += "tcode" "tutcode" "hangul" "viqr" "ipa-x-sampa" "latin"
-
if M17NLIB
module_names += "m17nlib"
endif
-
if SCIM
module_names += "scim"
endif
-
-# TODO: resolve dependency to $(top_builddir)/uim/uim-sh in proper way
+# TODO: resolve dependency to $(top_builddir)/uim/uim-module-manager
+# in a proper way
installed-modules.scm: $(SCM_FILES)
- $(MAKE) -C $(top_builddir)/uim uim-sh && \
- $(ECHO) "(define installed-im-module-list '(" '$(module_names)' ")) \
- (require \"manage-modules.scm\") \
- (generate-installed-modules-scm)" \
- | LIBUIM_VERBOSE=1 LIBUIM_VANILLA=1 LIBUIM_SCM_FILES=`(cd $(top_srcdir) && pwd)`/scm LIBUIM_PLUGIN_LIB_DIR=$(top_builddir)/uim/.libs \
- $(top_builddir)/uim/uim-sh -B >$@
+ $(MAKE) -C $(top_builddir)/uim uim-module-manager && \
+ LIBUIM_SCM_FILES=`(cd $(top_srcdir) && pwd)`/scm LIBUIM_PLUGIN_LIB_DIR=$(top_builddir)/uim/.libs \
+ $(top_builddir)/uim/uim-module-manager \
+ --path $(top_builddir)/scm --register $(module_names)
-# TODO: resolve dependency to $(top_builddir)/uim/uim-sh in proper way
-loader.scm: installed-modules.scm
- $(MAKE) -C $(top_builddir)/uim uim-sh && \
- $(ECHO) "(require \"manage-modules.scm\") \
- (require (string-append (getenv \"PWD\") \
- \"/installed-modules.scm\")) \
- (generate-loader-scm)" \
- | LIBUIM_VERBOSE=1 LIBUIM_VANILLA=1 LIBUIM_SCM_FILES=`(cd $(top_srcdir) && pwd)`/scm LIBUIM_PLUGIN_LIB_DIR=$(top_builddir)/uim/.libs \
- $(top_builddir)/uim/uim-sh -B >$@
+# Maybe redundant...
+loader.scm: $(SCM_FILES)
+ $(MAKE) -C $(top_builddir)/uim uim-module-manager && \
+ LIBUIM_SCM_FILES=`(cd $(top_srcdir) && pwd)`/scm LIBUIM_PLUGIN_LIB_DIR=$(top_builddir)/uim/.libs \
+ $(top_builddir)/uim/uim-module-manager \
+ --path $(top_builddir)/scm --register $(module_names)
# $(ECHO) $(ECHO_N) >$@
Modified: trunk/scm/uim-module-manager.scm
===================================================================
--- trunk/scm/uim-module-manager.scm 2005-09-07 12:14:22 UTC (rev 1450)
+++ trunk/scm/uim-module-manager.scm 2005-09-07 14:46:44 UTC (rev 1451)
@@ -32,72 +32,86 @@
(require "im.scm")
(require "lazy-load.scm")
-
-;; FIXME: This function works fine, but too hard to read.
-(define (get-new-registered-module-list modules old-module-list)
- (filter
- (lambda (x) ;; Test for valid module
- (if (require-module (symbol->string x))
- #t
- (begin (puts (string-append "Error: Module " x " is not a correct module.\n"))
- #f)))
- (remove (lambda (x) ;; Test
- (if (memq x old-module-list)
- (begin (puts (string-append "Error : Module " x " already registered\n"))
- #t)
- (begin ;(puts (string-append "Module " x " not registered\n"))
+(define add-modules-to-module-list
+ (lambda (modules current-module-list)
+ (append
+ (filter
+ (lambda (module)
+ ;; Test if the module is valid
+ (if (require-module (symbol->string module))
+ #t
+ (begin (puts (string-append "Warning: Module " module
+ " is not a correct module.\n"))
#f)))
- modules)))
+ (remove
+ (lambda (module)
+ (if (memq module current-module-list)
+ (begin (puts (string-append "Warning: Module " module
+ " is already registered\n"))
+ #t)
+ #f))
+ modules))
+ current-module-list)))
-(define (remove-unregistered-modules modules old-module-list)
- (remove (lambda (x)
- (if (memq x modules)
- (begin ;(puts (string-append "Error : Module " x " already registered\n"))
- #t)
- (begin ;(puts (string-append "Module " x " not registered\n"))
- #f)))
- old-module-list))
+(define remove-modules-from-module-list
+ (lambda (removing-modules current-module-list)
+ (remove
+ (lambda (module)
+ (if (memq module removing-modules)
+ #t
+ #f))
+ current-module-list)))
-;; This function will call when $ uim-module-manager --register
-(define (register-modules)
- (let* ((old-module-list (read-module-list))
- (new-module-list (get-new-registered-module-list (get-arguments) old-module-list)))
- (update-modules-installed-modules.scm-loader.scm (append new-module-list old-module-list))))
+;; This function is called with 'uim-module-manager --register'
+(define register-modules
+ (lambda (module-names)
+ (let* ((modules (map string->symbol (string-split module-names " ")))
+ (current-module-list (map string->symbol installed-im-module-list))
+ (revised-module-list (add-modules-to-module-list modules
+ current-module-list)))
+ (update-all-files revised-module-list))))
-;; This function will call when $ uim-module-manager --unregister
-(define (unregister-modules)
- (let* ((old-module-list (read-module-list))
- (new-module-list (remove-unregistered-modules (get-arguments) old-module-list)))
- (update-modules-installed-modules.scm-loader.scm new-module-list)))
+;; This function is called with 'uim-module-manager --unregister'
+(define unregister-modules
+ (lambda (module-names)
+ (let* ((modules (map string->symbol (string-split module-names " ")))
+ (current-module-list (map string->symbol installed-im-module-list))
+ (revised-module-list (remove-modules-from-module-list
+ modules
+ current-module-list)))
+ (update-all-files revised-module-list))))
-(define (update-modules-installed-modules.scm-loader.scm module-list)
- (update-modules module-list)
- (update-installed-modules-scm module-list)
- (update-loader-scm module-list))
+(define update-all-files
+ (lambda (module-list)
+ ;;(update-modules-file module-list)
+ (update-installed-modules-scm module-list)
+ (update-loader-scm module-list)))
-(define (update-modules module-list)
- (write-module-list #f
- (map symbol->string
- (reverse module-list))))
+(define update-modules-file
+ (lambda (module-list)
+ (write-module-list #f (map symbol->string module-list))))
-;; FIXME: Current implementation is heavy.
-(define (update-loader-scm module-list)
- (set! installed-im-module-list (map symbol->string module-list))
- (write-loader.scm (string-join "\n" (stub-im-generate-all-stub-im-list))))
+(define update-loader-scm
+ (lambda (module-list)
+ (set! installed-im-module-list (map symbol->string module-list))
+ (write-loader.scm (string-join "\n" (stub-im-generate-all-stub-im-list)))))
-(define (update-installed-modules-scm module-list)
- (set! installed-im-module-list (map symbol->string module-list))
- (try-require "custom.scm")
- (set! enabled-im-list
- (map custom-choice-rec-sym (custom-installed-im-list)))
- (write-installed-modules.scm
- (string-append
- "(define installed-im-module-list "
- (custom-list-as-literal installed-im-module-list)
- ")\n"
- (custom-definition-as-literal 'enabled-im-list)
- "\n")))
+(define update-installed-modules-scm
+ (lambda (module-list)
+ (set! installed-im-module-list (map symbol->string module-list))
+ (try-require "custom.scm")
+ (set! enabled-im-list
+ (map custom-choice-rec-sym (custom-installed-im-list)))
+ (write-installed-modules.scm
+ (string-append
+ ";; The described order of input methods affects which IM is preferred\n"
+ ";; at the default IM selection process for each locale. i.e. list\n"
+ ";; preferable IM first for each language\n"
+ "(define installed-im-module-list "
+ (custom-list-as-literal installed-im-module-list)
+ ")\n"
+ (custom-definition-as-literal 'enabled-im-list)
+ "\n"))))
-;(generate-installed-modules-scm))
(prealloc-heaps-for-heavy-job)
Modified: trunk/uim/uim-module-manager.c
===================================================================
--- trunk/uim/uim-module-manager.c 2005-09-07 12:14:22 UTC (rev 1450)
+++ trunk/uim/uim-module-manager.c 2005-09-07 14:46:44 UTC (rev 1451)
@@ -40,23 +40,27 @@
#include "uim.h"
#include "uim-scm.h"
-#include "uim-compat-scm.h"
+#include "context.h"
-static char *path;
-
#define MODULE_LIST_FILENAME UIM_DATADIR"/modules"
#define LOADER_SCM_FILENAME UIM_DATADIR"/loader.scm"
#define INSTALLED_MODULES_SCM_FILENAME UIM_DATADIR"/installed-modules.scm"
-static uim_lisp modulenames; /* FIXME: Provide a way to pass a list as an argument. */
+static char *path;
+enum Action {
+ Register,
+ UnRegister,
+ None
+};
+
/* Utility function */
static char *
concat(const char *a, const char *b)
{
int len;
char *dest;
- if(!a || !b)
+ if (!a || !b)
return NULL;
len = strlen(a) + strlen(b) + 1;
dest = malloc(len);
@@ -65,23 +69,30 @@
return dest;
}
-/* Utility function */
- /* FIXME: Provide a way to pass a list as an argument. */
-static uim_lisp
-get_arguments(void)
+static char *
+append_module_names(char *modules, const char *new_module)
{
- return modulenames;
+ if (!modules)
+ return strdup(new_module);
+
+ modules = realloc(modules, strlen(modules) + strlen(new_module) + 2);
+ if (modules) {
+ strcat(modules, " ");
+ strcat(modules, new_module);
+ }
+ return modules;
}
static void
print_usage(void)
{
printf("Usage:\n");
- printf(" uim-module-manager [OPTION] modulenames...\n\n");
+ printf(" uim-module-manager [options]\n\n");
printf("Options:\n");
- printf(" --register\n");
- printf(" --unregister\n");
- printf(" --path path to modules/loader.scm/installed-modules.scm\n");
+ printf(" --register <modules> Register the modules\n");
+ printf(" --unregister <modules> Unregister the modules\n");
+ printf(" --path <path> Target path where installed-modules.scm,\n");
+ printf(" loader.scm, and modules to be installed\n");
printf(" ** --path option may be removed in the future. **\n\n");
printf("Example:\n");
printf(" uim-module-manager --register anthy skk\n");
@@ -95,7 +106,7 @@
char buf[1024];
uim_lisp module_list = uim_scm_null_list();
- if(path) {
+ if (path) {
char *p = concat(path, "/modules");
fp = fopen(p, "r");
free(p);
@@ -103,18 +114,18 @@
fp = fopen(MODULE_LIST_FILENAME, "r");
}
- if(!fp) {
- perror("Failed to read module list.");
+ if (!fp) {
+ /* fprintf(stderr, "Warning: failed to read module list.\n"); */
return uim_scm_f();
}
- while (fgets (buf, sizeof(buf), fp) != NULL) {
- if(buf[0] == '#' || buf[0] == '\n') {
+ while (fgets(buf, sizeof(buf), fp) != NULL) {
+ if (buf[0] == '#' || buf[0] == '\n') {
continue; /* comment line or blank line */
}
- else if(buf[strlen(buf)-1] == '\n') {
- buf[strlen(buf)-1] = '\0'; /* Clear \n. */
+ else if (buf[strlen(buf) - 1] == '\n') {
+ buf[strlen(buf) - 1] = '\0'; /* Clear \n. */
}
- module_list = uim_scm_cons(uim_scm_intern_c_str(buf), module_list);
+ module_list = uim_scm_cons(uim_scm_make_symbol(buf), module_list);
}
fclose(fp);
return module_list;
@@ -124,7 +135,8 @@
write_module_list(uim_lisp new_module, uim_lisp module_list)
{
FILE *fp;
- if(path) {
+
+ if (path) {
char *p = concat(path, "/modules");
fp = fopen(p, "w");
free(p);
@@ -132,30 +144,28 @@
fp = fopen(MODULE_LIST_FILENAME, "w");
}
- if(!fp) {
+ if (!fp) {
perror("Failed to write module list");
return uim_scm_f();
}
fputs("# This is an automatically generated file. DO NOT EDIT.\n\n", fp);
- if(uim_scm_stringp(new_module) == UIM_TRUE) {
+ if (uim_scm_stringp(new_module) == UIM_TRUE) {
fputs(uim_scm_refer_c_str(new_module), fp);
- fputs("\n",fp);
+ fputs("\n", fp);
}
- if(uim_scm_consp(module_list) == UIM_TRUE) {
-
- while(1) {
+ if (uim_scm_consp(module_list) == UIM_TRUE) {
+ while (1) {
uim_lisp module_name = uim_scm_car(module_list);
fputs(uim_scm_refer_c_str(module_name), fp);
fputs("\n",fp);
module_list = uim_scm_cdr(module_list);
- if(module_list == uim_scm_null_list()) {
+ if (module_list == uim_scm_null_list()) {
break;
}
}
-
}
fclose(fp);
@@ -166,7 +176,8 @@
write_loader_scm(uim_lisp str)
{
FILE *fp;
- if(path) {
+
+ if (path) {
char *p = concat(path, "/loader.scm");
fp = fopen(p, "w");
free(p);
@@ -174,14 +185,14 @@
fp = fopen(LOADER_SCM_FILENAME, "w");
}
- if(!fp) {
+ if (!fp) {
perror("Failed to open loader.scm");
return uim_scm_f();
}
fputs(";; This is an automatically generated file. DO NOT EDIT.\n\n", fp);
+ fputs(uim_scm_refer_c_str(str), fp);
- fputs(uim_scm_refer_c_str(str), fp);
fclose(fp);
return uim_scm_t();
}
@@ -190,7 +201,8 @@
write_installed_modules_scm(uim_lisp str)
{
FILE *fp;
- if(path) {
+
+ if (path) {
char *p = concat(path, "/installed-modules.scm");
fp = fopen(p, "w");
free(p);
@@ -198,14 +210,14 @@
fp = fopen(INSTALLED_MODULES_SCM_FILENAME, "w");
}
- if(!fp) {
+ if (!fp) {
perror("Failed to open installed-modules.scm");
return uim_scm_f();
}
fputs(";; This is an automatically generated file. DO NOT EDIT.\n\n", fp);
+ fputs(uim_scm_refer_c_str(str), fp);
- fputs(uim_scm_refer_c_str(str), fp);
fclose(fp);
return uim_scm_t();
}
@@ -213,76 +225,70 @@
int
main(int argc, char *argv[]) {
int i;
- int registerp = 0;
- uim_lisp form;
+ int action = None;
+ char *module_names = NULL;
- if(argc <= 2) {
+ if (argc <= 2) {
print_usage();
exit(EXIT_FAILURE);
}
/* FIXME: To generate loader.scm, we need this setenv for now.
- But it's a dirty hack, not appropriate. I guess we need entirely new module system. */
+ But it's a dirty hack, not appropriate. I guess we need entirely
+ new module system. */
setenv("LIBUIM_VANILLA", "1", 1);
uim_init();
uim_scm_set_verbose_level(1);
- modulenames = uim_scm_null_list();
- for(i=0; i<argc; i++) {
- if(strcmp(argv[i], "--register") == 0) {
- if(registerp == 2) {
- printf("Regqistering and unregistering couldn't used at the same time.\n\n");
+ for (i = 0; i < argc; i++) {
+ if (strcmp(argv[i], "--register") == 0) {
+ if (action == UnRegister) {
+ fprintf(stderr, "Registering and unregistering cannot be used at the same time.\n\n");
exit(EXIT_FAILURE);
}
- registerp = 1; i++;
- while(argv[i] && strncmp(argv[i], "--", 2)) {
- modulenames = uim_scm_cons(uim_scm_intern_c_str(argv[i]), modulenames);
+ action = Register; i++;
+ while (argv[i] && strncmp(argv[i], "--", 2)) {
+ module_names = append_module_names(module_names, argv[i]);
i++;
}
i--;
- } else if(strcmp(argv[i], "--unregister") == 0) {
- if(registerp == 1) {
- printf("Registering and unregistering couldn't used at the same time.\n\n");
+ } else if (strcmp(argv[i], "--unregister") == 0) {
+ if (action == Register) {
+ fprintf(stderr, "Registering and unregistering cannot be used at the same time.\n\n");
exit(EXIT_FAILURE);
}
- registerp = 2; i++;
- while(argv[i] && strncmp(argv[i], "--", 2)) {
- modulenames = uim_scm_cons(uim_scm_intern_c_str(argv[i]), modulenames);
+ action = UnRegister; i++;
+ while (argv[i] && strncmp(argv[i], "--", 2)) {
+ module_names = append_module_names(module_names, argv[i]);
i++;
}
i--;
- } else if(strcmp(argv[i], "--path") == 0) {
- if(argv[i+1]) {
- path = argv[i+1];
+ } else if (strcmp(argv[i], "--path") == 0) {
+ if (argv[i + 1]) {
+ path = argv[i + 1];
}
}
}
- if(!argv[2]) {
+ if (action == None || !module_names) {
print_usage();
exit(EXIT_FAILURE);
}
uim_scm_init_subr_0("read-module-list", read_module_list);
uim_scm_init_subr_2("write-module-list", write_module_list);
-
- uim_scm_init_subr_0("get-arguments", get_arguments);
-
uim_scm_init_subr_1("write-loader.scm", write_loader_scm);
uim_scm_init_subr_1("write-installed-modules.scm", write_installed_modules_scm);
- uim_scm_require_file("uim-module-manager.scm");
+ if (!uim_scm_require_file("uim-module-manager.scm"))
+ exit(1);
- if(registerp == 1) {
- form = uim_scm_list1(uim_scm_intern_c_str("register-modules"));
- }
- if(registerp == 2) {
- form = uim_scm_list1(uim_scm_intern_c_str("unregister-modules"));
- }
+ UIM_EVAL_FSTRING2(NULL, "(%s \"%s\")",
+ action == Register ? "register-modules"
+ : "unregister-modules",
+ module_names);
- uim_scm_eval(form);
-
uim_quit();
return 0;
More information about the uim-commit
mailing list