[uim-commit] r943 - in trunk: scm uim
tkng at freedesktop.org
tkng at freedesktop.org
Wed Jul 6 19:52:41 PDT 2005
Author: tkng
Date: 2005-07-06 19:51:48 -0700 (Wed, 06 Jul 2005)
New Revision: 943
Modified:
trunk/scm/uim-module-manager.scm
trunk/uim/uim-module-manager.c
Log:
* uim/uim-module-manager.c:
-(get_arguments): New function to get argument passed to the program.
This function is need because apply/funcall is not exported.
-(main): Changed argument parsing code completely. Now plural module
chould be register/unregister at once. File path customizing feature
is also added.
* scm/uim-module-manager.scm:
-(register-modules, unregister-modules, get-new-registered-module-list,
remove-unregistered-modules,update-modules-installed-modules.scm-loader.scm,
update-modules): New procedure.
-(update-installed-modules&loader): Removed.
Modified: trunk/scm/uim-module-manager.scm
===================================================================
--- trunk/scm/uim-module-manager.scm 2005-07-06 15:04:41 UTC (rev 942)
+++ trunk/scm/uim-module-manager.scm 2005-07-07 02:51:48 UTC (rev 943)
@@ -33,16 +33,60 @@
(require "lazy-load.scm")
;; This function will call when $ uim-module-manager --register
-(define (register-module module-name)
+;; TODO: Refactoring
+(define (register-module module-names)
(let ((module-list (read-module-list)))
- (if (memq module-name module-list)
- (puts (string-append "Error : Module " module-name " already registered\n"))
- (if (register-module-to-file module-name module-list)
- (begin
- (puts (string-append "Module " module-name " registered.\n"))
- (update-installed-modules&loader (cons module-name module-list)))
- (puts (string-append "Error: Module " module-name " does not registered.\n"))))))
+ (write-modules
+ (filter (lambda (x)
+ (if (try-require x)
+ #t
+ (begin (puts (string-append "Error: Module " new-module " is not a correct module.\n"))
+ #f)))
+ (remove (lambda (x)
+ (if (memq x module-list)
+ (begin (puts (string-append "Error : Module " module-name " already registered\n"))
+ #t)
+ #f))
+ module-list))
+ module-list)
+ (update-installed-modules&loader (cons module-name module-list)))
+ (puts (string-append "Error: Module " module-name " does not registered.\n")))
+;; FIXME: This function works fine, but too hard to read.
+(define (get-new-registered-module-list modules old-module-list)
+ (filter
+ (lambda (x)
+ (if (require-module (symbol->string x))
+ #t
+ (begin (puts (string-append "Error: Module " x " is not a correct module.\n"))
+ #f)))
+ (remove (lambda (x)
+ (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"))
+ #f)))
+ modules)))
+
+(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 (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))))
+
+(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 will call when $ uim-module-manager --unregister
(define (unregister-module module-name)
(let ((module-list (read-module-list)))
@@ -57,7 +101,6 @@
(puts (string-append "Module " module-name " unregistered.\n")))
(puts (string-append "Error to remove " module-name ". No such module.\n")))))
-
(define (register-module-to-file new-module module-list)
(if (require-module (symbol->string new-module))
(begin
@@ -69,11 +112,16 @@
#f)))
(puts (string-append "Error: Module " new-module " is not a correct module.\n"))))
-
-(define (update-installed-modules&loader 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-modules module-list)
+ (write-module-list #f
+ (map symbol->string
+ (reverse module-list))))
+
;; FIXME: Current implementation is heavy.
(define (update-loader-scm module-list)
(set! installed-im-module-list (map symbol->string module-list))
Modified: trunk/uim/uim-module-manager.c
===================================================================
--- trunk/uim/uim-module-manager.c 2005-07-06 15:04:41 UTC (rev 942)
+++ trunk/uim/uim-module-manager.c 2005-07-07 02:51:48 UTC (rev 943)
@@ -48,6 +48,8 @@
#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. */
+
/* Utility function */
static char *
concat(const char *a, const char *b)
@@ -63,6 +65,13 @@
return dest;
}
+ /* FIXME: Provide a way to pass a list as an argument. */
+static uim_lisp
+get_arguments(void)
+{
+ return modulenames;
+}
+
static void
print_usage(void)
{
@@ -193,51 +202,73 @@
int
main(int argc, char *argv[]) {
- int registerp;
+ int i;
+ int registerp = 0;
uim_lisp form;
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. */
+ setenv("LIBUIM_VANILLA", "1", 1);
+
+ uim_init();
+ uim_scm_set_verbose_level(1);
+ modulenames = uim_scm_null_list();
- if(strcmp(argv[1], "--register") == 0) {
- registerp = 1;
- } else if(strcmp(argv[1], "--unregister") == 0) {
- registerp = 2;
- } else {
- print_usage();
- exit(EXIT_FAILURE);
+ 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");
+ 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);
+ 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");
+ 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);
+ i++;
+ }
+ i--;
+ } else if(strcmp(argv[i], "--path") == 0) {
+ if(argv[i+1]) {
+ path = argv[i+1];
+ }
+ }
}
-
+
if(!argv[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. */
- setenv("LIBUIM_VANILLA", "1", 1);
-
- uim_init();
-
- uim_scm_set_verbose_level(1);
-
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(registerp == 1) {
- form = uim_scm_list2(uim_scm_intern_c_str("register-module"),
- uim_scm_qintern_c_str(argv[2]));
+ form = uim_scm_list1(uim_scm_intern_c_str("register-modules"));
}
if(registerp == 2) {
- form = uim_scm_list2(uim_scm_intern_c_str("unregister-module"),
- uim_scm_qintern_c_str(argv[2]));
+ form = uim_scm_list1(uim_scm_intern_c_str("unregister-modules"));
}
uim_scm_eval(form);
More information about the uim-commit
mailing list