X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=input.cs;h=ca3f7e4a3904b3d0a7d89a19e9ecec574822deea;hb=d514dc2573b9efceca395594cefa93c6446f961d;hp=5b3cf202db0542b0f714a96ad6a782129d568578;hpb=4ab20c0f4785424513d93f02b82085e1394b3872;p=m17n%2Fm17n-lib-cs.git diff --git a/input.cs b/input.cs index 5b3cf20..ca3f7e4 100644 --- a/input.cs +++ b/input.cs @@ -2,23 +2,61 @@ using System; using System.Collections.Generic; using System.IO; using System.Xml; -using System.Xml.Expression; using M17N; using M17N.Core; using M17N.Input; -using Xex = System.Xml.Expression.Xexpression; +using Xex = System.Xml.Xexpression; public class Test { public static void Main(string[] args) { - //M17n.debug = true; - Xex.debug_level = 10; - MDatabase.ApplicationDir = "/usr/local/share/m17n"; - MInputMethod im = MInputMethod.Find ("vi", "telex"); - MInputMethod.Context ic = new MInputMethod.Context (im); - MText str = args[0]; + // M17n.debug = true; + int argc = 0; + string appdir = "/usr/local/share/m17n"; + int debug_depth = 0; + + while (argc < args.Length && args[argc][0] == '-') + { + if (args[argc] == "-debug") + debug_depth = 10; + else if (args[argc] == "-xml") + appdir = "/usr/local/share/m17n-xml"; + argc++; + } + if (argc + 2 >= args.Length) + { + Console.WriteLine ("Usage: mono [--debug] input.exe" + + " [-debug] [-xml] LANG NAME KEY-SEQUECE"); + return; + } + + Xex.DebugDepth = debug_depth; + MDatabase.ApplicationDir = appdir; + MInputMethod im = MInputMethod.Find (args[argc], args[argc + 1]); + MText mt = new MText (); + MInputMethod.Session session = new MInputMethod.Session (im, mt, 0); + + MText str = args[argc + 2]; for (int i = 0; i < str.Length; i++) - ic.Filter (new MInputMethod.Key (str[i])); + { + MInputMethod.Key key = new MInputMethod.Key (str[i]); + session.HandleKey (key); + int pos = session.CurrentPos; + MText head = mt[0, pos]; + MText preedit = session.Preedit; + MText tail = mt[pos, mt.Length]; + Console.Write ("{0} -> \"{1}|{2}|{3}\" (", + str[i, i + 1], head, preedit, tail); + for (int j = 0; j < head.Length; j++) + Console.Write ("{0}U+{1:X4}", j == 0 ? "(" : " ", head[j]); + Console.Write ("|"); + for (int j = 0; j < preedit.Length; j++) + Console.Write ("{0}U+{1:X4}", j == 0 ? "" : " ", preedit[j]); + Console.Write ("|"); + for (int j = 0; j < tail.Length; j++) + Console.Write ("{0}U+{1:X4}", j == 0 ? "" : " ", tail[j]); + Console.WriteLine (")"); + } } }