• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

A multilingual input method framework


Commit MetaInfo

Revision0ebcd8ac4d45753f81a018ecb537bef999f79a4e (tree)
Time2005-09-09 13:50:36
Authorekato <ekato@ff9a...>
Commiterekato

Log Message

* 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

Change Summary

Incremental Difference

--- a/scm/Makefile.am
+++ b/scm/Makefile.am
@@ -35,52 +35,39 @@ SCM_FILES += hk.scm
3535 endif
3636
3737 module_names = "pyload"
38-
3938 if ANTHY
4039 module_names += "anthy"
4140 endif
42-
4341 if CANNA
4442 module_names += "canna"
4543 endif
46-
4744 if PRIME
4845 module_names += "prime"
4946 endif
50-
5147 if SKK
5248 module_names += "skk"
5349 endif
54-
5550 module_names += "tcode" "tutcode" "hangul" "viqr" "ipa-x-sampa" "latin"
56-
5751 if M17NLIB
5852 module_names += "m17nlib"
5953 endif
60-
6154 if SCIM
6255 module_names += "scim"
6356 endif
6457
6558
66-
67-# TODO: resolve dependency to $(top_builddir)/uim/uim-sh in proper way
59+# TODO: resolve dependency to $(top_builddir)/uim/uim-module-manager
60+# in a proper way
6861 installed-modules.scm: $(SCM_FILES)
69- $(MAKE) -C $(top_builddir)/uim uim-sh && \
70- $(ECHO) "(define installed-im-module-list '(" '$(module_names)' ")) \
71- (require \"manage-modules.scm\") \
72- (generate-installed-modules-scm)" \
73- | LIBUIM_VERBOSE=1 LIBUIM_VANILLA=1 LIBUIM_SCM_FILES=`(cd $(top_srcdir) && pwd)`/scm LIBUIM_PLUGIN_LIB_DIR=$(top_builddir)/uim/.libs \
74- $(top_builddir)/uim/uim-sh -B >$@
62+ $(MAKE) -C $(top_builddir)/uim uim-module-manager && \
63+ LIBUIM_SCM_FILES=`(cd $(top_srcdir) && pwd)`/scm LIBUIM_PLUGIN_LIB_DIR=$(top_builddir)/uim/.libs \
64+ $(top_builddir)/uim/uim-module-manager \
65+ --path $(top_builddir)/scm --register $(module_names)
7566
76-# TODO: resolve dependency to $(top_builddir)/uim/uim-sh in proper way
77-loader.scm: installed-modules.scm
78- $(MAKE) -C $(top_builddir)/uim uim-sh && \
79- $(ECHO) "(require \"manage-modules.scm\") \
80- (require (string-append (getenv \"PWD\") \
81- \"/installed-modules.scm\")) \
82- (generate-loader-scm)" \
83- | LIBUIM_VERBOSE=1 LIBUIM_VANILLA=1 LIBUIM_SCM_FILES=`(cd $(top_srcdir) && pwd)`/scm LIBUIM_PLUGIN_LIB_DIR=$(top_builddir)/uim/.libs \
84- $(top_builddir)/uim/uim-sh -B >$@
67+loader.scm: $(SCM_FILES)
68+ $(MAKE) -C $(top_builddir)/uim uim-module-manager && \
69+ LIBUIM_SCM_FILES=`(cd $(top_srcdir) && pwd)`/scm LIBUIM_PLUGIN_LIB_DIR=$(top_builddir)/uim/.libs \
70+ $(top_builddir)/uim/uim-module-manager \
71+ --path $(top_builddir)/scm --register $(module_names)
8572
8673 # $(ECHO) $(ECHO_N) >$@
--- a/scm/im-custom.scm
+++ b/scm/im-custom.scm
@@ -209,7 +209,16 @@
209209 (custom-im-list-as-choice-rec (reverse
210210 (alist-delete 'direct im-list eq?))))))
211211
212-(define-custom 'enabled-im-list '(direct)
212+(define usable-im-list
213+ (lambda ()
214+ (let ((imlist (filter
215+ (lambda (name)
216+ (memq name system-available-im-list)) enabled-im-list)))
217+ (if (not (null? imlist))
218+ imlist
219+ '(direct)))))
220+
221+(define-custom 'enabled-im-list (usable-im-list)
213222 '(global im-deployment)
214223 (cons
215224 'ordered-list
--- a/scm/im.scm
+++ b/scm/im.scm
@@ -62,6 +62,7 @@
6262 ;; initialized. This limitation may be removed after uim 0.4.6.
6363 ;; -- YamaKen 2005-01-25
6464 (define enabled-im-list ())
65+(define system-available-im-list ())
6566
6667 (define-record 'im
6768 (list
--- a/scm/uim-module-manager.scm
+++ b/scm/uim-module-manager.scm
@@ -32,72 +32,91 @@
3232 (require "im.scm")
3333 (require "lazy-load.scm")
3434
35-
36-;; FIXME: This function works fine, but too hard to read.
37-(define (get-new-registered-module-list modules old-module-list)
38- (filter
39- (lambda (x) ;; Test for valid module
40- (if (require-module (symbol->string x))
41- #t
42- (begin (puts (string-append "Error: Module " x " is not a correct module.\n"))
43- #f)))
44- (remove (lambda (x) ;; Test
45- (if (memq x old-module-list)
46- (begin (puts (string-append "Error : Module " x " already registered\n"))
47- #t)
48- (begin ;(puts (string-append "Module " x " not registered\n"))
35+(define add-modules-to-module-list
36+ (lambda (modules current-module-list)
37+ (append
38+ (filter
39+ (lambda (module)
40+ ;; Test if the module is valid
41+ (if (require-module (symbol->string module))
42+ #t
43+ (begin (puts (string-append "Warning: Module " module
44+ " is not a correct module.\n"))
4945 #f)))
50- modules)))
46+ (remove
47+ (lambda (module)
48+ (if (memq module current-module-list)
49+ (begin (puts (string-append "Warning: Module " module
50+ " is already registered\n"))
51+ #t)
52+ #f))
53+ modules))
54+ current-module-list)))
55+
56+(define remove-modules-from-module-list
57+ (lambda (removing-modules current-module-list)
58+ (remove
59+ (lambda (module)
60+ (if (memq module removing-modules)
61+ #t
62+ #f))
63+ current-module-list)))
5164
52-(define (remove-unregistered-modules modules old-module-list)
53- (remove (lambda (x)
54- (if (memq x modules)
55- (begin ;(puts (string-append "Error : Module " x " already registered\n"))
56- #t)
57- (begin ;(puts (string-append "Module " x " not registered\n"))
58- #f)))
59- old-module-list))
65+;; This function is called with 'uim-module-manager --register'
66+(define register-modules
67+ (lambda (module-names)
68+ (let* ((modules (map string->symbol (string-split module-names " ")))
69+ (current-module-list (map string->symbol installed-im-module-list))
70+ (revised-module-list (add-modules-to-module-list modules
71+ current-module-list)))
72+ (update-all-files revised-module-list))))
6073
61-;; This function will call when $ uim-module-manager --register
62-(define (register-modules)
63- (let* ((old-module-list (read-module-list))
64- (new-module-list (get-new-registered-module-list (get-arguments) old-module-list)))
65- (update-modules-installed-modules.scm-loader.scm (append new-module-list old-module-list))))
74+;; This function is called with 'uim-module-manager --unregister'
75+(define unregister-modules
76+ (lambda (module-names)
77+ (let* ((modules (map string->symbol (string-split module-names " ")))
78+ (current-module-list (map string->symbol installed-im-module-list))
79+ (revised-module-list (remove-modules-from-module-list
80+ modules
81+ current-module-list)))
82+ (update-all-files revised-module-list))))
6683
67-;; This function will call when $ uim-module-manager --unregister
68-(define (unregister-modules)
69- (let* ((old-module-list (read-module-list))
70- (new-module-list (remove-unregistered-modules (get-arguments) old-module-list)))
71- (update-modules-installed-modules.scm-loader.scm new-module-list)))
84+(define unregister-all-modules
85+ (lambda (dummy)
86+ (update-all-files '())))
7287
73-(define (update-modules-installed-modules.scm-loader.scm module-list)
74- (update-modules module-list)
75- (update-installed-modules-scm module-list)
76- (update-loader-scm module-list))
88+(define update-all-files
89+ (lambda (module-list)
90+ ;;(update-modules-file module-list)
91+ (update-installed-modules-scm module-list)
92+ (update-loader-scm module-list)))
7793
78-(define (update-modules module-list)
79- (write-module-list #f
80- (map symbol->string
81- (reverse module-list))))
94+(define update-modules-file
95+ (lambda (module-list)
96+ (write-module-list #f (map symbol->string module-list))))
8297
83-;; FIXME: Current implementation is heavy.
84-(define (update-loader-scm module-list)
85- (set! installed-im-module-list (map symbol->string module-list))
86- (write-loader.scm (string-join "\n" (stub-im-generate-all-stub-im-list))))
98+(define update-loader-scm
99+ (lambda (module-list)
100+ (set! installed-im-module-list (map symbol->string module-list))
101+ (write-loader.scm (string-join "\n" (stub-im-generate-all-stub-im-list)))))
87102
88-(define (update-installed-modules-scm module-list)
89- (set! installed-im-module-list (map symbol->string module-list))
90- (try-require "custom.scm")
91- (set! enabled-im-list
92- (map custom-choice-rec-sym (custom-installed-im-list)))
93- (write-installed-modules.scm
94- (string-append
95- "(define installed-im-module-list "
96- (custom-list-as-literal installed-im-module-list)
97- ")\n"
98- (custom-definition-as-literal 'enabled-im-list)
99- "\n")))
103+(define update-installed-modules-scm
104+ (lambda (module-list)
105+ (set! installed-im-module-list (map symbol->string module-list))
106+ (try-require "custom.scm")
107+ (set! enabled-im-list
108+ (map custom-choice-rec-sym (custom-installed-im-list)))
109+ (write-installed-modules.scm
110+ (string-append
111+ ";; The described order of input methods affects which IM is preferred\n"
112+ ";; at the default IM selection process for each locale. i.e. list\n"
113+ ";; preferable IM first for each language\n"
114+ "(define installed-im-module-list "
115+ (custom-list-as-literal installed-im-module-list)
116+ ")\n"
117+ (custom-definition-as-literal 'enabled-im-list)
118+ "\n"
119+ "(define system-available-im-list enabled-im-list)\n"))))
100120
101-;(generate-installed-modules-scm))
102121
103122 (prealloc-heaps-for-heavy-job)
--- a/uim/uim-module-manager.c
+++ b/uim/uim-module-manager.c
@@ -40,15 +40,27 @@
4040
4141 #include "uim.h"
4242 #include "uim-scm.h"
43-#include "uim-compat-scm.h"
44-
45-static char *path;
43+#include "context.h"
4644
4745 #define MODULE_LIST_FILENAME UIM_DATADIR"/modules"
4846 #define LOADER_SCM_FILENAME UIM_DATADIR"/loader.scm"
4947 #define INSTALLED_MODULES_SCM_FILENAME UIM_DATADIR"/installed-modules.scm"
5048
51-static uim_lisp modulenames; /* FIXME: Provide a way to pass a list as an argument. */
49+static char *path;
50+
51+enum Action {
52+ Register,
53+ UnRegister,
54+ UnRegisterAll,
55+ None
56+};
57+
58+char *action_command[] = {
59+ "register-modules",
60+ "unregister-modules",
61+ "unregister-all-modules",
62+ NULL
63+};
5264
5365 /* Utility function */
5466 static char *
@@ -56,7 +68,7 @@ concat(const char *a, const char *b)
5668 {
5769 int len;
5870 char *dest;
59- if(!a || !b)
71+ if (!a || !b)
6072 return NULL;
6173 len = strlen(a) + strlen(b) + 1;
6274 dest = malloc(len);
@@ -65,27 +77,37 @@ concat(const char *a, const char *b)
6577 return dest;
6678 }
6779
68-/* Utility function */
69- /* FIXME: Provide a way to pass a list as an argument. */
70-static uim_lisp
71-get_arguments(void)
80+static char *
81+append_module_names(char *modules, const char *new_module)
7282 {
73- return modulenames;
83+ if (!modules)
84+ return strdup(new_module);
85+
86+ modules = realloc(modules, strlen(modules) + strlen(new_module) + 2);
87+ if (modules) {
88+ strcat(modules, " ");
89+ strcat(modules, new_module);
90+ }
91+ return modules;
7492 }
7593
7694 static void
7795 print_usage(void)
7896 {
7997 printf("Usage:\n");
80- printf(" uim-module-manager [OPTION] modulenames...\n\n");
98+ printf(" uim-module-manager [options]\n\n");
8199 printf("Options:\n");
82- printf(" --register\n");
83- printf(" --unregister\n");
84- printf(" --path path to modules/loader.scm/installed-modules.scm\n");
85- printf(" ** --path option may be removed in the future. **\n\n");
100+ printf(" --register <modules> Register the modules\n");
101+ printf(" --unregister <modules> Unregister the modules\n");
102+ printf(" --path <path> Target path where installed-modules.scm\n");
103+ printf(" and loader.scm to be installed\n");
104+ printf(" --unregister-all Unregister all modules\n\n");
86105 printf("Example:\n");
87106 printf(" uim-module-manager --register anthy skk\n");
88- printf(" uim-module-manager --register prime --path /usr/local/share/uim\n\n");
107+ printf(" uim-module-manager --register prime --path /usr/local/share/uim\n");
108+ printf(" uim-module-manager --register personal-module --path ~/.uim.d/plugin\n\n");
109+ printf("Note:\n");
110+ printf(" Registeration and unregistration cannot be done simultaneously.\n\n");
89111 }
90112
91113 static uim_lisp
@@ -95,7 +117,7 @@ read_module_list(void)
95117 char buf[1024];
96118 uim_lisp module_list = uim_scm_null_list();
97119
98- if(path) {
120+ if (path) {
99121 char *p = concat(path, "/modules");
100122 fp = fopen(p, "r");
101123 free(p);
@@ -103,18 +125,18 @@ read_module_list(void)
103125 fp = fopen(MODULE_LIST_FILENAME, "r");
104126 }
105127
106- if(!fp) {
107- perror("Failed to read module list.");
128+ if (!fp) {
129+ /* fprintf(stderr, "Warning: failed to read module list.\n"); */
108130 return uim_scm_f();
109131 }
110- while (fgets (buf, sizeof(buf), fp) != NULL) {
111- if(buf[0] == '#' || buf[0] == '\n') {
132+ while (fgets(buf, sizeof(buf), fp) != NULL) {
133+ if (buf[0] == '#' || buf[0] == '\n') {
112134 continue; /* comment line or blank line */
113135 }
114- else if(buf[strlen(buf)-1] == '\n') {
115- buf[strlen(buf)-1] = '\0'; /* Clear \n. */
136+ else if (buf[strlen(buf) - 1] == '\n') {
137+ buf[strlen(buf) - 1] = '\0'; /* Clear \n. */
116138 }
117- module_list = uim_scm_cons(uim_scm_intern_c_str(buf), module_list);
139+ module_list = uim_scm_cons(uim_scm_make_symbol(buf), module_list);
118140 }
119141 fclose(fp);
120142 return module_list;
@@ -124,7 +146,8 @@ static uim_lisp
124146 write_module_list(uim_lisp new_module, uim_lisp module_list)
125147 {
126148 FILE *fp;
127- if(path) {
149+
150+ if (path) {
128151 char *p = concat(path, "/modules");
129152 fp = fopen(p, "w");
130153 free(p);
@@ -132,30 +155,28 @@ write_module_list(uim_lisp new_module, uim_lisp module_list)
132155 fp = fopen(MODULE_LIST_FILENAME, "w");
133156 }
134157
135- if(!fp) {
158+ if (!fp) {
136159 perror("Failed to write module list");
137160 return uim_scm_f();
138161 }
139162
140163 fputs("# This is an automatically generated file. DO NOT EDIT.\n\n", fp);
141164
142- if(uim_scm_stringp(new_module) == UIM_TRUE) {
165+ if (uim_scm_stringp(new_module) == UIM_TRUE) {
143166 fputs(uim_scm_refer_c_str(new_module), fp);
144- fputs("\n",fp);
167+ fputs("\n", fp);
145168 }
146169
147- if(uim_scm_consp(module_list) == UIM_TRUE) {
148-
149- while(1) {
170+ if (uim_scm_consp(module_list) == UIM_TRUE) {
171+ while (1) {
150172 uim_lisp module_name = uim_scm_car(module_list);
151173 fputs(uim_scm_refer_c_str(module_name), fp);
152174 fputs("\n",fp);
153175 module_list = uim_scm_cdr(module_list);
154- if(module_list == uim_scm_null_list()) {
176+ if (module_list == uim_scm_null_list()) {
155177 break;
156178 }
157179 }
158-
159180 }
160181
161182 fclose(fp);
@@ -166,7 +187,8 @@ static uim_lisp
166187 write_loader_scm(uim_lisp str)
167188 {
168189 FILE *fp;
169- if(path) {
190+
191+ if (path) {
170192 char *p = concat(path, "/loader.scm");
171193 fp = fopen(p, "w");
172194 free(p);
@@ -174,14 +196,14 @@ write_loader_scm(uim_lisp str)
174196 fp = fopen(LOADER_SCM_FILENAME, "w");
175197 }
176198
177- if(!fp) {
199+ if (!fp) {
178200 perror("Failed to open loader.scm");
179201 return uim_scm_f();
180202 }
181203
182204 fputs(";; This is an automatically generated file. DO NOT EDIT.\n\n", fp);
183-
184205 fputs(uim_scm_refer_c_str(str), fp);
206+
185207 fclose(fp);
186208 return uim_scm_t();
187209 }
@@ -190,7 +212,8 @@ static uim_lisp
190212 write_installed_modules_scm(uim_lisp str)
191213 {
192214 FILE *fp;
193- if(path) {
215+
216+ if (path) {
194217 char *p = concat(path, "/installed-modules.scm");
195218 fp = fopen(p, "w");
196219 free(p);
@@ -198,14 +221,14 @@ write_installed_modules_scm(uim_lisp str)
198221 fp = fopen(INSTALLED_MODULES_SCM_FILENAME, "w");
199222 }
200223
201- if(!fp) {
224+ if (!fp) {
202225 perror("Failed to open installed-modules.scm");
203226 return uim_scm_f();
204227 }
205228
206229 fputs(";; This is an automatically generated file. DO NOT EDIT.\n\n", fp);
207-
208230 fputs(uim_scm_refer_c_str(str), fp);
231+
209232 fclose(fp);
210233 return uim_scm_t();
211234 }
@@ -213,75 +236,78 @@ write_installed_modules_scm(uim_lisp str)
213236 int
214237 main(int argc, char *argv[]) {
215238 int i;
216- int registerp = 0;
217- uim_lisp form;
239+ int action = None;
240+ char *module_names = NULL;
218241
219- if(argc <= 2) {
242+ if (argc <= 1) {
220243 print_usage();
221244 exit(EXIT_FAILURE);
222245 }
223246
224247 /* FIXME: To generate loader.scm, we need this setenv for now.
225- But it's a dirty hack, not appropriate. I guess we need entirely new module system. */
248+ But it's a dirty hack, not appropriate. I guess we need entirely
249+ new module system. */
226250 setenv("LIBUIM_VANILLA", "1", 1);
227251
228252 uim_init();
229253 uim_scm_set_verbose_level(1);
230- modulenames = uim_scm_null_list();
231254
232- for(i=0; i<argc; i++) {
233- if(strcmp(argv[i], "--register") == 0) {
234- if(registerp == 2) {
235- printf("Regqistering and unregistering couldn't used at the same time.\n\n");
236- exit(EXIT_FAILURE);
255+ for (i = 0; i < argc; i++) {
256+ if (strcmp(argv[i], "--register") == 0) {
257+ if (action != None) {
258+ action = None;
259+ break;
237260 }
238- registerp = 1; i++;
239- while(argv[i] && strncmp(argv[i], "--", 2)) {
240- modulenames = uim_scm_cons(uim_scm_intern_c_str(argv[i]), modulenames);
261+ action = Register; i++;
262+ while (argv[i] && strncmp(argv[i], "--", 2)) {
263+ module_names = append_module_names(module_names, argv[i]);
241264 i++;
242265 }
243266 i--;
244- } else if(strcmp(argv[i], "--unregister") == 0) {
245- if(registerp == 1) {
246- printf("Registering and unregistering couldn't used at the same time.\n\n");
247- exit(EXIT_FAILURE);
267+ } else if (strcmp(argv[i], "--unregister") == 0) {
268+ if (action != None) {
269+ action = None;
270+ break;
248271 }
249- registerp = 2; i++;
250- while(argv[i] && strncmp(argv[i], "--", 2)) {
251- modulenames = uim_scm_cons(uim_scm_intern_c_str(argv[i]), modulenames);
272+ action = UnRegister; i++;
273+ while (argv[i] && strncmp(argv[i], "--", 2)) {
274+ module_names = append_module_names(module_names, argv[i]);
252275 i++;
253276 }
254277 i--;
255- } else if(strcmp(argv[i], "--path") == 0) {
256- if(argv[i+1]) {
257- path = argv[i+1];
278+ } else if (strcmp(argv[i], "--path") == 0) {
279+ if (argv[i + 1]) {
280+ path = argv[i + 1];
258281 }
282+ } else if (strcmp(argv[i], "--unregister-all") == 0) {
283+ if (action != None) {
284+ action = None;
285+ break;
286+ }
287+ action = UnRegisterAll;
259288 }
260289 }
261290
262- if(!argv[2]) {
291+ if (action == None || (action != UnRegisterAll && !module_names)) {
263292 print_usage();
264293 exit(EXIT_FAILURE);
265294 }
266295
267296 uim_scm_init_subr_0("read-module-list", read_module_list);
268297 uim_scm_init_subr_2("write-module-list", write_module_list);
269-
270- uim_scm_init_subr_0("get-arguments", get_arguments);
271-
272298 uim_scm_init_subr_1("write-loader.scm", write_loader_scm);
273299 uim_scm_init_subr_1("write-installed-modules.scm", write_installed_modules_scm);
274300
275- uim_scm_require_file("uim-module-manager.scm");
301+ if (!uim_scm_require_file("uim-module-manager.scm"))
302+ exit(1);
276303
277- if(registerp == 1) {
278- form = uim_scm_list1(uim_scm_intern_c_str("register-modules"));
279- }
280- if(registerp == 2) {
281- form = uim_scm_list1(uim_scm_intern_c_str("unregister-modules"));
282- }
304+ /* for unregister-all */
305+ if (!module_names)
306+ module_names = "";
283307
284- uim_scm_eval(form);
308+ UIM_EVAL_FSTRING2(NULL, "(%s \"%s\")",
309+ action_command[action],
310+ module_names);
285311
286312 uim_quit();
287313