X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=input.cs;h=18e513d39a0433e63b22319c03d7a1ac748311d4;hb=8355f485c657f0cedf56795328468926ef83d186;hp=c4305d72767723624a5d575c2738263b3d5e8ff4;hpb=022f7789c6fa5adac2ad2dd52e296478b4bd1007;p=m17n%2Fm17n-lib-cs.git diff --git a/input.cs b/input.cs index c4305d7..18e513d 100644 --- a/input.cs +++ b/input.cs @@ -1,19 +1,93 @@ using System; using System.Collections.Generic; using System.IO; +using System.Xml; using M17N; using M17N.Core; using M17N.Input; +using Xex = System.Xml.Xexpression; public class Test { - public static void Main() + private static void print (char key, MText head, MText preedit, MText tail) { - MDatabase.ApplicationDir = "/usr/local/share/m17n"; - MInputMethod im = MInputMethod.Get (MSymbol.Of ("vi"), - MSymbol.Of ("telex"), - MSymbol.nil); - Console.WriteLine (im); + Console.Write ("{0} -> \"{1}|{2}|{3}\" (", key, head, preedit, tail); + for (int j = 0; j < head.Length; j++) + Console.Write ("{0}U+{1:X4}", j == 0 ? "(" : " ", head[j]); + Console.Write ("|"); + if (preedit != null) + 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 (")"); } -} + public static void Main(string[] args) + { + // M17n.debug = true; + int argc = 0; + string appdir = "/usr/local/share/m17n"; + int trace_depth = 0; + + while (argc < args.Length && args[argc][0] == '-') + { + if (args[argc] == "-trace") + trace_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" + + " [-trace] [-xml] LANG NAME KEY-SEQUECE"); + return; + } + + Xex.TraceDepth = trace_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]; + MInputMethod.Key left = new MInputMethod.Key ("left"); + MInputMethod.Key right = new MInputMethod.Key ("right"); + + for (int i = 0; i < str.Length; i++) + { + MInputMethod.Key key + = (str[i] == '<' ? left + : str[i] == '>' ? right + : new MInputMethod.Key (str[i])); + bool result = session.HandleKey (ref key); + int pos = session.CurrentPos; + if (! result) + { + if (key == left) + { + if (pos > 0) + session.CurrentPos = --pos; + } + else if (key == right) + { + if (pos < mt.Length) + session.CurrentPos = ++pos; + } + else + { + mt.Ins (pos, str[i]); + session.CurrentPos = ++pos; + } + } + print ((char) str[i], mt[0, pos], session.Preedit, mt[pos, mt.Length]); + } + if (! session.Close ()) + { + int pos = session.CurrentPos; + print (' ', mt[0, pos], null, mt[pos, mt.Length]); + } + } +}