--- /dev/null
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <m17n.h>
+#include <m17n-misc.h>
+
+MPlist *error_invalid_format;
+MPlist *error_unknown_command;
+MPlist *error_invalid_arg;
+
+MSymbol Merror;
+MSymbol Mset, Mopen, Mclose;
+MSymbol Mget_command, Mconfig_command, Mget_variable, Mconfig_variable;
+
+void
+init (void)
+{
+ Merror = msymbol ("error");
+ Mset = msymbol ("set");
+ Mopen = msymbol ("open");
+ Mclose = msymbol ("close");
+ Mget_command = msymbol ("get-command");
+ Mconfig_command = msymbol ("config-command");
+ Mget_variable = msymbol ("get-variable");
+ Mconfig_variable = msymbol ("config-variable");
+
+ error_invalid_format = mplist ();
+ mplist_add (error_invalid_format, Msymbol, Merror);
+ mplist_add (error_invalid_format, Msymbol, msymbol ("invalid-format"));
+
+ error_unknown_command = mplist ();
+ mplist_add (error_unknown_command, Msymbol, Merror);
+ mplist_add (error_unknown_command, Msymbol, msymbol ("unknwon-command"));
+
+ error_invalid_arg = mplist ();
+ mplist_add (error_invalid_arg, Msymbol, Merror);
+ mplist_add (error_invalid_arg, Msymbol, msymbol ("invalid-argument"));
+}
+
+MPlist *eval (MPlist *);
+
+#define INTEGERP(plist) (mplist_key (plist) == Minteger)
+#define SYMBOLP(plist) (mplist_key (plist) == Msymbol)
+#define MTEXTP(plist) (mplist_key (plist) == Mtext)
+#define PLISTP(plist) (mplist_key (plist) == Mplist)
+#define TAILP(plist) (mplist_key (plist) == Mnil)
+
+MPlist *
+eval_set (MPlist *arg)
+{
+ MSymbol var;
+ MPlist *plist;
+
+ if (! SYMBOLP (arg))
+ return error_invalid_arg;
+ var = mplist_value (arg);
+ arg = mplist_next (arg);
+ if (TAILP (arg))
+ msymbol_put (var, Mplist, NULL);
+ else if (PLISTP (arg))
+ {
+ arg = eval (mplist_value (arg));
+ msymbol_put (var, Mplist, arg);
+ }
+ else
+ {
+ msymbol_put (var, Mplist, arg);
+ }
+ return NULL;
+}
+
+MPlist *
+eval_open (MPlist *arg)
+{
+ MPlist *plist;
+ MSymbol lang, name;
+ MInputMethod *im;;
+
+ if (! SYMBOLP (arg))
+ return error_invalid_arg;
+ lang = mplist_value (arg);
+ plist = mplist_next (arg);
+ if (! SYMBOLP (plist))
+ return error_invalid_arg;
+ name = mplist_value (plist);
+ im = minput_open_im (lang, name, Mnil);
+ plist = mplist ();
+ mplist_add (plist, Mt, im);
+ return plist;
+}
+
+MPlist *
+eval_close (MPlist *arg)
+{
+ MPlist *plist;
+
+ if (! SYMBOLP (arg))
+ return error_invalid_arg;
+ plist = mplist_get (vars, mplist_value (arg));
+ if (! plist)
+ return error_invalid_arg;
+ minput_close_im (mplist_value (plist));
+ return NULL;
+}
+
+MPlist *
+eval_get_command (MPlist *arg)
+{
+ MPlist *plist;
+ MSymbol lang, name, command;
+
+ if (! SYMBOLP (arg))
+ return error_invalid_arg;
+ lang = mplist_value (arg);
+ plist = mplist_next (arg);
+ if (! SYMBOLP (plist))
+ return error_invalid_arg;
+ name = mplist_value (plist);
+ plist = mplist_next (arg);
+ if (SYMBOLP (arg))
+ command = mplist_value (arg);
+ else if (TAILP (arg))
+ command = Mnil;
+ else
+ return error_invalid_arg;
+ return minput_get_command (lang, name, command);
+}
+
+MPlist *
+eval_config_command (MPlist *arg)
+{
+ return NULL;
+}
+
+MPlist *
+eval_get_variable (MPlist *arg)
+{
+ MPlist *plist;
+ MSymbol lang, name, variable;
+
+ if (! SYMBOLP (arg))
+ return error_invalid_arg;
+ lang = mplist_value (arg);
+ plist = mplist_next (arg);
+ if (! SYMBOLP (plist))
+ return error_invalid_arg;
+ name = mplist_value (plist);
+ plist = mplist_next (arg);
+ if (SYMBOLP (arg))
+ variable = mplist_value (arg);
+ else if (TAILP (arg))
+ variable = Mnil;
+ else
+ return error_invalid_arg;
+ return minput_get_variable (lang, name, variable);
+}
+
+MPlist *
+eval_config_variable (MPlist *arg)
+{
+ return NULL;
+}
+
+MPlist *
+eval (MPlist *plist)
+{
+ MSymbol cmd;
+
+ if (! SYMBOLP (plist))
+ return error_invalid_format;
+ cmd = mplist_value (plist);
+ if (cmd == Mset)
+ return eval_set (mplist_next (plist));
+ if (cmd == Mopen)
+ return eval_open (mplist_next (plist));
+ if (cmd == Mclose)
+ return eval_close (mplist_next (plist));
+ if (cmd == Mget_command)
+ return eval_get_command (mplist_next (plist));
+ if (cmd == Mget_variable)
+ return eval_get_variable (mplist_next (plist));
+ if (cmd == Mconfig_command)
+ return eval_config_command (mplist_next (plist));
+ if (cmd == Mconfig_variable)
+ return eval_config_variable (mplist_next (plist));
+ return error_unknown_command;
+}
+
+int
+main ()
+{
+ char line[256];
+
+ M17N_INIT ();
+ init ();
+
+ while (fgets (line, 256, stdin) != NULL)
+ {
+ MText *mt = mtext_from_data (line, strlen (line), MTEXT_FORMAT_US_ASCII);
+ MPlist *plist = mplist_deserialize (mt);
+ MPlist *val = eval (plist);
+
+ if (val)
+ {
+ mdebug_dump_plist (val, 0);
+ fputc ('\n', stderr);
+ fflush (stderr);
+ }
+ m17n_object_unref (plist);
+ m17n_object_unref (mt);
+ }
+
+ M17N_FINI ();
+ exit (0);
+}
+
+