A multilingual input method framework
Revision | 0ebcd8ac4d45753f81a018ecb537bef999f79a4e (tree) |
---|---|
Time | 2005-09-09 13:50:36 |
Author | ekato <ekato@ff9a...> |
Commiter | ekato |
@@ -35,52 +35,39 @@ SCM_FILES += hk.scm | ||
35 | 35 | endif |
36 | 36 | |
37 | 37 | module_names = "pyload" |
38 | - | |
39 | 38 | if ANTHY |
40 | 39 | module_names += "anthy" |
41 | 40 | endif |
42 | - | |
43 | 41 | if CANNA |
44 | 42 | module_names += "canna" |
45 | 43 | endif |
46 | - | |
47 | 44 | if PRIME |
48 | 45 | module_names += "prime" |
49 | 46 | endif |
50 | - | |
51 | 47 | if SKK |
52 | 48 | module_names += "skk" |
53 | 49 | endif |
54 | - | |
55 | 50 | module_names += "tcode" "tutcode" "hangul" "viqr" "ipa-x-sampa" "latin" |
56 | - | |
57 | 51 | if M17NLIB |
58 | 52 | module_names += "m17nlib" |
59 | 53 | endif |
60 | - | |
61 | 54 | if SCIM |
62 | 55 | module_names += "scim" |
63 | 56 | endif |
64 | 57 | |
65 | 58 | |
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 | |
68 | 61 | 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) | |
75 | 66 | |
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) | |
85 | 72 | |
86 | 73 | # $(ECHO) $(ECHO_N) >$@ |
@@ -209,7 +209,16 @@ | ||
209 | 209 | (custom-im-list-as-choice-rec (reverse |
210 | 210 | (alist-delete 'direct im-list eq?)))))) |
211 | 211 | |
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) | |
213 | 222 | '(global im-deployment) |
214 | 223 | (cons |
215 | 224 | 'ordered-list |
@@ -62,6 +62,7 @@ | ||
62 | 62 | ;; initialized. This limitation may be removed after uim 0.4.6. |
63 | 63 | ;; -- YamaKen 2005-01-25 |
64 | 64 | (define enabled-im-list ()) |
65 | +(define system-available-im-list ()) | |
65 | 66 | |
66 | 67 | (define-record 'im |
67 | 68 | (list |
@@ -32,72 +32,91 @@ | ||
32 | 32 | (require "im.scm") |
33 | 33 | (require "lazy-load.scm") |
34 | 34 | |
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")) | |
49 | 45 | #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))) | |
51 | 64 | |
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)))) | |
60 | 73 | |
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)))) | |
66 | 83 | |
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 '()))) | |
72 | 87 | |
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))) | |
77 | 93 | |
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)))) | |
82 | 97 | |
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))))) | |
87 | 102 | |
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")))) | |
100 | 120 | |
101 | -;(generate-installed-modules-scm)) | |
102 | 121 | |
103 | 122 | (prealloc-heaps-for-heavy-job) |
@@ -40,15 +40,27 @@ | ||
40 | 40 | |
41 | 41 | #include "uim.h" |
42 | 42 | #include "uim-scm.h" |
43 | -#include "uim-compat-scm.h" | |
44 | - | |
45 | -static char *path; | |
43 | +#include "context.h" | |
46 | 44 | |
47 | 45 | #define MODULE_LIST_FILENAME UIM_DATADIR"/modules" |
48 | 46 | #define LOADER_SCM_FILENAME UIM_DATADIR"/loader.scm" |
49 | 47 | #define INSTALLED_MODULES_SCM_FILENAME UIM_DATADIR"/installed-modules.scm" |
50 | 48 | |
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 | +}; | |
52 | 64 | |
53 | 65 | /* Utility function */ |
54 | 66 | static char * |
@@ -56,7 +68,7 @@ concat(const char *a, const char *b) | ||
56 | 68 | { |
57 | 69 | int len; |
58 | 70 | char *dest; |
59 | - if(!a || !b) | |
71 | + if (!a || !b) | |
60 | 72 | return NULL; |
61 | 73 | len = strlen(a) + strlen(b) + 1; |
62 | 74 | dest = malloc(len); |
@@ -65,27 +77,37 @@ concat(const char *a, const char *b) | ||
65 | 77 | return dest; |
66 | 78 | } |
67 | 79 | |
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) | |
72 | 82 | { |
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; | |
74 | 92 | } |
75 | 93 | |
76 | 94 | static void |
77 | 95 | print_usage(void) |
78 | 96 | { |
79 | 97 | printf("Usage:\n"); |
80 | - printf(" uim-module-manager [OPTION] modulenames...\n\n"); | |
98 | + printf(" uim-module-manager [options]\n\n"); | |
81 | 99 | 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"); | |
86 | 105 | printf("Example:\n"); |
87 | 106 | 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"); | |
89 | 111 | } |
90 | 112 | |
91 | 113 | static uim_lisp |
@@ -95,7 +117,7 @@ read_module_list(void) | ||
95 | 117 | char buf[1024]; |
96 | 118 | uim_lisp module_list = uim_scm_null_list(); |
97 | 119 | |
98 | - if(path) { | |
120 | + if (path) { | |
99 | 121 | char *p = concat(path, "/modules"); |
100 | 122 | fp = fopen(p, "r"); |
101 | 123 | free(p); |
@@ -103,18 +125,18 @@ read_module_list(void) | ||
103 | 125 | fp = fopen(MODULE_LIST_FILENAME, "r"); |
104 | 126 | } |
105 | 127 | |
106 | - if(!fp) { | |
107 | - perror("Failed to read module list."); | |
128 | + if (!fp) { | |
129 | + /* fprintf(stderr, "Warning: failed to read module list.\n"); */ | |
108 | 130 | return uim_scm_f(); |
109 | 131 | } |
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') { | |
112 | 134 | continue; /* comment line or blank line */ |
113 | 135 | } |
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. */ | |
116 | 138 | } |
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); | |
118 | 140 | } |
119 | 141 | fclose(fp); |
120 | 142 | return module_list; |
@@ -124,7 +146,8 @@ static uim_lisp | ||
124 | 146 | write_module_list(uim_lisp new_module, uim_lisp module_list) |
125 | 147 | { |
126 | 148 | FILE *fp; |
127 | - if(path) { | |
149 | + | |
150 | + if (path) { | |
128 | 151 | char *p = concat(path, "/modules"); |
129 | 152 | fp = fopen(p, "w"); |
130 | 153 | free(p); |
@@ -132,30 +155,28 @@ write_module_list(uim_lisp new_module, uim_lisp module_list) | ||
132 | 155 | fp = fopen(MODULE_LIST_FILENAME, "w"); |
133 | 156 | } |
134 | 157 | |
135 | - if(!fp) { | |
158 | + if (!fp) { | |
136 | 159 | perror("Failed to write module list"); |
137 | 160 | return uim_scm_f(); |
138 | 161 | } |
139 | 162 | |
140 | 163 | fputs("# This is an automatically generated file. DO NOT EDIT.\n\n", fp); |
141 | 164 | |
142 | - if(uim_scm_stringp(new_module) == UIM_TRUE) { | |
165 | + if (uim_scm_stringp(new_module) == UIM_TRUE) { | |
143 | 166 | fputs(uim_scm_refer_c_str(new_module), fp); |
144 | - fputs("\n",fp); | |
167 | + fputs("\n", fp); | |
145 | 168 | } |
146 | 169 | |
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) { | |
150 | 172 | uim_lisp module_name = uim_scm_car(module_list); |
151 | 173 | fputs(uim_scm_refer_c_str(module_name), fp); |
152 | 174 | fputs("\n",fp); |
153 | 175 | module_list = uim_scm_cdr(module_list); |
154 | - if(module_list == uim_scm_null_list()) { | |
176 | + if (module_list == uim_scm_null_list()) { | |
155 | 177 | break; |
156 | 178 | } |
157 | 179 | } |
158 | - | |
159 | 180 | } |
160 | 181 | |
161 | 182 | fclose(fp); |
@@ -166,7 +187,8 @@ static uim_lisp | ||
166 | 187 | write_loader_scm(uim_lisp str) |
167 | 188 | { |
168 | 189 | FILE *fp; |
169 | - if(path) { | |
190 | + | |
191 | + if (path) { | |
170 | 192 | char *p = concat(path, "/loader.scm"); |
171 | 193 | fp = fopen(p, "w"); |
172 | 194 | free(p); |
@@ -174,14 +196,14 @@ write_loader_scm(uim_lisp str) | ||
174 | 196 | fp = fopen(LOADER_SCM_FILENAME, "w"); |
175 | 197 | } |
176 | 198 | |
177 | - if(!fp) { | |
199 | + if (!fp) { | |
178 | 200 | perror("Failed to open loader.scm"); |
179 | 201 | return uim_scm_f(); |
180 | 202 | } |
181 | 203 | |
182 | 204 | fputs(";; This is an automatically generated file. DO NOT EDIT.\n\n", fp); |
183 | - | |
184 | 205 | fputs(uim_scm_refer_c_str(str), fp); |
206 | + | |
185 | 207 | fclose(fp); |
186 | 208 | return uim_scm_t(); |
187 | 209 | } |
@@ -190,7 +212,8 @@ static uim_lisp | ||
190 | 212 | write_installed_modules_scm(uim_lisp str) |
191 | 213 | { |
192 | 214 | FILE *fp; |
193 | - if(path) { | |
215 | + | |
216 | + if (path) { | |
194 | 217 | char *p = concat(path, "/installed-modules.scm"); |
195 | 218 | fp = fopen(p, "w"); |
196 | 219 | free(p); |
@@ -198,14 +221,14 @@ write_installed_modules_scm(uim_lisp str) | ||
198 | 221 | fp = fopen(INSTALLED_MODULES_SCM_FILENAME, "w"); |
199 | 222 | } |
200 | 223 | |
201 | - if(!fp) { | |
224 | + if (!fp) { | |
202 | 225 | perror("Failed to open installed-modules.scm"); |
203 | 226 | return uim_scm_f(); |
204 | 227 | } |
205 | 228 | |
206 | 229 | fputs(";; This is an automatically generated file. DO NOT EDIT.\n\n", fp); |
207 | - | |
208 | 230 | fputs(uim_scm_refer_c_str(str), fp); |
231 | + | |
209 | 232 | fclose(fp); |
210 | 233 | return uim_scm_t(); |
211 | 234 | } |
@@ -213,75 +236,78 @@ write_installed_modules_scm(uim_lisp str) | ||
213 | 236 | int |
214 | 237 | main(int argc, char *argv[]) { |
215 | 238 | int i; |
216 | - int registerp = 0; | |
217 | - uim_lisp form; | |
239 | + int action = None; | |
240 | + char *module_names = NULL; | |
218 | 241 | |
219 | - if(argc <= 2) { | |
242 | + if (argc <= 1) { | |
220 | 243 | print_usage(); |
221 | 244 | exit(EXIT_FAILURE); |
222 | 245 | } |
223 | 246 | |
224 | 247 | /* 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. */ | |
226 | 250 | setenv("LIBUIM_VANILLA", "1", 1); |
227 | 251 | |
228 | 252 | uim_init(); |
229 | 253 | uim_scm_set_verbose_level(1); |
230 | - modulenames = uim_scm_null_list(); | |
231 | 254 | |
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; | |
237 | 260 | } |
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]); | |
241 | 264 | i++; |
242 | 265 | } |
243 | 266 | 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; | |
248 | 271 | } |
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]); | |
252 | 275 | i++; |
253 | 276 | } |
254 | 277 | 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]; | |
258 | 281 | } |
282 | + } else if (strcmp(argv[i], "--unregister-all") == 0) { | |
283 | + if (action != None) { | |
284 | + action = None; | |
285 | + break; | |
286 | + } | |
287 | + action = UnRegisterAll; | |
259 | 288 | } |
260 | 289 | } |
261 | 290 | |
262 | - if(!argv[2]) { | |
291 | + if (action == None || (action != UnRegisterAll && !module_names)) { | |
263 | 292 | print_usage(); |
264 | 293 | exit(EXIT_FAILURE); |
265 | 294 | } |
266 | 295 | |
267 | 296 | uim_scm_init_subr_0("read-module-list", read_module_list); |
268 | 297 | uim_scm_init_subr_2("write-module-list", write_module_list); |
269 | - | |
270 | - uim_scm_init_subr_0("get-arguments", get_arguments); | |
271 | - | |
272 | 298 | uim_scm_init_subr_1("write-loader.scm", write_loader_scm); |
273 | 299 | uim_scm_init_subr_1("write-installed-modules.scm", write_installed_modules_scm); |
274 | 300 | |
275 | - uim_scm_require_file("uim-module-manager.scm"); | |
301 | + if (!uim_scm_require_file("uim-module-manager.scm")) | |
302 | + exit(1); | |
276 | 303 | |
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 = ""; | |
283 | 307 | |
284 | - uim_scm_eval(form); | |
308 | + UIM_EVAL_FSTRING2(NULL, "(%s \"%s\")", | |
309 | + action_command[action], | |
310 | + module_names); | |
285 | 311 | |
286 | 312 | uim_quit(); |
287 | 313 |