summaryrefslogtreecommitdiff
path: root/tools/rdf2binary.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/rdf2binary.c')
-rw-r--r--tools/rdf2binary.c89
1 files changed, 89 insertions, 0 deletions
diff --git a/tools/rdf2binary.c b/tools/rdf2binary.c
new file mode 100644
index 0000000000..3597efa727
--- /dev/null
+++ b/tools/rdf2binary.c
@@ -0,0 +1,89 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 Miika Pekkarinen
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20/*
21This tool converts the rdf file to the binary data used in the dict plugin.
22*/
23
24#include <sys/types.h>
25#include <sys/stat.h>
26#include <fcntl.h>
27#include <string.h>
28#include <stdio.h>
29
30/* maximum word lenght, has to be the same in dict.c */
31#define WORDLEN 32
32
33struct word {
34 char word[WORDLEN];
35 long offset;
36};
37
38int main()
39{
40 FILE *in;
41 int idx_out, desc_out;
42 struct word w;
43 char buf[10000];
44 long cur_offset = 0;
45
46 in = fopen("dict.preparsed", "r");
47 idx_out = open("dict.index", O_WRONLY | O_CREAT);
48 desc_out = open("dict.desc", O_WRONLY | O_CREAT);
49
50 if (in == NULL || idx_out < 0 || desc_out < 0) {
51 fprintf(stderr, "Error: Some files couldn't be opened\n");
52 return 1;
53 }
54
55 while (fgets(buf, sizeof buf, in) != NULL) {
56 /* It is safe to use strtok here */
57 const char *word = strtok(buf, "\t");
58 const char *desc = strtok(NULL, "\t");
59
60 if (word == NULL || desc == NULL) {
61 fprintf(stderr, "Parse error!\n");
62 fprintf(stderr, "word: %s\ndesc: %s\n", word, desc);
63
64 return 2;
65 }
66
67 /* We will null-terminate the words */
68 strncpy(w.word, word, WORDLEN - 1);
69 w.offset = cur_offset;
70 write(idx_out, &w, sizeof(struct word));
71
72 while (1) {
73 int len = strlen(desc);
74 cur_offset += len;
75 write(desc_out, desc, len);
76
77 desc = strtok(NULL, "\t");
78 if (desc == NULL)
79 break ;
80
81 cur_offset++;
82 write(desc_out, "\n", 1);
83
84 }
85 }
86
87 return 0;
88}
89