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
{
+ private static void print (char key, MText head, MText preedit, MText tail)
+ {
+ 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;
- Xex.debug_level = 4;
- 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 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++)
- ic.Filter (new MInputMethod.Key (str[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]);
+ }
}
}