Author: yamakenz
Date: Mon May 28 02:52:01 2007
New Revision: 4567

Modified:
   trunk/uim/m17nlib.c

Log:
* This commit fix the problem opening all of registered m17n IM at
  startup reported by Kenichi Handa on [uim-ja 27]. Thanks letting us
  know the problem

* uim/m17nlib.c
  - (im_instance): New static function
  - (init_m17nlib): Defer m17nlib IM instantiation
  - (get_input_method_short_desc, find_im_by_name): Follow the
    introduction of lazy IM instantiation


Modified: trunk/uim/m17nlib.c
==============================================================================
--- trunk/uim/m17nlib.c (original)
+++ trunk/uim/m17nlib.c Mon May 28 02:52:01 2007
@@ -63,6 +63,8 @@
   int  nr_candidates;
 } *ic_array;
 
+static MInputMethod *im_instance(int nth);
+
 /* Utility function */
 static char *
 m17nlib_utf8_find_next_char(const char *p)
@@ -199,16 +201,16 @@
   }
 
   for (elm = imlist; mplist_key(elm) != Mnil; elm = mplist_next(elm)) {
-    MDatabase *mdb = mplist_value(elm);
-    MSymbol *tag = mdatabase_tag(mdb); /* tag[1]: lang, tag[2]: name */
+    MDatabase *mdb;
+    MSymbol *tag, lang, imname;
 
-    if (tag[1] != Mnil) {
-      MInputMethod *im = minput_open_im(tag[1], tag[2], NULL);
+    mdb = mplist_value(elm);
+    tag = mdatabase_tag(mdb);
+    lang = tag[1];
+    imname = tag[2];
 
-      if (im)
-       pushback_input_method(im, msymbol_name(im->language),
-                             msymbol_name(im->name));
-    }
+    if (lang != Mnil)
+      pushback_input_method(NULL, msymbol_name(lang), msymbol_name(imname));
   }
 #if 0
   register_callbacks();
@@ -476,7 +478,10 @@
     MInputMethod *im;
     MText *desc;
 
-    im = im_array[nth].im;
+    im = im_instance(nth);
+    if (!im)
+      return uim_scm_make_str(N_("m17n library IM open error"));
+
     desc = minput_get_description(im->language, im->name);
     if (desc) {
       int i, len;
@@ -523,6 +528,21 @@
 }
 
 static MInputMethod *
+im_instance(int nth)
+{
+  struct im_ *ent;
+
+  if (!(0 <= nth && nth < nr_input_methods))
+    return NULL;
+
+  ent = &im_array[nth];
+  if (!ent->im)
+    ent->im = minput_open_im(msymbol(ent->lang), msymbol(ent->name), NULL);
+
+  return ent->im;
+}
+
+static MInputMethod *
 find_im_by_name(const char *name)
 {
   int i;
@@ -542,7 +562,7 @@
       snprintf(buf, 100, "%s-%s", im_array[i].lang, im_array[i].name);
 
     if (!strcmp(im_name, buf))
-      return im_array[i].im;
+      return im_instance(i);
   }
 
   return NULL;

Reply via email to