#include <string.h>

#include <glib.h>
#include <enchant.h>

static void
enumerate_dicts (const gchar * const lang_tag,
    const gchar * const provider_name,
    const gchar * const provider_desc,
    const gchar * const provider_file,
    gpointer user_data)
{
  g_print ("%s %s %s %s\n", lang_tag, provider_name, provider_desc, provider_file);
}

static void
list_dicts (void)
{
  EnchantBroker *broker;

  g_print ("Installed dicts\n");
  broker = enchant_broker_init ();
  enchant_broker_list_dicts (broker, enumerate_dicts, NULL);
  enchant_broker_free (broker);
}

static void
check_word (const gchar *lang,
    const gchar *word)
{
  EnchantBroker *broker;
  EnchantDict *speller;
  gboolean result;

  broker = enchant_broker_init ();
  speller = enchant_broker_request_dict (broker, lang);
  g_assert (speller != NULL);

  result = (enchant_dict_check (speller, word, strlen (word)) == 0);

  g_print ("\nCheck '%s' using '%s': %d\n", word, lang, result);

  enchant_broker_free_dict (broker, speller);
  enchant_broker_free (broker);
}

int main (int argc,
    char **argv)
{
  list_dicts ();

  if (argc == 3)
    check_word (argv[1], argv[2]);

  return 0;
}
