prepare_meanings.c
author viric@llimona
Sun, 02 Sep 2007 15:59:31 +0200
changeset 26 700a68421116
parent 24 026a2ba0ce16
permissions -rw-r--r--
Adding .hgignore and the ia5test.
viric@22
     1
#include <stdio.h>
viric@22
     2
#include <stdlib.h>
viric@22
     3
#include "dictre.h"
viric@22
     4
viric@22
     5
#define NELEM(x) (sizeof(x)/sizeof(x[0]))
viric@22
     6
viric@22
     7
viric@23
     8
const char *dictionarynames[] = { "bokarjovrueo", "slovnyk_ru-en",
viric@23
     9
    "rus_eng_full" };
viric@22
    10
static struct Dict dictionaries[5/*MAX DICT*/];
viric@22
    11
static int ndictionaries;
viric@22
    12
viric@22
    13
static void init_dictionaries()
viric@22
    14
{
viric@22
    15
    ndictionaries = 0;
viric@22
    16
viric@23
    17
    init_dictionary(&dictionaries[0], dictionarynames[0]);
viric@22
    18
    dictionaries[0].trim_last_newlines = 1;
viric@22
    19
    ndictionaries++;
viric@22
    20
viric@23
    21
    init_dictionary(&dictionaries[1], dictionarynames[1]);
viric@22
    22
    dictionaries[1].trim_first_line = 1;
viric@22
    23
    dictionaries[1].trim_last_newlines = 1;
viric@22
    24
    ndictionaries++;
viric@23
    25
viric@23
    26
    init_dictionary(&dictionaries[2], dictionarynames[2]);
viric@23
    27
    dictionaries[2].trim_first_line = 1;
viric@23
    28
    dictionaries[2].trim_last_newlines = 1;
viric@23
    29
    ndictionaries++;
viric@22
    30
}
viric@22
    31
viric@22
    32
static void close_dictionaries()
viric@22
    33
{
viric@22
    34
    int i;
viric@22
    35
    for(i=0; i<ndictionaries; ++i)
viric@22
    36
        end_dictionary(&dictionaries[i]);
viric@22
    37
viric@22
    38
    ndictionaries=0;
viric@22
    39
}
viric@22
    40
viric@22
    41
void dump_word(const char *word)
viric@22
    42
{
viric@22
    43
    int i;
viric@22
    44
    char def[MAXDEF];
viric@22
    45
    int word_header_dumped = 0;
viric@22
    46
viric@22
    47
    if (strncmp(word, "00database", sizeof("00database"-1)) == 0)
viric@22
    48
        return;
viric@22
    49
viric@22
    50
    for (i=0; i < ndictionaries; ++i)
viric@22
    51
    {
viric@22
    52
        char *found;
viric@22
    53
        find_def(&dictionaries[i], word, def);
viric@22
    54
        if (def[0])
viric@22
    55
        {
viric@22
    56
            if(!word_header_dumped)
viric@22
    57
            {
viric@22
    58
                printf(":%s:", word);
viric@22
    59
                word_header_dumped = 1;
viric@22
    60
            }
viric@24
    61
            printf("-- [%s]\n%s\n\n", dictionarynames[i], def);
viric@22
    62
        }
viric@22
    63
    }
viric@22
    64
}
viric@22
    65
viric@22
    66
void dump_words()
viric@22
    67
{
viric@22
    68
    FILE *fwords;
viric@22
    69
    char word[MAXWORD];
viric@22
    70
viric@22
    71
    fwords = fopen("words.txt", "r");
viric@22
    72
    if (fwords == 0)
viric@22
    73
    {
viric@22
    74
        printf("Cannot open words.txt\n");
viric@22
    75
        exit(-1);
viric@22
    76
    }
viric@22
    77
viric@22
    78
    do
viric@22
    79
    {
viric@22
    80
        char *res;
viric@22
    81
        res = fgets(word, MAXWORD, fwords);
viric@22
    82
        if (res == 0)
viric@22
    83
            break;
viric@22
    84
        word[strlen(word) - 1] = 0; /* Remove \n in the line */
viric@22
    85
        dump_word(word);
viric@22
    86
    } while(1);
viric@22
    87
}
viric@22
    88
viric@22
    89
int main()
viric@22
    90
{
viric@22
    91
    init_dictionaries();
viric@22
    92
viric@22
    93
    dump_words();
viric@22
    94
viric@22
    95
    close_dictionaries();
viric@22
    96
viric@22
    97
    return 0;
viric@22
    98
}