1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2005 Miika Pekkarinen
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
23 This tool converts the rdf file to the binary data used in the dict plugin.
26 #include <sys/types.h>
32 /* maximum word lenght, has to be the same in dict.c */
37 #define STRUCT_PACKED __attribute__((packed))
40 #pragma pack (push, 2)
50 /* convert offsets here, not on device. */
51 long reverse (long N
) {
53 B
[0] = (N
& 0x000000FF) >> 0;
54 B
[1] = (N
& 0x0000FF00) >> 8;
55 B
[2] = (N
& 0x00FF0000) >> 16;
56 B
[3] = (N
& 0xFF000000) >> 24;
57 return ((B
[0] << 24) | (B
[1] << 16) | (B
[2] << 8) | (B
[3] << 0));
63 FILE *in
, *idx_out
, *desc_out
;
68 in
= fopen("dict.preparsed", "r");
69 idx_out
= fopen("dict.index", "wb");
70 desc_out
= fopen("dict.desc", "wb");
72 if (in
== NULL
|| idx_out
== NULL
|| desc_out
== NULL
)
74 fprintf(stderr
, "Error: Some files couldn't be opened\n");
78 while (fgets(buf
, sizeof buf
, in
) != NULL
)
80 /* It is safe to use strtok here */
81 const char *word
= strtok(buf
, "\t");
82 const char *desc
= strtok(NULL
, "\t");
84 if (word
== NULL
|| desc
== NULL
)
86 fprintf(stderr
, "Parse error!\n");
87 fprintf(stderr
, "word: %s\ndesc: %s\n", word
, desc
);
92 /* We will null-terminate the words */
93 strncpy(w
.word
, word
, WORDLEN
- 1);
94 w
.offset
= reverse(cur_offset
);
95 fwrite(&w
, sizeof(struct word
), 1, idx_out
);
99 int len
= strlen(desc
);
101 fwrite(desc
, len
, 1, desc_out
);
103 desc
= strtok(NULL
, "\t");
108 fwrite("\n", 1, 1, desc_out
);