10 show_description (MText *mt, int indent)
14 printf ("\n%*sdescription: ", indent, "");
15 mconv_encode_stream (utf8, mt, stdout);
18 printf ("\n%*sno-description", indent, "");
22 show_input_method (MSymbol lang, MSymbol name, int indent)
28 language = msymbol ("generic");
29 else if ((language = msymbol_get (lang, Mlanguage)) == Mnil)
31 printf ("\n%*slanguage: %s name: %s",
32 indent, "", msymbol_name (language), msymbol_name (name));
33 mt = minput_get_description (lang, name);
34 show_description (mt, indent + 2);
36 m17n_object_unref (mt);
40 show_command (MSymbol cmd, MPlist *p, int indent)
42 printf ("\n%*sname: %s", indent, "", msymbol_name (cmd));
44 show_description (mplist_value (p), indent);
46 if (mplist_key (p) == Mnil)
47 printf ("\n%*skey-sequence: global assignments are effective", indent, "");
49 for (; mplist_key (p) != Mnil; p = mplist_next (p))
50 if (mplist_key (p) == Mplist)
52 MPlist *p0 = mplist_value (p);
54 if (mplist_key (p0) != Mnil)
56 printf ("\n%*skey-sequence:", indent, "");
57 for (; mplist_key (p0) != Mnil; p0 = mplist_next (p0))
58 printf (" %s", msymbol_name ((MSymbol) mplist_value (p0)));
64 show_variable (MSymbol var, MPlist *p, int indent)
68 printf ("\n%*sname: %s", indent, "", msymbol_name (var));
70 show_description (mplist_value (p), indent);
72 printf ("\n%*sinitial-value: ", indent, "");
73 type = mplist_key (p);
75 printf ("%d", (int) mplist_value (p));
76 else if (type == Msymbol)
77 printf ("%s", msymbol_name ((MSymbol) mplist_value (p)));
78 else /* type == Mtext */
81 mconv_encode_stream (utf8, (MText *) mplist_value (p), stdout);
85 printf ("\n%*svalid-value:", indent, "");
86 if (mplist_key (p) == Mnil)
87 printf (" any value of type %s", msymbol_name (type));
89 for (; mplist_key (p) != Mnil; p = mplist_next (p))
91 MSymbol this_type = mplist_key (p);
93 if (type != this_type && (type != Minteger || this_type != Mplist))
94 /* This shouldn't happen. */
96 if (this_type == Minteger)
97 printf (" %d", (int) mplist_value (p));
98 else if (this_type == Msymbol)
99 printf (" %s", msymbol_name ((MSymbol) mplist_value (p)));
100 else if (this_type == Mtext)
103 mconv_encode_stream (utf8, (MText *) mplist_value (p), stdout);
106 else /* type == Mplist */
108 MPlist *p0 = mplist_value (p);
110 printf (" %d", (int) mplist_value (p0));
111 p0 = mplist_next (p0);
112 printf ("-%d", (int) mplist_value (p0));
118 MPlist *im_list = NULL;
121 get_im (MSymbol lang, MSymbol name)
128 for (p = im_list; mplist_key (p) != Mnil; p = mplist_next (p))
130 im = mplist_value (p);
131 if (im->language == lang && im->name == name)
134 im = minput_open_im (lang, name, NULL);
137 mplist_push (im_list, Mt, im);
149 for (p = im_list; mplist_key (p) != Mnil; p = mplist_next (p))
151 im = mplist_value (p);
152 minput_close_im (im);
154 m17n_object_unref (im_list);
158 show_preedit (MInputContext *ic)
160 int len = mtext_len (ic->preedit);
164 for (i = 0; i < len; i++)
165 printf (" U+%04X", mtext_ref_char (ic->preedit, i));
171 show_candidates (MInputContext *ic)
173 MPlist *plist = ic->candidate_list;
174 int idx = ic->candidate_index;
179 printf ("candidates:");
182 if (mplist_key (plist) == Mtext)
183 items = mtext_len ((MText *) mplist_value (plist));
185 items = mplist_length ((MPlist *) mplist_value (plist));
189 plist = mplist_next (plist);
191 if (mplist_key (plist) == Mtext)
193 mt = (MText *) mplist_value (plist);
194 for (i = 0; i < items; i++)
197 printf ("[U+%04X]", mtext_ref_char (mt, i));
199 printf (" U+%04X ", mtext_ref_char (mt, i));
204 plist = (MPlist *) mplist_value (plist);
205 for (i = 0; i < items; i++, plist = mplist_next (plist))
207 mt = (MText *) mplist_value (plist);
208 len = mtext_len (mt);
213 for (j = 0; j < len; j++)
217 printf ("U+%04X", mtext_ref_char (mt, j));
230 show_produced (MText *mt)
232 int len = mtext_len (mt);
235 printf ("produced:");
236 for (i = 0; i < len; i++)
237 printf (" U+%04X", mtext_ref_char (mt, i));
243 main (int argc, char **argv)
247 MInputMethod *im = NULL;
248 MInputContext *ic = NULL;
252 while (fgets (line, 256, stdin))
254 if (strncmp (line, "open", 4) == 0)
256 char langstr[16], namestr[16];
259 minput_destroy_ic (ic);
260 if (sscanf (line + 4, "%s %s", langstr, namestr) != 2)
262 lang = msymbol (langstr);
263 name = msymbol (namestr);
264 printf ("opening im \"%s\" \"%s\" ...", langstr, namestr);
265 im = get_im (lang, name);
268 printf (" failed\n");
273 printf ("creating context ...");
274 ic = minput_create_ic (im, NULL);
279 minput_close_im (im);
288 printf ("no input method is available\n");
298 for (i = 0; line[i] != '\n'; i++)
305 sprintf (keystr, "C-%c", c + 64);
307 sprintf (keystr, "%c", c);
308 key = msymbol (keystr);
309 result = minput_filter (ic, key, NULL);
310 if (ic->preedit_changed)
312 if (ic->candidates_changed && ic->candidate_show
313 && ic->candidate_list)
314 show_candidates (ic);
318 minput_lookup (ic, key, NULL, mt);
320 m17n_object_unref (mt);
326 minput_destroy_ic (ic);
334 main (int argc, char **argv)
337 MSymbol unicode, test, commit;
339 int test_input_method_found = 0;
341 /* To make database module find test.mim in this directory. */
345 utf8 = msymbol ("utf-8");
346 unicode = msymbol ("unicode");
347 test = msymbol ("test");
348 commit = msymbol ("commit");
350 mdatabase_define (msymbol ("input"), msymbol ("command"), Mnil, Mnil,
352 printf ("List all available input methods:");
353 plist = mdatabase_list (msymbol ("input-method"), Mnil, Mnil, Mnil);
356 for (pl = plist; mplist_key (pl) != Mnil; pl = mplist_next (pl))
358 MDatabase *mdb = mplist_value (pl);
359 MSymbol *tag = mdatabase_tag (mdb);
361 show_input_method (tag[1], tag[2], 2);
362 if (tag[1] == Mt && tag[2] == test)
363 test_input_method_found = 1;
366 m17n_object_unref (plist);
368 printf ("Is test input method found?\n");
369 if (! test_input_method_found)
373 printf ("Describe commit command and its global key assignment:");
374 plist = minput_get_commands (Mnil, Mnil);
375 if (! plist || ! (plist = mplist_get (plist, commit)))
377 show_command (commit, plist, 2);
380 /* Assign S-space to the command "commit" globally. */
381 printf ("Assign S-space to commit globally:");
383 mplist_add (keyseq, Msymbol, msymbol ("S-space"));
384 if (minput_assign_command_keys (Mnil, Mnil, commit, keyseq) < 0)
386 /* Check the above assignment. */
387 plist = minput_get_commands (Mnil, Mnil);
388 plist = mplist_get (plist, commit);
389 show_command (commit, plist, 2);
392 printf ("Describe commit command and its local key assignment in \"test\":");
393 plist = minput_get_commands (Mt, test);
395 || ! (plist = mplist_get (plist, commit)))
397 show_command (commit, plist, 2);
400 printf ("Assign A-space to commit locally in \"test\":");
401 mplist_put (keyseq, Msymbol, msymbol ("A-space"));
402 if (minput_assign_command_keys (Mt, test, commit, keyseq) < 0
403 || ! (plist = minput_get_commands (Mt, test))
404 || ! (plist = mplist_get (plist, commit)))
406 show_command (commit, plist, 2);
409 printf ("Cancel the above locale assignment:");
410 if (minput_assign_command_keys (Mt, test, commit, NULL) < 0
411 || ! (plist = minput_get_commands (Mt, test))
412 || ! (plist = mplist_get (plist, commit)))
414 show_command (commit, plist, 2);
417 printf ("Assign A-space in addition to global assignments to commit:");
418 minput_assign_command_keys (Mt, test, commit, keyseq);
419 plist = mplist_next (mplist_get (minput_get_commands (Mnil, Mnil), commit));
420 for (; mplist_key (plist) != Mnil; plist = mplist_next (plist))
421 minput_assign_command_keys (Mt, test, commit, mplist_value (plist));
423 if (! (plist = minput_get_commands (Mt, test))
424 || ! (plist = mplist_get (plist, commit)))
426 show_command (commit, plist, 2);
429 printf ("Cancel the assignment without making global assignment effective:");
430 /* Make KEYSEQ an empty plist. */
432 minput_assign_command_keys (Mt, test, commit, NULL);
433 minput_assign_command_keys (Mt, test, commit, keyseq);
434 if (! (plist = minput_get_commands (Mt, test))
435 || ! (plist = mplist_get (plist, commit)))
437 show_command (commit, plist, 2);
439 m17n_object_unref (keyseq);
441 printf ("List variables used in \"test\":");
442 plist = minput_get_variables (Mt, test);
445 for (; mplist_key (plist) != Mnil; plist = mplist_next (plist))
446 show_variable (mplist_key (plist), mplist_value (plist), 2);
449 printf ("Set the first variable to hello ... should fail:\n");
450 plist = minput_get_variables (Mt, test);
451 if (minput_set_variable (Mt, test, mplist_key (plist), msymbol ("hello")) < 0)
452 printf (" Correctly failed\n");
454 printf (" Incorrectly succeeded\n");
456 printf ("Set the first variable to no ... should succeed:\n");
457 if (minput_set_variable (Mt, test, mplist_key (plist), msymbol ("no")) < 0)
458 printf (" Incorrectly failed\n");
460 printf (" Correctly succeeded\n");
462 plist = mplist_next (plist);
463 printf ("Set the second variable to 5 ... should fail:\n");
464 if (minput_set_variable (Mt, test, mplist_key (plist), (void *) 5) < 0)
465 printf (" Correctly failed\n");
467 printf (" Incorrectly succeeded\n");
468 printf ("Set the second variable to 10 ... should succeeded:\n");
469 if (minput_set_variable (Mt, test, mplist_key (plist), (void *) 10) < 0)
470 printf (" Incorrectly failed\n");
472 printf (" Correctly succeeded\n");
474 plist = mplist_next (plist);
477 MText *mt = mtext_from_data (str, strlen (str), MTEXT_FORMAT_US_ASCII);
479 printf ("Set the third variable to \"hello\" ... should succeed:\n");
480 if (minput_set_variable (Mt, test, mplist_key (plist), mt) < 0)
481 printf (" Incorrectly failed\n");
483 printf (" Correctly succeeded\n");
484 m17n_object_unref (mt);
487 printf ("List variables used in \"test\" again:");
488 plist = minput_get_variables (Mt, test);
491 for (; mplist_key (plist) != Mnil; plist = mplist_next (plist))
492 show_variable (mplist_key (plist), mplist_value (plist), 2);
499 printf (" ...failed!\n");