err_t
ion_open_dictionary(
    dictionary_handler_t    *handler, /* Initialized */
    dictionary_t            *dictionary, /* Empty, to be returned */
    ion_dictionary_id_t     id
)
{
    err_t err;

    ion_dictionary_config_info_t config;
    err = ion_lookup_in_master_table(id, &config);
    if (err_ok != err) { return err_dictionary_initialization_failed; } /* Lookup for id failed */

    err = dictionary_open(handler, dictionary, &config);
    return err;
}
Exemple #2
0
static int save(char *outfile,
		char *lang1, char *lang2,
		char *dicfile1, nat_uint32_t *tab1,
		char *dicfile2, nat_uint32_t *tab2,
		wchar_t *string1, nat_uint32_t ptr1, NATCell *cells1, nat_uint32_t size1,
		wchar_t *string2, nat_uint32_t ptr2, NATCell *cells2, nat_uint32_t size2) {
    FILE *out = NULL;
    nat_int_t s;

    Dictionary *dic;

    out = gzopen(outfile, "wb");
    if (!out) return 0;

    // Say this is a NATDict
    gzprintf(out,"!NATDict");

    s = strlen(lang1)+1;
    gzwrite(out, &s, sizeof(nat_int_t));
    gzwrite(out, lang1, s);

    s = strlen(lang2)+1;
    gzwrite(out, &s, sizeof(nat_int_t));
    gzwrite(out, lang2, s);

    // Save first lexicon
    g_message("** Saving source Lexicon **");
    gzwrite(out, &ptr1, sizeof(nat_uint32_t));
    gzwrite(out, string1, ptr1);
    gzwrite(out, &size1, sizeof(nat_uint32_t));
    g_message("\tSize: %u", size1);
    gzwrite(out, cells1, sizeof(NATCell) * size1);

    // Save second lexicon
    g_message("** Saving target Lexicon **");
    gzwrite(out, &ptr2, sizeof(nat_uint32_t));
    gzwrite(out, string2, ptr2);
    gzwrite(out, &size2, sizeof(nat_uint32_t));
    g_message("\tSize: %u", size2);
    gzwrite(out, cells2, sizeof(NATCell)* size2);

    // Load first dictionary
    g_message("** Source -> Target dictionary **");
    g_message("\tLoading...");
    dic = dictionary_open(dicfile1);

    dictionary_remap(tab1, tab2, dic);

    g_message("\tSaving...");
    gzwrite(out, &dic->size, sizeof(nat_uint32_t));
    gzwrite(out, dic->pairs, sizeof(DicPair)*MAXENTRY*(dic->size+1));
    gzwrite(out, dic->occurs, sizeof(nat_uint32_t)*(dic->size+1));
    dictionary_free(dic);

    // Load second dictionary
    g_message("** Target -> Source dictionary **");
    g_message("\tLoading...");
    dic = dictionary_open(dicfile2);

    dictionary_remap(tab2, tab1, dic);

    g_message("\tSaving...");
    gzwrite(out, &dic->size, sizeof(nat_uint32_t));
    gzwrite(out, dic->pairs, sizeof(DicPair)*MAXENTRY*(dic->size+1));
    gzwrite(out, dic->occurs, sizeof(nat_uint32_t)*(dic->size+1));
    dictionary_free(dic);

    // Close the file
    g_message("** DONE **");
    gzclose(out);

    return 1;
}