prepare_meanings.c
author viric@llimona
Sun, 02 Sep 2007 14:24:10 +0200
changeset 24 026a2ba0ce16
parent 23 97feccfc5215
permissions -rw-r--r--
Now the HTML result shows word meanings.
#include <stdio.h>
#include <stdlib.h>
#include "dictre.h"

#define NELEM(x) (sizeof(x)/sizeof(x[0]))


const char *dictionarynames[] = { "bokarjovrueo", "slovnyk_ru-en",
    "rus_eng_full" };
static struct Dict dictionaries[5/*MAX DICT*/];
static int ndictionaries;

static void init_dictionaries()
{
    ndictionaries = 0;

    init_dictionary(&dictionaries[0], dictionarynames[0]);
    dictionaries[0].trim_last_newlines = 1;
    ndictionaries++;

    init_dictionary(&dictionaries[1], dictionarynames[1]);
    dictionaries[1].trim_first_line = 1;
    dictionaries[1].trim_last_newlines = 1;
    ndictionaries++;

    init_dictionary(&dictionaries[2], dictionarynames[2]);
    dictionaries[2].trim_first_line = 1;
    dictionaries[2].trim_last_newlines = 1;
    ndictionaries++;
}

static void close_dictionaries()
{
    int i;
    for(i=0; i<ndictionaries; ++i)
        end_dictionary(&dictionaries[i]);

    ndictionaries=0;
}

void dump_word(const char *word)
{
    int i;
    char def[MAXDEF];
    int word_header_dumped = 0;

    if (strncmp(word, "00database", sizeof("00database"-1)) == 0)
        return;

    for (i=0; i < ndictionaries; ++i)
    {
        char *found;
        find_def(&dictionaries[i], word, def);
        if (def[0])
        {
            if(!word_header_dumped)
            {
                printf(":%s:", word);
                word_header_dumped = 1;
            }
            printf("-- [%s]\n%s\n\n", dictionarynames[i], def);
        }
    }
}

void dump_words()
{
    FILE *fwords;
    char word[MAXWORD];

    fwords = fopen("words.txt", "r");
    if (fwords == 0)
    {
        printf("Cannot open words.txt\n");
        exit(-1);
    }

    do
    {
        char *res;
        res = fgets(word, MAXWORD, fwords);
        if (res == 0)
            break;
        word[strlen(word) - 1] = 0; /* Remove \n in the line */
        dump_word(word);
    } while(1);
}

int main()
{
    init_dictionaries();

    dump_words();

    close_dictionaries();

    return 0;
}