+ 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]);
+ }
+ }
+}