*** empty log message ***
[m17n/m17n-test.git] / finddb.c
diff --git a/finddb.c b/finddb.c
new file mode 100644 (file)
index 0000000..53ec655
--- /dev/null
+++ b/finddb.c
@@ -0,0 +1,55 @@
+#include <stdio.h>
+#include <m17n.h>
+#include <m17n-misc.h>
+
+int
+main (int argc, char **argv)
+{
+  MSymbol tags[4];
+  int i;
+  MDatabase *mdb;
+  MPlist *plist;
+
+  M17N_INIT ();
+  for (i = 0; i < argc - 1; i++)
+    tags[i] = msymbol (argv[i + 1]);
+  for (; i < 4; i++)
+    tags[i] = Mnil;
+  mdb = mdatabase_find (tags[0], tags[1], tags[2], tags[3]);
+  if (! mdb)
+    {
+      MPlist *p;
+
+      plist = mdatabase_list (tags[0], tags[1], tags[2], tags[3]);
+
+      if (! plist)
+       {
+         printf ("No such database!\n");
+         exit (1);
+       }
+      printf ("These databases matched.\n");
+      for (p = plist; mplist_key (p) != Mnil; p = mplist_next (p))
+       {
+         MSymbol *s = mdatabase_tag (mplist_value (p));
+
+         printf ("(");
+         for (i = 0; i < 4; i++)
+           {
+             if (i > 0) putchar (' ');
+             printf ("%s", msymbol_name (s[i]));
+           }
+         printf (")\n");
+       }
+      exit (1);
+    }
+  plist = mdatabase_load (mdb);
+  if (! plist)
+    {
+      printf ("Load fail!\n");
+      exit (1);
+    }
+  mdebug_dump_plist (plist, 0);
+  m17n_object_unref (plist);
+  M17N_FINI ();
+  exit (0);
+}