diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/rdf2binary.c | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/tools/rdf2binary.c b/tools/rdf2binary.c index 70ca495262..3b3afd59db 100644 --- a/tools/rdf2binary.c +++ b/tools/rdf2binary.c | |||
@@ -30,20 +30,32 @@ This tool converts the rdf file to the binary data used in the dict plugin. | |||
30 | /* maximum word lenght, has to be the same in dict.c */ | 30 | /* maximum word lenght, has to be the same in dict.c */ |
31 | #define WORDLEN 32 | 31 | #define WORDLEN 32 |
32 | 32 | ||
33 | /* struckt packing */ | ||
34 | #ifdef __GNUC__ | ||
35 | #define STRUCT_PACKED __attribute__((packed)) | ||
36 | #else | ||
37 | #define STRUCT_PACKED | ||
38 | #pragma pack (push, 2) | ||
39 | #endif | ||
40 | |||
41 | |||
33 | struct word | 42 | struct word |
34 | { | 43 | { |
35 | char word[WORDLEN]; | 44 | char word[WORDLEN]; |
36 | long offset; | 45 | long offset; |
37 | }; | 46 | } STRUCT_PACKED; |
38 | 47 | ||
39 | /* convert offsets here, not on device. */ | 48 | /* convert offsets here, not on device. */ |
40 | long long_to_big_endian (void* value) | 49 | long reverse (long N) { |
41 | { | 50 | unsigned char B[4]; |
42 | unsigned char* bytes = (unsigned char*) value; | 51 | B[0] = (N & 0x000000FF) >> 0; |
43 | return (long)bytes[0] | ((long)bytes[1] << 8) | | 52 | B[1] = (N & 0x0000FF00) >> 8; |
44 | ((long)bytes[2] << 16) | ((long)bytes[3] << 24); | 53 | B[2] = (N & 0x00FF0000) >> 16; |
54 | B[3] = (N & 0xFF000000) >> 24; | ||
55 | return ((B[0] << 24) | (B[1] << 16) | (B[2] << 8) | (B[3] << 0)); | ||
45 | } | 56 | } |
46 | 57 | ||
58 | |||
47 | int main() | 59 | int main() |
48 | { | 60 | { |
49 | FILE *in, *idx_out, *desc_out; | 61 | FILE *in, *idx_out, *desc_out; |
@@ -77,7 +89,7 @@ int main() | |||
77 | 89 | ||
78 | /* We will null-terminate the words */ | 90 | /* We will null-terminate the words */ |
79 | strncpy(w.word, word, WORDLEN - 1); | 91 | strncpy(w.word, word, WORDLEN - 1); |
80 | w.offset = long_to_big_endian(&cur_offset); | 92 | w.offset = reverse(cur_offset); |
81 | fwrite(&w, sizeof(struct word), 1, idx_out); | 93 | fwrite(&w, sizeof(struct word), 1, idx_out); |
82 | 94 | ||
83 | while (1) | 95 | while (1) |