ca3f7e4a3904b3d0a7d89a19e9ecec574822deea
[m17n/m17n-lib-cs.git] / input.cs
1 using System;
2 using System.Collections.Generic;
3 using System.IO;
4 using System.Xml;
5 using M17N;
6 using M17N.Core;
7 using M17N.Input;
8 using Xex = System.Xml.Xexpression;
9
10 public class Test
11 {
12   public static void Main(string[] args)
13   {
14     // M17n.debug = true;
15     int argc = 0;
16     string appdir = "/usr/local/share/m17n";
17     int debug_depth = 0;
18
19     while (argc < args.Length && args[argc][0] == '-')
20       {
21         if (args[argc] == "-debug")
22           debug_depth = 10;
23         else if (args[argc] == "-xml")
24           appdir = "/usr/local/share/m17n-xml";
25         argc++;
26       }
27     if (argc + 2 >= args.Length)
28       {
29         Console.WriteLine ("Usage: mono [--debug] input.exe"
30                            + " [-debug] [-xml] LANG NAME KEY-SEQUECE");
31         return;
32       }
33
34     Xex.DebugDepth = debug_depth;
35     MDatabase.ApplicationDir = appdir;
36     MInputMethod im = MInputMethod.Find (args[argc], args[argc + 1]);
37     MText mt = new MText ();
38     MInputMethod.Session session = new MInputMethod.Session (im, mt, 0);
39
40     MText str = args[argc + 2];
41     for (int i = 0; i < str.Length; i++)
42       {
43         MInputMethod.Key key = new MInputMethod.Key (str[i]);
44         session.HandleKey (key);
45         int pos = session.CurrentPos;
46         MText head = mt[0, pos];
47         MText preedit = session.Preedit;
48         MText tail = mt[pos, mt.Length];
49         Console.Write ("{0} -> \"{1}|{2}|{3}\" (",
50                            str[i, i + 1], head, preedit, tail);
51         for (int j = 0; j < head.Length; j++)
52           Console.Write ("{0}U+{1:X4}", j == 0 ? "(" : " ", head[j]);
53         Console.Write ("|");
54         for (int j = 0; j < preedit.Length; j++)
55           Console.Write ("{0}U+{1:X4}", j == 0 ? "" : " ", preedit[j]);
56         Console.Write ("|");
57         for (int j = 0; j < tail.Length; j++)
58           Console.Write ("{0}U+{1:X4}", j == 0 ? "" : " ", tail[j]);
59         Console.WriteLine (")");
60       }
61   }
62 }