[uim-commit] r1457 - in branches/0.4: scm uim

ekato at freedesktop.org ekato at freedesktop.org
Thu Sep 8 21:50:38 PDT 2005


Author: ekato
Date: 2005-09-08 21:50:36 -0700 (Thu, 08 Sep 2005)
New Revision: 1457

Modified:
   branches/0.4/scm/Makefile.am
   branches/0.4/scm/im-custom.scm
   branches/0.4/scm/im.scm
   branches/0.4/scm/uim-module-manager.scm
   branches/0.4/uim/uim-module-manager.c
Log:
* Fix bug #4363 ported from r1456 trunk.
* scm/im.scm
* scm/im-custom.scm
* scm/uim-module-manager.scm
* scm/Makefile.am
* uim/uim-module-manager.c


Modified: branches/0.4/scm/Makefile.am
===================================================================
--- branches/0.4/scm/Makefile.am	2005-09-08 10:30:58 UTC (rev 1456)
+++ branches/0.4/scm/Makefile.am	2005-09-09 04:50:36 UTC (rev 1457)
@@ -35,52 +35,39 @@
 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 >$@
+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: branches/0.4/scm/im-custom.scm
===================================================================
--- branches/0.4/scm/im-custom.scm	2005-09-08 10:30:58 UTC (rev 1456)
+++ branches/0.4/scm/im-custom.scm	2005-09-09 04:50:36 UTC (rev 1457)
@@ -209,7 +209,16 @@
       (custom-im-list-as-choice-rec (reverse
 				     (alist-delete 'direct im-list eq?))))))
 
-(define-custom 'enabled-im-list '(direct)
+(define usable-im-list
+  (lambda ()
+    (let ((imlist (filter
+		    (lambda (name)
+	              (memq name system-available-im-list)) enabled-im-list)))
+	 (if (not (null? imlist))
+	     imlist
+	     '(direct)))))
+
+(define-custom 'enabled-im-list (usable-im-list)
   '(global im-deployment)
   (cons
    'ordered-list

Modified: branches/0.4/scm/im.scm
===================================================================
--- branches/0.4/scm/im.scm	2005-09-08 10:30:58 UTC (rev 1456)
+++ branches/0.4/scm/im.scm	2005-09-09 04:50:36 UTC (rev 1457)
@@ -62,6 +62,7 @@
 ;; initialized. This limitation may be removed after uim 0.4.6.
 ;;   -- YamaKen 2005-01-25
 (define enabled-im-list ())
+(define system-available-im-list ())
 
 (define-record 'im
   (list

Modified: branches/0.4/scm/uim-module-manager.scm
===================================================================
--- branches/0.4/scm/uim-module-manager.scm	2005-09-08 10:30:58 UTC (rev 1456)
+++ branches/0.4/scm/uim-module-manager.scm	2005-09-09 04:50:36 UTC (rev 1457)
@@ -32,72 +32,91 @@
 (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 unregister-all-modules
+  (lambda (dummy)
+    (update-all-files '())))
 
-(define (update-modules module-list)
-  (write-module-list #f
-		     (map symbol->string
-			  (reverse 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)))
 
-;; 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-modules-file
+  (lambda (module-list)
+    (write-module-list #f (map symbol->string module-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-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)))))
 
-;(generate-installed-modules-scm))
+(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"
+      "(define system-available-im-list enabled-im-list)\n"))))
 
+
 (prealloc-heaps-for-heavy-job)

Modified: branches/0.4/uim/uim-module-manager.c
===================================================================
--- branches/0.4/uim/uim-module-manager.c	2005-09-08 10:30:58 UTC (rev 1456)
+++ branches/0.4/uim/uim-module-manager.c	2005-09-09 04:50:36 UTC (rev 1457)
@@ -40,23 +40,35 @@
 
 #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,
+  UnRegisterAll,
+  None
+};
+
+char *action_command[] = {
+  "register-modules",
+  "unregister-modules",
+  "unregister-all-modules",
+  NULL
+};
+
 /* 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,27 +77,37 @@
   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("    **  --path option may be removed in the future. **\n\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("                         and loader.scm to be installed\n");
+  printf("  --unregister-all       Unregister all modules\n\n");
   printf("Example:\n");
   printf("  uim-module-manager --register anthy skk\n");
-  printf("  uim-module-manager --register prime --path /usr/local/share/uim\n\n");
+  printf("  uim-module-manager --register prime --path /usr/local/share/uim\n");
+  printf("  uim-module-manager --register personal-module --path ~/.uim.d/plugin\n\n");
+  printf("Note:\n");
+  printf("  Registeration and unregistration cannot be done simultaneously.\n\n");
 }
 
 static uim_lisp
@@ -95,7 +117,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 +125,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 +146,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 +155,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 +187,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 +196,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 +212,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 +221,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,75 +236,78 @@
 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 <= 1) {
     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");
-	exit(EXIT_FAILURE);
+  for (i = 0; i < argc; i++) {
+    if (strcmp(argv[i], "--register") == 0) {
+      if (action != None) {
+	action = None;
+	break;
       }
-      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");
-	exit(EXIT_FAILURE);
+    } else if (strcmp(argv[i], "--unregister") == 0) {
+      if (action != None) {
+	action = None;
+	break;
       }
-      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];
       }
+    } else if (strcmp(argv[i], "--unregister-all") == 0) {
+      if (action != None) {
+	action = None;
+	break;
+      }
+      action = UnRegisterAll;
     }
   }
   
-  if(!argv[2]) {
+  if (action == None || (action != UnRegisterAll && !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"));
-  }
+  /* for unregister-all */
+  if (!module_names)
+    module_names = "";
 
-  uim_scm_eval(form);
+  UIM_EVAL_FSTRING2(NULL, "(%s \"%s\")",
+		    action_command[action],
+		    module_names);
 
   uim_quit();
 



More information about the uim-commit mailing list