idx2index.c
author viric <viriketo@gmail.com>
Fri, 30 Mar 2012 18:54:55 +0200
changeset 31 2bcc08d0f1d8
parent 8 09ec33061ff3
permissions -rw-r--r--
Fixing an error message
#include <stdio.h>
#include <netinet/in.h>

/*
 * idx2index - Part of the flow to convert a StarDict index to a dictd index.
 *             Author: LluĂ­s Batlle
 * In order to convert a StarDict idx file to a dictd index file, pass:
 * ./idx2index < file.idx | LC_ALL=POSIX sort > file.index
 * */

static int get_raw_int()
{
    int i;
    fread(&i, sizeof(int) , 1, stdin);
    i = ntohl(i); /* Network to Host order */
    return i;
}

static int get_raw_word(char * word)
{
    int c;
    int count = 0;

    do
    {
        c = getchar();
        if (c == EOF)
            break;
        word[count] = (char) c;
        ++count;
    } while (c != 0);
    return count;
}

int main()
{
    char word[256];

    do
    {
        int offset, length;
        int res;
        char c_offset[20], c_length[20];

        res = get_raw_word(word);
        if (res == 0)
            break;
        offset = get_raw_int();
        num_to_ia5(c_offset, offset);
        length = get_raw_int();
        num_to_ia5(c_length, length);
        printf("%s\t%s\t%s\n", word, c_offset, c_length);
    } while(1);
    return 0;
}