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()
+ public static void Main(string[] args)
{
- //M17n.debug = true;
- MDatabase.ApplicationDir = "/usr/local/share/m17n";
- MText desc, title;
- Xex.Variable[] vars;
- MInputMethod.Command[] cmds;
+ // M17n.debug = true;
+ int argc = 0;
+ string appdir = "/usr/local/share/m17n";
+ int debug_depth = 0;
-#if false
- MDatabase.Tag tag = new MDatabase.Tag ("input-method",
- "t", "nil", "vi-base");
- MDatabase mdb = MDatabase.Find (tag);
- XmlNode node = mdb.Load ("map-alnum", "input-method", "map-list", "map");
-
- Console.WriteLine (node.OuterXml);
-
-#elif false
- MInputMethod im = MInputMethod.Find ("vi", "telex");
-
- if (im.Info (out desc, out title, out vars, out cmds))
+ while (argc < args.Length && args[argc][0] == '-')
{
- Console.WriteLine ("{0}, {1}, {2}, {3}", desc, title, vars, cmds);
- im.Open ();
+ if (args[argc] == "-debug")
+ debug_depth = 10;
+ else if (args[argc] == "-xml")
+ appdir = "/usr/local/share/m17n-xml";
+ argc++;
}
-#else
- MInputMethod[] ims = MInputMethod.List ();
- foreach (MInputMethod im in ims)
+ 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);
- Console.Write ("(<{0}, {1}, {2}>", im.Language, im.Name, im.SubName);
- if (im.Info (out desc, out title, out vars, out cmds))
- Console.Write (" {0}, {1}, {2}, {3}", desc, title, vars, cmds);
- if (! im.Open ())
- Console.Write (" open fail");
+ MText str = args[argc + 2];
+ for (int i = 0; i < str.Length; 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 (")");
}
-#endif
}
}