idx2index.c
author viric <viriketo@gmail.com>
Fri, 30 Mar 2012 18:55:30 +0200
branchsql
changeset 32 6a1a709330bf
parent 8 09ec33061ff3
permissions -rw-r--r--
Adding code to dump the words as sql.
viric@0
     1
#include <stdio.h>
viric@0
     2
#include <netinet/in.h>
viric@0
     3
viric@0
     4
/*
viric@0
     5
 * idx2index - Part of the flow to convert a StarDict index to a dictd index.
viric@0
     6
 *             Author: LluĂ­s Batlle
viric@0
     7
 * In order to convert a StarDict idx file to a dictd index file, pass:
viric@0
     8
 * ./idx2index < file.idx | LC_ALL=POSIX sort > file.index
viric@0
     9
 * */
viric@0
    10
viric@8
    11
static int get_raw_int()
viric@0
    12
{
viric@0
    13
    int i;
viric@0
    14
    fread(&i, sizeof(int) , 1, stdin);
viric@0
    15
    i = ntohl(i); /* Network to Host order */
viric@0
    16
    return i;
viric@0
    17
}
viric@0
    18
viric@8
    19
static int get_raw_word(char * word)
viric@0
    20
{
viric@0
    21
    int c;
viric@0
    22
    int count = 0;
viric@0
    23
viric@0
    24
    do
viric@0
    25
    {
viric@0
    26
        c = getchar();
viric@0
    27
        if (c == EOF)
viric@0
    28
            break;
viric@0
    29
        word[count] = (char) c;
viric@0
    30
        ++count;
viric@0
    31
    } while (c != 0);
viric@0
    32
    return count;
viric@0
    33
}
viric@0
    34
viric@0
    35
int main()
viric@0
    36
{
viric@0
    37
    char word[256];
viric@0
    38
viric@0
    39
    do
viric@0
    40
    {
viric@0
    41
        int offset, length;
viric@0
    42
        int res;
viric@0
    43
        char c_offset[20], c_length[20];
viric@0
    44
viric@8
    45
        res = get_raw_word(word);
viric@0
    46
        if (res == 0)
viric@0
    47
            break;
viric@8
    48
        offset = get_raw_int();
viric@0
    49
        num_to_ia5(c_offset, offset);
viric@8
    50
        length = get_raw_int();
viric@0
    51
        num_to_ia5(c_length, length);
viric@0
    52
        printf("%s\t%s\t%s\n", word, c_offset, c_length);
viric@0
    53
    } while(1);
viric@0
    54
    return 0;
viric@0
    55
}